Index: babel.module.php
===================================================================
--- babel.module.php (revision 8)
+++ babel.module.php (working copy)
@@ -203,6 +203,10 @@
$this->SetParameterType("assign",CLEAN_STRING);
$this->SetParameterType("newlang",CLEAN_STRING);
$this->SetParameterType("newurl",CLEAN_STRING);
+
+ //Parameters for page_id / page_alias
+ $this->SetParameterType("page",CLEAN_STRING);
+ $this->SetParameterType("lang",CLEAN_STRING);
}
function HandlesEvents(){
@@ -378,6 +382,11 @@
$this->Redirect($id, "defaultadmin", $returnid, $newparams);
break;
+ case "page_alias":
+ case "page_id":
+ require "action.page.php";
+ break;
+
case "default":
default:
if(isset($params["show"])){
@@ -642,20 +651,41 @@
}
}
- function get_urls($desired_lang=false){
+ function get_urls($desired_lang=false, $page_id_or_alias = false){
+ global $gCms;
+ $hierarchy = $gCms->variables['position'];
+ $other_languages = $gCms->smarty->get_template_vars('other_languages');
+ if( $page_id_or_alias !== false ) {
+ $manager =& $gCms->GetHierarchyManager();
+ $node =& $manager->sureGetNodeByAlias($page_id_or_alias);
+ if (isset($node)) {
+ $content =& $node->GetContent( false, false, true );
+ if ($content !== FALSE && is_object($content))
+ {
+ if( $content->HasProperty( "Other_languages" ) ) {
+ $other_languages = $content->GetPropertyValue( "Other_languages" );
+ }
+ $friendly_hierarchy = $content->Hierarchy();
+ if( isset( $friendly_hierarchy ) ) {
+ $contentops =& $gCms->GetContentOperations();
+ $hierarchy = $contentops->CreateUnfriendlyHierarchyPosition($friendly_hierarchy);
+ }
+ }
+ }
+ }
+
if($this->GetPreference('hierarchy_redirect',true)){
- return $this->hierarchy_get_links($desired_lang);
+ return $this->hierarchy_get_links($desired_lang, $hierarchy);
}else{
- return $this->manual_get_links($desired_lang);
+ return $this->manual_get_links($desired_lang, $other_languages);
}
}
- function hierarchy_get_links($desired_lang=false){
+ function hierarchy_get_links($desired_lang=false, $hierarchy){
// retrieves the url to the page in the desired language(s) equivalent to the current page,
// based on hierarchy
// if $desired_lang is false, links for all active languages will be returned
if(!$this->available_languages || count($this->available_languages) == 0) return false;
- global $gCms;
$db = $this->GetDb();
$base_url = $this->get_base_url();
$default_hide = $this->GetPreference('default_hide', false);
@@ -666,7 +696,7 @@
}
$module_links = $this->module_get_url();
if(count($module_links) == count($langs) && isset($module_links[$lang[0]['langcode']])) return $module_links;
- $current_position = explode('.', $gCms->variables['position']);
+ $current_position = explode('.', $hierarchy );
$output = array();
$rootids = array();
$hierarchies = array();
@@ -679,7 +709,7 @@
$where .= ($where == ""?"":" OR ")."content_id=?";
array_push($query_values, $onelang['root_id']);
}
- $query = "SELECT content_name, menu_text, content_id, hierarchy, hierarchy_path FROM " . cms_db_prefix()."content WHERE (".$where.")";
+ $query = "SELECT content_name, menu_text, content_id, hierarchy, hierarchy_path, content_alias FROM " . cms_db_prefix()."content WHERE (".$where.")";
$dbresult = $db->Execute($query, $query_values);
$query_values = array();
$where = "";
@@ -692,17 +722,19 @@
$hierarchies[$rootids[$row['content_id']]] = $new_hierarchy;
array_push($query_values,$new_hierarchy);
$newpaths[$new_hierarchy] = $rootids[$row['content_id']];
- $default_paths[$rootids[$row['content_id']]] = array("url"=>$base_url.$row["hierarchy_path"], "name"=>$row["content_name"], "menu_text"=>$row["menu_text"]);
+ $default_paths[$rootids[$row['content_id']]] = array("url"=>$base_url.$row["hierarchy_path"], "name"=>$row["content_name"], "menu_text"=>$row["menu_text"], "alias"=>$row["hierarchy_path"], "id"=>$row["content_id"]);
$where .= ($where == ""?"":" OR ")."hierarchy=?";
}
- $query = "SELECT content_id, content_name, menu_text, hierarchy, hierarchy_path FROM ".cms_db_prefix()."content WHERE (".$where.")";
+ $query = "SELECT content_id, content_name, menu_text, hierarchy, hierarchy_path, content_alias FROM ".cms_db_prefix()."content WHERE (".$where.")";
$dbresult = $db->Execute($query, $query_values);
- while($dbresult && $row = $dbresult->FetchRow()) $output[$newpaths[$row["hierarchy"]]] = array("url"=>$base_url.$row["hierarchy_path"], "name"=>$row["content_name"], "menu_text"=>$row["menu_text"]);
+ while($dbresult && $row = $dbresult->FetchRow()) $output[$newpaths[$row["hierarchy"]]] = array("url"=>$base_url.$row["hierarchy_path"], "name"=>$row["content_name"], "menu_text"=>$row["menu_text"], "alias"=>$row["content_alias"], "id"=>$row["content_id"]);
$final = array();
foreach($output as $lang=>$value){
if(isset($module_links[$lang])){
$value["url"] = $module_links[$lang]["url"];
$value["name"] = $module_links[$lang]["name"];
+ $value["alias"] = $module_links[$lang]["alias"];
+ $value["id"] = $module_links[$lang]["id"];
}
if($value["url"] == "" && $default_hide){
}elseif($value["url"] == ""){
@@ -715,12 +747,11 @@
}
- function manual_get_links($desired_lang=false){
+ function manual_get_links($desired_lang=false, $other_languages){
// retrieves the url to the page in the desired language(s) equivalent to the current page,
// based on Marcos Cruz manual procedure (see help)
// if $desired_lang is false, links for all active languages will be returned
if(!$this->available_languages || count($this->available_languages) == 0) return false;
- global $gCms;
$db = $this->GetDb();
$base_url = $this->get_base_url();
if($desired_lang && isset($this->available_languages[$desired_lang])){
@@ -737,22 +768,23 @@
$btn_text = $this->GetPreference("use_page_title",false)?"":$newlang['menu_name'];
// we retrieve the alternatives from the content block
- $other_languages = $gCms->smarty->get_template_vars('other_languages');
$alternatives = array();
$wherevalues = array();
$where = "";
foreach ( explode(';', $other_languages) as $onelang ){
$parts = explode('=',$onelang);
if(count($parts)==2){
- $where .= ($where==""?"":" OR ")."content_alias=?";
- $alternatives[$parts[1]] = $parts[0];
- array_push($wherevalues, $parts[1]);
+ if( array_key_exists( $parts[0], $langs ) ) {
+ $where .= ($where==""?"":" OR ")."content_alias=?";
+ $alternatives[$parts[1]] = $parts[0];
+ array_push($wherevalues, $parts[1]);
+ }
}
}
- $query = "SELECT menu_text, content_name, content_alias, hierarchy_path FROM ".cms_db_prefix()."content WHERE (".$where.")";
+ $query = "SELECT menu_text, content_name, content_alias, hierarchy_path, content_alias FROM ".cms_db_prefix()."content WHERE (".$where.")";
$dbresult = $db->Execute($query, $wherevalues);
while($dbresult && $row = $dbresult->FetchRow()){
- $output[$alternatives[$row["content_alias"]]] = array("url"=>$base_url.$row["hierarchy_path"], "name"=>$row["content_name"], "menu_text"=>$row["menu_text"]);
+ $output[$alternatives[$row["content_alias"]]] = array("url"=>$base_url.$row["hierarchy_path"], "name"=>$row["content_name"], "menu_text"=>$row["menu_text"], "alias"=>$row["content_alias"], "id"=>$row["content_id"]);
}
if($this->GetPreference('default_hide', false)) return $output;
@@ -769,10 +801,10 @@
}
if($where == "") return $output;
- $query = "SELECT menu_text, content_name, content_id, hierarchy, hierarchy_path FROM " . cms_db_prefix()."content WHERE (".$where.")";
+ $query = "SELECT menu_text, content_name, content_id, hierarchy, hierarchy_path, content_alias FROM " . cms_db_prefix()."content WHERE (".$where.")";
$dbresult = $db->Execute($query, $wherevalues);
while($dbresult && $row = $dbresult->FetchRow()){
- $output[$idtolang[$row["content_id"]]] = array("url"=>$base_url.$row["hierarchy_path"], "name"=>$row["content_name"], "menu_text"=>$row["menu_text"]);
+ $output[$idtolang[$row["content_id"]]] = array("url"=>$base_url.$row["hierarchy_path"], "name"=>$row["content_name"], "menu_text"=>$row["menu_text"], "alias"=>$row["content_alias"], "id"=>$row["content_id"]);
}
return $output;
}
Index: lang/en_US.php
===================================================================
--- lang/en_US.php (revision 8)
+++ lang/en_US.php (working copy)
@@ -102,6 +102,14 @@
<p>Root language pages (1. and 2.) should be section headers. You can name them (alias and all) any way you want.</p>
<p>In order to display menu correctly (that is, not to display language header pages and pages belonging to other languages), all you have to do is add the start_level=\"2\" to your menu tags:<br/>
{menu start_level=\"2\"}</p>
+ <p>Sometime, you cannot always use menus for navigation. If you have some \"hardcoded\" links in your pages, templates or global content blocks (that is, if you use {cms_selflink page=\".....\"}), all you have to do is get the page id (or alias) in a smarty variable and use it :<br/><br/>
+ <b>Before :</b> {cms_selflink page=\"index\"}<br/><br/>
+ <b>After :</b> {babel action=\"page_id\" page=\"index\" assign=\"id_of_my_page_index\"}{cms_selflink page=\$id_of_my_page_index}<br/>
+ or<br/>
+ {babel action=\"page_alias\" page=\"index\" assign=\"alias_of_my_page_index\"}{cms_selflink page=\$alias_of_my_page_index}<br/>
+ <br/>
+ ( You can also force the target language with the parameter lang=\"....\" : {babel lang=\"fr_FR\" action=\"page_alias\" page=\"index\" assign=\"alias_of_my_page_index_in_french\"}{cms_selflink page=\$alias_of_my_page_index_in_french} )<br/>
+</p>
<br/><h4>Part 2: setting up the languages</h4>
<p>Next, go to Extensions->Babel: Multilingual site. For each language, click Add Language and enter the appropriate informations. The \"Root page\" should be the section headers you've created for each language (1.English, 2.Français). The \"Default page\" should be the home page for each language. As of the language code, you could use any 5 characters code, but in order to provide good compatibility with the modules, you should use the same as the cms (you may use the drop down list on the top right to partially fill the form).</p>
<p>( *When ready, make sur you activate each language... )</p>
Index: lang/ext/fr_FR.php
===================================================================
--- lang/ext/fr_FR.php (revision 8)
+++ lang/ext/fr_FR.php (working copy)
@@ -95,6 +95,14 @@
<p>Les pages racine (1. and 2.) devrait être des en-têtes de section. Vous pouvez leur donner n'importe quel nom ou alias.</p>
<p>Pour afficher vos menus correctement (c'est-à-dire, pour ne pas afficher les pages racines et les pages d'une autre langue), il vous suffira d'ajouter start_level=\"2\" à vos balises de menu:<br/>
{menu start_level=\"2\"}</p>
+ <p>Il n'est pas toujours possible d'utiliser des menus pour la navigation. Si vous avez de liens \"en dur\" dans vos pages, gabarits ou blocs de contenu global (c'est-à-dire, si vous utilisez le tag {cms_selflink page=\".....\"}), il suffit de récupérer l'id (ou l'alias) de la page concernée dans une variable smarty et de l'utiliser :<br/><br/>
+ <b>Avant :</b> {cms_selflink page=\"index\"}<br/><br/>
+ <b>Après :</b> {babel action=\"page_id\" page=\"index\" assign=\"id_de_ma_page_index\"}{cms_selflink page=\$id_de_ma_page_index}<br/>
+ ou<br/>
+ {babel action=\"page_alias\" page=\"index\" assign=\"alias_de_ma_page_index\"}{cms_selflink page=\$alias_de_ma_page_index}<br/>
+ <br/>
+ ( Il est également possible de forcer la langue souhaitée, avec le paramètre lang=\"....\" : {babel lang=\"fr_FR\" action=\"page_alias\" page=\"index\" assign=\"alias_de_ma_page_index_en_francais\"}{cms_selflink page=\$alias_de_ma_page_index_en_francais} )<br/>
+</p>
<br/><h3>Étape 2: création des langues</h3>
<p>Ensuite, rendez-vous dans Extensions->Babel: Site multilingue. Pour chaque langue, cliquez Ajouter une langue et entrez les informations appropriées. La \"Page racine\" devrait être l'en-tête de section que vous avez créé pour chaque langue (1.English, 2.Français). La \"Page par défaut\" devrait être la page d'accueil pour chaque langue. En ce qui concerne le code de langue, vous pourriez utiliser n'importe quel code de 5 caractères, mais pour une bonne compatibilité avec les autres modules, il est préférable d'utiliser les mêmes que le cms (vous pouvez utiliser la liste déroulante en haut à droite pour remplir partiellement le formulaire).</p>
<p>( *Lorsque les langues sont prêtes à l'utilisation, n'oubliez pas de les activer...)</p>
Index: action.page.php
===================================================================
--- action.page.php (revision 0)
+++ action.page.php (revision 0)
@@ -0,0 +1,36 @@
+<?php
+if (!isset($gCms)) exit;
+if(!$this->current_langcode) $this->assign_page_lang();
+if(!$this->current_langcode) return false; // no page lang assigned... maybe we aren't in a page that has a particular language?
+$current_language = $this->current_langcode;
+
+$result = "";
+
+//Parameter : $lang
+if( isset( $params["lang"] ) && ($params["lang"]!="") ) {
+ $current_language = $params["lang"];
+}
+
+//Parameter : $page
+if( isset( $params["page"] ) ) {
+
+ // Get an array of information on the page corresponding to this Page-or-ID, in the current language
+ $links = $this->get_urls( $current_language, $params["page"] );
+
+ // If the result is valid, set $page to it.
+ if( isset( $links[ $current_language ] ) ) {
+ $newlink = $links[ $current_language ];
+ if( $action == "page_id" ) {
+ if( isset( $newlink[ "id" ] ) ) {
+ $result = $newlink[ "id" ];
+ }
+ } else {
+ if( isset( $newlink[ "alias" ] ) ) {
+ $result = $newlink[ "alias" ];
+ }
+ }
+ }
+}
+
+echo $result;
+?>
Property changes on: action.page.php
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native