function add_referer() { global $single, $post_meta_cache, $wp_post_id, $wp_id, $blog_charset, $siteurl; if ($single) { if (isset($_SERVER["HTTP_REFERER"])) { $url = $_SERVER["HTTP_REFERER"]; if (not_excluded($url)) { if ($referer = fopen($url, "rb")) { $page = ''; while (!feof($referer)) { $page .= fread($referer, 8192); } fclose($referer); $matched = false; $page = mb_conv($page, $blog_charset, "auto"); if (preg_match_all("/<a\\s[^>]*?href=[\"\\']([^\"\\']*?)[\"\\'][^>]*>/", $page, $matches, PREG_PATTERN_ORDER)) { foreach ($matches[1] as $match) { if (strstr($match, $siteurl)) { $matched = true; } } } if (!$matched) { return; } preg_match("/<title>(.+)<\\/title>/is", $page, $title); $title = $title[1]; } if (!$title) { preg_match("/^(http:\\/\\/)?([^\\/]+)/i", $url, $matches); $host = $matches[2]; preg_match("/[^\\.\\/]+\\.[^\\.\\/]+\$/", $host, $matches); $title = $matches[0]; } $new_entry = addslashes($title . ":!-!:" . $url); add_post_meta($wp_post_id, 'wp-refer', $new_entry); $post_meta_cache[$wp_id][$wp_post_id]['wp-refer'][] = $new_entry; } } } }
function add_referer() { if (!empty($GLOBALS['single'])) { if (isset($_SERVER['HTTP_REFERER'])) { $url = $_SERVER['HTTP_REFERER']; if (not_excluded($url)) { require_once XOOPS_ROOT_PATH . '/class/snoopy.php'; $snoopy = new Snoopy(); if ($snoopy->fetch($url)) { $page = $snoopy->results; $matched = false; $page = mb_conv($page, $GLOBALS['blog_charset'], 'auto'); if (preg_match_all('/<a\\s[^>]*?href=[\\"\']([^\\"\']*?)[\\"\'][^>]*>/', $page, $matches, PREG_PATTERN_ORDER)) { foreach ($matches[1] as $match) { if (strstr($match, wp_siteurl())) { $matched = true; } } } if (!$matched) { return; } preg_match('/<title>(.+)<\\/title>/is', $page, $title); $title = $title[1]; if (!$title) { preg_match('/^(http:\\/\\/)?([^\\/]+)/i', $url, $matches); $host = $matches[2]; preg_match('/[^\\.\\/]+\\.[^\\.\\/]+$/', $host, $matches); $title = $matches[0]; } $new_entry = addslashes($title . ":!-!:" . $url); add_post_meta($GLOBALS['wp_post_id'], 'wp-refer', $new_entry); $GLOBALS['post_meta_cache'][wp_id()][$GLOBALS['wp_post_id']]['wp-refer'][] = $new_entry; } } } } }
/** * Returns a table mapping country codes to page views from the country in each row, for the specified time range. * range is half inclusive : [). * * $site_id site id to work on, or false for all sites, or true for current site in options table. (see not_excluded() doc). * $is_unix_time true if the start and end times are unix time, false for mysql datetime * $start_time timestamp of start time * $end_time timestamp of end time. */ function fs_get_views_per_country_range($site_id, $is_unix_time, $start_time, $end_time) { $fsdb =& fs_get_db_conn(); $hits = fs_hits_table(); $ua = fs_useragents_table(); $archive_countries = fs_archive_countries(); $ranges = fs_archive_ranges(); $not_excluded = not_excluded(); $valid_country_code = "`country_code` IS NOT NULL AND `country_code` != '0'"; if (fs_mysql_newer_than("4.1.14")) { $from_site = fs_get_site_id_query($site_id); $timestamp_between = fs_timestamp_between($is_unix_time, $start_time, $end_time); $select1 = "SELECT `site_id`,`country_code`, count(`country_code`) c\n\t \t\t\tFROM `{$hits}` h, `{$ua}` ua \n\t \t\t\tWHERE h.useragent_id = ua.id AND {$not_excluded} AND {$timestamp_between} AND {$valid_country_code}\n\t \t\t\tGROUP BY `site_id` , `country_code`"; $timerange_between = fs_time_range_between($is_unix_time, $start_time, $end_time); $select2 = "SELECT `site_id`,`country_code` ,`views` AS c FROM `{$archive_countries}` d, `{$ranges}` r " . "WHERE d.range_id = r.range_id AND {$from_site} AND {$timerange_between} AND {$valid_country_code}"; $sql = "SELECT `country_code`, sum( u.c ) c " . "FROM ({$select1} UNION ALL {$select2})\n\t\t\t\t`u` GROUP BY `site_id` , `country_code`\n\t\t\t\tORDER BY c DESC"; } else { $sql = "SELECT `country_code`, count(`country_code`) c\n\t\t\t\t\t\tFROM `{$hits}` h,`{$ua}` ua\n\t\t\t\t\t\tWHERE ua.id = h.useragent_id AND \n\t\t\t\t\t\t{$not_excluded} AND {$valid_country_code}"; $sql .= "AND " . fs_timestamp_between($is_unix_time, $start_time, $end_time); $sql .= " GROUP BY `country_code` ORDER BY c DESC"; } return $fsdb->get_results($sql); }