From 0a040966751e4a45fc9b9ac6cbaaea100b38ce53 Mon Sep 17 00:00:00 2001 From: Christian Hofmaier Date: Tue, 22 Jan 2019 16:12:28 +0100 Subject: [inc/Render] new optional argument to change rendered language --- inc/render.inc.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc') diff --git a/inc/render.inc.php b/inc/render.inc.php index 4b1d3643..4da0567e 100644 --- a/inc/render.inc.php +++ b/inc/render.inc.php @@ -213,7 +213,7 @@ class Render * @param string $module name of module to load template from; defaults to currently active module * @return string Rendered template */ - public static function parse($template, $params = false, $module = false) + public static function parse($template, $params = false, $module = false, $lang = false) { if ($module === false && class_exists('Page')) { $module = Page::getModule()->getIdentifier(); @@ -228,7 +228,7 @@ class Render } // Now find all language tags in this array if (preg_match_all('/{{\s*(lang_.+?)\s*}}/', $html, $out) > 0) { - $dictionary = Dictionary::getArray($module, 'template-tags'); + $dictionary = Dictionary::getArray($module, 'template-tags', $lang); $fallback = false; foreach ($out[1] as $tag) { if ($fallback === false && empty($dictionary[$tag])) { -- cgit v1.2.3-55-g7522 From 54a0a4c9b920bce1dc4e93d2cf05ebbea6502be0 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 28 Jan 2019 13:48:03 +0100 Subject: [inc/Util] readableFileSize: support input in KB/MB/... --- inc/util.inc.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'inc') diff --git a/inc/util.inc.php b/inc/util.inc.php index 1a5cbefe..e459cc46 100644 --- a/inc/util.inc.php +++ b/inc/util.inc.php @@ -234,9 +234,10 @@ SADFACE; * * @param float|int $bytes numeric value of the filesize to make readable * @param int $decimals number of decimals to show, -1 for automatic + * @param int $shift how many units to skip, i.e. if you pass in KiB or MiB * @return string human readable string representing the given file size */ - public static function readableFileSize($bytes, $decimals = -1) + public static function readableFileSize($bytes, $decimals = -1, $shift = 0) { $bytes = round($bytes); static $sz = array('Byte', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'); @@ -249,7 +250,7 @@ SADFACE; $decimals = 2 - floor(strlen((int)$bytes) - 1); } } - return sprintf("%.{$decimals}f", $bytes) . "\xe2\x80\x89" . $sz[$factor]; + return sprintf("%.{$decimals}f", $bytes) . "\xe2\x80\x89" . $sz[$factor + $shift]; } public static function sanitizeFilename($name) -- cgit v1.2.3-55-g7522 From 120956761383f8365e95e669a11b344af4764c74 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 30 Jan 2019 13:39:41 +0100 Subject: [inc/Dictionary] Teh evil unvalidated redirects must die! --- inc/dictionary.inc.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'inc') diff --git a/inc/dictionary.inc.php b/inc/dictionary.inc.php index fcbfdfb8..935d1f4e 100644 --- a/inc/dictionary.inc.php +++ b/inc/dictionary.inc.php @@ -30,10 +30,15 @@ class Dictionary if ($lang !== false && in_array($lang, self::$languages)) { setcookie('lang', $lang, time() + 60 * 60 * 24 * 30 * 12); $url = Request::get('url'); - if ($url === false && isset($_SERVER['HTTP_REFERER'])) + if ($url === false && isset($_SERVER['HTTP_REFERER'])) { $url = $_SERVER['HTTP_REFERER']; - if ($url === false) - $url = '?do=Main'; + } + $parts = parse_url($url); + if ($url === false || $parts === false || empty($parts['query'])) { + $url = '?do=main'; + } else { + $url = '?' . $parts['query']; + } Util::redirect($url); } -- cgit v1.2.3-55-g7522