Changeset 1550 in ExiteCMS


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

Location:
trunk/includes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/core_functions.php

    r1522 r1550  
    385385    $urlregex .= "[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)*";                           // HOSTNAME or IP 
    386386    $urlregex .= "(\:[0-9]{2,5})?";                                             // PORT (optional) 
    387     $urlregex .= "(\/([a-z0-9+\$_-]\.?)+)*\/?";                                 // PATH (optional) 
     387    $urlregex .= "(\/([a-z0-9+\$_%-]\.?)+)*\/?";                                // PATH (optional) 
    388388    $urlregex .= "(\?[a-z+&\$_.-][a-z0-9;:@/&%=+\$_.-]*)?";                     // GET querystring (optional) 
    389389    $urlregex .= "(#[a-z_.-][a-z0-9+\$_.-]*)?\$";                               // ANCHOR (optional) 
  • trunk/includes/forum_functions_include.php

    r1527 r1550  
    1818$codeblocks = array(); 
    1919$urlblocks = array(); 
     20$imgblocks = array(); 
    2021$blockcount = 0; 
    2122$raw_color_blocks = false; 
     
    337338        return ""; 
    338339    } 
    339     // trim the values passed 
     340 
     341    // remove leading CRLF 
     342    if (substr($matches[2],0,2) == "\r\n") { 
     343        $matches[2] = substr($matches[2],2); 
     344    } 
     345 
     346    // remove the leading '=' from the file type 
    340347    $matches[1] = trim(substr($matches[1],1)); 
    341348 
     349    // colorize the code if requested 
    342350    if ($raw_color_blocks == false) { 
    343351        require_once PATH_GESHI."/geshi.php"; 
    344352        $geshi =& new GeSHi("", ""); 
    345         // colorize the code 
    346353        $geshi->set_language($matches[1]); 
    347354        $geshi->set_header_type(GESHI_HEADER_DIV); 
     
    351358    } 
    352359 
     360    // if a raw block was requested, bail out here 
    353361    if ($raw_color_blocks) { 
    354362        $codeblocks[] = array($matches[2], $matches[1]); 
     
    376384} 
    377385 
    378 // message parser, strip [code] and [url] sections, parse for BBcode and smiley's, then insert the sections again 
     386function _parseubb_imgblock($matches) { 
     387    global $imgblocks; 
     388 
     389    $imgblocks[] = array($matches[1], $matches[1]); 
     390    return "{@*@".(count($imgblocks)-1)."@*@}"; 
     391} 
     392 
     393// message parser, strip [code], [img] and [url] sections, parse for BBcode, smiley's, then insert the sections again 
    379394function parsemessage($msg_array) { 
    380395    global $settings, $db_prefix, $codeblocks, $urlblocks, $current_message; 
     
    392407    $codeblocks = array(); 
    393408    $urlblocks = array(); 
     409    $imgblocks = array(); 
     410 
     411    // convert any newlines to html <br> 
     412    $rawmsg = nl2br($rawmsg); 
    394413 
    395414    // strip CODE bbcode, optionally perform Geshi color coding 
    396415    $rawmsg = preg_replace_callback('#\[code(=.*?)?\](.*?)([\r\n]*)\[/code\]#si', '_parseubb_codeblock', $rawmsg); 
    397416 
     417    // find URL's in the text, and convert them to a [url] BBcode 
     418    $rawmsg = preg_replace("#(^|\s)(www|WWW)\.([^\s<>\/]+)\/([^\s\r\n<>\)\,\:\;\[]+)#sm", "\\1[url=http://\\2.\\3/\\4]http://\\2.\\3[/url]", $rawmsg); 
     419    $rawmsg = preg_replace("#(^|[^\"=\]]{1})(http|HTTP|ftp)(s|S)?://([^\s<>\/]+)\/([^\s\r\n<>\,\[]+)#sm", "\\1[url=\\2\\3://\\4/\\5]\\2\\3://\\4\\5[/url]", $rawmsg); 
     420 
    398421    // strip URL bbcode 
    399422    $rawmsg = preg_replace_callback('#\[url(=.*?)\](.*?)([\r\n]*)\[/url\]#si', '_parseubb_urlblock', $rawmsg); 
     423 
     424    // strip IMG bbcode 
     425//  $rawmsg = preg_replace_callback('#\[img\](.*?)([\r\n]*)\[/img\]#si', '_parseubb_imgblock', $rawmsg); 
    400426 
    401427    // detect and convert wikitags to wiki bbcodes if needed 
     
    406432        $result = dbquery("SELECT DISTINCT tag FROM ".$db_prefix."wiki_pages"); 
    407433        while ($data = dbarray($result)) { 
    408             $search[] = "/([[:space:]\.\,-])+?(".$data['tag'].")([[:space:]\.\,-]+?|\]|$)/i"; 
    409             $replace[] = "\\1[wiki]\\2[/wiki]\\3"; 
     434            if (!empty($data['tag'])) { 
     435                $search[] = "/(\b)(".$data['tag'].")(\b)/i"; 
     436                $replace[] = "\\1[wiki]\\2[/wiki]\\3"; 
     437            } 
    410438        } 
    411439        $rawmsg = preg_replace($search, $replace, $rawmsg); 
     440    } 
     441 
     442    // re-insert the saved img blocks 
     443    foreach($imgblocks as $key => $imgblock) { 
     444        $rawmsg = str_replace("{*@*".$key."*@*}", $imgblock[0], $rawmsg); 
    412445    } 
    413446 
    414447    // parse the smileys in the message 
    415448    if ($smileys) $rawmsg = parsesmileys($rawmsg); 
     449 
    416450    // parse all ubbcode 
    417451    $rawmsg = parseubb($rawmsg); 
    418     // convert any newlines to html <br> 
    419     $rawmsg = str_replace("\r\n\r\n", "\r\n", $rawmsg); 
    420     $rawmsg = nl2br($rawmsg); 
    421452     
    422  
    423453    // re-insert the saved code blocks 
    424454    foreach($codeblocks as $key => $codeblock) { 
  • 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.