mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-13 16:14:40 +00:00
mvc: fix lang= hint in HTML; closes #7336
This commit is contained in:
parent
df5680b123
commit
6de05e0437
@ -31,8 +31,8 @@ $di->set('url', function () use ($config) {
|
||||
* Setting up the view component
|
||||
*/
|
||||
$di->set('view', function () use ($config) {
|
||||
|
||||
$view = new View();
|
||||
|
||||
// if configuration defines more view locations, convert phalcon config items to array
|
||||
if (is_string($config->application->viewsDir)) {
|
||||
$view->setViewsDir($config->application->viewsDir);
|
||||
@ -43,24 +43,26 @@ $di->set('view', function () use ($config) {
|
||||
}
|
||||
$view->setViewsDir($viewDirs);
|
||||
}
|
||||
$view->registerEngines(array(
|
||||
'.volt' => function ($view) use ($config) {
|
||||
|
||||
$view->registerEngines([
|
||||
'.volt' => function ($view) use ($config) {
|
||||
$volt = new VoltEngine($view, $this);
|
||||
|
||||
$volt->setOptions(array(
|
||||
$volt->setOptions([
|
||||
'path' => $config->application->cacheDir,
|
||||
'separator' => '_'
|
||||
));
|
||||
// register additional volt template functions
|
||||
]);
|
||||
|
||||
// register additional volt template functions and filters
|
||||
$volt->getCompiler()->addFunction('theme_file_or_default', 'view_fetch_themed_filename');
|
||||
$volt->getCompiler()->addFunction('file_exists', 'view_file_exists');
|
||||
$volt->getCompiler()->addFunction('cache_safe', 'view_cache_safe');
|
||||
$volt->getCompiler()->addFilter('safe', 'view_html_safe');
|
||||
|
||||
return $volt;
|
||||
},
|
||||
'.phtml' => 'Phalcon\Mvc\View\Engine\Php'
|
||||
));
|
||||
'.phtml' => 'Phalcon\Mvc\View\Engine\Php',
|
||||
]);
|
||||
|
||||
return $view;
|
||||
}, true);
|
||||
@ -96,8 +98,6 @@ $di->setShared('session', function () {
|
||||
return $session;
|
||||
});
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Setup router
|
||||
*/
|
||||
|
||||
@ -230,6 +230,8 @@ class ControllerBase extends ControllerRoot
|
||||
$cnf = Config::getInstance();
|
||||
|
||||
$this->view->setVar('lang', $this->translator);
|
||||
$this->view->setVar('langcode', str_replace('_', '-', $this->langcode));
|
||||
|
||||
$rewrite_uri = explode("?", $_SERVER["REQUEST_URI"])[0];
|
||||
$this->view->menuSystem = $menu->getItems($rewrite_uri);
|
||||
/* XXX generating breadcrumbs requires getItems() call */
|
||||
|
||||
@ -45,7 +45,6 @@ class ControllerRoot extends Controller
|
||||
*/
|
||||
public $translator;
|
||||
|
||||
|
||||
/**
|
||||
* log handle
|
||||
*/
|
||||
@ -56,6 +55,11 @@ class ControllerRoot extends Controller
|
||||
*/
|
||||
protected $logged_in_user = null;
|
||||
|
||||
/**
|
||||
* current language code
|
||||
*/
|
||||
protected $langcode = 'en_US';
|
||||
|
||||
/**
|
||||
* Wrap close session, for long running operations.
|
||||
*/
|
||||
@ -70,7 +74,7 @@ class ControllerRoot extends Controller
|
||||
protected function setLang()
|
||||
{
|
||||
$config = Config::getInstance()->object();
|
||||
$lang = 'en_US';
|
||||
$lang = $this->langcode;
|
||||
|
||||
foreach ($config->system->children() as $key => $node) {
|
||||
if ($key == 'language') {
|
||||
@ -100,6 +104,8 @@ class ControllerRoot extends Controller
|
||||
/* somehow this is not done by Phalcon */
|
||||
bind_textdomain_codeset('OPNsense', $locale);
|
||||
putenv('LANG=' . $locale);
|
||||
|
||||
$this->langcode = $lang;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -38,8 +38,6 @@ class ViewTranslator extends Gettext
|
||||
{
|
||||
public function _($translateKey, array $placeholders = []): string
|
||||
{
|
||||
$translateValue = parent::_($translateKey, $placeholders);
|
||||
/* gettext() embedded in JavaScript can cause syntax errors */
|
||||
return str_replace("\n", ' ', htmlspecialchars($translateValue ?? '', ENT_QUOTES | ENT_HTML401));
|
||||
return view_html_safe(parent::_($translateKey, $placeholders));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<!doctype html>
|
||||
<html lang="en-US" class="no-js">
|
||||
<html lang="{{ langcode|safe }}" class="no-js">
|
||||
<head>
|
||||
|
||||
<meta charset="UTF-8" />
|
||||
|
||||
@ -46,6 +46,17 @@ function view_cache_safe($url)
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* return safe HTML encoded version of input string
|
||||
* @param string $text to make HTML safe
|
||||
* @return string
|
||||
*/
|
||||
function view_html_safe($text)
|
||||
{
|
||||
/* gettext() embedded in JavaScript can cause syntax errors */
|
||||
return str_replace("\n", ' ', htmlspecialchars($text ?? '', ENT_QUOTES | ENT_HTML401));
|
||||
}
|
||||
|
||||
try {
|
||||
/**
|
||||
* Read the configuration
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user