BLOG:CMS :: Support Forum

Support Forum for BLOG:CMS

You are not logged in.

#1 15.06.2004 14:48

Alex Krylov
BLOG:CMS Junior
Registered: 14.06.2004
Posts: 10
Website

Cyrillic url paths and Fancy URLs

FancyURLs did strange things with cyrillic titles. To avoid this problem, I've made translation function and insert it in function _makefancyTitle() in file /nucleus/plugins/NP_FancierURL.php

Code:

function _makefancyTitle($title, $id) {
        $title = trim($title);
        $title = strip_tags($title);
        // disabled for Cyrillic by @lex: $title = $this->iso2ascii($title);
        $title = strtolower($title);
        
        $urltitle = $title = req_to_url ($title); // by @lex
        
        // disabled for Cyrillic by @lex: preg_match_all('/[a-zA-Z0-9]+/', $title, $nt);
        // disabled for Cyrillic by @lex: $urltitle = implode($this->getOption(spaceReplace), $nt[0]);
        $res = mysql_query('SELECT inumber FROM ' . sql_table('item') . ' WHERE ititle=\'' . addslashes($title) . '\' AND inumber !=' . $id);
        if (mysql_num_rows($res) > 0) {
            return strtolower($urltitle . $this->getOption(spaceReplace) . $id);
        } else {
            return strtolower($urltitle);
        }
    }


function    req_to_url ($req) // by @lex
{
    $ruchars    = 'абвгдезиклмнопрстуфхэю';
    $basemapto    = 'abvgdeziklmnoprstufheu';
    
    $allowed    = 'abcdefghijklmnopqrstuvwxyz1234567890-_';
    
    $rules = array (
        'ё' => 'yo',
        'ж' => 'zh',
        'й' => 'j',
        'ц' => 'ts',
        'ч' => 'ch',
        'ш' => 'sh',
        'щ' => 'sch',
        'ъ' => '',
        'ы' => 'i', 
        'ь' => '',
        'я' => 'ya'
    );
    
    $pad = '_';
    
    
    $url = strtolower ($req);
    foreach ($rules as $k => $subst) {
        $url = preg_replace ("/$k/", $subst, $url);
    };
    
    $l = strlen ($url);
    for ($i = 0; $i < $l; ++$i) {
        $ch = $url[$i];
        if (strpos ($allowed, $ch) === false) {
            if (($pos = strpos ($ruchars, $ch)) !== false) {
                $url[$i] = $basemapto[$pos];
            } else {
                $url[$i] = $pad;
            };
        };
    };
    
    $url = preg_replace ("/$pad+/", $pad, $url);
    $url = preg_replace ("/$pad+$/", '', $url);
    
    return $url;
}

Offline

 

#2 15.06.2004 15:07

Radek Hulán
Site Admin
From: Prague, Czech Republic
Registered: 17.03.2004
Posts: 2509
Website

Re: Cyrillic url paths and Fancy URLs

Great! I'm making this post sticky.


--= BLOG:CMS developer =--

Offline

 

#3 15.06.2004 17:39

Alex Krylov
BLOG:CMS Junior
Registered: 14.06.2004
Posts: 10
Website

Re: Cyrillic url paths and Fancy URLs

Little addon to this function:
add at the begining string

Code:

$prev_locale = setlocale (LC_ALL, 'ru_RU.cp1251');

and before return:

Code:

setlocale (LC_ALL, $prev_locale);

So, now function looks like that:

Code:

function    req_to_url ($req) // by @lex
{
    $prev_locale = setlocale (LC_ALL, 'ru_RU.cp1251');
    
    $ruchars    = 'абвгдезиклмнопрстуфхэю';
    $basemapto    = 'abvgdeziklmnoprstufheu';
    
    $allowed    = 'abcdefghijklmnopqrstuvwxyz1234567890-_';
    
    $rules = array (
        'ё' => 'yo',
        'ж' => 'zh',
        'й' => 'j',
        'ц' => 'ts',
        'ч' => 'ch',
        'ш' => 'sh',
        'щ' => 'sch',
        'ъ' => '',
        'ы' => 'i', 
        'ь' => '',
        'я' => 'ya'
    );
    
    $pad = '_';
        
    $url = strtolower ($req);
    foreach ($rules as $k => $subst) {
        $url = preg_replace ("/$k/", $subst, $url);
    };
    
    $l = strlen ($url);
    for ($i = 0; $i < $l; ++$i) {
        $ch = $url[$i];
        if (strpos ($allowed, $ch) === false) {
            if (($pos = strpos ($ruchars, $ch)) !== false) {
                $url[$i] = $basemapto[$pos];
            } else {
                $url[$i] = $pad;
            };
        };
    };
    
    $url = preg_replace ("/$pad+/", $pad, $url);
    $url = preg_replace ("/$pad+$/", '', $url);
    
    setlocale (LC_ALL, $prev_locale);
    
    return $url;
}

Anyway it is good idea to add locale switch to language file.

Offline

 

#4 08.05.2005 16:08

Michael Le
BLOG:CMS Junior
From: Somewhere in Litvínov
Registered: 06.02.2005
Posts: 12
Website

Re: Cyrillic url paths and Fancy URLs

CПACИбO. I needed this.

Last edited by Michael Le (08.05.2005 16:09)


Be clever and use Blog:CMS!
Michael Le

Offline

 

#5 28.09.2005 08:07

ihra
BLOG:CMS Senior
From: Helsinki, Finland
Registered: 03.08.2004
Posts: 83
Website

Re: Cyrillic url paths and Fancy URLs

Which reminds me: should title conversion also include ä and ö (finnish a with two dots and o with two dots). Currently if I have title:
"testiä part 1"
it is linked as:
"testi_part_1"

And I really prefer it to be:
"testia_part_1".

Should I just add my characters to translation table (where are greek and russian characters) and if I add, which character set they should be (utf-8?). Or should I use similar as with this russian conversion?

Last edited by ihra (28.09.2005 08:07)

Offline

 

#6 28.09.2005 10:42

Radek Hulán
Site Admin
From: Prague, Czech Republic
Registered: 17.03.2004
Posts: 2509
Website

Re: Cyrillic url paths and Fancy URLs

ihra wrote:

Should I just add my characters to translation table (where are greek and russian characters) and if I add, which character set they should be (utf-8?). Or should I use similar as with this russian conversion?

yes, simply add them to the table, and use UTF-8 capable editor


--= BLOG:CMS developer =--

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson

TOPlist