Forums / Cotonti / Extensions / [RELEASE] AutoALIAS <- simple way to autocreate aliases

Lombi
#10679 2009-03-29 19:49
This is a great technique that I use to autofill the alias field from title. You can use it with the URL system that I just published.

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>
<a href="http://www.domenlo.com">Surreal Art</a>
This post was edited by Lombi (2009-03-31 02:13, 15 years ago)