ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

SOLVED: utf8 in channel’s url_title and wiki pages EE21

August 18, 2010 3:38pm

Subscribe [2]
  • #1 / Aug 18, 2010 3:38pm

    Houdini

    42 posts

    First edit system/expressionengine/helpers/EE_url_helper.php

    Here we will modify url_title function:

    comment lines

    if (UTF8_ENABLED)
    {
        $CI =& get_instance();
        $CI->load->helper('text');
        $str = utf8_decode($str);
        $str = preg_replace_callback('/(.)/', 'convert_accented_characters', $str);            
    }

    and replace $trans variable with this:

    $trans = array(
        '&\#\d+?;'                    => '',
        '&\S+?;'                    => '',
        '\s+|/+'                    => $separator,
        '[^\p{L}\p{Nd}0-9\-\._]'            => '',
        $separator.'+'                => $separator,
        '^[-_]+|[-_]+$'                => '',
        '\.+$'                        => ''
      );

    and replace foreach cycle with:

    foreach ($trans as $key => $val)
    {
        $str = preg_replace("#".$key."#iu", $val, $str);
    }

    Done with php, now we would like to fix javascript, that on fly convert title to url:
    Open file: system/expressionengine/javascript/compressed/cp/publish.js

    Yep, we’ll fix that compressed javascript (pity that ellis lab doesn’t provide uncompressed version)

    find function liveUrlTitle and replace it to this one:

    function liveUrlTitle(){
        var d=EE.publish.default_entry_title,
            e=EE.publish.word_separator,
            c=document.getElementById("title").value||"",
            h=document.getElementById("url_title"),
            n=RegExp(e+"{2,}","g"),
            l=e!=="_"?/\_/g:/\-/g,
            m="";
        if(d!=="")
        if(c.substr(0,d.length)===d)
            c=c.substr(d.length);
        c=EE.publish.url_title_prefix+c;
        c=c.toLowerCase().replace(l,e);
        c=c.replace("/<(.*?)>/g","");
        c=c.replace(/\s+/g,e);
        c=c.replace(/\//g,e);
        c=c.replace(/[^a-z0-9а-я\-\._]/g,"");
        c=c.replace(/\+/g,e);
        c=c.replace(n,e);
        c=c.replace(/^[-_]|[-_]$/g,"");
        c=c.replace(/\.+$/g,"");if(h)h.value=c.substring(0,75)
    }

    Notice to line:

    c=c.replace(/[^a-z0-9а-я\-\._]/g,"");

    I would like to able url_titles in russian, that is why I added а-я, you should added your language.

    That’s all, now about wiki module.
    If you try to create page like: Хабаровск, you get error:
    Disallowed Key Characters.

    To fix it, open file: system/codeigniter/system/core/input.php
    Go to function _clean_input_keys

    if replace first if condition to:

    if ( ! preg_match("/^[\p{L}\p{Nd}0-9:_\/-]+$/i", $str))
    {
        exit('Disallowed Key Characters.');
    }

    Now you can have urls with /wiki/Хабаровск

    Best regards

  • #2 / Aug 18, 2010 4:39pm

    Ingmar

    29245 posts

    Since you don’t seem to be having a Tech Support issue as such yourself I am moving this thread to the CodeShare Corner. Thanks.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases