Skip to content

Commit

Permalink
Revert "Remove obsolete code from languages.php (#962)"
Browse files Browse the repository at this point in the history
This reverts commit 41090df.
  • Loading branch information
marianaballa authored Aug 18, 2023
1 parent 41090df commit 2740616
Showing 1 changed file with 107 additions and 2 deletions.
109 changes: 107 additions & 2 deletions public_html/lists/admin/languages.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,54 @@ public function __construct()
} else {
$_SESSION['hasI18Ntable'] = false;
}

if (isset($_GET['origpage']) && !empty($_GET['ajaxed'])) { //# used in ajaxed requests
$page = basename($_GET['origpage']);
} elseif (isset($_GET['page'])) {
$page = basename($_GET['page']);
} else {
$page = 'home';
}
//# as we're including things, let's make sure it's clean
$page = preg_replace('/\W/', '', $page);

if (!empty($_GET['pi'])) {
$plugin_languagedir = $this->getPluginBasedir();
if (is_dir($plugin_languagedir)) {
$this->basedir = $plugin_languagedir;
if (isset($GLOBALS['plugins'][$_GET['pi']])) {
$plugin = $GLOBALS['plugins'][$_GET['pi']];
if ($plugin->enabled && $plugin->needI18N && $plugin->i18nLanguageDir()) {
$this->basedir = $plugin->i18nLanguageDir();
}
}
}
}

$lan = array();

if (is_file($this->basedir.$this->language.'/'.$page.'.php')) {
@include $this->basedir.$this->language.'/'.$page.'.php';
} elseif (!isset($GLOBALS['developer_email'])) {
@include $this->basedir.$this->defaultlanguage.'/'.$page.'.php';
}
$this->lan = $lan;
$lan = array();

if (is_file($this->basedir.$this->language.'/common.php')) {
@include $this->basedir.$this->language.'/common.php';
} elseif (!isset($GLOBALS['developer_email'])) {
@include $this->basedir.$this->defaultlanguage.'/common.php';
}
$this->lan += $lan;
$lan = array();

if (is_file($this->basedir.$this->language.'/frontend.php')) {
@include $this->basedir.$this->language.'/frontend.php';
} elseif (!isset($GLOBALS['developer_email'])) {
@include $this->basedir.$this->defaultlanguage.'/frontend.php';
}
$this->lan += $lan;
}

public function gettext($text)
Expand Down Expand Up @@ -458,6 +506,21 @@ public function appendText($file, $text)
file_put_contents($file, $filecontents);
}

public function getPluginBasedir()
{
$pl = $_GET['pi'];
$pl = preg_replace('/\W/', '', $pl);
$pluginroot = '';
if (isset($GLOBALS['plugins'][$pl]) && is_object($GLOBALS['plugins'][$pl])) {
$pluginroot = $GLOBALS['plugins'][$pl]->coderoot;
}
if (is_dir($pluginroot.'/lan/')) {
return $pluginroot.'/lan/';
} else {
return $pluginroot.'/';
}
}

public function initFSTranslations($language = '')
{
if (empty($language)) {
Expand All @@ -482,7 +545,7 @@ public function updateDBtranslations($translations, $time, $language = '')
saveConfig('lastlanguageupdate-'.$language, $time, 0);
}

public function getTranslation($text)
public function getTranslation($text, $page, $basedir)
{

//# try DB, as it will be the latest
Expand Down Expand Up @@ -512,6 +575,24 @@ public function getTranslation($text)
}
}

$lan = $this->lan;

if (trim($text) == '') {
return '';
}
if (strip_tags($text) == '') {
return $text;
}
if (isset($lan[$text])) {
return $this->formatText($lan[$text]);
}
if (isset($lan[strtolower($text)])) {
return $this->formatText($lan[strtolower($text)]);
}
if (isset($lan[strtoupper($text)])) {
return $this->formatText($lan[strtoupper($text)]);
}

return '';
}

Expand All @@ -523,12 +604,36 @@ public function get($text)
if (strip_tags($text) == '') {
return $text;
}
$translation = '';

$this->basedir = dirname(__FILE__).'/lan/';
if (isset($_GET['origpage']) && !empty($_GET['ajaxed'])) { //# used in ajaxed requests
$page = basename($_GET['origpage']);
} elseif (isset($_GET['page'])) {
$page = basename($_GET['page']);
} else {
$page = 'home';
}
$page = preg_replace('/\W/', '', $page);

if (!empty($_GET['pi'])) {
$plugin_languagedir = $this->getPluginBasedir();
if (is_dir($plugin_languagedir)) {
$translation = $this->getTranslation($text, $page, $plugin_languagedir);
}
}

//# if a plugin did not return the translation, find it in core
if (empty($translation)) {
$translation = $this->getTranslation($text, $page, $this->basedir);
}

// print $this->language.' '.$text.' '.$translation. '<br/>';

// spelling mistake, retry with old spelling
if ($text == 'over threshold, user marked unconfirmed' && empty($translation)) {
return $this->get('over treshold, user marked unconfirmed');
}
$translation = $this->getTranslation($text);

if (!empty($translation)) {
return $translation;
Expand Down

0 comments on commit 2740616

Please sign in to comment.