Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Remove obsolete code from languages.php" #979

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading