Changeset 1528

Show
Ignore:
Timestamp:
02/24/08 22:35:34 (6 months ago)
Author:
Rickard
Message:

Improved the sef_friendly function.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/punbb-1.3-dev/upload/include/functions.php

    r1521 r1528  
    15131513// Make a string safe to use in a URL 
    15141514// 
    1515 function sef_friendly($string
     1515function sef_friendly($str
    15161516{ 
    15171517        ($hook = get_hook('fn_sef_friendly_start')) ? eval($hook) : null; 
    15181518 
    1519         $reserved_words = array('atom', 'last'); 
    1520         $words = explode(' ', $string); 
    1521         $string = ''; 
    1522  
    1523         foreach ($words as $word) 
    1524         { 
    1525                 if (strlen($word) > 3 && !in_array(strtolower($word), $reserved_words)) 
    1526                         $string .= '-'.$word; 
    1527         } 
    1528  
    1529         $string = urlencode(strtr(str_replace('?', '', utf8_decode($string)), utf8_decode('ÀÁÂÃÄà
    1530 Ã Ã¡Ã¢Ã£Ã€Ã¥Ã’ÓÔÕÖØòóÎõöÞÈÉÊËÚéêëÇçÌÍÎÏìíîïÙÚÛÜùúûÌÿÑñ/'), 'AAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn-')); 
    1531  
    1532         return $string; 
     1519        $str = strtolower(utf8_decode($str)); 
     1520        $str = strtr($str, 
     1521                "\xc0\xc1\xc2\xc3\xc4\xc5\xe0\xe1\xe2\xe3\xe4\xe5\xd2\xd3\xd4\xd5\xd6\xd8\xf2\xf3\xf4\xf5\xf6\xf8\xc8\xc9\xca\xcb\xe8\xe9\xea\xeb\xc7\xe7\xcc\xcd\xce\xcf\xec\xed\xee\xef\xd9\xda\xdb\xdc\xf9\xfa\xfb\xfc\xff\xd1\xf1", 
     1522                'aaaaaaaaaaaaooooooooooooeeeeeeeecciiiiiiiiuuuuuuuuynn' 
     1523        ); 
     1524        $str = preg_replace(array('/[^a-z0-9\s]/', '/[\s]+/'), array('', '-'), $str); 
     1525 
     1526        return $str != '-' ? '-'.trim($str, '-') : ''; 
    15331527} 
    15341528 
     
    19961990// a part of the URL itself), $target_url may be a plain string containing information related to the URL.  
    19971991// 
    1998 function generate_form_token ($target_url) 
     1992function generate_form_token($target_url) 
    19991993{ 
    20001994        global $pun_user;