[FIX] Add support for parameters in URL. Fix translation class

This commit is contained in:
Michay Guzman 2021-06-28 08:58:37 +02:00
parent e750cf21e9
commit 3262c7d7a9
3 changed files with 38 additions and 35 deletions

View File

@ -3,9 +3,9 @@ class ClassTranslation extends ClassConfig implements InterfaceTranslation {
public function __construct(){}
public function __destruct(){}
public function getTranslationV2($message_code, $lang_code, $set_data, $db_table="core_translation"){
$this->_code = $code;
$this->_lang = $lang;
public function getTranslationV2($message_code, $lang_code, $set_data = array(), $db_table="core_translation"){
$this->_code = $message_code;
$this->_lang = $lang_code;
$this->_setData = $set_data;
$this->_dbTable = $db_table;
$oPDOLink = ClassConfig::databaseConnect();
@ -104,28 +104,32 @@ class ClassTranslation extends ClassConfig implements InterfaceTranslation {
}
public function getTranslation($code, $lang, $set_data = array()){
$this->_code = $code;
$this->_lang = $lang;
$this->_setData = $set_data;
public function getTranslation($code, $lang = null, $set_data = array()){
$this->_code = $code;
$this->_lang = $lang ?? $_SESSION['config']['default_lang_code'];
$this->_setData = $set_data;
if(!isset($_SESSION['translations'][$this->_code]) or $_SESSION['translations'][$this->_code]['source']==''){
$row = $this->getTranslationInDatabase($this->_code, $this->_lang);
$_SESSION['translations'][$this->_code][$this->_lang] = $row[$this->_lang];
$_SESSION['translations'][$this->_code]['source'] = $row['source'];
}
//if translation not in SESSION, then go get it from DB
if(!isset($_SESSION['translations'][$this->_code]) or $_SESSION['translations'][$this->_code]['source']==''){
$row = $this->getTranslationInDatabase($this->_code, $this->_lang);
$_SESSION['translations'][$this->_code][$this->_lang] = $row[$this->_lang];
$_SESSION['translations'][$this->_code]['source'] = $row['source'];
}
if($_SESSION['translations'][$this->_code][$this->_lang] != ''){
$translation = $_SESSION['translations'][$this->_code][$this->_lang];
} else {
$translation = $_SESSION['translations'][$this->_code]['source'];
//if translation in current language, display it. Else, display source
if($_SESSION['translations'][$this->_code][$this->_lang] != ''){
$translation = $_SESSION['translations'][$this->_code][$this->_lang];
} 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){
// $this->_code = $code;

View File

@ -8,6 +8,7 @@ require_once './modules/ClassConfig.php';
$oConf = new ClassConfig();
$file_path = substr_replace($_SERVER['REQUEST_URI'], '/', 0, strlen($oConf->getURLRoot()));
$file_path = explode('?', $file_path)[0];
$custom_file = $oConf->getPathCustom($file_path);
$native_file = $oConf->getPathRoot($file_path);

View File

@ -1,20 +1,19 @@
<?php
session_start();
require_once('../modules/InterfaceTranslation.php');
require_once('../modules/InterfacePostgreSQL.php');
require_once('../modules/InterfaceEmail.php');
require_once('../modules/ClassConfig.php');
require_once('../modules/ClassContent.php');
require_once('../modules/ClassFeature.php');
require_once('../modules/ClassFeatureTranslation.php');
require_once('../modules/ClassUser.php');
require_once('../modules/ClassTranslation.php');
require_once('modules/InterfaceTranslation.php');
require_once('modules/InterfacePostgreSQL.php');
require_once('modules/InterfaceEmail.php');
require_once('modules/ClassConfig.php');
// require_once('modules/ClassContent.php');
require_once('modules/ClassFeature.php');
require_once('modules/ClassFeatureTranslation.php');
require_once('modules/ClassUser.php');
require_once('modules/ClassTranslation.php');
$oFeat = new ClassFeature();
$oFeatTrans = new ClassFeatureTranslation();
$oUser = new ClassUser();
$oContent = new ClassContent();
$oTrans = new ClassTranslation();
$oldLang = $_SESSION['config']['default_lang_code'];
@ -31,7 +30,6 @@ if(isset($_SESSION['user'])){
}
$_SESSION['config']['default_lang_code'] = $newLang;
$_SESSION['content'] = $oContent->listContent($newLang);
$_SESSION['translations'] = $oTrans->listTranslations($newLang);
$newPage = $oFeatTrans->getURLTranslation($oldLang, $newLang, $oldPage);