function iriValueTable($fld, $fldtitle, $limit = 0, $param = "", $queryfld = "", $exclude = "") { /* Maddler 04112007: 添加了参数 */ global $wpdb; $table_name = $wpdb->prefix . "statpress"; $to_time = current_time('timestamp'); if (strlen(get_option("statpress_details_period")) > 0) { $period = get_option("statpress_details_period"); } else { $period = "1 month"; update_option("statpress_details_period", $period); } $from_time = strtotime('-' . $period, $to_time); $exclude .= " and (statuscode != '404' or statuscode is null)"; #$fc_statpress = $wpdb->query("select * from $table_name where feed!='' and timestamp between $from_time and $to_time;"); //$qry = $wpdb->get_results("select count(DISTINCT(IP)) as feedcounts from $table_name where feed!='' and timestamp between $from_time and $to_time;"); if ($queryfld == '') { $queryfld = $fld; } print "<div class='wrap'><table align=center><tr><td align=center>"; print "<h3>{$fldtitle}</h3>(" . __("recently", "statpresscn") . " " . $period . ")<table style='width:100%;padding:0px;margin:0px;' cellpadding=0 cellspacing=0><thead><tr><th style='width:220px;background-color:white;'></th><th style='width:60px;background-color:white;'><u>" . __('Visits', 'statpresscn') . "</u></th><th style='background-color:white;'></th></tr></thead>"; print "<tbody id='the-list'>"; $rks = $wpdb->get_var("SELECT count({$param} {$queryfld}) as rks FROM {$table_name} where timestamp between {$from_time} and {$to_time} {$exclude};"); if ($rks > 0) { $sql = "SELECT count({$param} {$queryfld}) as pageview, {$fld} FROM {$table_name} where timestamp between {$from_time} and {$to_time} {$exclude} GROUP BY {$fld} ORDER BY pageview DESC"; if ($limit > 0) { $sql = $sql . " LIMIT {$limit}"; } $qry = $wpdb->get_results($sql); $tdwidth = 250; $red = 131; $green = 180; $blue = 216; $deltacolor = round(250 / count($qry), 0); // $chl=""; // $chd="t:"; foreach ($qry as $rk) { $pc = round($rk->pageview * 100 / $rks, 1); if ($fld == 'date') { $rk->{$fld} = irihdate($rk->{$fld}); } if ($fld == 'urlrequested') { $rk->{$fld} = iri_StatPress_Decode($rk->{$fld}); } // $chl.=urlencode(substr($rk->$fld,0,50))."|"; // $chd.=($tdwidth*$pc/100)."|"; print "<tr><td style='width:250px;overflow: hidden; white-space: nowrap; text-overflow: ellipsis;'>"; if ($fld == "referrer") { echo "<a href='" . $rk->{$fld} . "' target='_heart5'>"; } echo iri_StatPress_Abbrevia(urldecode($rk->{$fld}), 26); if ($fld == "referrer") { echo "</a>"; } print "</td><td style='text-align:center;'>" . $rk->pageview . "</td>"; // <td style='text-align:right'>$pc%</td>"; print "<td><div style='text-align:right;padding:2px;font-family:helvetica;font-size:7pt;font-weight:bold;height:16px;width:" . $tdwidth * $pc / 100 . "px;background:" . irirgbhex($red, $green, $blue) . ";border-top:1px solid " . irirgbhex($red + 20, $green + 20, $blue) . ";border-right:1px solid " . irirgbhex($red + 30, $green + 30, $blue) . ";border-bottom:1px solid " . irirgbhex($red - 20, $green - 20, $blue) . ";'>{$pc}%</div>"; print "</td></tr>\n"; $red = $red + $deltacolor; $blue = $blue - $deltacolor / 2; } } print "</table>\n</td><td bgcolor=gray><font color=white>*vs*</font></td>"; print "<td align=center><h3>{$fldtitle}</h3>(" . __("all stats days", "statpresscn") . ")<table style='width:100%;padding:0px;margin:0px;' cellpadding=0 cellspacing=0><thead><tr><th style='width:220px;background-color:white;'></th><th style='width:60px;background-color:white;'><u>" . __('Visits', 'statpresscn') . "</u></th><th style='background-color:white;'></th></tr></thead>"; print "<tbody id='the-list'>"; $rks = $wpdb->get_var("SELECT count({$param} {$queryfld}) as rks FROM {$table_name} WHERE 1=1 {$exclude};"); if ($rks > 0) { $sql = "SELECT count({$param} {$queryfld}) as pageview, {$fld} FROM {$table_name} WHERE 1=1 {$exclude} GROUP BY {$fld} ORDER BY pageview DESC"; if ($limit > 0) { $sql = $sql . " LIMIT {$limit}"; } $qry = $wpdb->get_results($sql); $tdwidth = 250; $red = 131; $green = 180; $blue = 216; $deltacolor = round(250 / count($qry), 0); // $chl=""; // $chd="t:"; foreach ($qry as $rk) { $pc = round($rk->pageview * 100 / $rks, 1); if ($fld == 'date') { $rk->{$fld} = irihdate($rk->{$fld}); } if ($fld == 'urlrequested') { $rk->{$fld} = iri_StatPress_Decode($rk->{$fld}); } print "<tr><td style='width:250px;overflow: hidden; white-space: nowrap; text-overflow: ellipsis;'>"; if ($fld == "referrer") { echo "<a href='" . $rk->{$fld} . "' target='_heart5'>"; } echo iri_StatPress_Abbrevia(urldecode($rk->{$fld}), 26); if ($fld == "referrer") { echo "</a>"; } print "</td><td style='text-align:center;'>" . $rk->pageview . "</td>"; // <td style='text-align:right'>$pc%</td>"; print "<td><div style='text-align:right;padding:2px;font-family:helvetica;font-size:7pt;font-weight:bold;height:16px;width:" . $tdwidth * $pc / 100 . "px;background:" . irirgbhex($red, $green, $blue) . ";border-top:1px solid " . irirgbhex($red + 20, $green + 20, $blue) . ";border-right:1px solid " . irirgbhex($red + 30, $green + 30, $blue) . ";border-bottom:1px solid " . irirgbhex($red - 20, $green - 20, $blue) . ";'>{$pc}%</div>"; print "</td></tr>\n"; $red = $red + $deltacolor; $blue = $blue - $deltacolor / 2; } } print "</table>\n"; print "</td></table>"; // print "<img src=http://chart.apis.google.com/chart?cht=p3&chd=".($chd)."&chs=400x200&chl=".($chl)."&chco=1B75DF,92BF23>\n"; print "</div>\n"; }
function iri_StatPress_Vars($body) { global $wpdb; $table_name = $wpdb->prefix . "statpress"; if (strpos(strtolower($body), "%visits%") !== false) { $qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as pageview FROM {$table_name} WHERE date = '" . gmdate("Ymd", current_time('timestamp')) . "' and spider='' and feed='';"); $body = str_replace("%visits%", $qry[0]->pageview, $body); } if (strpos(strtolower($body), "%totalvisits%") !== false) { $qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as pageview FROM {$table_name} WHERE spider='' and feed='';"); $body = str_replace("%totalvisits%", $qry[0]->pageview, $body); } if (strpos(strtolower($body), "%thistotalvisits%") !== false) { $qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as pageview FROM {$table_name} WHERE spider='' and feed='' AND urlrequested='" . mysql_real_escape_string(iri_StatPress_URL()) . "';"); $body = str_replace("%thistotalvisits%", $qry[0]->pageview, $body); } if (strpos(strtolower($body), "%since%") !== false) { $qry = $wpdb->get_results("SELECT date FROM {$table_name} ORDER BY date LIMIT 1;"); $body = str_replace("%since%", irihdate($qry[0]->date), $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); } if (strpos(strtolower($body), "%ip%") !== false) { $ipAddress = $_SERVER['REMOTE_ADDR']; $body = str_replace("%ip%", $ipAddress, $body); } if (strpos(strtolower($body), "%visitorsonline%") !== false) { $to_time = current_time('timestamp'); $from_time = strtotime('-4 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};"); $body = str_replace("%visitorsonline%", $qry[0]->visitors, $body); } if (strpos(strtolower($body), "%usersonline%") !== false) { $to_time = current_time('timestamp'); $from_time = strtotime('-4 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};"); $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 urlrequested LIKE '%p=%' GROUP BY urlrequested 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='' 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='' GROUP BY os ORDER BY totale DESC LIMIT 1;"); $body = str_replace("%topos%", iri_StatPress_Decode($qry[0]->os), $body); } if (strpos(strtolower($body), "%pagestoday%") !== false) { $qry = $wpdb->get_results("SELECT count(ip) as pageview FROM {$table_name} WHERE date = '" . gmdate("Ymd", current_time('timestamp')) . "' and spider='' and feed='';"); $body = str_replace("%pagestoday%", $qry[0]->pageview, $body); } if (strpos(strtolower($body), "%thistotalpages%") !== FALSE) { $qry = $wpdb->get_results("SELECT count(ip) as pageview FROM {$table_name} WHERE spider='' and feed='';"); $body = str_replace("%thistotalpages%", $qry[0]->pageview, $body); } if (strpos(strtolower($body), "%latesthits%") !== false) { $qry = $wpdb->get_results("SELECT search FROM {$table_name} WHERE search <> '' ORDER BY id DESC LIMIT 10"); $body = str_replace("%latesthits%", $qry[0]->search, $body); for ($counter = 0; $counter < 10; $counter += 1) { $body .= "<br>" . $qry[$counter]->search; } } if (strpos(strtolower($body), "%pagesyesterday%") !== false) { $yesterday = gmdate('Ymd', current_time('timestamp') - 86400); $qry = $wpdb->get_row("SELECT count(DISTINCT ip) AS visitsyesterday FROM {$table_name} WHERE feed='' AND spider='' AND date = '" . mysql_real_escape_string($yesterday) . "'"); $body = str_replace("%pagesyesterday%", iri_StatPress_Decode($qry[0]->visitsyesterday), $body); } return $body; }
function iri_StatPress_Vars($body) { global $wpdb; $table_name = $wpdb->prefix . "statpress"; if (strpos(strtolower($body), "%visits%") !== FALSE) { $qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as pageview FROM {$table_name} WHERE date = '" . gmdate("Ymd", current_time('timestamp')) . "' and spider='' and feed='';"); $body = str_replace("%visits%", $qry[0]->pageview, $body); } if (strpos(strtolower($body), "%totalvisits%") !== FALSE) { $qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as pageview FROM {$table_name} WHERE spider='' and feed='';"); $body = str_replace("%totalvisits%", $qry[0]->pageview, $body); } if (strpos(strtolower($body), "%thistotalvisits%") !== FALSE) { $qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as pageview FROM {$table_name} WHERE spider='' and feed='' AND urlrequested='" . iri_StatPress_URL() . "';"); $body = str_replace("%thistotalvisits%", $qry[0]->pageview, $body); } if (strpos(strtolower($body), "%since%") !== FALSE) { $qry = $wpdb->get_results("SELECT date FROM {$table_name} ORDER BY date LIMIT 1;"); $body = str_replace("%since%", irihdate($qry[0]->date), $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); } if (strpos(strtolower($body), "%ip%") !== FALSE) { $ipAddress = $_SERVER['REMOTE_ADDR']; $body = str_replace("%ip%", $ipAddress, $body); } if (strpos(strtolower($body), "%visitorsonline%") !== FALSE) { $to_time = current_time('timestamp'); $from_time = strtotime('-4 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};"); $body = str_replace("%visitorsonline%", $qry[0]->visitors, $body); } if (strpos(strtolower($body), "%usersonline%") !== FALSE) { $to_time = current_time('timestamp'); $from_time = strtotime('-4 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};"); $body = str_replace("%usersonline%", $qry[0]->users, $body); } if (strpos(strtolower($body), "%toppost%") !== FALSE) { $qry = $wpdb->get_results("SELECT urlrequested,count(*) as totale FROM wp_statpress WHERE spider='' AND feed='' AND urlrequested LIKE '%p=%' GROUP BY urlrequested 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 wp_statpress WHERE spider='' AND feed='' 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 wp_statpress WHERE spider='' AND feed='' GROUP BY os ORDER BY totale DESC LIMIT 1;"); $body = str_replace("%topos%", iri_StatPress_Decode($qry[0]->os), $body); } return $body; }