function wp_statistics_shortcake() { // ShortCake support if loaded. if (function_exists('shortcode_ui_register_for_shortcode')) { $se_list = wp_statistics_searchengine_list(); $se_options = array('' => 'None'); foreach ($se_list as $se) { $se_options[$se['tag']] = $se['translated']; } shortcode_ui_register_for_shortcode('wpstatistics', array('label' => 'WP Statistics', 'listItemImage' => '<img src="' . plugin_dir_url(__FILE__) . 'assets/images/logo-250.png" width="128" height="128">', 'attrs' => array(array('label' => __('Statistic', 'wp_statistics'), 'attr' => 'stat', 'type' => 'select', 'description' => __('Select the statistic you wish to display.', 'wp_statistics'), 'value' => 'usersonline', 'options' => array('usersonline' => __('Users Online', 'wp_statistiscs'), 'visits' => __('Visits', 'wp_statistiscs'), 'visitors' => __('Visitors', 'wp_statistiscs'), 'pagevisits' => __('Page Visits', 'wp_statistiscs'), 'searches' => __('Searches', 'wp_statistiscs'), 'postcount' => __('Post Count', 'wp_statistiscs'), 'pagecount' => __('Page Count', 'wp_statistiscs'), 'commentcount' => __('Comment Count', 'wp_statistiscs'), 'spamcount' => __('Spam Count', 'wp_statistiscs'), 'usercount' => __('User Count', 'wp_statistiscs'), 'postaverage' => __('Post Average', 'wp_statistiscs'), 'commentaverage' => __('Comment Average', 'wp_statistiscs'), 'useraverage' => __('User Average', 'wp_statistiscs'), 'lpd' => __('Last Post Date', 'wp_statistiscs'))), array('label' => __('Time Frame', 'wp_statistics'), 'attr' => 'time', 'type' => 'url', 'description' => __('The time frame to get the statistic for, strtotime() (http://php.net/manual/en/datetime.formats.php) will be used to calculate it.', 'wp_statistics'), 'meta' => array('size' => '10')), array('label' => __('Search Provider', 'wp_statistics'), 'attr' => 'provider', 'type' => 'select', 'description' => __('The search provider to get statistics on.', 'wp_statistics'), 'options' => $se_options), array('label' => __('Number Format', 'wp_statistics'), 'attr' => 'format', 'type' => 'select', 'description' => __('The format to display numbers in: i18n, english, none.', 'wp_statistics'), 'value' => 'none', 'options' => array('none' => __('None', 'wp_statistics'), 'english' => __('English', 'wp_statistics'), 'i18n' => __('International', 'wp_statistics')))))); } }
<script type="text/javascript"> jQuery(document).ready(function(){ postboxes.add_postbox_toggles(pagenow); }); </script> <?php $search_engines = wp_statistics_searchengine_list(); $search_result['All'] = wp_statistics_searchword('all', 'total'); foreach ($search_engines as $key => $se) { $search_result[$key] = wp_statistics_searchword($key, 'total'); } if (array_key_exists('referred', $_GET)) { if ($_GET['referred'] != '') { $referred = $_GET['referred']; } else { $referred = 'All'; } } else { $referred = 'All'; } $total = $search_result[$referred]; ?> <div class="wrap"> <?php screen_icon('options-general'); ?> <h2><?php _e('Latest Search Words', 'wp_statistics'); ?> </h2> <ul class="subsubsub">
function wp_statistics_searchengine_regex($search_engine = 'all') { // Get a complete list of search engines $searchengine_list = wp_statistics_searchengine_list(); $search_query = ''; // Are we getting results for all search engines or a specific one? if (strtolower($search_engine) == 'all') { foreach ($searchengine_list as $se) { // The SQL pattern for a search engine may be an array if it has to handle multiple domains (like google.com and google.ca) or other factors. if (is_array($se['regexpattern'])) { foreach ($se['regexpattern'] as $subse) { $search_query .= "{$subse}|"; } } else { $search_query .= "{$se['regexpattern']}|"; } } // Trim off the last '|' for the loop above. $search_query = substr($search_query, 0, strlen($search_query) - 1); } else { // For just one? Ok, the SQL pattern for a search engine may be an array if it has to handle multiple domains (like google.com and google.ca) or other factors. if (is_array($searchengine_list[$search_engine]['regexpattern'])) { foreach ($searchengine_list[$search_engine]['regexpattern'] as $se) { $search_query .= "{$se}|"; } // Trim off the last '|' for the loop above. $search_query = substr($search_query, 0, strlen($search_query) - 1); } else { $search_query .= $searchengine_list[$search_engine]['regexpattern']; } } // Add the brackets and return return "({$search_query})"; }
public function Visitors() { global $wp_query, $WP_Statistics; // Get the pages or posts ID if it exists. if (is_object($wp_query)) { $this->current_page_id = $wp_query->get_queried_object_id(); } if ($this->get_option('use_honeypot') && $this->get_option('honeypot_postid') > 0 && $this->get_option('honeypot_postid') == $this->current_page_id && $this->current_page_id > 0) { $this->exclusion_match = TRUE; $this->exclusion_reason = "honeypot"; } // If we're a webcrawler or referral from ourselves or an excluded address don't record the visit. // The exception here is if we've matched a honey page, we want to lookup the user and flag them // as having been trapped in the honey pot for later exclusions. if ($this->exclusion_reason == 'honeypot' || !$this->exclusion_match) { // Check to see if we already have an entry in the database. if ($this->ip_hash != false) { $this->result = $this->db->get_row("SELECT * FROM {$this->tb_prefix}statistics_visitor WHERE `last_counter` = '{$this->Current_Date('Y-m-d')}' AND `ip` = '{$this->ip_hash}'"); } else { $this->result = $this->db->get_row("SELECT * FROM {$this->tb_prefix}statistics_visitor WHERE `last_counter` = '{$this->Current_Date('Y-m-d')}' AND `ip` = '{$this->ip}' AND `agent` = '{$this->agent['browser']}' AND `platform` = '{$this->agent['platform']}' AND `version` = '{$this->agent['version']}'"); } // Check to see if this is a visit to the honey pot page, flag it when we create the new entry. $honeypot = 0; if ($this->exclusion_reason == 'honeypot') { $honeypot = 1; } // If we don't create a new one, otherwise update the old one. if (!$this->result) { // If we've been told to store the entire user agent, do so. if ($this->get_option('store_ua') == true) { $ua = $_SERVER['HTTP_USER_AGENT']; } else { $ua = ''; } // Store the result. // We'd normally use the WordPress insert function, but since we may run in to a race condition where another hit to the site has already created a new entry in the database // for this IP address we want to do an "INSERT IGNORE" which WordPress doesn't support. $sqlstring = $this->db->prepare('INSERT IGNORE INTO ' . $this->tb_prefix . 'statistics_visitor (last_counter, referred, agent, platform, version, ip, location, UAString, hits, honeypot) VALUES ( %s, %s, %s, %s, %s, %s, %s, %s, 1, %s )', $this->Current_date('Y-m-d'), $this->get_Referred(), $this->agent['browser'], $this->agent['platform'], $this->agent['version'], $this->ip_hash ? $this->ip_hash : $this->ip, $this->location, $ua, $honeypot); $this->db->query($sqlstring); // Now parse the referrer and store the results in the search table if the database has been converted. // Also make sure we actually inserted a row on the INSERT IGNORE above or we'll create duplicate entries. if ($this->get_option('search_converted') && $this->db->insert_id) { $search_engines = wp_statistics_searchengine_list(); $referred = $this->get_Referred(); // Parse the URL in to it's component parts. $parts = parse_url($referred); // Loop through the SE list until we find which search engine matches. foreach ($search_engines as $key => $value) { $search_regex = wp_statistics_searchengine_regex($key); preg_match('/' . $search_regex . '/', $parts['host'], $matches); if (isset($matches[1])) { $data['last_counter'] = $this->Current_date('Y-m-d'); $data['engine'] = $key; $data['words'] = $WP_Statistics->Search_Engine_QueryString($referred); $data['host'] = $parts['host']; $data['visitor'] = $this->db->insert_id; if ($data['words'] == 'No search query found!') { $data['words'] = ''; } $this->db->insert($this->db->prefix . 'statistics_search', $data); } } } } else { // Normally we've done all of our exclusion matching during the class creation, however for the robot threshold is calculated here to avoid another call the database. if ($this->get_option('robot_threshold') > 0 && $this->result->hits + 1 > $this->get_option('robot_threshold')) { $this->exclusion_match = TRUE; $this->exclusion_reason = "robot_threshold"; } else { if ($this->result->honeypot) { $this->exclusion_match = TRUE; $this->exclusion_reason = "honeypot"; } else { $sqlstring = $this->db->prepare('UPDATE ' . $this->tb_prefix . 'statistics_visitor SET `hits` = `hits` + %d, `honeypot` = %d WHERE `ID` = %d', 1 - $honeypot, $honeypot, $this->result->ID); $this->db->query($sqlstring); } } } } if ($this->exclusion_match) { $this->RecordExclusion(); } }
function wp_statistics_summary_widget() { global $WP_Statistics; // If the widget isn't visible, don't output the stats as they take too much memory and CPU to compute for no reason. if (($is_visible = wp_statistics_is_wp_widget_visible('wp-statistics-summary-widget', 'dashboard')) !== true) { echo $is_visible; return; } // Load the css we use for the statistics pages. wp_statistics_load_widget_css_and_scripts(); // Include the hits chart widget, we're going to display the last 10 days only as the WordPress columns are kind of small to do much else. include_once dirname(__FILE__) . "/includes/log/widgets/summary.php"; wp_statistics_generate_summary_postbox_content(wp_statistics_searchengine_list()); }
<?php $selist = wp_statistics_searchengine_list(true); if ($wps_nonce_valid) { // We need to handle a change in the report schedule manually, so check to see it has been set. if (array_key_exists('wps_time_report', $_POST)) { // If the report has been changed, we need to update the schedule. if ($WP_Statistics->get_option('time_report') != $_POST['wps_time_report']) { // Remove the old schedule if it exists. if (wp_next_scheduled('report_hook')) { wp_unschedule_event(wp_next_scheduled('report_hook'), 'report_hook'); } // Setup the new schedule, we could just let this fall through and let the code in schedule.php deal with it // but that would require an extra page load to start the schedule so do it here instead. wp_schedule_event(time(), $_POST['wps_time_report'], 'report_hook'); } } $wps_option_list = array("wps_stats_report", "wps_time_report", "wps_send_report", "wps_content_report", "wps_email_list", "wps_browscap_report", "wps_geoip_report", "wps_prune_report", "wps_upgrade_report"); foreach ($wps_option_list as $option) { if (array_key_exists($option, $_POST)) { $value = $_POST[$option]; } else { $value = ''; } // WordPress escapes form data no matter what the setting of magic quotes is in PHP (http://www.theblog.ca/wordpress-addslashes-magic-quotes). $value = stripslashes($value); $new_option = str_replace("wps_", "", $option); $WP_Statistics->store_option($new_option, $value); } } ?>
/** * Outputs the options form on admin * * @param array $instance The widget options */ public function form($instance) { global $WP_Statistics; $widget_options = $WP_Statistics->get_option('widget'); ?> <p> <?php _e('Name', 'wp_statistics'); ?> :<br /> <input id="name_widget" name="name_widget" type="text" value="<?php echo $widget_options['name_widget']; ?> " /> </p> <?php _e('Items', 'wp_statistics'); ?> :</br /> <ul> <li><input type="checkbox" id="useronline_widget" name="useronline_widget" <?php checked('on', $widget_options['useronline_widget']); ?> /> <label for="useronline_widget"><?php _e('User Online', 'wp_statistics'); ?> </label></li> <li><input type="checkbox" id="tvisit_widget" name="tvisit_widget" <?php checked('on', $widget_options['tvisit_widget']); ?> /> <label for="tvisit_widget"><?php _e('Today Visit', 'wp_statistics'); ?> </label></li> <li><input type="checkbox" id="tvisitor_widget" name="tvisitor_widget" <?php checked('on', $widget_options['tvisitor_widget']); ?> /> <label for="tvisitor_widget"><?php _e('Today Visitor', 'wp_statistics'); ?> </label></li> <li><input type="checkbox" id="yvisit_widget" name="yvisit_widget" <?php checked('on', $widget_options['yvisit_widget']); ?> /> <label for="yvisit_widget"><?php _e('Yesterday visit', 'wp_statistics'); ?> </label></li> <li><input type="checkbox" id="yvisitor_widget" name="yvisitor_widget" <?php checked('on', $widget_options['yvisitor_widget']); ?> /> <label for="yvisitor_widget"><?php _e('Yesterday Visitor', 'wp_statistics'); ?> </label></li> <li><input type="checkbox" id="wvisit_widget" name="wvisit_widget" <?php checked('on', $widget_options['wvisit_widget']); ?> /> <label for="wvisit_widget"><?php _e('Week Visit', 'wp_statistics'); ?> </label></li> <li><input type="checkbox" id="mvisit_widget" name="mvisit_widget" <?php checked('on', $widget_options['mvisit_widget']); ?> /> <label for="mvisit_widget"><?php _e('Month Visit', 'wp_statistics'); ?> </label></li> <li><input type="checkbox" id="ysvisit_widget" name="ysvisit_widget" <?php checked('on', $widget_options['ysvisit_widget']); ?> /> <label for="ysvisit_widget"><?php _e('Years Visit', 'wp_statistics'); ?> </label></li> <li><input type="checkbox" id="ttvisit_widget" name="ttvisit_widget" <?php checked('on', $widget_options['ttvisit_widget']); ?> /> <label for="ttvisit_widget"><?php _e('Total Visit', 'wp_statistics'); ?> </label></li> <li><input type="checkbox" id="ttvisitor_widget" name="ttvisitor_widget" <?php checked('on', $widget_options['ttvisitor_widget']); ?> /> <label for="ttvisitor_widget"><?php _e('Total Visitor', 'wp_statistics'); ?> </label></li> <li><input type="checkbox" id="tpviews_widget" name="tpviews_widget" <?php checked('on', $widget_options['tpviews_widget']); ?> /> <label for="tpviews_widget"><?php _e('Total Page Views', 'wp_statistics'); ?> </label></li> <li><input type="checkbox" id="ser_widget" class="ser_widget" name="ser_widget" <?php checked('on', $widget_options['ser_widget']); ?> /> <label for="ser_widget"><?php _e('Search Engine Referred', 'wp_statistics'); ?> </label></li> <p id="ser_option" style="<?php if (!$widget_options['ser_widget']) { echo "display: none;"; } ?> "> <?php _e('Select type of search engine', 'wp_statistics'); ?> :<br /> <?php $search_engines = wp_statistics_searchengine_list(); foreach ($search_engines as $se) { echo ' <input type="radio" id="select_' . $se['tag'] . '" name="select_se" value="' . $se['tag'] . '" '; checked($se['tag'], $widget_options['select_se']); echo "/>\n"; echo ' <label for="' . $se['name'] . '">' . $se['translated'] . "</label>\n"; echo "\n"; } ?> <input type="radio" id="select_all" name="select_se" value="all" <?php checked('all', $widget_options['select_se']); ?> /> <label for="select_all"><?php _e('All', 'wp_statistics'); ?> </label> </p> <li><input type="checkbox" id="tp_widget" name="tp_widget" <?php checked('on', $widget_options['tp_widget']); ?> /> <label for="tp_widget"><?php _e('Total Posts', 'wp_statistics'); ?> </label></li> <li><input type="checkbox" id="tpg_widget" name="tpg_widget" <?php checked('on', $widget_options['tpg_widget']); ?> /> <label for="tpg_widget"><?php _e('Total Pages', 'wp_statistics'); ?> </label></li> <li><input type="checkbox" id="tc_widget" name="tc_widget" <?php checked('on', $widget_options['tc_widget']); ?> /> <label for="tc_widget"><?php _e('Total Comments', 'wp_statistics'); ?> </label></li> <li><input type="checkbox" id="ts_widget" name="ts_widget" <?php checked('on', $widget_options['ts_widget']); ?> /> <label for="ts_widget"><?php _e('Total Spams', 'wp_statistics'); ?> </label></li> <li><input type="checkbox" id="tu_widget" name="tu_widget" <?php checked('on', $widget_options['tu_widget']); ?> /> <label for="tu_widget"><?php _e('Total Users', 'wp_statistics'); ?> </label></li> <li><input type="checkbox" id="ap_widget" name="ap_widget" <?php checked('on', $widget_options['ap_widget']); ?> /> <label for="ap_widget"><?php _e('Average Posts', 'wp_statistics'); ?> </label></li> <li><input type="checkbox" id="ac_widget" name="ac_widget" <?php checked('on', $widget_options['ac_widget']); ?> /> <label for="ac_widget"><?php _e('Average Comments', 'wp_statistics'); ?> </label></li> <li><input type="checkbox" id="au_widget" name="au_widget" <?php checked('on', $widget_options['au_widget']); ?> /> <label for="au_widget"><?php _e('Average Users', 'wp_statistics'); ?> </label></li> <li><input type="checkbox" id="lpd_widget" class="lpd_widget" name="lpd_widget" <?php checked('on', $widget_options['lpd_widget']); ?> /> <label for="lpd_widget"><?php _e('Last Post Date', 'wp_statistics'); ?> </label></li> </ul> <input type="hidden" id="wp_statistics_control_widget_submit" name="wp_statistics_control_widget_submit" value="1" /> <?php }
public function Search_Engine_QueryString($url = false) { // If no URL was passed in, get the current referrer for the session. if (!$url) { $url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false; } // If there is no URL and no referrer, always return false. if ($url == false) { return false; } // Parse the URL in to it's component parts. $parts = parse_url($url); // Check to see if there is a query component in the URL (everything after the ?). If there isn't one // set an empty array so we don't get errors later. if (array_key_exists('query', $parts)) { parse_str($parts['query'], $query); } else { $query = array(); } // Get the list of search engines we currently support. $search_engines = wp_statistics_searchengine_list(); // Loop through the SE list until we find which search engine matches. foreach ($search_engines as $key => $value) { $search_regex = wp_statistics_searchengine_regex($key); preg_match('/' . $search_regex . '/', $parts['host'], $matches); if (isset($matches[1])) { // Check to see if the query key the SE uses exists in the query part of the URL. if (array_key_exists($search_engines[$key]['querykey'], $query)) { $words = strip_tags($query[$search_engines[$key]['querykey']]); } else { $words = ''; } // If no words were found, return a pleasant default. if ($words == '') { $words = 'No search query found!'; } return $words; } } // We should never actually get to this point, but let's make sure we return something // just in case something goes terribly wrong. return 'No search query found!'; }
if (array_key_exists('wps_historical_visitors', $_POST)) { $result = $wpdb->update($wp_prefix . "statistics_historical", array('value' => $_POST['wps_historical_visitors']), array('category' => 'visitors')); if ($result == 0) { $result = $wpdb->insert($wp_prefix . "statistics_historical", array('value' => $_POST['wps_historical_visitors'], 'category' => 'visitors', 'page_id' => -1, 'uri' => '-1')); } } if (array_key_exists('wps_historical_visits', $_POST)) { $result = $wpdb->update($wp_prefix . "statistics_historical", array('value' => $_POST['wps_historical_visits']), array('category' => 'visits')); if ($result == 0) { $result = $wpdb->insert($wp_prefix . "statistics_historical", array('value' => $_POST['wps_historical_visits'], 'category' => 'visits', 'page_id' => -2, 'uri' => '-2')); } } } if (array_key_exists('search', $_GET)) { // Make sure we get all the search engines, even the ones the disabled ones. $se_list = wp_statistics_searchengine_list(); $total = 0; $limitsize = 10000; foreach ($se_list as $key => $se) { $sql = wp_statistics_searchengine_query($key); $rowcount = $wpdb->get_var("SELECT count(*) FROM `{$wpdb->prefix}statistics_visitor` WHERE {$sql}"); $offset = 0; while ($rowcount > 0) { $result = $wpdb->get_results("SELECT * FROM `{$wpdb->prefix}statistics_visitor` WHERE {$sql} LIMIT {$offset}, {$limitsize}"); foreach ($result as $row) { $parts = parse_url($row->referred); $data['last_counter'] = $row->last_counter; $data['engine'] = $key; $data['host'] = $parts['host']; $data['words'] = $WP_Statistics->Search_Engine_QueryString($row->referred); $data['visitor'] = $row->ID;
function wp_statistics_get_widget_contents_callback() { global $WP_Statistics, $wpdb; // this is how you get access to the database $widgets = array('about', 'browsers', 'map', 'countries', 'hits', 'hitsmap', 'page', 'pages', 'quickstats', 'recent', 'referring', 'search', 'summary', 'top.visitors', 'words'); $view_cap = wp_statistics_validate_capability($WP_Statistics->get_option('read_capability', 'manage_options')); if (current_user_can($view_cap)) { $widget = ''; if (array_key_exists('widget', $_POST)) { // Get the widget we're going to display. if (in_array($_POST['widget'], $widgets)) { $widget = $_POST['widget']; } } if ('map' == $widget || 'hitsmap' == $widget) { if ($WP_Statistics->get_option('map_type') == 'jqvmap') { $widget = 'jqv.map'; } else { $widget = 'google.map'; } } if ('' == $widget) { _e('No matching widget found!', 'wp_statistics'); wp_die(); } $ISOCountryCode = $WP_Statistics->get_country_codes(); $search_engines = wp_statistics_searchengine_list(); require $WP_Statistics->plugin_dir . '/includes/log/widgets/' . $widget . '.php'; switch ($widget) { case 'summary': wp_statistics_generate_summary_postbox_content($search_engines); break; case 'quickstats': wp_statistics_generate_quickstats_postbox_content($search_engines); break; case 'browsers': wp_statistics_generate_browsers_postbox_content(); break; case 'referring': wp_statistics_generate_referring_postbox_content(); break; case 'countries': wp_statistics_generate_countries_postbox_content($ISOCountryCode); break; case 'jqv.map': case 'google.map': wp_statistics_generate_map_postbox_content($ISOCountryCode); break; case 'hits': wp_statistics_generate_hits_postbox_content(); break; case 'search': wp_statistics_generate_search_postbox_content($search_engines); break; case 'words': wp_statistics_generate_words_postbox_content($ISOCountryCode); break; case 'page': $pageid = (int) $_POST['page-id']; wp_statistics_generate_page_postbox_content(null, $pageid); break; case 'pages': list($total, $uris) = wp_statistics_get_top_pages(); wp_statistics_generate_pages_postbox_content($total, $uris); break; case 'recent': wp_statistics_generate_recent_postbox_content($ISOCountryCode); break; case 'top.visitors': wp_statistics_generate_top_visitors_postbox_content($ISOCountryCode); break; case 'about': wp_statistics_generate_about_postbox_content($ISOCountryCode); break; default: _e('ERROR: Widget not found!', 'wp_statistics'); } } else { _e('Access denied!', 'wp_statistics'); } wp_die(); // this is required to terminate immediately and return a proper response }