summaryrefslogtreecommitdiff
path: root/includes/helper
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2017-09-11 17:52:55 +0200
committerGitHub <noreply@github.com>2017-09-11 17:52:55 +0200
commit359160613027a480620e22deef19ff883eaaeb21 (patch)
tree310600aaa23404f0cd7d3e198bacdbc93645da32 /includes/helper
parent581b81f1b25dc6b6f0a3b34810c293738fd40217 (diff)
parent0a20883aa862779b48fd2a297456c2db04cffb95 (diff)
Merge pull request #344 from MyIgel/master
Prepared routing, added symfony http Closes #336 and closes #337
Diffstat (limited to 'includes/helper')
-rw-r--r--includes/helper/internationalization_helper.php25
-rw-r--r--includes/helper/message_helper.php32
2 files changed, 34 insertions, 23 deletions
diff --git a/includes/helper/internationalization_helper.php b/includes/helper/internationalization_helper.php
index d2dbcdbd..131941e9 100644
--- a/includes/helper/internationalization_helper.php
+++ b/includes/helper/internationalization_helper.php
@@ -1,5 +1,7 @@
<?php
+use Engelsystem\Http\Request;
+
/**
* Return currently active locale
*
@@ -7,7 +9,7 @@
*/
function locale()
{
- return $_SESSION['locale'];
+ return session()->get('locale');
}
/**
@@ -27,11 +29,12 @@ function gettext_init()
{
$locales = config('locales');
$request = request();
+ $session = session();
if ($request->has('set_locale') && isset($locales[$request->input('set_locale')])) {
- $_SESSION['locale'] = $request->input('set_locale');
- } elseif (!isset($_SESSION['locale'])) {
- $_SESSION['locale'] = config('default_locale');
+ $session->set('locale', $request->input('set_locale'));
+ } elseif (!$session->has('locale')) {
+ $session->set('locale', config('default_locale'));
}
gettext_locale();
@@ -48,7 +51,7 @@ function gettext_init()
function gettext_locale($locale = null)
{
if ($locale == null) {
- $locale = $_SESSION['locale'];
+ $locale = session()->get('locale');
}
putenv('LC_ALL=' . $locale);
@@ -62,14 +65,20 @@ function gettext_locale($locale = null)
*/
function make_langselect()
{
- $url = $_SERVER['REQUEST_URI'] . (strpos($_SERVER['REQUEST_URI'], '?') > 0 ? '&' : '?') . 'set_locale=';
+ $request = Request::getInstance();
$items = [];
foreach (config('locales') as $locale => $name) {
+ $url = url($request->getPathInfo(), ['set_locale' => $locale]);
+
$items[] = toolbar_item_link(
- htmlspecialchars($url) . $locale,
+ htmlspecialchars($url),
'',
- '<img src="pic/flag/' . $locale . '.png" alt="' . $name . '" title="' . $name . '"> ' . $name
+ sprintf(
+ '<img src="%s" alt="%s" title="%2$s"> %2$s',
+ url('pic/flag/' . $locale . '.png'),
+ $name
+ )
);
}
return $items;
diff --git a/includes/helper/message_helper.php b/includes/helper/message_helper.php
index 1f429c27..4fa0efe3 100644
--- a/includes/helper/message_helper.php
+++ b/includes/helper/message_helper.php
@@ -7,12 +7,12 @@
*/
function msg()
{
- if (!isset($_SESSION['msg'])) {
- return '';
- }
- $msg = $_SESSION['msg'];
- $_SESSION['msg'] = '';
- return $msg;
+ $session = session();
+
+ $message = $session->get('msg', '');
+ $session->set('msg', '');
+
+ return $message;
}
/**
@@ -57,21 +57,23 @@ function success($msg, $immediately = false)
* @param string $class
* @param string $msg
* @param bool $immediately
- * @return string|null
+ * @return string
*/
function alert($class, $msg, $immediately = false)
{
+ $session = session();
+
+ if (empty($msg)) {
+ return '';
+ }
+
if ($immediately) {
- if ($msg == '') {
- return '';
- }
return '<div class="alert alert-' . $class . '">' . $msg . '</div>';
}
- if (!isset($_SESSION['msg'])) {
- $_SESSION['msg'] = '';
- }
- $_SESSION['msg'] .= alert($class, $msg, true);
+ $message = $session->get('msg', '');
+ $message .= alert($class, $msg, true);
+ $session->set('msg', $message);
- return null;
+ return '';
}