[FIX] Add support for parameters in URL. Fix translation class #1
@ -3,9 +3,9 @@ class ClassTranslation extends ClassConfig implements InterfaceTranslation {
|
|||||||
public function __construct(){}
|
public function __construct(){}
|
||||||
public function __destruct(){}
|
public function __destruct(){}
|
||||||
|
|
||||||
public function getTranslationV2($message_code, $lang_code, $set_data, $db_table="core_translation"){
|
public function getTranslationV2($message_code, $lang_code, $set_data = array(), $db_table="core_translation"){
|
||||||
$this->_code = $code;
|
$this->_code = $message_code;
|
||||||
$this->_lang = $lang;
|
$this->_lang = $lang_code;
|
||||||
$this->_setData = $set_data;
|
$this->_setData = $set_data;
|
||||||
$this->_dbTable = $db_table;
|
$this->_dbTable = $db_table;
|
||||||
$oPDOLink = ClassConfig::databaseConnect();
|
$oPDOLink = ClassConfig::databaseConnect();
|
||||||
@ -104,28 +104,32 @@ class ClassTranslation extends ClassConfig implements InterfaceTranslation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getTranslation($code, $lang, $set_data = array()){
|
public function getTranslation($code, $lang = null, $set_data = array()){
|
||||||
$this->_code = $code;
|
$this->_code = $code;
|
||||||
$this->_lang = $lang;
|
$this->_lang = $lang ?? $_SESSION['config']['default_lang_code'];
|
||||||
$this->_setData = $set_data;
|
$this->_setData = $set_data;
|
||||||
|
|
||||||
if(!isset($_SESSION['translations'][$this->_code]) or $_SESSION['translations'][$this->_code]['source']==''){
|
//if translation not in SESSION, then go get it from DB
|
||||||
$row = $this->getTranslationInDatabase($this->_code, $this->_lang);
|
if(!isset($_SESSION['translations'][$this->_code]) or $_SESSION['translations'][$this->_code]['source']==''){
|
||||||
$_SESSION['translations'][$this->_code][$this->_lang] = $row[$this->_lang];
|
$row = $this->getTranslationInDatabase($this->_code, $this->_lang);
|
||||||
$_SESSION['translations'][$this->_code]['source'] = $row['source'];
|
$_SESSION['translations'][$this->_code][$this->_lang] = $row[$this->_lang];
|
||||||
}
|
$_SESSION['translations'][$this->_code]['source'] = $row['source'];
|
||||||
|
}
|
||||||
|
|
||||||
if($_SESSION['translations'][$this->_code][$this->_lang] != ''){
|
//if translation in current language, display it. Else, display source
|
||||||
$translation = $_SESSION['translations'][$this->_code][$this->_lang];
|
if($_SESSION['translations'][$this->_code][$this->_lang] != ''){
|
||||||
} else {
|
$translation = $_SESSION['translations'][$this->_code][$this->_lang];
|
||||||
$translation = $_SESSION['translations'][$this->_code]['source'];
|
} else {
|
||||||
|
$translation = $_SESSION['translations'][$this->_code]['source'];
|
||||||
|
}
|
||||||
|
|
||||||
|
//if [data] in content, get values set in array $set_data
|
||||||
|
$replacement_regex = '/\[data\]/';
|
||||||
|
foreach($this->_setData as $k=>$v){
|
||||||
|
$translation = preg_replace($replacement_regex, $this->_setData[$k], $translation, 1);
|
||||||
|
}
|
||||||
|
return $translation;
|
||||||
}
|
}
|
||||||
$replacement_regex = '/\[data\]/';
|
|
||||||
foreach($this->_setData as $k=>$v){
|
|
||||||
$translation = preg_replace($replacement_regex, $this->_setData[$k], $translation, 1);
|
|
||||||
}
|
|
||||||
return $translation;
|
|
||||||
}
|
|
||||||
|
|
||||||
//public function getTranslation($code, $lang){
|
//public function getTranslation($code, $lang){
|
||||||
// $this->_code = $code;
|
// $this->_code = $code;
|
||||||
|
@ -8,6 +8,7 @@ require_once './modules/ClassConfig.php';
|
|||||||
$oConf = new ClassConfig();
|
$oConf = new ClassConfig();
|
||||||
|
|
||||||
$file_path = substr_replace($_SERVER['REQUEST_URI'], '/', 0, strlen($oConf->getURLRoot()));
|
$file_path = substr_replace($_SERVER['REQUEST_URI'], '/', 0, strlen($oConf->getURLRoot()));
|
||||||
|
$file_path = explode('?', $file_path)[0];
|
||||||
|
|
||||||
$custom_file = $oConf->getPathCustom($file_path);
|
$custom_file = $oConf->getPathCustom($file_path);
|
||||||
$native_file = $oConf->getPathRoot($file_path);
|
$native_file = $oConf->getPathRoot($file_path);
|
||||||
|
@ -1,20 +1,19 @@
|
|||||||
<?php
|
<?php
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
require_once('../modules/InterfaceTranslation.php');
|
require_once('modules/InterfaceTranslation.php');
|
||||||
require_once('../modules/InterfacePostgreSQL.php');
|
require_once('modules/InterfacePostgreSQL.php');
|
||||||
require_once('../modules/InterfaceEmail.php');
|
require_once('modules/InterfaceEmail.php');
|
||||||
require_once('../modules/ClassConfig.php');
|
require_once('modules/ClassConfig.php');
|
||||||
require_once('../modules/ClassContent.php');
|
// require_once('modules/ClassContent.php');
|
||||||
require_once('../modules/ClassFeature.php');
|
require_once('modules/ClassFeature.php');
|
||||||
require_once('../modules/ClassFeatureTranslation.php');
|
require_once('modules/ClassFeatureTranslation.php');
|
||||||
require_once('../modules/ClassUser.php');
|
require_once('modules/ClassUser.php');
|
||||||
require_once('../modules/ClassTranslation.php');
|
require_once('modules/ClassTranslation.php');
|
||||||
|
|
||||||
$oFeat = new ClassFeature();
|
$oFeat = new ClassFeature();
|
||||||
$oFeatTrans = new ClassFeatureTranslation();
|
$oFeatTrans = new ClassFeatureTranslation();
|
||||||
$oUser = new ClassUser();
|
$oUser = new ClassUser();
|
||||||
$oContent = new ClassContent();
|
|
||||||
$oTrans = new ClassTranslation();
|
$oTrans = new ClassTranslation();
|
||||||
|
|
||||||
$oldLang = $_SESSION['config']['default_lang_code'];
|
$oldLang = $_SESSION['config']['default_lang_code'];
|
||||||
@ -31,7 +30,6 @@ if(isset($_SESSION['user'])){
|
|||||||
}
|
}
|
||||||
|
|
||||||
$_SESSION['config']['default_lang_code'] = $newLang;
|
$_SESSION['config']['default_lang_code'] = $newLang;
|
||||||
$_SESSION['content'] = $oContent->listContent($newLang);
|
|
||||||
$_SESSION['translations'] = $oTrans->listTranslations($newLang);
|
$_SESSION['translations'] = $oTrans->listTranslations($newLang);
|
||||||
|
|
||||||
$newPage = $oFeatTrans->getURLTranslation($oldLang, $newLang, $oldPage);
|
$newPage = $oFeatTrans->getURLTranslation($oldLang, $newLang, $oldPage);
|
||||||
|
Loading…
Reference in New Issue
Block a user