Created
March 10, 2014 15:43
-
-
Save jbroadway/9467440 to your computer and use it in GitHub Desktop.
Rewrite internal links to always include a language prefix (Elefant CMS).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Rewrite internal links to always include a language prefix. | |
* Save this to a handler such as apps/myapp/handlers/langprefix.php | |
* then edit conf/config.php and add the following to the [Hooks] | |
* section: | |
* | |
* page/render[] = myapp/langprefix | |
*/ | |
echo preg_replace_callback ( | |
'/a href=(\'|")\/([a-zA-Z0-9_-]{2,}|\1)/', | |
function ($matches) use ($i18n) { | |
if (! isset ($i18n->languages[$matches[2]])) { | |
return 'a href=' . $matches[1] . '/' . $i18n->language . '/' . $matches[2]; | |
} | |
return 'a href=' . $matches[1] . '/' . $matches[2]; | |
}, | |
$this->data['html'] | |
); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you!