public function counterize_feed_most_used_browsers($number = 10, $header_override = '')
 {
     global $wpdb;
     $number = $wpdb->prepare("%d", $number);
     $sql = "SELECT " . " \tSUM( `count` ) AS `count`, " . " \tCONCAT( CONCAT( `browserName`, ' ' ), `browserVersion` ) AS `label`, " . " \t`browserCode` AS `code`, " . " \t`browserURL` AS `url` " . " FROM `" . counterize_agentsTable() . "`" . " GROUP BY `label` " . " ORDER BY `count` DESC " . " LIMIT {$number}";
     $rows = $wpdb->get_results($sql);
     $title = __('Most used browsers', COUNTERIZE_PLUGIN_BROWSERS_TD);
     if (!empty($header_override)) {
         $title = $header_override;
     }
     $feed = new CounterizeFeed(__('Most used browsers', COUNTERIZE_PLUGIN_BROWSERS_TD), __('Browsers', COUNTERIZE_PLUGIN_BROWSERS_TD));
     foreach ($rows as $row) {
         $src = counterize_get_image_url($row->code);
         $name = $row->label;
         if (empty($row->code) || $row->code == ' ' || $row->code == 'unknown') {
             $label = __('Unknown', COUNTERIZE_PLUGIN_BROWSERS_TD);
         } else {
             $label = $name;
         }
         if (!empty($src)) {
             $img = new CounterizeFeedImg($src, $label, $label, 'browsericon');
             $feed->add_item_4($row->count, $label, $row->url, $img);
         } else {
             $feed->add_item_3($row->count, $label, $row->url);
         }
         unset($src, $name, $label);
     }
     unset($rows, $sql);
     $feed->refresh_percentages();
     return $feed;
 }
 public function counterize_feed_most_popular_posts24hrs($number = 10, $tn_width = 50, $tn_height = 50, $header_override = '')
 {
     global $wpdb;
     $onedayago = date('Y-m-d H:i:s', time() - 86400);
     $number = $wpdb->prepare("%d", $number);
     $sql = "SELECT COUNT( l.`id` ) AS `count`, c.`postID`, c.`url` AS url, w.`post_title` AS label " . " FROM `" . counterize_logTable() . "` l, `" . counterize_pageTable() . "` c, `" . $wpdb->posts . "` w " . " WHERE l.`pageID` = c.`pageID` " . " AND c.`postID` = w.`ID` " . " AND l.`timestamp` >= '{$onedayago}'" . " GROUP BY c.`postID` " . " ORDER BY `count` DESC " . " LIMIT {$number}";
     $rows = $wpdb->get_results($sql);
     $title = __('Most popular posts/pages for the last 24 hours', COUNTERIZE_PLUGIN_PAGES_TD);
     if (!empty($header_override)) {
         $title = $header_override;
     }
     $feed = new CounterizeFeed($title, __('Posts/pages', COUNTERIZE_PLUGIN_PAGES_TD));
     foreach ($rows as $row) {
         $label = trim(stripslashes($row->label));
         if (function_exists('has_post_thumbnail') && has_post_thumbnail($row->postID)) {
             $thumbnail_id = get_post_thumbnail_id($row->postID);
             $thumbnail_arr = wp_get_attachment_image_src($thumbnail_id, array($tn_width, $tn_height));
             $thumbnail_src = $thumbnail_arr[0];
             $img = new CounterizeFeedImg($thumbnail_src, $label, sprintf(__('Click here to view the post "%s"', COUNTERIZE_PLUGIN_PAGES_TD), $row->label), 'counterize_thumb', $tn_width, $tn_height);
             $feed->add_item_4($row->count, $label, $row->url, $img);
             unset($thumbnail_id, $thumbnail_arr, $thumbnail_src);
         } else {
             $feed->add_item_3($row->count, $label, $row->url);
         }
         unset($label);
     }
     unset($rows, $sql, $onedayago);
     $feed->refresh_percentages();
     return $feed;
 }
 public function counterize_feed_hourly_stats($only_today = false, $header_override = '')
 {
     global $wpdb;
     $onedayago = date('Y-m-d H:i:s', time() - 86400);
     $sql = "SELECT " . " \tHOUR( `timestamp` ) AS `label`, " . " \tCOUNT( 1 ) AS `count` " . " FROM `" . counterize_logTable() . "` ";
     if ($only_today) {
         $sql .= " WHERE `timestamp` >= '{$onedayago}'";
     }
     $sql .= " GROUP BY `label` ";
     $rows = $wpdb->get_results($sql);
     if ($only_today) {
         $title = __('Hourly hits for the last 24 hours', COUNTERIZE_PLUGIN_TRAFFIC_TD);
         if (!empty($header_override)) {
             $title = $header_override;
         }
         $feed = new CounterizeFeed($title, __('Hour', COUNTERIZE_PLUGIN_TRAFFIC_TD));
     } else {
         $title = __('Hits based on hour of day', COUNTERIZE_PLUGIN_TRAFFIC_TD);
         if (!empty($header_override)) {
             $title = $header_override;
         }
         $feed = new CounterizeFeed($title, __('Hour', COUNTERIZE_PLUGIN_TRAFFIC_TD));
     }
     foreach ($rows as $row) {
         $feed->add_item_2($row->count, $row->label);
     }
     unset($rows, $sql);
     $feed->refresh_percentages();
     return $feed;
 }
 public function counterize_feed_most_searched_keywords24hrs($number = 10, $header_override = '')
 {
     global $wpdb;
     $number = $wpdb->prepare("%d", $number);
     $onedayago = date('Y-m-d H:i:s', time() - 86400);
     $sql = "SELECT COUNT( 1 ) AS `count`, k.keyword AS `label` " . " FROM " . counterize_keywordTable() . " k, " . counterize_logTable() . " l, " . counterize_refererTable() . " r " . " WHERE r.`refererID` = l.`refererID` " . " AND r.`keywordID` = k.`keywordID` " . " AND k.`keywordID` <> 1 " . " AND l.`timestamp` >= '{$onedayago}' " . " GROUP BY k.`keyword` " . " ORDER BY `count` DESC " . " LIMIT {$number}";
     $rows = $wpdb->get_results($sql);
     $title = __('Most searched keywords for the last 24 hours', COUNTERIZE_PLUGIN_KEYWORDS_TD);
     if (!empty($header_override)) {
         $title = $header_override;
     }
     $feed = new CounterizeFeed($title, __('Keywords', COUNTERIZE_PLUGIN_KEYWORDS_TD));
     foreach ($rows as $row) {
         $feed->add_item_2($row->count, $row->label);
     }
     unset($rows, $sqm, $onedayago);
     $feed->refresh_percentages();
     return $feed;
 }
 public function counterize_feed_most_active_hosts24hrs($number = 10, $header_override = '')
 {
     global $wpdb;
     $onedayago = date('Y-m-d H:i:s', time() - 86400);
     $number = $wpdb->prepare("%d", $number);
     $geoip = $wpdb->prepare("%s", counterize_get_option('geoip'));
     $sql = "SELECT COUNT(`IP`) AS `count`, `IP` AS `label`, CONCAT( {$geoip}, `IP` ) AS `url` " . " FROM `" . counterize_logTable() . "`" . " WHERE `IP` <> 'unavailable' " . " AND `timestamp` >= '{$onedayago}'" . " GROUP BY `IP` " . " ORDER BY `count` DESC " . " LIMIT {$number}";
     $rows = $wpdb->get_results($sql);
     $title = __('Most active hosts for the last 24 hours', COUNTERIZE_PLUGIN_IP_TD);
     if (!empty($header_override)) {
         $title = $header_override;
     }
     $feed = new CounterizeFeed($title, __('Hosts', COUNTERIZE_PLUGIN_IP_TD));
     foreach ($rows as $row) {
         $feed->add_item_3($row->count, $this->gethost($row->label), $row->url);
     }
     unset($rows, $sql, $onedayago, $geoip);
     $feed->refresh_percentages();
     return $feed;
 }
 public function counterize_feed_exit_pages24hrs($number = 10, $header_override = '')
 {
     global $wpdb;
     $number = $wpdb->prepare("%d", $number);
     $onedayago = date('Y-m-d H:i:s', time() - 86400);
     $sql = "SELECT COUNT( m.`id` ) AS `count`, p.`url` AS url, p.`url` AS label " . " FROM `" . counterize_logTable() . "` m, `" . counterize_pageTable() . "` p " . " WHERE m.`pageID` = p.`pageID`" . " AND m.`outlinkID` > 0 " . " AND m.`timestamp` >= '{$onedayago}'" . " GROUP BY p.`url` " . " ORDER BY `count` DESC " . " LIMIT {$number}";
     $rows = $wpdb->get_results($sql);
     $title = __('Exit pages of the last 24 hours', COUNTERIZE_PLUGIN_OUTLINKS_TD);
     if (!empty($header_override)) {
         $title = $header_override;
     }
     $feed = new CounterizeFeed($title, __('URL', COUNTERIZE_PLUGIN_OUTLINKS_TD));
     foreach ($rows as $row) {
         $feed->add_item_3($row->count, $row->label, $row->url);
     }
     unset($rows, $sql);
     $feed->refresh_percentages();
     return $feed;
 }
 public function counterize_feed_most_seen_referers_domains24hrs($number = 10, $header_override = '')
 {
     global $wpdb;
     $number = $wpdb->prepare("%d", $number);
     $onedayago = date('Y-m-d H:i:s', time() - 86400);
     $sql = 'SELECT COUNT( m.id ) AS `count`, SUBSTRING_INDEX( SUBSTRING_INDEX( TRIM( LEADING "https://" FROM TRIM( LEADING "http://" FROM TRIM( r.`name` ) ) ), "/", 1 ), ":", 1 ) AS `domain` ' . " FROM `" . counterize_logTable() . "` m, `" . counterize_refererTable() . "` r " . " WHERE m.`refererID` = r.`refererID` " . " AND r.`name` <> 'unknown' " . " AND r.`name` NOT LIKE " . $wpdb->prepare("%s", get_option("home") . "%%") . " " . " AND r.`name` NOT LIKE " . $wpdb->prepare("%s", get_option("siteurl") . "%%") . " " . " AND m.`timestamp` >= '{$onedayago}'" . " GROUP BY `domain` " . " ORDER BY `count` DESC " . " LIMIT {$number}";
     $rows = $wpdb->get_results($sql);
     $title = __('Most seen refering domains for the last 24 hours', COUNTERIZE_PLUGIN_REFERERS_TD);
     if (!empty($header_override)) {
         $title = $header_override;
     }
     $feed = new CounterizeFeed($title, __('Domains', COUNTERIZE_PLUGIN_REFERERS_TD));
     foreach ($rows as $row) {
         $feed->add_item_3($row->count, $row->domain, "http://{$row->domain}");
     }
     unset($rows, $sql, $onedayago);
     $feed->refresh_percentages();
     return $feed;
 }
 public function counterize_feed_most_visiting_countries24hrs($number = 10, $header_override = '')
 {
     global $wpdb;
     $number = $wpdb->prepare("%d", $number);
     $onedayago = date('Y-m-d H:i:s', time() - 86400);
     $sql = "SELECT COUNT( m.id ) AS `count`, c.code, c.code AS label " . " FROM `" . counterize_logTable() . "` m, `" . counterize_countryTable() . "` c " . " WHERE m.countryID = c.countryID" . " AND m.timestamp >= '{$onedayago}'" . " GROUP BY c.code " . " ORDER BY `count` DESC " . " LIMIT {$number}";
     $rows = $wpdb->get_results($sql);
     $title = __('Most visiting countries for the last 24 hours', COUNTERIZE_PLUGIN_COUNTRIES_TD);
     if (!empty($header_override)) {
         $title = $header_override;
     }
     $feed = new CounterizeFeed($title, __('Countries', COUNTERIZE_PLUGIN_COUNTRIES_TD));
     foreach ($rows as $row) {
         $src = counterize_get_flag_url($row->code);
         $name = counterize_get_countryname($row->code);
         if (empty($row->code) || $row->code == ' ' || $row->code == '00') {
             $label = __('unknown', COUNTERIZE_PLUGIN_COUNTRIES_TD);
         } else {
             $label = $name;
         }
         if (!empty($src)) {
             $img = new CounterizeFeedImg($src, sprintf(__('National flag of %s', COUNTERIZE_PLUGIN_COUNTRIES_TD), $name), counterize_get_countryname($row->code) . " ({$row->code})", 'countryflag');
             $feed->add_item_4($row->count, $label, '', $img);
         } else {
             $feed->add_item_2($row->count, $label);
         }
         unset($src, $name, $label);
     }
     unset($rows, $sql);
     $feed->refresh_percentages();
     return $feed;
 }