Passed
Push — 17.1 ( 431f3f...4dae72 )
by Ralf
01:23 queued 12s
created
api/src/Json/Tail.php 2 patches
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -68,15 +68,15 @@  discard block
 block discarded – undo
68 68
 	 *
69 69
 	 * @param string $filename =null if not starting with as slash relative to EGw files dir (this is strongly prefered for security reasons)
70 70
 	 */
71
-	public function __construct($filename=null)
71
+	public function __construct($filename = null)
72 72
 	{
73
-		$this->filenames =& Api\Cache::getSession('phpgwapi', __CLASS__);
73
+		$this->filenames = & Api\Cache::getSession('phpgwapi', __CLASS__);
74 74
 
75 75
 		if ($filename)
76 76
 		{
77 77
 			$this->filename = $filename;
78 78
 
79
-			if (!$this->filenames || !in_array($filename,$this->filenames)) $this->filenames[] = $filename;
79
+			if (!$this->filenames || !in_array($filename, $this->filenames)) $this->filenames[] = $filename;
80 80
 		}
81 81
 	}
82 82
 
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
 	 * @param int $start =0 last position in log-file
88 88
 	 * @throws Api\Exception\WrongParameter
89 89
 	 */
90
-	public function ajax_chunk($filename,$start=0)
90
+	public function ajax_chunk($filename, $start = 0)
91 91
 	{
92
-		if (!in_array($filename,$this->filenames))
92
+		if (!in_array($filename, $this->filenames))
93 93
 		{
94 94
 			throw new Api\Exception\WrongParameter("Not allowed to view '$filename'!");
95 95
 		}
@@ -98,9 +98,9 @@  discard block
 block discarded – undo
98 98
 		if (file_exists($filename))
99 99
 		{
100 100
 			$size = filesize($filename);
101
-			if (!$start || $start < 0 || $start > $size || $size-$start > 4*self::MAX_CHUNK_SIZE)
101
+			if (!$start || $start < 0 || $start > $size || $size - $start > 4 * self::MAX_CHUNK_SIZE)
102 102
 			{
103
-				$start = $size - 4*self::MAX_CHUNK_SIZE;
103
+				$start = $size - 4 * self::MAX_CHUNK_SIZE;
104 104
 				if ($start < 0) $start = 0;
105 105
 			}
106 106
 			$hsize = Api\Vfs::hsize($size);
@@ -131,9 +131,9 @@  discard block
 block discarded – undo
131 131
 	 * @param boolean $truncate =false true: truncate file, false: delete file
132 132
 	 * @throws Api\Exception\WrongParameter
133 133
 	 */
134
-	public function ajax_delete($filename,$truncate=false)
134
+	public function ajax_delete($filename, $truncate = false)
135 135
 	{
136
-		if (!in_array($filename,$this->filenames))
136
+		if (!in_array($filename, $this->filenames))
137 137
 		{
138 138
 			throw new Api\Exception\WrongParameter("Not allowed to view '$filename'!");
139 139
 		}
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 	 * @return string
156 156
 	 * @throws Api\Exception\WrongParameter
157 157
 	 */
158
-	public function show($header=null)
158
+	public function show($header = null)
159 159
 	{
160 160
 		if (!isset($this->filename))
161 161
 		{
@@ -167,11 +167,11 @@  discard block
 block discarded – undo
167 167
 <p style="float: left; margin: 5px"><b>'.htmlspecialchars($header).'</b></p>
168 168
 <div style="float: right; margin: 2px; margin-right: 5px">
169 169
 	'.Api\Html::form(
170
-		Api\Html::input('clear_log',lang('Clear window'),'button','id="clear_log"')."\n".
171
-		Api\Html::input('delete_log',lang('Delete file'),'button','id="purge_log"')."\n".
172
-		Api\Html::input('empty_log',lang('Empty file'),'button','id="empty_log"')."\n".
173
-		Api\Html::input('download_log',lang('Download'),'submit','id="download_log"'),
174
-		'','/index.php',array(
170
+		Api\Html::input('clear_log', lang('Clear window'), 'button', 'id="clear_log"')."\n".
171
+		Api\Html::input('delete_log', lang('Delete file'), 'button', 'id="purge_log"')."\n".
172
+		Api\Html::input('empty_log', lang('Empty file'), 'button', 'id="empty_log"')."\n".
173
+		Api\Html::input('download_log', lang('Download'), 'submit', 'id="download_log"'),
174
+		'', '/index.php', array(
175 175
 		'menuaction' => 'api.'.__CLASS__.'.download',
176 176
 		'filename' => $this->filename,
177 177
 	)).'
@@ -187,15 +187,15 @@  discard block
 block discarded – undo
187 187
 	public function download()
188 188
 	{
189 189
 		$filename = $_GET['filename'];
190
-		if (!in_array($filename,$this->filenames))
190
+		if (!in_array($filename, $this->filenames))
191 191
 		{
192 192
 			throw new Api\Exception\WrongParameter("Not allowed to download '$filename'!");
193 193
 		}
194 194
 		Api\Header\Content::type(basename($filename), 'text/plain');
195 195
 		if ($filename[0] != '/') $filename = $GLOBALS['egw_info']['server']['files_dir'].'/'.$filename;
196
-		for($n=ob_get_level(); $n > 0; --$n)
196
+		for ($n = ob_get_level(); $n > 0; --$n)
197 197
 		{
198
-			ob_end_clean();	// stop all output buffering, to NOT run into memory_limit
198
+			ob_end_clean(); // stop all output buffering, to NOT run into memory_limit
199 199
 		}
200 200
 		readfile($filename);
201 201
 		exit;
Please login to merge, or discard this patch.
Braces   +24 added lines, -6 removed lines patch added patch discarded remove patch
@@ -79,7 +79,10 @@  discard block
 block discarded – undo
79 79
 
80 80
 			$this->filename = $filename;
81 81
 
82
-			if (!$this->filenames || !in_array($filename,$this->filenames)) $this->filenames[] = $filename;
82
+			if (!$this->filenames || !in_array($filename,$this->filenames))
83
+			{
84
+				$this->filenames[] = $filename;
85
+			}
83 86
 		}
84 87
 	}
85 88
 
@@ -96,7 +99,10 @@  discard block
 block discarded – undo
96 99
 		{
97 100
 			throw new Api\Exception\WrongParameter("Not allowed to view '$filename'!");
98 101
 		}
99
-		if ($filename[0] != '/') $filename = $GLOBALS['egw_info']['server']['files_dir'].'/'.$filename;
102
+		if ($filename[0] != '/')
103
+		{
104
+			$filename = $GLOBALS['egw_info']['server']['files_dir'].'/'.$filename;
105
+		}
100 106
 
101 107
 		if (file_exists($filename))
102 108
 		{
@@ -104,7 +110,10 @@  discard block
 block discarded – undo
104 110
 			if (!$start || $start < 0 || $start > $size || $size-$start > 4*self::MAX_CHUNK_SIZE)
105 111
 			{
106 112
 				$start = $size - 4*self::MAX_CHUNK_SIZE;
107
-				if ($start < 0) $start = 0;
113
+				if ($start < 0)
114
+				{
115
+					$start = 0;
116
+				}
108 117
 			}
109 118
 			$hsize = Api\Vfs::hsize($size);
110 119
 			$content = file_get_contents($filename, false, null, $start, self::MAX_CHUNK_SIZE);
@@ -140,7 +149,10 @@  discard block
 block discarded – undo
140 149
 		{
141 150
 			throw new Api\Exception\WrongParameter("Not allowed to view '$filename'!");
142 151
 		}
143
-		if ($filename[0] != '/') $filename = $GLOBALS['egw_info']['server']['files_dir'].'/'.$filename;
152
+		if ($filename[0] != '/')
153
+		{
154
+			$filename = $GLOBALS['egw_info']['server']['files_dir'].'/'.$filename;
155
+		}
144 156
 		if ($truncate)
145 157
 		{
146 158
 			file_put_contents($filename, '');
@@ -164,7 +176,10 @@  discard block
 block discarded – undo
164 176
 		{
165 177
 			throw new Api\Exception\WrongParameter("Must be instanciated with filename!");
166 178
 		}
167
-		if (is_null($header)) $header = $this->filename;
179
+		if (is_null($header))
180
+		{
181
+			$header = $this->filename;
182
+		}
168 183
 
169 184
 		return '
170 185
 <p style="float: left; margin: 5px"><b>'.htmlspecialchars($header).'</b></p>
@@ -195,7 +210,10 @@  discard block
 block discarded – undo
195 210
 			throw new Api\Exception\WrongParameter("Not allowed to download '$filename'!");
196 211
 		}
197 212
 		Api\Header\Content::type(basename($filename), 'text/plain');
198
-		if ($filename[0] != '/') $filename = $GLOBALS['egw_info']['server']['files_dir'].'/'.$filename;
213
+		if ($filename[0] != '/')
214
+		{
215
+			$filename = $GLOBALS['egw_info']['server']['files_dir'].'/'.$filename;
216
+		}
199 217
 		for($n=ob_get_level(); $n > 0; --$n)
200 218
 		{
201 219
 			ob_end_clean();	// stop all output buffering, to NOT run into memory_limit
Please login to merge, or discard this patch.
api/src/CalDAV/IcalIterator.php 3 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -249,12 +249,12 @@
 block discarded – undo
249 249
 
250 250
 		$this->component = Horde_Icalendar::newComponent($type, $this);
251 251
 		//error_log(__METHOD__."() this->component = Horde_Icalendar::newComponent('$type', \$this) = ".array2string($this->component));
252
-        if ($this->component === false)
253
-        {
254
-        	error_log(__METHOD__."() Horde_Icalendar::newComponent('$type', \$this) returned FALSE");
255
-        	return;
256
-            //return PEAR::raiseError("Unable to create object for type $type");
257
-        }
252
+		if ($this->component === false)
253
+		{
254
+			error_log(__METHOD__."() Horde_Icalendar::newComponent('$type', \$this) returned FALSE");
255
+			return;
256
+			//return PEAR::raiseError("Unable to create object for type $type");
257
+		}
258 258
 		if ($this->charset && $this->charset != 'utf-8')
259 259
 		{
260 260
 			$data = Api\Translation::convert($data, $this->charset, 'utf-8');
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 	 * @param array $callback_params =array() further parameters for the callback, 1. parameter is component
107 107
 	 * @param boolean $add_container =false true, add container / $this as last parameter to callback
108 108
 	 */
109
-	public function __construct($ical_file,$base='VCALENDAR',$charset=null,$callback=null,array $callback_params=array(), $add_container=false)
109
+	public function __construct($ical_file, $base = 'VCALENDAR', $charset = null, $callback = null, array $callback_params = array(), $add_container = false)
110 110
 	{
111 111
 		// call parent constructor
112 112
 		parent::__construct();
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 		}
132 132
 		if (!is_resource($this->ical_file))
133 133
 		{
134
-			throw new Api\Exception\WrongParameter(__METHOD__.'($ical_file, ...) NO resource! $ical_file='.substr(array2string($ical_file),0,100));
134
+			throw new Api\Exception\WrongParameter(__METHOD__.'($ical_file, ...) NO resource! $ical_file='.substr(array2string($ical_file), 0, 100));
135 135
 		}
136 136
 	}
137 137
 
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 		{
156 156
 			$line = array_shift($this->unread_lines);
157 157
 		}
158
-		elseif(feof($this->ical_file))
158
+		elseif (feof($this->ical_file))
159 159
 		{
160 160
 			$line = false;
161 161
 		}
@@ -164,9 +164,9 @@  discard block
 block discarded – undo
164 164
 			$line = fgets($this->ical_file);
165 165
 		}
166 166
 		// check if end of container reached
167
-		if ($this->container && $line && substr($line,0,4+strlen($this->base)) === 'END:'.$this->base)
167
+		if ($this->container && $line && substr($line, 0, 4 + strlen($this->base)) === 'END:'.$this->base)
168 168
 		{
169
-			$this->unread_line($line);	// put back end-of-container, to continue to return false
169
+			$this->unread_line($line); // put back end-of-container, to continue to return false
170 170
 			$line = false;
171 171
 		}
172 172
 		//error_log(__METHOD__."() returning ".($line === false ? 'FALSE' : "'$line'"));
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 	protected function unread_line($line)
183 183
 	{
184 184
 		//error_log(__METHOD__."('$line')");
185
-		array_unshift($this->unread_lines,$line);
185
+		array_unshift($this->unread_lines, $line);
186 186
 	}
187 187
 
188 188
 	/**
@@ -195,14 +195,14 @@  discard block
 block discarded – undo
195 195
 		//error_log(__METHOD__."() returning a ".gettype($this->component));
196 196
 		if ($this->callback)
197 197
 		{
198
-			$ret = is_a($this->component,'Horde_Icalendar');
198
+			$ret = is_a($this->component, 'Horde_Icalendar');
199 199
 			do {
200 200
 				if ($ret === false) $this->next();
201
-				if (!is_a($this->component,'Horde_Icalendar')) return false;
201
+				if (!is_a($this->component, 'Horde_Icalendar')) return false;
202 202
 				$params = $this->callback_params;
203
-				array_unshift($params,$this->component);
203
+				array_unshift($params, $this->component);
204 204
 			}
205
-			while(($ret = call_user_func_array($this->callback,$params)) === false);
205
+			while (($ret = call_user_func_array($this->callback, $params)) === false);
206 206
 
207 207
 			return $ret;
208 208
 		}
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 	{
228 228
 		unset($this->component);
229 229
 
230
-		while (($line = $this->read_line()) && substr($line,0,6) !== 'BEGIN:')
230
+		while (($line = $this->read_line()) && substr($line, 0, 6) !== 'BEGIN:')
231 231
 		{
232 232
 			// ignore it
233 233
 		}
@@ -236,12 +236,12 @@  discard block
 block discarded – undo
236 236
 			$this->component = false;
237 237
 			return;
238 238
 		}
239
-		$type = substr(trim($line),6);
239
+		$type = substr(trim($line), 6);
240 240
 
241 241
 		//error_log(__METHOD__."() found $type component");
242 242
 
243 243
 		$data = $line;
244
-		while (($line = $this->read_line()) && substr($line,0,4+strlen($type)) !== 'END:'.$type)
244
+		while (($line = $this->read_line()) && substr($line, 0, 4 + strlen($type)) !== 'END:'.$type)
245 245
 		{
246 246
 			$data .= $line;
247 247
 		}
@@ -276,23 +276,23 @@  discard block
 block discarded – undo
276 276
 	 */
277 277
 	public function rewind()
278 278
 	{
279
-		@fseek($this->ical_file,0,SEEK_SET);
279
+		@fseek($this->ical_file, 0, SEEK_SET);
280 280
 
281 281
 		// advance to begin of container
282
-		while(($line = $this->read_line()) && substr($line,0,6+strlen($this->base)) !== 'BEGIN:'.$this->base)
282
+		while (($line = $this->read_line()) && substr($line, 0, 6 + strlen($this->base)) !== 'BEGIN:'.$this->base)
283 283
 		{
284 284
 
285 285
 		}
286 286
 		// if no container start found --> use whole file (rewind) and set container marker
287 287
 		if (!($this->container = $line !== false))
288 288
 		{
289
-			fseek($this->ical_file,0,SEEK_SET);
289
+			fseek($this->ical_file, 0, SEEK_SET);
290 290
 		}
291 291
 		//error_log(__METHOD__."() $this->base container ".($this->container ? 'found' : 'NOT found'));
292 292
 
293 293
 		$data = $line;
294 294
 		// advance to first component
295
-		while (($line = $this->read_line()) && substr($line,0,6) !== 'BEGIN:')
295
+		while (($line = $this->read_line()) && substr($line, 0, 6) !== 'BEGIN:')
296 296
 		{
297 297
 			$matches = null;
298 298
 			if (preg_match('/^VERSION:(\d\.\d)\s*$/ism', $line, $matches))
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
 		{
308 308
 			$data .= "END:$this->base\n";
309 309
 			//error_log(__METHOD__."() about to call this->parsevCalendar('$data','$this->base','$this->charset')");
310
-			$this->parsevCalendar($data,$this->base,$this->charset);
310
+			$this->parsevCalendar($data, $this->base, $this->charset);
311 311
 		}
312 312
 		if ($line) $this->unread_line($line);
313 313
 
@@ -320,10 +320,10 @@  discard block
 block discarded – undo
320 320
 	 *
321 321
 	 * @return boolean
322 322
 	 */
323
-	public function valid ()
323
+	public function valid()
324 324
 	{
325 325
 		//error_log(__METHOD__."() returning ".(is_a($this->component,'Horde_Icalendar') ? 'TRUE' : 'FALSE').' get_class($this->component)='.get_class($this->component));
326
-		return is_a($this->component,'Horde_Icalendar');
326
+		return is_a($this->component, 'Horde_Icalendar');
327 327
 	}
328 328
 }
329 329
 
@@ -441,8 +441,8 @@  discard block
 block discarded – undo
441 441
 	if (!is_resource($ical_file)) echo "<pre>$ical_file</pre>\n";
442 442
 	//$calendar_ical = new calendar_ical();
443 443
 	//$calendar_ical->setSupportedFields('file');
444
-	$ical_it = new IcalIterator($ical_file);//,'VCALENDAR','iso-8859-1',array($calendar_ical,'_ical2egw_callback'),array('Europe/Berlin'));
445
-	foreach($ical_it as $uid => $vevent)
444
+	$ical_it = new IcalIterator($ical_file); //,'VCALENDAR','iso-8859-1',array($calendar_ical,'_ical2egw_callback'),array('Europe/Berlin'));
445
+	foreach ($ical_it as $uid => $vevent)
446 446
 	{
447 447
 		echo "$uid<pre>".print_r($vevent->toHash(), true)."</pre>\n";
448 448
 	}
Please login to merge, or discard this patch.
Braces   +29 added lines, -8 removed lines patch added patch discarded remove patch
@@ -116,7 +116,10 @@  discard block
 block discarded – undo
116 116
 		if (is_callable($callback))
117 117
 		{
118 118
 			$this->callback = $callback;
119
-			if ($add_container) $callback_params[] = $this;
119
+			if ($add_container)
120
+			{
121
+				$callback_params[] = $this;
122
+			}
120 123
 			$this->callback_params = $callback_params;
121 124
 		}
122 125
 		if (is_string($ical_file))
@@ -197,8 +200,14 @@  discard block
 block discarded – undo
197 200
 		{
198 201
 			$ret = is_a($this->component,'Horde_Icalendar');
199 202
 			do {
200
-				if ($ret === false) $this->next();
201
-				if (!is_a($this->component,'Horde_Icalendar')) return false;
203
+				if ($ret === false)
204
+				{
205
+					$this->next();
206
+				}
207
+				if (!is_a($this->component,'Horde_Icalendar'))
208
+				{
209
+					return false;
210
+				}
202 211
 				$params = $this->callback_params;
203 212
 				array_unshift($params,$this->component);
204 213
 			}
@@ -231,9 +240,12 @@  discard block
 block discarded – undo
231 240
 		{
232 241
 			// ignore it
233 242
 		}
234
-		if ($line === false)	// end-of-file or end-of-container
243
+		if ($line === false)
244
+		{
245
+			// end-of-file or end-of-container
235 246
 		{
236 247
 			$this->component = false;
248
+		}
237 249
 			return;
238 250
 		}
239 251
 		$type = substr(trim($line),6);
@@ -309,7 +321,10 @@  discard block
 block discarded – undo
309 321
 			//error_log(__METHOD__."() about to call this->parsevCalendar('$data','$this->base','$this->charset')");
310 322
 			$this->parsevCalendar($data,$this->base,$this->charset);
311 323
 		}
312
-		if ($line) $this->unread_line($line);
324
+		if ($line)
325
+		{
326
+			$this->unread_line($line);
327
+		}
313 328
 
314 329
 		// advance to first element
315 330
 		$this->next();
@@ -438,7 +453,10 @@  discard block
 block discarded – undo
438 453
 ';
439 454
 	echo $GLOBALS['egw']->framework->header();
440 455
 	//$ical_file = fopen('/tmp/KalenderFelicitasKubala.ics');
441
-	if (!is_resource($ical_file)) echo "<pre>$ical_file</pre>\n";
456
+	if (!is_resource($ical_file))
457
+	{
458
+		echo "<pre>$ical_file</pre>\n";
459
+	}
442 460
 	//$calendar_ical = new calendar_ical();
443 461
 	//$calendar_ical->setSupportedFields('file');
444 462
 	$ical_it = new IcalIterator($ical_file);//,'VCALENDAR','iso-8859-1',array($calendar_ical,'_ical2egw_callback'),array('Europe/Berlin'));
@@ -446,5 +464,8 @@  discard block
 block discarded – undo
446 464
 	{
447 465
 		echo "$uid<pre>".print_r($vevent->toHash(), true)."</pre>\n";
448 466
 	}
449
-	if (is_resource($ical_file)) fclose($ical_file);
450
-}
451 467
\ No newline at end of file
468
+	if (is_resource($ical_file))
469
+	{
470
+		fclose($ical_file);
471
+	}
472
+	}
452 473
\ No newline at end of file
Please login to merge, or discard this patch.
api/src/Vfs.php 5 patches
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
 			return;	// not found, should not happen
673 673
 		}
674 674
 		if ($type && (($type == 'd') == !($stat['mode'] & Vfs\Sqlfs\StreamWrapper::MODE_DIR) ||	// != is_dir() which can be true for symlinks
675
-		    $type == 'F' && is_dir($path)))	// symlink to a directory
675
+			$type == 'F' && is_dir($path)))	// symlink to a directory
676 676
 		{
677 677
 			return;	// wrong type
678 678
 		}
@@ -1621,13 +1621,13 @@  discard block
 block discarded – undo
1621 1621
 		{
1622 1622
 			return false;
1623 1623
 		}
1624
-    	// remove the lock info evtl. set in the cache
1625
-    	unset(self::$lock_cache[$path]);
1624
+		// remove the lock info evtl. set in the cache
1625
+		unset(self::$lock_cache[$path]);
1626 1626
 
1627
-    	if ($timeout < 1000000)	// < 1000000 is a relative timestamp, so we add the current time
1628
-    	{
1629
-    		$timeout += time();
1630
-    	}
1627
+		if ($timeout < 1000000)	// < 1000000 is a relative timestamp, so we add the current time
1628
+		{
1629
+			$timeout += time();
1630
+		}
1631 1631
 
1632 1632
 		if ($update)	// Lock Update
1633 1633
 		{
@@ -1688,32 +1688,32 @@  discard block
 block discarded – undo
1688 1688
 		return $ret;
1689 1689
 	}
1690 1690
 
1691
-    /**
1692
-     * unlock a ressource/path
1693
-     *
1694
-     * @param string $path path to unlock
1695
-     * @param string $token locktoken
1691
+	/**
1692
+	 * unlock a ressource/path
1693
+	 *
1694
+	 * @param string $path path to unlock
1695
+	 * @param string $token locktoken
1696 1696
 	 * @param boolean $check_writable =true should we check if the ressource is writable, before granting locks, default yes
1697
-     * @return boolean true on success
1698
-     */
1699
-    static function unlock($path,$token,$check_writable=true)
1700
-    {
1697
+	 * @return boolean true on success
1698
+	 */
1699
+	static function unlock($path,$token,$check_writable=true)
1700
+	{
1701 1701
 		// we require write rights to lock/unlock a resource
1702 1702
 		if ($check_writable && !self::is_writable($path))
1703 1703
 		{
1704 1704
 			return false;
1705 1705
 		}
1706
-        if (($ret = self::$db->delete(self::LOCK_TABLE,array(
1707
-        	'lock_path' => $path,
1708
-        	'lock_token' => $token,
1709
-        ),__LINE__,__FILE__) && self::$db->affected_rows()))
1710
-        {
1711
-        	// remove the lock from the cache too
1712
-        	unset(self::$lock_cache[$path]);
1713
-        }
1706
+		if (($ret = self::$db->delete(self::LOCK_TABLE,array(
1707
+			'lock_path' => $path,
1708
+			'lock_token' => $token,
1709
+		),__LINE__,__FILE__) && self::$db->affected_rows()))
1710
+		{
1711
+			// remove the lock from the cache too
1712
+			unset(self::$lock_cache[$path]);
1713
+		}
1714 1714
 		if (self::LOCK_DEBUG) error_log(__METHOD__."($path,$token,$check_writable) returns ".($ret ? 'true' : 'false'));
1715 1715
 		return $ret;
1716
-    }
1716
+	}
1717 1717
 
1718 1718
 	/**
1719 1719
 	 * checkLock() helper
@@ -1741,13 +1741,13 @@  discard block
 block discarded – undo
1741 1741
 		}
1742 1742
 		if ($result && $result['expires'] < time())	// lock is expired --> remove it
1743 1743
 		{
1744
-	        self::$db->delete(self::LOCK_TABLE,array(
1745
-	        	'lock_path' => $result['path'],
1746
-	        	'lock_token' => $result['token'],
1747
-	        ),__LINE__,__FILE__);
1744
+			self::$db->delete(self::LOCK_TABLE,array(
1745
+				'lock_path' => $result['path'],
1746
+				'lock_token' => $result['token'],
1747
+			),__LINE__,__FILE__);
1748 1748
 
1749 1749
 			if (self::LOCK_DEBUG) error_log(__METHOD__."($path) lock is expired at ".date('Y-m-d H:i:s',$result['expires'])." --> removed");
1750
-	        $result = false;
1750
+			$result = false;
1751 1751
 		}
1752 1752
 		if (self::LOCK_DEBUG) error_log(__METHOD__."($path) returns ".($result?array2string($result):'false'));
1753 1753
 		return self::$lock_cache[$path] = $result;
@@ -1887,9 +1887,9 @@  discard block
 block discarded – undo
1887 1887
 			$image = Image::find($mime_sub, 'navbar');
1888 1888
 		}
1889 1889
 		else if ($file && $mime_main == 'image' && in_array($mime_sub, array('png','jpeg','jpg','gif','bmp')) &&
1890
-		         (string)$GLOBALS['egw_info']['server']['link_list_thumbnail'] != '0' &&
1891
-		         (string)$GLOBALS['egw_info']['user']['preferences']['common']['link_list_thumbnail'] != '0' &&
1892
-		         ($stat = self::stat($file)) && $stat['size'] < 1500000)
1890
+				 (string)$GLOBALS['egw_info']['server']['link_list_thumbnail'] != '0' &&
1891
+				 (string)$GLOBALS['egw_info']['user']['preferences']['common']['link_list_thumbnail'] != '0' &&
1892
+				 ($stat = self::stat($file)) && $stat['size'] < 1500000)
1893 1893
 		{
1894 1894
 			if (substr($file, 0, 6) == '/apps/')
1895 1895
 			{
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1415,7 +1415,7 @@
 block discarded – undo
1415 1415
 	 *
1416 1416
 	 * @todo use https://github.com/maennchen/ZipStream-PHP to not assamble all files in memmory
1417 1417
 	 */
1418
-	public static function download_zip(Array $_files, $name = false)
1418
+	public static function download_zip(array $_files, $name = false)
1419 1419
 	{
1420 1420
 		//error_log(__METHOD__ . ': '.implode(',',$_files));
1421 1421
 
Please login to merge, or discard this patch.
Braces   +221 added lines, -58 removed lines patch added patch discarded remove patch
@@ -246,7 +246,10 @@  discard block
 block discarded – undo
246 246
 		}
247 247
 		foreach($props as &$prop)
248 248
 		{
249
-			if ($prop['name'] == $name && $prop['ns'] == $ns) return $prop;
249
+			if ($prop['name'] == $name && $prop['ns'] == $ns)
250
+			{
251
+				return $prop;
252
+			}
250 253
 		}
251 254
 		return null;
252 255
 	}
@@ -416,17 +419,27 @@  discard block
 block discarded – undo
416 419
 		$dirs_last = $options['depth'];	// put content of dirs before the dir itself
417 420
 		// show dirs on top by default, if no recursive listing (allways disabled if $type specified, as unnecessary)
418 421
 		$dirsontop = !$type && (isset($options['dirsontop']) ? (boolean)$options['dirsontop'] : isset($options['maxdepth'])&&$options['maxdepth']>0);
419
-		if ($dirsontop) $options['need_mime'] = true;	// otherwise dirsontop can NOT work
422
+		if ($dirsontop)
423
+		{
424
+			$options['need_mime'] = true;
425
+		}
426
+		// otherwise dirsontop can NOT work
420 427
 
421 428
 		// process some of the options (need to be done only once)
422
-		if (isset($options['name']) && !isset($options['name_preg']))	// change from simple *,? wildcards to preg regular expression once
429
+		if (isset($options['name']) && !isset($options['name_preg']))
430
+		{
431
+			// change from simple *,? wildcards to preg regular expression once
423 432
 		{
424 433
 			$options['name_preg'] = '/^'.str_replace(array('\\?','\\*'),array('.{1}','.*'),preg_quote($options['name'])).'$/i';
425 434
 		}
426
-		if (isset($options['path']) && !isset($options['preg_path']))	// change from simple *,? wildcards to preg regular expression once
435
+		}
436
+		if (isset($options['path']) && !isset($options['preg_path']))
437
+		{
438
+			// change from simple *,? wildcards to preg regular expression once
427 439
 		{
428 440
 			$options['path_preg'] = '/^'.str_replace(array('\\?','\\*'),array('.{1}','.*'),preg_quote($options['path'])).'$/i';
429 441
 		}
442
+		}
430 443
 		if (!isset($options['uid']))
431 444
 		{
432 445
 			if (isset($options['user']))
@@ -473,7 +486,10 @@  discard block
 block discarded – undo
473 486
 		{
474 487
 			if (!$url)
475 488
 			{
476
-				if ($path[0] != '/' || !self::stat($path)) continue;
489
+				if ($path[0] != '/' || !self::stat($path))
490
+				{
491
+					continue;
492
+				}
477 493
 				$path = self::PREFIX . $path;
478 494
 			}
479 495
 			if (!isset($options['remove']))
@@ -491,9 +507,17 @@  discard block
 block discarded – undo
491 507
 			{
492 508
 				while(($fname = readdir($dir)) !== false)
493 509
 				{
494
-					if ($fname == '.' || $fname == '..') continue;	// ignore current and parent dir!
510
+					if ($fname == '.' || $fname == '..')
511
+					{
512
+						continue;
513
+					}
514
+					// ignore current and parent dir!
495 515
 
496
-					if (self::is_hidden($fname, $options['show-deleted']) && !$options['hidden']) continue;	// ignore hidden files
516
+					if (self::is_hidden($fname, $options['show-deleted']) && !$options['hidden'])
517
+					{
518
+						continue;
519
+					}
520
+					// ignore hidden files
497 521
 
498 522
 					$file = self::concat($path, $fname);
499 523
 
@@ -505,8 +529,14 @@  discard block
 block discarded – undo
505 529
 					if (is_dir($file) && ($options['follow'] || !is_link($file)) && (!isset($options['maxdepth']) || $options['maxdepth'] > 1))
506 530
 					{
507 531
 						$opts = $options;
508
-						if ($opts['mindepth']) $opts['mindepth']--;
509
-						if ($opts['maxdepth']) $opts['depth']++;
532
+						if ($opts['mindepth'])
533
+						{
534
+							$opts['mindepth']--;
535
+						}
536
+						if ($opts['maxdepth'])
537
+						{
538
+							$opts['depth']++;
539
+						}
510 540
 						unset($opts['order']);
511 541
 						unset($opts['limit']);
512 542
 						foreach(self::find($options['url']?$file:self::parse_url($file,PHP_URL_PATH),$opts,true) as $p => $s)
@@ -550,7 +580,10 @@  discard block
 block discarded – undo
550 580
 							 $cmp *= -1;
551 581
 						}
552 582
 						// always use name as second sort criteria
553
-						if (!$cmp) $cmp = strcasecmp($a['name'], $b['name']);
583
+						if (!$cmp)
584
+						{
585
+							$cmp = strcasecmp($a['name'], $b['name']);
586
+						}
554 587
 						return $cmp;
555 588
 					});
556 589
 					break;
@@ -575,7 +608,10 @@  discard block
 block discarded – undo
575 608
 							$cmp *= -1;
576 609
 						}
577 610
 						// always use name as second sort criteria
578
-						if (!$cmp && $order != 'name') $cmp = strcasecmp($a['name'], $b['name']);
611
+						if (!$cmp && $order != 'name')
612
+						{
613
+							$cmp = strcasecmp($a['name'], $b['name']);
614
+						}
579 615
 						return $cmp;
580 616
 					});
581 617
 					break;
@@ -586,7 +622,10 @@  discard block
 block discarded – undo
586 622
 		if (isset($options['limit']))
587 623
 		{
588 624
 			list($limit,$start) = explode(',',$options['limit']);
589
-			if (!$limit && !($limit = $GLOBALS['egw_info']['user']['preferences']['comman']['maxmatches'])) $limit = 15;
625
+			if (!$limit && !($limit = $GLOBALS['egw_info']['user']['preferences']['comman']['maxmatches']))
626
+			{
627
+				$limit = 15;
628
+			}
590 629
 			//echo "total=".self::$find_total.", limit=$options[limit] --> start=$start, limit=$limit<br>\n";
591 630
 
592 631
 			if ((int)$start || self::$find_total > $limit)
@@ -646,9 +685,13 @@  discard block
 block discarded – undo
646 685
 			return;	// not found, should not happen
647 686
 		}
648 687
 		if ($type && (($type == 'd') == !($stat['mode'] & Vfs\Sqlfs\StreamWrapper::MODE_DIR) ||	// != is_dir() which can be true for symlinks
649
-		    $type == 'F' && is_dir($path)))	// symlink to a directory
688
+		    $type == 'F' && is_dir($path)))
650 689
 		{
651
-			return;	// wrong type
690
+			// symlink to a directory
691
+		{
692
+			return;
693
+		}
694
+		// wrong type
652 695
 		}
653 696
 		$stat['path'] = self::parse_url($path,PHP_URL_PATH);
654 697
 		$stat['name'] = $options['remove'] > 0 ? implode('/',array_slice(explode('/',$stat['path']),$options['remove'])) : self::basename($path);
@@ -670,11 +713,15 @@  discard block
 block discarded – undo
670 713
 		}
671 714
 		if (isset($options['mime']) && $options['mime'] != $stat['mime'])
672 715
 		{
673
-			if ($options['mime'][0] == '/')	// perl regular expression given
716
+			if ($options['mime'][0] == '/')
717
+			{
718
+				// perl regular expression given
674 719
 			{
675 720
 				if (!preg_match($options['mime'], $stat['mime']))
676 721
 				{
677
-					return;	// wrong mime-type
722
+					return;
723
+			}
724
+			// wrong mime-type
678 725
 				}
679 726
 			}
680 727
 			else
@@ -737,7 +784,10 @@  discard block
 block discarded – undo
737 784
 	 */
738 785
 	static function isProtectedDir($dir)
739 786
 	{
740
-		if ($dir[0] != '/') $dir = self::parse_url($dir, PHP_URL_PATH);
787
+		if ($dir[0] != '/')
788
+		{
789
+			$dir = self::parse_url($dir, PHP_URL_PATH);
790
+		}
741 791
 
742 792
 		return preg_match('#^/(apps(/[^/]+)?|home|templates(/[^/]+)?)?/*$#', $dir) > 0;
743 793
 	}
@@ -824,7 +874,10 @@  discard block
 block discarded – undo
824 874
 			{
825 875
 				self::clearstatcache($path);
826 876
 
827
-				if (!isset($vfs)) $vfs = new Vfs\StreamWrapper();
877
+				if (!isset($vfs))
878
+				{
879
+					$vfs = new Vfs\StreamWrapper();
880
+				}
828 881
 				$path_user_stat[$path][$user] = $vfs->url_stat($path, 0);
829 882
 
830 883
 				self::clearstatcache($path);	// we need to clear the stat-cache after the call too, as the next call might be the regular user again!
@@ -867,7 +920,10 @@  discard block
 block discarded – undo
867 920
 		// query stat array, if not given
868 921
 		if (is_null($stat))
869 922
 		{
870
-			if (!isset($vfs)) $vfs = new Vfs\StreamWrapper();
923
+			if (!isset($vfs))
924
+			{
925
+				$vfs = new Vfs\StreamWrapper();
926
+			}
871 927
 			$stat = $vfs->url_stat($path,0);
872 928
 		}
873 929
 		//error_log(__METHOD__."(path=$path||stat[name]={$stat['name']},stat[mode]=".sprintf('%o',$stat['mode']).",$check)");
@@ -1015,7 +1071,8 @@  discard block
 block discarded – undo
1015 1071
 			}
1016 1072
 
1017 1073
 			// sort by length descending, to show precedence
1018
-			usort($eacls, function($a, $b) {
1074
+			usort($eacls, function($a, $b)
1075
+			{
1019 1076
 				return strlen($b['path']) - strlen($a['path']);
1020 1077
 			});
1021 1078
 		}
@@ -1070,14 +1127,21 @@  discard block
 block discarded – undo
1070 1127
 	 */
1071 1128
 	static function mode2int($set,$mode=0)
1072 1129
 	{
1073
-		if (is_int($set))		// already an integer
1130
+		if (is_int($set))
1131
+		{
1132
+			// already an integer
1074 1133
 		{
1075 1134
 			return $set;
1076 1135
 		}
1077
-		if (is_numeric($set))	// octal string
1136
+		}
1137
+		if (is_numeric($set))
1138
+		{
1139
+			// octal string
1078 1140
 		{
1079 1141
 			//error_log(__METHOD__."($set,$mode) returning ".(int)base_convert($set,8,10));
1080
-			return (int)base_convert($set,8,10);	// convert octal to decimal
1142
+			return (int)base_convert($set,8,10);
1143
+		}
1144
+		// convert octal to decimal
1081 1145
 		}
1082 1146
 		foreach(explode(',',$set) as $s)
1083 1147
 		{
@@ -1133,34 +1197,55 @@  discard block
 block discarded – undo
1133 1197
 	 */
1134 1198
 	static function int2mode( $mode )
1135 1199
 	{
1136
-		if(($mode & self::MODE_LINK) == self::MODE_LINK) // Symbolic Link
1200
+		if(($mode & self::MODE_LINK) == self::MODE_LINK)
1201
+		{
1202
+			// Symbolic Link
1137 1203
 		{
1138 1204
 			$sP = 'l';
1139 1205
 		}
1140
-		elseif(($mode & 0xC000) == 0xC000) // Socket
1206
+		}
1207
+		elseif(($mode & 0xC000) == 0xC000)
1208
+		{
1209
+			// Socket
1141 1210
 		{
1142 1211
 			$sP = 's';
1143 1212
 		}
1144
-		elseif($mode & 0x1000)     // FIFO pipe
1213
+		}
1214
+		elseif($mode & 0x1000)
1215
+		{
1216
+			// FIFO pipe
1145 1217
 		{
1146 1218
 			$sP = 'p';
1147 1219
 		}
1148
-		elseif($mode & 0x2000) // Character special
1220
+		}
1221
+		elseif($mode & 0x2000)
1222
+		{
1223
+			// Character special
1149 1224
 		{
1150 1225
 			$sP = 'c';
1151 1226
 		}
1152
-		elseif($mode & 0x4000) // Directory
1227
+		}
1228
+		elseif($mode & 0x4000)
1229
+		{
1230
+			// Directory
1153 1231
 		{
1154 1232
 			$sP = 'd';
1155 1233
 		}
1156
-		elseif($mode & 0x6000) // Block special
1234
+		}
1235
+		elseif($mode & 0x6000)
1236
+		{
1237
+			// Block special
1157 1238
 		{
1158 1239
 			$sP = 'b';
1159 1240
 		}
1160
-		elseif($mode & 0x8000) // Regular
1241
+		}
1242
+		elseif($mode & 0x8000)
1243
+		{
1244
+			// Regular
1161 1245
 		{
1162 1246
 			$sP = '-';
1163 1247
 		}
1248
+		}
1164 1249
 		else                         // UNKNOWN
1165 1250
 		{
1166 1251
 			$sP = 'u';
@@ -1227,9 +1312,18 @@  discard block
 block discarded – undo
1227 1312
 	 */
1228 1313
 	static function hsize($size)
1229 1314
 	{
1230
-		if ($size < 1024) return $size;
1231
-		if ($size < 1024*1024) return sprintf('%3.1lfk',(float)$size/1024);
1232
-		if ($size < 1024*1024*1024) return sprintf('%3.1lfM',(float)$size/(1024*1024));
1315
+		if ($size < 1024)
1316
+		{
1317
+			return $size;
1318
+		}
1319
+		if ($size < 1024*1024)
1320
+		{
1321
+			return sprintf('%3.1lfk',(float)$size/1024);
1322
+		}
1323
+		if ($size < 1024*1024*1024)
1324
+		{
1325
+			return sprintf('%3.1lfM',(float)$size/(1024*1024));
1326
+		}
1233 1327
 		return sprintf('%3.1lfG',(float)$size/(1024*1024*1024));
1234 1328
 	}
1235 1329
 
@@ -1240,7 +1334,10 @@  discard block
 block discarded – undo
1240 1334
 	 */
1241 1335
 	static function int_size($_val)
1242 1336
 	{
1243
-		if(empty($_val))return 0;
1337
+		if(empty($_val))
1338
+		{
1339
+			return 0;
1340
+		}
1244 1341
 
1245 1342
 		$val = trim($_val);
1246 1343
 
@@ -1248,11 +1345,13 @@  discard block
 block discarded – undo
1248 1345
 		preg_match('#([0-9]+)[\s]*([a-z]+)#i', $val, $matches);
1249 1346
 
1250 1347
 		$last = '';
1251
-		if(isset($matches[2])){
1348
+		if(isset($matches[2]))
1349
+		{
1252 1350
 			$last = $matches[2];
1253 1351
 		}
1254 1352
 
1255
-		if(isset($matches[1])){
1353
+		if(isset($matches[1]))
1354
+		{
1256 1355
 			$val = (int) $matches[1];
1257 1356
 		}
1258 1357
 
@@ -1317,7 +1416,10 @@  discard block
 block discarded – undo
1317 1416
 			static $entities = array('%21', '%2A', '%27', '%28', '%29', '%3B', '%3A', '%40', '%26', '%3D', '%24', '%2C', '%2F', '%3F', '%23', '%5B', '%5D');
1318 1417
 			static $replacements = array('!', '*', "'", "(", ")", ";", ":", "@", "&", "=", "$", ",", "/", "?", "#", "[", "]");
1319 1418
 			static $str_replace = null;
1320
-			if (!isset($str_replace)) $str_replace = function_exists('mb_str_replace') ? 'mb_str_replace' : 'str_replace';
1419
+			if (!isset($str_replace))
1420
+			{
1421
+				$str_replace = function_exists('mb_str_replace') ? 'mb_str_replace' : 'str_replace';
1422
+			}
1321 1423
 
1322 1424
 			// Create encoded URL with special URL characters decoded so it can be parsed
1323 1425
 			// All other characters will be encoded
@@ -1357,7 +1459,10 @@  discard block
 block discarded – undo
1357 1459
 			return false;
1358 1460
 		}
1359 1461
 		$parts = explode('/',$url);
1360
-		if (substr($url,-1) == '/') array_pop($parts);
1462
+		if (substr($url,-1) == '/')
1463
+		{
1464
+			array_pop($parts);
1465
+		}
1361 1466
 		array_pop($parts);
1362 1467
 		if ($url[0] != '/' && count($parts) == 3 || count($parts) == 1 && $parts[0] === '')
1363 1468
 		{
@@ -1400,7 +1505,10 @@  discard block
 block discarded – undo
1400 1505
 	static function concat($_url,$relative)
1401 1506
 	{
1402 1507
 		list($url,$query) = explode('?',$_url,2);
1403
-		if (substr($url,-1) == '/') $url = substr($url,0,-1);
1508
+		if (substr($url,-1) == '/')
1509
+		{
1510
+			$url = substr($url,0,-1);
1511
+		}
1404 1512
 		$ret = ($relative === '' || $relative[0] == '/' ? $url.$relative : $url.'/'.$relative);
1405 1513
 
1406 1514
 		// now normalize the path (remove "/something/..")
@@ -1493,7 +1601,8 @@  discard block
 block discarded – undo
1493 1601
 		if(count($paths) > 0)
1494 1602
 		{
1495 1603
 			// Shortest to longest
1496
-			usort($paths, function($a, $b) {
1604
+			usort($paths, function($a, $b)
1605
+			{
1497 1606
 				return strlen($a) - strlen($b);
1498 1607
 			});
1499 1608
 
@@ -1566,7 +1675,10 @@  discard block
 block discarded – undo
1566 1675
 			// Don't go infinite with app entries
1567 1676
 			if(self::is_link($addfile))
1568 1677
 			{
1569
-				if(in_array($addfile, $links)) continue;
1678
+				if(in_array($addfile, $links))
1679
+				{
1680
+					continue;
1681
+				}
1570 1682
 				$links[] = $addfile;
1571 1683
 			}
1572 1684
 			// Add directory - if empty, client app might not show it though
@@ -1677,12 +1789,17 @@  discard block
 block discarded – undo
1677 1789
     	// remove the lock info evtl. set in the cache
1678 1790
     	unset(self::$lock_cache[$path]);
1679 1791
 
1680
-    	if ($timeout < 1000000)	// < 1000000 is a relative timestamp, so we add the current time
1792
+    	if ($timeout < 1000000)
1793
+    	{
1794
+    		// < 1000000 is a relative timestamp, so we add the current time
1681 1795
     	{
1682 1796
     		$timeout += time();
1683 1797
     	}
1798
+    	}
1684 1799
 
1685
-		if ($update)	// Lock Update
1800
+		if ($update)
1801
+		{
1802
+			// Lock Update
1686 1803
 		{
1687 1804
 			if (($ret = (boolean)($row = self::$db->select(self::LOCK_TABLE,array('lock_owner','lock_exclusive','lock_write'),array(
1688 1805
 				'lock_path' => $path,
@@ -1690,6 +1807,7 @@  discard block
 block discarded – undo
1690 1807
 			),__LINE__,__FILE__)->fetch())))
1691 1808
 			{
1692 1809
 				$owner = $row['lock_owner'];
1810
+		}
1693 1811
 				$scope = Db::from_bool($row['lock_exclusive']) ? 'exclusive' : 'shared';
1694 1812
 				$type  = Db::from_bool($row['lock_write']) ? 'write' : 'read';
1695 1813
 
@@ -1737,7 +1855,10 @@  discard block
 block discarded – undo
1737 1855
 				$ret = false;	// there's already a lock
1738 1856
 			}
1739 1857
 		}
1740
-		if (self::LOCK_DEBUG) error_log(__METHOD__."($path,$token,$timeout,$owner,$scope,$type,update=$update,check_writable=$check_writable) returns ".($ret ? 'true' : 'false'));
1858
+		if (self::LOCK_DEBUG)
1859
+		{
1860
+			error_log(__METHOD__."($path,$token,$timeout,$owner,$scope,$type,update=$update,check_writable=$check_writable) returns ".($ret ? 'true' : 'false'));
1861
+		}
1741 1862
 		return $ret;
1742 1863
 	}
1743 1864
 
@@ -1764,7 +1885,10 @@  discard block
 block discarded – undo
1764 1885
         	// remove the lock from the cache too
1765 1886
         	unset(self::$lock_cache[$path]);
1766 1887
         }
1767
-		if (self::LOCK_DEBUG) error_log(__METHOD__."($path,$token,$check_writable) returns ".($ret ? 'true' : 'false'));
1888
+		if (self::LOCK_DEBUG)
1889
+		{
1890
+			error_log(__METHOD__."($path,$token,$check_writable) returns ".($ret ? 'true' : 'false'));
1891
+		}
1768 1892
 		return $ret;
1769 1893
     }
1770 1894
 
@@ -1778,7 +1902,10 @@  discard block
 block discarded – undo
1778 1902
 	{
1779 1903
 		if (isset(self::$lock_cache[$path]))
1780 1904
 		{
1781
-			if (self::LOCK_DEBUG) error_log(__METHOD__."($path) returns from CACHE ".str_replace(array("\n",'    '),'',print_r(self::$lock_cache[$path],true)));
1905
+			if (self::LOCK_DEBUG)
1906
+			{
1907
+				error_log(__METHOD__."($path) returns from CACHE ".str_replace(array("\n",'    '),'',print_r(self::$lock_cache[$path],true)));
1908
+			}
1782 1909
 			return self::$lock_cache[$path];
1783 1910
 		}
1784 1911
 		$where = 'lock_path='.self::$db->quote($path);
@@ -1792,17 +1919,26 @@  discard block
 block discarded – undo
1792 1919
 			$result['scope'] = Db::from_bool($result['exclusive']) ? 'exclusive' : 'shared';
1793 1920
 			$result['depth'] = Db::from_bool($result['recursive']) ? 'infinite' : 0;
1794 1921
 		}
1795
-		if ($result && $result['expires'] < time())	// lock is expired --> remove it
1922
+		if ($result && $result['expires'] < time())
1923
+		{
1924
+			// lock is expired --> remove it
1796 1925
 		{
1797 1926
 	        self::$db->delete(self::LOCK_TABLE,array(
1798 1927
 	        	'lock_path' => $result['path'],
1799 1928
 	        	'lock_token' => $result['token'],
1800 1929
 	        ),__LINE__,__FILE__);
1930
+		}
1801 1931
 
1802
-			if (self::LOCK_DEBUG) error_log(__METHOD__."($path) lock is expired at ".date('Y-m-d H:i:s',$result['expires'])." --> removed");
1932
+			if (self::LOCK_DEBUG)
1933
+			{
1934
+				error_log(__METHOD__."($path) lock is expired at ".date('Y-m-d H:i:s',$result['expires'])." --> removed");
1935
+			}
1803 1936
 	        $result = false;
1804 1937
 		}
1805
-		if (self::LOCK_DEBUG) error_log(__METHOD__."($path) returns ".($result?array2string($result):'false'));
1938
+		if (self::LOCK_DEBUG)
1939
+		{
1940
+			error_log(__METHOD__."($path) returns ".($result?array2string($result):'false'));
1941
+		}
1806 1942
 		return self::$lock_cache[$path] = $result;
1807 1943
 	}
1808 1944
 
@@ -1816,10 +1952,13 @@  discard block
 block discarded – undo
1816 1952
 	static function getExtraInfo($path,array $content=null)
1817 1953
 	{
1818 1954
 		$extra = array();
1819
-		if (($extra_info = self::_call_on_backend('extra_info',array($path,$content),true)))	// true = fail silent if backend does NOT support it
1955
+		if (($extra_info = self::_call_on_backend('extra_info',array($path,$content),true)))
1956
+		{
1957
+			// true = fail silent if backend does NOT support it
1820 1958
 		{
1821 1959
 			$extra[] = $extra_info;
1822 1960
 		}
1961
+		}
1823 1962
 
1824 1963
 		if (($vfs_extra = Hooks::process(array(
1825 1964
 			'location' => 'vfs_extra',
@@ -2098,30 +2237,42 @@  discard block
 block discarded – undo
2098 2237
 		}
2099 2238
 		if ($check_is_uploaded_file && !is_resource($tmp_name) && !is_uploaded_file($tmp_name))
2100 2239
 		{
2101
-			if (self::LOG_LEVEL) error_log(__METHOD__."($tmp_name, $target, ".array2string($props).",$check_is_uploaded_file) returning FALSE !is_uploaded_file()");
2240
+			if (self::LOG_LEVEL)
2241
+			{
2242
+				error_log(__METHOD__."($tmp_name, $target, ".array2string($props).",$check_is_uploaded_file) returning FALSE !is_uploaded_file()");
2243
+			}
2102 2244
 			return false;
2103 2245
 		}
2104 2246
 		if (!(self::is_writable($target) || ($dir = self::dirname($target)) && self::is_writable($dir)))
2105 2247
 		{
2106
-			if (self::LOG_LEVEL) error_log(__METHOD__."($tmp_name, $target, ".array2string($props).",$check_is_uploaded_file) returning FALSE !writable");
2248
+			if (self::LOG_LEVEL)
2249
+			{
2250
+				error_log(__METHOD__."($tmp_name, $target, ".array2string($props).",$check_is_uploaded_file) returning FALSE !writable");
2251
+			}
2107 2252
 			return false;
2108 2253
 		}
2109 2254
 		if ($props)
2110 2255
 		{
2111
-			if (!is_array($props)) $props = array(array('name' => 'comment','val' => $props));
2256
+			if (!is_array($props))
2257
+			{
2258
+				$props = array(array('name' => 'comment','val' => $props));
2259
+			}
2112 2260
 
2113 2261
 			// if $props is name => value pairs, convert it to internal array or array with values for keys 'name', 'val' and optional 'ns'
2114 2262
 			if (!isset($props[0]))
2115 2263
 			{
2116 2264
 				foreach($props as $name => $val)
2117 2265
 				{
2118
-					if (($name == 'comment' || $name[0] == '#') && $val)	// only copy 'comment' and cfs
2266
+					if (($name == 'comment' || $name[0] == '#') && $val)
2267
+					{
2268
+						// only copy 'comment' and cfs
2119 2269
 					{
2120 2270
 						$vfs_props[] = array(
2121 2271
 							'name' => $name,
2122 2272
 							'val'  => $val,
2123 2273
 						);
2124 2274
 					}
2275
+					}
2125 2276
 				}
2126 2277
 				$props = $vfs_props;
2127 2278
 			}
@@ -2153,7 +2304,10 @@  discard block
 block discarded – undo
2153 2304
 				copy($tmp_name, self::PREFIX.$target)) ?
2154 2305
 				self::stat($target) : false;
2155 2306
 		}
2156
-		if (self::LOG_LEVEL > 1 || !$ret && self::LOG_LEVEL) error_log(__METHOD__."($tmp_name, $target, ".array2string($props).") returning ".array2string($ret));
2307
+		if (self::LOG_LEVEL > 1 || !$ret && self::LOG_LEVEL)
2308
+		{
2309
+			error_log(__METHOD__."($tmp_name, $target, ".array2string($props).") returning ".array2string($ret));
2310
+		}
2157 2311
 		return $ret;
2158 2312
 	}
2159 2313
 
@@ -2286,7 +2440,10 @@  discard block
 block discarded – undo
2286 2440
 				return false;
2287 2441
 			}
2288 2442
 			$k=(string)self::parse_url($url,PHP_URL_SCHEME);
2289
-			if (!(is_array($scheme2urls[$k]))) $scheme2urls[$k] = array();
2443
+			if (!(is_array($scheme2urls[$k])))
2444
+			{
2445
+				$scheme2urls[$k] = array();
2446
+			}
2290 2447
 			$scheme2urls[$k][$path] = $url;
2291 2448
 		}
2292 2449
 		$ret = array();
@@ -2296,7 +2453,10 @@  discard block
 block discarded – undo
2296 2453
 			{
2297 2454
 				if (!class_exists($class = self::scheme2class($scheme)) || !method_exists($class,$name))
2298 2455
 				{
2299
-					if (!$fail_silent) trigger_error("Can't $name for scheme $scheme!\n",E_USER_WARNING);
2456
+					if (!$fail_silent)
2457
+					{
2458
+						trigger_error("Can't $name for scheme $scheme!\n",E_USER_WARNING);
2459
+					}
2300 2460
 					return false;
2301 2461
 				}
2302 2462
 				if (!is_array($pathes))
@@ -2414,10 +2574,13 @@  discard block
 block discarded – undo
2414 2574
 	 */
2415 2575
 	static function symlink($target,$link)
2416 2576
 	{
2417
-		if (($ret = self::_call_on_backend('symlink',array($target,$link),false,1)))	// 1=path is in $link!
2577
+		if (($ret = self::_call_on_backend('symlink',array($target,$link),false,1)))
2578
+		{
2579
+			// 1=path is in $link!
2418 2580
 		{
2419 2581
 			Vfs\StreamWrapper::symlinkCache_remove($link);
2420 2582
 		}
2583
+		}
2421 2584
 		return $ret;
2422 2585
 	}
2423 2586
 
Please login to merge, or discard this patch.
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 	 * dir working on just the eGW VFS: returns directory object
175 175
 	 *
176 176
 	 * @param string $path filename with absolute path in the eGW VFS
177
-	 * @return Directory
177
+	 * @return \Directory
178 178
 	 */
179 179
 	static function dir($path)
180 180
 	{
@@ -1345,7 +1345,7 @@  discard block
 block discarded – undo
1345 1345
 	 * Also works around PHP under Windows returning dirname('/something') === '\\', which is NOT understood by EGroupware's VFS!
1346 1346
 	 *
1347 1347
 	 * @param string $_url path or url
1348
-	 * @return string|boolean parent or false if there's none ($path == '/')
1348
+	 * @return false|string parent or false if there's none ($path == '/')
1349 1349
 	 */
1350 1350
 	static function dirname($_url)
1351 1351
 	{
@@ -1774,7 +1774,7 @@  discard block
 block discarded – undo
1774 1774
 	 * checkLock() helper
1775 1775
 	 *
1776 1776
 	 * @param  string resource path to check for locks
1777
-	 * @return array|boolean false if there's no lock, else array with lock info
1777
+	 * @return string|null false if there's no lock, else array with lock info
1778 1778
 	 */
1779 1779
 	static function checkLock($path)
1780 1780
 	{
@@ -2057,6 +2057,7 @@  discard block
 block discarded – undo
2057 2057
 
2058 2058
 	/**
2059 2059
 	 * Moves the files given in src to dst
2060
+	 * @param string|boolean $dst
2060 2061
 	 */
2061 2062
 	static public function move_files(array $src, $dst, &$errs, array &$moved)
2062 2063
 	{
@@ -2247,7 +2248,6 @@  discard block
 block discarded – undo
2247 2248
 	 * In order for the appropriate error message to be returned, do not define this method if your wrapper does not support removing directories.
2248 2249
 	 *
2249 2250
 	 * @param string $path
2250
-	 * @param int $options Possible values include STREAM_REPORT_ERRORS.
2251 2251
 	 * @return boolean TRUE on success or FALSE on failure.
2252 2252
 	 */
2253 2253
 	static function rmdir($path)
@@ -2373,7 +2373,7 @@  discard block
 block discarded – undo
2373 2373
 	 * Requires root rights!
2374 2374
 	 *
2375 2375
 	 * @param string $path
2376
-	 * @param int|string $owner numeric user id or account-name
2376
+	 * @param integer $owner numeric user id or account-name
2377 2377
 	 * @return boolean true on success, false otherwise
2378 2378
 	 */
2379 2379
 	static function chown($path,$owner)
Please login to merge, or discard this patch.
Spacing   +289 added lines, -294 removed lines patch added patch discarded remove patch
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 	 * @param resource $context =null context to pass to stream-wrapper
146 146
 	 * @return resource
147 147
 	 */
148
-	static function fopen($path, $mode, $context=null)
148
+	static function fopen($path, $mode, $context = null)
149 149
 	{
150 150
 		if ($path[0] != '/')
151 151
 		{
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 	 * @param resource $context =null context to pass to stream-wrapper
162 162
 	 * @return resource
163 163
 	 */
164
-	static function opendir($path, $context=null)
164
+	static function opendir($path, $context = null)
165 165
 	{
166 166
 		if ($path[0] != '/')
167 167
 		{
@@ -192,13 +192,13 @@  discard block
 block discarded – undo
192 192
 	 * @param int $sorting_order =0 !$sorting_order (default) alphabetical in ascending order, $sorting_order alphabetical in descending order.
193 193
 	 * @return array
194 194
 	 */
195
-	static function scandir($path,$sorting_order=0)
195
+	static function scandir($path, $sorting_order = 0)
196 196
 	{
197 197
 		if ($path[0] != '/')
198 198
 		{
199 199
 			throw new Exception\AssertionFailed("Directory '$path' is not an absolute path!");
200 200
 		}
201
-		return scandir(self::PREFIX.$path,$sorting_order);
201
+		return scandir(self::PREFIX.$path, $sorting_order);
202 202
 	}
203 203
 
204 204
 	/**
@@ -208,25 +208,25 @@  discard block
 block discarded – undo
208 208
 	 * @param string $to
209 209
 	 * @return boolean
210 210
 	 */
211
-	static function copy($from,$to)
211
+	static function copy($from, $to)
212 212
 	{
213
-		$old_props = self::file_exists($to) ? self::propfind($to,null) : array();
213
+		$old_props = self::file_exists($to) ? self::propfind($to, null) : array();
214 214
 		// copy properties (eg. file comment), if there are any and evtl. existing old properties
215
-		$props = self::propfind($from,null);
216
-		if(!$props)
215
+		$props = self::propfind($from, null);
216
+		if (!$props)
217 217
 		{
218 218
 			$props = array();
219 219
 		}
220
-		foreach($old_props as $prop)
220
+		foreach ($old_props as $prop)
221 221
 		{
222
-			if (!self::find_prop($props,$prop))
222
+			if (!self::find_prop($props, $prop))
223 223
 			{
224
-				$prop['val'] = null;	// null = delete prop
224
+				$prop['val'] = null; // null = delete prop
225 225
 				$props[] = $prop;
226 226
 			}
227 227
 		}
228 228
 		// using self::copy_uploaded() to treat copying incl. properties as atomar operation in respect of notifications
229
-		return self::copy_uploaded(self::PREFIX.$from,$to,$props,false);	// false = no is_uploaded_file check!
229
+		return self::copy_uploaded(self::PREFIX.$from, $to, $props, false); // false = no is_uploaded_file check!
230 230
 	}
231 231
 
232 232
 	/**
@@ -237,14 +237,14 @@  discard block
 block discarded – undo
237 237
 	 * @param string $ns =self::DEFAULT_PROP_NAMESPACE namespace, only if $prop is no array
238 238
 	 * @return &array reference to property in $props or null if not found
239 239
 	 */
240
-	static function &find_prop(array &$props,$name,$ns=self::DEFAULT_PROP_NAMESPACE)
240
+	static function &find_prop(array &$props, $name, $ns = self::DEFAULT_PROP_NAMESPACE)
241 241
 	{
242 242
 		if (is_array($name))
243 243
 		{
244 244
 			$ns = $name['ns'];
245 245
 			$name = $name['name'];
246 246
 		}
247
-		foreach($props as &$prop)
247
+		foreach ($props as &$prop)
248 248
 		{
249 249
 			if ($prop['name'] == $name && $prop['ns'] == $ns) return $prop;
250 250
 		}
@@ -258,16 +258,16 @@  discard block
 block discarded – undo
258 258
 	 * @param boolean $try_create_home =false should a non-existing home-directory be automatically created
259 259
 	 * @return array
260 260
 	 */
261
-	static function stat($path,$try_create_home=false)
261
+	static function stat($path, $try_create_home = false)
262 262
 	{
263 263
 		if ($path[0] != '/' && strpos($path, self::PREFIX.'/') !== 0)
264 264
 		{
265 265
 			throw new Exception\AssertionFailed("File '$path' is not an absolute path!");
266 266
 		}
267 267
 		$vfs = new Vfs\StreamWrapper();
268
-		if (($stat = $vfs->url_stat($path,0,$try_create_home)))
268
+		if (($stat = $vfs->url_stat($path, 0, $try_create_home)))
269 269
 		{
270
-			$stat = array_slice($stat,13);	// remove numerical indices 0-12
270
+			$stat = array_slice($stat, 13); // remove numerical indices 0-12
271 271
 		}
272 272
 		return $stat;
273 273
 	}
@@ -279,16 +279,16 @@  discard block
 block discarded – undo
279 279
 	 * @param boolean $try_create_home =false should a non-existing home-directory be automatically created
280 280
 	 * @return array
281 281
 	 */
282
-	static function lstat($path,$try_create_home=false)
282
+	static function lstat($path, $try_create_home = false)
283 283
 	{
284 284
 		if ($path[0] != '/' && strpos($path, self::PREFIX.'/') !== 0)
285 285
 		{
286 286
 			throw new Exception\AssertionFailed("File '$path' is not an absolute path!");
287 287
 		}
288 288
 		$vfs = new Vfs\StreamWrapper();
289
-		if (($stat = $vfs->url_stat($path,STREAM_URL_STAT_LINK,$try_create_home)))
289
+		if (($stat = $vfs->url_stat($path, STREAM_URL_STAT_LINK, $try_create_home)))
290 290
 		{
291
-			$stat = array_slice($stat,13);	// remove numerical indices 0-12
291
+			$stat = array_slice($stat, 13); // remove numerical indices 0-12
292 292
 		}
293 293
 		return $stat;
294 294
 	}
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
 	 * @param boolean $clear_fstab =false true clear current fstab, false (default) only add given mount
340 340
 	 * @return array|boolean array with fstab, if called without parameter or true on successful mount
341 341
 	 */
342
-	static function mount($url=null,$path=null,$check_url=null,$persitent_mount=true,$clear_fstab=false)
342
+	static function mount($url = null, $path = null, $check_url = null, $persitent_mount = true, $clear_fstab = false)
343 343
 	{
344 344
 		return Vfs\StreamWrapper::mount($url, $path, $check_url, $persitent_mount, $clear_fstab);
345 345
 	}
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
 	 * @param boolean $allow_versions =false allow .versions or .attic
373 373
 	 * @return boolean
374 374
 	 */
375
-	public static function is_hidden($path, $allow_versions=false)
375
+	public static function is_hidden($path, $allow_versions = false)
376 376
 	{
377 377
 		$file = self::basename($path);
378 378
 
@@ -409,30 +409,30 @@  discard block
 block discarded – undo
409 409
 	 * @param array $exec_params =null further params for exec as array, path is always the first param and stat the last!
410 410
 	 * @return array of pathes if no $exec, otherwise path => stat pairs
411 411
 	 */
412
-	static function find($base,$options=null,$exec=null,$exec_params=null)
412
+	static function find($base, $options = null, $exec = null, $exec_params = null)
413 413
 	{
414 414
 		//error_log(__METHOD__."(".print_r($base,true).",".print_r($options,true).",".print_r($exec,true).",".print_r($exec_params,true).")\n");
415 415
 
416
-		$type = $options['type'];	// 'd', 'f' or 'F'
417
-		$dirs_last = $options['depth'];	// put content of dirs before the dir itself
416
+		$type = $options['type']; // 'd', 'f' or 'F'
417
+		$dirs_last = $options['depth']; // put content of dirs before the dir itself
418 418
 		// show dirs on top by default, if no recursive listing (allways disabled if $type specified, as unnecessary)
419
-		$dirsontop = !$type && (isset($options['dirsontop']) ? (boolean)$options['dirsontop'] : isset($options['maxdepth'])&&$options['maxdepth']>0);
420
-		if ($dirsontop) $options['need_mime'] = true;	// otherwise dirsontop can NOT work
419
+		$dirsontop = !$type && (isset($options['dirsontop']) ? (boolean)$options['dirsontop'] : isset($options['maxdepth']) && $options['maxdepth'] > 0);
420
+		if ($dirsontop) $options['need_mime'] = true; // otherwise dirsontop can NOT work
421 421
 
422 422
 		// process some of the options (need to be done only once)
423 423
 		if (isset($options['name']) && !isset($options['name_preg']))	// change from simple *,? wildcards to preg regular expression once
424 424
 		{
425
-			$options['name_preg'] = '/^'.str_replace(array('\\?','\\*'),array('.{1}','.*'),preg_quote($options['name'])).'$/i';
425
+			$options['name_preg'] = '/^'.str_replace(array('\\?', '\\*'), array('.{1}', '.*'), preg_quote($options['name'])).'$/i';
426 426
 		}
427 427
 		if (isset($options['path']) && !isset($options['preg_path']))	// change from simple *,? wildcards to preg regular expression once
428 428
 		{
429
-			$options['path_preg'] = '/^'.str_replace(array('\\?','\\*'),array('.{1}','.*'),preg_quote($options['path'])).'$/i';
429
+			$options['path_preg'] = '/^'.str_replace(array('\\?', '\\*'), array('.{1}', '.*'), preg_quote($options['path'])).'$/i';
430 430
 		}
431 431
 		if (!isset($options['uid']))
432 432
 		{
433 433
 			if (isset($options['user']))
434 434
 			{
435
-				$options['uid'] = $GLOBALS['egw']->accounts->name2id($options['user'],'account_lid','u');
435
+				$options['uid'] = $GLOBALS['egw']->accounts->name2id($options['user'], 'account_lid', 'u');
436 436
 			}
437 437
 			elseif (isset($options['nouser']))
438 438
 			{
@@ -443,7 +443,7 @@  discard block
 block discarded – undo
443 443
 		{
444 444
 			if (isset($options['group']))
445 445
 			{
446
-				$options['gid'] = abs($GLOBALS['egw']->accounts->name2id($options['group'],'account_lid','g'));
446
+				$options['gid'] = abs($GLOBALS['egw']->accounts->name2id($options['group'], 'account_lid', 'g'));
447 447
 			}
448 448
 			elseif (isset($options['nogroup']))
449 449
 			{
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
 		}
453 453
 		if ($options['order'] == 'mime')
454 454
 		{
455
-			$options['need_mime'] = true;	// we need to return the mime colum
455
+			$options['need_mime'] = true; // we need to return the mime colum
456 456
 		}
457 457
 		// implicit show deleted files, if hidden is enabled (requires versioning!)
458 458
 		if (!empty($options['hidden']) && !isset($options['show-deleted']))
@@ -470,37 +470,37 @@  discard block
 block discarded – undo
470 470
 			$base = array($base);
471 471
 		}
472 472
 		$result = array();
473
-		foreach($base as $path)
473
+		foreach ($base as $path)
474 474
 		{
475 475
 			if (!$url)
476 476
 			{
477 477
 				if ($path[0] != '/' || !self::stat($path)) continue;
478
-				$path = self::PREFIX . $path;
478
+				$path = self::PREFIX.$path;
479 479
 			}
480 480
 			if (!isset($options['remove']))
481 481
 			{
482
-				$options['remove'] = count($base) == 1 ? count(explode('/',$path))-3+(int)(substr($path,-1)!='/') : 0;
482
+				$options['remove'] = count($base) == 1 ? count(explode('/', $path)) - 3 + (int)(substr($path, -1) != '/') : 0;
483 483
 			}
484 484
 			$is_dir = is_dir($path);
485 485
 			if ((int)$options['mindepth'] == 0 && (!$dirs_last || !$is_dir))
486 486
 			{
487
-				self::_check_add($options,$path,$result);
487
+				self::_check_add($options, $path, $result);
488 488
 			}
489 489
 			if ($is_dir && (!isset($options['maxdepth']) || ($options['maxdepth'] > 0 &&
490 490
 				$options['depth'] < $options['maxdepth'])) &&
491 491
 				($dir = @opendir($path, $context)))
492 492
 			{
493
-				while(($fname = readdir($dir)) !== false)
493
+				while (($fname = readdir($dir)) !== false)
494 494
 				{
495
-					if ($fname == '.' || $fname == '..') continue;	// ignore current and parent dir!
495
+					if ($fname == '.' || $fname == '..') continue; // ignore current and parent dir!
496 496
 
497
-					if (self::is_hidden($fname, $options['show-deleted']) && !$options['hidden']) continue;	// ignore hidden files
497
+					if (self::is_hidden($fname, $options['show-deleted']) && !$options['hidden']) continue; // ignore hidden files
498 498
 
499 499
 					$file = self::concat($path, $fname);
500 500
 
501 501
 					if ((int)$options['mindepth'] <= 1)
502 502
 					{
503
-						self::_check_add($options,$file,$result);
503
+						self::_check_add($options, $file, $result);
504 504
 					}
505 505
 					// only descend into subdirs, if it's a real dir (no link to a dir) or we should follow symlinks
506 506
 					if (is_dir($file) && ($options['follow'] || !is_link($file)) && (!isset($options['maxdepth']) || $options['maxdepth'] > 1))
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
 						if ($opts['maxdepth']) $opts['depth']++;
511 511
 						unset($opts['order']);
512 512
 						unset($opts['limit']);
513
-						foreach(self::find($options['url']?$file:self::parse_url($file,PHP_URL_PATH),$opts,true) as $p => $s)
513
+						foreach (self::find($options['url'] ? $file : self::parse_url($file, PHP_URL_PATH), $opts, true) as $p => $s)
514 514
 						{
515 515
 							unset($result[$p]);
516 516
 							$result[$p] = $s;
@@ -521,14 +521,14 @@  discard block
 block discarded – undo
521 521
 			}
522 522
 			if ($is_dir && (int)$options['mindepth'] == 0 && $dirs_last)
523 523
 			{
524
-				self::_check_add($options,$path,$result);
524
+				self::_check_add($options, $path, $result);
525 525
 			}
526 526
 		}
527 527
 		// ordering of the rows
528 528
 		if (isset($options['order']))
529 529
 		{
530 530
 			$sort_desc = strtolower($options['sort']) == 'desc';
531
-			switch($order = $options['order'])
531
+			switch ($order = $options['order'])
532 532
 			{
533 533
 				// sort numerical
534 534
 				case 'size':
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
 						// sort code, to place directories before files, if $dirsontop enabled
544 544
 						if ($dirsontop && ($a['mime'] == self::DIR_MIME_TYPE) !== ($b['mime'] == self::DIR_MIME_TYPE))
545 545
 						{
546
-							$cmp = $a['mime' ] == self::DIR_MIME_TYPE ? -1 : 1;
546
+							$cmp = $a['mime'] == self::DIR_MIME_TYPE ? -1 : 1;
547 547
 						}
548 548
 						// reverse sort for descending, if no directory sorted to top
549 549
 						elseif ($sort_desc)
@@ -568,7 +568,7 @@  discard block
 block discarded – undo
568 568
 						// sort code, to place directories before files, if $dirsontop enabled
569 569
 						if ($dirsontop && ($a['mime'] == self::DIR_MIME_TYPE) !== ($b['mime'] == self::DIR_MIME_TYPE))
570 570
 						{
571
-							$cmp = $a['mime' ] == self::DIR_MIME_TYPE ? -1 : 1;
571
+							$cmp = $a['mime'] == self::DIR_MIME_TYPE ? -1 : 1;
572 572
 						}
573 573
 						// reverse sort for descending
574 574
 						elseif ($sort_desc)
@@ -586,13 +586,13 @@  discard block
 block discarded – undo
586 586
 		self::$find_total = count($result);
587 587
 		if (isset($options['limit']))
588 588
 		{
589
-			list($limit,$start) = explode(',',$options['limit']);
589
+			list($limit, $start) = explode(',', $options['limit']);
590 590
 			if (!$limit && !($limit = $GLOBALS['egw_info']['user']['preferences']['comman']['maxmatches'])) $limit = 15;
591 591
 			//echo "total=".self::$find_total.", limit=$options[limit] --> start=$start, limit=$limit<br>\n";
592 592
 
593 593
 			if ((int)$start || self::$find_total > $limit)
594 594
 			{
595
-				$result = array_slice($result,(int)$start,(int)$limit,true);
595
+				$result = array_slice($result, (int)$start, (int)$limit, true);
596 596
 			}
597 597
 		}
598 598
 		//echo $path; _debug_array($result);
@@ -602,13 +602,13 @@  discard block
 block discarded – undo
602 602
 			{
603 603
 				$exec_params = is_null($exec_params) ? array() : array($exec_params);
604 604
 			}
605
-			foreach($result as $path => &$stat)
605
+			foreach ($result as $path => &$stat)
606 606
 			{
607 607
 				$options = $exec_params;
608
-				array_unshift($options,$path);
609
-				array_push($options,$stat);
608
+				array_unshift($options, $path);
609
+				array_push($options, $stat);
610 610
 				//echo "calling ".print_r($exec,true).print_r($options,true)."\n";
611
-				$stat = call_user_func_array($exec,$options);
611
+				$stat = call_user_func_array($exec, $options);
612 612
 			}
613 613
 			return $result;
614 614
 		}
@@ -627,15 +627,15 @@  discard block
 block discarded – undo
627 627
 	 * @param string $path name of path to add
628 628
 	 * @param array &$result here we add the stat for the key $path, if the checks are successful
629 629
 	 */
630
-	private static function _check_add($options,$path,&$result)
630
+	private static function _check_add($options, $path, &$result)
631 631
 	{
632
-		$type = $options['type'];	// 'd' or 'f'
632
+		$type = $options['type']; // 'd' or 'f'
633 633
 
634 634
 		if ($options['url'])
635 635
 		{
636 636
 			if (($stat = @lstat($path)))
637 637
 			{
638
-				$stat = array_slice($stat,13);	// remove numerical indices 0-12
638
+				$stat = array_slice($stat, 13); // remove numerical indices 0-12
639 639
 			}
640 640
 		}
641 641
 		else
@@ -644,30 +644,30 @@  discard block
 block discarded – undo
644 644
 		}
645 645
 		if (!$stat)
646 646
 		{
647
-			return;	// not found, should not happen
647
+			return; // not found, should not happen
648 648
 		}
649
-		if ($type && (($type == 'd') == !($stat['mode'] & Vfs\Sqlfs\StreamWrapper::MODE_DIR) ||	// != is_dir() which can be true for symlinks
649
+		if ($type && (($type == 'd') == !($stat['mode']&Vfs\Sqlfs\StreamWrapper::MODE_DIR) || // != is_dir() which can be true for symlinks
650 650
 		    $type == 'F' && is_dir($path)))	// symlink to a directory
651 651
 		{
652
-			return;	// wrong type
652
+			return; // wrong type
653 653
 		}
654
-		$stat['path'] = self::parse_url($path,PHP_URL_PATH);
655
-		$stat['name'] = $options['remove'] > 0 ? implode('/',array_slice(explode('/',$stat['path']),$options['remove'])) : self::basename($path);
654
+		$stat['path'] = self::parse_url($path, PHP_URL_PATH);
655
+		$stat['name'] = $options['remove'] > 0 ? implode('/', array_slice(explode('/', $stat['path']), $options['remove'])) : self::basename($path);
656 656
 
657 657
 		if ($options['mime'] || $options['need_mime'])
658 658
 		{
659 659
 			$stat['mime'] = self::mime_content_type($path);
660 660
 		}
661
-		if (isset($options['name_preg']) && !preg_match($options['name_preg'],$stat['name']) ||
662
-			isset($options['path_preg']) && !preg_match($options['path_preg'],$path))
661
+		if (isset($options['name_preg']) && !preg_match($options['name_preg'], $stat['name']) ||
662
+			isset($options['path_preg']) && !preg_match($options['path_preg'], $path))
663 663
 		{
664 664
 			//echo "<p>!preg_match('{$options['name_preg']}','{$stat['name']}')</p>\n";
665
-			return;	// wrong name or path
665
+			return; // wrong name or path
666 666
 		}
667 667
 		if (isset($options['gid']) && $stat['gid'] != $options['gid'] ||
668 668
 			isset($options['uid']) && $stat['uid'] != $options['uid'])
669 669
 		{
670
-			return;	// wrong user or group
670
+			return; // wrong user or group
671 671
 		}
672 672
 		if (isset($options['mime']) && $options['mime'] != $stat['mime'])
673 673
 		{
@@ -675,40 +675,40 @@  discard block
 block discarded – undo
675 675
 			{
676 676
 				if (!preg_match($options['mime'], $stat['mime']))
677 677
 				{
678
-					return;	// wrong mime-type
678
+					return; // wrong mime-type
679 679
 				}
680 680
 			}
681 681
 			else
682 682
 			{
683
-				list($type,$subtype) = explode('/',$options['mime']);
683
+				list($type, $subtype) = explode('/', $options['mime']);
684 684
 				// no subtype (eg. 'image') --> check only the main type
685
-				if ($subtype || substr($stat['mime'],0,strlen($type)+1) != $type.'/')
685
+				if ($subtype || substr($stat['mime'], 0, strlen($type) + 1) != $type.'/')
686 686
 				{
687
-					return;	// wrong mime-type
687
+					return; // wrong mime-type
688 688
 				}
689 689
 			}
690 690
 		}
691
-		if (isset($options['size']) && !self::_check_num($stat['size'],$options['size']) ||
691
+		if (isset($options['size']) && !self::_check_num($stat['size'], $options['size']) ||
692 692
 			(isset($options['empty']) && !!$options['empty'] !== !$stat['size']))
693 693
 		{
694
-			return;	// wrong size
694
+			return; // wrong size
695 695
 		}
696
-		if (isset($options['cmin']) && !self::_check_num(round((time()-$stat['ctime'])/60),$options['cmin']) ||
697
-			isset($options['mmin']) && !self::_check_num(round((time()-$stat['mtime'])/60),$options['mmin']) ||
698
-			isset($options['ctime']) && !self::_check_num(round((time()-$stat['ctime'])/86400),$options['ctime']) ||
699
-			isset($options['mtime']) && !self::_check_num(round((time()-$stat['mtime'])/86400),$options['mtime']))
696
+		if (isset($options['cmin']) && !self::_check_num(round((time() - $stat['ctime']) / 60), $options['cmin']) ||
697
+			isset($options['mmin']) && !self::_check_num(round((time() - $stat['mtime']) / 60), $options['mmin']) ||
698
+			isset($options['ctime']) && !self::_check_num(round((time() - $stat['ctime']) / 86400), $options['ctime']) ||
699
+			isset($options['mtime']) && !self::_check_num(round((time() - $stat['mtime']) / 86400), $options['mtime']))
700 700
 		{
701
-			return;	// not create/modified in the spezified time
701
+			return; // not create/modified in the spezified time
702 702
 		}
703 703
 		// do we return url or just vfs pathes
704 704
 		if (!$options['url'])
705 705
 		{
706
-			$path = self::parse_url($path,PHP_URL_PATH);
706
+			$path = self::parse_url($path, PHP_URL_PATH);
707 707
 		}
708 708
 		$result[$path] = $stat;
709 709
 	}
710 710
 
711
-	private static function _check_num($value,$argument)
711
+	private static function _check_num($value, $argument)
712 712
 	{
713 713
 		if (is_int($argument) && $argument >= 0 || $argument[0] != '-' && $argument[0] != '+')
714 714
 		{
@@ -721,7 +721,7 @@  discard block
 block discarded – undo
721 721
 			return $value < abs($argument);
722 722
 		}
723 723
 		//echo "_check_num($value,$argument) check > == ".(int)($value > (int)substr($argument,1))."\n";
724
-		return $value > (int) substr($argument,1);
724
+		return $value > (int)substr($argument, 1);
725 725
 	}
726 726
 
727 727
 	/**
@@ -751,10 +751,10 @@  discard block
 block discarded – undo
751 751
 	 * @throws Vfs\Exception\ProtectedDirectory if trying to delete a protected directory, see Vfs::isProtected()
752 752
 	 * @return array
753 753
 	 */
754
-	static function remove($urls,$allow_urls=false)
754
+	static function remove($urls, $allow_urls = false)
755 755
 	{
756 756
 		//error_log(__METHOD__.'('.array2string($urls).')');
757
-		foreach((array)$urls as $url)
757
+		foreach ((array)$urls as $url)
758 758
 		{
759 759
 			// some precaution to never allow to (recursivly) remove /, /apps or /home, see Vfs::isProtected()
760 760
 			if (self::isProtectedDir($url))
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
 				throw new Vfs\Exception\ProtectedDirectory("Deleting protected directory '$url' rejected!");
763 763
 			}
764 764
 		}
765
-		return self::find($urls, array('depth'=>true,'url'=>$allow_urls,'hidden'=>true), __CLASS__.'::_rm_rmdir');
765
+		return self::find($urls, array('depth'=>true, 'url'=>$allow_urls, 'hidden'=>true), __CLASS__.'::_rm_rmdir');
766 766
 	}
767 767
 
768 768
 	/**
@@ -775,12 +775,12 @@  discard block
 block discarded – undo
775 775
 	{
776 776
 		if ($url[0] == '/')
777 777
 		{
778
-			$url = self::PREFIX . $url;
778
+			$url = self::PREFIX.$url;
779 779
 		}
780 780
 		$vfs = new Vfs\StreamWrapper();
781 781
 		if (is_dir($url) && !is_link($url))
782 782
 		{
783
-			return $vfs->rmdir($url,0);
783
+			return $vfs->rmdir($url, 0);
784 784
 		}
785 785
 		return $vfs->unlink($url);
786 786
 	}
@@ -794,9 +794,9 @@  discard block
 block discarded – undo
794 794
 	 * 	2 = self::WRITABLE, 1 = self::EXECUTABLE
795 795
 	 * @return boolean
796 796
 	 */
797
-	static function is_readable($path,$check = self::READABLE)
797
+	static function is_readable($path, $check = self::READABLE)
798 798
 	{
799
-		return self::check_access($path,$check);
799
+		return self::check_access($path, $check);
800 800
 	}
801 801
 
802 802
 	/**
@@ -810,7 +810,7 @@  discard block
 block discarded – undo
810 810
 	 * @param int $user =null user used for check, if not current user (self::$user)
811 811
 	 * @return boolean
812 812
 	 */
813
-	static function check_access($path, $check, $stat=null, $user=null)
813
+	static function check_access($path, $check, $stat = null, $user = null)
814 814
 	{
815 815
 		static $vfs = null;
816 816
 
@@ -828,7 +828,7 @@  discard block
 block discarded – undo
828 828
 				if (!isset($vfs)) $vfs = new Vfs\StreamWrapper();
829 829
 				$path_user_stat[$path][$user] = $vfs->url_stat($path, 0);
830 830
 
831
-				self::clearstatcache($path);	// we need to clear the stat-cache after the call too, as the next call might be the regular user again!
831
+				self::clearstatcache($path); // we need to clear the stat-cache after the call too, as the next call might be the regular user again!
832 832
 			}
833 833
 			if (($stat = $path_user_stat[$path][$user]))
834 834
 			{
@@ -844,7 +844,7 @@  discard block
 block discarded – undo
844 844
 			}
845 845
 			else
846 846
 			{
847
-				$ret = false;	// no access, if we can not stat the file
847
+				$ret = false; // no access, if we can not stat the file
848 848
 			}
849 849
 			self::$user = $backup_user;
850 850
 
@@ -869,20 +869,20 @@  discard block
 block discarded – undo
869 869
 		if (is_null($stat))
870 870
 		{
871 871
 			if (!isset($vfs)) $vfs = new Vfs\StreamWrapper();
872
-			$stat = $vfs->url_stat($path,0);
872
+			$stat = $vfs->url_stat($path, 0);
873 873
 		}
874 874
 		//error_log(__METHOD__."(path=$path||stat[name]={$stat['name']},stat[mode]=".sprintf('%o',$stat['mode']).",$check)");
875 875
 
876 876
 		if (!$stat)
877 877
 		{
878 878
 			//error_log(__METHOD__."(path=$path||stat[name]={$stat['name']},stat[mode]=".sprintf('%o',$stat['mode']).",$check) no stat array!");
879
-			return false;	// file not found
879
+			return false; // file not found
880 880
 		}
881 881
 		// check if we use an EGroupwre stream wrapper, or a stock php one
882 882
 		// if it's not an EGroupware one, we can NOT use uid, gid and mode!
883
-		if (($scheme = self::parse_url($stat['url'],PHP_URL_SCHEME)) && !(class_exists(self::scheme2class($scheme))))
883
+		if (($scheme = self::parse_url($stat['url'], PHP_URL_SCHEME)) && !(class_exists(self::scheme2class($scheme))))
884 884
 		{
885
-			switch($check)
885
+			switch ($check)
886 886
 			{
887 887
 				case self::READABLE:
888 888
 					return is_readable($stat['url']);
@@ -893,19 +893,19 @@  discard block
 block discarded – undo
893 893
 			}
894 894
 		}
895 895
 		// check if other rights grant access
896
-		if (($stat['mode'] & $check) == $check)
896
+		if (($stat['mode']&$check) == $check)
897 897
 		{
898 898
 			//error_log(__METHOD__."(path=$path||stat[name]={$stat['name']},stat[mode]=".sprintf('%o',$stat['mode']).",$check) access via other rights!");
899 899
 			return true;
900 900
 		}
901 901
 		// check if there's owner access and we are the owner
902
-		if (($stat['mode'] & ($check << 6)) == ($check << 6) && $stat['uid'] && $stat['uid'] == self::$user)
902
+		if (($stat['mode']&($check << 6)) == ($check << 6) && $stat['uid'] && $stat['uid'] == self::$user)
903 903
 		{
904 904
 			//error_log(__METHOD__."(path=$path||stat[name]={$stat['name']},stat[mode]=".sprintf('%o',$stat['mode']).",$check) access via owner rights!");
905 905
 			return true;
906 906
 		}
907 907
 		// check if there's a group access and we have the right membership
908
-		if (($stat['mode'] & ($check << 3)) == ($check << 3) && $stat['gid'])
908
+		if (($stat['mode']&($check << 3)) == ($check << 3) && $stat['gid'])
909 909
 		{
910 910
 			if (($memberships = $GLOBALS['egw']->accounts->memberships(self::$user, true)) && in_array(-abs($stat['gid']), $memberships))
911 911
 			{
@@ -919,7 +919,7 @@  discard block
 block discarded – undo
919 919
 			return false;
920 920
 		}
921 921
 		// check backend for extended acls (only if path given)
922
-		$ret = $path && self::_call_on_backend('check_extended_acl',array(isset($stat['url'])?$stat['url']:$path,$check),true);	// true = fail silent if backend does not support
922
+		$ret = $path && self::_call_on_backend('check_extended_acl', array(isset($stat['url']) ? $stat['url'] : $path, $check), true); // true = fail silent if backend does not support
923 923
 
924 924
 		//error_log(__METHOD__."(path=$path||stat[name]={$stat['name']},stat[mode]=".sprintf('%o',$stat['mode']).",$check) ".($ret ? 'backend extended acl granted access.' : 'no access!!!'));
925 925
 		return $ret;
@@ -934,7 +934,7 @@  discard block
 block discarded – undo
934 934
 	 */
935 935
 	static function is_writable($path)
936 936
 	{
937
-		return self::is_readable($path,self::WRITABLE);
937
+		return self::is_readable($path, self::WRITABLE);
938 938
 	}
939 939
 
940 940
 	/**
@@ -946,7 +946,7 @@  discard block
 block discarded – undo
946 946
 	 */
947 947
 	static function is_executable($path)
948 948
 	{
949
-		return self::is_readable($path,self::EXECUTABLE);
949
+		return self::is_readable($path, self::EXECUTABLE);
950 950
 	}
951 951
 
952 952
 	/**
@@ -957,7 +957,7 @@  discard block
 block discarded – undo
957 957
 	 */
958 958
 	static function deny_script($path)
959 959
 	{
960
-		return self::_call_on_backend('deny_script',array($path),true);
960
+		return self::_call_on_backend('deny_script', array($path), true);
961 961
 	}
962 962
 
963 963
 	/**
@@ -976,11 +976,11 @@  discard block
 block discarded – undo
976 976
 	 * @param boolean $session_only =false true: set eacl only for this session, does NO further checks currently!
977 977
 	 * @return boolean true if acl is set/deleted, false on error
978 978
 	 */
979
-	static function eacl($url,$rights=null,$owner=null,$session_only=false)
979
+	static function eacl($url, $rights = null, $owner = null, $session_only = false)
980 980
 	{
981 981
 		if ($session_only)
982 982
 		{
983
-			$session_eacls =& Cache::getSession(__CLASS__, self::SESSION_EACL);
983
+			$session_eacls = & Cache::getSession(__CLASS__, self::SESSION_EACL);
984 984
 			$session_eacls[] = array(
985 985
 				'path'   => $url[0] == '/' ? $url : self::parse_url($url, PHP_URL_PATH),
986 986
 				'owner'  => $owner ? $owner : self::$user,
@@ -988,7 +988,7 @@  discard block
 block discarded – undo
988 988
 			);
989 989
 			return true;
990 990
 		}
991
-		return self::_call_on_backend('eacl',array($url,$rights,$owner));
991
+		return self::_call_on_backend('eacl', array($url, $rights, $owner));
992 992
 	}
993 993
 
994 994
 	/**
@@ -1001,9 +1001,9 @@  discard block
 block discarded – undo
1001 1001
 	 */
1002 1002
 	static function get_eacl($path)
1003 1003
 	{
1004
-		$eacls = self::_call_on_backend('get_eacl',array($path),true);	// true = fail silent (no PHP Warning)
1004
+		$eacls = self::_call_on_backend('get_eacl', array($path), true); // true = fail silent (no PHP Warning)
1005 1005
 
1006
-		$session_eacls =& Cache::getSession(__CLASS__, self::SESSION_EACL);
1006
+		$session_eacls = & Cache::getSession(__CLASS__, self::SESSION_EACL);
1007 1007
 		if ($session_eacls)
1008 1008
 		{
1009 1009
 			// eacl is recursive, therefore we have to match all parent-dirs too
@@ -1012,7 +1012,7 @@  discard block
 block discarded – undo
1012 1012
 			{
1013 1013
 				$paths[] = $path = self::dirname($path);
1014 1014
 			}
1015
-			foreach((array)$session_eacls as $eacl)
1015
+			foreach ((array)$session_eacls as $eacl)
1016 1016
 			{
1017 1017
 				if (in_array($eacl['path'], $paths))
1018 1018
 				{
@@ -1035,9 +1035,9 @@  discard block
 block discarded – undo
1035 1035
 	 * @param array $props array of array with values for keys 'name', 'ns', 'val' (null to delete the prop)
1036 1036
 	 * @return boolean true if props are updated, false otherwise (eg. ressource not found)
1037 1037
 	 */
1038
-	static function proppatch($path,array $props)
1038
+	static function proppatch($path, array $props)
1039 1039
 	{
1040
-		return self::_call_on_backend('proppatch',array($path,$props));
1040
+		return self::_call_on_backend('proppatch', array($path, $props));
1041 1041
 	}
1042 1042
 
1043 1043
 	/**
@@ -1054,9 +1054,9 @@  discard block
 block discarded – undo
1054 1054
 	 * @return array|boolean array with props (values for keys 'name', 'ns', 'val'), or path => array of props for is_array($path)
1055 1055
 	 * 	false if $path does not exist
1056 1056
 	 */
1057
-	static function propfind($path,$ns=self::DEFAULT_PROP_NAMESPACE)
1057
+	static function propfind($path, $ns = self::DEFAULT_PROP_NAMESPACE)
1058 1058
 	{
1059
-		return self::_call_on_backend('propfind',array($path,$ns),true);	// true = fail silent (no PHP Warning)
1059
+		return self::_call_on_backend('propfind', array($path, $ns), true); // true = fail silent (no PHP Warning)
1060 1060
 	}
1061 1061
 
1062 1062
 	/**
@@ -1074,7 +1074,7 @@  discard block
 block discarded – undo
1074 1074
 	 * @param int $mode =0 current mode of the file, necessary for +/- operation
1075 1075
 	 * @return int
1076 1076
 	 */
1077
-	static function mode2int($set,$mode=0)
1077
+	static function mode2int($set, $mode = 0)
1078 1078
 	{
1079 1079
 		if (is_int($set))		// already an integer
1080 1080
 		{
@@ -1083,23 +1083,23 @@  discard block
 block discarded – undo
1083 1083
 		if (is_numeric($set))	// octal string
1084 1084
 		{
1085 1085
 			//error_log(__METHOD__."($set,$mode) returning ".(int)base_convert($set,8,10));
1086
-			return (int)base_convert($set,8,10);	// convert octal to decimal
1086
+			return (int)base_convert($set, 8, 10); // convert octal to decimal
1087 1087
 		}
1088
-		foreach(explode(',',$set) as $s)
1088
+		foreach (explode(',', $set) as $s)
1089 1089
 		{
1090 1090
 			$matches = null;
1091
-			if (!preg_match($use='/^([ugoa]*)([+=-]+)([rwx]+)$/',$s,$matches))
1091
+			if (!preg_match($use = '/^([ugoa]*)([+=-]+)([rwx]+)$/', $s, $matches))
1092 1092
 			{
1093
-				$use = str_replace(array('/','^','$','(',')'),'',$use);
1093
+				$use = str_replace(array('/', '^', '$', '(', ')'), '', $use);
1094 1094
 				throw new Exception\WrongUserinput("$s is not an allowed mode, use $use !");
1095 1095
 			}
1096
-			$base = (strpos($matches[3],'r') !== false ? self::READABLE : 0) |
1097
-				(strpos($matches[3],'w') !== false ? self::WRITABLE : 0) |
1098
-				(strpos($matches[3],'x') !== false ? self::EXECUTABLE : 0);
1096
+			$base = (strpos($matches[3], 'r') !== false ? self::READABLE : 0)|
1097
+				(strpos($matches[3], 'w') !== false ? self::WRITABLE : 0)|
1098
+				(strpos($matches[3], 'x') !== false ? self::EXECUTABLE : 0);
1099 1099
 
1100
-			for($n = $m = 0; $n < strlen($matches[1]); $n++)
1100
+			for ($n = $m = 0; $n < strlen($matches[1]); $n++)
1101 1101
 			{
1102
-				switch($matches[1][$n])
1102
+				switch ($matches[1][$n])
1103 1103
 				{
1104 1104
 					case 'o':
1105 1105
 						$m |= $base;
@@ -1112,10 +1112,10 @@  discard block
 block discarded – undo
1112 1112
 						break;
1113 1113
 					default:
1114 1114
 					case 'a':
1115
-						$m = $base | ($base << 3) | ($base << 6);
1115
+						$m = $base|($base << 3)|($base << 6);
1116 1116
 				}
1117 1117
 			}
1118
-			switch($matches[2])
1118
+			switch ($matches[2])
1119 1119
 			{
1120 1120
 				case '+':
1121 1121
 					$mode |= $m;
@@ -1137,33 +1137,33 @@  discard block
 block discarded – undo
1137 1137
 	 * @param int $mode
1138 1138
 	 * @return string
1139 1139
 	 */
1140
-	static function int2mode( $mode )
1140
+	static function int2mode($mode)
1141 1141
 	{
1142
-		if(($mode & self::MODE_LINK) == self::MODE_LINK) // Symbolic Link
1142
+		if (($mode&self::MODE_LINK) == self::MODE_LINK) // Symbolic Link
1143 1143
 		{
1144 1144
 			$sP = 'l';
1145 1145
 		}
1146
-		elseif(($mode & 0xC000) == 0xC000) // Socket
1146
+		elseif (($mode&0xC000) == 0xC000) // Socket
1147 1147
 		{
1148 1148
 			$sP = 's';
1149 1149
 		}
1150
-		elseif($mode & 0x1000)     // FIFO pipe
1150
+		elseif ($mode&0x1000)     // FIFO pipe
1151 1151
 		{
1152 1152
 			$sP = 'p';
1153 1153
 		}
1154
-		elseif($mode & 0x2000) // Character special
1154
+		elseif ($mode&0x2000) // Character special
1155 1155
 		{
1156 1156
 			$sP = 'c';
1157 1157
 		}
1158
-		elseif($mode & 0x4000) // Directory
1158
+		elseif ($mode&0x4000) // Directory
1159 1159
 		{
1160 1160
 			$sP = 'd';
1161 1161
 		}
1162
-		elseif($mode & 0x6000) // Block special
1162
+		elseif ($mode&0x6000) // Block special
1163 1163
 		{
1164 1164
 			$sP = 'b';
1165 1165
 		}
1166
-		elseif($mode & 0x8000) // Regular
1166
+		elseif ($mode&0x8000) // Regular
1167 1167
 		{
1168 1168
 			$sP = '-';
1169 1169
 		}
@@ -1173,22 +1173,19 @@  discard block
 block discarded – undo
1173 1173
 		}
1174 1174
 
1175 1175
 		// owner
1176
-		$sP .= (($mode & 0x0100) ? 'r' : '-') .
1177
-		(($mode & 0x0080) ? 'w' : '-') .
1178
-		(($mode & 0x0040) ? (($mode & 0x0800) ? 's' : 'x' ) :
1179
-		(($mode & 0x0800) ? 'S' : '-'));
1176
+		$sP .= (($mode&0x0100) ? 'r' : '-').
1177
+		(($mode&0x0080) ? 'w' : '-').
1178
+		(($mode&0x0040) ? (($mode&0x0800) ? 's' : 'x') : (($mode&0x0800) ? 'S' : '-'));
1180 1179
 
1181 1180
 		// group
1182
-		$sP .= (($mode & 0x0020) ? 'r' : '-') .
1183
-		(($mode & 0x0010) ? 'w' : '-') .
1184
-		(($mode & 0x0008) ? (($mode & 0x0400) ? 's' : 'x' ) :
1185
-		(($mode & 0x0400) ? 'S' : '-'));
1181
+		$sP .= (($mode&0x0020) ? 'r' : '-').
1182
+		(($mode&0x0010) ? 'w' : '-').
1183
+		(($mode&0x0008) ? (($mode&0x0400) ? 's' : 'x') : (($mode&0x0400) ? 'S' : '-'));
1186 1184
 
1187 1185
 		// world
1188
-		$sP .= (($mode & 0x0004) ? 'r' : '-') .
1189
-		(($mode & 0x0002) ? 'w' : '-') .
1190
-		(($mode & 0x0001) ? (($mode & 0x0200) ? 't' : 'x' ) :
1191
-		(($mode & 0x0200) ? 'T' : '-'));
1186
+		$sP .= (($mode&0x0004) ? 'r' : '-').
1187
+		(($mode&0x0002) ? 'w' : '-').
1188
+		(($mode&0x0001) ? (($mode&0x0200) ? 't' : 'x') : (($mode&0x0200) ? 'T' : '-'));
1192 1189
 
1193 1190
 		return $sP;
1194 1191
 	}
@@ -1201,26 +1198,26 @@  discard block
 block discarded – undo
1201 1198
 	 * @param int $size =128
1202 1199
 	 * @return string
1203 1200
 	 */
1204
-	static function mime_icon($mime_type, $et_image=true, $size=128)
1201
+	static function mime_icon($mime_type, $et_image = true, $size = 128)
1205 1202
 	{
1206 1203
 		if ($mime_type == self::DIR_MIME_TYPE)
1207 1204
 		{
1208 1205
 			$mime_type = 'Directory';
1209 1206
 		}
1210
-		if(!$mime_type)
1207
+		if (!$mime_type)
1211 1208
 		{
1212 1209
 			$mime_type = 'unknown';
1213 1210
 		}
1214
-		$mime_full = strtolower(str_replace	('/','_',$mime_type));
1215
-		list($mime_part) = explode('_',$mime_full);
1211
+		$mime_full = strtolower(str_replace('/', '_', $mime_type));
1212
+		list($mime_part) = explode('_', $mime_full);
1216 1213
 
1217
-		if (!($img=Image::find('etemplate',$icon='mime'.$size.'_'.$mime_full)) &&
1214
+		if (!($img = Image::find('etemplate', $icon = 'mime'.$size.'_'.$mime_full)) &&
1218 1215
 			// check mime-alias-map before falling back to more generic icons
1219 1216
 			!(isset(MimeMagic::$mime_alias_map[$mime_type]) &&
1220
-				($img=Image::find('etemplate',$icon='mime'.$size.'_'.str_replace('/','_',MimeMagic::$mime_alias_map[$mime_full])))) &&
1221
-			!($img=Image::find('etemplate',$icon='mime'.$size.'_'.$mime_part)))
1217
+				($img = Image::find('etemplate', $icon = 'mime'.$size.'_'.str_replace('/', '_', MimeMagic::$mime_alias_map[$mime_full])))) &&
1218
+			!($img = Image::find('etemplate', $icon = 'mime'.$size.'_'.$mime_part)))
1222 1219
 		{
1223
-			$img = Image::find('etemplate',$icon='mime'.$size.'_unknown');
1220
+			$img = Image::find('etemplate', $icon = 'mime'.$size.'_unknown');
1224 1221
 		}
1225 1222
 		return $et_image ? 'etemplate/'.$icon : $img;
1226 1223
 	}
@@ -1234,9 +1231,9 @@  discard block
 block discarded – undo
1234 1231
 	static function hsize($size)
1235 1232
 	{
1236 1233
 		if ($size < 1024) return $size;
1237
-		if ($size < 1024*1024) return sprintf('%3.1lfk',(float)$size/1024);
1238
-		if ($size < 1024*1024*1024) return sprintf('%3.1lfM',(float)$size/(1024*1024));
1239
-		return sprintf('%3.1lfG',(float)$size/(1024*1024*1024));
1234
+		if ($size < 1024 * 1024) return sprintf('%3.1lfk', (float)$size / 1024);
1235
+		if ($size < 1024 * 1024 * 1024) return sprintf('%3.1lfM', (float)$size / (1024 * 1024));
1236
+		return sprintf('%3.1lfG', (float)$size / (1024 * 1024 * 1024));
1240 1237
 	}
1241 1238
 
1242 1239
 	/**
@@ -1246,7 +1243,7 @@  discard block
 block discarded – undo
1246 1243
 	 */
1247 1244
 	static function int_size($_val)
1248 1245
 	{
1249
-		if(empty($_val))return 0;
1246
+		if (empty($_val))return 0;
1250 1247
 
1251 1248
 		$val = trim($_val);
1252 1249
 
@@ -1254,12 +1251,12 @@  discard block
 block discarded – undo
1254 1251
 		preg_match('#([0-9]+)[\s]*([a-z]+)#i', $val, $matches);
1255 1252
 
1256 1253
 		$last = '';
1257
-		if(isset($matches[2])){
1254
+		if (isset($matches[2])) {
1258 1255
 			$last = $matches[2];
1259 1256
 		}
1260 1257
 
1261
-		if(isset($matches[1])){
1262
-			$val = (int) $matches[1];
1258
+		if (isset($matches[1])) {
1259
+			$val = (int)$matches[1];
1263 1260
 		}
1264 1261
 
1265 1262
 		switch (strtolower($last))
@@ -1275,7 +1272,7 @@  discard block
 block discarded – undo
1275 1272
 			$val *= 1024;
1276 1273
 		}
1277 1274
 
1278
-		return (int) $val;
1275
+		return (int)$val;
1279 1276
 	}
1280 1277
 
1281 1278
 	/**
@@ -1286,8 +1283,8 @@  discard block
 block discarded – undo
1286 1283
 	 */
1287 1284
 	static function basename($_path)
1288 1285
 	{
1289
-		list($path) = explode('?',$_path);	// remove query
1290
-		$parts = explode('/',$path);
1286
+		list($path) = explode('?', $_path); // remove query
1287
+		$parts = explode('/', $path);
1291 1288
 
1292 1289
 		return array_pop($parts);
1293 1290
 	}
@@ -1301,7 +1298,7 @@  discard block
 block discarded – undo
1301 1298
 	 * @param int $component =-1 PHP_URL_* constants
1302 1299
 	 * @return array|string|boolean on success array or string, if $component given, or false on failure
1303 1300
 	 */
1304
-	static function parse_url($url, $component=-1)
1301
+	static function parse_url($url, $component = -1)
1305 1302
 	{
1306 1303
 		static $component2str = array(
1307 1304
 			PHP_URL_SCHEME => 'scheme',
@@ -1313,9 +1310,9 @@  discard block
 block discarded – undo
1313 1310
 			PHP_URL_QUERY => 'query',
1314 1311
 			PHP_URL_FRAGMENT => 'fragment',
1315 1312
 		);
1316
-		static $cache = array();	// some caching
1313
+		static $cache = array(); // some caching
1317 1314
 
1318
-		$result =& $cache[$url];
1315
+		$result = & $cache[$url];
1319 1316
 
1320 1317
 		if (!isset($result))
1321 1318
 		{
@@ -1355,22 +1352,22 @@  discard block
 block discarded – undo
1355 1352
 	 */
1356 1353
 	static function dirname($_url)
1357 1354
 	{
1358
-		list($url,$query) = explode('?',$_url,2);	// strip the query first, as it can contain slashes
1355
+		list($url, $query) = explode('?', $_url, 2); // strip the query first, as it can contain slashes
1359 1356
 
1360
-		if ($url == '/' || $url[0] != '/' && self::parse_url($url,PHP_URL_PATH) == '/')
1357
+		if ($url == '/' || $url[0] != '/' && self::parse_url($url, PHP_URL_PATH) == '/')
1361 1358
 		{
1362 1359
 			//error_log(__METHOD__."($url) returning FALSE: already in root!");
1363 1360
 			return false;
1364 1361
 		}
1365
-		$parts = explode('/',$url);
1366
-		if (substr($url,-1) == '/') array_pop($parts);
1362
+		$parts = explode('/', $url);
1363
+		if (substr($url, -1) == '/') array_pop($parts);
1367 1364
 		array_pop($parts);
1368 1365
 		if ($url[0] != '/' && count($parts) == 3 || count($parts) == 1 && $parts[0] === '')
1369 1366
 		{
1370
-			array_push($parts,'');	// scheme://host is wrong (no path), has to be scheme://host/
1367
+			array_push($parts, ''); // scheme://host is wrong (no path), has to be scheme://host/
1371 1368
 		}
1372 1369
 		//error_log(__METHOD__."($url)=".implode('/',$parts).($query ? '?'.$query : ''));
1373
-		return implode('/',$parts).($query ? '?'.$query : '');
1370
+		return implode('/', $parts).($query ? '?'.$query : '');
1374 1371
 	}
1375 1372
 
1376 1373
 	/**
@@ -1382,18 +1379,18 @@  discard block
 block discarded – undo
1382 1379
 	 * @param array $stat =null stat for path, default queried by this function
1383 1380
 	 * @return boolean
1384 1381
 	 */
1385
-	static function has_owner_rights($path,array $stat=null)
1382
+	static function has_owner_rights($path, array $stat = null)
1386 1383
 	{
1387 1384
 		if (!$stat)
1388 1385
 		{
1389 1386
 			$vfs = new Vfs\StreamWrapper();
1390
-			$stat = $vfs->url_stat($path,0);
1387
+			$stat = $vfs->url_stat($path, 0);
1391 1388
 		}
1392
-		return $stat['uid'] == self::$user &&	// (current) user is the owner
1389
+		return $stat['uid'] == self::$user && // (current) user is the owner
1393 1390
 				// in sharing current user != self::$user and should NOT have owner rights
1394 1391
 				$GLOBALS['egw_info']['user']['account_id'] == self::$user ||
1395
-			self::$is_root ||					// class runs with root rights
1396
-			!$stat['uid'] && $stat['gid'] && self::$is_admin;	// group directory and user is an eGW admin
1392
+			self::$is_root || // class runs with root rights
1393
+			!$stat['uid'] && $stat['gid'] && self::$is_admin; // group directory and user is an eGW admin
1397 1394
 	}
1398 1395
 
1399 1396
 	/**
@@ -1405,22 +1402,22 @@  discard block
 block discarded – undo
1405 1402
 	 * @param string $relative relative path to add to $url
1406 1403
 	 * @return string
1407 1404
 	 */
1408
-	static function concat($_url,$relative)
1405
+	static function concat($_url, $relative)
1409 1406
 	{
1410
-		list($url,$query) = explode('?',$_url,2);
1411
-		if (substr($url,-1) == '/') $url = substr($url,0,-1);
1407
+		list($url, $query) = explode('?', $_url, 2);
1408
+		if (substr($url, -1) == '/') $url = substr($url, 0, -1);
1412 1409
 		$ret = ($relative === '' || $relative[0] == '/' ? $url.$relative : $url.'/'.$relative);
1413 1410
 
1414 1411
 		// now normalize the path (remove "/something/..")
1415
-		while (strpos($ret,'/../') !== false)
1412
+		while (strpos($ret, '/../') !== false)
1416 1413
 		{
1417
-			list($a_str,$b_str) = explode('/../',$ret,2);
1418
-			$a = explode('/',$a_str);
1414
+			list($a_str, $b_str) = explode('/../', $ret, 2);
1415
+			$a = explode('/', $a_str);
1419 1416
 			array_pop($a);
1420
-			$b = explode('/',$b_str);
1421
-			$ret = implode('/',array_merge($a,$b));
1417
+			$b = explode('/', $b_str);
1418
+			$ret = implode('/', array_merge($a, $b));
1422 1419
 		}
1423
-		return $ret.($query ? (strpos($url,'?')===false ? '?' : '&').$query : '');
1420
+		return $ret.($query ? (strpos($url, '?') === false ? '?' : '&').$query : '');
1424 1421
 	}
1425 1422
 
1426 1423
 	/**
@@ -1431,11 +1428,11 @@  discard block
 block discarded – undo
1431 1428
 	 */
1432 1429
 	static function build_url(array $url_parts)
1433 1430
 	{
1434
-		$url = (!isset($url_parts['scheme'])?'':$url_parts['scheme'].'://'.
1435
-			(!isset($url_parts['user'])?'':$url_parts['user'].(!isset($url_parts['pass'])?'':':'.$url_parts['pass']).'@').
1431
+		$url = (!isset($url_parts['scheme']) ? '' : $url_parts['scheme'].'://'.
1432
+			(!isset($url_parts['user']) ? '' : $url_parts['user'].(!isset($url_parts['pass']) ? '' : ':'.$url_parts['pass']).'@').
1436 1433
 			$url_parts['host']).$url_parts['path'].
1437
-			(!isset($url_parts['query'])?'':'?'.$url_parts['query']).
1438
-			(!isset($url_parts['fragment'])?'':'?'.$url_parts['fragment']);
1434
+			(!isset($url_parts['query']) ? '' : '?'.$url_parts['query']).
1435
+			(!isset($url_parts['fragment']) ? '' : '?'.$url_parts['fragment']);
1439 1436
 		//error_log(__METHOD__.'('.array2string($url_parts).") = '".$url."'");
1440 1437
 		return $url;
1441 1438
 	}
@@ -1453,19 +1450,19 @@  discard block
 block discarded – undo
1453 1450
 	 * @todo get $force_download working through webdav
1454 1451
 	 * @return string
1455 1452
 	 */
1456
-	static function download_url($path,$force_download=false)
1453
+	static function download_url($path, $force_download = false)
1457 1454
 	{
1458
-		if (($url = self::_call_on_backend('download_url',array($path,$force_download),true)))
1455
+		if (($url = self::_call_on_backend('download_url', array($path, $force_download), true)))
1459 1456
 		{
1460 1457
 			return $url;
1461 1458
 		}
1462 1459
 		if ($path[0] != '/')
1463 1460
 		{
1464
-			$path = self::parse_url($path,PHP_URL_PATH);
1461
+			$path = self::parse_url($path, PHP_URL_PATH);
1465 1462
 		}
1466 1463
 		// we do NOT need to encode % itself, as our path are already url encoded, with the exception of ' ' and '+'
1467 1464
 		// we urlencode double quotes '"', as that fixes many problems in html markup
1468
-		return '/webdav.php'.strtr($path,array('+' => '%2B',' ' => '%20','"' => '%22')).($force_download ? '?download' : '');
1465
+		return '/webdav.php'.strtr($path, array('+' => '%2B', ' ' => '%20', '"' => '%22')).($force_download ? '?download' : '');
1469 1466
 	}
1470 1467
 
1471 1468
 	/**
@@ -1493,12 +1490,12 @@  discard block
 block discarded – undo
1493 1490
 		// eg: User selected /home/nathan/picture.jpg, /home/Pictures/logo.jpg
1494 1491
 		// We want /home
1495 1492
 		$dirs = array();
1496
-		foreach($_files as $file)
1493
+		foreach ($_files as $file)
1497 1494
 		{
1498 1495
 			$dirs[] = self::dirname($file);
1499 1496
 		}
1500 1497
 		$paths = array_unique($dirs);
1501
-		if(count($paths) > 0)
1498
+		if (count($paths) > 0)
1502 1499
 		{
1503 1500
 			// Shortest to longest
1504 1501
 			usort($paths, function($a, $b) {
@@ -1506,13 +1503,13 @@  discard block
 block discarded – undo
1506 1503
 			});
1507 1504
 
1508 1505
 			// Start with shortest, pop off sub-directories that don't match
1509
-			$parts = explode('/',$paths[0]);
1510
-			foreach($paths as $path)
1506
+			$parts = explode('/', $paths[0]);
1507
+			foreach ($paths as $path)
1511 1508
 			{
1512
-				$dirs = explode('/',$path);
1513
-				foreach($dirs as $dir_index => $dir)
1509
+				$dirs = explode('/', $path);
1510
+				foreach ($dirs as $dir_index => $dir)
1514 1511
 				{
1515
-					if($parts[$dir_index] && $parts[$dir_index] != $dir)
1512
+					if ($parts[$dir_index] && $parts[$dir_index] != $dir)
1516 1513
 					{
1517 1514
 						unset($parts[$dir_index]);
1518 1515
 					}
@@ -1531,24 +1528,23 @@  discard block
 block discarded – undo
1531 1528
 			// Linux
1532 1529
 			'/',
1533 1530
 			// Windows
1534
-			'\\','?','%','*',':','|',/*'.',*/ '"','<','>'
1531
+			'\\', '?', '%', '*', ':', '|', /*'.',*/ '"', '<', '>'
1535 1532
 		);
1536 1533
 
1537 1534
 		// A nice name for the user,
1538
-		$filename = $GLOBALS['egw_info']['server']['site_title'] . '_' .
1539
-			str_replace($replace,'_',(
1535
+		$filename = $GLOBALS['egw_info']['server']['site_title'].'_'.
1536
+			str_replace($replace, '_', (
1540 1537
 			$name ? $name : (
1541 1538
 			count($_files) == 1 ?
1542 1539
 			// Just one file (hopefully a directory?) selected
1543
-			self::basename($_files[0]) :
1544
-			// Use the lowest common directory (eg: Infolog, Open, nathan)
1540
+			self::basename($_files[0]) : // Use the lowest common directory (eg: Infolog, Open, nathan)
1545 1541
 			self::basename($base_dir))
1546
-		)) . '.zip';
1542
+		)).'.zip';
1547 1543
 
1548 1544
 		// Make sure basename is a dir
1549
-		if(substr($base_dir, -1) != '/')
1545
+		if (substr($base_dir, -1) != '/')
1550 1546
 		{
1551
-			$base_dir .='/';
1547
+			$base_dir .= '/';
1552 1548
 		}
1553 1549
 
1554 1550
 		// Go into directories, find them all
@@ -1559,37 +1555,37 @@  discard block
 block discarded – undo
1559 1555
 		$tempfiles = array();
1560 1556
 
1561 1557
 		// Give 1 second per file, but try to allow more time for big files when amount of files is low
1562
-		set_time_limit((count($files)<=9?10:count($files)));
1558
+		set_time_limit((count($files) <= 9 ? 10 : count($files)));
1563 1559
 
1564 1560
 		// Add files to archive
1565
-		foreach($files as &$addfile)
1561
+		foreach ($files as &$addfile)
1566 1562
 		{
1567 1563
 			// Use relative paths inside zip
1568 1564
 			$relative = substr($addfile, strlen($base_dir));
1569 1565
 
1570 1566
 			// Use safe names - replace unsafe chars, convert to ASCII (ZIP spec says CP437, but we'll try)
1571
-			$path = explode('/',$relative);
1572
-			$_name = Translation::convert(Translation::to_ascii(implode('/', str_replace($replace,'_',$path))),false,'ASCII');
1567
+			$path = explode('/', $relative);
1568
+			$_name = Translation::convert(Translation::to_ascii(implode('/', str_replace($replace, '_', $path))), false, 'ASCII');
1573 1569
 
1574 1570
 			// Don't go infinite with app entries
1575
-			if(self::is_link($addfile))
1571
+			if (self::is_link($addfile))
1576 1572
 			{
1577
-				if(in_array($addfile, $links)) continue;
1573
+				if (in_array($addfile, $links)) continue;
1578 1574
 				$links[] = $addfile;
1579 1575
 			}
1580 1576
 			// Add directory - if empty, client app might not show it though
1581
-			if(self::is_dir($addfile))
1577
+			if (self::is_dir($addfile))
1582 1578
 			{
1583 1579
 				// Zip directories
1584 1580
 				$zip->addEmptyDir($addfile);
1585 1581
 			}
1586
-			else if(self::is_readable($addfile))
1582
+			else if (self::is_readable($addfile))
1587 1583
 			{
1588 1584
 				// Copy to temp file, as ZipArchive fails to read VFS
1589 1585
 				$temp = tempnam($GLOBALS['egw_info']['server']['temp_dir'], 'zip_');
1590
-				$from = self::fopen($addfile,'r');
1591
-		 		$to = fopen($temp,'w');
1592
-				if(!stream_copy_to_stream($from,$to) || !$zip->addFile($temp, $_name))
1586
+				$from = self::fopen($addfile, 'r');
1587
+		 		$to = fopen($temp, 'w');
1588
+				if (!stream_copy_to_stream($from, $to) || !$zip->addFile($temp, $_name))
1593 1589
 				{
1594 1590
 					unlink($temp);
1595 1591
 					trigger_error("Could not add $addfile to ZIP file", E_USER_ERROR);
@@ -1600,10 +1596,10 @@  discard block
 block discarded – undo
1600 1596
 
1601 1597
 				// Add comment in
1602 1598
 				$props = self::propfind($addfile);
1603
-				if($props)
1599
+				if ($props)
1604 1600
 				{
1605
-					$comment = self::find_prop($props,'comment');
1606
-					if($comment)
1601
+					$comment = self::find_prop($props, 'comment');
1602
+					if ($comment)
1607 1603
 					{
1608 1604
 						$zip->setCommentName($_name, $comment);
1609 1605
 					}
@@ -1613,13 +1609,13 @@  discard block
 block discarded – undo
1613 1609
 		}
1614 1610
 
1615 1611
 		// Set a comment to help tell them apart
1616
-		$zip->setArchiveComment(lang('Created by %1', $GLOBALS['egw_info']['user']['account_lid']) . ' ' .DateTime::to());
1612
+		$zip->setArchiveComment(lang('Created by %1', $GLOBALS['egw_info']['user']['account_lid']).' '.DateTime::to());
1617 1613
 
1618 1614
 		// Record total for debug, not available after close()
1619 1615
 		$total_files = $zip->numFiles;
1620 1616
 
1621 1617
 		$result = $zip->close();
1622
-		if(!$result || !filesize($zip_file))
1618
+		if (!$result || !filesize($zip_file))
1623 1619
 		{
1624 1620
 			error_log('close() result: '.array2string($result));
1625 1621
 			return 'Error creating zip file';
@@ -1628,19 +1624,19 @@  discard block
 block discarded – undo
1628 1624
 		//error_log("Total files: " . $total_files . " Peak memory to zip: " . self::hsize(memory_get_peak_usage(true)));
1629 1625
 
1630 1626
 		// Stop any buffering
1631
-		while(ob_get_level() > 0)
1627
+		while (ob_get_level() > 0)
1632 1628
 		{
1633 1629
 			ob_end_clean();
1634 1630
 		}
1635 1631
 
1636 1632
 		// Stream the file to the client
1637 1633
 		header("Content-Type: application/zip");
1638
-		header("Content-Length: " . filesize($zip_file));
1634
+		header("Content-Length: ".filesize($zip_file));
1639 1635
 		header("Content-Disposition: attachment; filename=\"$filename\"");
1640 1636
 		readfile($zip_file);
1641 1637
 
1642 1638
 		unlink($zip_file);
1643
-		foreach($tempfiles as $temp_file)
1639
+		foreach ($tempfiles as $temp_file)
1644 1640
 		{
1645 1641
 			unlink($temp_file);
1646 1642
 		}
@@ -1674,11 +1670,11 @@  discard block
 block discarded – undo
1674 1670
 	 * @param boolean $check_writable =true should we check if the ressource is writable, before granting locks, default yes
1675 1671
 	 * @return boolean true on success
1676 1672
 	 */
1677
-	static function lock($path,&$token,&$timeout,&$owner,&$scope,&$type,$update=false,$check_writable=true)
1673
+	static function lock($path, &$token, &$timeout, &$owner, &$scope, &$type, $update = false, $check_writable = true)
1678 1674
 	{
1679 1675
 		// we require write rights to lock/unlock a resource
1680 1676
 		if (!$path || $update && !$token || $check_writable &&
1681
-			!(self::is_writable($path) || !self::file_exists($path) && ($dir=self::dirname($path)) && self::is_writable($dir)))
1677
+			!(self::is_writable($path) || !self::file_exists($path) && ($dir = self::dirname($path)) && self::is_writable($dir)))
1682 1678
 		{
1683 1679
 			return false;
1684 1680
 		}
@@ -1692,28 +1688,28 @@  discard block
 block discarded – undo
1692 1688
 
1693 1689
 		if ($update)	// Lock Update
1694 1690
 		{
1695
-			if (($ret = (boolean)($row = self::$db->select(self::LOCK_TABLE,array('lock_owner','lock_exclusive','lock_write'),array(
1691
+			if (($ret = (boolean)($row = self::$db->select(self::LOCK_TABLE, array('lock_owner', 'lock_exclusive', 'lock_write'), array(
1696 1692
 				'lock_path' => $path,
1697 1693
 				'lock_token' => $token,
1698
-			),__LINE__,__FILE__)->fetch())))
1694
+			), __LINE__, __FILE__)->fetch())))
1699 1695
 			{
1700 1696
 				$owner = $row['lock_owner'];
1701 1697
 				$scope = Db::from_bool($row['lock_exclusive']) ? 'exclusive' : 'shared';
1702 1698
 				$type  = Db::from_bool($row['lock_write']) ? 'write' : 'read';
1703 1699
 
1704
-				self::$db->update(self::LOCK_TABLE,array(
1700
+				self::$db->update(self::LOCK_TABLE, array(
1705 1701
 					'lock_expires' => $timeout,
1706 1702
 					'lock_modified' => time(),
1707
-				),array(
1703
+				), array(
1708 1704
 					'lock_path' => $path,
1709 1705
 					'lock_token' => $token,
1710
-				),__LINE__,__FILE__);
1706
+				), __LINE__, __FILE__);
1711 1707
 			}
1712 1708
 		}
1713 1709
 		// HTTP_WebDAV_Server does this check before calling LOCK, but we want to be complete and usable outside WebDAV
1714
-		elseif(($lock = self::checkLock($path)) && ($lock['scope'] == 'exclusive' || $scope == 'exclusive'))
1710
+		elseif (($lock = self::checkLock($path)) && ($lock['scope'] == 'exclusive' || $scope == 'exclusive'))
1715 1711
 		{
1716
-			$ret = false;	// there's alread a lock
1712
+			$ret = false; // there's alread a lock
1717 1713
 		}
1718 1714
 		else
1719 1715
 		{
@@ -1728,7 +1724,7 @@  discard block
 block discarded – undo
1728 1724
 				$token = HTTP_WebDAV_Server::_new_locktoken();
1729 1725
 			}
1730 1726
 			try {
1731
-				self::$db->insert(self::LOCK_TABLE,array(
1727
+				self::$db->insert(self::LOCK_TABLE, array(
1732 1728
 					'lock_token' => $token,
1733 1729
 					'lock_path'  => $path,
1734 1730
 					'lock_created' => time(),
@@ -1737,12 +1733,12 @@  discard block
 block discarded – undo
1737 1733
 					'lock_expires' => $timeout,
1738 1734
 					'lock_exclusive' => $scope == 'exclusive',
1739 1735
 					'lock_write' => $type == 'write',
1740
-				),false,__LINE__,__FILE__);
1736
+				), false, __LINE__, __FILE__);
1741 1737
 				$ret = true;
1742 1738
 			}
1743
-			catch(Db\Exception $e) {
1739
+			catch (Db\Exception $e) {
1744 1740
 				unset($e);
1745
-				$ret = false;	// there's already a lock
1741
+				$ret = false; // there's already a lock
1746 1742
 			}
1747 1743
 		}
1748 1744
 		if (self::LOCK_DEBUG) error_log(__METHOD__."($path,$token,$timeout,$owner,$scope,$type,update=$update,check_writable=$check_writable) returns ".($ret ? 'true' : 'false'));
@@ -1757,17 +1753,17 @@  discard block
 block discarded – undo
1757 1753
 	 * @param boolean $check_writable =true should we check if the ressource is writable, before granting locks, default yes
1758 1754
      * @return boolean true on success
1759 1755
      */
1760
-    static function unlock($path,$token,$check_writable=true)
1756
+    static function unlock($path, $token, $check_writable = true)
1761 1757
     {
1762 1758
 		// we require write rights to lock/unlock a resource
1763 1759
 		if ($check_writable && !self::is_writable($path))
1764 1760
 		{
1765 1761
 			return false;
1766 1762
 		}
1767
-        if (($ret = self::$db->delete(self::LOCK_TABLE,array(
1763
+        if (($ret = self::$db->delete(self::LOCK_TABLE, array(
1768 1764
         	'lock_path' => $path,
1769 1765
         	'lock_token' => $token,
1770
-        ),__LINE__,__FILE__) && self::$db->affected_rows()))
1766
+        ), __LINE__, __FILE__) && self::$db->affected_rows()))
1771 1767
         {
1772 1768
         	// remove the lock from the cache too
1773 1769
         	unset(self::$lock_cache[$path]);
@@ -1786,31 +1782,31 @@  discard block
 block discarded – undo
1786 1782
 	{
1787 1783
 		if (isset(self::$lock_cache[$path]))
1788 1784
 		{
1789
-			if (self::LOCK_DEBUG) error_log(__METHOD__."($path) returns from CACHE ".str_replace(array("\n",'    '),'',print_r(self::$lock_cache[$path],true)));
1785
+			if (self::LOCK_DEBUG) error_log(__METHOD__."($path) returns from CACHE ".str_replace(array("\n", '    '), '', print_r(self::$lock_cache[$path], true)));
1790 1786
 			return self::$lock_cache[$path];
1791 1787
 		}
1792 1788
 		$where = 'lock_path='.self::$db->quote($path);
1793 1789
 		// ToDo: additional check parent dirs for locks and children of the requested directory
1794 1790
 		//$where .= ' OR '.self::$db->quote($path).' LIKE '.self::$db->concat('lock_path',"'%'").' OR lock_path LIKE '.self::$db->quote($path.'%');
1795 1791
 		// ToDo: shared locks can return multiple rows
1796
-		if (($result = self::$db->select(self::LOCK_TABLE,'*',$where,__LINE__,__FILE__)->fetch()))
1792
+		if (($result = self::$db->select(self::LOCK_TABLE, '*', $where, __LINE__, __FILE__)->fetch()))
1797 1793
 		{
1798
-			$result = Db::strip_array_keys($result,'lock_');
1794
+			$result = Db::strip_array_keys($result, 'lock_');
1799 1795
 			$result['type']  = Db::from_bool($result['write']) ? 'write' : 'read';
1800 1796
 			$result['scope'] = Db::from_bool($result['exclusive']) ? 'exclusive' : 'shared';
1801 1797
 			$result['depth'] = Db::from_bool($result['recursive']) ? 'infinite' : 0;
1802 1798
 		}
1803 1799
 		if ($result && $result['expires'] < time())	// lock is expired --> remove it
1804 1800
 		{
1805
-	        self::$db->delete(self::LOCK_TABLE,array(
1801
+	        self::$db->delete(self::LOCK_TABLE, array(
1806 1802
 	        	'lock_path' => $result['path'],
1807 1803
 	        	'lock_token' => $result['token'],
1808
-	        ),__LINE__,__FILE__);
1804
+	        ), __LINE__, __FILE__);
1809 1805
 
1810
-			if (self::LOCK_DEBUG) error_log(__METHOD__."($path) lock is expired at ".date('Y-m-d H:i:s',$result['expires'])." --> removed");
1806
+			if (self::LOCK_DEBUG) error_log(__METHOD__."($path) lock is expired at ".date('Y-m-d H:i:s', $result['expires'])." --> removed");
1811 1807
 	        $result = false;
1812 1808
 		}
1813
-		if (self::LOCK_DEBUG) error_log(__METHOD__."($path) returns ".($result?array2string($result):'false'));
1809
+		if (self::LOCK_DEBUG) error_log(__METHOD__."($path) returns ".($result ?array2string($result) : 'false'));
1814 1810
 		return self::$lock_cache[$path] = $result;
1815 1811
 	}
1816 1812
 
@@ -1821,10 +1817,10 @@  discard block
 block discarded – undo
1821 1817
 	 * @param array $content =null
1822 1818
 	 * @return array|boolean array with values for keys 'data','etemplate','name','label','help' or false if not supported by backend
1823 1819
 	 */
1824
-	static function getExtraInfo($path,array $content=null)
1820
+	static function getExtraInfo($path, array $content = null)
1825 1821
 	{
1826 1822
 		$extra = array();
1827
-		if (($extra_info = self::_call_on_backend('extra_info',array($path,$content),true)))	// true = fail silent if backend does NOT support it
1823
+		if (($extra_info = self::_call_on_backend('extra_info', array($path, $content), true)))	// true = fail silent if backend does NOT support it
1828 1824
 		{
1829 1825
 			$extra[] = $extra_info;
1830 1826
 		}
@@ -1835,7 +1831,7 @@  discard block
 block discarded – undo
1835 1831
 			'content' => $content,
1836 1832
 		))))
1837 1833
 		{
1838
-			foreach($vfs_extra as $data)
1834
+			foreach ($vfs_extra as $data)
1839 1835
 			{
1840 1836
 				$extra = $extra ? array_merge($extra, $data) : $data;
1841 1837
 			}
@@ -1850,7 +1846,7 @@  discard block
 block discarded – undo
1850 1846
 	 * @param int|string $id
1851 1847
 	 * @return string
1852 1848
 	 */
1853
-	static function app_entry_lock_path($app,$id)
1849
+	static function app_entry_lock_path($app, $id)
1854 1850
 	{
1855 1851
 		return "/apps/$app/entry/$id";
1856 1852
 	}
@@ -1864,7 +1860,7 @@  discard block
 block discarded – undo
1864 1860
 		//'%' => '%25',	// % should be encoded, but easily leads to double encoding, therefore better NOT encodig it
1865 1861
 		'#' => '%23',
1866 1862
 		'?' => '%3F',
1867
-		'/' => '',	// better remove it completly
1863
+		'/' => '', // better remove it completly
1868 1864
 	);
1869 1865
 
1870 1866
 	/**
@@ -1879,7 +1875,7 @@  discard block
 block discarded – undo
1879 1875
 	 */
1880 1876
 	static public function encodePathComponent($component)
1881 1877
 	{
1882
-		return str_replace(array_keys(self::$encode),array_values(self::$encode),$component);
1878
+		return str_replace(array_keys(self::$encode), array_values(self::$encode), $component);
1883 1879
 	}
1884 1880
 
1885 1881
 	/**
@@ -1892,7 +1888,7 @@  discard block
 block discarded – undo
1892 1888
 	 */
1893 1889
 	static public function encodePath($path)
1894 1890
 	{
1895
-		return implode('/',self::encodePathComponent(explode('/',$path)));
1891
+		return implode('/', self::encodePathComponent(explode('/', $path)));
1896 1892
 	}
1897 1893
 
1898 1894
 	/**
@@ -1947,7 +1943,7 @@  discard block
 block discarded – undo
1947 1943
 		{
1948 1944
 			$image = Image::find($mime_sub, 'navbar');
1949 1945
 		}
1950
-		else if ($file && $mime_main == 'image' && in_array($mime_sub, array('png','jpeg','jpg','gif','bmp')) &&
1946
+		else if ($file && $mime_main == 'image' && in_array($mime_sub, array('png', 'jpeg', 'jpg', 'gif', 'bmp')) &&
1951 1947
 		         (string)$GLOBALS['egw_info']['server']['link_list_thumbnail'] != '0' &&
1952 1948
 		         (string)$GLOBALS['egw_info']['user']['preferences']['common']['link_list_thumbnail'] != '0' &&
1953 1949
 		         ($stat = self::stat($file)) && $stat['size'] < 1500000)
@@ -2007,7 +2003,7 @@  discard block
 block discarded – undo
2007 2003
 	 * @param array& $copied =null on return files copied
2008 2004
 	 * @return boolean true for no errors, false otherwise
2009 2005
 	 */
2010
-	static public function copy_files(array $src, $dst, &$errs=null, array &$copied=null)
2006
+	static public function copy_files(array $src, $dst, &$errs = null, array &$copied = null)
2011 2007
 	{
2012 2008
 		if (self::is_dir($dst))
2013 2009
 		{
@@ -2025,7 +2021,7 @@  discard block
 block discarded – undo
2025 2021
 						if ($file !== $target)
2026 2022
 						{
2027 2023
 							// Create the target directory
2028
-							self::mkdir($target,null,STREAM_MKDIR_RECURSIVE);
2024
+							self::mkdir($target, null, STREAM_MKDIR_RECURSIVE);
2029 2025
 
2030 2026
 							$copied[] = $file;
2031 2027
 							$copied[] = $target; // < newly created folder must not be copied again!
@@ -2069,7 +2065,7 @@  discard block
 block discarded – undo
2069 2065
 		if (self::is_dir($dst))
2070 2066
 		{
2071 2067
 			$vfs = new Vfs\StreamWrapper();
2072
-			foreach($src as $file)
2068
+			foreach ($src as $file)
2073 2069
 			{
2074 2070
 				$target = self::concat($dst, self::basename($file));
2075 2071
 
@@ -2101,7 +2097,7 @@  discard block
 block discarded – undo
2101 2097
 	 * @param boolean $check_is_uploaded_file =true should method perform an is_uploaded_file check, default yes
2102 2098
 	 * @return boolean|array stat array on success, false on error
2103 2099
 	 */
2104
-	static public function copy_uploaded($src,$target,$props=null,$check_is_uploaded_file=true)
2100
+	static public function copy_uploaded($src, $target, $props = null, $check_is_uploaded_file = true)
2105 2101
 	{
2106 2102
 		$tmp_name = is_array($src) ? $src['tmp_name'] : $src;
2107 2103
 
@@ -2121,12 +2117,12 @@  discard block
 block discarded – undo
2121 2117
 		}
2122 2118
 		if ($props)
2123 2119
 		{
2124
-			if (!is_array($props)) $props = array(array('name' => 'comment','val' => $props));
2120
+			if (!is_array($props)) $props = array(array('name' => 'comment', 'val' => $props));
2125 2121
 
2126 2122
 			// if $props is name => value pairs, convert it to internal array or array with values for keys 'name', 'val' and optional 'ns'
2127 2123
 			if (!isset($props[0]))
2128 2124
 			{
2129
-				foreach($props as $name => $val)
2125
+				foreach ($props as $name => $val)
2130 2126
 				{
2131 2127
 					if (($name == 'comment' || $name[0] == '#') && $val)	// only copy 'comment' and cfs
2132 2128
 					{
@@ -2144,7 +2140,7 @@  discard block
 block discarded – undo
2144 2140
 			// set props before copying the file, so notifications already contain them
2145 2141
 			if (!self::stat($target))
2146 2142
 			{
2147
-				self::touch($target);	// create empty file, to be able to attach properties
2143
+				self::touch($target); // create empty file, to be able to attach properties
2148 2144
 				// tell vfs stream-wrapper to treat file in following copy as a new file notification-wises
2149 2145
 				$context = stream_context_create(array(
2150 2146
 					self::SCHEME => array('treat_as_new' => true)
@@ -2162,8 +2158,7 @@  discard block
 block discarded – undo
2162 2158
 		}
2163 2159
 		else
2164 2160
 		{
2165
-			$ret = ($context ? copy($tmp_name, self::PREFIX.$target, $context) :
2166
-				copy($tmp_name, self::PREFIX.$target)) ?
2161
+			$ret = ($context ? copy($tmp_name, self::PREFIX.$target, $context) : copy($tmp_name, self::PREFIX.$target)) ?
2167 2162
 				self::stat($target) : false;
2168 2163
 		}
2169 2164
 		if (self::LOG_LEVEL > 1 || !$ret && self::LOG_LEVEL) error_log(__METHOD__."($tmp_name, $target, ".array2string($props).") returning ".array2string($ret));
@@ -2209,7 +2204,7 @@  discard block
 block discarded – undo
2209 2204
 	 * @param array|boolean &$stat=null on return: stat of existing file or false for non-existing files
2210 2205
 	 * @return string|boolean false if the url cant be resolved, should not happen if fstab has a root entry
2211 2206
 	 */
2212
-	static function resolve_url_symlinks($_path,$file_exists=true,$resolve_last_symlink=true,&$stat=null)
2207
+	static function resolve_url_symlinks($_path, $file_exists = true, $resolve_last_symlink = true, &$stat = null)
2213 2208
 	{
2214 2209
 		$vfs = new Vfs\StreamWrapper();
2215 2210
 		return $vfs->resolve_url_symlinks($_path, $file_exists, $resolve_last_symlink, $stat);
@@ -2225,7 +2220,7 @@  discard block
 block discarded – undo
2225 2220
 	 * @param boolean $fix_url_query =false true append relativ path to url query parameter, default not
2226 2221
 	 * @return string|boolean false if the url cant be resolved, should not happen if fstab has a root entry
2227 2222
 	 */
2228
-	static function resolve_url($_path,$do_symlink=true,$use_symlinkcache=true,$replace_user_pass_host=true,$fix_url_query=false)
2223
+	static function resolve_url($_path, $do_symlink = true, $use_symlinkcache = true, $replace_user_pass_host = true, $fix_url_query = false)
2229 2224
 	{
2230 2225
 		return Vfs\StreamWrapper::resolve_url($_path, $do_symlink, $use_symlinkcache, $replace_user_pass_host, $fix_url_query);
2231 2226
 	}
@@ -2241,7 +2236,7 @@  discard block
 block discarded – undo
2241 2236
 	 * @param boolean $recursive =false true: create missing parents too
2242 2237
 	 * @return boolean TRUE on success or FALSE on failure
2243 2238
 	 */
2244
-	static function mkdir ($path, $mode=0750, $recursive=false)
2239
+	static function mkdir($path, $mode = 0750, $recursive = false)
2245 2240
 	{
2246 2241
 		return $path[0] == '/' && mkdir(self::PREFIX.$path, $mode, $recursive);
2247 2242
 	}
@@ -2270,7 +2265,7 @@  discard block
 block discarded – undo
2270 2265
 	 * @param string $path
2271 2266
 	 * @return boolean TRUE on success or FALSE on failure
2272 2267
 	 */
2273
-	static function unlink ( $path )
2268
+	static function unlink($path)
2274 2269
 	{
2275 2270
 		return $path[0] == '/' && unlink(self::PREFIX.$path);
2276 2271
 	}
@@ -2287,60 +2282,60 @@  discard block
 block discarded – undo
2287 2282
 	 * @param int $path_param_key =0 key in params containing the path, default 0
2288 2283
 	 * @return mixed return value of backend or false if function does not exist on backend
2289 2284
 	 */
2290
-	static protected function _call_on_backend($name,$params,$fail_silent=false,$path_param_key=0)
2285
+	static protected function _call_on_backend($name, $params, $fail_silent = false, $path_param_key = 0)
2291 2286
 	{
2292 2287
 		$pathes = $params[$path_param_key];
2293 2288
 
2294 2289
 		$scheme2urls = array();
2295
-		foreach(is_array($pathes) ? $pathes : array($pathes) as $path)
2290
+		foreach (is_array($pathes) ? $pathes : array($pathes) as $path)
2296 2291
 		{
2297
-			if (!($url = self::resolve_url_symlinks($path,false,false)))
2292
+			if (!($url = self::resolve_url_symlinks($path, false, false)))
2298 2293
 			{
2299 2294
 				return false;
2300 2295
 			}
2301
-			$k=(string)self::parse_url($url,PHP_URL_SCHEME);
2296
+			$k = (string)self::parse_url($url, PHP_URL_SCHEME);
2302 2297
 			if (!(is_array($scheme2urls[$k]))) $scheme2urls[$k] = array();
2303 2298
 			$scheme2urls[$k][$path] = $url;
2304 2299
 		}
2305 2300
 		$ret = array();
2306
-		foreach($scheme2urls as $scheme => $urls)
2301
+		foreach ($scheme2urls as $scheme => $urls)
2307 2302
 		{
2308 2303
 			if ($scheme)
2309 2304
 			{
2310
-				if (!class_exists($class = self::scheme2class($scheme)) || !method_exists($class,$name))
2305
+				if (!class_exists($class = self::scheme2class($scheme)) || !method_exists($class, $name))
2311 2306
 				{
2312
-					if (!$fail_silent) trigger_error("Can't $name for scheme $scheme!\n",E_USER_WARNING);
2307
+					if (!$fail_silent) trigger_error("Can't $name for scheme $scheme!\n", E_USER_WARNING);
2313 2308
 					return false;
2314 2309
 				}
2315 2310
 				if (!is_array($pathes))
2316 2311
 				{
2317 2312
 					$params[$path_param_key] = $url;
2318 2313
 
2319
-					return call_user_func_array(array($class,$name),$params);
2314
+					return call_user_func_array(array($class, $name), $params);
2320 2315
 				}
2321 2316
 				$params[$path_param_key] = $urls;
2322
-				if (!is_array($r = call_user_func_array(array($class,$name),$params)))
2317
+				if (!is_array($r = call_user_func_array(array($class, $name), $params)))
2323 2318
 				{
2324 2319
 					return $r;
2325 2320
 				}
2326 2321
 				// we need to re-translate the urls to pathes, as they can eg. contain symlinks
2327
-				foreach($urls as $path => $url)
2322
+				foreach ($urls as $path => $url)
2328 2323
 				{
2329
-					if (isset($r[$url]) || isset($r[$url=self::parse_url($url,PHP_URL_PATH)]))
2324
+					if (isset($r[$url]) || isset($r[$url = self::parse_url($url, PHP_URL_PATH)]))
2330 2325
 					{
2331 2326
 						$ret[$path] = $r[$url];
2332 2327
 					}
2333 2328
 				}
2334 2329
 			}
2335 2330
 			// call the filesystem specific function (dont allow to use arrays!)
2336
-			elseif(!function_exists($name) || is_array($pathes))
2331
+			elseif (!function_exists($name) || is_array($pathes))
2337 2332
 			{
2338 2333
 				return false;
2339 2334
 			}
2340 2335
 			else
2341 2336
 			{
2342 2337
 				$time = null;
2343
-				return $name($url,$time);
2338
+				return $name($url, $time);
2344 2339
 			}
2345 2340
 		}
2346 2341
 		return $ret;
@@ -2354,7 +2349,7 @@  discard block
 block discarded – undo
2354 2349
 	 * @param int $atime =null access time (unix timestamp), default null = current time, not implemented in the vfs!
2355 2350
 	 * @return boolean true on success, false otherwise
2356 2351
 	 */
2357
-	static function touch($path,$time=null,$atime=null)
2352
+	static function touch($path, $time = null, $atime = null)
2358 2353
 	{
2359 2354
 		return $path[0] == '/' && touch(self::PREFIX.$path, $time, $atime);
2360 2355
 	}
@@ -2368,7 +2363,7 @@  discard block
 block discarded – undo
2368 2363
 	 * @param string $mode mode string see Vfs::mode2int
2369 2364
 	 * @return boolean true on success, false otherwise
2370 2365
 	 */
2371
-	static function chmod($path,$mode)
2366
+	static function chmod($path, $mode)
2372 2367
 	{
2373 2368
 		return $path[0] == '/' && chmod(self::PREFIX.$path, $mode);
2374 2369
 	}
@@ -2382,7 +2377,7 @@  discard block
 block discarded – undo
2382 2377
 	 * @param int|string $owner numeric user id or account-name
2383 2378
 	 * @return boolean true on success, false otherwise
2384 2379
 	 */
2385
-	static function chown($path,$owner)
2380
+	static function chown($path, $owner)
2386 2381
 	{
2387 2382
 		return $path[0] == '/' && chown(self::PREFIX.$path, is_numeric($owner) ? abs($owner) : $owner);
2388 2383
 	}
@@ -2396,7 +2391,7 @@  discard block
 block discarded – undo
2396 2391
 	 * @param int|string $group numeric group id or group-name
2397 2392
 	 * @return boolean true on success, false otherwise
2398 2393
 	 */
2399
-	static function chgrp($path,$group)
2394
+	static function chgrp($path, $group)
2400 2395
 	{
2401 2396
 		return $path[0] == '/' && chgrp(self::PREFIX.$path, is_numeric($group) ? abs($group) : $group);
2402 2397
 	}
@@ -2411,7 +2406,7 @@  discard block
 block discarded – undo
2411 2406
 	 */
2412 2407
 	static function readlink($path)
2413 2408
 	{
2414
-		$ret = self::_call_on_backend('readlink',array($path),true);	// true = fail silent, if backend does not support readlink
2409
+		$ret = self::_call_on_backend('readlink', array($path), true); // true = fail silent, if backend does not support readlink
2415 2410
 		//error_log(__METHOD__."('$path') returning ".array2string($ret).' '.function_backtrace());
2416 2411
 		return $ret;
2417 2412
 	}
@@ -2425,9 +2420,9 @@  discard block
 block discarded – undo
2425 2420
 	 * @param string $link path of the link to create
2426 2421
 	 * @return boolean true on success, false on error
2427 2422
 	 */
2428
-	static function symlink($target,$link)
2423
+	static function symlink($target, $link)
2429 2424
 	{
2430
-		if (($ret = self::_call_on_backend('symlink',array($target,$link),false,1)))	// 1=path is in $link!
2425
+		if (($ret = self::_call_on_backend('symlink', array($target, $link), false, 1)))	// 1=path is in $link!
2431 2426
 		{
2432 2427
 			Vfs\StreamWrapper::symlinkCache_remove($link);
2433 2428
 		}
@@ -2447,13 +2442,13 @@  discard block
 block discarded – undo
2447 2442
 	 * @param boolean $recheck =false true = do a new check, false = rely on stored mime type (if existing)
2448 2443
 	 * @return string mime-type (self::DIR_MIME_TYPE for directories)
2449 2444
 	 */
2450
-	static function mime_content_type($path,$recheck=false)
2445
+	static function mime_content_type($path, $recheck = false)
2451 2446
 	{
2452 2447
 		if (!($url = self::resolve_url_symlinks($path)))
2453 2448
 		{
2454 2449
 			return false;
2455 2450
 		}
2456
-		if (($scheme = self::parse_url($url,PHP_URL_SCHEME)) && !$recheck)
2451
+		if (($scheme = self::parse_url($url, PHP_URL_SCHEME)) && !$recheck)
2457 2452
 		{
2458 2453
 			// check it it's an eGW stream wrapper returning mime-type via url_stat
2459 2454
 			// we need to first check if the constant is defined, as we get a fatal error in php5.3 otherwise
@@ -2462,7 +2457,7 @@  discard block
 block discarded – undo
2462 2457
 				($mime_attr = constant($class.'::STAT_RETURN_MIME_TYPE')))
2463 2458
 			{
2464 2459
 				$inst = new $class;
2465
-				$stat = $inst->url_stat(self::parse_url($url,PHP_URL_PATH),0);
2460
+				$stat = $inst->url_stat(self::parse_url($url, PHP_URL_PATH), 0);
2466 2461
 				if ($stat && $stat[$mime_attr])
2467 2462
 				{
2468 2463
 					$mime = $stat[$mime_attr];
@@ -2481,7 +2476,7 @@  discard block
 block discarded – undo
2481 2476
 		// using EGw's own mime magic (currently only checking the extension!)
2482 2477
 		if (!$mime)
2483 2478
 		{
2484
-			$mime = MimeMagic::filename2mime(self::parse_url($url,PHP_URL_PATH));
2479
+			$mime = MimeMagic::filename2mime(self::parse_url($url, PHP_URL_PATH));
2485 2480
 		}
2486 2481
 		//error_log(__METHOD__."($path,$recheck) mime=$mime");
2487 2482
 		return $mime;
@@ -2511,7 +2506,7 @@  discard block
 block discarded – undo
2511 2506
 	 *
2512 2507
 	 * @param string $path ='/' path of backend, whos cache to clear
2513 2508
 	 */
2514
-	static function clearstatcache($path='/')
2509
+	static function clearstatcache($path = '/')
2515 2510
 	{
2516 2511
 		//error_log(__METHOD__."('$path')");
2517 2512
 		Vfs\StreamWrapper::clearstatcache($path);
@@ -2531,7 +2526,7 @@  discard block
 block discarded – undo
2531 2526
 	 * @param string $path_to
2532 2527
 	 * @return boolean TRUE on success or FALSE on failure
2533 2528
 	 */
2534
-	static function rename ( $path_from, $path_to )
2529
+	static function rename($path_from, $path_to)
2535 2530
 	{
2536 2531
 		$vfs = new Vfs\StreamWrapper();
2537 2532
 		return $vfs->rename($path_from, $path_to);
@@ -2585,7 +2580,7 @@  discard block
 block discarded – undo
2585 2580
 	 */
2586 2581
 	static function get_minimum_file_id($path)
2587 2582
 	{
2588
-		if(!self::file_exists($path))
2583
+		if (!self::file_exists($path))
2589 2584
 		{
2590 2585
 			return false;
2591 2586
 		}
Please login to merge, or discard this patch.
api/src/Storage/Db2DataIterator.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -46,13 +46,13 @@  discard block
 block discarded – undo
46 46
 	 * @param Base $storage
47 47
 	 * @param \Traversable $rs
48 48
 	 */
49
-	public function __construct(Base $storage, \Traversable $rs=null)
49
+	public function __construct(Base $storage, \Traversable $rs = null)
50 50
 	{
51 51
 		$this->storage = $storage;
52 52
 
53 53
 		$this->total = $storage->total;
54 54
 
55
-		if (is_a($rs,'IteratorAggregate'))
55
+		if (is_a($rs, 'IteratorAggregate'))
56 56
 		{
57 57
 			$this->rs = $rs->getIterator();
58 58
 		}
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 */
70 70
 	public function current()
71 71
 	{
72
-		if (is_a($this->rs,'iterator'))
72
+		if (is_a($this->rs, 'iterator'))
73 73
 		{
74 74
 			$data = $this->rs->current();
75 75
 
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 	 */
86 86
 	public function key()
87 87
 	{
88
-		if (is_a($this->rs,'iterator'))
88
+		if (is_a($this->rs, 'iterator'))
89 89
 		{
90 90
 			return $this->rs->key();
91 91
 		}
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 	 */
98 98
 	public function next()
99 99
 	{
100
-		if (is_a($this->rs,'iterator'))
100
+		if (is_a($this->rs, 'iterator'))
101 101
 		{
102 102
 			return $this->rs->next();
103 103
 		}
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 	 */
109 109
 	public function rewind()
110 110
 	{
111
-		if (is_a($this->rs,'iterator'))
111
+		if (is_a($this->rs, 'iterator'))
112 112
 		{
113 113
 			return $this->rs->rewind();
114 114
 		}
@@ -119,9 +119,9 @@  discard block
 block discarded – undo
119 119
 	 *
120 120
 	 * @return boolean
121 121
 	 */
122
-	public function valid ()
122
+	public function valid()
123 123
 	{
124
-		if (is_a($this->rs,'iterator'))
124
+		if (is_a($this->rs, 'iterator'))
125 125
 		{
126 126
 			return $this->rs->valid();
127 127
 		}
Please login to merge, or discard this patch.
api/src/Storage/Base.php 4 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1367,14 +1367,14 @@
 block discarded – undo
1367 1367
 	}
1368 1368
 
1369 1369
 	/**
1370
-	* Get a default list of columns to search
1371
-	* This is to be used as a fallback, for when the extending class does not define
1372
-	* $this->columns_to_search.  All the columns are considered, and any with $skip_columns_with in
1373
-	* their name are discarded because these columns are expected to be foreign keys or other numeric
1374
-	* values with no meaning to the user.
1375
-	*
1376
-	* @return array of column names
1377
-	*/
1370
+	 * Get a default list of columns to search
1371
+	 * This is to be used as a fallback, for when the extending class does not define
1372
+	 * $this->columns_to_search.  All the columns are considered, and any with $skip_columns_with in
1373
+	 * their name are discarded because these columns are expected to be foreign keys or other numeric
1374
+	 * values with no meaning to the user.
1375
+	 *
1376
+	 * @return array of column names
1377
+	 */
1378 1378
 	protected function get_default_search_columns()
1379 1379
 	{
1380 1380
 		$skip_columns_with = array('_id', 'modified', 'modifier', 'status', 'cat_id', 'owner');
Please login to merge, or discard this patch.
Braces   +193 added lines, -51 removed lines patch added patch discarded remove patch
@@ -182,7 +182,10 @@  discard block
 block discarded – undo
182 182
 	function __construct($app='',$table='',Api\Db $db=null,$column_prefix='',$no_clone=false,$timestamp_type=null)
183 183
 	{
184 184
 		// ease the transition to api
185
-		if ($app == 'phpgwapi') $app = 'api';
185
+		if ($app == 'phpgwapi')
186
+		{
187
+			$app = 'api';
188
+		}
186 189
 
187 190
 		if ($no_clone)
188 191
 		{
@@ -198,9 +201,15 @@  discard block
 block discarded – undo
198 201
 		{
199 202
 			$this->app = $app;
200 203
 
201
-			if (!$no_clone) $this->db->set_app($app);
204
+			if (!$no_clone)
205
+			{
206
+				$this->db->set_app($app);
207
+			}
202 208
 
203
-			if ($table) $this->setup_table($app,$table,$column_prefix);
209
+			if ($table)
210
+			{
211
+				$this->setup_table($app,$table,$column_prefix);
212
+			}
204 213
 		}
205 214
 		$this->init();
206 215
 
@@ -221,7 +230,10 @@  discard block
 block discarded – undo
221 230
 	 */
222 231
 	public function set_times($timestamp_type=false)
223 232
 	{
224
-		if ($timestamp_type !== false) $this->timestamp_type = $timestamp_type;
233
+		if ($timestamp_type !== false)
234
+		{
235
+			$this->timestamp_type = $timestamp_type;
236
+		}
225 237
 
226 238
 		// set current time
227 239
 		switch($this->timestamp_type)
@@ -279,7 +291,10 @@  discard block
 block discarded – undo
279 291
 			{
280 292
 				$this->autoinc_id = $col;
281 293
 			}
282
-			if ($def['type'] == 'bool') $this->has_bools = true;
294
+			if ($def['type'] == 'bool')
295
+			{
296
+				$this->has_bools = true;
297
+			}
283 298
 
284 299
 			foreach($this->table_def['uc'] as $k => $uni_index)
285 300
 			{
@@ -318,7 +333,10 @@  discard block
 block discarded – undo
318 333
 	 */
319 334
 	function data_merge($new)
320 335
 	{
321
-		if ((int) $this->debug >= 4) echo "<p>so_sql::data_merge(".print_r($new,true).")</p>\n";
336
+		if ((int) $this->debug >= 4)
337
+		{
338
+			echo "<p>so_sql::data_merge(".print_r($new,true).")</p>\n";
339
+		}
322 340
 
323 341
 		if (!is_array($new) || !count($new))
324 342
 		{
@@ -342,7 +360,10 @@  discard block
 block discarded – undo
342 360
 		{
343 361
 			$this->data[self::USER_TIMEZONE_READ] = $new[self::USER_TIMEZONE_READ];
344 362
 		}
345
-		if ((int) $this->debug >= 4) _debug_array($this->data);
363
+		if ((int) $this->debug >= 4)
364
+		{
365
+			_debug_array($this->data);
366
+		}
346 367
 	}
347 368
 
348 369
 	/**
@@ -486,7 +507,10 @@  discard block
 block discarded – undo
486 507
 		if (!is_array($keys))
487 508
 		{
488 509
 			$pk = array_values($this->db_key_cols);
489
-			if ($pk) $keys = array($pk[0] => $keys);
510
+			if ($pk)
511
+			{
512
+				$keys = array($pk[0] => $keys);
513
+			}
490 514
 		}
491 515
 
492 516
 		$this->init($keys);
@@ -500,13 +524,16 @@  discard block
 block discarded – undo
500 524
 				$query[$db_col] = $this->data[$col];
501 525
 			}
502 526
 		}
503
-		if (!$query)	// no primary key in keys, lets try the data_cols for a unique key
527
+		if (!$query)
528
+		{
529
+			// no primary key in keys, lets try the data_cols for a unique key
504 530
 		{
505 531
 			foreach($this->db_uni_cols as $db_col => $col)
506 532
 			{
507 533
 				if (!is_array($col) && $this->data[$col] != '')
508 534
 				{
509 535
 					$query[$db_col] = $this->data[$col];
536
+		}
510 537
 				}
511 538
 				elseif(is_array($col))
512 539
 				{
@@ -520,31 +547,43 @@  discard block
 block discarded – undo
520 547
 						}
521 548
 						$q[$db_c] = $this->data[$c];
522 549
 					}
523
-					if ($q) $query += $q;
550
+					if ($q)
551
+					{
552
+						$query += $q;
553
+					}
524 554
 				}
525 555
 			}
526 556
 		}
527
-		if (!$query)	// no unique key in keys, lets try everything else
557
+		if (!$query)
558
+		{
559
+			// no unique key in keys, lets try everything else
528 560
 		{
529 561
 			foreach($this->db_data_cols as $db_col => $col)
530 562
 			{
531 563
 				if ($this->data[$col] != '')
532 564
 				{
533 565
 					$query[$db_col] = $this->data[$col];
566
+		}
534 567
 				}
535 568
 			}
536 569
 		}
537
-		if (!$query)	// keys has no cols
570
+		if (!$query)
571
+		{
572
+			// keys has no cols
538 573
 		{
539 574
 			$this->db2data();
575
+		}
540 576
 
541 577
 			return False;
542 578
 		}
543
-		if ($join)	// Prefix the columns with the table-name, as they might exist in the join
579
+		if ($join)
580
+		{
581
+			// Prefix the columns with the table-name, as they might exist in the join
544 582
 		{
545 583
 			foreach($query as $col => $val)
546 584
 			{
547 585
 				if (is_int($col) || strpos($join,$col) === false) continue;
586
+		}
548 587
 				$query[] = $this->db->expression($this->table_name,$this->table_name.'.',array($col=>$val));
549 588
 				unset($query[$col]);
550 589
 			}
@@ -558,11 +597,14 @@  discard block
 block discarded – undo
558 597
 			$query,__LINE__,__FILE__,False,'',$this->app,0,$join) as $row)
559 598
 		{
560 599
 			$cols = $this->db_cols;
561
-			if ($extra_cols)	// extra columns to report
600
+			if ($extra_cols)
601
+			{
602
+				// extra columns to report
562 603
 			{
563 604
 				foreach(is_array($extra_cols) ? $extra_cols : array($extra_cols) as $col)
564 605
 				{
565 606
 					if (FALSE!==stripos($col,' as ')) $col = preg_replace('/^.* as *([a-z0-9_]+) *$/i','\\1',$col);
607
+			}
566 608
 					$cols[$col] = $col;
567 609
 				}
568 610
 			}
@@ -585,7 +627,10 @@  discard block
 block discarded – undo
585 627
 		{
586 628
 			unset($this->data[$this->db_key_cols[$this->autoinc_id]]);
587 629
 		}
588
-		if ((int) $this->debug >= 4) echo "nothing found !!!</p>\n";
630
+		if ((int) $this->debug >= 4)
631
+		{
632
+			echo "nothing found !!!</p>\n";
633
+		}
589 634
 
590 635
 		$this->db2data();
591 636
 
@@ -601,7 +646,10 @@  discard block
 block discarded – undo
601 646
 	 */
602 647
 	function save($keys=null,$extra_where=null)
603 648
 	{
604
-		if (is_array($keys) && count($keys)) $this->data_merge($keys);
649
+		if (is_array($keys) && count($keys))
650
+		{
651
+			$this->data_merge($keys);
652
+		}
605 653
 
606 654
 		// check if data contains user timezone during read AND user changed timezone since then
607 655
 		// --> load old timezone for the rest of this request
@@ -618,9 +666,13 @@  discard block
 block discarded – undo
618 666
 		}
619 667
 		$this->data2db();
620 668
 
621
-		if ((int) $this->debug >= 4) { echo "so_sql::save(".print_r($keys,true).") autoinc_id='$this->autoinc_id', data="; _debug_array($this->data); }
669
+		if ((int) $this->debug >= 4)
670
+		{
671
+echo "so_sql::save(".print_r($keys,true).") autoinc_id='$this->autoinc_id', data="; _debug_array($this->data); }
622 672
 
623
-		if ($this->autoinc_id && !$this->data[$this->db_key_cols[$this->autoinc_id]])	// insert with auto id
673
+		if ($this->autoinc_id && !$this->data[$this->db_key_cols[$this->autoinc_id]])
674
+		{
675
+			// insert with auto id
624 676
 		{
625 677
 			foreach($this->db_cols as $db_col => $col)
626 678
 			{
@@ -630,7 +682,9 @@  discard block
 block discarded – undo
630 682
 						(isset($this->table_def['fd'][$db_col]['default']) ||	// we have a default value
631 683
 						 !isset($this->table_def['fd'][$db_col]['nullable']) || $this->table_def['fd'][$db_col]['nullable']))	// column is nullable
632 684
 					{
633
-						continue;	// no need to write that (unset) column
685
+						continue;
686
+		}
687
+		// no need to write that (unset) column
634 688
 					}
635 689
 					if ($this->table_def['fd'][$db_col]['type'] == 'varchar' &&
636 690
 						strlen($this->data[$col]) > $this->table_def['fd'][$db_col]['precision'])
@@ -661,9 +715,13 @@  discard block
 block discarded – undo
661 715
 				if (!array_key_exists($col,$this->data) &&	// handling of unset columns in $this->data
662 716
 					($this->autoinc_id ||			// update of table with auto id or
663 717
 					 isset($this->table_def['fd'][$db_col]['default']) ||	// we have a default value or
664
-					 !isset($this->table_def['fd'][$db_col]['nullable']) || $this->table_def['fd'][$db_col]['nullable']))	// column is nullable
718
+					 !isset($this->table_def['fd'][$db_col]['nullable']) || $this->table_def['fd'][$db_col]['nullable']))
665 719
 				{
666
-					continue;	// no need to write that (unset) column
720
+					// column is nullable
721
+				{
722
+					continue;
723
+				}
724
+				// no need to write that (unset) column
667 725
 				}
668 726
 				$data[$db_col] = !is_object($this->data[$col]) && (string) $this->data[$col] === '' && $this->empty_on_write == 'NULL' ? null : $this->data[$col];
669 727
 			}
@@ -680,9 +738,12 @@  discard block
 block discarded – undo
680 738
 			{
681 739
 				$keys[$db_col] = $this->data[$col];
682 740
 			}
683
-			if (!$data && !$this->autoinc_id)	// happens if all columns are in the primary key
741
+			if (!$data && !$this->autoinc_id)
742
+			{
743
+				// happens if all columns are in the primary key
684 744
 			{
685 745
 				$data = $keys;
746
+			}
686 747
 				$keys = False;
687 748
 			}
688 749
 			if ($this->autoinc_id)
@@ -713,7 +774,10 @@  discard block
 block discarded – undo
713 774
 	 */
714 775
 	function update($_fields,$merge=true)
715 776
 	{
716
-		if ($merge) $this->data_merge($_fields);
777
+		if ($merge)
778
+		{
779
+			$this->data_merge($_fields);
780
+		}
717 781
 
718 782
 		$fields = $this->data2db($_fields);
719 783
 
@@ -766,9 +830,12 @@  discard block
 block discarded – undo
766 830
 		{
767 831
 			$keys = array($this->autoinc_id => $keys);
768 832
 		}
769
-		if (!is_array($keys) || !count($keys))	// use internal data
833
+		if (!is_array($keys) || !count($keys))
834
+		{
835
+			// use internal data
770 836
 		{
771 837
 			$data = $this->data;
838
+		}
772 839
 			$keys = $this->db_key_cols;
773 840
 		}
774 841
 		else	// data and keys are supplied in $keys
@@ -799,7 +866,10 @@  discard block
 block discarded – undo
799 866
 				$query[$db_col] = $data[$col];
800 867
 			}
801 868
 		}
802
-		if ($only_return_query) return $query;
869
+		if ($only_return_query)
870
+		{
871
+			return $query;
872
+		}
803 873
 
804 874
 		$this->db->delete($this->table_name,$query,__LINE__,__FILE__,$this->app);
805 875
 
@@ -832,7 +902,10 @@  discard block
 block discarded – undo
832 902
 	function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false)
833 903
 	{
834 904
 		//error_log(__METHOD__.'('.array2string(array_combine(array_slice(array('criteria','only_keys','order_by','extra_cols','wildcard','empty','op','start','filter','join','need_full_no_count'), 0, count(func_get_args())), func_get_args())).')');
835
-		if ((int) $this->debug >= 4) echo "<p>so_sql::search(".print_r($criteria,true).",'$only_keys','$order_by',".print_r($extra_cols,true).",'$wildcard','$empty','$op','$start',".print_r($filter,true).",'$join')</p>\n";
905
+		if ((int) $this->debug >= 4)
906
+		{
907
+			echo "<p>so_sql::search(".print_r($criteria,true).",'$only_keys','$order_by',".print_r($extra_cols,true).",'$wildcard','$empty','$op','$start',".print_r($filter,true).",'$join')</p>\n";
908
+		}
836 909
 
837 910
 		// if extending class or instanciator set columns to search, convert string criteria to array
838 911
 		if ($criteria && !is_array($criteria))
@@ -852,7 +925,8 @@  discard block
 block discarded – undo
852 925
 		{
853 926
 			$db_filter = array();
854 927
 			$data2db_filter = $this->data2db($filter);
855
-			if (!is_array($data2db_filter)) {
928
+			if (!is_array($data2db_filter))
929
+			{
856 930
 				echo function_backtrace()."<br/>\n";
857 931
 				echo "filter=";_debug_array($filter);
858 932
 				echo "data2db(filter)=";_debug_array($data2db_filter);
@@ -948,7 +1022,10 @@  discard block
 block discarded – undo
948 1022
 			}
949 1023
 		}
950 1024
 		$num_rows = 0;	// as spec. in max_matches in the user-prefs
951
-		if (is_array($start)) list($start,$num_rows) = $start;
1025
+		if (is_array($start))
1026
+		{
1027
+			list($start,$num_rows) = $start;
1028
+		}
952 1029
 
953 1030
 		// fix GROUP BY clause to contain all non-aggregate selected columns
954 1031
 		if ($order_by && stripos($order_by,'GROUP BY') !== false)
@@ -976,18 +1053,24 @@  discard block
 block discarded – undo
976 1053
 					'append' => $order_by,
977 1054
 					'join'   => $join,
978 1055
 				);
979
-				if (!$union_cols)	// union used the colum-names of the first query
1056
+				if (!$union_cols)
1057
+				{
1058
+					// union used the colum-names of the first query
980 1059
 				{
981 1060
 					$union_cols = $this->_get_columns($only_keys,$extra_cols);
982 1061
 				}
1062
+				}
983 1063
 				return true;	// waiting for further calls, before running the union-query
984 1064
 			}
985 1065
 			// running the union query now
986
-			if ($start !== false)	// need to get the total too, saved in $this->total
1066
+			if ($start !== false)
1067
+			{
1068
+				// need to get the total too, saved in $this->total
987 1069
 			{
988 1070
 				if ($this->db->Type == 'mysql' && $this->db->ServerInfo['version'] >= 4.0)
989 1071
 				{
990 1072
 					$union[0]['cols'] = ($mysql_calc_rows = 'SQL_CALC_FOUND_ROWS ').$union[0]['cols'];
1073
+			}
991 1074
 				}
992 1075
 				else	// cant do a count, have to run the query without limit
993 1076
 				{
@@ -995,18 +1078,24 @@  discard block
 block discarded – undo
995 1078
 				}
996 1079
 			}
997 1080
 			$rs = $this->db->union($union,__LINE__,__FILE__,$order_by,$start,$num_rows);
998
-			if ($this->debug) error_log(__METHOD__."() ".$this->db->Query_ID->sql);
1081
+			if ($this->debug)
1082
+			{
1083
+				error_log(__METHOD__."() ".$this->db->Query_ID->sql);
1084
+			}
999 1085
 
1000 1086
 			$cols = $union_cols;
1001 1087
 			$union = $union_cols = array();
1002 1088
 		}
1003 1089
 		else	// no UNION
1004 1090
 		{
1005
-			if ($start !== false)	// need to get the total too, saved in $this->total
1091
+			if ($start !== false)
1092
+			{
1093
+				// need to get the total too, saved in $this->total
1006 1094
 			{
1007 1095
 				if ($this->db->Type == 'mysql' && $this->db->ServerInfo['version'] >= 4.0)
1008 1096
 				{
1009 1097
 					$mysql_calc_rows = 'SQL_CALC_FOUND_ROWS ';
1098
+			}
1010 1099
 				}
1011 1100
 				elseif (!$need_full_no_count && (!$join || stripos($join,'LEFT JOIN')!==false))
1012 1101
 				{
@@ -1019,10 +1108,16 @@  discard block
 block discarded – undo
1019 1108
 			}
1020 1109
 			$rs = $this->db->select($this->table_name,$mysql_calc_rows.$colums,$query,__LINE__,__FILE__,
1021 1110
 				$start,$order_by,$this->app,$num_rows,$join);
1022
-			if ($this->debug) error_log(__METHOD__."() ".$this->db->Query_ID->sql);
1111
+			if ($this->debug)
1112
+			{
1113
+				error_log(__METHOD__."() ".$this->db->Query_ID->sql);
1114
+			}
1023 1115
 			$cols = $this->_get_columns($only_keys,$extra_cols);
1024 1116
 		}
1025
-		if ((int) $this->debug >= 4) echo "<p>sql='{$this->db->Query_ID->sql}'</p>\n";
1117
+		if ((int) $this->debug >= 4)
1118
+		{
1119
+			echo "<p>sql='{$this->db->Query_ID->sql}'</p>\n";
1120
+		}
1026 1121
 
1027 1122
 		if ($mysql_calc_rows)
1028 1123
 		{
@@ -1035,9 +1130,12 @@  discard block
 block discarded – undo
1035 1130
 		}
1036 1131
 		$arr = array();
1037 1132
 		$n = 0;
1038
-		if ($rs) foreach($rs as $row)
1133
+		if ($rs)
1134
+		{
1135
+			foreach($rs as $row)
1039 1136
 		{
1040 1137
 			$data = array();
1138
+		}
1041 1139
 			foreach($cols as $db_col => $col)
1042 1140
 			{
1043 1141
 				$data[$col] = (isset($row[$db_col]) ? $row[$db_col] : $row[$col]);
@@ -1111,9 +1209,12 @@  discard block
 block discarded – undo
1111 1209
 							($negate ? ') ' : '');
1112 1210
 					}
1113 1211
 				}
1114
-				elseif (strpos($db_col,'.') !== false)	// we have a table-name specified
1212
+				elseif (strpos($db_col,'.') !== false)
1213
+				{
1214
+					// we have a table-name specified
1115 1215
 				{
1116 1216
 					list($table,$only_col) = explode('.',$db_col);
1217
+				}
1117 1218
 					$type = $this->db->get_column_attribute($only_col, $table, true, 'type');
1118 1219
 					if (empty($type))
1119 1220
 					{
@@ -1138,7 +1239,10 @@  discard block
 block discarded – undo
1138 1239
 				}
1139 1240
 			}
1140 1241
 		}
1141
-		if (is_array($query) && $op != 'AND') $query = $this->db->column_data_implode(' '.$op.' ',$query);
1242
+		if (is_array($query) && $op != 'AND')
1243
+		{
1244
+			$query = $this->db->column_data_implode(' '.$op.' ',$query);
1245
+		}
1142 1246
 		return $query;
1143 1247
 	}
1144 1248
 
@@ -1199,9 +1303,15 @@  discard block
 block discarded – undo
1199 1303
 					$col = substr($col, $pos+9);
1200 1304
 				}
1201 1305
 				$alias = $col;
1202
-				if (stripos($col, ' AS ')) list($col, $alias) = preg_split('/ +AS +/i', $col);
1306
+				if (stripos($col, ' AS '))
1307
+				{
1308
+					list($col, $alias) = preg_split('/ +AS +/i', $col);
1309
+				}
1203 1310
 				// do NOT group by constant expressions
1204
-				if (preg_match('/^ *(-?[0-9]+|".*"|\'.*\'|NULL) *$/i', $col)) continue;
1311
+				if (preg_match('/^ *(-?[0-9]+|".*"|\'.*\'|NULL) *$/i', $col))
1312
+				{
1313
+					continue;
1314
+				}
1205 1315
 				if (!in_array($col, $group_by_cols) && !in_array($alias, $group_by_cols))
1206 1316
 				{
1207 1317
 					// instead of aliased primary key, we have to use original column incl. table-name as alias is ambigues
@@ -1238,7 +1348,10 @@  discard block
 block discarded – undo
1238 1348
 	{
1239 1349
 		$pattern = trim($_pattern);
1240 1350
 		// This function can get called multiple times.  Make sure it doesn't re-process.
1241
-		if (empty($pattern) || is_array($pattern)) return $pattern;
1351
+		if (empty($pattern) || is_array($pattern))
1352
+		{
1353
+			return $pattern;
1354
+		}
1242 1355
 		if(strpos($pattern, 'CAST(COALESCE(') !== false)
1243 1356
 		{
1244 1357
 			return $pattern;
@@ -1313,7 +1426,7 @@  discard block
 block discarded – undo
1313 1426
 			{
1314 1427
 				$token = substr($token, 1,strlen($token));
1315 1428
  				if(substr($token, -1) != '"')
1316
-				{
1429
+ 				{
1317 1430
 					$token .= ' '.strtok('"');
1318 1431
 				}
1319 1432
 				else
@@ -1429,7 +1542,8 @@  discard block
 block discarded – undo
1429 1542
 			foreach($search_cols as $key => &$col)
1430 1543
 			{
1431 1544
 				// If the name as given isn't a real column name, and adding the prefix doesn't help, skip it
1432
-				if(!$this->table_def['fd'][$col] && !($col = $this->prefix.array_search($col, $search_cols))) {
1545
+				if(!$this->table_def['fd'][$col] && !($col = $this->prefix.array_search($col, $search_cols)))
1546
+				{
1433 1547
 					// Can't search this column
1434 1548
 					unset($search_cols[$key]);
1435 1549
 					continue;
@@ -1463,10 +1577,13 @@  discard block
 block discarded – undo
1463 1577
 	function _get_columns($only_keys,$extra_cols)
1464 1578
 	{
1465 1579
 		//echo "_get_columns() only_keys="; _debug_array($only_keys); echo "extra_cols="; _debug_array($extra_cols);
1466
-		if ($only_keys === true)	// only primary key
1580
+		if ($only_keys === true)
1581
+		{
1582
+			// only primary key
1467 1583
 		{
1468 1584
 			$cols = $this->db_key_cols;
1469 1585
 		}
1586
+		}
1470 1587
 		else
1471 1588
 		{
1472 1589
 			$cols = array();
@@ -1475,18 +1592,27 @@  discard block
 block discarded – undo
1475 1592
 			{
1476 1593
 				if (!$distinct_checked)
1477 1594
 				{
1478
-					if (stripos($col, 'DISTINCT ') === 0) $col = substr($col, 9);
1595
+					if (stripos($col, 'DISTINCT ') === 0)
1596
+					{
1597
+						$col = substr($col, 9);
1598
+					}
1479 1599
 					$distinct_checked = true;
1480 1600
 				}
1481
-				if (!$col || $col == '*' || $col == $this->table_name.'.*')	// all columns
1601
+				if (!$col || $col == '*' || $col == $this->table_name.'.*')
1602
+				{
1603
+					// all columns
1482 1604
 				{
1483 1605
 					$cols = array_merge($cols,$this->db_cols);
1484 1606
 				}
1607
+				}
1485 1608
 				else	// only the specified columns
1486 1609
 				{
1487
-					if (stripos($col,'as'))	// if there's already an explicit naming of the column, just use it
1610
+					if (stripos($col,'as'))
1611
+					{
1612
+						// if there's already an explicit naming of the column, just use it
1488 1613
 					{
1489 1614
 						$col = preg_replace('/^.*as +([a-z0-9_]+) *$/i','\\1',$col);
1615
+					}
1490 1616
 						$cols[$col] = $col;
1491 1617
 						continue;
1492 1618
 					}
@@ -1501,11 +1627,14 @@  discard block
 block discarded – undo
1501 1627
 				}
1502 1628
 			}
1503 1629
 		}
1504
-		if ($extra_cols)	// extra columns to report
1630
+		if ($extra_cols)
1631
+		{
1632
+			// extra columns to report
1505 1633
 		{
1506 1634
 			foreach(is_array($extra_cols) ? $extra_cols : explode(',',$extra_cols) as $col)
1507 1635
 			{
1508 1636
 				if (stripos($col,'as ')!==false) $col = preg_replace('/^.*as +([a-z0-9_]+) *$/i','\\1',$col);
1637
+		}
1509 1638
 				if (($db_col = array_search($col,$this->db_cols)) !== false)
1510 1639
 				{
1511 1640
 					$cols[$db_col] = $col;
@@ -1550,7 +1679,11 @@  discard block
 block discarded – undo
1550 1679
 			'',false,$op,$query['num_rows']?array((int)$query['start'],$query['num_rows']):(int)$query['start'],
1551 1680
 			$query['col_filter'],$join,$need_full_no_count);
1552 1681
 
1553
-		if (!$rows) $rows = array();	// otherwise false returned from search would be returned as array(false)
1682
+		if (!$rows)
1683
+		{
1684
+			$rows = array();
1685
+		}
1686
+		// otherwise false returned from search would be returned as array(false)
1554 1687
 
1555 1688
 		return $this->total;
1556 1689
 	}
@@ -1629,7 +1762,10 @@  discard block
 block discarded – undo
1629 1762
 		{
1630 1763
 			return $cache[$cache_key];
1631 1764
 		}
1632
-		if (!is_array($value_col)) $value_col = array($value_col);
1765
+		if (!is_array($value_col))
1766
+		{
1767
+			$value_col = array($value_col);
1768
+		}
1633 1769
 
1634 1770
 		$cols = $ret = array();
1635 1771
 		foreach($value_col as $key => $col)
@@ -1637,7 +1773,10 @@  discard block
 block discarded – undo
1637 1773
 			$matches = null;
1638 1774
 			$cols[$key] = preg_match('/AS ([a-z_0-9]+)$/i',$col,$matches) ? $matches[1] : $col;
1639 1775
 		}
1640
-		if (!$order) $order = current($cols);
1776
+		if (!$order)
1777
+		{
1778
+			$order = current($cols);
1779
+		}
1641 1780
 
1642 1781
 		if (($search =& $this->search(array(),($key_col ? $key_col.',' : 'DISTINCT ').implode(',',$value_col),$order,'','',false,'AND',false,$filter)))
1643 1782
 		{
@@ -1663,7 +1802,10 @@  discard block
 block discarded – undo
1663 1802
 				{
1664 1803
 					$data = $row[current($cols)];
1665 1804
 				}
1666
-				if ($data) $ret[$row[$key_col]] = $data;
1805
+				if ($data)
1806
+				{
1807
+					$ret[$row[$key_col]] = $data;
1808
+				}
1667 1809
 			}
1668 1810
 		}
1669 1811
 		return $cache[$cache_key] =& $ret;
Please login to merge, or discard this patch.
Spacing   +220 added lines, -220 removed lines patch added patch discarded remove patch
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 	 * @param string $timestamp_type =null default null=leave them as is, 'ts'|'integer' use integer unix timestamps,
180 180
 	 * 	'object' use Api\DateTime objects or 'string' use DB timestamp (Y-m-d H:i:s) string
181 181
 	 */
182
-	function __construct($app='',$table='',Api\Db $db=null,$column_prefix='',$no_clone=false,$timestamp_type=null)
182
+	function __construct($app = '', $table = '', Api\Db $db = null, $column_prefix = '', $no_clone = false, $timestamp_type = null)
183 183
 	{
184 184
 		// ease the transition to api
185 185
 		if ($app == 'phpgwapi') $app = 'api';
@@ -200,11 +200,11 @@  discard block
 block discarded – undo
200 200
 
201 201
 			if (!$no_clone) $this->db->set_app($app);
202 202
 
203
-			if ($table) $this->setup_table($app,$table,$column_prefix);
203
+			if ($table) $this->setup_table($app, $table, $column_prefix);
204 204
 		}
205 205
 		$this->init();
206 206
 
207
-		if ((int) $this->debug >= 4)
207
+		if ((int)$this->debug >= 4)
208 208
 		{
209 209
 			echo "<p>".__METHOD__."('$app','$table')</p>\n";
210 210
 			_debug_array($this);
@@ -219,21 +219,21 @@  discard block
 block discarded – undo
219 219
 	 * 	null=leave them as is, 'ts'|'integer' use integer unix timestamps, 'object' use Api\DateTime objects,
220 220
 	 *  'string' use DB timestamp (Y-m-d H:i:s) string
221 221
 	 */
222
-	public function set_times($timestamp_type=false)
222
+	public function set_times($timestamp_type = false)
223 223
 	{
224 224
 		if ($timestamp_type !== false) $this->timestamp_type = $timestamp_type;
225 225
 
226 226
 		// set current time
227
-		switch($this->timestamp_type)
227
+		switch ($this->timestamp_type)
228 228
 		{
229 229
 			case 'object':
230 230
 				$this->now = new Api\DateTime('now');
231 231
 				break;
232 232
 			case 'string':
233
-				$this->now = Api\DateTime::to('now',Api\DateTime::DATABASE);
233
+				$this->now = Api\DateTime::to('now', Api\DateTime::DATABASE);
234 234
 				break;
235 235
 			default:
236
-				$this->now = Api\DateTime::to('now','ts');
236
+				$this->now = Api\DateTime::to('now', 'ts');
237 237
 		}
238 238
 		$this->tz_offset_s = Api\DateTime::tz_offset_s();
239 239
 	}
@@ -247,10 +247,10 @@  discard block
 block discarded – undo
247 247
 	 * @param string $table table-name
248 248
 	 * @param string $colum_prefix ='' column prefix to automatic remove from the column-name, if the column name starts with it
249 249
 	 */
250
-	function setup_table($app,$table,$colum_prefix='')
250
+	function setup_table($app, $table, $colum_prefix = '')
251 251
 	{
252 252
 		$this->table_name = $table;
253
-		$this->table_def = $this->db->get_table_definitions($app,$table);
253
+		$this->table_def = $this->db->get_table_definitions($app, $table);
254 254
 		if (!$this->table_def || !is_array($this->table_def['fd']))
255 255
 		{
256 256
 			throw new Api\Exception\WrongParameter(__METHOD__."('$app','$table'): No table definition for '$table' found !!!");
@@ -258,14 +258,14 @@  discard block
 block discarded – undo
258 258
 		$this->db_key_cols = $this->db_data_cols = $this->db_cols = array();
259 259
 		$this->autoinc_id = '';
260 260
 		$len_prefix = strlen($colum_prefix);
261
-		foreach($this->table_def['fd'] as $col => $def)
261
+		foreach ($this->table_def['fd'] as $col => $def)
262 262
 		{
263 263
 			$name = $col;
264
-			if ($len_prefix && substr($name,0,$len_prefix) == $colum_prefix)
264
+			if ($len_prefix && substr($name, 0, $len_prefix) == $colum_prefix)
265 265
 			{
266
-				$name = substr($col,$len_prefix);
266
+				$name = substr($col, $len_prefix);
267 267
 			}
268
-			if (in_array($col,$this->table_def['pk']))
268
+			if (in_array($col, $this->table_def['pk']))
269 269
 			{
270 270
 				$this->db_key_cols[$col] = $name;
271 271
 			}
@@ -281,13 +281,13 @@  discard block
 block discarded – undo
281 281
 			}
282 282
 			if ($def['type'] == 'bool') $this->has_bools = true;
283 283
 
284
-			foreach($this->table_def['uc'] as $k => $uni_index)
284
+			foreach ($this->table_def['uc'] as $k => $uni_index)
285 285
 			{
286
-				if (is_array($uni_index) && in_array($name,$uni_index))
286
+				if (is_array($uni_index) && in_array($name, $uni_index))
287 287
 				{
288 288
 					$this->db_uni_cols[$k][$col] = $name;
289 289
 				}
290
-				elseif($name === $uni_index)
290
+				elseif ($name === $uni_index)
291 291
 				{
292 292
 					$this->db_uni_cols[$col] = $name;
293 293
 				}
@@ -302,9 +302,9 @@  discard block
 block discarded – undo
302 302
 	function convert_all_timestamps()
303 303
 	{
304 304
 		$check_already_included = !empty($this->timestamps);
305
-		foreach($this->table_def['fd'] as $name => $data)
305
+		foreach ($this->table_def['fd'] as $name => $data)
306 306
 		{
307
-			if ($data['type'] == 'timestamp' && (!$check_already_included || !in_array($name,$this->timestamps)))
307
+			if ($data['type'] == 'timestamp' && (!$check_already_included || !in_array($name, $this->timestamps)))
308 308
 			{
309 309
 				$this->timestamps[] = $name;
310 310
 			}
@@ -318,22 +318,22 @@  discard block
 block discarded – undo
318 318
 	 */
319 319
 	function data_merge($new)
320 320
 	{
321
-		if ((int) $this->debug >= 4) echo "<p>so_sql::data_merge(".print_r($new,true).")</p>\n";
321
+		if ((int)$this->debug >= 4) echo "<p>so_sql::data_merge(".print_r($new, true).")</p>\n";
322 322
 
323 323
 		if (!is_array($new) || !count($new))
324 324
 		{
325 325
 			return;
326 326
 		}
327
-		foreach($this->db_cols as $db_col => $col)
327
+		foreach ($this->db_cols as $db_col => $col)
328 328
 		{
329
-			if (array_key_exists($col,$new))
329
+			if (array_key_exists($col, $new))
330 330
 			{
331 331
 				$this->data[$col] = $new[$col];
332 332
 			}
333 333
 		}
334
-		foreach($this->non_db_cols as $db_col => $col)
334
+		foreach ($this->non_db_cols as $db_col => $col)
335 335
 		{
336
-			if (array_key_exists($col,$new))
336
+			if (array_key_exists($col, $new))
337 337
 			{
338 338
 				$this->data[$col] = $new[$col];
339 339
 			}
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
 		{
343 343
 			$this->data[self::USER_TIMEZONE_READ] = $new[self::USER_TIMEZONE_READ];
344 344
 		}
345
-		if ((int) $this->debug >= 4) _debug_array($this->data);
345
+		if ((int)$this->debug >= 4) _debug_array($this->data);
346 346
 	}
347 347
 
348 348
 	/**
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
 	 * @param array $data =null if given works on that array and returns result, else works on internal data-array
367 367
 	 * @return array
368 368
 	 */
369
-	function db2data($data=null)
369
+	function db2data($data = null)
370 370
 	{
371 371
 		if (!is_array($data))
372 372
 		{
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
 		}
375 375
 		if ($this->timestamps)
376 376
 		{
377
-			foreach($this->timestamps as $name)
377
+			foreach ($this->timestamps as $name)
378 378
 			{
379 379
 				if (isset($data[$name]) && $data[$name])
380 380
 				{
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
 					}
385 385
 					else
386 386
 					{
387
-						$data[$name] = Api\DateTime::server2user($data[$name],$this->timestamp_type);
387
+						$data[$name] = Api\DateTime::server2user($data[$name], $this->timestamp_type);
388 388
 					}
389 389
 				}
390 390
 			}
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 					throw new Api\Exception\WrongParameter(__METHOD__."(): No table definition for '$this->table' found !!!");
401 401
 				}
402 402
 			}
403
-			foreach($this->table_def['fd'] as $col => $def)
403
+			foreach ($this->table_def['fd'] as $col => $def)
404 404
 			{
405 405
 				if ($def['type'] == 'bool' && isset($data[$col]))
406 406
 				{
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 	 * @param array $data =null if given works on that array and returns result, else works on internal data-array
433 433
 	 * @return array
434 434
 	 */
435
-	function data2db($data=null)
435
+	function data2db($data = null)
436 436
 	{
437 437
 		if (!is_array($data))
438 438
 		{
@@ -440,11 +440,11 @@  discard block
 block discarded – undo
440 440
 		}
441 441
 		if ($this->timestamps)
442 442
 		{
443
-			foreach($this->timestamps as $name)
443
+			foreach ($this->timestamps as $name)
444 444
 			{
445 445
 				if (isset($data[$name]) && $data[$name])
446 446
 				{
447
-					$data[$name] = Api\DateTime::user2server($data[$name],$this->timestamp_type);
447
+					$data[$name] = Api\DateTime::user2server($data[$name], $this->timestamp_type);
448 448
 				}
449 449
 			}
450 450
 		}
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
 	 * @param array $keys =array() array with keys in form internalName => value
458 458
 	 * @return array internal data after init
459 459
 	 */
460
-	function init($keys=array())
460
+	function init($keys = array())
461 461
 	{
462 462
 		$this->data = array();
463 463
 
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
 	 * @param string $join ='' sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or
482 482
 	 * @return array|boolean data if row could be retrived else False
483 483
 	 */
484
-	function read($keys,$extra_cols='',$join='')
484
+	function read($keys, $extra_cols = '', $join = '')
485 485
 	{
486 486
 		if (!is_array($keys))
487 487
 		{
@@ -502,16 +502,16 @@  discard block
 block discarded – undo
502 502
 		}
503 503
 		if (!$query)	// no primary key in keys, lets try the data_cols for a unique key
504 504
 		{
505
-			foreach($this->db_uni_cols as $db_col => $col)
505
+			foreach ($this->db_uni_cols as $db_col => $col)
506 506
 			{
507 507
 				if (!is_array($col) && $this->data[$col] != '')
508 508
 				{
509 509
 					$query[$db_col] = $this->data[$col];
510 510
 				}
511
-				elseif(is_array($col))
511
+				elseif (is_array($col))
512 512
 				{
513 513
 					$q = array();
514
-					foreach($col as $db_c => $c)
514
+					foreach ($col as $db_c => $c)
515 515
 					{
516 516
 						if ($this->data[$col] == '')
517 517
 						{
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
 		}
527 527
 		if (!$query)	// no unique key in keys, lets try everything else
528 528
 		{
529
-			foreach($this->db_data_cols as $db_col => $col)
529
+			foreach ($this->db_data_cols as $db_col => $col)
530 530
 			{
531 531
 				if ($this->data[$col] != '')
532 532
 				{
@@ -542,27 +542,27 @@  discard block
 block discarded – undo
542 542
 		}
543 543
 		if ($join)	// Prefix the columns with the table-name, as they might exist in the join
544 544
 		{
545
-			foreach($query as $col => $val)
545
+			foreach ($query as $col => $val)
546 546
 			{
547
-				if (is_int($col) || strpos($join,$col) === false) continue;
548
-				$query[] = $this->db->expression($this->table_name,$this->table_name.'.',array($col=>$val));
547
+				if (is_int($col) || strpos($join, $col) === false) continue;
548
+				$query[] = $this->db->expression($this->table_name, $this->table_name.'.', array($col=>$val));
549 549
 				unset($query[$col]);
550 550
 			}
551 551
 		}
552 552
 		// copy direct SQL parts from $keys
553
-		for($i = 0; is_array($keys) && isset($keys[$i]); ++$i)
553
+		for ($i = 0; is_array($keys) && isset($keys[$i]); ++$i)
554 554
 		{
555 555
 			$query[] = $keys[$i];
556 556
 		}
557
-		foreach($this->db->select($this->table_name,'*'.($extra_cols?','.(is_array($extra_cols)?implode(',',$extra_cols):$extra_cols):''),
558
-			$query,__LINE__,__FILE__,False,'',$this->app,0,$join) as $row)
557
+		foreach ($this->db->select($this->table_name, '*'.($extra_cols ? ','.(is_array($extra_cols) ?implode(',', $extra_cols) : $extra_cols) : ''),
558
+			$query, __LINE__, __FILE__, False, '', $this->app, 0, $join) as $row)
559 559
 		{
560 560
 			$cols = $this->db_cols;
561 561
 			if ($extra_cols)	// extra columns to report
562 562
 			{
563
-				foreach(is_array($extra_cols) ? $extra_cols : array($extra_cols) as $col)
563
+				foreach (is_array($extra_cols) ? $extra_cols : array($extra_cols) as $col)
564 564
 				{
565
-					if (FALSE!==stripos($col,' as ')) $col = preg_replace('/^.* as *([a-z0-9_]+) *$/i','\\1',$col);
565
+					if (FALSE !== stripos($col, ' as ')) $col = preg_replace('/^.* as *([a-z0-9_]+) *$/i', '\\1', $col);
566 566
 					$cols[$col] = $col;
567 567
 				}
568 568
 			}
@@ -575,7 +575,7 @@  discard block
 block discarded – undo
575 575
 			// store user timezone used for reading
576 576
 			$this->data[self::USER_TIMEZONE_READ] = Api\DateTime::$user_timezone->getName();
577 577
 
578
-			if ((int) $this->debug >= 4)
578
+			if ((int)$this->debug >= 4)
579 579
 			{
580 580
 				echo "data =\n"; _debug_array($this->data);
581 581
 			}
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
 		{
586 586
 			unset($this->data[$this->db_key_cols[$this->autoinc_id]]);
587 587
 		}
588
-		if ((int) $this->debug >= 4) echo "nothing found !!!</p>\n";
588
+		if ((int)$this->debug >= 4) echo "nothing found !!!</p>\n";
589 589
 
590 590
 		$this->db2data();
591 591
 
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
 	 * @param string|array $extra_where =null extra where clause, eg. to check an etag, returns true if no affected rows!
600 600
 	 * @return int|boolean 0 on success, or errno != 0 on error, or true if $extra_where is given and no rows affected
601 601
 	 */
602
-	function save($keys=null,$extra_where=null)
602
+	function save($keys = null, $extra_where = null)
603 603
 	{
604 604
 		if (is_array($keys) && count($keys)) $this->data_merge($keys);
605 605
 
@@ -618,65 +618,65 @@  discard block
 block discarded – undo
618 618
 		}
619 619
 		$this->data2db();
620 620
 
621
-		if ((int) $this->debug >= 4) { echo "so_sql::save(".print_r($keys,true).") autoinc_id='$this->autoinc_id', data="; _debug_array($this->data); }
621
+		if ((int)$this->debug >= 4) { echo "so_sql::save(".print_r($keys, true).") autoinc_id='$this->autoinc_id', data="; _debug_array($this->data); }
622 622
 
623 623
 		if ($this->autoinc_id && !$this->data[$this->db_key_cols[$this->autoinc_id]])	// insert with auto id
624 624
 		{
625
-			foreach($this->db_cols as $db_col => $col)
625
+			foreach ($this->db_cols as $db_col => $col)
626 626
 			{
627 627
 				if (!$this->autoinc_id || $db_col != $this->autoinc_id)	// not write auto-inc-id
628 628
 				{
629
-					if (!array_key_exists($col,$this->data) && 	// handling of unset columns in $this->data
630
-						(isset($this->table_def['fd'][$db_col]['default']) ||	// we have a default value
629
+					if (!array_key_exists($col, $this->data) && // handling of unset columns in $this->data
630
+						(isset($this->table_def['fd'][$db_col]['default']) || // we have a default value
631 631
 						 !isset($this->table_def['fd'][$db_col]['nullable']) || $this->table_def['fd'][$db_col]['nullable']))	// column is nullable
632 632
 					{
633
-						continue;	// no need to write that (unset) column
633
+						continue; // no need to write that (unset) column
634 634
 					}
635 635
 					if ($this->table_def['fd'][$db_col]['type'] == 'varchar' &&
636 636
 						strlen($this->data[$col]) > $this->table_def['fd'][$db_col]['precision'])
637 637
 					{
638 638
 						// truncate the field to mamimum length, if upper layers didn't care
639
-						$data[$db_col] = substr($this->data[$col],0,$this->table_def['fd'][$db_col]['precision']);
639
+						$data[$db_col] = substr($this->data[$col], 0, $this->table_def['fd'][$db_col]['precision']);
640 640
 					}
641 641
 					else
642 642
 					{
643
-						$data[$db_col] = (string) $this->data[$col] === '' && $this->empty_on_write == 'NULL' ? null : $this->data[$col];
643
+						$data[$db_col] = (string)$this->data[$col] === '' && $this->empty_on_write == 'NULL' ? null : $this->data[$col];
644 644
 					}
645 645
 				}
646 646
 			}
647
-			$this->db->insert($this->table_name,$data,false,__LINE__,__FILE__,$this->app);
647
+			$this->db->insert($this->table_name, $data, false, __LINE__, __FILE__, $this->app);
648 648
 
649 649
 			if ($this->autoinc_id)
650 650
 			{
651
-				$this->data[$this->db_key_cols[$this->autoinc_id]] = $this->db->get_last_insert_id($this->table_name,$this->autoinc_id);
651
+				$this->data[$this->db_key_cols[$this->autoinc_id]] = $this->db->get_last_insert_id($this->table_name, $this->autoinc_id);
652 652
 			}
653 653
 		}
654 654
 		else // insert in table without auto id or update of existing row, dont write colums unset in $this->data
655 655
 		{
656
-			foreach($this->db_data_cols as $db_col => $col)
656
+			foreach ($this->db_data_cols as $db_col => $col)
657 657
 			{
658 658
 				// we need to update columns set to null: after a $this->data[$col]=null:
659 659
 				// - array_key_exits($col,$this->data) === true
660 660
 				// - isset($this->data[$col]) === false
661
-				if (!array_key_exists($col,$this->data) &&	// handling of unset columns in $this->data
662
-					($this->autoinc_id ||			// update of table with auto id or
663
-					 isset($this->table_def['fd'][$db_col]['default']) ||	// we have a default value or
661
+				if (!array_key_exists($col, $this->data) && // handling of unset columns in $this->data
662
+					($this->autoinc_id || // update of table with auto id or
663
+					 isset($this->table_def['fd'][$db_col]['default']) || // we have a default value or
664 664
 					 !isset($this->table_def['fd'][$db_col]['nullable']) || $this->table_def['fd'][$db_col]['nullable']))	// column is nullable
665 665
 				{
666
-					continue;	// no need to write that (unset) column
666
+					continue; // no need to write that (unset) column
667 667
 				}
668
-				$data[$db_col] = !is_object($this->data[$col]) && (string) $this->data[$col] === '' && $this->empty_on_write == 'NULL' ? null : $this->data[$col];
668
+				$data[$db_col] = !is_object($this->data[$col]) && (string)$this->data[$col] === '' && $this->empty_on_write == 'NULL' ? null : $this->data[$col];
669 669
 			}
670 670
 			// allow to add direct sql updates, eg. "etag=etag+1" with int keys
671 671
 			if (is_array($keys) && isset($keys[0]))
672 672
 			{
673
-				for($n=0; isset($keys[$n]); ++$n)
673
+				for ($n = 0; isset($keys[$n]); ++$n)
674 674
 				{
675 675
 					$data[] = $keys[$n];
676 676
 				}
677 677
 			}
678 678
 			$keys = $extra_where;
679
-			foreach($this->db_key_cols as $db_col => $col)
679
+			foreach ($this->db_key_cols as $db_col => $col)
680 680
 			{
681 681
 				$keys[$db_col] = $this->data[$col];
682 682
 			}
@@ -687,16 +687,16 @@  discard block
 block discarded – undo
687 687
 			}
688 688
 			if ($this->autoinc_id)
689 689
 			{
690
-				$this->db->update($this->table_name,$data,$keys,__LINE__,__FILE__,$this->app);
690
+				$this->db->update($this->table_name, $data, $keys, __LINE__, __FILE__, $this->app);
691 691
 				if (($nothing_affected = !$this->db->Errno && !$this->db->affected_rows()) && $extra_where)
692 692
 				{
693
-					return true;	// extra_where not met, eg. etag wrong
693
+					return true; // extra_where not met, eg. etag wrong
694 694
 				}
695 695
 			}
696 696
 			// always try an insert if we have no autoinc_id, as we dont know if the data exists
697 697
 			if (!$this->autoinc_id || $nothing_affected)
698 698
 			{
699
-				$this->db->insert($this->table_name,$data,$keys,__LINE__,__FILE__,$this->app);
699
+				$this->db->insert($this->table_name, $data, $keys, __LINE__, __FILE__, $this->app);
700 700
 			}
701 701
 		}
702 702
 		$this->db2data();
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
 	 * @param boolean $merge =true if true $fields will be merged with $this->data (after update!), otherwise $this->data will be just $fields
712 712
 	 * @return int|boolean 0 on success, or errno != 0 on error, or true if $extra_where is given and no rows affected
713 713
 	 */
714
-	function update($_fields,$merge=true)
714
+	function update($_fields, $merge = true)
715 715
 	{
716 716
 		if ($merge) $this->data_merge($_fields);
717 717
 
@@ -719,23 +719,23 @@  discard block
 block discarded – undo
719 719
 
720 720
 		// extract the keys from $fields or - if not set there - from $this->data
721 721
 		$keys = array();
722
-		foreach($this->db_key_cols as $col => $name)
722
+		foreach ($this->db_key_cols as $col => $name)
723 723
 		{
724 724
 			$keys[$col] = isset($fields[$name]) ? $fields[$name] : $this->data[$name];
725 725
 			unset($fields[$name]);
726 726
 		}
727 727
 		// extract the data from $fields
728 728
 		$data = array();
729
-		foreach($this->db_data_cols as $col => $name)
729
+		foreach ($this->db_data_cols as $col => $name)
730 730
 		{
731
-			if (array_key_exists($name,$fields))
731
+			if (array_key_exists($name, $fields))
732 732
 			{
733 733
 				$data[$col] = $fields[$name];
734 734
 				unset($fields[$name]);
735 735
 			}
736 736
 		}
737 737
 		// add direct sql like 'etag=etag+1' (it has integer keys)
738
-		foreach($fields as $key => $value)
738
+		foreach ($fields as $key => $value)
739 739
 		{
740 740
 			if (is_int($key))
741 741
 			{
@@ -744,9 +744,9 @@  discard block
 block discarded – undo
744 744
 		}
745 745
 		if (!$data)
746 746
 		{
747
-			return 0;	// nothing to update
747
+			return 0; // nothing to update
748 748
 		}
749
-		if (!$this->db->update($this->table_name,$data,$keys,__LINE__,__FILE__,$this->app))
749
+		if (!$this->db->update($this->table_name, $data, $keys, __LINE__, __FILE__, $this->app))
750 750
 		{
751 751
 			return $this->db->Errno;
752 752
 		}
@@ -760,7 +760,7 @@  discard block
 block discarded – undo
760 760
 	 * @param boolean $only_return_query =false return $query of delete call to db object, but not run it (used by so_sql_cf!)
761 761
 	 * @return int|array affected rows, should be 1 if ok, 0 if an error or array with id's if $only_return_ids
762 762
 	 */
763
-	function delete($keys=null,$only_return_query=false)
763
+	function delete($keys = null, $only_return_query = false)
764 764
 	{
765 765
 		if ($this->autoinc_id && $keys && !is_array($keys))
766 766
 		{
@@ -774,7 +774,7 @@  discard block
 block discarded – undo
774 774
 		else	// data and keys are supplied in $keys
775 775
 		{
776 776
 			$data = $keys; $keys = array();
777
-			foreach($this->db_cols as $db_col => $col)
777
+			foreach ($this->db_cols as $db_col => $col)
778 778
 			{
779 779
 				if (isset($data[$col]))
780 780
 				{
@@ -782,7 +782,7 @@  discard block
 block discarded – undo
782 782
 				}
783 783
 			}
784 784
 			// keep sql fragments (with integer key)
785
-			foreach($data as $key => $val)
785
+			foreach ($data as $key => $val)
786 786
 			{
787 787
 				if (is_int($key))
788 788
 				{
@@ -792,7 +792,7 @@  discard block
 block discarded – undo
792 792
 		}
793 793
 		$data = $this->data2db($data);
794 794
 
795
-		foreach($keys as $db_col => $col)
795
+		foreach ($keys as $db_col => $col)
796 796
 		{
797 797
 			if (is_int($db_col))
798 798
 			{
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
 		}
806 806
 		if ($only_return_query) return $query;
807 807
 
808
-		$this->db->delete($this->table_name,$query,__LINE__,__FILE__,$this->app);
808
+		$this->db->delete($this->table_name, $query, __LINE__, __FILE__, $this->app);
809 809
 
810 810
 		return $this->db->affected_rows();
811 811
 	}
@@ -833,15 +833,15 @@  discard block
 block discarded – undo
833 833
 	 * @todo return an interator instead of an array
834 834
 	 * @return array|NULL array of matching rows (the row is an array of the cols) or NULL
835 835
 	 */
836
-	function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false)
836
+	function &search($criteria, $only_keys = True, $order_by = '', $extra_cols = '', $wildcard = '', $empty = False, $op = 'AND', $start = false, $filter = null, $join = '', $need_full_no_count = false)
837 837
 	{
838 838
 		//error_log(__METHOD__.'('.array2string(array_combine(array_slice(array('criteria','only_keys','order_by','extra_cols','wildcard','empty','op','start','filter','join','need_full_no_count'), 0, count(func_get_args())), func_get_args())).')');
839
-		if ((int) $this->debug >= 4) echo "<p>so_sql::search(".print_r($criteria,true).",'$only_keys','$order_by',".print_r($extra_cols,true).",'$wildcard','$empty','$op','$start',".print_r($filter,true).",'$join')</p>\n";
839
+		if ((int)$this->debug >= 4) echo "<p>so_sql::search(".print_r($criteria, true).",'$only_keys','$order_by',".print_r($extra_cols, true).",'$wildcard','$empty','$op','$start',".print_r($filter, true).",'$join')</p>\n";
840 840
 
841 841
 		// if extending class or instanciator set columns to search, convert string criteria to array
842 842
 		if ($criteria && !is_array($criteria))
843 843
 		{
844
-			$search = $this->search2criteria($criteria,$wildcard,$op);
844
+			$search = $this->search2criteria($criteria, $wildcard, $op);
845 845
 			$criteria = array($search);
846 846
 		}
847 847
 		if (!is_array($criteria))
@@ -858,19 +858,19 @@  discard block
 block discarded – undo
858 858
 			$data2db_filter = $this->data2db($filter);
859 859
 			if (!is_array($data2db_filter)) {
860 860
 				echo function_backtrace()."<br/>\n";
861
-				echo "filter=";_debug_array($filter);
862
-				echo "data2db(filter)=";_debug_array($data2db_filter);
861
+				echo "filter="; _debug_array($filter);
862
+				echo "data2db(filter)="; _debug_array($data2db_filter);
863 863
 			}
864
-			foreach($data2db_filter as $col => $val)
864
+			foreach ($data2db_filter as $col => $val)
865 865
 			{
866 866
 				if ($val !== '')
867 867
 				{
868 868
 					// check if a db-internal name conversation necessary
869
-					if (!is_int($col) && ($c = array_search($col,$this->db_cols)))
869
+					if (!is_int($col) && ($c = array_search($col, $this->db_cols)))
870 870
 					{
871
-						$col = $this->table_name . '.' . $c;
871
+						$col = $this->table_name.'.'.$c;
872 872
 					}
873
-					if(is_int($col))
873
+					if (is_int($col))
874 874
 					{
875 875
 						$db_filter[] = $val;
876 876
 					}
@@ -888,35 +888,35 @@  discard block
 block discarded – undo
888 888
 			{
889 889
 				if ($op != 'AND')
890 890
 				{
891
-					$db_filter[] = '('.$this->db->column_data_implode(' '.$op.' ',$query).')';
891
+					$db_filter[] = '('.$this->db->column_data_implode(' '.$op.' ', $query).')';
892 892
 				}
893 893
 				else
894 894
 				{
895
-					$db_filter = array_merge($db_filter,$query);
895
+					$db_filter = array_merge($db_filter, $query);
896 896
 				}
897 897
 			}
898 898
 			$query = $db_filter;
899 899
 		}
900
-		if ((int) $this->debug >= 4)
900
+		if ((int)$this->debug >= 4)
901 901
 		{
902
-			echo "<p>so_sql::search(,only_keys=$only_keys,order_by='$order_by',wildcard='$wildcard',empty=$empty,$op,start='$start',".print_r($filter,true).") query=".print_r($query,true).", total='$this->total'</p>\n";
902
+			echo "<p>so_sql::search(,only_keys=$only_keys,order_by='$order_by',wildcard='$wildcard',empty=$empty,$op,start='$start',".print_r($filter, true).") query=".print_r($query, true).", total='$this->total'</p>\n";
903 903
 			echo "<br>criteria = "; _debug_array($criteria);
904 904
 		}
905 905
 		if ($only_keys === true)
906 906
 		{
907 907
 			$colums = array_keys($this->db_key_cols);
908
-			foreach($colums as &$column)
908
+			foreach ($colums as &$column)
909 909
 			{
910
-				$column = $this->table_name . '.' . $column;
910
+				$column = $this->table_name.'.'.$column;
911 911
 			}
912 912
 		}
913 913
 		elseif (is_array($only_keys))
914 914
 		{
915 915
 			$colums = array();
916
-			foreach($only_keys as $key => $col)
916
+			foreach ($only_keys as $key => $col)
917 917
 			{
918 918
 				//Convert ambiguous columns to prefixed tablename.column name
919
-				$colums[] = ($db_col = array_search($col,$this->db_cols)) ?  $this->table_name .'.'.$db_col.' AS '.$col :$col;
919
+				$colums[] = ($db_col = array_search($col, $this->db_cols)) ? $this->table_name.'.'.$db_col.' AS '.$col : $col;
920 920
 			}
921 921
 		}
922 922
 		elseif (!$only_keys)
@@ -946,20 +946,20 @@  discard block
 block discarded – undo
946 946
 			{
947 947
 				$colums[$key] = $this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id;
948 948
 			}
949
-			elseif (!is_array($colums) && strpos($colums,$this->autoinc_id) !== false)
949
+			elseif (!is_array($colums) && strpos($colums, $this->autoinc_id) !== false)
950 950
 			{
951
-				$colums = preg_replace('/(?<! AS)([ ,]+)'.preg_quote($this->autoinc_id).'([ ,]+)/','\\1'.$this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id.'\\2',$colums);
951
+				$colums = preg_replace('/(?<! AS)([ ,]+)'.preg_quote($this->autoinc_id).'([ ,]+)/', '\\1'.$this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id.'\\2', $colums);
952 952
 			}
953 953
 		}
954
-		$num_rows = 0;	// as spec. in max_matches in the user-prefs
955
-		if (is_array($start)) list($start,$num_rows) = $start;
954
+		$num_rows = 0; // as spec. in max_matches in the user-prefs
955
+		if (is_array($start)) list($start, $num_rows) = $start;
956 956
 
957 957
 		// fix GROUP BY clause to contain all non-aggregate selected columns
958
-		if ($order_by && stripos($order_by,'GROUP BY') !== false)
958
+		if ($order_by && stripos($order_by, 'GROUP BY') !== false)
959 959
 		{
960 960
 			$order_by = $this->fix_group_by_columns($order_by, $colums, $this->table_name, $this->autoinc_id);
961 961
 		}
962
-		elseif ($order_by && stripos($order_by,'ORDER BY')===false && stripos($order_by,'GROUP BY')===false && stripos($order_by,'HAVING')===false)
962
+		elseif ($order_by && stripos($order_by, 'ORDER BY') === false && stripos($order_by, 'GROUP BY') === false && stripos($order_by, 'HAVING') === false)
963 963
 		{
964 964
 			$order_by = 'ORDER BY '.$order_by;
965 965
 		}
@@ -982,9 +982,9 @@  discard block
 block discarded – undo
982 982
 				);
983 983
 				if (!$union_cols)	// union used the colum-names of the first query
984 984
 				{
985
-					$union_cols = $this->_get_columns($only_keys,$extra_cols);
985
+					$union_cols = $this->_get_columns($only_keys, $extra_cols);
986 986
 				}
987
-				return true;	// waiting for further calls, before running the union-query
987
+				return true; // waiting for further calls, before running the union-query
988 988
 			}
989 989
 			// running the union query now
990 990
 			if ($start !== false)	// need to get the total too, saved in $this->total
@@ -995,10 +995,10 @@  discard block
 block discarded – undo
995 995
 				}
996 996
 				else	// cant do a count, have to run the query without limit
997 997
 				{
998
-					$this->total = $this->db->union($union,__LINE__,__FILE__)->NumRows();
998
+					$this->total = $this->db->union($union, __LINE__, __FILE__)->NumRows();
999 999
 				}
1000 1000
 			}
1001
-			$rs = $this->db->union($union,__LINE__,__FILE__,$order_by,$start,$num_rows);
1001
+			$rs = $this->db->union($union, __LINE__, __FILE__, $order_by, $start, $num_rows);
1002 1002
 			if ($this->debug) error_log(__METHOD__."() ".$this->db->Query_ID->sql);
1003 1003
 
1004 1004
 			$cols = $union_cols;
@@ -1012,21 +1012,21 @@  discard block
 block discarded – undo
1012 1012
 				{
1013 1013
 					$mysql_calc_rows = 'SQL_CALC_FOUND_ROWS ';
1014 1014
 				}
1015
-				elseif (!$need_full_no_count && (!$join || stripos($join,'LEFT JOIN')!==false))
1015
+				elseif (!$need_full_no_count && (!$join || stripos($join, 'LEFT JOIN') !== false))
1016 1016
 				{
1017
-					$this->total = $this->db->select($this->table_name,'COUNT(*)',$query,__LINE__,__FILE__,false,'',$this->app,0,$join)->fetchColumn();
1017
+					$this->total = $this->db->select($this->table_name, 'COUNT(*)', $query, __LINE__, __FILE__, false, '', $this->app, 0, $join)->fetchColumn();
1018 1018
 				}
1019 1019
 				else	// cant do a count, have to run the query without limit
1020 1020
 				{
1021
-					$this->total = $this->db->select($this->table_name,$colums,$query,__LINE__,__FILE__,false,$order_by,false,0,$join)->NumRows();
1021
+					$this->total = $this->db->select($this->table_name, $colums, $query, __LINE__, __FILE__, false, $order_by, false, 0, $join)->NumRows();
1022 1022
 				}
1023 1023
 			}
1024
-			$rs = $this->db->select($this->table_name,$mysql_calc_rows.$colums,$query,__LINE__,__FILE__,
1025
-				$start,$order_by,$this->app,$num_rows,$join);
1024
+			$rs = $this->db->select($this->table_name, $mysql_calc_rows.$colums, $query, __LINE__, __FILE__,
1025
+				$start, $order_by, $this->app, $num_rows, $join);
1026 1026
 			if ($this->debug) error_log(__METHOD__."() ".$this->db->Query_ID->sql);
1027
-			$cols = $this->_get_columns($only_keys,$extra_cols);
1027
+			$cols = $this->_get_columns($only_keys, $extra_cols);
1028 1028
 		}
1029
-		if ((int) $this->debug >= 4) echo "<p>sql='{$this->db->Query_ID->sql}'</p>\n";
1029
+		if ((int)$this->debug >= 4) echo "<p>sql='{$this->db->Query_ID->sql}'</p>\n";
1030 1030
 
1031 1031
 		if ($mysql_calc_rows)
1032 1032
 		{
@@ -1035,14 +1035,14 @@  discard block
 block discarded – undo
1035 1035
 		// ToDo: Implement that as an iterator, as $rs is also an interator and we could return one instead of an array
1036 1036
 		if ($this->search_return_iterator)
1037 1037
 		{
1038
-			return new Db2DataIterator($this,$rs);
1038
+			return new Db2DataIterator($this, $rs);
1039 1039
 		}
1040 1040
 		$arr = array();
1041 1041
 		$n = 0;
1042
-		if ($rs) foreach($rs as $row)
1042
+		if ($rs) foreach ($rs as $row)
1043 1043
 		{
1044 1044
 			$data = array();
1045
-			foreach($cols as $db_col => $col)
1045
+			foreach ($cols as $db_col => $col)
1046 1046
 			{
1047 1047
 				$data[$col] = (isset($row[$db_col]) ? $row[$db_col] : $row[$col]);
1048 1048
 			}
@@ -1066,7 +1066,7 @@  discard block
 block discarded – undo
1066 1066
 	protected function parse_search(Array $_criteria, $wildcard, $empty, $op)
1067 1067
 	{
1068 1068
 		$criteria = $this->data2db($_criteria);
1069
-		foreach($criteria as $col => $val)
1069
+		foreach ($criteria as $col => $val)
1070 1070
 		{
1071 1071
 			if (is_int($col))
1072 1072
 			{
@@ -1074,7 +1074,7 @@  discard block
 block discarded – undo
1074 1074
 			}
1075 1075
 			elseif ($empty || $val != '')
1076 1076
 			{
1077
-				if (!($db_col = array_search($col,$this->db_cols)))
1077
+				if (!($db_col = array_search($col, $this->db_cols)))
1078 1078
 				{
1079 1079
 					$db_col = $col;
1080 1080
 				}
@@ -1085,7 +1085,7 @@  discard block
 block discarded – undo
1085 1085
 						$this->table_def['fd'][$db_col]['nullable'] !== false)
1086 1086
 					{
1087 1087
 						unset($criteria[$col]);
1088
-						$query[] =  '(' . $db_col . ' IS NULL OR ' . $db_col . " = '')";
1088
+						$query[] = '('.$db_col.' IS NULL OR '.$db_col." = '')";
1089 1089
 					}
1090 1090
 					else
1091 1091
 					{
@@ -1093,10 +1093,10 @@  discard block
 block discarded – undo
1093 1093
 					}
1094 1094
 				}
1095 1095
 				elseif ($wildcard || $criteria[$col][0] == '!' ||
1096
-					is_string($criteria[$col]) && (strpos($criteria[$col],'*')!==false || strpos($criteria[$col],'?')!==false))
1096
+					is_string($criteria[$col]) && (strpos($criteria[$col], '*') !== false || strpos($criteria[$col], '?') !== false))
1097 1097
 				{
1098 1098
 					// if search pattern alread contains a wildcard, do NOT add further ones automatic
1099
-					if (is_string($criteria[$col]) && (strpos($criteria[$col],'*')!==false || strpos($criteria[$col],'?')!==false))
1099
+					if (is_string($criteria[$col]) && (strpos($criteria[$col], '*') !== false || strpos($criteria[$col], '?') !== false))
1100 1100
 					{
1101 1101
 						$wildcard = '';
1102 1102
 					}
@@ -1105,19 +1105,19 @@  discard block
 block discarded – undo
1105 1105
 					if ($criteria[$col][0] == '!')
1106 1106
 					{
1107 1107
 						$cmp_op = ' NOT'.$cmp_op;
1108
-						$criteria[$col] = substr($criteria[$col],1);
1108
+						$criteria[$col] = substr($criteria[$col], 1);
1109 1109
 						$negate = true;
1110 1110
 					}
1111
-					foreach(explode(' ',$criteria[$col]) as $crit)
1111
+					foreach (explode(' ', $criteria[$col]) as $crit)
1112 1112
 					{
1113 1113
 						$query[] = ($negate ? ' ('.$db_col.' IS NULL OR ' : '').$db_col.$cmp_op.
1114
-							$this->db->quote($wildcard.str_replace(array('%','_','*','?'),array('\\%','\\_','%','_'),$crit).$wildcard).
1114
+							$this->db->quote($wildcard.str_replace(array('%', '_', '*', '?'), array('\\%', '\\_', '%', '_'), $crit).$wildcard).
1115 1115
 							($negate ? ') ' : '');
1116 1116
 					}
1117 1117
 				}
1118
-				elseif (strpos($db_col,'.') !== false)	// we have a table-name specified
1118
+				elseif (strpos($db_col, '.') !== false)	// we have a table-name specified
1119 1119
 				{
1120
-					list($table,$only_col) = explode('.',$db_col);
1120
+					list($table, $only_col) = explode('.', $db_col);
1121 1121
 					$type = $this->db->get_column_attribute($only_col, $table, true, 'type');
1122 1122
 					if (empty($type))
1123 1123
 					{
@@ -1125,15 +1125,15 @@  discard block
 block discarded – undo
1125 1125
 					}
1126 1126
 					if (is_array($val) && count($val) > 1)
1127 1127
 					{
1128
-						foreach($val as &$v)
1128
+						foreach ($val as &$v)
1129 1129
 						{
1130 1130
 							$v = $this->db->quote($v, $type);
1131 1131
 						}
1132
-						$query[] = $sql = $db_col.' IN (' .implode(',',$val).')';
1132
+						$query[] = $sql = $db_col.' IN ('.implode(',', $val).')';
1133 1133
 					}
1134 1134
 					else
1135 1135
 					{
1136
-						$query[] = $db_col.'='.$this->db->quote(is_array($val)?array_shift($val):$val,$type);
1136
+						$query[] = $db_col.'='.$this->db->quote(is_array($val) ?array_shift($val) : $val, $type);
1137 1137
 					}
1138 1138
 				}
1139 1139
 				else
@@ -1142,7 +1142,7 @@  discard block
 block discarded – undo
1142 1142
 				}
1143 1143
 			}
1144 1144
 		}
1145
-		if (is_array($query) && $op != 'AND') $query = $this->db->column_data_implode(' '.$op.' ',$query);
1145
+		if (is_array($query) && $op != 'AND') $query = $this->db->column_data_implode(' '.$op.' ', $query);
1146 1146
 		return $query;
1147 1147
 	}
1148 1148
 
@@ -1166,7 +1166,7 @@  discard block
 block discarded – undo
1166 1166
 		$matches = null;
1167 1167
 		if (substr($GLOBALS['egw']->db->Type, 0, 5) == 'mysql' || !preg_match('/(GROUP BY .*)(HAVING.*|ORDER BY.*)?$/iU', $group_by, $matches))
1168 1168
 		{
1169
-			return $group_by;	// nothing to do
1169
+			return $group_by; // nothing to do
1170 1170
 		}
1171 1171
 		$changes = 0;
1172 1172
 		$group_by_cols = preg_split('/, */', trim(substr($matches[1], 9)));
@@ -1176,9 +1176,9 @@  discard block
 block discarded – undo
1176 1176
 			$columns = preg_split('/, */', $columns);
1177 1177
 
1178 1178
 			// fix columns containing commas as part of function calls
1179
-			for($n = 0; $n < count($columns); ++$n)
1179
+			for ($n = 0; $n < count($columns); ++$n)
1180 1180
 			{
1181
-				$col =& $columns[$n];
1181
+				$col = & $columns[$n];
1182 1182
 				while (substr_count($col, '(') > substr_count($col, ')') && ++$n < count($columns))
1183 1183
 				{
1184 1184
 					$col .= ','.$columns[$n];
@@ -1187,7 +1187,7 @@  discard block
 block discarded – undo
1187 1187
 			}
1188 1188
 			unset($col);
1189 1189
 		}
1190
-		foreach($columns as $n => $col)
1190
+		foreach ($columns as $n => $col)
1191 1191
 		{
1192 1192
 			if ($col == '*')
1193 1193
 			{
@@ -1200,7 +1200,7 @@  discard block
 block discarded – undo
1200 1200
 			{
1201 1201
 				if (($pos = stripos($col, 'DISTINCT ')) !== false)
1202 1202
 				{
1203
-					$col = substr($col, $pos+9);
1203
+					$col = substr($col, $pos + 9);
1204 1204
 				}
1205 1205
 				$alias = $col;
1206 1206
 				if (stripos($col, ' AS ')) list($col, $alias) = preg_split('/ +AS +/i', $col);
@@ -1218,7 +1218,7 @@  discard block
 block discarded – undo
1218 1218
 		$ret = $group_by;
1219 1219
 		if ($changes)
1220 1220
 		{
1221
-			$ret = str_replace($matches[1], 'GROUP BY '.implode(',', $group_by_cols).' ',  $group_by);
1221
+			$ret = str_replace($matches[1], 'GROUP BY '.implode(',', $group_by_cols).' ', $group_by);
1222 1222
 			//error_log(__METHOD__."('$group_by', ".array2string($columns).") group_by_cols=".array2string($group_by_cols)." changed to $ret");
1223 1223
 		}
1224 1224
 		return $ret;
@@ -1238,12 +1238,12 @@  discard block
 block discarded – undo
1238 1238
 	 * @param array $search_cols =array() List of columns to search.  If not provided, all columns in $this->db_cols will be considered
1239 1239
 	 * @return array or column => value pairs
1240 1240
 	 */
1241
-	public function search2criteria($_pattern,&$wildcard='',&$op='AND',$extra_col=null, $search_cols = array())
1241
+	public function search2criteria($_pattern, &$wildcard = '', &$op = 'AND', $extra_col = null, $search_cols = array())
1242 1242
 	{
1243 1243
 		$pattern = trim($_pattern);
1244 1244
 		// This function can get called multiple times.  Make sure it doesn't re-process.
1245 1245
 		if (empty($pattern) || is_array($pattern)) return $pattern;
1246
-		if(strpos($pattern, 'CAST(COALESCE(') !== false)
1246
+		if (strpos($pattern, 'CAST(COALESCE(') !== false)
1247 1247
 		{
1248 1248
 			return $pattern;
1249 1249
 		}
@@ -1260,24 +1260,24 @@  discard block
 block discarded – undo
1260 1260
 		$numeric_columns = array();
1261 1261
 
1262 1262
 		// Special handling for an ID search, #<int>
1263
-		if(strpos($_pattern, '#') === 0 && is_numeric(substr($_pattern, 1)))
1263
+		if (strpos($_pattern, '#') === 0 && is_numeric(substr($_pattern, 1)))
1264 1264
 		{
1265
-			return array('(' . $this->table_name.'.'. $this->autoinc_id . '=' . (int)substr($_pattern,1) . ')');
1265
+			return array('('.$this->table_name.'.'.$this->autoinc_id.'='.(int)substr($_pattern, 1).')');
1266 1266
 		}
1267
-		if(!$search_cols)
1267
+		if (!$search_cols)
1268 1268
 		{
1269 1269
 			$search_cols = $this->get_default_search_columns();
1270 1270
 		}
1271 1271
 		// Concat all fields to be searched together, so the conditions operate across the whole record
1272
-		foreach($search_cols as $col)
1272
+		foreach ($search_cols as $col)
1273 1273
 		{
1274 1274
 			$col_name = $col;
1275 1275
 			$table = $this->table_name;
1276
-			if (strpos($col,'.') !== false)
1276
+			if (strpos($col, '.') !== false)
1277 1277
 			{
1278
-				list($table,$col_name) = explode('.',$col);
1278
+				list($table, $col_name) = explode('.', $col);
1279 1279
 			}
1280
-			$table_def = $table == $this->table_name ? $this->table_def : $this->db->get_table_definitions(true,$table);
1280
+			$table_def = $table == $this->table_name ? $this->table_def : $this->db->get_table_definitions(true, $table);
1281 1281
 			if ($table_def['fd'][$col_name] && in_array($table_def['fd'][$col_name]['type'], $numeric_types))
1282 1282
 			{
1283 1283
 				$numeric_columns[] = $col;
@@ -1285,11 +1285,11 @@  discard block
 block discarded – undo
1285 1285
 			}
1286 1286
 			if ($this->db->Type == 'mysql' && $table_def['fd'][$col_name]['type'] === 'ascii' && preg_match('/[\x80-\xFF]/', $_pattern))
1287 1287
 			{
1288
-				continue;	// will only give sql error
1288
+				continue; // will only give sql error
1289 1289
 			}
1290
-			$columns[] = sprintf($this->db->capabilities[Api\Db::CAPABILITY_CAST_AS_VARCHAR],"COALESCE($col,'')");
1290
+			$columns[] = sprintf($this->db->capabilities[Api\Db::CAPABILITY_CAST_AS_VARCHAR], "COALESCE($col,'')");
1291 1291
 		}
1292
-		if(!$columns)
1292
+		if (!$columns)
1293 1293
 		{
1294 1294
 			return array();
1295 1295
 		}
@@ -1298,9 +1298,9 @@  discard block
 block discarded – undo
1298 1298
 		$break = ' ';
1299 1299
 		$token = strtok($pattern, $break);
1300 1300
 
1301
-		while($token)
1301
+		while ($token)
1302 1302
 		{
1303
-			if($token == strtoupper(lang('AND')) || $token == 'AND')
1303
+			if ($token == strtoupper(lang('AND')) || $token == 'AND')
1304 1304
 			{
1305 1305
 				$token = '+'.strtok($break);
1306 1306
 			}
@@ -1313,10 +1313,10 @@  discard block
 block discarded – undo
1313 1313
 			{
1314 1314
 				$token = '-'.strtok($break);
1315 1315
 			}
1316
-			if ($token[0]=='"')
1316
+			if ($token[0] == '"')
1317 1317
 			{
1318
-				$token = substr($token, 1,strlen($token));
1319
- 				if(substr($token, -1) != '"')
1318
+				$token = substr($token, 1, strlen($token));
1319
+ 				if (substr($token, -1) != '"')
1320 1320
 				{
1321 1321
 					$token .= ' '.strtok('"');
1322 1322
 				}
@@ -1327,16 +1327,16 @@  discard block
 block discarded – undo
1327 1327
 			}
1328 1328
 
1329 1329
 			// prepend and append extra wildcard %, if pattern does NOT already contain wildcards
1330
-			if (strpos($token,'*') === false && strpos($token,'?') === false)
1330
+			if (strpos($token, '*') === false && strpos($token, '?') === false)
1331 1331
 			{
1332
-				$wildcard = '%';	// if pattern contains no wildcards, add them before AND after the pattern
1332
+				$wildcard = '%'; // if pattern contains no wildcards, add them before AND after the pattern
1333 1333
 			}
1334 1334
 			else
1335 1335
 			{
1336
-				$wildcard = '';		// no extra wildcard, if pattern already contains some
1336
+				$wildcard = ''; // no extra wildcard, if pattern already contains some
1337 1337
 			}
1338 1338
 
1339
-			switch($token[0])
1339
+			switch ($token[0])
1340 1340
 			{
1341 1341
 				case '+':
1342 1342
 					$op = 'AND';
@@ -1351,9 +1351,9 @@  discard block
 block discarded – undo
1351 1351
 					$op = 'OR';
1352 1352
 					break;
1353 1353
 			}
1354
-			$search_token = $wildcard.str_replace(array('%','_','*','?'),array('\\%','\\_','%','_'),$token).$wildcard;
1355
-			$token_filter = ' '.call_user_func_array(array($GLOBALS['egw']->db,'concat'),$columns).' '.
1356
-				$this->db->capabilities['case_insensitive_like'] . ' ' .
1354
+			$search_token = $wildcard.str_replace(array('%', '_', '*', '?'), array('\\%', '\\_', '%', '_'), $token).$wildcard;
1355
+			$token_filter = ' '.call_user_func_array(array($GLOBALS['egw']->db, 'concat'), $columns).' '.
1356
+				$this->db->capabilities['case_insensitive_like'].' '.
1357 1357
 				$GLOBALS['egw']->db->quote($search_token);
1358 1358
 
1359 1359
 			// if we have customfields and this is Api\Storage (not Api\Storage\Base)
@@ -1365,26 +1365,26 @@  discard block
 block discarded – undo
1365 1365
 
1366 1366
 			// Compare numeric token as equality for numeric columns
1367 1367
 			// skip user-wildcards (*,?) in is_numeric test, but not SQL wildcards, which get escaped and give sql-error
1368
-			if (is_numeric(str_replace(array('*','?'), '', $token)))
1368
+			if (is_numeric(str_replace(array('*', '?'), '', $token)))
1369 1369
 			{
1370 1370
 				$numeric_filter = array();
1371
-				foreach($numeric_columns as $col)
1371
+				foreach ($numeric_columns as $col)
1372 1372
 				{
1373
-					if($wildcard == '')
1373
+					if ($wildcard == '')
1374 1374
 					{
1375 1375
 						// Token has a wildcard from user, use LIKE
1376
-						$numeric_filter[] = "($col IS NOT NULL AND CAST($col AS CHAR) " .
1377
-							$this->db->capabilities['case_insensitive_like'] . ' ' .
1378
-							$GLOBALS['egw']->db->quote(str_replace(array('*','?'), array('%','_'), $token)) . ')';
1376
+						$numeric_filter[] = "($col IS NOT NULL AND CAST($col AS CHAR) ".
1377
+							$this->db->capabilities['case_insensitive_like'].' '.
1378
+							$GLOBALS['egw']->db->quote(str_replace(array('*', '?'), array('%', '_'), $token)).')';
1379 1379
 					}
1380 1380
 					else
1381 1381
 					{
1382 1382
 						$numeric_filter[] = "($col IS NOT NULL AND $col = $token)";
1383 1383
 					}
1384 1384
 				}
1385
-				if(count($numeric_filter) > 0)
1385
+				if (count($numeric_filter) > 0)
1386 1386
 				{
1387
-					$token_filter .= ' OR ' . implode(' OR ', $numeric_filter);
1387
+					$token_filter .= ' OR '.implode(' OR ', $numeric_filter);
1388 1388
 				}
1389 1389
 			}
1390 1390
 			$criteria[$op][] = '('.$token_filter.')';
@@ -1392,32 +1392,32 @@  discard block
 block discarded – undo
1392 1392
 			$token = strtok($break);
1393 1393
 		}
1394 1394
 
1395
-		if($criteria['NOT'])
1395
+		if ($criteria['NOT'])
1396 1396
 		{
1397
-			$filter[] = 'NOT (' . implode(' OR ', $criteria['NOT']) . ') ';
1397
+			$filter[] = 'NOT ('.implode(' OR ', $criteria['NOT']).') ';
1398 1398
 		}
1399
-		if($criteria['AND'])
1399
+		if ($criteria['AND'])
1400 1400
 		{
1401
-			$filter[] = implode(' AND ', $criteria['AND']) . ' ';
1401
+			$filter[] = implode(' AND ', $criteria['AND']).' ';
1402 1402
 		}
1403
-		if($criteria['OR'])
1403
+		if ($criteria['OR'])
1404 1404
 		{
1405
-			$filter[] = '(' . implode(' OR ', $criteria['OR']) . ') ';
1405
+			$filter[] = '('.implode(' OR ', $criteria['OR']).') ';
1406 1406
 		}
1407 1407
 
1408
-		if(count($filter))
1408
+		if (count($filter))
1409 1409
 		{
1410
-			$result = '(' . implode(' AND ', $filter) . ')';
1410
+			$result = '('.implode(' AND ', $filter).')';
1411 1411
 		}
1412 1412
 
1413 1413
 		// OR extra column on the end so a null or blank won't block a hit in the main columns
1414 1414
 		if ($extra_col)
1415 1415
 		{
1416
-			$result .= (strlen($result) ? ' OR ' : ' ') . "$extra_col = " . $GLOBALS['egw']->db->quote($pattern);
1416
+			$result .= (strlen($result) ? ' OR ' : ' ')."$extra_col = ".$GLOBALS['egw']->db->quote($pattern);
1417 1417
 		}
1418 1418
 
1419 1419
 		$op = 'OR';
1420
-		return array('(' . $result . ')');
1420
+		return array('('.$result.')');
1421 1421
 	}
1422 1422
 
1423 1423
 	/**
@@ -1436,21 +1436,21 @@  discard block
 block discarded – undo
1436 1436
 		$numeric_types = array('auto', 'int', 'float', 'double');
1437 1437
 
1438 1438
 		// Skip some numeric columns that don't make sense to search if we have to default to all columns
1439
-		if(is_null($this->columns_to_search))
1439
+		if (is_null($this->columns_to_search))
1440 1440
 		{
1441
-			foreach($search_cols as $key => &$col)
1441
+			foreach ($search_cols as $key => &$col)
1442 1442
 			{
1443 1443
 				// If the name as given isn't a real column name, and adding the prefix doesn't help, skip it
1444
-				if(!$this->table_def['fd'][$col] && !($col = $this->prefix.array_search($col, $search_cols))) {
1444
+				if (!$this->table_def['fd'][$col] && !($col = $this->prefix.array_search($col, $search_cols))) {
1445 1445
 					// Can't search this column
1446 1446
 					unset($search_cols[$key]);
1447 1447
 					continue;
1448 1448
 				}
1449
-				if(in_array($this->table_def['fd'][$col]['type'], $numeric_types))
1449
+				if (in_array($this->table_def['fd'][$col]['type'], $numeric_types))
1450 1450
 				{
1451
-					foreach($skip_columns_with as $bad)
1451
+					foreach ($skip_columns_with as $bad)
1452 1452
 					{
1453
-						if(strpos($col, $bad) !== false)
1453
+						if (strpos($col, $bad) !== false)
1454 1454
 						{
1455 1455
 							unset($search_cols[$key]);
1456 1456
 							continue 2;
@@ -1472,7 +1472,7 @@  discard block
 block discarded – undo
1472 1472
 	 * @param string|array $extra_cols ='' string or array of strings to be added to the SELECT, eg. "count(*) as num"
1473 1473
 	 * @return array with columns as db-name => internal-name pairs
1474 1474
 	 */
1475
-	function _get_columns($only_keys,$extra_cols)
1475
+	function _get_columns($only_keys, $extra_cols)
1476 1476
 	{
1477 1477
 		//echo "_get_columns() only_keys="; _debug_array($only_keys); echo "extra_cols="; _debug_array($extra_cols);
1478 1478
 		if ($only_keys === true)	// only primary key
@@ -1483,7 +1483,7 @@  discard block
 block discarded – undo
1483 1483
 		{
1484 1484
 			$cols = array();
1485 1485
 			$distinct_checked = false;
1486
-			foreach(is_array($only_keys) ? $only_keys : explode(',', $only_keys) as $col)
1486
+			foreach (is_array($only_keys) ? $only_keys : explode(',', $only_keys) as $col)
1487 1487
 			{
1488 1488
 				if (!$distinct_checked)
1489 1489
 				{
@@ -1492,17 +1492,17 @@  discard block
 block discarded – undo
1492 1492
 				}
1493 1493
 				if (!$col || $col == '*' || $col == $this->table_name.'.*')	// all columns
1494 1494
 				{
1495
-					$cols = array_merge($cols,$this->db_cols);
1495
+					$cols = array_merge($cols, $this->db_cols);
1496 1496
 				}
1497 1497
 				else	// only the specified columns
1498 1498
 				{
1499
-					if (stripos($col,'as'))	// if there's already an explicit naming of the column, just use it
1499
+					if (stripos($col, 'as'))	// if there's already an explicit naming of the column, just use it
1500 1500
 					{
1501
-						$col = preg_replace('/^.*as +([a-z0-9_]+) *$/i','\\1',$col);
1501
+						$col = preg_replace('/^.*as +([a-z0-9_]+) *$/i', '\\1', $col);
1502 1502
 						$cols[$col] = $col;
1503 1503
 						continue;
1504 1504
 					}
1505
-					if (($db_col = array_search($col,$this->db_cols)) !== false)
1505
+					if (($db_col = array_search($col, $this->db_cols)) !== false)
1506 1506
 					{
1507 1507
 						$cols[$db_col] = $col;
1508 1508
 					}
@@ -1515,10 +1515,10 @@  discard block
 block discarded – undo
1515 1515
 		}
1516 1516
 		if ($extra_cols)	// extra columns to report
1517 1517
 		{
1518
-			foreach(is_array($extra_cols) ? $extra_cols : explode(',',$extra_cols) as $col)
1518
+			foreach (is_array($extra_cols) ? $extra_cols : explode(',', $extra_cols) as $col)
1519 1519
 			{
1520
-				if (stripos($col,'as ')!==false) $col = preg_replace('/^.*as +([a-z0-9_]+) *$/i','\\1',$col);
1521
-				if (($db_col = array_search($col,$this->db_cols)) !== false)
1520
+				if (stripos($col, 'as ') !== false) $col = preg_replace('/^.*as +([a-z0-9_]+) *$/i', '\\1', $col);
1521
+				if (($db_col = array_search($col, $this->db_cols)) !== false)
1522 1522
 				{
1523 1523
 					$cols[$db_col] = $col;
1524 1524
 				}
@@ -1545,12 +1545,12 @@  discard block
 block discarded – undo
1545 1545
 	 * @param string|array $extra_cols =array()
1546 1546
 	 * @return int total number of rows
1547 1547
 	 */
1548
-	function get_rows($query,&$rows,&$readonlys,$join='',$need_full_no_count=false,$only_keys=false,$extra_cols=array())
1548
+	function get_rows($query, &$rows, &$readonlys, $join = '', $need_full_no_count = false, $only_keys = false, $extra_cols = array())
1549 1549
 	{
1550
-		unset($readonlys);	// required by function signature, but not used in this default implementation
1551
-		if ((int) $this->debug >= 4)
1550
+		unset($readonlys); // required by function signature, but not used in this default implementation
1551
+		if ((int)$this->debug >= 4)
1552 1552
 		{
1553
-			echo "<p>so_sql::get_rows(".print_r($query,true).",,)</p>\n";
1553
+			echo "<p>so_sql::get_rows(".print_r($query, true).",,)</p>\n";
1554 1554
 		}
1555 1555
 		$criteria = array();
1556 1556
 		$op = 'AND';
@@ -1558,11 +1558,11 @@  discard block
 block discarded – undo
1558 1558
 		{
1559 1559
 			$criteria = $query['search'];
1560 1560
 		}
1561
-		$rows = $this->search($criteria,$only_keys,$query['order']?$query['order'].' '.$query['sort']:'',$extra_cols,
1562
-			'',false,$op,$query['num_rows']?array((int)$query['start'],$query['num_rows']):(int)$query['start'],
1563
-			$query['col_filter'],$join,$need_full_no_count);
1561
+		$rows = $this->search($criteria, $only_keys, $query['order'] ? $query['order'].' '.$query['sort'] : '', $extra_cols,
1562
+			'', false, $op, $query['num_rows'] ? array((int)$query['start'], $query['num_rows']) : (int)$query['start'],
1563
+			$query['col_filter'], $join, $need_full_no_count);
1564 1564
 
1565
-		if (!$rows) $rows = array();	// otherwise false returned from search would be returned as array(false)
1565
+		if (!$rows) $rows = array(); // otherwise false returned from search would be returned as array(false)
1566 1566
 
1567 1567
 		return $this->total;
1568 1568
 	}
@@ -1573,7 +1573,7 @@  discard block
 block discarded – undo
1573 1573
 	 * @param array $data =null data-set to check, defaults to $this->data
1574 1574
 	 * @return int 0: all keys are unique, 1: first key not unique, 2: ...
1575 1575
 	 */
1576
-	function not_unique($data=null)
1576
+	function not_unique($data = null)
1577 1577
 	{
1578 1578
 		if (!is_array($data))
1579 1579
 		{
@@ -1586,12 +1586,12 @@  discard block
 block discarded – undo
1586 1586
 		{
1587 1587
 			$uni_keys[] = $this->db_key_cols;
1588 1588
 		}
1589
-		foreach($uni_keys as $db_col => $col)
1589
+		foreach ($uni_keys as $db_col => $col)
1590 1590
 		{
1591 1591
 			if (is_array($col))
1592 1592
 			{
1593 1593
 				$query = array();
1594
-				foreach($col as $db_c => $c)
1594
+				foreach ($col as $db_c => $c)
1595 1595
 				{
1596 1596
 					$query[$db_c] = $data[$c];
1597 1597
 				}
@@ -1600,17 +1600,17 @@  discard block
 block discarded – undo
1600 1600
 			{
1601 1601
 				$query = array($db_col => $data[$col]);
1602 1602
 			}
1603
-			foreach($this->db->select($this->table_name,$this->db_key_cols,$query,__LINE__,__FILE__,false,'',$this->app) as $other)
1603
+			foreach ($this->db->select($this->table_name, $this->db_key_cols, $query, __LINE__, __FILE__, false, '', $this->app) as $other)
1604 1604
 			{
1605
-				foreach($this->db_key_cols as $key_col)
1605
+				foreach ($this->db_key_cols as $key_col)
1606 1606
 				{
1607 1607
 					if ($data[$key_col] != $other[$key_col])
1608 1608
 					{
1609
-						if ((int) $this->debug >= 4)
1609
+						if ((int)$this->debug >= 4)
1610 1610
 						{
1611 1611
 							echo "<p>not_unique in ".array2string($col)." as for '$key_col': '${data[$key_col]}' != '${other[$key_col]}'</p>\n";
1612 1612
 						}
1613
-						return $n;	// different entry => $n not unique
1613
+						return $n; // different entry => $n not unique
1614 1614
 					}
1615 1615
 				}
1616 1616
 			}
@@ -1631,7 +1631,7 @@  discard block
 block discarded – undo
1631 1631
 	 * @param string $order ='' order, default '' = same as (first) $value_col
1632 1632
 	 * @return array with key_col => value_col pairs or array if more then one value_col given (keys as in value_col)
1633 1633
 	 */
1634
-	function query_list($value_col,$key_col='',$filter=array(),$order='')
1634
+	function query_list($value_col, $key_col = '', $filter = array(), $order = '')
1635 1635
 	{
1636 1636
 		static $cache = array();
1637 1637
 
@@ -1644,16 +1644,16 @@  discard block
 block discarded – undo
1644 1644
 		if (!is_array($value_col)) $value_col = array($value_col);
1645 1645
 
1646 1646
 		$cols = $ret = array();
1647
-		foreach($value_col as $key => $col)
1647
+		foreach ($value_col as $key => $col)
1648 1648
 		{
1649 1649
 			$matches = null;
1650
-			$cols[$key] = preg_match('/AS ([a-z_0-9]+)$/i',$col,$matches) ? $matches[1] : $col;
1650
+			$cols[$key] = preg_match('/AS ([a-z_0-9]+)$/i', $col, $matches) ? $matches[1] : $col;
1651 1651
 		}
1652 1652
 		if (!$order) $order = current($cols);
1653 1653
 
1654
-		if (($search =& $this->search(array(),($key_col ? $key_col.',' : 'DISTINCT ').implode(',',$value_col),$order,'','',false,'AND',false,$filter)))
1654
+		if (($search = & $this->search(array(), ($key_col ? $key_col.',' : 'DISTINCT ').implode(',', $value_col), $order, '', '', false, 'AND', false, $filter)))
1655 1655
 		{
1656
-			if (preg_match('/AS ([a-z_0-9]+)$/i',$key_col,$matches))
1656
+			if (preg_match('/AS ([a-z_0-9]+)$/i', $key_col, $matches))
1657 1657
 			{
1658 1658
 				$key_col = $matches[1];
1659 1659
 			}
@@ -1661,12 +1661,12 @@  discard block
 block discarded – undo
1661 1661
 			{
1662 1662
 				$key_col = current($cols);
1663 1663
 			}
1664
-			foreach($search as $row)
1664
+			foreach ($search as $row)
1665 1665
 			{
1666 1666
 				if (count($cols) > 1)
1667 1667
 				{
1668 1668
 					$data = array();
1669
-					foreach($cols as $key => $col)
1669
+					foreach ($cols as $key => $col)
1670 1670
 					{
1671 1671
 						$data[$key] = $row[$col];
1672 1672
 					}
@@ -1678,7 +1678,7 @@  discard block
 block discarded – undo
1678 1678
 				if ($data) $ret[$row[$key_col]] = $data;
1679 1679
 			}
1680 1680
 		}
1681
-		return $cache[$cache_key] =& $ret;
1681
+		return $cache[$cache_key] = & $ret;
1682 1682
 	}
1683 1683
 
1684 1684
 	/**
@@ -1687,13 +1687,13 @@  discard block
 block discarded – undo
1687 1687
 	 * @param string $column =null name of column or null for all (default)
1688 1688
 	 * @return array|string array with internal-name => comment pairs, or string with comment, if $column given
1689 1689
 	 */
1690
-	public function get_comments($column=null)
1690
+	public function get_comments($column = null)
1691 1691
 	{
1692
-		static $comments=null;
1692
+		static $comments = null;
1693 1693
 
1694 1694
 		if (is_null($comments))
1695 1695
 		{
1696
-			foreach($this->db_cols as $db_col => $col)
1696
+			foreach ($this->db_cols as $db_col => $col)
1697 1697
 			{
1698 1698
 				$comments[$col] = $this->table_def['fd'][$db_col]['comment'];
1699 1699
 			}
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1063,7 +1063,7 @@
 block discarded – undo
1063 1063
 	 * @return Array
1064 1064
 	 * @throws Api\Db\Exception
1065 1065
 	 */
1066
-	protected function parse_search(Array $_criteria, $wildcard, $empty, $op)
1066
+	protected function parse_search(array $_criteria, $wildcard, $empty, $op)
1067 1067
 	{
1068 1068
 		$criteria = $this->data2db($_criteria);
1069 1069
 		foreach($criteria as $col => $val)
Please login to merge, or discard this patch.
api/src/Storage/Base2.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -53,9 +53,9 @@  discard block
 block discarded – undo
53 53
 	 *
54 54
 	 * @return so_sql2
55 55
 	 */
56
-	function __construct($app='',$table='',Api\Db $db=null,$column_prefix='',$no_clone=false)
56
+	function __construct($app = '', $table = '', Api\Db $db = null, $column_prefix = '', $no_clone = false)
57 57
 	{
58
-		parent::__construct($app,$table,$db,$column_prefix,$no_clone);
58
+		parent::__construct($app, $table, $db, $column_prefix, $no_clone);
59 59
 	}
60 60
 
61 61
 	/**
@@ -68,13 +68,13 @@  discard block
 block discarded – undo
68 68
 	 */
69 69
 	function __get($property)
70 70
 	{
71
-		switch($property)
71
+		switch ($property)
72 72
 		{
73 73
 			case 'id':
74 74
 				$property = $this->autoinc_id;
75 75
 				break;
76 76
 		}
77
-		if (in_array($property,$this->db_cols) || in_array($property,$this->non_db_cols))
77
+		if (in_array($property, $this->db_cols) || in_array($property, $this->non_db_cols))
78 78
 		{
79 79
 			return $this->data[$property];
80 80
 		}
@@ -88,15 +88,15 @@  discard block
 block discarded – undo
88 88
 	 * @param string $property
89 89
 	 * @param mixed $value
90 90
 	 */
91
-	function __set($property,$value)
91
+	function __set($property, $value)
92 92
 	{
93
-		switch($property)
93
+		switch ($property)
94 94
 		{
95 95
 			case 'id':
96 96
 				$property = $this->autoinc_id;
97 97
 				break;
98 98
 		}
99
-		if (in_array($property,$this->db_cols) || in_array($property,$this->non_db_cols))
99
+		if (in_array($property, $this->db_cols) || in_array($property, $this->non_db_cols))
100 100
 		{
101 101
 			$this->data[$property] = $value;
102 102
 		}
Please login to merge, or discard this patch.
api/src/Exception/NoPermission/App.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class App extends Exception\NoPermission
23 23
 {
24
-	function __construct($msg=null,$code=101)
24
+	function __construct($msg = null, $code = 101)
25 25
 	{
26 26
 		if (isset($GLOBALS['egw_info']['apps'][$msg]))
27 27
 		{
@@ -39,6 +39,6 @@  discard block
 block discarded – undo
39 39
 						'"'.$app.'"');
40 40
 			}
41 41
 		}
42
-		parent::__construct($msg,$code);
42
+		parent::__construct($msg, $code);
43 43
 	}
44 44
 }
Please login to merge, or discard this patch.
api/src/Exception/NotFound.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -26,10 +26,10 @@
 block discarded – undo
26 26
 	 * @param string $msg =null message, default "Entry not found!"
27 27
 	 * @param int $code =99 numerical code, default 2
28 28
 	 */
29
-	function __construct($msg=null,$code=2)
29
+	function __construct($msg = null, $code = 2)
30 30
 	{
31 31
 		if (is_null($msg)) $msg = lang('Entry not found!');
32 32
 
33
-		parent::__construct($msg,$code);
33
+		parent::__construct($msg, $code);
34 34
 	}
35 35
 }
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -28,7 +28,10 @@
 block discarded – undo
28 28
 	 */
29 29
 	function __construct($msg=null,$code=2)
30 30
 	{
31
-		if (is_null($msg)) $msg = lang('Entry not found!');
31
+		if (is_null($msg))
32
+		{
33
+			$msg = lang('Entry not found!');
34
+		}
32 35
 
33 36
 		parent::__construct($msg,$code);
34 37
 	}
Please login to merge, or discard this patch.
api/src/Exception/Redirect.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@
 block discarded – undo
33 33
 	 * @param string $msg
34 34
 	 * @param int $code
35 35
 	 */
36
-	function __construct($url,$app=null,$msg=null,$code=301)
36
+	function __construct($url, $app = null, $msg = null, $code = 301)
37 37
 	{
38 38
 		$this->url = $url;
39 39
 		$this->app = $app;
Please login to merge, or discard this patch.