コード例 #1
0
 /**
  * updates CountPerDay table
  */
 function updateDB()
 {
     global $count_per_day, $cpd_path, $wpdb;
     $count_per_day->mysqlQuery('rows', "SELECT country FROM {$wpdb->cpd_counter} LIMIT 1", 'GeoIP updateDB Table ' . __LINE__);
     if ((int) mysql_errno() == 1054) {
         // add row "country" to table
         $count_per_day->mysqlQuery('', "ALTER TABLE {$wpdb->cpd_counter} ADD `country` CHAR( 2 ) NOT NULL", 'GeoIP updateDB create column ' . __LINE__);
     }
     $limit = 20;
     $res = $count_per_day->mysqlQuery('rows', "SELECT ip, INET_NTOA(ip) realip FROM {$wpdb->cpd_counter} WHERE country LIKE '' GROUP BY ip LIMIT {$limit}", 'GeoIP updateDB ' . __LINE__);
     $gi = cpd_geoip_open($cpd_path . '/geoip/GeoIP.dat', GEOIP_STANDARD);
     foreach ($res as $r) {
         $c = '';
         $ip = explode('.', $r->realip);
         if ($ip[0] == 10 || $ip[0] == 127 || $ip[0] == 169 && $ip[1] == 254 || $ip[0] == 172 && $ip[1] >= 16 && $ip[1] <= 31 || $ip[0] == 192 && $ip[1] == 168) {
             // set local IPs to '-'
             $c = '-';
         } else {
             // get country
             $c = strtolower(cpd_geoip_country_code_by_addr($gi, $r->realip));
         }
         if (!empty($c)) {
             $count_per_day->mysqlQuery('', "UPDATE {$wpdb->cpd_counter} SET country = '{$c}' WHERE ip = '{$r->ip}'", 'GeoIP updateDB ' . __LINE__);
         }
     }
     cpd_geoip_close($gi);
     $rest = $count_per_day->mysqlQuery('var', "SELECT COUNT(*) FROM {$wpdb->cpd_counter} WHERE country like ''", 'GeoIP updateDB ' . __LINE__);
     return (int) $rest;
 }
コード例 #2
0
ファイル: data.xml.php プロジェクト: ahsaeldin/projects
if (!session_id()) {
    session_start();
}
$cpd_wp = !empty($_SESSION['cpd_wp']) ? $_SESSION['cpd_wp'] : '../../../../';
require_once $cpd_wp . 'wp-load.php';
require_once $cpd_path . '/geoip/geoip.php';
$geoip = new GeoIPCpD();
$data = array();
$what = empty($_GET['map']) ? 'reads' : strip_tags($_GET['map']);
if ($what == 'online') {
    $gi = cpd_geoip_open($cpd_path . 'geoip/GeoIP.dat', GEOIP_STANDARD);
    $oc = get_option('count_per_day_online', array());
    $vo = array();
    foreach ($oc as $ip => $x) {
        $country = cpd_geoip_country_code_by_addr($gi, $ip);
        $id = $geoip->GEOIP_COUNTRY_CODE_TO_NUMBER[$country];
        if (!empty($id)) {
            $name = $geoip->GEOIP_COUNTRY_NAMES[$id];
            $count = isset($vo[$country]) ? $vo[$country][1] + 1 : 1;
            $vo[$country] = array($name, $count);
        }
    }
    foreach ($vo as $k => $v) {
        $data[] = array($v[0], $k, $v[1]);
    }
} else {
    $temp = $count_per_day->addCollectionToCountries($what == 'visitors');
    foreach ($temp as $country => $value) {
        if ($country != '-') {
            $country = strtoupper($country);
コード例 #3
0
ファイル: counter.php プロジェクト: ahsaeldin/projects
 /**
  * shows current visitors
  */
 function getUserOnline($frontend = false, $country = false, $return = false)
 {
     global $wpdb, $cpd_geoip, $cpd_path;
     $c = '';
     $oc = get_option('count_per_day_online');
     if ($oc && $cpd_geoip && $country) {
         // map link
         if (!$frontend && file_exists($cpd_path . 'map/map.php')) {
             $c .= '<div style="margin: 5px 0 10px 0;"><a href="' . $this->dir . '/map/map.php?map=online' . '&amp;KeepThis=true&amp;TB_iframe=true" title="Count per Day - ' . __('Map', 'cpd') . '" class="thickbox button">' . __('Map', 'cpd') . '</a></div>';
         }
         // countries list
         $geoip = new GeoIPCpd();
         $gi = cpd_geoip_open($cpd_path . 'geoip/GeoIP.dat', GEOIP_STANDARD);
         $vo = array();
         foreach ($oc as $ip => $x) {
             $country = strtolower(cpd_geoip_country_code_by_addr($gi, $ip));
             $id = $geoip->GEOIP_COUNTRY_CODE_TO_NUMBER[strtoupper($country)];
             if (empty($id)) {
                 $name = '???';
                 $country = 'unknown';
             } else {
                 $name = $geoip->GEOIP_COUNTRY_NAMES[$id];
             }
             $count = isset($vo[$country]) ? $vo[$country][1] + 1 : 1;
             $vo[$country] = array($name, $count);
         }
         $c .= '<ul class="cpd_front_list">';
         foreach ($vo as $k => $v) {
             $c .= '<li><div class="cpd-flag cpd-flag-' . $k . '"></div> ' . $v[0] . '&nbsp;<b>' . $v[1] . '</b></li>' . "\n";
         }
         $c .= "</ul>\n";
     } else {
         if ($oc) {
             $c = count($oc);
         } else {
             $c = 0;
         }
     }
     if ($return) {
         return $c;
     } else {
         echo $c;
     }
 }