Page 1 of 1

page alias in other languages

Posted: Thu Jun 04, 2009 1:51 pm
by samplist
Hi all, I have been asked by a client to provide pretty urls in his site but the problem is that the webpage is in greek. I tried to put page aliases in Greek but it seems that this is not possible (i get an error). I found the function that checks page alias and disabled this check but this doesn't seem to work either. Is there any way that i can alter some of the code so to allow full utf chars into page alias?

Re: page alias in other languages

Posted: Thu Jun 04, 2009 2:23 pm
by NaN
samplist wrote:
[...]
but it seems that this is not possible (i get an error).
[...]
What error message?
Where?
In CMS backend or when accessing the frontend?

samplist wrote:
[...]
I found the function that checks page alias and disabled this check but this doesn't seem to work either.
[...]
What function?
What file?
What happened?

Re: page alias in other languages

Posted: Thu Jun 04, 2009 3:53 pm
by samplist
I get the error "Alias must be all letters and numbers" that is from function "CheckAliasError". I'm writing only one word as a page alias of course so that's strange. Anyway if i comment the part

Code: Select all

		else if (!preg_match('/^[\-\_\w]+$/', $alias))
		{
			$error = lang('aliasmustbelettersandnumbers');
		}
		else
		{

on line 836 of class.contentoperations.inc.php i avoid the error but then page alias does not get imported to the database.

I tried to insert manually the word into the database and that works! So it must be a problem when the field page_alias gets imported to the database but where is that?

Re: page alias in other languages

Posted: Thu Jun 04, 2009 4:31 pm
by samplist
ok, back from the start...
I chose Default language for the frontend: Greek. Now i can insert a greek word as page alias and press submit without getting an error. But it doesn't get inserted in the database. So instead of index.php?page=ιστορία I get index.php?id=65.

Re: page alias in other languages

Posted: Thu Jun 04, 2009 5:55 pm
by NaN
The Problem is the function munge_string_to_url() that is used to convert the alias into latin characters.
The function is declared in misc.functions.php and includes a replacement.php where two arrays are defined that contain various non latin characters that will be replaced by an equivalent of latin characters.

munge_string_to_url() is called in class.content.php in the function SetAlias().
SetALias() is called in addcontent.php as well as editcontent.php (in admin directory) when saving a content.

Now its up to you to change that.

But just one thing:

Did you ever entered "ιστορία" in the addressbar of your browser?
In my case it results in

"%CF%80%CE%B1%CF%81-%CE%B9%CF%83%CF%84%CE%BF%CF%81%CE%AF%CE%B1"

or

"%26%23953%3B%26%23963%3B%26%23964%3B%26%23959%3B%26%23961%3B%26%23943%3B%26%23945%3B"

Do you really want your URL look like that?
Using UTF-8 characters in an URL is - imho -  no good idea.

Re: page alias in other languages

Posted: Thu Jun 04, 2009 8:02 pm
by samplist
Thanks NaN,
no what i'm trying to do is have a url like http://www.mysite.com/index.php?page=ιστορία
anyway bypassing munge_string_to_url(), still gives me the same error, i must figure out something else.

Re: page alias in other languages

Posted: Fri Jun 05, 2009 8:28 am
by samplist
Back to a clean install of 1.5.4.
In config.php i have $config['auto_alias_content'] = true; (that's the default)
In admin console -> Global settings i have Default language for the frontend: "No Default Language selected"

I'm creating a new page in admin console with title Ιστορία, menu text Ιστορία and some content. Now with the above settings when i press the submit button cmsms should take the menu text make it lowercase and put it in the page alias but instead i get error: Alias must be all letters and numbers.

Now when i change the Default language for the frontend to: "Ελληνικά" (Greek)
when i press submit i get no error (The content was successfully added to the database.) but when i edit the page i see that page alias is empty. Page alias didn't make it to database (field content_alias in db is empty).

I think maybe this is a bug.

Now studying the code around the page alias generation i tried various stuff but i didn't manage to fix it (i'm not really a very good php coder) but i bypassed the error by doing the above:

NOTE THIS IS A HACK OK? I DO NOT RECOMMEND IT

In file \lib\classes\class.content.inc.php
1) I commented all content of function SetAlias and i replaced it with $this->mAlias = 'fake';

Code: Select all

	function SetAlias($alias)
	{
		$this->mAlias = 'fake';
	} 
So this bypasses all SetAlias checks it's WRONG i know.

2)Then in the update function instead of insertng the mAlias into the db i'm inserting the menu text.

Code: Select all

		$myalias = $this->mMenuText; //I use menutext as page alias
		$myalias = trim($myalias);
		$myalias = ereg_replace("/", "-", $myalias);
		$myalias = ereg_replace(" ", "-", $myalias);
				
		$dbresult = $db->Execute($query, array(
			$this->mName,
			$this->mOwner,
			strtolower($this->mType),
			$this->mTemplateId,
			$this->mParentId,
			($this->mActive == true         ? 1 : 0),
			($this->mDefaultContent == true ? 1 : 0),
			($this->mShowInMenu == true     ? 1 : 0),
			($this->mCachable == true       ? 1 : 0),
			$this->mMenuText,
			$myalias, //here it is...
			$this->mMetadata,
			$this->mTitleAttribute,
			$this->mAccessKey,
			$this->mTabIndex,
			$this->mModifiedDate,
			$this->mItemOrder,
			$this->mMarkup,
			$this->mLastModifiedBy,
			$this->mId
			));

Some conclusions that i have made is that i think something is not right in function CheckAliasError and SetAlias maybe they are not compatible with utf-8 chars. Hope this gets fixed in the next update. Cheers.