PHP 8. Conversion from float to int loses precision in file: line 1391. Fixed.
[fa-stable.git] / includes / JsHttpRequest.php
index c0a2036a35fac4a643d0e07254529f6b48a4d3a7..59d5b86edf168aeb34ffcd55a07543acd21a98bc 100644 (file)
@@ -15,7 +15,7 @@
  * This backend library also supports POST requests additionally to GET.
  *
  * @author Dmitry Koterov 
- * @version 5.x $Id$
+ * @version 5.x
  */
 
 class JsHttpRequest
@@ -63,7 +63,7 @@ class JsHttpRequest
      * If an object is created WITHOUT an active AJAX query, it is simply marked as
      * non-active. Use statuc method isActive() to check.
      */
-    function JsHttpRequest($enc)
+    function __construct($enc)
     {
         global $JsHttpRequest_Active;
         
@@ -71,7 +71,7 @@ class JsHttpRequest
         $GLOBALS['_RESULT'] =& $this->RESULT; 
         
         // Parse QUERY_STRING.
-        if (preg_match('/^(.*)(?:&|^)JsHttpRequest=(?:(\d+)-)?([^&]+)((?:&|$).*)$/s', @$_SERVER['QUERY_STRING'], $m)) {
+        if (array_key_exists('QUERY_STRING', $_SERVER) && preg_match('/^(.*)(?:&|^)JsHttpRequest=(?:(\d+)-)?([^&]+)((?:&|$).*)$/s', @$_SERVER['QUERY_STRING'], $m)) {
             $this->ID = $m[2];
             $this->LOADER = strtolower($m[3]);
             $_SERVER['QUERY_STRING'] = preg_replace('/^&+|&+$/s', '', preg_replace('/(^|&)'.session_name().'=[^&]*&?/s', '&', $m[1] . $m[4]));
@@ -187,7 +187,7 @@ class JsHttpRequest
         if ($this->SCRIPT_DECODE_MODE == 'entities')
             return str_replace(array('"', '<', '>'), array('&quot;', '&lt;', '&gt;'), $s);
         else
-            return htmlspecialchars($s);
+            return html_specials_encode($s);
     }
     
 
@@ -230,12 +230,12 @@ class JsHttpRequest
         $result = array();
         if ($isList) {
             foreach ($a as $v) {
-                $result[] = JsHttpRequest::php2js($v);
+                $result[] = $this->php2js($v);
             }
             return '[ ' . join(', ', $result) . ' ]';
         } else {
             foreach ($a as $k => $v) {
-                $result[] = JsHttpRequest::php2js($k) . ': ' . JsHttpRequest::php2js($v);
+                $result[] = $this->php2js($k) . ': ' . $this->php2js($v);
             }
             return '{ ' . join(', ', $result) . ' }';
         }
@@ -266,12 +266,14 @@ class JsHttpRequest
             '_POST'=> $rawPost,
         );
         foreach ($source as $dst=>$src) {
-            // First correct all 2-byte entities.
-            $s = preg_replace('/%(?!5B)(?!5D)([0-9a-f]{2})/si', '%u00\\1', $src);
-            // Now we can use standard parse_str() with no worry!
-            $data = null;
-            parse_str($s, $data);
-            $GLOBALS[$dst] = $this->_ucs2EntitiesDecode($data);
+            if ($src != NULL) {
+                // First correct all 2-byte entities.
+                $s = preg_replace('/%(?!5B)(?!5D)([0-9a-f]{2})/si', '%u00\\1', $src);
+                // Now we can use standard parse_str() with no worry!
+                $data = null;
+                parse_str($s, $data);
+                $GLOBALS[$dst] = $this->_ucs2EntitiesDecode($data);
+            }
         }
         $GLOBALS['HTTP_GET_VARS'] = $_GET; // deprecated vars
         $GLOBALS['HTTP_POST_VARS'] = $_POST;