Changeset 1550 in ExiteCMS for trunk/includes/geoip_include.php


Ignore:
Timestamp:
07/27/08 14:26:17 (4 years ago)
Author:
root
Message:

Fixed country code and flag caching issue due to an array index overflow. Fixed incorrect wikilink parsing (missing some works, parsing URL's in [img] tags). Fixed isURL() not accepting a % sign in the path of an URL

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/geoip_include.php

    r1478 r1550  
    2929    global $db_prefix, $_GeoIP_result; 
    3030 
    31     // convert the IP address to a number 
    32     $ipnum = GeoIP_IP2Num($ip_addr); 
    33     if (!$ipnum) return false; 
    34      
    3531    // not cached? 
    36     if (!isset($_GeoIP_result[$ipnum])) { 
     32    if (!isset($_GeoIP_result[$ip_addr])) { 
    3733 
    3834        // check if there is an exception defined 
     
    4036        if ($data = dbarray($result)) { 
    4137            // add it to the cache 
    42             $_GeoIP_result[$ipnum] = $data['ip_code']; 
     38            $_GeoIP_result[$ip_addr] = $data['ip_code']; 
    4339        } else { 
     40            // convert the IP address to a number 
     41            $ipnum = GeoIP_IP2Num($ip_addr); 
     42            if (!$ipnum) return false;           
    4443            // look this IP address up 
    4544            $result = dbquery("SELECT * FROM ".$db_prefix."GeoIP WHERE '".sprintf("%u", $ipnum)."' BETWEEN ip_start_num AND ip_end_num LIMIT 1"); 
    4645            if ($data = dbarray($result)) { 
    4746                // add it to the cache 
    48                 $_GeoIP_result[$ipnum] = $data['ip_code']; 
     47                $_GeoIP_result[$ip_addr] = $data['ip_code']; 
    4948            } else { 
    50                 $_GeoIP_result[$ipnum] = false; 
     49                $_GeoIP_result[$ip_addr] = false; 
    5150            } 
    5251        } 
     
    5453    } 
    5554 
    56     return $_GeoIP_result[$ipnum]; 
     55    return $_GeoIP_result[$ip_addr]; 
    5756} 
    5857 
     
    7170    global $db_prefix, $settings; 
    7271 
    73     $result = dbquery("SELECT locales_value FROM ".$db_prefix."locales WHERE locales_code = '".$settings['locale_code']."' AND locales_name = 'countrycode' AND locales_key = '".$ip_code."' LIMIT 1"); 
    74     if (!dbrows($result)) { 
    75         // no translated country names found, load the english set instead 
    76         $result = dbquery("SELECT locales_value FROM ".$db_prefix."locales WHERE locales_code = 'en' AND locales_name = 'countrycode' AND locales_key = '".$ip_code."' LIMIT 1"); 
     72    // not cached? 
     73    if (!isset($_GeoIP_result[$ip_code])) { 
     74 
     75        $result = dbquery("SELECT locales_value FROM ".$db_prefix."locales WHERE locales_code = '".$settings['locale_code']."' AND locales_name = 'countrycode' AND locales_key = '".$ip_code."' LIMIT 1"); 
     76        if (!dbrows($result)) { 
     77            // no translated country names found, load the english set instead 
     78            $result = dbquery("SELECT locales_value FROM ".$db_prefix."locales WHERE locales_code = 'en' AND locales_name = 'countrycode' AND locales_key = '".$ip_code."' LIMIT 1"); 
     79        } 
     80        if (dbrows($result) == 0) { 
     81            $_GeoIP_result[$ip_code] = ""; 
     82        } else { 
     83            $data = dbarray($result); 
     84            $_GeoIP_result[$ip_code] = $data['locales_value']; 
     85        } 
    7786    } 
    78     if (dbrows($result) == 0) { 
    79         return ""; 
    80     } 
    81     $data = dbarray($result); 
    82     return $data['locales_value']; 
     87 
     88    return $_GeoIP_result[$ip_code]; 
    8389} 
    8490 
Note: See TracChangeset for help on using the changeset viewer.