cotonti.com : [RELEASE] AutoALIAS <- simple way to autocreate aliases https://www.cotonti.com Last topic posts Cotonti en Sat, 18 Oct 2025 11:41:43 -0000 musiconly Sun, 17 May 2009 15:51:17 -0000 Lombi # Koradhil : There are better ways to replace illegal URI characters from a string. Please have a look here and here. Of course this isn't the prettiest option, but at least it should work for all languages.
Noone in their right mind would want to have htmlentity aliases. This was used on slovenian sites so the replaces are for slovenian characters which normalizes them. I'm aware that there may be fancier ways to do it, but it completely does the trick and it's fully client-based.

So no plugs or extra files needed.

The admin can put their own characters in there, if it's an english site it can stay as is.

$output = preg_replace("/[^A-Za-z0-9]/", "", $input);

Obviously noone would want that, since it needs one extra file or even a plugin.

---------------

Btw I noticed that two thirds of the code are for other cool features on the page add/edit page, so I'll remove them.]]>
Tue, 31 Mar 2009 02:09:07 -0000
dervan # Koradhil : The best thing to use would be the php command:
$output = preg_replace("/[^A-Za-z0-9]/", "", $input);
Even though it will remove illegal chars instead of replace them.
and good practice would be to use "transliteration" feature which is supported in Cotonti, like this:
if ($lang != 'en' && is_array($sed_translit))
{
	$output = strtr($input, $sed_translit); // transliterate non-English characters
}
$output = preg_replace("/[^A-Za-z0-9]/", "", $output);

transliteration works when transition tables ($sed_translit, $sed_translitb) are defined in main.lang.php, see system/lang/ru/main.lang.php for example of these tables]]>
Mon, 30 Mar 2009 18:48:45 -0000
GHengeveld here and here. Of course this isn't the prettiest option, but at least it should work for all languages. The best thing to use would be the php command:
$output = preg_replace("/[^A-Za-z0-9]/", "", $input);
Even though it will remove illegal chars instead of replace them.

Also, you could have done with a lot less code if you had used jQuery... Something like:
$("input[name='newpagealias']").val('Default text');
]]>
Mon, 30 Mar 2009 17:13:43 -0000
Lombi Mon, 30 Mar 2009 17:11:14 -0000 Kingsley # Brock : I love you #2.

there's a lot of love here :p
Not that I mind.. Cotonti is a f***ing great system..


Ontopic:

niceeeeee..]]>
Mon, 30 Mar 2009 16:54:38 -0000
Brock Sun, 29 Mar 2009 23:14:53 -0000 Lombi Sun, 29 Mar 2009 21:47:12 -0000 musiconly I'm gonna shutdown the site on Sunday XD]]> Sun, 29 Mar 2009 19:53:57 -0000 Lombi
PAGE.ADD.TPL

Put this before <form

<script language=javascript>
	function setAlias(objvalue){
		document.newpage.newpagealias.value = makesafe(objvalue);
	}

	function makesafe(text)
{
    text = text.toLowerCase();
    text = text.replace(/č/g,   "c");
    text = text.replace(/š/g,   "s");
    text = text.replace(/ž/g,   "z");
    text = text.replace(/ć/g,   "c");
    text = text.replace(/đ/g,   "d");
    text = text.replace(/&/g,   " and ");
    text = text.replace(/%/g,   " percent ");
    text = text.replace(/\W/g,  "_");

    while (text.indexOf("__") >= 0)
    {
        text = text.replace(/__/g, "_");
    }
    
    if ((text.length > 0) && (text.lastIndexOf("_") == (text.length - 1)))
    {
        text = text.substr(0, text.length - 1);
    }

    
    return text;
}
}
</script>

PAGE.EDIT.TPL

Put this before <form

<script language=javascript>
	function setAlias(objvalue){
		document.update.rpagealias.value = makesafe(objvalue);
	}

	function makesafe(text)
{
    text = text.toLowerCase();
    text = text.replace(/č/g,   "c");
    text = text.replace(/š/g,   "s");
    text = text.replace(/ž/g,   "z");
    text = text.replace(/ć/g,   "c");
    text = text.replace(/đ/g,   "d");
    text = text.replace(/&/g,   " and ");
    text = text.replace(/%/g,   " percent ");
    text = text.replace(/\W/g,  "_");

    while (text.indexOf("__") >= 0)
    {
        text = text.replace(/__/g, "_");
    }
    
    if ((text.length > 0) && (text.lastIndexOf("_") == (text.length - 1)))
    {
        text = text.substr(0, text.length - 1);
    }

    
    return text;
} 
}
</script>
]]>
Sun, 29 Mar 2009 19:49:47 -0000