From f8378672b1d34c7ec67629e87c73cdfd964de022 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Fri, 1 Aug 2014 14:22:19 -0500
Subject: [PATCH] i18n: Couple slight performance tweaks

---
 include/class.misc.php     | 3 ++-
 include/mysqli.php         | 6 +++++-
 setup/cli/modules/i18n.php | 6 +++---
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/include/class.misc.php b/include/class.misc.php
index 4ab741bbd..4664e7b6d 100644
--- a/include/class.misc.php
+++ b/include/class.misc.php
@@ -127,12 +127,13 @@ class Misc {
         ob_start();
         echo sprintf('<select name="%s" id="%s">',$name,$name);
         echo '<option value="" selected>'.__('Time').'</option>';
+        $format = $cfg->getTimeFormat();
         for($i=23; $i>=0; $i--) {
             for($minute=45; $minute>=0; $minute-=15) {
                 $sel=($hr==$i && $min==$minute)?'selected="selected"':'';
                 $_minute=str_pad($minute, 2, '0',STR_PAD_LEFT);
                 $_hour=str_pad($i, 2, '0',STR_PAD_LEFT);
-                $disp = date($cfg->getTimeFormat(), $i*3600 + $minute*60);
+                $disp = date($format, $i*3600 + $minute*60);
                 echo sprintf('<option value="%s:%s" %s>%s</option>',$_hour,$_minute,$sel,$disp);
             }
         }
diff --git a/include/mysqli.php b/include/mysqli.php
index e8bfeb32e..a6da0334d 100644
--- a/include/mysqli.php
+++ b/include/mysqli.php
@@ -250,8 +250,12 @@ function db_free_result($res) {
 }
 
 function db_output($var) {
+    static $no_magic_quotes = null;
 
-    if(!function_exists('get_magic_quotes_runtime') || !get_magic_quotes_runtime()) //Sucker is NOT on - thanks.
+    if (!isset($no_magic_quotes))
+        $no_magic_quotes = !function_exists('get_magic_quotes_runtime') || !get_magic_quotes_runtime();
+
+    if ($no_magic_quotes) //Sucker is NOT on - thanks.
         return $var;
 
     if (is_array($var))
diff --git a/setup/cli/modules/i18n.php b/setup/cli/modules/i18n.php
index dd5332eb8..c9152ac62 100644
--- a/setup/cli/modules/i18n.php
+++ b/setup/cli/modules/i18n.php
@@ -293,7 +293,7 @@ class i18n_Compiler extends Module {
         while (list(,$T) = each($tokens)) {
             switch ($T[0]) {
                 case T_CONSTANT_ENCAPSED_STRING:
-                    // String leading and trailing ' and " chars
+                    // Strip leading and trailing ' and " chars
                     $string['form'] = preg_replace(array("`^{$T[1][0]}`","`{$T[1][0]}$`"),array("",""), $T[1]);
                     $string['line'] = $T[2];
                     break;
@@ -434,8 +434,8 @@ class i18n_Compiler extends Module {
     function __write_string($string) {
         // Unescape single quote (') and escape unescaped double quotes (")
         $string = preg_replace(array("`\\\(['$])`", '`(?<!\\\)"`'), array("$1", '\"'), $string);
-        // Preserve embedded newlines
-        $string = preg_replace("`\n\s*`", "\\n\n", $string);
+        // Preserve embedded newlines -- preserve up to on
+        $string = preg_replace("`\n\s*`u", "\\n\n", $string);
         // Word-wrap long lines
         $string = rtrim(preg_replace('/(?=[\s\p{Ps}])(.{1,76})(\s|$|(\p{Ps}))/uS',
             "$1$2\n", $string), "\n");
-- 
GitLab