Code: Select all
http://localhost:8888/cmsold/modules/babel/redirect.php?newlang=en_US&newurl=http://localhost:8888/cmsold/index.php?page=english/eng-home
Code: Select all
http://localhost:8888/cmsold/modules/babel/redirect.php?newlang=en_US&newurl=
Code: Select all
http://localhost:8888/cmsold/modules/babel/redirect.php?newlang=en_US&newurl=http://localhost:8888/cmsold/index.php?page=english/eng-home
Code: Select all
http://localhost:8888/cmsold/modules/babel/redirect.php?newlang=en_US&newurl=
Code: Select all
http://localhost:8888/cmsold/modules/babel/redirect.php?newlang=en_US&newurl=http://localhost:8888/cmsold/index.php?page=english/eng-home
Code: Select all
http://localhost:8888/cmsold/modules/babel/redirect.php?newlang=en_US&newurl=
Code: Select all
if($item->url && $use_cookies) $item->url = $gCms->config['root_url'].'/modules/babel/redirect.php?newlang='.$item->code.'&newurl='.$item->url;
Code: Select all
if($item->url && $use_cookies) $item->url = $item->url;
Code: Select all
http://localhost:8888/cmsold/index.php?page=english/eng-home
Code: Select all
<?php
if(!isset($_GET["newurl"]) ){
header("location: index.php");
}else{
if(isset($_GET["newlang"])) setcookie('usrlang',$_GET["newlang"],time()+86400*30,'/');
header("location: ".$_GET["newurl"]);
}
?>
Code: Select all
if($item->url && $use_cookies) $item->url = $gCms->config['root_url'].'/modules/babel/redirect.php?newlang='.$item->code.'&newurl='.$item->url;
Patricia wrote: plger, that module is simply one of the best thing that could happen to me
Code: Select all
/*
Assign the Smarty variable $page_lang depending on the root parent of the current page.
The root parent alias must be the language code (two letters).
2008-02-02 Marcos Cruz (http://alinome.net)
2012-09-20 by blast2007 (blastg [at] gmail [dot] com)
New features in this version:
- Works with v. 1.11.x and Smarty3
Reference:
http://wiki.cmsmadesimple.org/index.php/Share_your_tags_here#Get_a_page.27s_root_parent.27s_alias
*/
$gCms = cmsms();
global $smarty;
$manager =& $gCms->GetHierarchyManager();
$result = '??';
$thisPage = $gCms->variables['content_id'];
$currentNode = &$manager->sureGetNodeById($thisPage);
while( isset($currentNode) && $currentNode->getLevel() >= 0 )
{
$currentContent =& $currentNode->getContent();
$result = $currentContent->Alias();
$currentNode =& $currentNode->getParentNode();
}
$smarty->assign('page_lang',$result);
Code: Select all
/*
Create a language menu (version 6).
2008-02-06 Por/Far/By Marcos Cruz (http://alinome.net)
2012-09-20 by blast2007 (blastg [at] gmail [dot] com)
New features in this version 6:
- Works with v. 1.11.x and Smarty3
New features in this version 5:
- New parameter show_default.
- New parameter show_inactive.
Changes in the code in this version 5:
- Some forgotten doble quotes has been changed to single quotes for better perfomance.
- Doble and single quotes changed in the example HTML buttons.
- New constants DEFAULT_PAGE and BUTTON to make the code more readable without using keys in the language array.
- Language array and other variables renamed to make the code more readable.
- More comments to help beginners understand the code.
New features in version 4:
- Every language has a default page to be used when no translation has been specified for the current page,
or when the specified page doesn't exist.
- The HTML attribute hreflang is added to the links.
- The UDT parameter show_title now works in inactive links to the current page too.
Changes in the code in version 4:
- The function smarty_cms_selflink has been factored to make it easier to reuse the code.
- The conditional operator "?:" used instead of several if-structures.
- Code revised according to the PHP coding guidelines (spaces, string quotes, braces...)
- Optional debug points homogenized and marked with the word "DEBUG". Delete them if you want.
- New comments for beginners.
Possible future improvements:
- Spaces allowed in the template variable $other_languages (syntactic sugar to make it error-proof).
*/
$gCms = cmsms();
$db = cmsms()->GetDb();
$smarty = cmsms()->GetSmarty();
// ----------------------------------------------------------------
// Parameters
// Show the page title in the links? (true/false)
// (if false, show the defined buttons)
$show_title = isset($params['show_title']) ? $params['show_title'] : false;
// Show an inactive link to the current page in the menu? (true/false)
// (if false, don't create a menu entry for the current page)
$show_current = isset($params['show_current']) ? $params['show_current'] : false;
// If there's no valid translation, then show a link to the default page? (true/false)
// (if false, don't create a menu entry for that language)
$show_default = isset($params['show_default']) ? $params['show_default'] : true;
// If $show_default==false or there's no valid default page, then show an inactive link? (true/false)
// (if false, don't create a menu entry for that language)
$show_inactive = isset($params['show_inactive']) ? $params['show_inactive'] : true;
// ----------------------------------------------------------------
// Constants
define ("DEFAULT_PAGE",0);
define ("BUTTON",1);
// ----------------------------------------------------------------
// Language data common to all pages
/*
The array $languages keeps information about all languages of the site.
It is indexed by the language code.
Every item is an array that contains two items:
0) The optional default page for the language (used when there's no valid translation, if the parameter show_default is true). It can be empty (and then the parameter show_inactive will decide what to do).
1) The HTML code of the link button (used when the parameter show_title is false or unset).
To make the code more readable, these items are accessed with the constants DEFAULT_PAGE and BUTTON in the main loop.
*/
// Example data
$it='<img src="uploads/images/flags/it.png" alt="IT" />';
$en='<img src="uploads/images/flags/gb.png" alt="EN" />';
$fr='<img src="uploads/images/flags/fr.png" alt="FR" />' ;
$es='<img src="uploads/images/flags/es.png" alt="FR" />' ;
$languages = array(
// 'it' => array('Italiano', '<span xml:lang="it">' . $it . '</span>'),
'it' => array('Italiano', $it ),
// 'en' => array('English', '<span xml:lang="en">' . $en . '</span>'),
'en' => array('English', $en ),
// 'fr' => array('French', '<span xml:lang="fr">' . $fr . '</span>')
'fr' => array('French', $fr )
);
// ----------------------------------------------------------------
// Variables about the current page
$page_lang = $smarty->get_template_vars('page_lang'); // assigned in the template by the User Defined Tag {assign_page_lang}
// ----------------------------------------------------------------
// Language versions of the current page
/*
The template variable $other_languages is assigned with a content block in the template. eg.:
{content block='Other languages' oneline='true' assign=other_languages wysiwyg='false'}
For every page, it has to filled with a string in the following format:
"c1=page1;c2=page2;c3=page3" (no spaces allowed),
where c(n) are language codes (two letters);
any number of languages can be specified in any order.
That string is converted into the array $language_versions.
*/
$other_languages = $smarty->get_template_vars('other_languages');
foreach ( explode(';', $other_languages) as $other_language )
{
$language_codes[]=substr($other_language, 0, 2);
$language_pages[]=substr($other_language, 3);
}
if (!function_exists('array_combine')) {
function array_combine($keys, $values)
{
if (!is_array($keys)) {
user_error('array_combine() expects parameter 1 to be array, ' .
gettype($keys) . ' given', E_USER_WARNING);
return;
}
if (!is_array($values)) {
user_error('array_combine() expects parameter 2 to be array, ' .
gettype($values) . ' given', E_USER_WARNING);
return;
}
$key_count = count($keys);
$value_count = count($values);
if ($key_count !== $value_count) {
user_error('array_combine() Both parameters should have equal number of elements', E_USER_WARNING);
return false;
}
if ($key_count === 0 || $value_count === 0) {
user_error('array_combine() Both parameters should have number of elements at least 0', E_USER_WARNING);
return false;
}
$keys = array_values($keys);
$values = array_values($values);
$combined = array();
for ($i = 0; $i < $key_count; $i++) {
$combined[$keys[$i]] = $values[$i];
}
return $combined;
}
}
$language_versions = array_combine($language_codes, $language_pages);
/*
echo '<p><strong>DEBUG</strong>:';
echo "<br/>language_codes="; print_r($language_codes);
echo "<br/>language_pages="; print_r($language_pages);
echo "<br/>language_versions="; print_r($language_versions);
echo '</p>';
*/
// ----------------------------------------------------------------
function smarty_tag ($smarty_tag)
{
// Call a smarty tag.
// Reference:
// http://wiki.cmsmadesimple.org/index.php/User_Handbook/Admin_Panel/Extensions/User_Defined_Tags#How_to_Execute_Smarty_Tags_from_A_User_Defined_Tag_.28UDT.29
$gCms = cmsms();
$db = cmsms()->GetDb();
$smarty = cmsms()->GetSmarty();
@ob_start();
$smarty->display('eval:'.$smarty_tag);
$_contents = @ob_get_contents();
@ob_end_clean();
echo $_contents;
}
// ----------------------------------------------------------------
function smarty_cms_selflink ($page, $text, $more)
{
// Call the CMSMS tag {cms_selflink}.
/*
echo "<!--" ."\n";
echo '<p><strong>smarty_self_link DEBUG</strong>:'."\n";
echo "<br/>page=$page". "\n";
echo "<br/>text=$text" . "\n";
echo "<br/>more=$more" ."\n";
echo '</p>' ."\n";
echo "-->"."\n";
*/
smarty_tag ("{cms_selflink page=\"$page\"" .( (empty($text)) ? '' : " text='$text'" ) . ' more="' . $more . '"}');
}
// ----------------------------------------------------------------
function valid_page($page_alias)
{
// Is a page alias valid?
// References:
// http://forum.cmsmadesimple.org/index.php/topic,3778.msg20921.html#msg20921
$gCms = cmsms();
$manager =& $gCms->GetHierarchyManager();
$node =& $manager->getNodeByAlias($page_alias);
return ( $node != null );
}
// ----------------------------------------------------------------
function current_page_title()
{
// Return the title of the current page.
// This is needed only to print and inactive link to the current page when $show_title==true.
// References:
// http://forum.cmsmadesimple.org/index.php/topic,3778.msg20921.html#msg20921
// http://forum.cmsmadesimple.org/index.php/topic,3778.msg21051.html#msg21051
$gCms = cmsms();
$this_page = $gCms->variables['content_id'];
$manager =& $gCms->GetHierarchyManager();
$node =& $manager->GetNodeById($this_page);
$content =& $node->getContent();
return $content->Name();
}
// ----------------------------------------------------------------
// Create the menu
/*
echo '<p><strong>DEBUG</strong>:';
echo "<br/>page_lang=$page_lang";
echo "<br/>show_title=$show_title";
echo "<br/>show_current=$show_current";
echo "<br/>page_title=$page_title";
echo "<br/>language_versions="; print_r($language_versions);
echo "<br/>language_buttons="; print_r($language_buttons);
echo '</p>';
*/
echo "\n" . '<ul>'."\n";
foreach ( $languages as $language_code => $language ) // explore all possible languages of the site
{
// $language_code = code of the language to create a link for
// $language[DEFAULT_PAGE] = the default page used when no alternative has been defined for the language
// $language[BUTTON] = HTML used as button for the link, when $show_title==false.
/*
echo '<p><strong>menu DEBUG</strong>:';
echo "<br/>language_code=$language_code";
echo "<br/>language="; print_r($language);
echo '</p>';
*/
if ( $language_code != $page_lang )
{
$alternative_page = $language_versions[$language_code];
// echo "alternative_page=$alternative_page"; // DEBUG
if ( valid_page($alternative_page) )
{
echo '<li>'."\n";
// echo "ALTERNATIVE: $alternative_page"; // DEBUG
smarty_cms_selflink($alternative_page,($show_title == true ) ? "" : $language[BUTTON], "hreflang='".$language_code. "'");
echo '</li>'."\n";
}
else // no alternative page is valid for this language
{
if ( $show_default == true and valid_page($language[DEFAULT_PAGE]) )
{
echo '<li>'."\n";
// echo 'NO ALTERNATIVE! DEFAULT: '; // DEBUG
smarty_cms_selflink($language[DEFAULT_PAGE],( ($show_title == true ) ? "" : $language[BUTTON] ) , "hreflang='".$language_code."'");
echo '</li>'. "\n";
}
else
{
if ( $show_inactive == true )
{
echo '<li class="inactive">'."\n";
// echo 'DEFAULT CAN NOT BE USED! INACTIVE BUTTON: '; // DEBUG
echo $language[BUTTON] . '</li>'."\n";
}
}
}
}
elseif ( $show_current == true )
{
// echo 'SHOW CURRENT'; // DEBUG
echo '<li class="currentpage">' .'\n' . ( ($show_title == true) ? current_page_title() : $language[BUTTON] ) . '</li>'."\n";
}
}
echo '</ul>'."\n";