Fixed: saving report error.

Updated: dompdf
This commit is contained in:
thanghv 2024-05-14 01:41:03 +07:00
parent ded4ac0bb6
commit 115da5a45d
4 changed files with 2721 additions and 1046 deletions

View file

@ -12,6 +12,9 @@ class MainWP_CReport_DB {
/** @var string Database table prefix. */
private $table_prefix;

public $default_formats = array();
public $default_reports = array();

/**
* Public static variable to hold the single instance of the class.
*
@ -317,7 +320,7 @@ PRIMARY KEY (`id`) ';
if ( $website ) {
$website = current( $website );
$sql = 'UPDATE ' . $this->table_name( 'client_report_site_token' ) . '
SET site_id = ' . $this->escape( $website->id ) . '
SET site_id = ' . $this->escape( $website->id ) . '
WHERE id = ' . $item->id;
$wpdb->query( $sql );
}
@ -609,8 +612,8 @@ We hope that this report was useful and we look forward to managing your website

if ( $token && ! empty( $site_id ) ) {
$sql = 'SELECT * FROM ' .
$this->table_name( 'client_report_site_token' ) . "
WHERE site_id = '" . $this->escape( $site_id ) . "'
$this->table_name( 'client_report_site_token' ) . "
WHERE site_id = '" . $this->escape( $site_id ) . "'
AND token_id = " . $token->id;

$site_token = $wpdb->get_row( $sql );
@ -684,8 +687,8 @@ We hope that this report was useful and we look forward to managing your website

$qry = ' SELECT st.*, t.token_name FROM ' .
$this->table_name( 'client_report_site_token' ) . ' st , ' .
$this->table_name( 'client_report_token' ) . ' t ' . "
WHERE ( st.site_url = '" . $site_url . "' OR st.site_id = " . $site_id . ' )
$this->table_name( 'client_report_token' ) . ' t ' . "
WHERE ( st.site_url = '" . $site_url . "' OR st.site_id = " . $site_id . ' )
AND st.token_id = t.id '; // st.site_url for compatible data.

$site_tokens = $wpdb->get_results( $qry );
@ -913,8 +916,12 @@ We hope that this report was useful and we look forward to managing your website
if ( $client_tokens ) {
$client_id = $client_tokens->clientid; // do not override client with email is [client.email]
}
} elseif ( $updatedClient = $this->update_client( $update_client ) ) { // create new client
}

if( empty( $client_id ) ) {
if ( $updatedClient = $this->update_client( $update_client ) ) { // create new client
$client_id = $updatedClient->clientid;
}
}
}

@ -1401,7 +1408,7 @@ We hope that this report was useful and we look forward to managing your website
. ' LEFT JOIN ' . $this->table_name( 'client_report_client' ) . ' c '
. ' ON rp.client_id = c.clientid '
. " WHERE rp.recurring_schedule != '' AND rp.scheduled = 1 "
. ' AND rp.completed < rp.schedule_lastsend ' // do not send if completed > schedule_lastsend.
. ' AND ( rp.schedule_lastsend = 0 OR rp.completed < rp.schedule_lastsend ) ' // do not send if completed > schedule_lastsend.
. ' AND rp.retry_counter < 3 ' // try to send three time.
. ' ORDER BY rp.lastsend ASC '
. ' LIMIT 1';

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -2,29 +2,29 @@
/** MainWP Client Reports Extension */

/*
Plugin Name: MainWP Client Reports Extension
Plugin URI: https://mainwp.com
Description: MainWP Client Reports Extension allows you to generate activity reports for your clients sites. Requires MainWP Dashboard.
Version: 4.0.13
Author: MainWP
Author URI: https://mainwp.com
Documentation URI: https://mainwp.com/help/docs/category/mainwp-extensions/client-reports/
Plugin Name: MainWP Client Reports Extension
Plugin URI: https://mainwp.com
Description: MainWP Client Reports Extension allows you to generate activity reports for your clients sites. Requires MainWP Dashboard.
Version: 4.0.14
Author: MainWP
Author URI: https://mainwp.com
Documentation URI: https://mainwp.com/help/docs/category/mainwp-extensions/client-reports/
*/

if ( ! defined( 'MAINWP_CLIENT_REPORTS_PLUGIN_FILE' ) ) {

/**
* Define MAINWP_CLIENT_REPORTS_PLUGIN_FILE with MainWP client reports extension.
*/
define( 'MAINWP_CLIENT_REPORTS_PLUGIN_FILE', __FILE__ );
/**
* Define MAINWP_CLIENT_REPORTS_PLUGIN_FILE with MainWP client reports extension.
*/
define( 'MAINWP_CLIENT_REPORTS_PLUGIN_FILE', __FILE__ );
}

if ( ! defined( 'MAINWP_CLIENT_REPORTS_LOG_PRIORITY_NUMBER' ) ) {

/**
* Define MAINWP_CLIENT_REPORTS_LOG_PRIORITY_NUMBER with MainWP client reports extension.
*/
define( 'MAINWP_CLIENT_REPORTS_LOG_PRIORITY_NUMBER', 55 );
/**
* Define MAINWP_CLIENT_REPORTS_LOG_PRIORITY_NUMBER with MainWP client reports extension.
*/
define( 'MAINWP_CLIENT_REPORTS_LOG_PRIORITY_NUMBER', 55 );
}

/**
@ -32,43 +32,43 @@ if ( ! defined( 'MAINWP_CLIENT_REPORTS_LOG_PRIORITY_NUMBER' ) ) {
*/
class MainWP_CReport_Extension {

/**
* Method instance()
*
* Create a public static instance.
*
* @return mixed Class instance.
*/
public static $instance = null;
/**
* Method instance()
*
* Create a public static instance.
*
* @return mixed Class instance.
*/
public static $instance = null;

/** @var string Hold the extension handle. */
public $plugin_handle = 'mainwp-wpcreport-extension';
/** @var string Hold the extension handle. */
public $plugin_handle = 'mainwp-wpcreport-extension';

/** @var string Hold the entension URL. */
public static $plugin_url;
/** @var string Hold the entension URL. */
public static $plugin_url;

/** @var string Holds the extension's slug. */
public $plugin_slug;
/** @var string Holds the extension's slug. */
public $plugin_slug;

/** @var string Hold the extension's directory location. */
public $plugin_dir;
/** @var string Hold the extension's directory location. */
public $plugin_dir;

/** @var string Hold extension option. */
protected $option;
/** @var string Hold extension option. */
protected $option;

/** @var string Holds option handle. */
protected $option_handle = 'mainwp_wpcreport_extension';
/** @var string Holds option handle. */
protected $option_handle = 'mainwp_wpcreport_extension';

/** @var string Extension version. */
public $version = '1.6';
/** @var string Extension version. */
public $version = '1.6';

/**
* Create a public static instance.
*
* @return mixed Class instance.
*
* @uses MainWP_CReport_Extension()
*/
/**
* Create a public static instance.
*
* @return mixed Class instance.
*
* @uses MainWP_CReport_Extension()
*/
static function get_instance() {
if ( null == self::$instance ) {
self::$instance = new MainWP_CReport_Extension();
@ -76,17 +76,17 @@ class MainWP_CReport_Extension {
return self::$instance;
}

/**
* MainWP_CReport_Extension constructor.
*
* Run each time the class is called.
*
* @uses MainWP_CReport::hook_generate_report()
* @uses MainWP_CReport::hook_get_site_tokens()
* @uses MainWP_CReport::hook_generate_content()
* @uses MainWP_CReport_DB::install()
*/
public function __construct() {
/**
* MainWP_CReport_Extension constructor.
*
* Run each time the class is called.
*
* @uses MainWP_CReport::hook_generate_report()
* @uses MainWP_CReport::hook_get_site_tokens()
* @uses MainWP_CReport::hook_generate_content()
* @uses MainWP_CReport_DB::install()
*/
public function __construct() {

$this->plugin_dir = plugin_dir_path( __FILE__ );
self::$plugin_url = plugin_dir_url( __FILE__ );
@ -101,20 +101,21 @@ class MainWP_CReport_Extension {
add_action( 'mainwp_site_synced', array( &$this, 'site_synced' ), 10, 2 );
add_action( 'mainwp_delete_site', array( &$this, 'on_delete_site' ), 10, 1 );

// to fix action for wp cli.
add_filter( 'mainwp_log_specific_actions', array( $this, 'hook_log_specific_actions' ), 10, 2 );

// to fix action for wp cli.
add_action( 'mainwp_sucuri_scan_done', array( &$this, 'sucuri_scan_done' ), 10, 3 );

/**
* This hook allows you to generate report content via the 'mainwp_client_report_generate' filter.
*
* @see \MainWP_CReport::hook_generate_report();
*/
add_filter( 'mainwp_client_report_generate', array( 'MainWP_CReport', 'hook_generate_report' ), 10, 5 );
/**
* This hook allows you to generate report content via the 'mainwp_client_report_generate' filter.
*
* @see \MainWP_CReport::hook_generate_report();
*/
add_filter( 'mainwp_client_report_generate', array( 'MainWP_CReport', 'hook_generate_report' ), 10, 5 );

add_filter( 'mainwp_client_report_get_site_tokens', array( 'MainWP_CReport', 'hook_get_site_tokens' ), 10, 2 );
add_filter( 'mainwp_client_report_generate_content', array( 'MainWP_CReport', 'hook_generate_content' ), 10, 5 );


if ( isset( $_GET['page'] ) && ( 'Extensions-Mainwp-Client-Reports-Extension' == $_GET['page'] ) && isset( $_GET['tab'] ) && $_GET['tab'] == 'report' ) {
require_once 'includes/functions.php';
add_action( 'admin_print_footer_scripts', 'mainwp_creport_admin_print_footer_scripts' );
@ -125,33 +126,46 @@ class MainWP_CReport_Extension {
add_filter( 'cron_schedules', array( $this, 'getCronSchedules' ) );
}

/**
* Initiate extension localization.
*/
/**
* Initiate extension localization.
*/
public function localization() {
load_plugin_textdomain( 'mainwp-client-reports-extension', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}

/**
* Initiate MainWP Client reports instance.
*
* @uses MainWP_CReport()
*/
public function init() {
/**
* Initiate MainWP Client reports instance.
*
* @uses MainWP_CReport()
*/
public function init() {

$mwp_creport = new MainWP_CReport();
$mwp_creport->init_cron();
}

/**
* Plugin meta row.
*
* @param array $plugin_meta Plugin Meta data.
* @param string $plugin_file Plugin file.
*
* @return array Return plugin meta array.
*/
public function plugin_row_meta( $plugin_meta, $plugin_file ) {

/**
* Hook hook_log_specific_actions.
*
* Hook sites table sortable columns.
*
* @return mixed $sortable_columns.
*/
public function hook_log_specific_actions( $inputs ) {
$inputs[ MAINWP_CLIENT_REPORTS_LOG_PRIORITY_NUMBER ] = __( 'Client Reports', 'mainwp-client-reports-extension' );
return $inputs;
}

/**
* Plugin meta row.
*
* @param array $plugin_meta Plugin Meta data.
* @param string $plugin_file Plugin file.
*
* @return array Return plugin meta array.
*/
public function plugin_row_meta( $plugin_meta, $plugin_file ) {

if ( $this->plugin_slug != $plugin_file ) {
return $plugin_meta;
@ -167,14 +181,14 @@ class MainWP_CReport_Extension {
return $plugin_meta;
}

/**
* Sync client reports data.
*
* @param array $data Client reports data.
* @param array $pWebsite Child Site data.
*
* @return array Return client reports data.
*/
/**
* Sync client reports data.
*
* @param array $data Client reports data.
* @param array $pWebsite Child Site data.
*
* @return array Return client reports data.
*/
public function sync_others_data( $data, $pWebsite = null ) {
if ( ! is_array( $data ) ) {
$data = array();
@ -183,15 +197,15 @@ class MainWP_CReport_Extension {
return $data;
}

/**
* Sync Client reports data.
*
* @param array $website Child site data.
* @param array $information Information data.
*
* @uses MainWP_CReport_Stream::get_option()
* @uses MainWP_CReport_Stream::set_option()
*/
/**
* Sync Client reports data.
*
* @param array $website Child site data.
* @param array $information Information data.
*
* @uses MainWP_CReport_Stream::get_option()
* @uses MainWP_CReport_Stream::set_option()
*/
public function site_synced( $website, $information = array() ) {
$website_id = $website->id;
if ( is_array( $information ) && isset( $information['syncClientReportData'] ) && is_array( $information['syncClientReportData'] ) ) {
@ -207,27 +221,27 @@ class MainWP_CReport_Extension {
}
}

/**
* On delete site.
*
* @param array $website Child site array.
*
* @uses MainWP_CReport_DB::delete_group_report_content()
*/
/**
* On delete site.
*
* @param array $website Child site array.
*
* @uses MainWP_CReport_DB::delete_group_report_content()
*/
public function on_delete_site( $website ) {
if ( $website ) {
MainWP_CReport_DB::get_instance()->delete_group_report_content( 0, $website->id );
}
}

/**
* Sucuri scan done.
*
* @param string $website_id Child Site ID.
* @param string $scan_status Scan status.
* @param array $data Return scan data.
*/
public function sucuri_scan_done( $website_id, $scan_status, $data ) {
/**
* Sucuri scan done.
*
* @param string $website_id Child Site ID.
* @param string $scan_status Scan status.
* @param array $data Return scan data.
*/
public function sucuri_scan_done( $website_id, $scan_status, $data ) {
$scan_result = array();
if ( is_array( $data ) ) {
$blacklisted = isset( $data['BLACKLIST']['WARN'] ) ? true : false;
@ -262,13 +276,12 @@ class MainWP_CReport_Extension {
apply_filters( 'mainwp_fetchurlauthed', $mainWPCReportExtensionActivator->get_child_file(), $mainWPCReportExtensionActivator->get_child_key(), $website_id, 'client_report', $post_data );
}

/**
* Initiate Admin page.
*
* @uses MainWP_CReport::init()
* @uses MainWP_CReport()
* @uses MainWP_CReport_Stream()
*/
/**
* Initiate Admin page.
*
* @uses MainWP_CReport()
* @uses MainWP_CReport_Stream()
*/
public function admin_init() {

if ( isset( $_GET['page'] ) && ( 'Extensions-Mainwp-Client-Reports-Extension' == $_GET['page'] ) &&
@ -290,19 +303,19 @@ class MainWP_CReport_Extension {
)
);

MainWP_CReport::init();
MainWP_CReport::get_instance();
$mwp_creport = new MainWP_CReport();
$mwp_creport->admin_init();
$mwp_creport_stream = new MainWP_CReport_Stream();
$mwp_creport_stream->admin_init();
}

/**
* Set cron schedules to once every 5 minuets.
*
* @param array $schedules Holds the Cron job schedules.
* @return array Return array of cron jobs schedules.
*/
/**
* Set cron schedules to once every 5 minuets.
*
* @param array $schedules Holds the Cron job schedules.
* @return array Return array of cron jobs schedules.
*/
public static function getCronSchedules( $schedules ) {

$schedules['5minutely'] = array(
@ -314,12 +327,12 @@ class MainWP_CReport_Extension {
}


/**
* Sync extensions options.
*
* @param array $values Option values array.
* @return array Return option values array.
*/
/**
* Sync extensions options.
*
* @param array $values Option values array.
* @return array Return option values array.
*/
function mainwp_sync_extensions_options( $values = array() ) {
$values['mainwp-client-reports-extension'] = array(
'plugin_name' => 'MainWP Child Reports',
@ -329,33 +342,31 @@ class MainWP_CReport_Extension {
return $values;
}

/**
* Get option value by given key.
*
* @param string $key Option array key.
* @param string $default Default option key.
* @return string Return option string.
*/
public function get_option( $key, $default = '' ) {
/**
* Get option value by given key.
*
* @param string $key Option array key.
* @param string $default Default option key.
* @return string Return option string.
*/
public function get_option( $key, $default = '' ) {
if ( isset( $this->option[ $key ] ) ) {
return $this->option[ $key ];
}
return $default;
}

/**
* Set options by given key.
*
* @param string $key Option array key.
* @param string $value New option value.
* @return bool True if the value was updated, false otherwise.
*/
public function set_option( $key, $value ) {
/**
* Set options by given key.
*
* @param string $key Option array key.
* @param string $value New option value.
* @return bool True if the value was updated, false otherwise.
*/
public function set_option( $key, $value ) {
$this->option[ $key ] = $value;
return update_option( $this->option_handle, $this->option );
}


}

/**
@ -363,33 +374,33 @@ class MainWP_CReport_Extension {
*/
class MainWP_CReport_Extension_Activator {

/** @var bool Whether MainWP is active or not. */
protected $mainwpMainActivated = false;
/** @var bool Whether MainWP is active or not. */
protected $mainwpMainActivated = false;

/** @var bool Whether MainWP Child Plugin is activated. */
protected $childEnabled = false;
/** @var bool Whether MainWP Child Plugin is activated. */
protected $childEnabled = false;

/** @var bool Whether or not there is a Child Key. */
protected $childKey = false;
/** @var bool Whether or not there is a Child Key. */
protected $childKey = false;

/** @var string Holds the Child File. */
protected $childFile;
/** @var string Holds the Child File. */
protected $childFile;

/** @var string Plugin handle. */
protected $plugin_handle = 'mainwp-client-reports-extension';
/** @var string Plugin handle. */
protected $plugin_handle = 'mainwp-client-reports-extension';

/** @var string MainWP extension name. */
protected $product_id = 'MainWP Client Reports Extension';
/** @var string MainWP extension name. */
protected $product_id = 'MainWP Client Reports Extension';

/** @var string MainWP extension version. */
protected $software_version = '4.0.13';
/** @var string MainWP extension version. */
protected $software_version = '4.0.13';

/**
* MainWP_CReport_Extension_Activator constructor.
*
* Run each time the class is called.
*/
public function __construct() {
/**
* MainWP_CReport_Extension_Activator constructor.
*
* Run each time the class is called.
*/
public function __construct() {

$this->childFile = __FILE__;

@ -410,11 +421,11 @@ class MainWP_CReport_Extension_Activator {
add_action( 'mainwp_cronload_action', array( $this, 'load_cron_actions' ) );
}

/**
* Class Autoloader.
*
* @param string $class_name Class name to load.
*/
/**
* Class Autoloader.
*
* @param string $class_name Class name to load.
*/
function autoload( $class_name ) {
$allowedLoadingTypes = array( 'class' );
$class_name = str_replace( '_', '-', strtolower( $class_name ) );
@ -426,23 +437,23 @@ class MainWP_CReport_Extension_Activator {
}
}

/**
* Load cron actions.
*
* @uses MainWP_CReport::managesite_schedule_backup()
*/
function load_cron_actions() {
/**
* Load cron actions.
*
* @uses MainWP_CReport::managesite_schedule_backup()
*/
function load_cron_actions() {
add_action( 'mainwp_managesite_schedule_backup', array( 'MainWP_CReport', 'managesite_schedule_backup' ), 10, 3 );
}

/**
* Get this extension array.
*
* @param array $pArray Hold the extension array.
*
* @return array Return this extension array.
*/
function get_this_extension( $pArray ) {
/**
* Get this extension array.
*
* @param array $pArray Hold the extension array.
*
* @return array Return this extension array.
*/
function get_this_extension( $pArray ) {

$pArray[] = array(
'plugin' => __FILE__,
@ -454,24 +465,24 @@ class MainWP_CReport_Extension_Activator {
return $pArray;
}

/**
* MainWP Client Report settings.
*
* @uses MainWP_CReport::render()
*/
function settings() {
/**
* MainWP Client Report settings.
*
* @uses MainWP_CReport::render()
*/
function settings() {
do_action( 'mainwp_pageheader_extensions', __FILE__ );
MainWP_CReport::render();
do_action( 'mainwp_pagefooter_extensions', __FILE__ );
}

/**
* Activate MainWP Client Reports Plugin.
*
* @uses MainWP_CReport::renderClientReportsSiteTokens()
* @uses MainWP_CReport_Extension()
*/
function activate_this_plugin() {
/**
* Activate MainWP Client Reports Plugin.
*
* @uses MainWP_CReport::renderClientReportsSiteTokens()
* @uses MainWP_CReport_Extension()
*/
function activate_this_plugin() {

$this->mainwpMainActivated = apply_filters( 'mainwp_activated_check', $this->mainwpMainActivated );
$this->childEnabled = apply_filters( 'mainwp_extension_enabled_check', __FILE__ );
@ -486,31 +497,31 @@ class MainWP_CReport_Extension_Activator {
new MainWP_CReport_Extension();
}

/**
* Get Child key.
*
* @return string|bool Return Child Key or FALSE on failure.
*/
/**
* Get Child key.
*
* @return string|bool Return Child Key or FALSE on failure.
*/
public function get_child_key() {
return $this->childKey;
}

/**
* Get child file.
*
* @return string Return child file.
*/
public function get_child_file() {
/**
* Get child file.
*
* @return string Return child file.
*/
public function get_child_file() {

return $this->childFile;
}

/**
* MainWP error notices.
*/
function mainwp_error_notice() {
/**
* MainWP error notices.
*/
function mainwp_error_notice() {

/** @global string $current_screen Current page. */
/** @global string $current_screen Current page. */
global $current_screen;

if ( $current_screen->parent_base == 'plugins' && $this->mainwpMainActivated == false ) {
@ -518,9 +529,9 @@ class MainWP_CReport_Extension_Activator {
}
}

/**
* Activate MainWP Extension.
*/
/**
* Activate MainWP Extension.
*/
public function activate() {
$options = array(
'product_id' => $this->product_id,
@ -530,9 +541,9 @@ class MainWP_CReport_Extension_Activator {
do_action( 'mainwp_activate_extention', $this->plugin_handle, $options );
}

/**
* Deactivate MainWP Extension.
*/
/**
* Deactivate MainWP Extension.
*/
public function deactivate() {
do_action( 'mainwp_deactivate_extention', $this->plugin_handle );
}