From 9df9b9b533c2d8c63ea1cb3032447022689b7061 Mon Sep 17 00:00:00 2001
From: Ralf Becker <ralfbecker@outdoor-training.de>
Date: Mon, 15 Dec 2014 09:08:12 +0000
Subject: [PATCH] fix some PHP 5.6 Deprecated and IDE warnings

---
 phpgwapi/inc/HTTP/WebDAV/Server.php | 71 +++++++++++++++--------------
 phpgwapi/inc/horde/Horde/String.php | 46 +++++++++----------
 2 files changed, 60 insertions(+), 57 deletions(-)

diff --git a/phpgwapi/inc/HTTP/WebDAV/Server.php b/phpgwapi/inc/HTTP/WebDAV/Server.php
index a9f6eefe04..132ef044cf 100644
--- a/phpgwapi/inc/HTTP/WebDAV/Server.php
+++ b/phpgwapi/inc/HTTP/WebDAV/Server.php
@@ -190,7 +190,7 @@ class HTTP_WebDAV_Server
      *
      * dispatch WebDAV HTTP request to the apropriate method handler
      *
-     * @param  $prefix=null prefix filesystem path with given path, eg. "/webdav" for owncloud 4.5 remote.php
+     * @param  $prefix =null prefix filesystem path with given path, eg. "/webdav" for owncloud 4.5 remote.php
      * @return void
      */
     function ServeRequest($prefix=null)
@@ -213,18 +213,19 @@ class HTTP_WebDAV_Server
         // seem to pass '?' unencoded, so we need to extract the path info out
         // of the request URI ourselves
         // if request URI contains a full url, remove schema and domain
+		$matches = null;
         if (preg_match('|^https?://[^/]+(/.*)$|', $path_info=$this->_SERVER["REQUEST_URI"], $matches))
         {
         	$path_info = $matches[1];
         }
-        $path_info = substr($path_info, strlen($this->_SERVER["SCRIPT_NAME"]));
+        $path_info_raw = substr($path_info, strlen($this->_SERVER["SCRIPT_NAME"]));
 
         // just in case the path came in empty ...
-        if (empty($path_info)) {
-            $path_info = "/";
+        if (empty($path_info_raw)) {
+            $path_info_raw = "/";
         }
 
-        $path_info = $this->_urldecode($path_info);
+        $path_info = self::_urldecode($path_info_raw);
 
         if ($prefix && strpos($path_info, $prefix) === 0)
         {
@@ -237,7 +238,7 @@ class HTTP_WebDAV_Server
 
         // set path
         // $_SERVER['PATH_INFO'] is already urldecoded
-        //$this->path = $this->_urldecode($path_info);
+        //$this->path = self::_urldecode($path_info);
         // quote '#' (e.g. OpenOffice uses this for lock-files)
         $this->path = strtr($path_info,array(
         	'%' => '%25',
@@ -306,7 +307,6 @@ class HTTP_WebDAV_Server
         } else { // method not found/implemented
             if ($this->_SERVER["REQUEST_METHOD"] == "LOCK") {
             	$error = '412 Precondition failed';
-                ;
             } else {
                 $error = '405 Method not allowed';
                 header("Allow: ".join(", ", $this->_allow()));  // tell client what's allowed
@@ -650,7 +650,7 @@ class HTTP_WebDAV_Server
     /**
      * PROPFIND method handler
      *
-     * @param  string $handler='PROPFIND' allows to use method eg. for CalDAV REPORT
+     * @param  string $handler ='PROPFIND' allows to use method eg. for CalDAV REPORT
      * @return void
      */
     function http_PROPFIND($handler='PROPFIND')
@@ -691,7 +691,7 @@ class HTTP_WebDAV_Server
                 if (is_array($lock) && count($lock)) {
                     $created          = isset($lock['created'])  ? $lock['created']  : time();
                     $modified         = isset($lock['modified']) ? $lock['modified'] : time();
-                    $files['files'][] = array("path"  => $this->_slashify($this->path),
+                    $files['files'][] = array("path"  => self::_slashify($this->path),
                                               "props" => array($this->mkprop("displayname",      $this->path),
                                                                $this->mkprop("creationdate",     $created),
                                                                $this->mkprop("getlastmodified",  $modified),
@@ -917,10 +917,10 @@ class HTTP_WebDAV_Server
             /* TODO right now the user implementation has to make sure
              collections end in a slash, this should be done in here
              by checking the resource attribute */
-            $href = $this->_mergePaths($this->base_uri, $path);
+            $href_raw = $this->_mergePaths($this->base_uri, $path);
 
             /* minimal urlencoding is needed for the resource path */
-            $href = $this->_urlencode($href);
+            $href = $this->_urlencode($href_raw);
 
             if ($this->crrnd)
             {
@@ -1240,7 +1240,7 @@ class HTTP_WebDAV_Server
 	 * we can NOT send Content-Length headers, as the have to reflect size
 	 * AFTER applying compression/transfer encoding.
 	 *
-	 * @param boolean $set=null
+	 * @param boolean $set =null
 	 * @return boolean true if we use compression, false otherwise
 	 */
 	public static function use_compression($set=null)
@@ -1322,7 +1322,7 @@ class HTTP_WebDAV_Server
                                            . (isset($options['size']) ? $options['size'] : "*"));
                                     while ($size && !feof($options['stream'])) {
                                         $buffer = fread($options['stream'], 4096);
-                                        $size  -= $this->bytes($buffer);
+                                        $size  -= self::bytes($buffer);
                                         echo $buffer;
                                     }
                                 } else {
@@ -1358,7 +1358,7 @@ class HTTP_WebDAV_Server
                                 fseek($options['stream'], $from, SEEK_SET);
                                 while ($size && !feof($options['stream'])) {
                                     $buffer = fread($options['stream'], 4096);
-                                    $size  -= $this->bytes($buffer);
+                                    $size  -= self::bytes($buffer);
                                     echo $buffer;
                                 }
                             }
@@ -1376,7 +1376,7 @@ class HTTP_WebDAV_Server
                     if (is_array($options['data'])) {
                         // reply to partial request
                     } else {
-                        if (!self::use_compression()) header("Content-Length: ".$this->bytes($options['data']));
+                        if (!self::use_compression()) header("Content-Length: ".self::bytes($options['data']));
                         echo $options['data'];
                     }
                 }
@@ -1406,6 +1406,7 @@ class HTTP_WebDAV_Server
         if (isset($this->_SERVER['HTTP_RANGE'])) {
 
             // we only support standard "bytes" range specifications for now
+			$matches = null;
             if (preg_match('/bytes\s*=\s*(.+)/', $this->_SERVER['HTTP_RANGE'], $matches)) {
                 $options["ranges"] = array();
 
@@ -1613,6 +1614,7 @@ class HTTP_WebDAV_Server
 			        // single byte range requests are supported
 			        // the header format is also specified in RFC 2616 14.16
 			        // TODO we have to ensure that implementations support this or send 501 instead
+					$matches = null;
 			        if (!preg_match('@bytes\s+(\d+)-(\d+)/((\d+)|\*)@', $val, $matches)) {
 				        $this->http_status('400 bad request');
 				        echo 'The service does only support single byte ranges';
@@ -1623,7 +1625,7 @@ class HTTP_WebDAV_Server
 			        if (is_numeric($matches[3])) {
 				        $range['total_length'] = $matches[3];
 			        }
-			        $option['ranges'][] = $range;
+			        $options['ranges'][] = $range;
 
 			        // TODO make sure the implementation supports partial POST
 			        // this has to be done in advance to avoid data being overwritten
@@ -1792,6 +1794,7 @@ class HTTP_WebDAV_Server
                     // single byte range requests are supported
                     // the header format is also specified in RFC 2616 14.16
                     // TODO we have to ensure that implementations support this or send 501 instead
+					$matches = null;
                     if (!preg_match('@bytes\s+(\d+)-(\d+)/((\d+)|\*)@', $val, $matches)) {
                         $this->http_status("400 bad request");
                         echo "The service does only support single byte ranges";
@@ -2156,7 +2159,7 @@ class HTTP_WebDAV_Server
 	        }
 	        $content .=  '</'.($this->crrnd?'':'D:')."error>\n";
         }
-        if (!self::use_compression()) header("Content-Length: ".$this->bytes($content));
+        if (!self::use_compression()) header("Content-Length: ".self::bytes($content));
         if ($content) echo $options['content'];
     }
 
@@ -2189,7 +2192,7 @@ class HTTP_WebDAV_Server
                 $http_host.= ":".$url["port"];
         } else {
             // only path given, set host to self
-            $http_host == $http_header_host;
+            $http_host = $http_header_host;
         }
 
         if ($http_host == $http_header_host &&
@@ -2267,7 +2270,7 @@ class HTTP_WebDAV_Server
      * @praram boolen  property raw-flag
      * @return array   property array
      */
-    function mkprop()
+    public static function mkprop()
     {
 	    $args = func_get_args();
 	    switch (count($args)) {
@@ -2323,7 +2326,7 @@ class HTTP_WebDAV_Server
      * @param  void
      * @return string  a new UUID
      */
-    function _new_uuid()
+    public static function _new_uuid()
     {
         // use uuid extension from PECL if available
         if (function_exists("uuid_create")) {
@@ -2353,9 +2356,9 @@ class HTTP_WebDAV_Server
      * @param  void
      * @return string  new RFC2518 opaque lock token
      */
-    function _new_locktoken()
+    public static function _new_locktoken()
     {
-        return "opaquelocktoken:".HTTP_WebDAV_Server::_new_uuid();
+        return "opaquelocktoken:".self::_new_uuid();
     }
 
     // }}}
@@ -2558,6 +2561,7 @@ class HTTP_WebDAV_Server
      */
     function _check_uri_condition($uri, $condition)
     {
+		unset($uri);	// not used, but required by function signature
         // not really implemented here,
         // implementations must override
 
@@ -2694,7 +2698,7 @@ class HTTP_WebDAV_Server
      * @param  string  URL to encode
      * @return string  encoded URL
      */
-    function _urlencode($url)
+    public static function _urlencode($url)
     {
     	// cadaver (and probably all neon using agents) need a more complete url encoding
     	// otherwise special chars like "$,()'" in filenames do NOT work
@@ -2724,7 +2728,7 @@ class HTTP_WebDAV_Server
      * @param  string  URL to decode
      * @return string  decoded URL
      */
-    function _urldecode($path)
+    public static function _urldecode($path)
     {
         return rawurldecode($path);
     }
@@ -2850,10 +2854,10 @@ class HTTP_WebDAV_Server
      * @param   string directory path
      * @returns string directory path wiht trailing slash
      */
-    function _slashify($path)
+    public static function _slashify($path)
     {
 		//error_log(__METHOD__." called with $path");
-		if ($path[$this->bytes($path)-1] != '/') {
+		if ($path[self::bytes($path)-1] != '/') {
 			//error_log(__METHOD__." added slash at the end of path");
 			$path = $path."/";
 		}
@@ -2866,10 +2870,10 @@ class HTTP_WebDAV_Server
      * @param   string directory path
      * @returns string directory path wihtout trailing slash
      */
-    function _unslashify($path)
+    public static function _unslashify($path)
     {
         //error_log(__METHOD__." called with $path");
-        if ($path[$this->bytes($path)-1] == '/') {
+        if ($path[self::bytes($path)-1] == '/') {
             $path = substr($path, 0, -1);
 			//error_log(__METHOD__." removed slash at the end of path");
         }
@@ -2883,14 +2887,14 @@ class HTTP_WebDAV_Server
      * @param  string  child path
      * @return string  merged path
      */
-    function _mergePaths($parent, $child)
+    public static function _mergePaths($parent, $child)
     {
         //error_log("merge called :\n$parent \n$child\n" . function_backtrace());
         //error_log("merge :\n".print_r($this->_mergePaths($this->_SERVER["SCRIPT_NAME"], $this->path)true));
         if ($child{0} == '/') {
-            return $this->_unslashify($parent).$child;
+            return self::_unslashify($parent).$child;
         } else {
-            return $this->_slashify($parent).$child;
+            return self::_slashify($parent).$child;
         }
     }
 
@@ -2900,9 +2904,9 @@ class HTTP_WebDAV_Server
      * @param string $str
      * @return int
      */
-    function bytes($str)
+    public static function bytes($str)
     {
-    	static $func_overload;
+    	static $func_overload=null;
 
     	if (is_null($func_overload))
     	{
@@ -2918,4 +2922,3 @@ class HTTP_WebDAV_Server
  * c-basic-offset: 4
  * End:
  */
-?>
diff --git a/phpgwapi/inc/horde/Horde/String.php b/phpgwapi/inc/horde/Horde/String.php
index 237541a418..608ac222f3 100644
--- a/phpgwapi/inc/horde/Horde/String.php
+++ b/phpgwapi/inc/horde/Horde/String.php
@@ -28,7 +28,7 @@ class String {
      *
      * @see Util::extensionExists()
      */
-    function extensionExists($ext)
+    public static function extensionExists($ext)
     {
         static $cache = array();
 
@@ -45,7 +45,7 @@ class String {
      *
      * @param string $charset  The charset to use as the default one.
      */
-    function setDefaultCharset($charset)
+    public static function setDefaultCharset($charset)
     {
         $GLOBALS['_HORDE_STRING_CHARSET'] = $charset;
         if (String::extensionExists('mbstring') &&
@@ -73,7 +73,7 @@ class String {
      *
      * @return mixed  The converted input data.
      */
-    function convertCharset($input, $from, $to = null)
+    public static function convertCharset($input, $from, $to = null)
     {
         /* Don't bother converting numbers. */
         if (is_numeric($input)) {
@@ -127,7 +127,7 @@ class String {
     }
 
     /**
-     * Internal function used to do charset conversion.
+     * Internal public static function used to do charset conversion.
      *
      * @access private
      *
@@ -137,7 +137,7 @@ class String {
      *
      * @return string  The converted string.
      */
-    function _convertCharset($input, $from, $to)
+    public static function _convertCharset($input, $from, $to)
     {
         $output = '';
         $from_check = (($from == 'iso-8859-1') || ($from == 'us-ascii'));
@@ -145,7 +145,7 @@ class String {
 
         /* Use utf8_[en|de]code() if possible and if the string isn't too
          * large (less than 16 MB = 16 * 1024 * 1024 = 16777216 bytes) - these
-         * functions use more memory. */
+         * public static functions use more memory. */
         if (strlen($input) < 16777216 || !(String::extensionExists('iconv') || String::extensionExists('mbstring'))) {
             if ($from_check && ($to == 'utf-8')) {
                 return utf8_encode($input);
@@ -201,7 +201,7 @@ class String {
      *
      * @return string  The string with lowercase characters
      */
-    function lower($string, $locale = false, $charset = null)
+    public static function lower($string, $locale = false, $charset = null)
     {
         static $lowers;
 
@@ -246,7 +246,7 @@ class String {
      *
      * @return string  The string with uppercase characters
      */
-    function upper($string, $locale = false, $charset = null)
+    public static function upper($string, $locale = false, $charset = null)
     {
         static $uppers;
 
@@ -291,7 +291,7 @@ class String {
      *
      * @return string  The capitalized string.
      */
-    function ucfirst($string, $locale = false, $charset = null)
+    public static function ucfirst($string, $locale = false, $charset = null)
     {
         if ($locale) {
             $first = String::substr($string, 0, 1, $charset);
@@ -316,7 +316,7 @@ class String {
      *
      * @return string  The string's part.
      */
-    function substr($string, $start, $length = null, $charset = null)
+    public static function substr($string, $start, $length = null, $charset = null)
     {
         if (is_null($length)) {
             $length = String::length($string, $charset) - $start;
@@ -367,7 +367,7 @@ class String {
      *
      * @return string  The string's part.
      */
-    function length($string, $charset = null)
+    public static function length($string, $charset = null)
     {
         if (is_null($charset)) {
             $charset = $GLOBALS['_HORDE_STRING_CHARSET'];
@@ -400,7 +400,7 @@ class String {
      *
      * @return integer  The position of first occurrence.
      */
-    function pos($haystack, $needle, $offset = 0, $charset = null)
+    public static function pos($haystack, $needle, $offset = 0, $charset = null)
     {
         if (String::extensionExists('mbstring')) {
             if (is_null($charset)) {
@@ -434,7 +434,7 @@ class String {
      *
      * @return string  The padded string.
      */
-    function pad($input, $length, $pad = ' ', $type = STR_PAD_RIGHT,
+    public static function pad($input, $length, $pad = ' ', $type = STR_PAD_RIGHT,
                  $charset = null)
     {
         $mb_length = String::length($input, $charset);
@@ -491,7 +491,7 @@ class String {
      *
      * @return string  String containing the wrapped text.
      */
-    function wordwrap($string, $width = 75, $break = "\n", $cut = false,
+    public static function wordwrap($string, $width = 75, $break = "\n", $cut = false,
                       $charset = null, $line_folding = false)
     {
         /* Get the user's default character set if none passed in. */
@@ -560,7 +560,7 @@ class String {
      *
      * @return string  String containing the wrapped text.
      */
-    function wrap($text, $length = 80, $break_char = "\n", $charset = null,
+    public static function wrap($text, $length = 80, $break_char = "\n", $charset = null,
                   $quote = false)
     {
         $paragraphs = array();
@@ -593,7 +593,7 @@ class String {
      *
      * @return boolean  True if the parameter was alphabetic only.
      */
-    function isAlpha($string, $charset = null)
+    public static function isAlpha($string, $charset = null)
     {
         if (!String::extensionExists('mbstring')) {
             return ctype_alpha($string);
@@ -625,7 +625,7 @@ class String {
      *
      * @return boolean  True if the parameter was lowercase.
      */
-    function isLower($string, $charset = null)
+    public static function isLower($string, $charset = null)
     {
         return ((String::lower($string, true, $charset) === $string) &&
                 String::isAlpha($string, $charset));
@@ -640,7 +640,7 @@ class String {
      *
      * @return boolean  True if the parameter was uppercase.
      */
-    function isUpper($string, $charset = null)
+    public static function isUpper($string, $charset = null)
     {
         return ((String::upper($string, true, $charset) === $string) &&
                 String::isAlpha($string, $charset));
@@ -658,7 +658,7 @@ class String {
      *
      * @return array  The matches array from the first regex that matches.
      */
-    function regexMatch($text, $regex, $charset = null)
+    public static function regexMatch($text, $regex, $charset = null)
     {
         if (!empty($charset)) {
             $regex = String::convertCharset($regex, $charset, 'utf-8');
@@ -680,17 +680,17 @@ class String {
     }
 
     /**
-     * Workaround charsets that don't work with mbstring functions.
+     * Workaround charsets that don't work with mbstring public static functions.
      *
      * @access private
      *
      * @param string $charset  The original charset.
      *
-     * @return string  The charset to use with mbstring functions.
+     * @return string  The charset to use with mbstring public static functions.
      */
-    function _mbstringCharset($charset)
+    public static function _mbstringCharset($charset)
     {
-        /* mbstring functions do not handle the 'ks_c_5601-1987' &
+        /* mbstring public static functions do not handle the 'ks_c_5601-1987' &
          * 'ks_c_5601-1989' charsets. However, these charsets are used, for
          * example, by various versions of Outlook to send Korean characters.
          * Use UHC (CP949) encoding instead. See, e.g.,