Ejemplo n.º 1
0
function iri_StatPress_Vars($body)
{
    global $wpdb;
    $table_name = $wpdb->prefix . "statpress";
    $normallimit = " and (statuscode!='404' or statuscode is null)";
    $today = gmdate('Ymd', current_time('timestamp'));
    $yesterday = gmdate('Ymd', current_time('timestamp') - 86400);
    //今天来访者数量
    if (strpos(strtolower($body), "%visits%") !== FALSE) {
        $qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as pageview FROM {$table_name} WHERE date = {$today} and spider='' and feed=''{$normallimit};");
        $body = str_replace("%visits%", $qry[0]->pageview, $body);
    }
    //昨天来访者数量
    if (strpos(strtolower($body), "%yesterdayvisits%") !== FALSE) {
        $body = str_replace("%yesterdayvisits%", get_option("statpress_archive_yesterday_visitors"), $body);
    }
    //来访者数量总计
    if (strpos(strtolower($body), "%totalvisits%") !== FALSE) {
        $qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as pageview FROM {$table_name} WHERE spider='' and feed=''{$normallimit};");
        $body = str_replace("%totalvisits%", $qry[0]->pageview, $body);
    }
    //今天页面访问数量
    if (strpos(strtolower($body), "%pagevisits%") !== FALSE) {
        $qry = $wpdb->get_results("SELECT count(*) as pageview FROM {$table_name} WHERE spider='' and feed='' and date={$today}{$normallimit};");
        $body = str_replace("%pagevisits%", $qry[0]->pageview, $body);
    }
    //昨天页面访问数量总计
    if (strpos(strtolower($body), "%yesterdaypagevisits%") !== FALSE) {
        $qry = $wpdb->get_results("SELECT count(*) as pageview FROM {$table_name} WHERE spider='' and feed='' and date = {$yesterday}{$normallimit};");
        $body = str_replace("%yesterdaypagevisits%", get_option("statpress_archive_yesterday_pageviews"), $body);
    }
    //页面访问数量总计
    if (strpos(strtolower($body), "%totalpagevisits%") !== FALSE) {
        $qry = $wpdb->get_results("SELECT count(*) as pageview FROM {$table_name} WHERE spider='' and feed=''{$normallimit};");
        $body = str_replace("%totalpagevisits%", $qry[0]->pageview, $body);
    }
    //当前页面被访问次数
    if (strpos(strtolower($body), "%thistotalvisits%") !== FALSE) {
        $qry = $wpdb->get_results("SELECT count(*) as pageview FROM {$table_name} WHERE spider='' and feed='' AND urlrequested='" . iri_StatPress_URL() . "'{$normallimit};");
        $body = str_replace("%thistotalvisits%", $qry[0]->pageview, $body);
    }
    //统计起始日期
    if (strpos(strtolower($body), "%since%") !== FALSE) {
        $body = str_replace("%since%", get_option("statpress_date_first_sets"), $body);
    }
    //操作系统(当前访问者)
    if (strpos(strtolower($body), "%os%") !== FALSE) {
        $userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
        $os = iriGetOS($userAgent);
        $body = str_replace("%os%", $os, $body);
    }
    //浏览器(当前访问者)
    if (strpos(strtolower($body), "%browser%") !== FALSE) {
        $browser = iriGetBrowser($userAgent);
        $body = str_replace("%browser%", $browser, $body);
    }
    //IP地址(当前访问者)
    if (strpos(strtolower($body), "%ip%") !== FALSE) {
        $ipAddress = $_SERVER['REMOTE_ADDR'];
        $body = str_replace("%ip%", $ipAddress, $body);
    }
    //FROM何地(当前访问者)
    if (strpos(strtolower($body), "%comefrom%") !== FALSE) {
        $comeFrom = iriDomain($_SERVER['REMOTE_ADDR']);
        $body = str_replace("%comefrom%", $comeFrom, $body);
    }
    //%pagesyouvisited%
    //if(strpos(strtolower($body),"%pagesyouvisited%") !== FALSE) {
    //    $pagesyouvisited = $_SESSION['views'];
    //    $body = str_replace("%pagesyouvisited%", $pagesyouvisited, $body);
    //}
    //最近一段时间(10分钟内)的访问者数量,类似于在线人数
    if (strpos(strtolower($body), "%visitorsonline%") !== FALSE) {
        $to_time = current_time('timestamp');
        $from_time = strtotime('-10 minutes', $to_time);
        $qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as visitors FROM {$table_name} WHERE spider='' and feed='' AND timestamp BETWEEN {$from_time} AND {$to_time}{$normallimit};");
        $body = str_replace("%visitorsonline%", $qry[0]->visitors, $body);
    }
    //最近一段时间(10分钟内)的用户数量,这里用户指的登记在册的内容贡献者或订阅者
    if (strpos(strtolower($body), "%usersonline%") !== FALSE) {
        $to_time = current_time('timestamp');
        $from_time = strtotime('-10 minutes', $to_time);
        $qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as users FROM {$table_name} WHERE spider='' and feed='' AND user!='' AND timestamp BETWEEN {$from_time} AND {$to_time}{$normallimit};");
        $body = str_replace("%usersonline%", $qry[0]->users, $body);
    }
    //访问最多的帖子
    if (strpos(strtolower($body), "%toppost%") !== FALSE) {
        $qry = $wpdb->get_results("SELECT urlrequested,count(*) as totale FROM {$table_name} WHERE spider='' AND feed='' and pvalue !='' and pvalue !=0{$normallimit} GROUP BY pvalue ORDER BY totale DESC LIMIT 1;");
        $body = str_replace("%toppost%", iri_StatPress_Decode($qry[0]->urlrequested), $body);
    }
    //使用最多的浏览器
    if (strpos(strtolower($body), "%topbrowser%") !== FALSE) {
        $qry = $wpdb->get_results("SELECT browser,count(*) as totale FROM {$table_name} WHERE spider='' AND feed=''{$normallimit} GROUP BY browser ORDER BY totale DESC LIMIT 1;");
        $body = str_replace("%topbrowser%", iri_StatPress_Decode($qry[0]->browser), $body);
    }
    //使用最多的操作系统
    if (strpos(strtolower($body), "%topos%") !== FALSE) {
        $qry = $wpdb->get_results("SELECT os,count(*) as totale FROM {$table_name} WHERE spider='' AND feed=''{$normallimit} GROUP BY os ORDER BY totale DESC LIMIT 1;");
        $body = str_replace("%topos%", iri_StatPress_Decode($qry[0]->os), $body);
    }
    //订阅数
    if (strpos(strtolower($body), "%feeds%") !== FALSE) {
        $body = str_replace("%feeds%", iri_StatPress_FeedCount(), $body);
    }
    //blog文章总数,add by 蚊子
    if (strpos(strtolower($body), "%blogtotalpost%") !== FALSE) {
        $qry = $wpdb->get_results("SELECT count(ID) as pageview FROM {$wpdb->posts} WHERE post_status = 'publish' and post_type = 'post';");
        $body = str_replace("%blogtotalpost%", $qry[0]->pageview, $body);
    }
    //blog页面总数
    if (strpos(strtolower($body), "%blogtotalpage%") !== FALSE) {
        $qry = $wpdb->get_results("SELECT count(ID) as pageview FROM {$wpdb->posts} WHERE post_status = 'publish' and post_type = 'page';");
        $body = str_replace("%blogtotalpage%", $qry[0]->pageview, $body);
    }
    //留言者总数
    if (strpos(strtolower($body), "%blogtotalcommentor%") !== FALSE) {
        $qry = $wpdb->get_results("SELECT count(distinct(comment_author)) as pageview FROM {$wpdb->comments} WHERE comment_approved = '1';");
        $body = str_replace("%blogtotalcommentor%", $qry[0]->pageview, $body);
    }
    //留言总数
    if (strpos(strtolower($body), "%blogtotalcomment%") !== FALSE) {
        $qry = $wpdb->get_results("SELECT count(*) as pageview FROM {$wpdb->comments} WHERE comment_approved = '1';");
        $body = str_replace("%blogtotalcomment%", $qry[0]->pageview, $body);
    }
    return $body;
}
Ejemplo n.º 2
0
function iriStatAppend()
{
    global $wpdb;
    $table_name = $wpdb->prefix . "statpress";
    global $userdata;
    global $_STATPRESS;
    get_currentuserinfo();
    $feed = '';
    // Time
    $timestamp = current_time('timestamp');
    $vdate = gmdate("Ymd", $timestamp);
    $vtime = gmdate("H:i:s", $timestamp);
    // IP
    $ipAddress = $_SERVER['REMOTE_ADDR'];
    if (iriCheckBanIP($ipAddress) === true) {
        return '';
    }
    // Determine Threats if http:bl installed
    $threat_score = 0;
    $threat_type = 0;
    $httpbl_key = get_option("httpbl_key");
    if ($httpbl_key !== false) {
        $result = explode(".", gethostbyname($httpbl_key . "." . implode(".", array_reverse(explode(".", $ipAddress))) . ".dnsbl.httpbl.org"));
        // If the response is positive
        if ($result[0] == 127) {
            $threat_score = $result[2];
            $threat_type = $result[3];
        }
    }
    // URL (requested)
    $urlRequested = iri_StatPress_URL();
    if (eregi(".ico\$", $urlRequested)) {
        return '';
    }
    if (eregi("favicon.ico", $urlRequested)) {
        return '';
    }
    if (eregi(".css\$", $urlRequested)) {
        return '';
    }
    if (eregi(".js\$", $urlRequested)) {
        return '';
    }
    if (stristr($urlRequested, "/wp-content/themes/wicketpixie/plugins") != false) {
        return '';
    }
    if (stristr($urlRequested, "/wp-content/themes") != false) {
        return '';
    }
    $referrer = isset($_SERVER['HTTP_REFERER']) ? htmlentities($_SERVER['HTTP_REFERER']) : '';
    $userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? htmlentities($_SERVER['HTTP_USER_AGENT']) : '';
    $spider = iriGetSpider($userAgent);
    if ($spider != '' and get_option('statpress_donotcollectspider') == 'checked') {
        return '';
    }
    if ($spider != '') {
        $os = '';
        $browser = '';
    } else {
        // Trap feeds
        $prsurl = parse_url(get_bloginfo('url'));
        $feed = iri_StatPress_is_feed($prsurl['scheme'] . '://' . $prsurl['host'] . $_SERVER['REQUEST_URI']);
        // Get OS and browser
        $os = iriGetOS($userAgent);
        $browser = iriGetBrowser($userAgent);
        list($searchengine, $search_phrase) = explode("|", iriGetSE($referrer));
    }
    // Auto-delete visits if...
    if (get_option('statpress_autodelete_spider') != '') {
        $t = gmdate("Ymd", strtotime('-' . get_option('statpress_autodelete_spider')));
        $results = $wpdb->query("DELETE FROM " . $table_name . " WHERE date < '" . $t . "' AND spider <> ''");
    }
    if (get_option('statpress_autodelete') != '') {
        $t = gmdate("Ymd", strtotime('-' . get_option('statpress_autodelete')));
        $results = $wpdb->query("DELETE FROM " . $table_name . " WHERE date < '" . $t . "'");
    }
    if (!is_user_logged_in() or get_option('statpress_collectloggeduser') == 'checked') {
        if ($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") != $table_name) {
            iri_StatPress_CreateTable();
        }
        $insert = "INSERT INTO " . $table_name . " (date, time, ip, urlrequested, agent, referrer, search,nation,os,browser,searchengine,spider,feed,user,threat_score,threat_type,timestamp) " . "VALUES ('{$vdate}','{$vtime}','{$ipAddress}','" . mysql_real_escape_string($urlRequested) . "','" . mysql_real_escape_string(strip_tags($userAgent)) . "','" . mysql_real_escape_string($referrer) . "','" . mysql_real_escape_string(strip_tags($search_phrase)) . "','" . iriDomain($ipAddress) . "','" . mysql_real_escape_string($os) . "','" . mysql_real_escape_string($browser) . "','{$searchengine}','{$spider}','{$feed}','{$userdata->user_login}',{$threat_score},{$threat_type},'{$timestamp}')";
        $results = $wpdb->query($insert);
    }
}
function iriStatAppend()
{
    global $wpdb;
    $table_name = $wpdb->prefix . "statpress";
    global $userdata;
    global $_STATPRESS;
    get_currentuserinfo();
    $feed = '';
    // Time
    $timestamp = current_time('timestamp');
    $vdate = gmdate("Ymd", $timestamp);
    $vtime = gmdate("H:i:s", $timestamp);
    // IP
    $ipAddress = $_SERVER['REMOTE_ADDR'];
    if (iriCheckBanIP($ipAddress) == '') {
        return '';
    }
    // URL (requested)
    $urlRequested = iri_StatPress_URL();
    if (eregi(".ico\$", $urlRequested)) {
        return '';
    }
    if (eregi("favicon.ico", $urlRequested)) {
        return '';
    }
    if (eregi(".css\$", $urlRequested)) {
        return '';
    }
    if (eregi(".js\$", $urlRequested)) {
        return '';
    }
    if (stristr($urlRequested, "/wp-content/plugins") != FALSE) {
        return '';
    }
    if (stristr($urlRequested, "/wp-content/themes") != FALSE) {
        return '';
    }
    $referrer = isset($_SERVER['HTTP_REFERER']) ? htmlentities($_SERVER['HTTP_REFERER']) : '';
    $userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? htmlentities($_SERVER['HTTP_USER_AGENT']) : '';
    $spider = iriGetSpider($userAgent);
    if ($spider != '' and get_option('statpress_donotcollectspider') == 'checked') {
        return '';
    }
    if ($spider != '') {
        $os = '';
        $browser = '';
    } else {
        // Trap feeds
        $feed = iri_StatPress_is_feed(get_bloginfo('url') . $_SERVER['REQUEST_URI']);
        // Get OS and browser
        $os = iriGetOS($userAgent);
        $browser = iriGetBrowser($userAgent);
        list($searchengine, $search_phrase) = explode("|", iriGetSE($referrer));
    }
    // Auto-delete visits if...
    if (get_option('statpress_autodelete') != '') {
        $t = gmdate("Ymd", strtotime('-' . get_option('statpress_autodelete')));
        $results = $wpdb->query("DELETE FROM " . $table_name . " WHERE date < '" . $t . "'");
    }
    if (!is_user_logged_in() or get_option('statpress_collectloggeduser') == 'checked') {
        if ($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") != $table_name) {
            iri_StatPress_CreateTable();
        }
        $insert = "INSERT INTO " . $table_name . " (date, time, ip, urlrequested, agent, referrer, search,nation,os,browser,searchengine,spider,feed,user,timestamp) " . "VALUES ('{$vdate}','{$vtime}','{$ipAddress}','{$urlRequested}','" . addslashes(strip_tags($userAgent)) . "','{$referrer}','" . addslashes(strip_tags($search_phrase)) . "','" . iriDomain($ipAddress) . "','{$os}','{$browser}','{$searchengine}','{$spider}','{$feed}','{$userdata->user_login}','{$timestamp}')";
        $results = $wpdb->query($insert);
    }
}