Ejemplo n.º 1
0
function iri_StatPress_TopPosts($limit = 5, $showcounts = 'checked')
{
    global $wpdb;
    $res = "\n<ul>\n";
    $table_name = $wpdb->prefix . "statpress";
    $qry = $wpdb->get_results("SELECT urlrequested,count(*) as totale FROM {$table_name} WHERE spider='' AND feed='' GROUP BY urlrequested ORDER BY totale DESC LIMIT {$limit};");
    foreach ($qry as $rk) {
        $res .= "<li><a href='" . irigetblogurl() . (strpos($rk->urlrequested, 'index.php') === FALSE ? $rk->urlrequested : '') . "'>" . iri_StatPress_Decode($rk->urlrequested) . "</a></li>\n";
        if (strtolower($showcounts) == 'checked') {
            $res .= " (" . $rk->totale . ")";
        }
    }
    return "{$res}</ul>\n";
}
Ejemplo n.º 2
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;
}