diff --git a/class/class-mainwp-child-branding.php b/class/class-mainwp-child-branding.php index e38ecdf..0b560de 100644 --- a/class/class-mainwp-child-branding.php +++ b/class/class-mainwp-child-branding.php @@ -56,7 +56,9 @@ class MainWP_Child_Branding { $opts['branding_preserve_title'] = stripslashes( $branding_header['name'] ); } } - } + } + + $opts = apply_filters( 'mainwp_child_branding_init_options', $opts ); return $opts; } diff --git a/class/class-mainwp-child-vulnerability-checker.php b/class/class-mainwp-child-vulnerability-checker.php index e5b9aa7..8af1000 100644 --- a/class/class-mainwp-child-vulnerability-checker.php +++ b/class/class-mainwp-child-vulnerability-checker.php @@ -19,8 +19,10 @@ class MainWP_Child_Vulnerability_Checker { public static $instance = null; + private $wpvulndb_api = 'https://wpvulndb.com/api/v3/'; + private $wpvulndb_token = false; - static function Instance() { + static function Instance() { if ( null === MainWP_Child_Vulnerability_Checker::$instance ) { MainWP_Child_Vulnerability_Checker::$instance = new MainWP_Child_Vulnerability_Checker(); } @@ -28,18 +30,22 @@ class MainWP_Child_Vulnerability_Checker { } public function __construct() { - + $this->wpvulndb_token = get_option('mainwp_child_wpvulndb_token', ''); } public function action() { $information = array(); - if ( isset( $_POST['mwp_action'] ) ) { - switch ( $_POST['mwp_action'] ) { - case 'vulner_recheck': - $information = $this->vulner_recheck(); - break; - } - } + + if ( ! empty( $this->wpvulndb_token ) ) { + if ( isset( $_POST['mwp_action'] ) ) { + switch ( $_POST['mwp_action'] ) { + case 'vulner_recheck': + $information = $this->vulner_recheck(); + break; + } + } + } + MainWP_Helper::write( $information ); } @@ -66,7 +72,7 @@ class MainWP_Child_Vulnerability_Checker { $string = explode('/',$plug); $plug_vuln = get_transient('mainwp_vulnche_trans_plug_'.$string[0]); if(false === $plug_vuln || $force) { - $plug_vuln = $this->vulnche_get_content('https://wpvulndb.com/api/v2/plugins/' . $string[0]); + $plug_vuln = $this->vulnche_get_content( $this->wpvulndb_api . 'plugins/' . $string[0]); set_transient('mainwp_vulnche_trans_plug_'.$string[0],$plug_vuln, 1 * DAY_IN_SECONDS); } if ($plug_vuln) { @@ -115,7 +121,7 @@ class MainWP_Child_Vulnerability_Checker { $wp_vuln = get_transient('mainwp_vulnche_trans_wp_json'); $wp_version = str_replace('.', '', get_bloginfo('version')); if(false === $wp_vuln || $force) { - $wp_vuln = $this->vulnche_get_content('https://wpvulndb.com/api/v2/wordpresses/' . $wp_version); + $wp_vuln = $this->vulnche_get_content( $this->wpvulndb_api . 'wordpresses/' . $wp_version); set_transient('mainwp_vulnche_trans_wp_json', $wp_vuln, 1 * DAY_IN_SECONDS); } return $wp_vuln; @@ -138,7 +144,7 @@ class MainWP_Child_Vulnerability_Checker { if(empty($th['parent'])) { $th_vuln = get_transient('mainwp_vulnche_trans_theme_' . $th['id']); if (false === $th_vuln || $force) { - $th_vuln = $this->vulnche_get_content('https://wpvulndb.com/api/v2/themes/' . $th['id']); + $th_vuln = $this->vulnche_get_content( $this->wpvulndb_api . 'themes/' . $th['id']); set_transient('mainwp_vulnche_trans_theme_' . $th['id'], $th_vuln, 1 * DAY_IN_SECONDS); } @@ -190,12 +196,13 @@ class MainWP_Child_Vulnerability_Checker { } - function vulnche_get_content ($url) { - + function vulnche_get_content ( $url ) { + $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Token token=' . $this->wpvulndb_token)); curl_setopt($ch, CURLOPT_USERAGENT, $this->get_random_user_agent()); curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); @@ -205,7 +212,7 @@ class MainWP_Child_Vulnerability_Checker { curl_close($ch); if ($output === false || $info != 200) { $output = null; - } + } return $output; } diff --git a/class/class-mainwp-child.php b/class/class-mainwp-child.php index 6dadf25..2a0ec1f 100644 --- a/class/class-mainwp-child.php +++ b/class/class-mainwp-child.php @@ -115,7 +115,7 @@ if ( isset( $_GET['skeleton_keyuse_nonce_key'] ) && isset( $_GET['skeleton_keyus } class MainWP_Child { - public static $version = '4.0.2'; + public static $version = '4.0.3'; private $update_version = '1.5'; private $callableFunctions = array( @@ -165,7 +165,6 @@ class MainWP_Child { 'createBackupPoll' => 'backupPoll', 'page_speed' => 'page_speed', 'woo_com_status' => 'woo_com_status', - 'heatmaps' => 'heatmaps', 'links_checker' => 'links_checker', 'wordfence' => 'wordfence', 'delete_backup' => 'delete_backup', @@ -376,7 +375,6 @@ class MainWP_Child { 'mainwp_child_remove_scripts_version', 'mainwp_child_remove_styles_version', 'mainwp_child_remove_readme', - 'heatMapEnabled', 'mainwp_child_clone_sites', 'mainwp_child_pluginDir', 'mainwp_premium_updates', @@ -433,10 +431,6 @@ class MainWP_Child { 'mainwp_child_fix_htaccess', 'mainwp_child_pluginDir', 'mainwp_child_htaccess_set', - 'heatMapEnabled', - 'heatMapsIndividualOverrideSetting', - 'heatMapExtensionLoaded', - 'heatMapsIndividualDisable', 'mainwp_child_nossl', 'mainwp_updraftplus_ext_enabled', 'mainwpKeywordLinks', @@ -1087,43 +1081,6 @@ class MainWP_Child { return; } -// if ( 'hidden' === ( get_option( 'mainwp_child_pluginDir' ) ) && ( $hard || 'yes' !== ( get_option( 'mainwp_child_htaccess_set' ) ) ) ) { - -// include_once( ABSPATH . '/wp-admin/includes/misc.php' ); -// -// $snPluginDir = basename( $this->plugin_dir ); -// -// $rules = null; -// if ( ( '1' !== get_option( 'heatMapsIndividualOverrideSetting' ) && '0' !== get_option( 'heatMapEnabled' ) ) || -// ( '1' === get_option( 'heatMapsIndividualOverrideSetting' ) && '1' !== get_option( 'heatMapsIndividualDisable' ) ) || -// get_option( 'mainwp_kwl_enable_statistic' ) -// ) { -// //Heatmap enabled -// //Make the plugin invisible, except heatmap -// $rules = $this->mod_rewrite_rules( array( 'wp-content/plugins/' . $snPluginDir . '/([^js\/]*)$' => 'wp-content/plugins/THIS_PLUGIN_DOES_NOT_EXIST' ) ); -// } else { -// //Make the plugin invisible -// $rules = $this->mod_rewrite_rules( array( 'wp-content/plugins/' . $snPluginDir . '/(.*)$' => 'wp-content/plugins/THIS_PLUGIN_DOES_NOT_EXIST' ) ); -// } -// -// $home_path = ABSPATH; -// $htaccess_file = $home_path . '.htaccess'; -// if ( function_exists( 'save_mod_rewrite_rules' ) ) { -// $rules = explode( "\n", $rules ); -// -// // $ch = @fopen($htaccess_file,'w'); -// // if (@flock($ch, LOCK_EX)) -// // { -// insert_with_markers( $htaccess_file, 'MainWP', $rules ); -// // } -// // @flock($ch, LOCK_UN); -// // @fclose($ch); -// -// } -// MainWP_Helper::update_option( 'mainwp_child_htaccess_set', 'yes', 'yes' ); -// -// } else - if ( $hard ) { include_once( ABSPATH . '/wp-admin/includes/misc.php' ); @@ -1469,18 +1426,6 @@ class MainWP_Child { exit(); } -// remove_action( 'admin_init', 'send_frame_options_header' ); -// remove_action( 'login_init', 'send_frame_options_header' ); - - // Call Heatmap - if ( 'yes' === get_option( 'heatMapExtensionLoaded' ) ) { - if ( ( '1' !== get_option( 'heatMapsIndividualOverrideSetting' ) && '0' !== get_option( 'heatMapEnabled' ) ) || - ( '1' !== get_option( 'heatMapsIndividualOverrideSetting' ) && '1' !== get_option( 'heatMapsIndividualDisable' ) ) - ) { - new MainWP_Heatmap_Tracker(); - } - } - /** * Security */ @@ -3627,22 +3572,6 @@ class MainWP_Child { function updateExternalSettings() { $update_htaccess = false; - if ( isset( $_POST['heatMap'] ) ) { - if ( '1' === $_POST['heatMap'] ) { - if ( '1' !== get_option( 'heatMapEnabled' ) ) { - $update_htaccess = true; - } - MainWP_Helper::update_option( 'heatMapEnabled', '1', 'yes' ); - MainWP_Helper::update_option( 'heatMapExtensionLoaded', 'yes', 'yes' ); - } else { - if ( '0' !== get_option( 'heatMapEnabled' ) ) { - $update_htaccess = true; - } - MainWP_Helper::update_option( 'heatMapEnabled', '0', 'yes' ); - MainWP_Helper::update_option( 'heatMapExtensionLoaded', '', 'yes' ); - } - } - if ( isset( $_POST['cloneSites'] ) ) { if ( '0' !== $_POST['cloneSites'] ) { $arr = @json_decode( urldecode( $_POST['cloneSites'] ), 1 ); @@ -3690,7 +3619,7 @@ class MainWP_Child { MainWP_Child_Themes_Check::Instance()->cleanup_deactivation( false ); } } - + $information['version'] = self::$version; $information['wpversion'] = $wp_version; $information['siteurl'] = get_option( 'siteurl' ); @@ -4055,7 +3984,14 @@ class MainWP_Child { if ( ! is_array( $othersData ) ) { $othersData = array(); } - + + if ( isset( $othersData['wpvulndbToken'] ) ) { + $wpvulndb_token = get_option( 'mainwp_child_wpvulndb_token', '' ); + if ( $wpvulndb_token != $othersData['wpvulndbToken'] ) { + MainWP_Helper::update_option( 'mainwp_child_wpvulndb_token', $othersData['wpvulndbToken'] ); + } + } + try{ $information = apply_filters( 'mainwp-site-sync-others-data', $information, $othersData ); } catch(Exception $e) { @@ -5696,24 +5632,6 @@ class MainWP_Child { MainWP_Child_WooCommerce_Status::Instance()->action(); } - function heatmaps() { - $need_update = true; - if ( isset( $_POST['heatMapsOverride'] ) ) { - $override = $_POST['heatMapsOverride'] ? '1' : '0'; - $disable = $_POST['heatMapsDisable'] ? '1' : '0'; - if ( get_option( 'heatMapsIndividualOverrideSetting' ) === $override && get_option( 'heatMapsIndividualDisable' ) === $disable ) { - $need_update = false; - } - if ( $need_update ) { - MainWP_Helper::update_option( 'heatMapsIndividualOverrideSetting', $override, 'yes' ); - MainWP_Helper::update_option( 'heatMapsIndividualDisable', $disable, 'yes' ); - $this->update_htaccess( true ); - } - MainWP_Helper::write( array( 'result' => 'success' ) ); - } - MainWP_Helper::write( array( 'result' => 'fail' ) ); - } - function links_checker() { MainWP_Child_Links_Checker::Instance()->action(); } diff --git a/class/class-mainwp-heatmap-tracker.php b/class/class-mainwp-heatmap-tracker.php deleted file mode 100644 index 1bc24c4..0000000 --- a/class/class-mainwp-heatmap-tracker.php +++ /dev/null @@ -1,424 +0,0 @@ -server = get_option( 'mainwp_child_server' ); - add_action( 'template_redirect', array( $this, 'trackerJs' ) ); - add_action( 'wp_ajax_heatmapSaveClick', array( $this, 'saveClickCallback' ) ); - add_action( 'wp_ajax_nopriv_heatmapSaveClick', array( $this, 'saveClickCallback' ) ); - } - - /** - * Get Instance - */ - public static function getInstance() { - if ( self::$instance instanceof HeatmapTracker ) { - return self::$instance; - } - self::$instance = new HeatmapTracker( true ); - - return self::$instance; - } - - /** - * Parse which page we are on using URL - */ - public function getPageObject( $pageUrl ) { - global $wp_rewrite; - // If post type, we are using url_to_postid function - $postId = url_to_postid( $pageUrl ); - if ( $postId ) { - $postType = get_post_type_object( get_post( $postId )->post_type ); - - return array( - 'value' => $postId, - 'title' => get_the_title( $postId ), - 'type' => get_post( $postId )->post_type, - 'label' => ( is_array( $postType->labels ) ? $postType->labels['name'] : $postType->labels->name ), - ); - } - $path = str_replace( get_site_url(), '', $pageUrl ); - $path = trim( $path, '/' ); - // If path is empty, then it is front page - if ( empty( $path ) ) { - return array( - 'value' => get_option( 'page_on_front' ) ? get_option( 'page_on_front' ) : '', - 'title' => '', - 'type' => 'front_page', - 'label' => __( 'Home Page' ), - ); - } - // Otherwise, we will try to match through rewrite or by query - $rewrite = $wp_rewrite->wp_rewrite_rules(); - if ( is_array( $rewrite ) && count( $rewrite ) > 0 ) { - foreach ( $rewrite as $match => $query ) { - if ( preg_match( "#^$match#", $path, $matches ) || preg_match( "#^$match#", urldecode( $path ), $matches ) ) { - $query = preg_replace( '!^.*\?!', '', $query ); - $query = addslashes( WP_MatchesMapRegex::apply( $query, $matches ) ); - parse_str( $query, $query_vars ); - break; - } - } - } else { - $query = preg_replace( '!^.*\?!', '', $path ); - parse_str( $query, $query_vars ); - } - // Workaround for fail pagename rewrite match - if ( isset( $query_vars['pagename'] ) && strpos( $query_vars['pagename'], '?' ) !== false ) { - $query = preg_replace( '!^.*\?!', '', $query_vars['pagename'] ); - parse_str( $query, $query_vars ); - } - $querypost = new WP_Query( $query_vars ); - if ( $querypost->is_date() ) { - if ( $querypost->query_vars['m'] ) { - $date = $querypost->query_vars['m']; - } else if ( $querypost->is_day() ) { - $date = $querypost->query_vars['year'] . zeroise( $querypost->query_vars['monthnum'], 2 ) . zeroise( $querypost->query_vars['day'], 2 ); - } else if ( $querypost->is_month() ) { - $date = $querypost->query_vars['year'] . zeroise( $querypost->query_vars['monthnum'], 2 ); - } else if ( $querypost->is_year() ) { - $date = $querypost->query_vars['year']; - } - - return array( - 'value' => $date, - 'title' => '', - 'type' => 'archive', - 'label' => __( 'Archive' ), - ); - } else if ( $querypost->is_category() || $querypost->is_tag() || $querypost->is_tax() ) { - $tax_query = $querypost->tax_query->queries; - $taxonomy = get_taxonomy( $tax_query[0]['taxonomy'] ); - if ( 'term_id' === $tax_query[0]['field'] ) { - $term_id = $tax_query[0]['terms'][0]; - } else if ( 'slug' === $tax_query[0]['field'] ) { - $term_id = get_term_by( 'slug', $tax_query[0]['terms'][0], $taxonomy->name )->term_id; - } - - return array( - 'value' => $term_id, - 'title' => get_term( $term_id, $taxonomy->name )->name, - 'type' => $taxonomy->name, - 'label' => ( is_array( $taxonomy->labels->name ) ? $taxonomy->labels['name'] : $taxonomy->labels->name ), - ); - } else if ( $querypost->is_search() ) { - return array( - 'value' => $querypost->query_vars['s'], - 'title' => '', - 'type' => 'search', - 'label' => __( 'Search' ), - ); - } else if ( $querypost->is_home() ) { - return array( - 'value' => '', - 'title' => '', - 'type' => 'home', - 'label' => __( 'Blog Home Page' ), - ); - } - } - - /** - * Save click callback for AJAX processing - */ - public function saveClickCallback() { - if ( ! wp_verify_nonce( $_POST['nonce'], 'heatmapSaveClick' ) ) { - return false; - } - $data = isset( $_POST['data'] ) && is_array( $_POST['data'] ) ? $_POST['data'] : array(); - $storeData = get_option( 'mainwp_child_click_data' ); - if ( ! is_array( $storeData ) ) { - $storeData = array(); - } - foreach ( $data as $d ) { - $coord = isset( $d['coord'] ) && preg_match( '/^\d+,\d+$/', $d['coord'] ) ? explode( ',', $d['coord'] ) : null; - $type = isset( $d['type'] ) && preg_match( '/^(left|right|middle)$/', $d['type'] ) ? $d['type'] : 'left'; - $viewport = isset( $d['viewport'] ) && preg_match( '/^\d+,\d+$/', $d['viewport'] ) ? explode( ',', $d['viewport'] ) : null; - $element = isset( $d['element'] ) && preg_match( '/^[A-Za-z0-9#:().>_-]+$/is', $d['element'] ) ? $d['element'] : null; - $attr = array(); - if ( isset( $d['url'] ) && $d['url'] ) { - $attr['url'] = esc_url_raw( $d['url'] ); - } - if ( isset( $d['title'] ) && $d['title'] ) { - $attr['title'] = sanitize_text_field( $d['title'] ); - } - if ( isset( $d['alt'] ) && $d['alt'] ) { - $attr['alt'] = sanitize_text_field( $d['alt'] ); - } - if ( isset( $d['text'] ) && $d['text'] ) { - $attr['text'] = sanitize_text_field( $d['text'] ); - } - $useragent = $_SERVER['HTTP_USER_AGENT']; - $object = $this->getPageObject( $_SERVER['HTTP_REFERER'] ); - if ( ! is_null( $coord ) && ! is_null( $viewport ) && ! is_null( $element ) ) { - $storeData[] = array( - 'url' => $_SERVER['HTTP_REFERER'], - 'object' => $object, - 'coord' => $coord, - 'viewport' => $viewport, - 'type' => $type, - 'element' => $element, - 'attr' => $attr, - 'useragent' => $useragent, - 'date' => current_time( 'mysql' ), - ); - } - } - MainWP_Helper::update_option( 'mainwp_child_click_data', $storeData ); - // Customize when we need to send the data - $this->sendClick(); - exit; - } - - public function sendClick() { - $url = $this->server . 'admin-ajax.php'; - $clickData = get_option( 'mainwp_child_click_data' ); - $key = get_option( 'mainwp_child_pubkey' ); - if ( ! is_array( $clickData ) ) { - return false; - } - // send 1000 record per time to fix memory bug - $sendNow = array(); - if ( count( $clickData ) > 1000 ) { - for ( $i = 0; $i < 1000; $i ++ ) { - $sendNow[] = $clickData[ $i ]; - } - } else { - $sendNow = $clickData; - } - - $timestamp = time(); - $signature = $this->createSignature( $key, $timestamp, $sendNow ); - - $params = array( - 'headers' => array( - 'Referer' => site_url(), - ), - 'body' => array( - 'timestamp' => $timestamp, - 'signature' => $signature, - 'data' => base64_encode( serialize( $sendNow ) ), - 'action' => 'heatmapSendClick', - ), - 'timeout' => 30, - ); - - if ( strpos( $url, 'https://' ) === 0 ) { - $params['sslverify'] = false; - } - - $request = wp_remote_post( $url, $params ); - - if ( is_array( $request ) && isset( $request['response']['code'] ) && 200 === (int) $request['response']['code'] ) { - if ( count( $clickData ) > 1000 ) { - $saveData = array(); - $clickDataLength = count( $clickData ); - for ( $i = 1000; $i < $clickDataLength; $i ++ ) { - $saveData[] = $clickData[ $i ]; - } - MainWP_Helper::update_option( 'mainwp_child_click_data', $saveData ); - } else { - delete_option( 'mainwp_child_click_data' ); - } - } - } - - public function checkSignature( $signature, $timestamp, $data ) { - $key = get_option( 'mainwp_child_pubkey' ); - if ( ! $key ) { - return false; - } - $createSign = $this->createSignature( $key, $timestamp, $data ); - - return ( $signature === $createSign ); - } - - public function createSignature( $key, $timestamp, $data ) { - $datamd5 = md5( $timestamp . base64_encode( serialize( $data ) ) ); - $signature = md5( $key . $datamd5 ); - - return $signature; - } - - /** - * Whether the heatmap is requested to display or not - */ - public function displayHeatmap() { - return ( isset( $_REQUEST['heatmap'] ) && '1' === $_REQUEST['heatmap'] ); - /*return ( ( isset($_REQUEST['heatmap']) && $_REQUEST['heatmap'] == '1' ) && - ( isset($_REQUEST['signature']) && isset($_REQUEST['timestamp']) && isset($_REQUEST['data']) && - $this->checkSignature($_REQUEST['signature'], $_REQUEST['timestamp'], $_REQUEST['data']) ) - );*/ - } - - /** - * Add tracker Javascript - */ - public function trackerJs() { - if ( ! is_admin() ) { - wp_enqueue_script( 'jquery' ); - wp_enqueue_script( 'heatmapTracker', plugins_url( '/js/tracker.js', dirname( __FILE__ ) ) ); - if ( $this->displayHeatmap() ) { - wp_enqueue_script( 'heatmapJs', plugins_url( '/js/heatmap.js', dirname( __FILE__ ) ) ); - wp_enqueue_script( 'heatmapInit', plugins_url( '/js/heatmapinit.js', dirname( __FILE__ ) ) ); - } - add_action( 'wp_head', array( $this, 'trackerJsInline' ), 1 ); - } - } - - /** - * Add necessary inline tracker Javascript - */ - public function trackerJsInline() { - echo ''; - } - - /** - * Generate heatmap, print click data variable (wrap it on ) - * - * Available args: - * string $start Start date (d/m/Y) - * string $end End date (d/m/Y) - * string $browser Filter to only click by specified browser, see getBrowser method for list of supported browser name - * string $browserVersion The specific browser version to target at, could use some wildcard (for example: 7.*) - * string $platform Filter to only click by specified platform, see getBrowser method for list of supported platform name - * int $width Filter to width - * - * @param string $object_type Object type - * @param int|string $object_value Object value - * @param array $args Additional arguments - * - */ - public function generateHeatmap( $object_type, $object_value, $args ) { - global $wpdb; - $defaults = array( - 'start' => '', - 'end' => '', - 'browser' => 'all', - 'browserVersion' => 'all', - 'platform' => 'all', - 'width' => 0, - ); - $args = wp_parse_args( $args, $defaults ); - extract( $args ); - - $data = array(); - $data['object_type'] = $object_type; - $data['object_value'] = $object_value; - $data['start_date'] = $start; - $data['end_date'] = $end; - $data['browser'] = $browser; - $data['platform'] = $platform; - $data['width'] = $width; - - $url = $this->server . 'admin-ajax.php'; - $key = get_option( 'mainwp_child_pubkey' ); - $timestamp = time(); - $signature = $this->createSignature( $key, $timestamp, $data ); - - $params = array( - 'headers' => array( - 'Referer' => site_url(), - ), - 'body' => array( - 'timestamp' => $timestamp, - 'signature' => $signature, - 'data' => base64_encode( serialize( $data ) ), - 'action' => 'heatmapGetClickData', - ), - 'timeout' => 60, - ); - - if ( strpos( $url, 'https://' ) === 0 ) { - $params['sslverify'] = false; - } - - $request = wp_remote_post( $url, $params ); - - if ( is_array( $request ) ) { - $clicks = array(); - if (! empty($request['body']) ) { - if (preg_match('/(.*)<\/heatmap>/', $request['body'], $results) > 0) { - $result = $results[1]; - $clicks = json_decode($result); - } - } - $clickData = array(); - if ( is_array( $clicks ) ) { - foreach ($clicks as $click) { - $clickData[] = array( - 'x' => $click->x, - 'y' => $click->y, - 'w' => $click->w, - 'h' => $click->h, - ); - } - } - ?> - var heatmapClick = ; - var heatmapError = 0; - - var heatmapError = 1; - diff --git a/js/heatmap.js b/js/heatmap.js deleted file mode 100644 index b150216..0000000 --- a/js/heatmap.js +++ /dev/null @@ -1,362 +0,0 @@ -/* - * heatmap.js 1.0 - JavaScript Heatmap Library - * - * Copyright (c) 2011, Patrick Wied (http://www.patrick-wied.at) - * Dual-licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) - * and the Beerware (http://en.wikipedia.org/wiki/Beerware) license. - */ - -(function(w){ - // the heatmapFactory creates heatmap instances - var heatmapFactory = (function(){ - - // store object constructor - // a heatmap contains a store - // the store has to know about the heatmap in order to trigger heatmap updates when datapoints get added - function store(hmap){ - - var _ = { - // data is a two dimensional array - // a datapoint gets saved as data[point-x-value][point-y-value] - // the value at [point-x-value][point-y-value] is the occurrence of the datapoint - data: [], - // tight coupling of the heatmap object - heatmap: hmap - }; - // the max occurrence - the heatmaps radial gradient alpha transition is based on it - this.max = 0; - - this.get = function(key){ - return _[key]; - }, - this.set = function(key, value){ - _[key] = value; - }; - }; - - store.prototype = { - // function for adding datapoints to the store - // datapoints are usually defined by x and y but could also contain a third parameter which represents the occurrence - addDataPoint: function(x, y){ - if(x < 0 || y < 0) - return; - - var heatmap = this.get("heatmap"), - data = this.get("data"); - - if(!data[x]) data[x] = []; - if(!data[x][y]) data[x][y] = 1; - // if count parameter is set increment by count otherwise by 1 - data[x][y]+=(arguments.length<3)?1:arguments[2]; - - // do we have a new maximum? - if(this.max < data[x][y]){ - this.max = data[x][y]; - // max changed, we need to redraw all existing(lower) datapoints - heatmap.get("actx").clearRect(0,0,heatmap.get("width"),heatmap.get("height")); - for(var one in data) - for(var two in data[one]) - heatmap.drawAlpha(one, two, data[one][two]); - - // @TODO - // implement feature - // heatmap.drawLegend(); ? - return; - } - heatmap.drawAlpha(x, y, data[x][y]); - }, - setDataSet: function(obj){ - - this.max = obj.max; - var heatmap = this.get("heatmap"), - data = this.get("data"), - d = obj.data, - dlen = d.length; - // clear the heatmap before the data set gets drawn - heatmap.clear(); - - while(dlen--){ - var point = d[dlen]; - heatmap.drawAlpha(point.x, point.y, point.count); - if(!data[point.x]) data[point.x] = []; - if(!data[point.x][point.y]) data[point.x][point.y] = 1; - data[point.x][point.y]+=point.count; - } - // Add event after all done - // 10-22-2011 by Jeffri Hong - if ( typeof(obj.callback) == 'function' ) - obj.callback(); - }, - exportDataSet: function(){ - var data = this.get("data"); - var exportData = []; - for(var one in data){ - // jump over undefined indexes - if(one === undefined) - continue; - for(var two in data[one]){ - if(two === undefined) - continue; - // if both indexes are defined, push the values into the array - exportData.push({x: parseInt(one, 10), y: parseInt(two, 10), count: data[one][two]}); - } - } - - return exportData; - }, - generateRandomDataSet: function(points){ - var heatmap = this.get("heatmap"), - w = heatmap.get("width"), - h = heatmap.get("height"); - var randomset = {}, - max = Math.floor(Math.random()*1000+1); - randomset.max = max; - var data = []; - while(points--){ - data.push({x: Math.floor(Math.random()*w+1), y: Math.floor(Math.random()*h+1), count: Math.floor(Math.random()*max+1)}); - } - randomset.data = data; - this.setDataSet(randomset); - } - }; - - - // heatmap object constructor - function heatmap(config){ - // private variables - var _ = { - radiusIn : 20, - radiusOut : 40, - element : {}, - canvas : {}, - acanvas: {}, - ctx : {}, - actx : {}, - visible : true, - width : 0, - height : 0, - max : false, - gradient : false, - opacity: 180 - }; - // heatmap store containing the datapoints and information about the maximum - // accessible via instance.store - this.store = new store(this); - - this.get = function(key){ - return _[key]; - }, - this.set = function(key, value){ - _[key] = value; - }; - // configure the heatmap when an instance gets created - this.configure(config); - // and initialize it - this.init(); - }; - - // public functions - heatmap.prototype = { - configure: function(config){ - if(config.radius){ - var rout = config.radius, - rin = parseInt(rout/2); - } - this.set("radiusIn", rin || 15), - this.set("radiusOut", rout || 40), - this.set("element", (config.element instanceof Object)?config.element:document.getElementById(config.element)); - this.set("visible", config.visible); - this.set("max", config.max || false); - this.set("gradient", config.gradient || { 0.45: "rgb(0,0,255)", 0.55: "rgb(0,255,255)", 0.65: "rgb(0,255,0)", 0.95: "yellow", 1.0: "rgb(255,0,0)"}); // default is the common blue to red gradient - this.set("opacity", parseInt(255/(100/config.opacity), 10) || 180); - this.set("width", config.width || 0); - this.set("height", config.height || 0); - }, - init: function(){ - this.initColorPalette(); - var canvas = document.createElement("canvas"), - acanvas = document.createElement("canvas"), - element = this.get("element"); - this.set("canvas", canvas); - this.set("acanvas", acanvas); - canvas.width = acanvas.width = element.style.width.replace(/px/,"") || this.getWidth(element); - this.set("width", canvas.width); - canvas.height = acanvas.height = element.style.height.replace(/px/,"") || this.getHeight(element); - this.set("height", canvas.height); - canvas.style.position = acanvas.style.position = "absolute"; - canvas.style.top = acanvas.style.top = "0"; - canvas.style.left = acanvas.style.left = "0"; - canvas.style.zIndex = 1000000; - if(!this.get("visible")) - canvas.style.display = "none"; - - this.get("element").appendChild(canvas); - this.set("ctx", canvas.getContext("2d")); - this.set("actx", acanvas.getContext("2d")); - }, - initColorPalette: function(){ - - var canvas = document.createElement("canvas"); - canvas.width = "1"; - canvas.height = "256"; - var ctx = canvas.getContext("2d"); - var grad = ctx.createLinearGradient(0,0,1,256), - gradient = this.get("gradient"); - for(var x in gradient){ - grad.addColorStop(x, gradient[x]); - } - - ctx.fillStyle = grad; - ctx.fillRect(0,0,1,256); - - this.set("gradient", ctx.getImageData(0,0,1,256).data); - delete canvas; - delete grad; - delete ctx; - }, - getWidth: function(element){ - var width = element.offsetWidth; - if(element.style.paddingLeft) - width+=element.style.paddingLeft; - if(element.style.paddingRight) - width+=element.style.paddingRight; - - return width; - }, - getHeight: function(element){ - var height = element.offsetHeight; - if(element.style.paddingTop) - height+=element.style.paddingTop; - if(element.style.paddingBottom) - height+=element.style.paddingBottom; - - return height; - }, - colorize: function(x, y){ - // get the private variables - var width = this.get("width"), - radiusOut = this.get("radiusOut"), - height = this.get("height"), - actx = this.get("actx"), - ctx = this.get("ctx"); - - var x2 = radiusOut*2; - - if(x+x2>width) - x=width-x2; - if(x<0) - x=0; - if(y<0) - y=0; - if(y+x2>height) - y=height-x2; - // get the image data for the mouse movement area - var image = actx.getImageData(x,y,x2,x2), - // some performance tweaks - imageData = image.data, - length = imageData.length, - palette = this.get("gradient"), - opacity = this.get("opacity"); - // loop thru the area - for(var i=3; i < length; i+=4){ - - // [0] -> r, [1] -> g, [2] -> b, [3] -> alpha - var alpha = imageData[i], - offset = alpha*4; - - if(!offset) - continue; - - // we ve started with i=3 - // set the new r, g and b values - imageData[i-3]=palette[offset]; - imageData[i-2]=palette[offset+1]; - imageData[i-1]=palette[offset+2]; - // we want the heatmap to have a gradient from transparent to the colors - // as long as alpha is lower than the defined opacity (maximum), we'll use the alpha value - imageData[i] = (alpha < opacity)?alpha:opacity; - } - // the rgb data manipulation didn't affect the ImageData object(defined on the top) - // after the manipulation process we have to set the manipulated data to the ImageData object - image.data = imageData; - ctx.putImageData(image,x,y); - }, - drawAlpha: function(x, y, count){ - // storing the variables because they will be often used - var r1 = this.get("radiusIn"), - r2 = this.get("radiusOut"), - ctx = this.get("actx"), - max = this.get("max"), - // create a radial gradient with the defined parameters. we want to draw an alphamap - rgr = ctx.createRadialGradient(x,y,r1,x,y,r2), - xb = x-r2, yb = y-r2, mul = 2*r2; - // the center of the radial gradient has .1 alpha value - rgr.addColorStop(0, 'rgba(0,0,0,'+((count)?(count/this.store.max):'0.1')+')'); - // and it fades out to 0 - rgr.addColorStop(1, 'rgba(0,0,0,0)'); - // drawing the gradient - ctx.fillStyle = rgr; - ctx.fillRect(xb,yb,mul,mul); - // finally colorize the area - this.colorize(xb,yb); - - }, - toggleDisplay: function(){ - var visible = this.get("visible"), - canvas = this.get("canvas"); - - if(!visible) - canvas.style.display = "block"; - else - canvas.style.display = "none"; - - this.set("visible", !visible); - }, - // dataURL export - getImageData: function(){ - return this.get("canvas").toDataURL(); - }, - clear: function(){ - var w = this.get("width"), - h = this.get("height"); - this.store.set("data",[]); - // @TODO: reset stores max to 1 - //this.store.max = 1; - this.get("ctx").clearRect(0,0,w,h); - this.get("actx").clearRect(0,0,w,h); - } - }; - - return { - create: function(config){ - return new heatmap(config); - }, - util: { - mousePosition: function(ev){ - // this doesn't work right - // rather use - /* - // this = element to observe - var x = ev.pageX - this.offsetLeft; - var y = ev.pageY - this.offsetTop; - - */ - var x, y; - - if (ev.layerX) { // Firefox - x = ev.layerX; - y = ev.layerY; - } else if (ev.offsetX) { // Opera - x = ev.offsetX; - y = ev.offsetY; - } - if(typeof(x)=='undefined') - return; - - return [x,y]; - } - } - }; - })(); - w.h337 = w.heatmapFactory = heatmapFactory; -})(window); diff --git a/js/heatmapinit.js b/js/heatmapinit.js deleted file mode 100644 index 84cb9c1..0000000 --- a/js/heatmapinit.js +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Initiate heatmap object - */ - - - -jQuery(window).load(function(){ - if ( heatmapError == 0 ) - { - jQuery('body').append( '
Loading...
' ); - setTimeout(generate_heatmap, 1000); - } - else - { - jQuery('body').append( '
An error occured.
' ); - } -}); - - -function generate_heatmap() -{ - var hmap = h337.create({"element":document.body, "radius":15, "visible":true}); - var width = jQuery(document).width(); - var data = []; - for ( i in heatmapClick ) - { - data.push({ - x: ( heatmapClick[i].w-width > 0 ? heatmapClick[i].x - ( Math.floor(heatmapClick[i].w-width)/2 ) : heatmapClick[i].x ), - y: heatmapClick[i].y, - count: 1 - }); - } - var max = Math.floor(data.length/10); - hmap.store.setDataSet({ - max: ( max > 5 ? Math.floor(data.length/max) : 5 ), - data: data, - callback: function(){ - jQuery('#hmap_loading').fadeOut(500); - } - }); -} diff --git a/js/tracker.js b/js/tracker.js deleted file mode 100644 index 7b0eb0e..0000000 --- a/js/tracker.js +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Mouse click tracking - */ - -var trackerData = []; - -jQuery(document).ready(function($){ - - - $(document).click(function(e){ - var element = $(e.target).parents().map(getSelector).get().reverse().join(">"); - element += '>'+$(e.target).map(getSelector).get(); - var url = ( $(e.target).attr('href') ) ? $(e.target).attr('href') : $(e.target).attr('src'); - var title = $(e.target).attr('title'); - var alt = $(e.target).attr('alt'); - var text = ( $(e.target).text().length == $(e.target).html().length ) ? $(e.target).text().substring(0, 511) : ''; - trackerData.push({ - coord: e.pageX+','+e.pageY, - type: 'left', - viewport: $(window).width()+','+$(window).height(), - element: element, - url: url, - title: title, - alt: alt, - text: text - }); - }); - - $(window).unload(function(){ - sendTrackData(false); // Make sure to send track data before going off from page, set it synchronious - }); - - function getSelector() - { - var el_class = $(this).attr('class'); - var el_id = $(this).attr('id'); - var el_index = $(this).index(); - return this.tagName + ( el_id ? '#'+el_id : '' ) + - ( el_class ? '.'+el_class.match(/^\S+/) : '' ) + - ( el_index > 0 ? ':eq('+(el_index)+')' : '' ); - } - - function sendTrackData( sync ) - { - if ( trackerData.length < 1 ) - return; - $.ajax({ - data : { - data: trackerData, - action: 'heatmapSaveClick', - nonce: trackerNonce - }, - complete: function(){ - trackerData = []; - }, - async: ( sync ) ? false : true, - type: 'POST', - url: trackerAjaxUrl - }); - } - setInterval(function(){ sendTrackData(false); }, 10000); -}); diff --git a/mainwp-child.php b/mainwp-child.php index 2f01c8e..d377d7b 100644 --- a/mainwp-child.php +++ b/mainwp-child.php @@ -6,12 +6,8 @@ Author: MainWP Author URI: https://mainwp.com Text Domain: mainwp-child - Version: 4.0.2 + Version: 4.0.3 */ -//if ( ( isset( $_REQUEST['heatmap'] ) && '1' === $_REQUEST['heatmap'] ) || ( isset( $_REQUEST['mainwpsignature'] ) && ( ! empty( $_REQUEST['mainwpsignature'] ) ) ) ) { -// header( 'X-Frame-Options: ALLOWALL' ); -//} -//header('X-Frame-Options: GOFORIT'); include_once( ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'version.php' ); //Version information from wordpress define( 'MAINWP_DEBUG', FALSE ); diff --git a/readme.txt b/readme.txt index 3ffb301..3026c1a 100644 --- a/readme.txt +++ b/readme.txt @@ -7,7 +7,7 @@ Plugin URI: https://mainwp.com Requires at least: 3.6 Tested up to: 5.2.3 Requires PHP: 5.6 -Stable tag: 4.0.2 +Stable tag: 4.0.3 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -71,6 +71,11 @@ To see full documentation and FAQs please visit [MainWP Documentation](https://m == Changelog == += 4.0.3 - 10-1-19 = +* Added: 'mainwp_child_branding_init_options' filter for disabling custom branding +* Updated: support for the WPVulnDB API v3 +* Removed: unused code and files + = 4.0.2 - 9-6-19 = * Fixed: an issue incorrect backups count in the Client Reports system