Completed
Push — master ( 051531...5a7c65 )
by Nathan
18:36
created
api/src/Mail/Html.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -227,7 +227,7 @@
 block discarded – undo
227 227
 	 * @param string $displayCharset : charset to use; should be a valid charset
228 228
 	 * @param bool $stripcrl :  flag to indicate for the removal of all crlf \r\n
229 229
 	 * @param bool $stripalltags : flag to indicate wether or not to strip $_html from all remaining tags
230
-	 * @return text $_html : the modified text.
230
+	 * @return string $_html : the modified text.
231 231
 	 */
232 232
 	static function convertHTMLToText($_html,$displayCharset=false,$stripcrl=false,$stripalltags=true)
233 233
 	{
Please login to merge, or discard this patch.
Spacing   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -28,17 +28,17 @@  discard block
 block discarded – undo
28 28
 	 * @param integer $reclevel param to control recursive calls (to prevent endless recursion)
29 29
 	 * @return string
30 30
 	 */
31
-	static function decodeMailHeader($_string, $displayCharset='utf-8', $reclevel=0)
31
+	static function decodeMailHeader($_string, $displayCharset = 'utf-8', $reclevel = 0)
32 32
 	{
33
-		$maxreclevel=25;
33
+		$maxreclevel = 25;
34 34
 		if ($reclevel > $maxreclevel) {
35
-			error_log( __METHOD__.__LINE__." Recursion Level Exeeded ($reclevel) while decoding $_string ");
35
+			error_log(__METHOD__.__LINE__." Recursion Level Exeeded ($reclevel) while decoding $_string ");
36 36
 			return $_string;
37 37
 		}
38 38
 		$reclevel++;
39 39
 
40 40
 		//error_log(__FILE__.','.__METHOD__.':'."called with $_string and CHARSET $displayCharset");
41
-		if(function_exists('imap_mime_header_decode'))
41
+		if (function_exists('imap_mime_header_decode'))
42 42
 		{
43 43
 			// some characterreplacements, as they fail to translate
44 44
 			$sar = array(
@@ -60,20 +60,20 @@  discard block
 block discarded – undo
60 60
 
61 61
 			$convertAtEnd = false;
62 62
 			$string = '';
63
-			foreach((array)$elements as $element)
63
+			foreach ((array)$elements as $element)
64 64
 			{
65 65
 				if ($element->charset == 'default') $element->charset = Api\Translation::detect_encoding($element->text);
66 66
 				if ($element->charset != 'x-unknown')
67 67
 				{
68
-					if( strtoupper($element->charset) != 'UTF-8') $element->text = preg_replace($sar,$rar,$element->text);
68
+					if (strtoupper($element->charset) != 'UTF-8') $element->text = preg_replace($sar, $rar, $element->text);
69 69
 					// check if there is a possible nested encoding; make sure that the inputstring and the decoded result are different to avoid loops
70
-					$openTags = substr_count($element->text,'?=');
71
-					if(preg_match('/\?=.+=\?/', $element->text) && $openTags>0 && $openTags==substr_count($element->text,'=?') && $element->text != $_string)
70
+					$openTags = substr_count($element->text, '?=');
71
+					if (preg_match('/\?=.+=\?/', $element->text) && $openTags > 0 && $openTags == substr_count($element->text, '=?') && $element->text != $_string)
72 72
 					{
73 73
 						$element->text = self::decodeMailHeader($element->text, $element->charset, $reclevel);
74 74
 						$element->charset = $displayCharset;
75 75
 					}
76
-					$string .= Api\Translation::convert($element->text,$element->charset);
76
+					$string .= Api\Translation::convert($element->text, $element->charset);
77 77
 				}
78 78
 				else
79 79
 				{
@@ -83,22 +83,22 @@  discard block
 block discarded – undo
83 83
 			}
84 84
 			if ($convertAtEnd) $string = self::decodeMailHeader($string, $displayCharset, $reclevel);
85 85
 		}
86
-		elseif(function_exists(mb_decode_mimeheader))
86
+		elseif (function_exists(mb_decode_mimeheader))
87 87
 		{
88 88
 			$matches = null;
89
-			if(preg_match_all('/=\?.*\?Q\?.*\?=/iU', $string=$_string, $matches))
89
+			if (preg_match_all('/=\?.*\?Q\?.*\?=/iU', $string = $_string, $matches))
90 90
 			{
91
-				foreach($matches[0] as $match)
91
+				foreach ($matches[0] as $match)
92 92
 				{
93 93
 					$fixedMatch = str_replace('_', ' ', $match);
94 94
 					$string = str_replace($match, $fixedMatch, $string);
95 95
 				}
96
-				$string = str_replace('=?ISO8859-','=?ISO-8859-',
97
-					str_replace('=?windows-1258','=?ISO-8859-1',$string));
96
+				$string = str_replace('=?ISO8859-', '=?ISO-8859-',
97
+					str_replace('=?windows-1258', '=?ISO-8859-1', $string));
98 98
 			}
99 99
 			$string = mb_decode_mimeheader($string);
100 100
 		}
101
-		elseif(function_exists(iconv_mime_decode))
101
+		elseif (function_exists(iconv_mime_decode))
102 102
 		{
103 103
 			// continue decoding also if an error occurs
104 104
 			$string = @iconv_mime_decode($_string, 2, $displayCharset);
@@ -122,15 +122,15 @@  discard block
 block discarded – undo
122 122
 	{
123 123
 		//error_log($text);
124 124
 		//replace CRLF with something other to be preserved via preg_replace as CRLF seems to vanish
125
-		$text2 = str_replace("\r\n",'<#cr-lf#>',$text);
125
+		$text2 = str_replace("\r\n", '<#cr-lf#>', $text);
126 126
 			// replace emailaddresses eclosed in <> (eg.: <[email protected]>) with the emailaddress only (e.g: [email protected])
127
-		$text3 = preg_replace("/(<|&lt;a href=\")*(mailto:([\w\.,-.,_.,0-9.]+)(@)([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","$2 ", $text2);
127
+		$text3 = preg_replace("/(<|&lt;a href=\")*(mailto:([\w\.,-.,_.,0-9.]+)(@)([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i", "$2 ", $text2);
128 128
 		//$text = preg_replace_callback("/(<|&lt;a href=\")*(mailto:([\w\.,-.,_.,0-9.]+)(@)([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i",'self::transform_mailto2text',$text);
129 129
 		//$text = preg_replace('~<a[^>]+href=\"(mailto:)+([^"]+)\"[^>]*>~si','$2 ',$text);
130
-		$text4 = preg_replace_callback('~<a[^>]+href=\"(mailto:)+([^"]+)\"[^>]*>([ @\w\.,-.,_.,0-9.]+)<\/a>~si','self::transform_mailto2text',$text3);
131
-		$text5 = preg_replace("/(([\w\.,-.,_.,0-9.]+)(@)([\w\.,-.,_.,0-9.]+))( |\s)*(<\/a>)*( |\s)*(>|&gt;)*/i","$1 ", $text4);
132
-		$text6 = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","$2 ", $text5);
133
-		$text = str_replace('<#cr-lf#>',"\r\n",$text6);
130
+		$text4 = preg_replace_callback('~<a[^>]+href=\"(mailto:)+([^"]+)\"[^>]*>([ @\w\.,-.,_.,0-9.]+)<\/a>~si', 'self::transform_mailto2text', $text3);
131
+		$text5 = preg_replace("/(([\w\.,-.,_.,0-9.]+)(@)([\w\.,-.,_.,0-9.]+))( |\s)*(<\/a>)*( |\s)*(>|&gt;)*/i", "$1 ", $text4);
132
+		$text6 = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i", "$2 ", $text5);
133
+		$text = str_replace('<#cr-lf#>', "\r\n", $text6);
134 134
 		return 1;
135 135
 	}
136 136
 
@@ -144,11 +144,11 @@  discard block
 block discarded – undo
144 144
 	 *				or if you want the string to be matched as is
145 145
 	 * @return void the modified text is passed via reference
146 146
 	 */
147
-	static function replaceTagsCompletley(&$_body,$tag,$endtag='',$addbracesforendtag=true)
147
+	static function replaceTagsCompletley(&$_body, $tag, $endtag = '', $addbracesforendtag = true)
148 148
 	{
149 149
 		if ($tag) $tag = strtolower($tag);
150 150
 		$singleton = false;
151
-		if ($endtag=='/>') $singleton =true;
151
+		if ($endtag == '/>') $singleton = true;
152 152
 		if ($endtag == '' || empty($endtag) || !isset($endtag))
153 153
 		{
154 154
 			$endtag = $tag;
@@ -161,31 +161,31 @@  discard block
 block discarded – undo
161 161
 			if ($singleton)
162 162
 			{
163 163
 				//$_body = preg_replace('~<'.$tag.'[^>].*? '.$endtag.'~simU','',$_body);
164
-				$_body = preg_replace('~<?'.$tag.'[^>].* '.$endtag.'~simU','',$_body); // we are in Ungreedy mode, so we expect * to be ungreedy without specifying ?
164
+				$_body = preg_replace('~<?'.$tag.'[^>].* '.$endtag.'~simU', '', $_body); // we are in Ungreedy mode, so we expect * to be ungreedy without specifying ?
165 165
 			}
166 166
 			else
167 167
 			{
168
-				$found=null;
169
-				if ($addbracesforendtag === true )
168
+				$found = null;
169
+				if ($addbracesforendtag === true)
170 170
 				{
171
-					if (stripos($_body,'<'.$tag)!==false)  $ct = preg_match_all('#<'.$tag.'(?:\s.*)?>(.+)</'.$endtag.'>#isU', $_body, $found);
172
-					if ($ct>0)
171
+					if (stripos($_body, '<'.$tag) !== false)  $ct = preg_match_all('#<'.$tag.'(?:\s.*)?>(.+)</'.$endtag.'>#isU', $_body, $found);
172
+					if ($ct > 0)
173 173
 					{
174 174
 						//error_log(__METHOD__.__LINE__.array2string($found[0]));
175 175
 						// only replace what we have found
176
-						$_body = str_ireplace($found[0],'',$_body);
176
+						$_body = str_ireplace($found[0], '', $_body);
177 177
 					}
178 178
 					// remove left over tags, unfinished ones, and so on
179
-					$_body = preg_replace('~<'.$tag.'[^>]*?>~si','',$_body);
179
+					$_body = preg_replace('~<'.$tag.'[^>]*?>~si', '', $_body);
180 180
 				}
181
-				if ($addbracesforendtag === false )
181
+				if ($addbracesforendtag === false)
182 182
 				{
183
-					if (stripos($_body,'<'.$tag)!==false)  $ct = preg_match_all('#<'.$tag.'(?:\s.*)?>(.+)'.$endtag.'#isU', $_body, $found);
184
-					if ($ct>0)
183
+					if (stripos($_body, '<'.$tag) !== false)  $ct = preg_match_all('#<'.$tag.'(?:\s.*)?>(.+)'.$endtag.'#isU', $_body, $found);
184
+					if ($ct > 0)
185 185
 					{
186 186
 						//error_log(__METHOD__.__LINE__.array2string($found[0]));
187 187
 						// only replace what we have found
188
-						$_body = str_ireplace($found[0],'',$_body);
188
+						$_body = str_ireplace($found[0], '', $_body);
189 189
 					}
190 190
 /*
191 191
 					$_body = preg_replace('~<'.$tag.'[^>]*?>(.*?)'.$endtag.'~simU','',$_body);
@@ -203,9 +203,9 @@  discard block
 block discarded – undo
203 203
 		// this is the actual url
204 204
 		$matches[2] = trim(strip_tags($matches[2]));
205 205
 		$matches[3] = trim(strip_tags($matches[3]));
206
-		$matches[2] = str_replace(array('%40','%20'),array('@',' '),$matches[2]);
207
-		$matches[3] = str_replace(array('%40','%20'),array('@',' '),$matches[3]);
208
-		return $matches[1].$matches[2].($matches[2]==$matches[3]?' ':' -> '.$matches[3].' ');
206
+		$matches[2] = str_replace(array('%40', '%20'), array('@', ' '), $matches[2]);
207
+		$matches[3] = str_replace(array('%40', '%20'), array('@', ' '), $matches[3]);
208
+		return $matches[1].$matches[2].($matches[2] == $matches[3] ? ' ' : ' -> '.$matches[3].' ');
209 209
 	}
210 210
 
211 211
 	static function transform_url2text($matches)
@@ -214,9 +214,9 @@  discard block
 block discarded – undo
214 214
 		$linkTextislink = false;
215 215
 		// this is the actual url
216 216
 		$matches[2] = trim(strip_tags($matches[2]));
217
-		if ($matches[2]==$matches[1]) $linkTextislink = true;
218
-		$matches[1] = str_replace(' ','%20',$matches[1]);
219
-		return ($linkTextislink?' ':'[ ').$matches[1].($linkTextislink?'':' -> '.$matches[2]).($linkTextislink?' ':' ]');
217
+		if ($matches[2] == $matches[1]) $linkTextislink = true;
218
+		$matches[1] = str_replace(' ', '%20', $matches[1]);
219
+		return ($linkTextislink ? ' ' : '[ ').$matches[1].($linkTextislink ? '' : ' -> '.$matches[2]).($linkTextislink ? ' ' : ' ]');
220 220
 	}
221 221
 
222 222
 	/**
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 	 * @param bool $stripalltags : flag to indicate wether or not to strip $_html from all remaining tags
228 228
 	 * @return text $_html : the modified text.
229 229
 	 */
230
-	static function convertHTMLToText($_html,$displayCharset=false,$stripcrl=false,$stripalltags=true)
230
+	static function convertHTMLToText($_html, $displayCharset = false, $stripcrl = false, $stripalltags = true)
231 231
 	{
232 232
 		// assume input isHTML, but test the input anyway, because,
233 233
 		// if it is not, we may not want to strip whitespace
@@ -243,27 +243,27 @@  discard block
 block discarded – undo
243 243
 		#print "<pre>"; print htmlspecialchars($_html);
244 244
 		#print "</pre>";
245 245
 		#print "<hr>";
246
-		if (stripos($_html,'style')!==false) self::replaceTagsCompletley($_html,'style'); // clean out empty or pagewide style definitions / left over tags
247
-		if (stripos($_html,'head')!==false) self::replaceTagsCompletley($_html,'head'); // Strip out stuff in head
248
-		if (stripos($_html,'![if')!==false && stripos($_html,'<![endif]>')!==false) self::replaceTagsCompletley($_html,'!\[if','<!\[endif\]>',false); // Strip out stuff in ifs
249
-		if (stripos($_html,'!--[if')!==false && stripos($_html,'<![endif]-->')!==false) self::replaceTagsCompletley($_html,'!--\[if','<!\[endif\]-->',false); // Strip out stuff in ifs
250
-		$Rules = array ('@<script[^>]*?>.*?</script>@siU', // Strip out javascript
251
-			'@&(quot|#34);@i',                // Replace HTML entities
252
-			'@&(amp|#38);@i',                 //   Ampersand &
253
-			'@&(lt|#60);@i',                  //   Less Than <
254
-			'@&(gt|#62);@i',                  //   Greater Than >
255
-			'@&(nbsp|#160);@i',               //   Non Breaking Space
256
-			'@&(iexcl|#161);@i',              //   Inverted Exclamation point
257
-			'@&(cent|#162);@i',               //   Cent
258
-			'@&(pound|#163);@i',              //   Pound
259
-			'@&(copy|#169);@i',               //   Copyright
260
-			'@&(reg|#174);@i',                //   Registered
261
-			'@&(trade|#8482);@i',             //   trade
262
-			'@&#39;@i',                       //   singleQuote
263
-			'@(\xc2\xa0)@',                   //   nbsp or tab (encoded windows-style)
264
-			'@(\xe2\x80\x8b)@',               //   ZERO WIDTH SPACE
246
+		if (stripos($_html, 'style') !== false) self::replaceTagsCompletley($_html, 'style'); // clean out empty or pagewide style definitions / left over tags
247
+		if (stripos($_html, 'head') !== false) self::replaceTagsCompletley($_html, 'head'); // Strip out stuff in head
248
+		if (stripos($_html, '![if') !== false && stripos($_html, '<![endif]>') !== false) self::replaceTagsCompletley($_html, '!\[if', '<!\[endif\]>', false); // Strip out stuff in ifs
249
+		if (stripos($_html, '!--[if') !== false && stripos($_html, '<![endif]-->') !== false) self::replaceTagsCompletley($_html, '!--\[if', '<!\[endif\]-->', false); // Strip out stuff in ifs
250
+		$Rules = array('@<script[^>]*?>.*?</script>@siU', // Strip out javascript
251
+			'@&(quot|#34);@i', // Replace HTML entities
252
+			'@&(amp|#38);@i', //   Ampersand &
253
+			'@&(lt|#60);@i', //   Less Than <
254
+			'@&(gt|#62);@i', //   Greater Than >
255
+			'@&(nbsp|#160);@i', //   Non Breaking Space
256
+			'@&(iexcl|#161);@i', //   Inverted Exclamation point
257
+			'@&(cent|#162);@i', //   Cent
258
+			'@&(pound|#163);@i', //   Pound
259
+			'@&(copy|#169);@i', //   Copyright
260
+			'@&(reg|#174);@i', //   Registered
261
+			'@&(trade|#8482);@i', //   trade
262
+			'@&#39;@i', //   singleQuote
263
+			'@(\xc2\xa0)@', //   nbsp or tab (encoded windows-style)
264
+			'@(\xe2\x80\x8b)@', //   ZERO WIDTH SPACE
265 265
 		);
266
-		$Replace = array ('',
266
+		$Replace = array('',
267 267
 			'"',
268 268
 			'#amper#sand#',
269 269
 			'<',
@@ -272,9 +272,9 @@  discard block
 block discarded – undo
272 272
 			chr(161),
273 273
 			chr(162),
274 274
 			chr(163),
275
-			'(C)',//chr(169),// copyrighgt
276
-			'(R)',//chr(174),// registered
277
-			'(TM)',// trade
275
+			'(C)', //chr(169),// copyrighgt
276
+			'(R)', //chr(174),// registered
277
+			'(TM)', // trade
278 278
 			"'",
279 279
 			' ',
280 280
 			'',
@@ -282,27 +282,27 @@  discard block
 block discarded – undo
282 282
 		$_html = preg_replace($Rules, $Replace, $_html);
283 283
 
284 284
 		//   removing carriage return linefeeds, preserve those enclosed in <pre> </pre> tags
285
-		if ($stripcrl === true )
285
+		if ($stripcrl === true)
286 286
 		{
287
-			if (stripos($_html,'<pre ')!==false || stripos($_html,'<pre>')!==false)
287
+			if (stripos($_html, '<pre ') !== false || stripos($_html, '<pre>') !== false)
288 288
 			{
289 289
 				$contentArr = self::splithtmlByPRE($_html);
290 290
 				foreach ($contentArr as $k =>&$elem)
291 291
 				{
292
-					if (stripos($elem,'<pre ')===false && stripos($elem,'<pre>')===false)
292
+					if (stripos($elem, '<pre ') === false && stripos($elem, '<pre>') === false)
293 293
 					{
294 294
 						//$elem = str_replace('@(\r\n)@i',' ',$elem);
295
-						$elem = str_replace(array("\r\n","\n"),($isHTML?'':' '),$elem);
295
+						$elem = str_replace(array("\r\n", "\n"), ($isHTML ? '' : ' '), $elem);
296 296
 					}
297 297
 				}
298
-				$_html = implode('',$contentArr);
298
+				$_html = implode('', $contentArr);
299 299
 			}
300 300
 			else
301 301
 			{
302
-				$_html = str_replace(array("\r\n","\n"),($isHTML?'':' '),$_html);
302
+				$_html = str_replace(array("\r\n", "\n"), ($isHTML ? '' : ' '), $_html);
303 303
 			}
304 304
 		}
305
-		$tags = array (
305
+		$tags = array(
306 306
 			0 => '~<h[123][^>]*>\r*\n*~si',
307 307
 			1 => '~<h[456][^>]*>\r*\n*~si',
308 308
 			2 => '~<table[^>]*>\r*\n*~si',
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
 			17 => '/<\s([1234567890])/',
324 324
 			18 => '/>\s([1234567890])/',
325 325
 		);
326
-		$Replace = array (
326
+		$Replace = array(
327 327
 			0 => "\r\n",
328 328
 			1 => "\r\n",
329 329
 			2 => "\r\n",
@@ -344,112 +344,112 @@  discard block
 block discarded – undo
344 344
 			17 => '#lower#than#$1',
345 345
 			18 => '#greater#than#$1',
346 346
 		);
347
-		$_html = preg_replace($tags,$Replace,$_html);
348
-		$_html = preg_replace('~</t(d|h)>\s*<t(d|h)[^>]*>~si',' - ',$_html);
349
-		$_html = preg_replace('~<img[^>]+>~s','',$_html);
347
+		$_html = preg_replace($tags, $Replace, $_html);
348
+		$_html = preg_replace('~</t(d|h)>\s*<t(d|h)[^>]*>~si', ' - ', $_html);
349
+		$_html = preg_replace('~<img[^>]+>~s', '', $_html);
350 350
 		// replace emailaddresses eclosed in <> (eg.: <[email protected]>) with the emailaddress only (e.g: [email protected])
351 351
 		self::replaceEmailAdresses($_html);
352 352
 		//convert hrefs to description -> URL
353 353
 		//$_html = preg_replace('~<a[^>]+href=\"([^"]+)\"[^>]*>(.*)</a>~si','[$2 -> $1]',$_html);
354
-		$_html = preg_replace_callback('~<a[^>]+href=\"([^"]+)\"[^>]*>(.*?)</a>~si','self::transform_url2text',$_html);
354
+		$_html = preg_replace_callback('~<a[^>]+href=\"([^"]+)\"[^>]*>(.*?)</a>~si', 'self::transform_url2text', $_html);
355 355
 
356 356
 		// reducing double \r\n to single ones, dont mess with pre sections
357 357
 		if ($stripcrl === true && $isHTML)
358 358
 		{
359
-			if (stripos($_html,'<pre ')!==false || stripos($_html,'<pre>')!==false)
359
+			if (stripos($_html, '<pre ') !== false || stripos($_html, '<pre>') !== false)
360 360
 			{
361 361
 				$contentArr = self::splithtmlByPRE($_html);
362 362
 				foreach ($contentArr as $k =>&$elem)
363 363
 				{
364
-					if (stripos($elem,'<pre ')===false && stripos($elem,'<pre>')===false)
364
+					if (stripos($elem, '<pre ') === false && stripos($elem, '<pre>') === false)
365 365
 					{
366 366
 						//this is supposed to strip out all remaining stuff in tags, this is sometimes taking out whole sections off content
367
-						if ( $stripalltags ) {
368
-							$_html = preg_replace('~<[^>^@]+>~s','',$_html);
367
+						if ($stripalltags) {
368
+							$_html = preg_replace('~<[^>^@]+>~s', '', $_html);
369 369
 						}
370 370
 						// strip out whitespace inbetween CR/LF
371 371
 						$elem = preg_replace('~\r\n\s+\r\n~si', "\r\n\r\n", $elem);
372 372
 						// strip out / reduce exess CR/LF
373
-						$elem = preg_replace('~\r\n{3,}~si',"\r\n\r\n",$elem);
373
+						$elem = preg_replace('~\r\n{3,}~si', "\r\n\r\n", $elem);
374 374
 					}
375 375
 				}
376
-				$_html = implode('',$contentArr);
376
+				$_html = implode('', $contentArr);
377 377
 			}
378 378
 			else
379 379
 			{
380 380
 				//this is supposed to strip out all remaining stuff in tags, this is sometimes taking out whole sections off content
381
-				if ( $stripalltags ) {
382
-					$_html = preg_replace('~<[^>^@]+>~s','',$_html);
381
+				if ($stripalltags) {
382
+					$_html = preg_replace('~<[^>^@]+>~s', '', $_html);
383 383
 				}
384 384
 				// strip out whitespace inbetween CR/LF
385 385
 				$_html = preg_replace('~\r\n\s+\r\n~si', "\r\n\r\n", $_html);
386 386
 				// strip out / reduce exess CR/LF
387
-				$_html = preg_replace('~(\r\n){3,}~si',"\r\n\r\n",$_html);
387
+				$_html = preg_replace('~(\r\n){3,}~si', "\r\n\r\n", $_html);
388 388
 			}
389 389
 		}
390 390
 		//this is supposed to strip out all remaining stuff in tags, this is sometimes taking out whole sections off content
391
-		if ( $stripalltags ) {
392
-			$_html = preg_replace('~<[^>^@]+>~s','',$_html);
391
+		if ($stripalltags) {
392
+			$_html = preg_replace('~<[^>^@]+>~s', '', $_html);
393 393
 			//$_html = strip_tags($_html, '<a>');
394 394
 		}
395 395
 		// reducing spaces (not for input that was plain text from the beginning)
396
-		if ($isHTML) $_html = preg_replace('~ +~s',' ',$_html);
396
+		if ($isHTML) $_html = preg_replace('~ +~s', ' ', $_html);
397 397
 		// restoring ampersands
398
-		$_html = str_replace('#amper#sand#','&',$_html);
398
+		$_html = str_replace('#amper#sand#', '&', $_html);
399 399
 		// restoring lower|greater[or equal] than
400
-		$_html = str_replace('#lowerorequal#than#','<=',$_html);
401
-		$_html = str_replace('#greaterorequal#than#','>=',$_html);
402
-		$_html = str_replace('#lower#than#','<',$_html);
403
-		$_html = str_replace('#greater#than#','>',$_html);
400
+		$_html = str_replace('#lowerorequal#than#', '<=', $_html);
401
+		$_html = str_replace('#greaterorequal#than#', '>=', $_html);
402
+		$_html = str_replace('#lower#than#', '<', $_html);
403
+		$_html = str_replace('#greater#than#', '>', $_html);
404 404
 		//error_log(__METHOD__.__LINE__.' Charset:'.$displayCharset.' -> '.$_html);
405 405
 		$_html = html_entity_decode($_html, ENT_COMPAT, $displayCharset);
406 406
 		//error_log(__METHOD__.__LINE__.' Charset:'.$displayCharset.' After html_entity_decode: -> '.$_html);
407 407
 		//self::replaceEmailAdresses($_html);
408 408
 		$pos = strpos($_html, 'blockquote');
409 409
 		//error_log("convert HTML2Text: $_html");
410
-		if($pos === false) {
410
+		if ($pos === false) {
411 411
 			return $_html;
412 412
 		} else {
413 413
 			$indent = 0;
414 414
 			$indentString = '';
415 415
 
416 416
 			$quoteParts = preg_split('/#blockquote#type#cite#/', $_html, -1, PREG_SPLIT_OFFSET_CAPTURE);
417
-			foreach($quoteParts as $quotePart) {
418
-				if($quotePart[1] > 0) {
417
+			foreach ($quoteParts as $quotePart) {
418
+				if ($quotePart[1] > 0) {
419 419
 					$indent++;
420 420
 					$indentString .= '>';
421 421
 				}
422 422
 				$quoteParts2 = preg_split('/#blockquote#end#cite#/', $quotePart[0], -1, PREG_SPLIT_OFFSET_CAPTURE);
423 423
 
424
-				foreach($quoteParts2 as $quotePart2) {
425
-					if($quotePart2[1] > 0) {
424
+				foreach ($quoteParts2 as $quotePart2) {
425
+					if ($quotePart2[1] > 0) {
426 426
 						$indent--;
427 427
 						$indentString = substr($indentString, 0, $indent);
428 428
 					}
429 429
 
430 430
 					$quoteParts3 = explode("\r\n", $quotePart2[0]);
431 431
 
432
-					foreach($quoteParts3 as $quotePart3) {
432
+					foreach ($quoteParts3 as $quotePart3) {
433 433
 						//error_log(__METHOD__.__LINE__.'Line:'.$quotePart3);
434
-						$allowedLength = 76-strlen("\r\n$indentString");
434
+						$allowedLength = 76 - strlen("\r\n$indentString");
435 435
 						// only break lines, if not already indented
436
-						if (substr($quotePart3,0,strlen($indentString)) != $indentString)
436
+						if (substr($quotePart3, 0, strlen($indentString)) != $indentString)
437 437
 						{
438 438
 							if (strlen($quotePart3) > $allowedLength) {
439
-								$s=explode(" ", $quotePart3);
439
+								$s = explode(" ", $quotePart3);
440 440
 								$quotePart3 = "";
441 441
 								$linecnt = 0;
442 442
 								foreach ($s as $k=>$v) {
443 443
 									$cnt = strlen($v);
444 444
 									// only break long words within the wordboundaries,
445 445
 									// but it may destroy links, so we check for href and dont do it if we find it
446
-									if($cnt > $allowedLength && stripos($v,'href=')===false) {
446
+									if ($cnt > $allowedLength && stripos($v, 'href=') === false) {
447 447
 										//error_log(__METHOD__.__LINE__.'LongWordFound:'.$v);
448
-										$v=wordwrap($v, $allowedLength, "\r\n$indentString", true);
448
+										$v = wordwrap($v, $allowedLength, "\r\n$indentString", true);
449 449
 									}
450 450
 									// the rest should be broken at the start of the new word that exceeds the limit
451
-									if ($linecnt+$cnt > $allowedLength) {
452
-										$v="\r\n$indentString$v";
451
+									if ($linecnt + $cnt > $allowedLength) {
452
+										$v = "\r\n$indentString$v";
453 453
 										//error_log(__METHOD__.__LINE__.'breaking here:'.$v);
454 454
 										$linecnt = 0;
455 455
 									} else {
@@ -460,11 +460,11 @@  discard block
 block discarded – undo
460 460
 							}
461 461
 						}
462 462
 						//error_log(__METHOD__.__LINE__.'partString to return:'.$indentString . $quotePart3);
463
-						$asciiTextBuff[] = $indentString . $quotePart3 ;
463
+						$asciiTextBuff[] = $indentString.$quotePart3;
464 464
 					}
465 465
 				}
466 466
 			}
467
-			return implode("\r\n",$asciiTextBuff);
467
+			return implode("\r\n", $asciiTextBuff);
468 468
 		}
469 469
 	}
470 470
 
@@ -477,30 +477,30 @@  discard block
 block discarded – undo
477 477
 	static function splithtmlByPRE($html)
478 478
 	{
479 479
 		$searchFor = '<pre ';
480
-		$pos = stripos($html,$searchFor);
481
-		if ($pos===false)
480
+		$pos = stripos($html, $searchFor);
481
+		if ($pos === false)
482 482
 		{
483 483
 			$searchFor = '<pre>';
484
-			$pos = stripos($html,$searchFor);
484
+			$pos = stripos($html, $searchFor);
485 485
 		}
486 486
 		if ($pos === false)
487 487
 		{
488 488
 			return $html;
489 489
 		}
490
-		$html2ret[] = substr($html,0,$pos);
491
-		while ($pos!==false)
490
+		$html2ret[] = substr($html, 0, $pos);
491
+		while ($pos !== false)
492 492
 		{
493
-			$endofpre = stripos($html,'</pre>',$pos);
494
-			$length = $endofpre-$pos+6;
495
-			$html2ret[] = substr($html,$pos,$length);
493
+			$endofpre = stripos($html, '</pre>', $pos);
494
+			$length = $endofpre - $pos + 6;
495
+			$html2ret[] = substr($html, $pos, $length);
496 496
 			$searchFor = '<pre ';
497
-			$pos = stripos($html,$searchFor, $endofpre+6);
498
-			if ($pos===false)
497
+			$pos = stripos($html, $searchFor, $endofpre + 6);
498
+			if ($pos === false)
499 499
 			{
500 500
 				$searchFor = '<pre>';
501
-				$pos = stripos($html,$searchFor, $endofpre+6);
501
+				$pos = stripos($html, $searchFor, $endofpre + 6);
502 502
 			}
503
-			$html2ret[] = ($pos ? substr($html,$endofpre+6,$pos-($endofpre+6)): substr($html,$endofpre+6));
503
+			$html2ret[] = ($pos ? substr($html, $endofpre + 6, $pos - ($endofpre + 6)) : substr($html, $endofpre + 6));
504 504
 			//$pos=false;
505 505
 		}
506 506
 		//error_log(__METHOD__.__LINE__.array2string($html2ret));
Please login to merge, or discard this patch.
Braces   +103 added lines, -33 removed lines patch added patch discarded remove patch
@@ -31,7 +31,8 @@  discard block
 block discarded – undo
31 31
 	static function decodeMailHeader($_string, $displayCharset='utf-8', $reclevel=0)
32 32
 	{
33 33
 		$maxreclevel=25;
34
-		if ($reclevel > $maxreclevel) {
34
+		if ($reclevel > $maxreclevel)
35
+		{
35 36
 			error_log( __METHOD__.__LINE__." Recursion Level Exeeded ($reclevel) while decoding $_string ");
36 37
 			return $_string;
37 38
 		}
@@ -62,10 +63,16 @@  discard block
 block discarded – undo
62 63
 			$string = '';
63 64
 			foreach((array)$elements as $element)
64 65
 			{
65
-				if ($element->charset == 'default') $element->charset = Api\Translation::detect_encoding($element->text);
66
+				if ($element->charset == 'default')
67
+				{
68
+					$element->charset = Api\Translation::detect_encoding($element->text);
69
+				}
66 70
 				if ($element->charset != 'x-unknown')
67 71
 				{
68
-					if( strtoupper($element->charset) != 'UTF-8') $element->text = preg_replace($sar,$rar,$element->text);
72
+					if( strtoupper($element->charset) != 'UTF-8')
73
+					{
74
+						$element->text = preg_replace($sar,$rar,$element->text);
75
+					}
69 76
 					// check if there is a possible nested encoding; make sure that the inputstring and the decoded result are different to avoid loops
70 77
 					$openTags = substr_count($element->text,'?=');
71 78
 					if(preg_match('/\?=.+=\?/', $element->text) && $openTags>0 && $openTags==substr_count($element->text,'=?') && $element->text != $_string)
@@ -81,7 +88,10 @@  discard block
 block discarded – undo
81 88
 					$convertAtEnd = true;
82 89
 				}
83 90
 			}
84
-			if ($convertAtEnd) $string = self::decodeMailHeader($string, $displayCharset, $reclevel);
91
+			if ($convertAtEnd)
92
+			{
93
+				$string = self::decodeMailHeader($string, $displayCharset, $reclevel);
94
+			}
85 95
 		}
86 96
 		elseif(function_exists(mb_decode_mimeheader))
87 97
 		{
@@ -146,18 +156,27 @@  discard block
 block discarded – undo
146 156
 	 */
147 157
 	static function replaceTagsCompletley(&$_body,$tag,$endtag='',$addbracesforendtag=true)
148 158
 	{
149
-		if ($tag) $tag = strtolower($tag);
159
+		if ($tag)
160
+		{
161
+			$tag = strtolower($tag);
162
+		}
150 163
 		$singleton = false;
151
-		if ($endtag=='/>') $singleton =true;
164
+		if ($endtag=='/>')
165
+		{
166
+			$singleton =true;
167
+		}
152 168
 		if ($endtag == '' || empty($endtag) || !isset($endtag))
153 169
 		{
154 170
 			$endtag = $tag;
155
-		} else {
171
+		}
172
+		else
173
+		{
156 174
 			$endtag = strtolower($endtag);
157 175
 			//error_log(__METHOD__.' Using EndTag:'.$endtag);
158 176
 		}
159 177
 		// strip tags out of the message completely with their content
160
-		if ($_body) {
178
+		if ($_body)
179
+		{
161 180
 			if ($singleton)
162 181
 			{
163 182
 				//$_body = preg_replace('~<'.$tag.'[^>].*? '.$endtag.'~simU','',$_body);
@@ -168,7 +187,10 @@  discard block
 block discarded – undo
168 187
 				$found=null;
169 188
 				if ($addbracesforendtag === true )
170 189
 				{
171
-					if (stripos($_body,'<'.$tag)!==false)  $ct = preg_match_all('#<'.$tag.'(?:\s.*)?>(.+)</'.$endtag.'>#isU', $_body, $found);
190
+					if (stripos($_body,'<'.$tag)!==false)
191
+					{
192
+						$ct = preg_match_all('#<'.$tag.'(?:\s.*)?>(.+)</'.$endtag.'>#isU', $_body, $found);
193
+					}
172 194
 					if ($ct>0)
173 195
 					{
174 196
 						//error_log(__METHOD__.__LINE__.array2string($found[0]));
@@ -180,7 +202,10 @@  discard block
 block discarded – undo
180 202
 				}
181 203
 				if ($addbracesforendtag === false )
182 204
 				{
183
-					if (stripos($_body,'<'.$tag)!==false)  $ct = preg_match_all('#<'.$tag.'(?:\s.*)?>(.+)'.$endtag.'#isU', $_body, $found);
205
+					if (stripos($_body,'<'.$tag)!==false)
206
+					{
207
+						$ct = preg_match_all('#<'.$tag.'(?:\s.*)?>(.+)'.$endtag.'#isU', $_body, $found);
208
+					}
184 209
 					if ($ct>0)
185 210
 					{
186 211
 						//error_log(__METHOD__.__LINE__.array2string($found[0]));
@@ -214,7 +239,10 @@  discard block
 block discarded – undo
214 239
 		$linkTextislink = false;
215 240
 		// this is the actual url
216 241
 		$matches[2] = trim(strip_tags($matches[2]));
217
-		if ($matches[2]==$matches[1]) $linkTextislink = true;
242
+		if ($matches[2]==$matches[1])
243
+		{
244
+			$linkTextislink = true;
245
+		}
218 246
 		$matches[1] = str_replace(' ','%20',$matches[1]);
219 247
 		return ($linkTextislink?' ':'[ ').$matches[1].($linkTextislink?'':' -> '.$matches[2]).($linkTextislink?' ':' ]');
220 248
 	}
@@ -237,16 +265,35 @@  discard block
 block discarded – undo
237 265
 			$isHTML = false;
238 266
 			// return $_html; // maybe we should not proceed at all
239 267
 		}
240
-		if ($displayCharset === false) $displayCharset = Api\Translation::charset();
268
+		if ($displayCharset === false)
269
+		{
270
+			$displayCharset = Api\Translation::charset();
271
+		}
241 272
 		//error_log(__METHOD__.$_html);
242 273
 		#print '<hr>';
243 274
 		#print "<pre>"; print htmlspecialchars($_html);
244 275
 		#print "</pre>";
245 276
 		#print "<hr>";
246
-		if (stripos($_html,'style')!==false) self::replaceTagsCompletley($_html,'style'); // clean out empty or pagewide style definitions / left over tags
247
-		if (stripos($_html,'head')!==false) self::replaceTagsCompletley($_html,'head'); // Strip out stuff in head
248
-		if (stripos($_html,'![if')!==false && stripos($_html,'<![endif]>')!==false) self::replaceTagsCompletley($_html,'!\[if','<!\[endif\]>',false); // Strip out stuff in ifs
249
-		if (stripos($_html,'!--[if')!==false && stripos($_html,'<![endif]-->')!==false) self::replaceTagsCompletley($_html,'!--\[if','<!\[endif\]-->',false); // Strip out stuff in ifs
277
+		if (stripos($_html,'style')!==false)
278
+		{
279
+			self::replaceTagsCompletley($_html,'style');
280
+		}
281
+		// clean out empty or pagewide style definitions / left over tags
282
+		if (stripos($_html,'head')!==false)
283
+		{
284
+			self::replaceTagsCompletley($_html,'head');
285
+		}
286
+		// Strip out stuff in head
287
+		if (stripos($_html,'![if')!==false && stripos($_html,'<![endif]>')!==false)
288
+		{
289
+			self::replaceTagsCompletley($_html,'!\[if','<!\[endif\]>',false);
290
+		}
291
+		// Strip out stuff in ifs
292
+		if (stripos($_html,'!--[if')!==false && stripos($_html,'<![endif]-->')!==false)
293
+		{
294
+			self::replaceTagsCompletley($_html,'!--\[if','<!\[endif\]-->',false);
295
+		}
296
+		// Strip out stuff in ifs
250 297
 		$Rules = array ('@<script[^>]*?>.*?</script>@siU', // Strip out javascript
251 298
 			'@&(quot|#34);@i',                // Replace HTML entities
252 299
 			'@&(amp|#38);@i',                 //   Ampersand &
@@ -364,7 +411,8 @@  discard block
 block discarded – undo
364 411
 					if (stripos($elem,'<pre ')===false && stripos($elem,'<pre>')===false)
365 412
 					{
366 413
 						//this is supposed to strip out all remaining stuff in tags, this is sometimes taking out whole sections off content
367
-						if ( $stripalltags ) {
414
+						if ( $stripalltags )
415
+						{
368 416
 							$_html = preg_replace('~<[^>^@]+>~s','',$_html);
369 417
 						}
370 418
 						// strip out whitespace inbetween CR/LF
@@ -378,7 +426,8 @@  discard block
 block discarded – undo
378 426
 			else
379 427
 			{
380 428
 				//this is supposed to strip out all remaining stuff in tags, this is sometimes taking out whole sections off content
381
-				if ( $stripalltags ) {
429
+				if ( $stripalltags )
430
+				{
382 431
 					$_html = preg_replace('~<[^>^@]+>~s','',$_html);
383 432
 				}
384 433
 				// strip out whitespace inbetween CR/LF
@@ -388,12 +437,16 @@  discard block
 block discarded – undo
388 437
 			}
389 438
 		}
390 439
 		//this is supposed to strip out all remaining stuff in tags, this is sometimes taking out whole sections off content
391
-		if ( $stripalltags ) {
440
+		if ( $stripalltags )
441
+		{
392 442
 			$_html = preg_replace('~<[^>^@]+>~s','',$_html);
393 443
 			//$_html = strip_tags($_html, '<a>');
394 444
 		}
395 445
 		// reducing spaces (not for input that was plain text from the beginning)
396
-		if ($isHTML) $_html = preg_replace('~ +~s',' ',$_html);
446
+		if ($isHTML)
447
+		{
448
+			$_html = preg_replace('~ +~s',' ',$_html);
449
+		}
397 450
 		// restoring ampersands
398 451
 		$_html = str_replace('#amper#sand#','&',$_html);
399 452
 		// restoring lower|greater[or equal] than
@@ -407,55 +460,72 @@  discard block
 block discarded – undo
407 460
 		//self::replaceEmailAdresses($_html);
408 461
 		$pos = strpos($_html, 'blockquote');
409 462
 		//error_log("convert HTML2Text: $_html");
410
-		if($pos === false) {
463
+		if($pos === false)
464
+		{
411 465
 			return $_html;
412
-		} else {
466
+		}
467
+		else
468
+		{
413 469
 			$indent = 0;
414 470
 			$indentString = '';
415 471
 
416 472
 			$quoteParts = preg_split('/#blockquote#type#cite#/', $_html, -1, PREG_SPLIT_OFFSET_CAPTURE);
417
-			foreach($quoteParts as $quotePart) {
418
-				if($quotePart[1] > 0) {
473
+			foreach($quoteParts as $quotePart)
474
+			{
475
+				if($quotePart[1] > 0)
476
+				{
419 477
 					$indent++;
420 478
 					$indentString .= '>';
421 479
 				}
422 480
 				$quoteParts2 = preg_split('/#blockquote#end#cite#/', $quotePart[0], -1, PREG_SPLIT_OFFSET_CAPTURE);
423 481
 
424
-				foreach($quoteParts2 as $quotePart2) {
425
-					if($quotePart2[1] > 0) {
482
+				foreach($quoteParts2 as $quotePart2)
483
+				{
484
+					if($quotePart2[1] > 0)
485
+					{
426 486
 						$indent--;
427 487
 						$indentString = substr($indentString, 0, $indent);
428 488
 					}
429 489
 
430 490
 					$quoteParts3 = explode("\r\n", $quotePart2[0]);
431 491
 
432
-					foreach($quoteParts3 as $quotePart3) {
492
+					foreach($quoteParts3 as $quotePart3)
493
+					{
433 494
 						//error_log(__METHOD__.__LINE__.'Line:'.$quotePart3);
434 495
 						$allowedLength = 76-strlen("\r\n$indentString");
435 496
 						// only break lines, if not already indented
436 497
 						if (substr($quotePart3,0,strlen($indentString)) != $indentString)
437 498
 						{
438
-							if (strlen($quotePart3) > $allowedLength) {
499
+							if (strlen($quotePart3) > $allowedLength)
500
+							{
439 501
 								$s=explode(" ", $quotePart3);
440 502
 								$quotePart3 = "";
441 503
 								$linecnt = 0;
442
-								foreach ($s as $k=>$v) {
504
+								foreach ($s as $k=>$v)
505
+								{
443 506
 									$cnt = strlen($v);
444 507
 									// only break long words within the wordboundaries,
445 508
 									// but it may destroy links, so we check for href and dont do it if we find it
446
-									if($cnt > $allowedLength && stripos($v,'href=')===false) {
509
+									if($cnt > $allowedLength && stripos($v,'href=')===false)
510
+									{
447 511
 										//error_log(__METHOD__.__LINE__.'LongWordFound:'.$v);
448 512
 										$v=wordwrap($v, $allowedLength, "\r\n$indentString", true);
449 513
 									}
450 514
 									// the rest should be broken at the start of the new word that exceeds the limit
451
-									if ($linecnt+$cnt > $allowedLength) {
515
+									if ($linecnt+$cnt > $allowedLength)
516
+									{
452 517
 										$v="\r\n$indentString$v";
453 518
 										//error_log(__METHOD__.__LINE__.'breaking here:'.$v);
454 519
 										$linecnt = 0;
455
-									} else {
520
+									}
521
+									else
522
+									{
456 523
 										$linecnt += $cnt;
457 524
 									}
458
-									if (strlen($v))  $quotePart3 .= (strlen($quotePart3) ? " " : "").$v;
525
+									if (strlen($v))
526
+									{
527
+										$quotePart3 .= (strlen($quotePart3) ? " " : "").$v;
528
+									}
459 529
 								}
460 530
 							}
461 531
 						}
Please login to merge, or discard this patch.
api/src/Mail/Imap/Iface.php 2 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -121,6 +121,7 @@
 block discarded – undo
121 121
 	 * @param bool $_adminConnection create admin connection if true
122 122
 	 * @param int $_timeout =null timeout in secs, if none given fmail pref or default of 20 is used
123 123
 	 * @throws Exception on error
124
+	 * @return void
124 125
 	 */
125 126
 	function openConnection($_adminConnection=false, $_timeout=null);
126 127
 
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -14,9 +14,9 @@  discard block
 block discarded – undo
14 14
 namespace EGroupware\Api\Mail\Imap;
15 15
 
16 16
 define('IMAP_NAMESPACE_PERSONAL', 'personal');
17
-define('IMAP_NAMESPACE_OTHERS'	, 'others');
18
-define('IMAP_NAMESPACE_SHARED'	, 'shared');
19
-define('IMAP_NAMESPACE_ALL'	, 'all');
17
+define('IMAP_NAMESPACE_OTHERS', 'others');
18
+define('IMAP_NAMESPACE_SHARED', 'shared');
19
+define('IMAP_NAMESPACE_ALL', 'all');
20 20
 
21 21
 /**
22 22
  * This class holds all information about the imap connection.
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 	 * @param string $_folderName=''
88 88
 	 * @return string utf-7 encoded (done in getMailboxName)
89 89
 	 */
90
-	function getUserMailboxString($_username, $_folderName='');
90
+	function getUserMailboxString($_username, $_folderName = '');
91 91
 
92 92
 	/**
93 93
 	 * get list of namespaces
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 	 * @param string $_what - what to retrieve either QMAX, USED or ALL is supported
104 104
 	 * @return mixed the quota for specified user (by what) or array with all available Quota Information, or false
105 105
 	 */
106
-	function getQuotaByUser($_username, $_what='QMAX');
106
+	function getQuotaByUser($_username, $_what = 'QMAX');
107 107
 
108 108
 	/**
109 109
 	 * returns information about a user
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	 * @param int $_timeout =null timeout in secs, if none given fmail pref or default of 20 is used
123 123
 	 * @throws Exception on error
124 124
 	 */
125
-	function openConnection($_adminConnection=false, $_timeout=null);
125
+	function openConnection($_adminConnection = false, $_timeout = null);
126 126
 
127 127
 	/**
128 128
 	 * set userdata
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 	 * @param string $_scriptName =null
150 150
 	 * @return boolean
151 151
 	 */
152
-	public function setVacationUser($_euser, array $_vacation, $_scriptName=null);
152
+	public function setVacationUser($_euser, array $_vacation, $_scriptName = null);
153 153
 
154 154
 	/**
155 155
 	 * Get vacation message for given user
@@ -159,5 +159,5 @@  discard block
 block discarded – undo
159 159
 	 * @throws Exception on connection error or authentication failure
160 160
 	 * @return array
161 161
 	 */
162
-	public function getVacationUser($_euser, $_scriptName=null);
162
+	public function getVacationUser($_euser, $_scriptName = null);
163 163
 }
Please login to merge, or discard this patch.
api/src/Mail/Sieve.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 	/**
83 83
 	 * Constructor
84 84
 	 *
85
-	 * @param array|Imap $params =array()
85
+	 * @param Imap $params =array()
86 86
 	 */
87 87
 	function __construct($params=array())
88 88
 	{
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	 *
166 166
 	 * @param array $_emailNotification
167 167
 	 * @param string $_scriptName
168
-	 * @return Script
168
+	 * @return boolean
169 169
 	 */
170 170
 	function setEmailNotification(array $_emailNotification, $_scriptName=null)
171 171
 	{
Please login to merge, or discard this patch.
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -37,28 +37,28 @@  discard block
 block discarded – undo
37 37
 	var $icServer;
38 38
 
39 39
 	/**
40
-	* @var string name of active script queried from Sieve server
41
-	*/
40
+	 * @var string name of active script queried from Sieve server
41
+	 */
42 42
 	var $scriptName;
43 43
 
44 44
 	/**
45
-	* @var $rules containing the rules
46
-	*/
45
+	 * @var $rules containing the rules
46
+	 */
47 47
 	var $rules;
48 48
 
49 49
 	/**
50
-	* @var $vacation containing the vacation
51
-	*/
50
+	 * @var $vacation containing the vacation
51
+	 */
52 52
 	var $vacation;
53 53
 
54 54
 	/**
55
-	* @var $emailNotification containing the emailNotification
56
-	*/
55
+	 * @var $emailNotification containing the emailNotification
56
+	 */
57 57
 	var $emailNotification;
58 58
 
59 59
 	/**
60
-	* @var object $error the last PEAR error object
61
-	*/
60
+	 * @var object $error the last PEAR error object
61
+	 */
62 62
 	var $error;
63 63
 
64 64
 	/**
@@ -170,11 +170,11 @@  discard block
 block discarded – undo
170 170
 	function setEmailNotification(array $_emailNotification, $_scriptName=null)
171 171
 	{
172 172
 		if ($_emailNotification['externalEmail'] == '' || !preg_match("/\@/",$_emailNotification['externalEmail'])) {
173
-    		$_emailNotification['status'] = 'off';
174
-    		$_emailNotification['externalEmail'] = '';
175
-    	}
173
+			$_emailNotification['status'] = 'off';
174
+			$_emailNotification['externalEmail'] = '';
175
+		}
176 176
 
177
-    	$script = $this->retrieveRules($_scriptName);
177
+		$script = $this->retrieveRules($_scriptName);
178 178
    		$script->emailNotification = $_emailNotification;
179 179
 		$ret = $script->updateScript($this);
180 180
 		$this->error = $script->errstr;
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 	 *
85 85
 	 * @param array|Imap $params =array()
86 86
 	 */
87
-	function __construct($params=array())
87
+	function __construct($params = array())
88 88
 	{
89 89
 		if (is_a($params, __NAMESPACE__.'\\Imap'))
90 90
 		{
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 		}
100 100
 		parent::__construct($params);
101 101
 
102
-		$this->displayCharset	= Translation::charset();
102
+		$this->displayCharset = Translation::charset();
103 103
 	}
104 104
 
105 105
 	function getRules()
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 	 * @param string $_scriptName
131 131
 	 * @param boolean $utf7imap_fileinto =false true: encode foldernames with utf7imap, default utf8
132 132
 	 */
133
-	function setRules(array $_rules, $_scriptName=null, $utf7imap_fileinto=false)
133
+	function setRules(array $_rules, $_scriptName = null, $utf7imap_fileinto = false)
134 134
 	{
135 135
 		$script = $this->retrieveRules($_scriptName);
136 136
 		$script->debug = $this->debug;
@@ -146,11 +146,11 @@  discard block
 block discarded – undo
146 146
 	 * @param array $_vacation
147 147
 	 * @param string $_scriptName
148 148
 	 */
149
-	function setVacation(array $_vacation, $_scriptName=null)
149
+	function setVacation(array $_vacation, $_scriptName = null)
150 150
 	{
151 151
 		if ($this->debug)
152 152
 		{
153
-			error_log(__METHOD__ . "($_scriptName," . print_r($_vacation, true) . ')');
153
+			error_log(__METHOD__."($_scriptName,".print_r($_vacation, true).')');
154 154
 		}
155 155
 		$script = $this->retrieveRules($_scriptName);
156 156
 		$script->debug = $this->debug;
@@ -167,9 +167,9 @@  discard block
 block discarded – undo
167 167
 	 * @param string $_scriptName
168 168
 	 * @return Script
169 169
 	 */
170
-	function setEmailNotification(array $_emailNotification, $_scriptName=null)
170
+	function setEmailNotification(array $_emailNotification, $_scriptName = null)
171 171
 	{
172
-		if ($_emailNotification['externalEmail'] == '' || !preg_match("/\@/",$_emailNotification['externalEmail'])) {
172
+		if ($_emailNotification['externalEmail'] == '' || !preg_match("/\@/", $_emailNotification['externalEmail'])) {
173 173
     		$_emailNotification['status'] = 'off';
174 174
     		$_emailNotification['externalEmail'] = '';
175 175
     	}
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 	 * @param string $_scriptName
188 188
 	 * @return Script
189 189
 	 */
190
-	function retrieveRules($_scriptName=null)
190
+	function retrieveRules($_scriptName = null)
191 191
 	{
192 192
 		if (!$_scriptName)
193 193
 		{
@@ -197,8 +197,8 @@  discard block
 block discarded – undo
197 197
 				try {
198 198
 					$this->scriptName = $this->getActive();
199 199
 				}
200
-				catch(Exception $e) {
201
-					unset($e);	// ignore NOTEXISTS exception
200
+				catch (Exception $e) {
201
+					unset($e); // ignore NOTEXISTS exception
202 202
 				}
203 203
 				if (empty($this->scriptName))
204 204
 				{
@@ -213,11 +213,11 @@  discard block
 block discarded – undo
213 213
 			$script->retrieveRules($this);
214 214
 		}
215 215
 		catch (\Exception $e) {
216
-			unset($e);	// ignore not found script exception
216
+			unset($e); // ignore not found script exception
217 217
 		}
218
-		$this->rules =& $script->rules;
219
-		$this->vacation =& $script->vacation;
220
-		$this->emailNotification =& $script->emailNotification; // Added email notifications
218
+		$this->rules = & $script->rules;
219
+		$this->vacation = & $script->vacation;
220
+		$this->emailNotification = & $script->emailNotification; // Added email notifications
221 221
 
222 222
 		return $script;
223 223
 	}
Please login to merge, or discard this patch.
Braces   +14 added lines, -4 removed lines patch added patch discarded remove patch
@@ -104,21 +104,30 @@  discard block
 block discarded – undo
104 104
 
105 105
 	function getRules()
106 106
 	{
107
-		if (!isset($this->rules)) $this->retrieveRules();
107
+		if (!isset($this->rules))
108
+		{
109
+			$this->retrieveRules();
110
+		}
108 111
 
109 112
 		return $this->rules;
110 113
 	}
111 114
 
112 115
 	function getVacation()
113 116
 	{
114
-		if (!isset($this->rules)) $this->retrieveRules();
117
+		if (!isset($this->rules))
118
+		{
119
+			$this->retrieveRules();
120
+		}
115 121
 
116 122
 		return $this->vacation;
117 123
 	}
118 124
 
119 125
 	function getEmailNotification()
120 126
 	{
121
-		if (!isset($this->rules)) $this->retrieveRules();
127
+		if (!isset($this->rules))
128
+		{
129
+			$this->retrieveRules();
130
+		}
122 131
 
123 132
 		return $this->emailNotification;
124 133
 	}
@@ -169,7 +178,8 @@  discard block
 block discarded – undo
169 178
 	 */
170 179
 	function setEmailNotification(array $_emailNotification, $_scriptName=null)
171 180
 	{
172
-		if ($_emailNotification['externalEmail'] == '' || !preg_match("/\@/",$_emailNotification['externalEmail'])) {
181
+		if ($_emailNotification['externalEmail'] == '' || !preg_match("/\@/",$_emailNotification['externalEmail']))
182
+		{
173 183
     		$_emailNotification['status'] = 'off';
174 184
     		$_emailNotification['externalEmail'] = '';
175 185
     	}
Please login to merge, or discard this patch.
api/src/Mail/Smtp.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -156,7 +156,7 @@
 block discarded – undo
156 156
 	/**
157 157
 	 * Get the data of a given user
158 158
 	 *
159
-	 * @param int|string $user numerical account-id, account-name or email address
159
+	 * @param integer $user numerical account-id, account-name or email address
160 160
 	 * @param boolean $match_uid_at_domain =true true: uid@domain matches, false only an email or alias address matches
161 161
 	 * @return array with values for keys 'mailLocalAddress', 'mailAlternateAddress' (array), 'mailForwardingAddress' (array),
162 162
 	 * 	'accountStatus' ("active"), 'quotaLimit' and 'deliveryMode' ("forwardOnly")
Please login to merge, or discard this patch.
Spacing   +16 added lines, -18 removed lines patch added patch discarded remove patch
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	 *
80 80
 	 * @param string $defaultDomain =null
81 81
 	 */
82
-	function __construct($defaultDomain=null)
82
+	function __construct($defaultDomain = null)
83 83
 	{
84 84
 		$this->defaultDomain = $defaultDomain ? $defaultDomain : $GLOBALS['egw_info']['server']['mail_suffix'];
85 85
 
@@ -104,12 +104,10 @@  discard block
 block discarded – undo
104 104
 	 */
105 105
 	function addAccount($_hookValues)
106 106
 	{
107
-		$mailLocalAddress = $_hookValues['account_email'] ? $_hookValues['account_email'] :
108
-			Api\Accounts::email($_hookValues['account_firstname'],
109
-				$_hookValues['account_lastname'],$_hookValues['account_lid'],$this->defaultDomain);
107
+		$mailLocalAddress = $_hookValues['account_email'] ? $_hookValues['account_email'] : Api\Accounts::email($_hookValues['account_firstname'],
108
+				$_hookValues['account_lastname'], $_hookValues['account_lid'], $this->defaultDomain);
110 109
 
111
-		$account_id = !empty($_hookValues['account_id']) ? $_hookValues['account_id'] :
112
-			$this->accounts->name2id($_hookValues['account_lid'], 'account_lid', 'u');
110
+		$account_id = !empty($_hookValues['account_id']) ? $_hookValues['account_id'] : $this->accounts->name2id($_hookValues['account_lid'], 'account_lid', 'u');
113 111
 
114 112
 		if ($this->accounts->exists($account_id) != 1)
115 113
 		{
@@ -126,7 +124,7 @@  discard block
 block discarded – undo
126 124
 	 */
127 125
 	function deleteAccount($_hookValues)
128 126
 	{
129
-		unset($_hookValues);	// not used, but required by function signature
127
+		unset($_hookValues); // not used, but required by function signature
130 128
 
131 129
 		return true;
132 130
 	}
@@ -139,12 +137,12 @@  discard block
 block discarded – undo
139 137
 	 */
140 138
 	function getAccountEmailAddress($_accountName)
141 139
 	{
142
-		$emailAddresses	= array();
140
+		$emailAddresses = array();
143 141
 
144 142
 		if (($account_id = $this->accounts->name2id($_accountName, 'account_lid', 'u')))
145 143
 		{
146
-			$realName = trim($GLOBALS['egw_info']['user']['account_firstname'] . (!empty($GLOBALS['egw_info']['user']['account_firstname']) ? ' ' : '') . $GLOBALS['egw_info']['user']['account_lastname']);
147
-			$emailAddresses[] = array (
144
+			$realName = trim($GLOBALS['egw_info']['user']['account_firstname'].(!empty($GLOBALS['egw_info']['user']['account_firstname']) ? ' ' : '').$GLOBALS['egw_info']['user']['account_lastname']);
145
+			$emailAddresses[] = array(
148 146
 				'name'		=> $realName,
149 147
 				'address'	=> $this->accounts->id2name($account_id, 'account_email'),
150 148
 				'type'		=> 'default',
@@ -161,9 +159,9 @@  discard block
 block discarded – undo
161 159
 	 * @return array with values for keys 'mailLocalAddress', 'mailAlternateAddress' (array), 'mailForwardingAddress' (array),
162 160
 	 * 	'accountStatus' ("active"), 'quotaLimit' and 'deliveryMode' ("forwardOnly")
163 161
 	 */
164
-	function getUserData($user, $match_uid_at_domain=false)
162
+	function getUserData($user, $match_uid_at_domain = false)
165 163
 	{
166
-		unset($user, $match_uid_at_domain);	// not used, but required by function signature
164
+		unset($user, $match_uid_at_domain); // not used, but required by function signature
167 165
 
168 166
 		$userData = array();
169 167
 
@@ -201,9 +199,9 @@  discard block
 block discarded – undo
201 199
 	 * @return boolean true on success, false on error writing to ldap
202 200
 	 */
203 201
 	function setUserData($_uidnumber, array $_mailAlternateAddress, array $_mailForwardingAddress, $_deliveryMode,
204
-		$_accountStatus, $_mailLocalAddress, $_quota, $_forwarding_only=false, $_setMailbox=null)
202
+		$_accountStatus, $_mailLocalAddress, $_quota, $_forwarding_only = false, $_setMailbox = null)
205 203
 	{
206
-		unset($_uidnumber, $_mailAlternateAddress, $_mailForwardingAddress,	// not used, but require by function signature
204
+		unset($_uidnumber, $_mailAlternateAddress, $_mailForwardingAddress, // not used, but require by function signature
207 205
 			$_deliveryMode, $_accountStatus, $_mailLocalAddress, $_quota, $_forwarding_only, $_setMailbox);
208 206
 
209 207
 		return true;
@@ -217,7 +215,7 @@  discard block
 block discarded – undo
217 215
 	 */
218 216
 	function updateAccount($_hookValues)
219 217
 	{
220
-		unset($_hookValues);	// not used, but required by function signature
218
+		unset($_hookValues); // not used, but required by function signature
221 219
 
222 220
 		return true;
223 221
 	}
@@ -233,15 +231,15 @@  discard block
 block discarded – undo
233 231
 	 * 	default use $this->loginType
234 232
 	 * @return string
235 233
 	 */
236
-	/*static*/ public function mailbox_addr($account,$domain=null,$mail_login_type=null)
234
+	/*static*/ public function mailbox_addr($account, $domain = null, $mail_login_type = null)
237 235
 	{
238 236
 		if (is_null($domain)) $domain = $this->defaultDomain;
239 237
 		if (is_null($mail_login_type)) $mail_login_type = $this->loginType;
240 238
 
241
-		switch($mail_login_type)
239
+		switch ($mail_login_type)
242 240
 		{
243 241
 			case 'email':
244
-				$mbox = is_array($account) ? $account['account_email'] : $GLOBALS['egw']->accounts->id2name($account,'account_email');
242
+				$mbox = is_array($account) ? $account['account_email'] : $GLOBALS['egw']->accounts->id2name($account, 'account_email');
245 243
 				break;
246 244
 
247 245
 			case 'uidNumber':
Please login to merge, or discard this patch.
Braces   +12 added lines, -3 removed lines patch added patch discarded remove patch
@@ -235,8 +235,14 @@  discard block
 block discarded – undo
235 235
 	 */
236 236
 	/*static*/ public function mailbox_addr($account,$domain=null,$mail_login_type=null)
237 237
 	{
238
-		if (is_null($domain)) $domain = $this->defaultDomain;
239
-		if (is_null($mail_login_type)) $mail_login_type = $this->loginType;
238
+		if (is_null($domain))
239
+		{
240
+			$domain = $this->defaultDomain;
241
+		}
242
+		if (is_null($mail_login_type))
243
+		{
244
+			$mail_login_type = $this->loginType;
245
+		}
240 246
 
241 247
 		switch($mail_login_type)
242 248
 		{
@@ -245,7 +251,10 @@  discard block
 block discarded – undo
245 251
 				break;
246 252
 
247 253
 			case 'uidNumber':
248
-				if (is_array($account)) $account = $account['account_id'];
254
+				if (is_array($account))
255
+				{
256
+					$account = $account['account_id'];
257
+				}
249 258
 				$mbox = 'u'.$account.'@'.$domain;
250 259
 				break;
251 260
 
Please login to merge, or discard this patch.
api/src/Mail/Smtp/Ldap.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -628,7 +628,7 @@
 block discarded – undo
628 628
 	 * @param int $_accountID
629 629
 	 * @param string $_forwardingAddress
630 630
 	 * @param string $_keepLocalCopy 'yes'
631
-	 * @return boolean true on success, false on error writing to ldap
631
+	 * @return boolean|null true on success, false on error writing to ldap
632 632
 	 */
633 633
 	function saveSMTPForwarding($_accountID, $_forwardingAddress, $_keepLocalCopy)
634 634
 	{
Please login to merge, or discard this patch.
Braces   +69 added lines, -17 removed lines patch added patch discarded remove patch
@@ -303,7 +303,10 @@  discard block
 block discarded – undo
303 303
 			{
304 304
 				foreach($allValues[0][static::MAIL_ATTR] as $key => $value)
305 305
 				{
306
-					if ($key === 'count') continue;
306
+					if ($key === 'count')
307
+					{
308
+						continue;
309
+					}
307 310
 
308 311
 					$emailAddresses[] = array (
309 312
 						'name'		=> $realName,
@@ -324,7 +327,10 @@  discard block
 block discarded – undo
324 327
 				}
325 328
 			}
326 329
 		}
327
-		if ($this->debug) error_log(__METHOD__."('$_accountName') returning ".array2string($emailAddresses));
330
+		if ($this->debug)
331
+		{
332
+			error_log(__METHOD__."('$_accountName') returning ".array2string($emailAddresses));
333
+		}
328 334
 
329 335
 		return $emailAddresses;
330 336
 	}
@@ -357,7 +363,10 @@  discard block
 block discarded – undo
357 363
 		}
358 364
 		elseif (strpos($user, '@') === false)
359 365
 		{
360
-			if (is_numeric($user)) $user = $GLOBALS['egw']->accounts->id2name($user);
366
+			if (is_numeric($user))
367
+			{
368
+				$user = $GLOBALS['egw']->accounts->id2name($user);
369
+			}
361 370
 			$filter = '(&'.static::USER_FILTER.'('.static::USER_ATTR.'='.Api\Ldap::quote($user).'))';
362 371
 		}
363 372
 		else	// email address --> build filter by attributes defined in config
@@ -374,7 +383,10 @@  discard block
 block discarded – undo
374 383
 			else
375 384
 			{
376 385
 				$to_or = array('('.static::MAIL_ATTR.'='.Api\Ldap::quote($user).')');
377
-				if ($match_uid_at_domain) $to_or[] = '('.static::USER_ATTR.'='.Api\Ldap::quote($namepart).')';
386
+				if ($match_uid_at_domain)
387
+				{
388
+					$to_or[] = '('.static::USER_ATTR.'='.Api\Ldap::quote($namepart).')';
389
+				}
378 390
 				if (static::ALIAS_ATTR)
379 391
 				{
380 392
 					$to_or[] = '('.static::ALIAS_ATTR.'='.static::ALIAS_PREFIX.Api\Ldap::quote($user).')';
@@ -399,11 +411,17 @@  discard block
 block discarded – undo
399 411
 		if ($sri)
400 412
 		{
401 413
 			$allValues = ldap_get_entries($ldap, $sri);
402
-			if ($this->debug) error_log(__METHOD__."('$user') --> ldap_search(, '$this->search_base', '$filter') --> ldap_get_entries=".array2string($allValues[0]));
414
+			if ($this->debug)
415
+			{
416
+				error_log(__METHOD__."('$user') --> ldap_search(, '$this->search_base', '$filter') --> ldap_get_entries=".array2string($allValues[0]));
417
+			}
403 418
 
404 419
 			foreach($allValues as $key => $values)
405 420
 			{
406
-				if ($key === 'count') continue;
421
+				if ($key === 'count')
422
+				{
423
+					continue;
424
+				}
407 425
 
408 426
 				// groups are always active (if they have an email) and allways forwardOnly
409 427
 				if (in_array(static::GROUP_SCHEMA, $values['objectclass']))
@@ -445,11 +463,14 @@  discard block
 block discarded – undo
445 463
 								}
446 464
 							}
447 465
 						}
448
-						elseif (static::FORWARD_ONLY)	// check caseinsensitiv for existence of that value
466
+						elseif (static::FORWARD_ONLY)
467
+						{
468
+							// check caseinsensitiv for existence of that value
449 469
 						{
450 470
 							$deliveryMode = self::getAttributePrefix($values[static::FORWARD_ONLY_ATTR], static::FORWARD_ONLY) ?
451 471
 								Mail\Smtp::FORWARD_ONLY : '';
452 472
 						}
473
+						}
453 474
 						else	// check for existence of any value
454 475
 						{
455 476
 							$deliveryMode = $values[static::FORWARD_ONLY_ATTR]['count'] > 0 ?
@@ -482,7 +503,10 @@  discard block
 block discarded – undo
482 503
 				}
483 504
 
484 505
 				// regular user-data can only be from users, NOT groups
485
-				if (in_array(static::GROUP_SCHEMA, $values['objectclass'])) continue;
506
+				if (in_array(static::GROUP_SCHEMA, $values['objectclass']))
507
+				{
508
+					continue;
509
+				}
486 510
 
487 511
 				$userData['mailLocalAddress'] = $values[static::MAIL_ATTR][0];
488 512
 				$userData['accountStatus'] = $accountStatus;
@@ -507,7 +531,10 @@  discard block
 block discarded – undo
507 531
 					$userData['mailForwardingAddress']	= self::getAttributePrefix($values[static::FORWARD_ATTR], static::FORWARD_PREFIX);
508 532
 				}
509 533
 
510
-				if (static::MAILBOX_ATTR) $userData['mailMessageStore']	= $values[static::MAILBOX_ATTR][0];
534
+				if (static::MAILBOX_ATTR)
535
+				{
536
+					$userData['mailMessageStore']	= $values[static::MAILBOX_ATTR][0];
537
+				}
511 538
 
512 539
 				$userData['deliveryMode'] = $deliveryMode;
513 540
 
@@ -526,7 +553,10 @@  discard block
 block discarded – undo
526 553
 				}
527 554
 			}
528 555
 		}
529
-		if ($this->debug) error_log(__METHOD__."('$user') returning ".array2string($userData));
556
+		if ($this->debug)
557
+		{
558
+			error_log(__METHOD__."('$user') returning ".array2string($userData));
559
+		}
530 560
 
531 561
 		return $userData;
532 562
 	}
@@ -649,7 +679,10 @@  discard block
 block discarded – undo
649 679
 
650 680
 		$this->addAccountExtra(array('location' => 'setUserData'), $allValues[0], $newData);
651 681
 
652
-		if ($this->debug) error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'$accountDN',".array2string($newData).')');
682
+		if ($this->debug)
683
+		{
684
+			error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'$accountDN',".array2string($newData).')');
685
+		}
653 686
 
654 687
 		if (!($ret = @ldap_mod_replace($ldap, $accountDN, $newData)) && static::CHECK_FORWARD_ATTR)
655 688
 		{
@@ -749,7 +782,10 @@  discard block
 block discarded – undo
749 782
 				// merge in again all new set forwards incl. opt. prefix
750 783
 				self::setAttributePrefix($newData[static::FORWARD_ATTR], $forwards, static::FORWARD_PREFIX);
751 784
 			}
752
-			if ($this->debug) error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'{$allValues[0]['dn']}',".array2string($newData).')');
785
+			if ($this->debug)
786
+			{
787
+				error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'{$allValues[0]['dn']}',".array2string($newData).')');
788
+			}
753 789
 
754 790
 			return ldap_modify ($ds, $allValues[0]['dn'], $newData);
755 791
 		}
@@ -795,7 +831,11 @@  discard block
 block discarded – undo
795 831
 		$mailboxes = array();
796 832
 		foreach($entries as $entry)
797 833
 		{
798
-			if ($entry[static::USER_ATTR][0] == 'anonymous') continue;	// anonymous is never a mail-user!
834
+			if ($entry[static::USER_ATTR][0] == 'anonymous')
835
+			{
836
+				continue;
837
+			}
838
+			// anonymous is never a mail-user!
799 839
 			list($mailbox) = explode('@', $entry[static::MAILBOX_ATTR ? static::MAILBOX_ATTR : static::MAIL_ATTR][0]);
800 840
 			$mailboxes[$entry[static::USER_ATTR][0]] = $mailbox;
801 841
 		}
@@ -812,8 +852,14 @@  discard block
 block discarded – undo
812 852
 	protected static function setAttributePrefix(&$attribute, $values, $prefix='')
813 853
 	{
814 854
 		//$attribute_in = $attribute;
815
-		if (empty($attribute)) $attribute = array();
816
-		if (!is_array($attribute)) $attribute = (array)$attribute;
855
+		if (empty($attribute))
856
+		{
857
+			$attribute = array();
858
+		}
859
+		if (!is_array($attribute))
860
+		{
861
+			$attribute = (array)$attribute;
862
+		}
817 863
 
818 864
 		foreach((array)$values as $value)
819 865
 		{
@@ -843,12 +889,18 @@  discard block
 block discarded – undo
843 889
 			{
844 890
 				if (!$prefix || stripos($value, $prefix) === 0)
845 891
 				{
846
-					if ($remove) unset($attribute[$key]);
892
+					if ($remove)
893
+					{
894
+						unset($attribute[$key]);
895
+					}
847 896
 					$values[] = substr($value, strlen($prefix));
848 897
 				}
849 898
 			}
850 899
 			// reindex $attribute, if neccessary
851
-			if ($values && $attribute) $attribute = array_values($attribute);
900
+			if ($values && $attribute)
901
+			{
902
+				$attribute = array_values($attribute);
903
+			}
852 904
 		}
853 905
 		//error_log(__METHOD__."(".array2string($attribute_in).", '$prefix', $remove) attribute=".array2string($attribute).' returning '.array2string($values));
854 906
 		return $values;
Please login to merge, or discard this patch.
Spacing   +43 added lines, -44 removed lines patch added patch discarded remove patch
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 	 *
165 165
 	 * @param string $defaultDomain =null
166 166
 	 */
167
-	function __construct($defaultDomain=null)
167
+	function __construct($defaultDomain = null)
168 168
 	{
169 169
 		parent::__construct($defaultDomain);
170 170
 
@@ -212,9 +212,8 @@  discard block
 block discarded – undo
212 212
 	 */
213 213
 	function addAccount($_hookValues)
214 214
 	{
215
-		$mailLocalAddress = $_hookValues['account_email'] ? $_hookValues['account_email'] :
216
-			Api\Accounts::email($_hookValues['account_firstname'],
217
-				$_hookValues['account_lastname'],$_hookValues['account_lid'],$this->defaultDomain);
215
+		$mailLocalAddress = $_hookValues['account_email'] ? $_hookValues['account_email'] : Api\Accounts::email($_hookValues['account_firstname'],
216
+				$_hookValues['account_lastname'], $_hookValues['account_lid'], $this->defaultDomain);
218 217
 
219 218
 		$ds = $this->getLdapConnection();
220 219
 
@@ -226,13 +225,13 @@  discard block
 block discarded – undo
226 225
 		}
227 226
 		$allValues 	= ldap_get_entries($ds, $sri);
228 227
 		$accountDN 	= $allValues[0]['dn'];
229
-		$objectClasses	= $allValues[0]['objectclass'];
228
+		$objectClasses = $allValues[0]['objectclass'];
230 229
 		unset($objectClasses['count']);
231 230
 
232 231
 		// add our mail schema, if not already set
233
-		if(!in_array(static::SCHEMA,$objectClasses) && !in_array(strtolower(static::SCHEMA),$objectClasses))
232
+		if (!in_array(static::SCHEMA, $objectClasses) && !in_array(strtolower(static::SCHEMA), $objectClasses))
234 233
 		{
235
-			$objectClasses[]	= static::SCHEMA;
234
+			$objectClasses[] = static::SCHEMA;
236 235
 		}
237 236
 		// the new code for postfix+cyrus+ldap
238 237
 		$newData = array(
@@ -263,7 +262,7 @@  discard block
 block discarded – undo
263 262
 		{
264 263
 			error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'$accountDN',".
265 264
 				array2string($newData).') returning '.array2string($ret).
266
-				(!$ret?' ('.ldap_error($ds).')':''));
265
+				(!$ret ? ' ('.ldap_error($ds).')' : ''));
267 266
 		}
268 267
 		return $ret;
269 268
 	}
@@ -277,7 +276,7 @@  discard block
 block discarded – undo
277 276
 	 */
278 277
 	function addAccountExtra(array $_hookValues, array $allValues, array &$newData)
279 278
 	{
280
-		unset($_hookValues, $allValues, $newData);	// not used, but required by function signature
279
+		unset($_hookValues, $allValues, $newData); // not used, but required by function signature
281 280
 	}
282 281
 
283 282
 	/**
@@ -288,24 +287,24 @@  discard block
 block discarded – undo
288 287
 	 */
289 288
 	function getAccountEmailAddress($_accountName)
290 289
 	{
291
-		$emailAddresses	= array();
290
+		$emailAddresses = array();
292 291
 		$ds = $this->getLdapConnection();
293 292
 		$filter = '(&'.static::USER_FILTER.'('.static::USER_ATTR.'='.Api\Ldap::quote($_accountName).'))';
294
-		$attributes	= array('dn', static::MAIL_ATTR, static::ALIAS_ATTR);
293
+		$attributes = array('dn', static::MAIL_ATTR, static::ALIAS_ATTR);
295 294
 		$sri = @ldap_search($ds, $this->search_base, $filter, $attributes);
296 295
 
297 296
 		if ($sri)
298 297
 		{
299
-			$realName = trim($GLOBALS['egw_info']['user']['account_firstname'] . (!empty($GLOBALS['egw_info']['user']['account_firstname']) ? ' ' : '') . $GLOBALS['egw_info']['user']['account_lastname']);
298
+			$realName = trim($GLOBALS['egw_info']['user']['account_firstname'].(!empty($GLOBALS['egw_info']['user']['account_firstname']) ? ' ' : '').$GLOBALS['egw_info']['user']['account_lastname']);
300 299
 			$allValues = ldap_get_entries($ds, $sri);
301 300
 
302
-			if(isset($allValues[0][static::MAIL_ATTR]))
301
+			if (isset($allValues[0][static::MAIL_ATTR]))
303 302
 			{
304
-				foreach($allValues[0][static::MAIL_ATTR] as $key => $value)
303
+				foreach ($allValues[0][static::MAIL_ATTR] as $key => $value)
305 304
 				{
306 305
 					if ($key === 'count') continue;
307 306
 
308
-					$emailAddresses[] = array (
307
+					$emailAddresses[] = array(
309 308
 						'name'		=> $realName,
310 309
 						'address'	=> $value,
311 310
 						'type'		=> !$key ? 'default' : 'alternate',
@@ -314,7 +313,7 @@  discard block
 block discarded – undo
314 313
 			}
315 314
 			if (static::ALIAS_ATTR && isset($allValues[0][static::ALIAS_ATTR]))
316 315
 			{
317
-				foreach(self::getAttributePrefix($allValues[0][static::ALIAS_ATTR], static::ALIAS_PREFIX) as $value)
316
+				foreach (self::getAttributePrefix($allValues[0][static::ALIAS_ATTR], static::ALIAS_PREFIX) as $value)
318 317
 				{
319 318
 					$emailAddresses[] = array(
320 319
 						'name'		=> $realName,
@@ -341,7 +340,7 @@  discard block
 block discarded – undo
341 340
 	 * @return array with values for keys 'mailLocalAddress', 'mailAlternateAddress' (array), 'mailForwardingAddress' (array),
342 341
 	 * 	'accountStatus' ("active"), 'quotaLimit' and 'deliveryMode' ("forwardOnly")
343 342
 	 */
344
-	function getUserData($user, $match_uid_at_domain=false)
343
+	function getUserData($user, $match_uid_at_domain = false)
345 344
 	{
346 345
 		$userData = array(
347 346
 			'mailbox' => array(),
@@ -401,7 +400,7 @@  discard block
 block discarded – undo
401 400
 			$allValues = ldap_get_entries($ldap, $sri);
402 401
 			if ($this->debug) error_log(__METHOD__."('$user') --> ldap_search(, '$this->search_base', '$filter') --> ldap_get_entries=".array2string($allValues[0]));
403 402
 
404
-			foreach($allValues as $key => $values)
403
+			foreach ($allValues as $key => $values)
405 404
 			{
406 405
 				if ($key === 'count') continue;
407 406
 
@@ -504,16 +503,16 @@  discard block
 block discarded – undo
504 503
 					// remember if server returned forward-attribute
505 504
 					$this->forward_attr_returned = isset($values[static::FORWARD_ATTR]);
506 505
 
507
-					$userData['mailForwardingAddress']	= self::getAttributePrefix($values[static::FORWARD_ATTR], static::FORWARD_PREFIX);
506
+					$userData['mailForwardingAddress'] = self::getAttributePrefix($values[static::FORWARD_ATTR], static::FORWARD_PREFIX);
508 507
 				}
509 508
 
510
-				if (static::MAILBOX_ATTR) $userData['mailMessageStore']	= $values[static::MAILBOX_ATTR][0];
509
+				if (static::MAILBOX_ATTR) $userData['mailMessageStore'] = $values[static::MAILBOX_ATTR][0];
511 510
 
512 511
 				$userData['deliveryMode'] = $deliveryMode;
513 512
 
514 513
 				// eg. suse stores all email addresses as aliases
515 514
 				if (static::REQUIRE_MAIL_AS_ALIAS &&
516
-					($k = array_search($userData['mailLocalAddress'],$userData['mailAlternateAddress'])) !== false)
515
+					($k = array_search($userData['mailLocalAddress'], $userData['mailAlternateAddress'])) !== false)
517 516
 				{
518 517
 					unset($userData['mailAlternateAddress'][$k]);
519 518
 					$userData['mailAlternateAddress'] = array_values($userData['mailAlternateAddress']);
@@ -547,9 +546,9 @@  discard block
 block discarded – undo
547 546
 	 * @return boolean true on success, false on error writing to ldap
548 547
 	 */
549 548
 	function setUserData($_uidnumber, array $_mailAlternateAddress, array $_mailForwardingAddress, $_deliveryMode,
550
-		$_accountStatus, $_mailLocalAddress, $_quota, $_forwarding_only=false, $_setMailbox=null)
549
+		$_accountStatus, $_mailLocalAddress, $_quota, $_forwarding_only = false, $_setMailbox = null)
551 550
 	{
552
-		unset($_forwarding_only);	// not used
551
+		unset($_forwarding_only); // not used
553 552
 
554 553
 		if (static::USERID_ATTR)
555 554
 		{
@@ -569,15 +568,15 @@  discard block
 block discarded – undo
569 568
 		$allValues 	= ldap_get_entries($ldap, $sri);
570 569
 
571 570
 		$accountDN 	= $allValues[0]['dn'];
572
-		$uid	   	= $allValues[0][static::USER_ATTR][0];
573
-		$objectClasses	= $allValues[0]['objectclass'];
571
+		$uid = $allValues[0][static::USER_ATTR][0];
572
+		$objectClasses = $allValues[0]['objectclass'];
574 573
 
575 574
 		unset($objectClasses['count']);
576 575
 
577
-		if(!in_array(static::SCHEMA,$objectClasses) && !in_array(strtolower(static::SCHEMA),$objectClasses))
576
+		if (!in_array(static::SCHEMA, $objectClasses) && !in_array(strtolower(static::SCHEMA), $objectClasses))
578 577
 		{
579
-			$objectClasses[]	= static::SCHEMA;
580
-			$newData['objectclass']	= $objectClasses;
578
+			$objectClasses[] = static::SCHEMA;
579
+			$newData['objectclass'] = $objectClasses;
581 580
 		}
582 581
 
583 582
 		sort($_mailAlternateAddress);
@@ -590,7 +589,7 @@  discard block
 block discarded – undo
590 589
 			self::setAttributePrefix($newData[static::ALIAS_ATTR], $_mailAlternateAddress, static::ALIAS_PREFIX);
591 590
 
592 591
 			// all email must be stored as alias for suse
593
-			if (static::REQUIRE_MAIL_AS_ALIAS && !in_array($_mailLocalAddress,(array)$_mailAlternateAddress))
592
+			if (static::REQUIRE_MAIL_AS_ALIAS && !in_array($_mailLocalAddress, (array)$_mailAlternateAddress))
594 593
 			{
595 594
 				self::setAttributePrefix($newData[static::ALIAS_ATTR], $_mailLocalAddress, static::ALIAS_PREFIX);
596 595
 			}
@@ -628,12 +627,12 @@  discard block
 block discarded – undo
628 627
 		if (static::QUOTA_ATTR)
629 628
 		{
630 629
 			self::setAttributePrefix($newData[static::QUOTA_ATTR],
631
-				(int)$_quota > 0 ? (int)$_quota*static::QUOTA_FACTOR : array(), static::QUOTA_PREFIX);
630
+				(int)$_quota > 0 ? (int)$_quota * static::QUOTA_FACTOR : array(), static::QUOTA_PREFIX);
632 631
 		}
633 632
 		// does schema support enabling/disabling mail via attribute
634 633
 		if (static::MAIL_ENABLE_ATTR)
635 634
 		{
636
-			$newData[static::MAIL_ENABLE_ATTR]	= $_accountStatus ?
635
+			$newData[static::MAIL_ENABLE_ATTR] = $_accountStatus ?
637 636
 				(static::MAIL_ENABLED == self::MAIL_ENABLED_USE_MAIL ? $_mailLocalAddress : static::MAIL_ENABLED) : array();
638 637
 		}
639 638
 		// if we have no mail-enabled attribute, but require primary mail in aliases-attr
@@ -681,7 +680,7 @@  discard block
 block discarded – undo
681 680
 			$uid = $GLOBALS['egw']->accounts->id2name($_accountID);
682 681
 			$filter = '(&'.static::USER_FILTER.'('.static::USER_ATTR.'='.Api\Ldap::quote($uid).'))';
683 682
 		}
684
-		$attributes	= array('dn', static::MAIL_ATTR, static::FORWARD_ATTR, 'objectclass');
683
+		$attributes = array('dn', static::MAIL_ATTR, static::FORWARD_ATTR, 'objectclass');
685 684
 		if (static::FORWARD_ONLY_ATTR)
686 685
 		{
687 686
 			$attributes[] = static::FORWARD_ONLY_ATTR;
@@ -692,12 +691,12 @@  discard block
 block discarded – undo
692 691
 		{
693 692
 			$newData = array();
694 693
 			$allValues = ldap_get_entries($ds, $sri);
695
-			$objectClasses  = $allValues[0]['objectclass'];
696
-			$newData['objectclass']	= $allValues[0]['objectclass'];
694
+			$objectClasses = $allValues[0]['objectclass'];
695
+			$newData['objectclass'] = $allValues[0]['objectclass'];
697 696
 
698 697
 			unset($newData['objectclass']['count']);
699 698
 
700
-			if(!in_array(static::SCHEMA,$objectClasses))
699
+			if (!in_array(static::SCHEMA, $objectClasses))
701 700
 			{
702 701
 				$newData['objectclass'][] = static::SCHEMA;
703 702
 			}
@@ -707,9 +706,9 @@  discard block
 block discarded – undo
707 706
 				$newData[static::FORWARD_ATTR] = $allValues[0][static::FORWARD_ATTR];
708 707
 				$forwards = self::getAttributePrefix($newData[static::FORWARD_ATTR], static::FORWARD_PREFIX);
709 708
 
710
-				if(!empty($_forwardingAddress))
709
+				if (!empty($_forwardingAddress))
711 710
 				{
712
-					if($forwards)
711
+					if ($forwards)
713 712
 					{
714 713
 						if (!is_array($_forwardingAddress))
715 714
 						{
@@ -752,7 +751,7 @@  discard block
 block discarded – undo
752 751
 			}
753 752
 			if ($this->debug) error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'{$allValues[0]['dn']}',".array2string($newData).')');
754 753
 
755
-			return ldap_modify ($ds, $allValues[0]['dn'], $newData);
754
+			return ldap_modify($ds, $allValues[0]['dn'], $newData);
756 755
 		}
757 756
 	}
758 757
 
@@ -794,9 +793,9 @@  discard block
 block discarded – undo
794 793
 		unset($entries['count']);
795 794
 
796 795
 		$mailboxes = array();
797
-		foreach($entries as $entry)
796
+		foreach ($entries as $entry)
798 797
 		{
799
-			if ($entry[static::USER_ATTR][0] == 'anonymous') continue;	// anonymous is never a mail-user!
798
+			if ($entry[static::USER_ATTR][0] == 'anonymous') continue; // anonymous is never a mail-user!
800 799
 			list($mailbox) = explode('@', $entry[static::MAILBOX_ATTR ? static::MAILBOX_ATTR : static::MAIL_ATTR][0]);
801 800
 			$mailboxes[$entry[static::USER_ATTR][0]] = $mailbox;
802 801
 		}
@@ -810,13 +809,13 @@  discard block
 block discarded – undo
810 809
 	 * @param string|array $values value(s) to set
811 810
 	 * @param string $prefix ='' prefix to use or ''
812 811
 	 */
813
-	protected static function setAttributePrefix(&$attribute, $values, $prefix='')
812
+	protected static function setAttributePrefix(&$attribute, $values, $prefix = '')
814 813
 	{
815 814
 		//$attribute_in = $attribute;
816 815
 		if (empty($attribute)) $attribute = array();
817 816
 		if (!is_array($attribute)) $attribute = (array)$attribute;
818 817
 
819
-		foreach((array)$values as $value)
818
+		foreach ((array)$values as $value)
820 819
 		{
821 820
 			$attribute[] = $prefix.$value;
822 821
 		}
@@ -831,7 +830,7 @@  discard block
 block discarded – undo
831 830
 	 * @param boolean $remove =true remove returned values from $attribute
832 831
 	 * @return array with values (prefix removed) or array() if nothing found
833 832
 	 */
834
-	protected static function getAttributePrefix(&$attribute, $prefix='', $remove=true)
833
+	protected static function getAttributePrefix(&$attribute, $prefix = '', $remove = true)
835 834
 	{
836 835
 		//$attribute_in = $attribute;
837 836
 		$values = array();
@@ -840,7 +839,7 @@  discard block
 block discarded – undo
840 839
 		{
841 840
 			unset($attribute['count']);
842 841
 
843
-			foreach($attribute as $key => $value)
842
+			foreach ($attribute as $key => $value)
844 843
 			{
845 844
 				if (!$prefix || stripos($value, $prefix) === 0)
846 845
 				{
Please login to merge, or discard this patch.
api/src/Session.php 4 patches
Doc Comments   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -311,6 +311,7 @@  discard block
 block discarded – undo
311 311
 	 * Encrypt the variables in the session
312 312
 	 *
313 313
 	 * Is called by self::__destruct().
314
+	 * @param string $kp3
314 315
 	 */
315 316
 	static function encrypt($kp3)
316 317
 	{
@@ -439,7 +440,7 @@  discard block
 block discarded – undo
439 440
 	 * @param boolean $no_session =false dont create a real session, eg. for GroupDAV clients using only basic auth, no cookie support
440 441
 	 * @param boolean $auth_check =true if false, the user is loged in without checking his password (eg. for single sign on), default = true
441 442
 	 * @param boolean $fail_on_forced_password_change =false true: do NOT create session, if password change requested
442
-	 * @return string|boolean session id or false if session was not created, $this->(cd_)reason contains cause
443
+	 * @return false|string session id or false if session was not created, $this->(cd_)reason contains cause
443 444
 	 */
444 445
 	function create($login,$passwd = '',$passwd_type = '',$no_session=false,$auth_check=true,$fail_on_forced_password_change=false)
445 446
 	{
@@ -1021,7 +1022,7 @@  discard block
 block discarded – undo
1021 1022
 	/**
1022 1023
 	 * Terminate a session
1023 1024
 	 *
1024
-	 * @param int|string $sessionid nummeric or php session id of session to be terminated
1025
+	 * @param string $sessionid nummeric or php session id of session to be terminated
1025 1026
 	 * @param string $kp3
1026 1027
 	 * @return boolean true on success, false on error
1027 1028
 	 */
Please login to merge, or discard this patch.
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -74,60 +74,60 @@  discard block
 block discarded – undo
74 74
 	const EGW_SESSION_NAME = 'sessionid';
75 75
 
76 76
 	/**
77
-	* current user login (account_lid@domain)
78
-	*
79
-	* @var string
80
-	*/
77
+	 * current user login (account_lid@domain)
78
+	 *
79
+	 * @var string
80
+	 */
81 81
 	var $login;
82 82
 
83 83
 	/**
84
-	* current user password
85
-	*
86
-	* @var string
87
-	*/
84
+	 * current user password
85
+	 *
86
+	 * @var string
87
+	 */
88 88
 	var $passwd;
89 89
 
90 90
 	/**
91
-	* current user db/ldap account id
92
-	*
93
-	* @var int
94
-	*/
91
+	 * current user db/ldap account id
92
+	 *
93
+	 * @var int
94
+	 */
95 95
 	var $account_id;
96 96
 
97 97
 	/**
98
-	* current user account login id (without the eGW-domain/-instance part
99
-	*
100
-	* @var string
101
-	*/
98
+	 * current user account login id (without the eGW-domain/-instance part
99
+	 *
100
+	 * @var string
101
+	 */
102 102
 	var $account_lid;
103 103
 
104 104
 	/**
105
-	* domain for current user
106
-	*
107
-	* @var string
108
-	*/
105
+	 * domain for current user
106
+	 *
107
+	 * @var string
108
+	 */
109 109
 	var $account_domain;
110 110
 
111 111
 	/**
112
-	* type flag, A - anonymous session, N - None, normal session
113
-	*
114
-	* @var string
115
-	*/
112
+	 * type flag, A - anonymous session, N - None, normal session
113
+	 *
114
+	 * @var string
115
+	 */
116 116
 	var $session_flags;
117 117
 
118 118
 	/**
119
-	* current user session id
120
-	*
121
-	* @var string
122
-	*/
119
+	 * current user session id
120
+	 *
121
+	 * @var string
122
+	 */
123 123
 	var $sessionid;
124 124
 
125 125
 	/**
126
-	* an other session specific id (md5 from a random string),
127
-	* used together with the sessionid for xmlrpc basic auth and the encryption of session-data (if that's enabled)
128
-	*
129
-	* @var string
130
-	*/
126
+	 * an other session specific id (md5 from a random string),
127
+	 * used together with the sessionid for xmlrpc basic auth and the encryption of session-data (if that's enabled)
128
+	 *
129
+	 * @var string
130
+	 */
131 131
 	var $kp3;
132 132
 
133 133
 	/**
@@ -138,17 +138,17 @@  discard block
 block discarded – undo
138 138
 	var $sessionid_access_log;
139 139
 
140 140
 	/**
141
-	* name of XML-RPC/SOAP method called
142
-	*
143
-	* @var string
144
-	*/
141
+	 * name of XML-RPC/SOAP method called
142
+	 *
143
+	 * @var string
144
+	 */
145 145
 	var $xmlrpc_method_called;
146 146
 
147 147
 	/**
148
-	* Array with the name of the system domains
149
-	*
150
-	* @var array
151
-	*/
148
+	 * Array with the name of the system domains
149
+	 *
150
+	 * @var array
151
+	 */
152 152
 	private $egw_domains;
153 153
 
154 154
 	/**
@@ -249,9 +249,9 @@  discard block
 block discarded – undo
249 249
 
250 250
 		// set session_timeout from global php.ini and default to 14400=4h, if not set
251 251
 		if (!($GLOBALS['egw_info']['server']['sessions_timeout'] = ini_get('session.gc_maxlifetime')))
252
-      	{
253
-      		ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout']=14400);
254
-      	}
252
+	  	{
253
+	  		ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout']=14400);
254
+	  	}
255 255
 	}
256 256
 
257 257
 	/**
@@ -673,14 +673,14 @@  discard block
 block discarded – undo
673 673
 	const FALSE_ID_CACHE_PREFIX = 'false_id-';
674 674
 
675 675
 	/**
676
-    * Write or update (for logout) the access_log
677
-	*
678
-	* @param string|int $sessionid nummeric or PHP session id or 0 for unsuccessful logins
679
-	* @param string $login ='' account_lid (evtl. with domain) or '' for setting the logout-time
680
-	* @param string $user_ip ='' ip to log
681
-	* @param int $account_id =0 numerical account_id
682
-	* @return int $sessionid primary key of egw_access_log for login, null otherwise
683
-	*/
676
+	 * Write or update (for logout) the access_log
677
+	 *
678
+	 * @param string|int $sessionid nummeric or PHP session id or 0 for unsuccessful logins
679
+	 * @param string $login ='' account_lid (evtl. with domain) or '' for setting the logout-time
680
+	 * @param string $user_ip ='' ip to log
681
+	 * @param int $account_id =0 numerical account_id
682
+	 * @return int $sessionid primary key of egw_access_log for login, null otherwise
683
+	 */
684 684
 	private function log_access($sessionid,$login='',$user_ip='',$account_id=0)
685 685
 	{
686 686
 		$now = time();
@@ -740,7 +740,7 @@  discard block
 block discarded – undo
740 740
 
741 741
 	/**
742 742
 	 * Protect against brute force attacks, block login if too many unsuccessful login attmepts
743
-     *
743
+	 *
744 744
 	 * @param string $login account_lid (evtl. with domain)
745 745
 	 * @param string $ip ip of the user
746 746
 	 * @returns bool login blocked?
Please login to merge, or discard this patch.
Spacing   +170 added lines, -173 removed lines patch added patch discarded remove patch
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 	const CD_BAD_LOGIN_OR_PASSWORD = 5;
167 167
 	const CD_FORCE_PASSWORD_CHANGE = 97;
168 168
 	const CD_ACCOUNT_EXPIRED = 98;
169
-	const CD_BLOCKED = 99;	// to many failed attempts to loing
169
+	const CD_BLOCKED = 99; // to many failed attempts to loing
170 170
 
171 171
 	/**
172 172
 	 * Verbose reason why session creation failed
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 	 *
188 188
 	 * @param array $domain_names =null domain-names used in this install
189 189
 	 */
190
-	function __construct(array $domain_names=null)
190
+	function __construct(array $domain_names = null)
191 191
 	{
192 192
 		$this->required_files = $_SESSION[self::EGW_REQUIRED_FILES];
193 193
 
@@ -203,27 +203,27 @@  discard block
 block discarded – undo
203 203
 			$save_rep = false;
204 204
 			if (!isset($GLOBALS['egw_info']['server']['max_access_log_age']))
205 205
 			{
206
-				$GLOBALS['egw_info']['server']['max_access_log_age'] = 90;	// default 90 days
206
+				$GLOBALS['egw_info']['server']['max_access_log_age'] = 90; // default 90 days
207 207
 				$save_rep = true;
208 208
 			}
209 209
 			if (!isset($GLOBALS['egw_info']['server']['block_time']))
210 210
 			{
211
-				$GLOBALS['egw_info']['server']['block_time'] = 1;	// default 1min, its enough to slow down brute force attacks
211
+				$GLOBALS['egw_info']['server']['block_time'] = 1; // default 1min, its enough to slow down brute force attacks
212 212
 				$save_rep = true;
213 213
 			}
214 214
 			if (!isset($GLOBALS['egw_info']['server']['num_unsuccessful_id']))
215 215
 			{
216
-				$GLOBALS['egw_info']['server']['num_unsuccessful_id']  = 3;	// default 3 trys per id
216
+				$GLOBALS['egw_info']['server']['num_unsuccessful_id'] = 3; // default 3 trys per id
217 217
 				$save_rep = true;
218 218
 			}
219 219
 			if (!isset($GLOBALS['egw_info']['server']['num_unsuccessful_ip']))
220 220
 			{
221
-				$GLOBALS['egw_info']['server']['num_unsuccessful_ip']  = $GLOBALS['egw_info']['server']['num_unsuccessful_id'] * 5;	// default is 5 times as high as the id default; since accessing via proxy is quite common
221
+				$GLOBALS['egw_info']['server']['num_unsuccessful_ip'] = $GLOBALS['egw_info']['server']['num_unsuccessful_id'] * 5; // default is 5 times as high as the id default; since accessing via proxy is quite common
222 222
 				$save_rep = true;
223 223
 			}
224 224
 			if (!isset($GLOBALS['egw_info']['server']['install_id']))
225 225
 			{
226
-				$GLOBALS['egw_info']['server']['install_id']  = md5(Auth::randomstring(15));
226
+				$GLOBALS['egw_info']['server']['install_id'] = md5(Auth::randomstring(15));
227 227
 			}
228 228
 			if (!isset($GLOBALS['egw_info']['server']['max_history']))
229 229
 			{
@@ -235,12 +235,12 @@  discard block
 block discarded – undo
235 235
 			{
236 236
 				$config = new Config('phpgwapi');
237 237
 				$config->read_repository();
238
-				$config->value('max_access_log_age',$GLOBALS['egw_info']['server']['max_access_log_age']);
239
-				$config->value('block_time',$GLOBALS['egw_info']['server']['block_time']);
240
-				$config->value('num_unsuccessful_id',$GLOBALS['egw_info']['server']['num_unsuccessful_id']);
241
-				$config->value('num_unsuccessful_ip',$GLOBALS['egw_info']['server']['num_unsuccessful_ip']);
242
-				$config->value('install_id',$GLOBALS['egw_info']['server']['install_id']);
243
-				$config->value('max_history',$GLOBALS['egw_info']['server']['max_history']);
238
+				$config->value('max_access_log_age', $GLOBALS['egw_info']['server']['max_access_log_age']);
239
+				$config->value('block_time', $GLOBALS['egw_info']['server']['block_time']);
240
+				$config->value('num_unsuccessful_id', $GLOBALS['egw_info']['server']['num_unsuccessful_id']);
241
+				$config->value('num_unsuccessful_ip', $GLOBALS['egw_info']['server']['num_unsuccessful_ip']);
242
+				$config->value('install_id', $GLOBALS['egw_info']['server']['install_id']);
243
+				$config->value('max_history', $GLOBALS['egw_info']['server']['max_history']);
244 244
 				$config->save_repository();
245 245
 			}
246 246
 		}
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 		// set session_timeout from global php.ini and default to 14400=4h, if not set
250 250
 		if (!($GLOBALS['egw_info']['server']['sessions_timeout'] = ini_get('session.gc_maxlifetime')))
251 251
       	{
252
-      		ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout']=14400);
252
+      		ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout'] = 14400);
253 253
       	}
254 254
 	}
255 255
 
@@ -324,15 +324,15 @@  discard block
 block discarded – undo
324 324
 
325 325
 		if (!isset($_SESSION[self::EGW_SESSION_ENCRYPTED]) && self::init_crypt($kp3))
326 326
 		{
327
-			foreach(self::$egw_session_vars as $name)
327
+			foreach (self::$egw_session_vars as $name)
328 328
 			{
329 329
 				if (isset($_SESSION[$name]))
330 330
 				{
331
-					$_SESSION[$name] = mcrypt_generic(self::$mcrypt,serialize($_SESSION[$name]));
331
+					$_SESSION[$name] = mcrypt_generic(self::$mcrypt, serialize($_SESSION[$name]));
332 332
 					//error_log(__METHOD__."() 'encrypting' session var: $name, len=".strlen($_SESSION[$name]));
333 333
 				}
334 334
 			}
335
-			$_SESSION[self::EGW_SESSION_ENCRYPTED] = true;	// flag session as encrypted
335
+			$_SESSION[self::EGW_SESSION_ENCRYPTED] = true; // flag session as encrypted
336 336
 
337 337
 			mcrypt_generic_deinit(self::$mcrypt);
338 338
 			self::$mcrypt = null;
@@ -347,24 +347,24 @@  discard block
 block discarded – undo
347 347
 	 * @param boolean $recursion =true if true call itself for every item > $limit
348 348
 	 * @param int $limit =1000 log only differences > $limit
349 349
 	 */
350
-	static function log_session_usage(&$arr,$label,$recursion=true,$limit=1000)
350
+	static function log_session_usage(&$arr, $label, $recursion = true, $limit = 1000)
351 351
 	{
352 352
 		if (!is_array($arr)) return;
353 353
 
354 354
 		$sizes = array();
355
-		foreach($arr as $key => &$data)
355
+		foreach ($arr as $key => &$data)
356 356
 		{
357 357
 			$sizes[$key] = strlen(serialize($data));
358 358
 		}
359
-		arsort($sizes,SORT_NUMERIC);
360
-		foreach($sizes as $key => $size)
359
+		arsort($sizes, SORT_NUMERIC);
360
+		foreach ($sizes as $key => $size)
361 361
 		{
362 362
 			$diff = $size - (int)$_SESSION[$label.'-sizes'][$key];
363 363
 			$_SESSION[$label.'-sizes'][$key] = $size;
364 364
 			if ($diff > $limit)
365 365
 			{
366 366
 				error_log("strlen({$label}[$key])=".Vfs::hsize($size).", diff=".Vfs::hsize($diff));
367
-				if ($recursion) self::log_session_usage($arr[$key],$label.'['.$key.']',$recursion,$limit);
367
+				if ($recursion) self::log_session_usage($arr[$key], $label.'['.$key.']', $recursion, $limit);
368 368
 			}
369 369
 		}
370 370
 	}
@@ -379,15 +379,15 @@  discard block
 block discarded – undo
379 379
 	{
380 380
 		if ($_SESSION[self::EGW_SESSION_ENCRYPTED] && self::init_crypt(self::get_request('kp3')))
381 381
 		{
382
-			foreach(self::$egw_session_vars as $name)
382
+			foreach (self::$egw_session_vars as $name)
383 383
 			{
384 384
 				if (isset($_SESSION[$name]))
385 385
 				{
386
-					$_SESSION[$name] = unserialize(trim(mdecrypt_generic(self::$mcrypt,$_SESSION[$name])));
386
+					$_SESSION[$name] = unserialize(trim(mdecrypt_generic(self::$mcrypt, $_SESSION[$name])));
387 387
 					//error_log(__METHOD__."() 'decrypting' session var $name: gettype($name) = ".gettype($_SESSION[$name]));
388 388
 				}
389 389
 			}
390
-			unset($_SESSION[self::EGW_SESSION_ENCRYPTED]);	// delete encryption flag
390
+			unset($_SESSION[self::EGW_SESSION_ENCRYPTED]); // delete encryption flag
391 391
 		}
392 392
 	}
393 393
 
@@ -402,13 +402,13 @@  discard block
 block discarded – undo
402 402
 	 */
403 403
 	static private function init_crypt($kp3)
404 404
 	{
405
-		if(!$GLOBALS['egw_info']['server']['mcrypt_enabled'])
405
+		if (!$GLOBALS['egw_info']['server']['mcrypt_enabled'])
406 406
 		{
407
-			return false;	// session encryption is switched off
407
+			return false; // session encryption is switched off
408 408
 		}
409 409
 		if ($GLOBALS['egw_info']['currentapp'] == 'syncml' || !$kp3)
410 410
 		{
411
-			$kp3 = 'staticsyncmlkp3';	// syncml has no kp3!
411
+			$kp3 = 'staticsyncmlkp3'; // syncml has no kp3!
412 412
 		}
413 413
 		if (is_null(self::$mcrypt))
414 414
 		{
@@ -424,9 +424,9 @@  discard block
 block discarded – undo
424 424
 			}
425 425
 			$iv_size = mcrypt_enc_get_iv_size(self::$mcrypt);
426 426
 			$iv = !isset($GLOBALS['egw_info']['server']['mcrypt_iv']) || strlen($GLOBALS['egw_info']['server']['mcrypt_iv']) < $iv_size ?
427
-				mcrypt_create_iv ($iv_size, MCRYPT_RAND) : substr($GLOBALS['egw_info']['server']['mcrypt_iv'],0,$iv_size);
427
+				mcrypt_create_iv ($iv_size, MCRYPT_RAND) : substr($GLOBALS['egw_info']['server']['mcrypt_iv'], 0, $iv_size);
428 428
 
429
-			if (mcrypt_generic_init(self::$mcrypt,$kp3, $iv) < 0)
429
+			if (mcrypt_generic_init(self::$mcrypt, $kp3, $iv) < 0)
430 430
 			{
431 431
 				error_log(__METHOD__."() could not initialise mcrypt, sessions get NOT encrypted!");
432 432
 				return self::$mcrypt = false;
@@ -446,7 +446,7 @@  discard block
 block discarded – undo
446 446
 	 * @param boolean $fail_on_forced_password_change =false true: do NOT create session, if password change requested
447 447
 	 * @return string|boolean session id or false if session was not created, $this->(cd_)reason contains cause
448 448
 	 */
449
-	function create($login,$passwd = '',$passwd_type = '',$no_session=false,$auth_check=true,$fail_on_forced_password_change=false)
449
+	function create($login, $passwd = '', $passwd_type = '', $no_session = false, $auth_check = true, $fail_on_forced_password_change = false)
450 450
 	{
451 451
 		try {
452 452
 			if (is_array($login))
@@ -464,9 +464,9 @@  discard block
 block discarded – undo
464 464
 			}
465 465
 			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) starting ...");
466 466
 
467
-			self::split_login_domain($login,$this->account_lid,$this->account_domain);
467
+			self::split_login_domain($login, $this->account_lid, $this->account_domain);
468 468
 			// add domain to the login, if not already there
469
-			if (substr($this->login,-strlen($this->account_domain)-1) != '@'.$this->account_domain)
469
+			if (substr($this->login, -strlen($this->account_domain) - 1) != '@'.$this->account_domain)
470 470
 			{
471 471
 				$this->login .= '@'.$this->account_domain;
472 472
 			}
@@ -483,7 +483,7 @@  discard block
 block discarded – undo
483 483
 			{
484 484
 				$this->account_domain = $GLOBALS['egw_info']['user']['domain'];
485 485
 			}
486
-			elseif($this->account_domain != $GLOBALS['egw_info']['user']['domain'])
486
+			elseif ($this->account_domain != $GLOBALS['egw_info']['user']['domain'])
487 487
 			{
488 488
 				throw new Exception("Wrong domain! '$this->account_domain' != '{$GLOBALS['egw_info']['user']['domain']}'");
489 489
 			}
@@ -491,9 +491,9 @@  discard block
 block discarded – undo
491 491
 
492 492
 			$user_ip = self::getuser_ip();
493 493
 
494
-			$this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid,'account_lid','u');
494
+			$this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid, 'account_lid', 'u');
495 495
 
496
-			if (($blocked = $this->login_blocked($login,$user_ip)) ||	// too many unsuccessful attempts
496
+			if (($blocked = $this->login_blocked($login, $user_ip)) || // too many unsuccessful attempts
497 497
 				$GLOBALS['egw_info']['server']['global_denied_users'][$this->account_lid] ||
498 498
 				$auth_check && !$GLOBALS['egw']->auth->authenticate($this->account_lid, $this->passwd, $this->passwd_type) ||
499 499
 				$this->account_id && $GLOBALS['egw']->accounts->get_type($this->account_id) == 'g')
@@ -502,9 +502,9 @@  discard block
 block discarded – undo
502 502
 				$this->cd_reason = $blocked ? self::CD_BLOCKED : self::CD_BAD_LOGIN_OR_PASSWORD;
503 503
 
504 504
 				// we dont log anon users as it would block the website
505
-				if (!$GLOBALS['egw']->acl->get_specific_rights_for_account($this->account_id,'anonymous','phpgwapi'))
505
+				if (!$GLOBALS['egw']->acl->get_specific_rights_for_account($this->account_id, 'anonymous', 'phpgwapi'))
506 506
 				{
507
-					$this->log_access($this->reason,$login,$user_ip,0);	// log unsuccessfull login
507
+					$this->log_access($this->reason, $login, $user_ip, 0); // log unsuccessfull login
508 508
 				}
509 509
 				if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
510 510
 				return false;
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
 			if ($this->account_lid != ($lid = $GLOBALS['egw']->accounts->id2name($this->account_id)))
527 527
 			{
528 528
 				$this->account_lid = $lid;
529
-				$this->login = $lid.substr($this->login,strlen($lid));
529
+				$this->login = $lid.substr($this->login, strlen($lid));
530 530
 			}
531 531
 
532 532
 			$GLOBALS['egw_info']['user']['account_id'] = $this->account_id;
@@ -548,7 +548,7 @@  discard block
 block discarded – undo
548 548
 				}
549 549
 				$this->sessionid = session_id();
550 550
 			}
551
-			$this->kp3       = Auth::randomstring(24);
551
+			$this->kp3 = Auth::randomstring(24);
552 552
 
553 553
 			$GLOBALS['egw_info']['user'] = $this->read_repositories();
554 554
 			if ($GLOBALS['egw']->accounts->is_expired($GLOBALS['egw_info']['user']))
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
 
563 563
 			Cache::setSession('phpgwapi', 'password', base64_encode($this->passwd));
564 564
 
565
-			if ($GLOBALS['egw']->acl->check('anonymous',1,'phpgwapi'))
565
+			if ($GLOBALS['egw']->acl->check('anonymous', 1, 'phpgwapi'))
566 566
 			{
567 567
 				$this->session_flags = 'A';
568 568
 			}
@@ -580,39 +580,39 @@  discard block
 block discarded – undo
580 580
 				'passwd'         => $this->passwd,
581 581
 				'account_domain' => $this->account_domain,
582 582
 				'user_ip'        => $user_ip,
583
-			),'',true)))	// true = run hooks from all apps, not just the ones the current user has perms to run
583
+			), '', true)))	// true = run hooks from all apps, not just the ones the current user has perms to run
584 584
 			{
585
-				foreach($hook_result as $reason)
585
+				foreach ($hook_result as $reason)
586 586
 				{
587 587
 					if ($reason)	// called hook requests to deny the session
588 588
 					{
589 589
 						$this->reason = $this->cd_reason = $reason;
590
-						$this->log_access($this->reason,$login,$user_ip,0);		// log unsuccessfull login
590
+						$this->log_access($this->reason, $login, $user_ip, 0); // log unsuccessfull login
591 591
 						if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
592 592
 						return false;
593 593
 					}
594 594
 				}
595 595
 			}
596 596
 			$GLOBALS['egw']->db->transaction_begin();
597
-			$this->register_session($this->login,$user_ip,$now,$this->session_flags);
597
+			$this->register_session($this->login, $user_ip, $now, $this->session_flags);
598 598
 			if ($this->session_flags != 'A')		// dont log anonymous sessions
599 599
 			{
600
-				$this->sessionid_access_log = $this->log_access($this->sessionid,$login,$user_ip,$this->account_id);
600
+				$this->sessionid_access_log = $this->log_access($this->sessionid, $login, $user_ip, $this->account_id);
601 601
 			}
602 602
 			Cache::setSession('phpgwapi', 'account_previous_login', $GLOBALS['egw']->auth->previous_login);
603
-			$GLOBALS['egw']->accounts->update_lastlogin($this->account_id,$user_ip);
603
+			$GLOBALS['egw']->accounts->update_lastlogin($this->account_id, $user_ip);
604 604
 			$GLOBALS['egw']->db->transaction_commit();
605 605
 
606 606
 			if ($GLOBALS['egw_info']['server']['usecookies'] && !$no_session)
607 607
 			{
608
-				self::egw_setcookie(self::EGW_SESSION_NAME,$this->sessionid);
609
-				self::egw_setcookie('kp3',$this->kp3);
610
-				self::egw_setcookie('domain',$this->account_domain);
608
+				self::egw_setcookie(self::EGW_SESSION_NAME, $this->sessionid);
609
+				self::egw_setcookie('kp3', $this->kp3);
610
+				self::egw_setcookie('domain', $this->account_domain);
611 611
 			}
612 612
 			if ($GLOBALS['egw_info']['server']['usecookies'] && !$no_session || isset($_COOKIE['last_loginid']))
613 613
 			{
614
-				self::egw_setcookie('last_loginid', $this->account_lid ,$now+1209600); /* For 2 weeks */
615
-				self::egw_setcookie('last_domain',$this->account_domain,$now+1209600);
614
+				self::egw_setcookie('last_loginid', $this->account_lid, $now + 1209600); /* For 2 weeks */
615
+				self::egw_setcookie('last_domain', $this->account_domain, $now + 1209600);
616 616
 			}
617 617
 			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) successfull sessionid=$this->sessionid");
618 618
 
@@ -628,13 +628,13 @@  discard block
 block discarded – undo
628 628
 				'user_ip'        => $user_ip,
629 629
 				'session_type'   => Session\Type::get($_SERVER['REQUEST_URI'],
630 630
 					$GLOBALS['egw_info']['flags']['current_app'],
631
-					true),	// true return WebGUI instead of login, as we are logged in now
632
-			),'',true);
631
+					true), // true return WebGUI instead of login, as we are logged in now
632
+			), '', true);
633 633
 
634 634
 			return $this->sessionid;
635 635
 		}
636 636
 		// catch all exceptions, as their (allways logged) trace (eg. on a database error) would contain the user password
637
-		catch(Exception $e) {
637
+		catch (Exception $e) {
638 638
 			$this->reason = $this->cd_reason = $e->getMessage();
639 639
 			error_log(__METHOD__."('$login', ".array2string(str_repeat('*', strlen($passwd))).
640 640
 				", '$passwd_type', no_session=".array2string($no_session).
@@ -653,13 +653,12 @@  discard block
 block discarded – undo
653 653
 	 * @param int $now
654 654
 	 * @param string $session_flags
655 655
 	 */
656
-	private function register_session($login,$user_ip,$now,$session_flags)
656
+	private function register_session($login, $user_ip, $now, $session_flags)
657 657
 	{
658 658
 		// restore session vars set before session was started
659 659
 		if (is_array($this->required_files))
660 660
 		{
661
-			$_SESSION[self::EGW_REQUIRED_FILES] = !is_array($_SESSION[self::EGW_REQUIRED_FILES]) ? $this->required_files :
662
-				array_unique(array_merge($_SESSION[self::EGW_REQUIRED_FILES],$this->required_files));
661
+			$_SESSION[self::EGW_REQUIRED_FILES] = !is_array($_SESSION[self::EGW_REQUIRED_FILES]) ? $this->required_files : array_unique(array_merge($_SESSION[self::EGW_REQUIRED_FILES], $this->required_files));
663 662
 			unset($this->required_files);
664 663
 		}
665 664
 		$_SESSION[self::EGW_SESSION_VAR] = array(
@@ -695,13 +694,13 @@  discard block
 block discarded – undo
695 694
 	* @param int $account_id =0 numerical account_id
696 695
 	* @return int $sessionid primary key of egw_access_log for login, null otherwise
697 696
 	*/
698
-	private function log_access($sessionid,$login='',$user_ip='',$account_id=0)
697
+	private function log_access($sessionid, $login = '', $user_ip = '', $account_id = 0)
699 698
 	{
700 699
 		$now = time();
701 700
 
702 701
 		if ($login)
703 702
 		{
704
-			$GLOBALS['egw']->db->insert(self::ACCESS_LOG_TABLE,array(
703
+			$GLOBALS['egw']->db->insert(self::ACCESS_LOG_TABLE, array(
705 704
 				'session_php' => $sessionid,
706 705
 				'loginid'   => $login,
707 706
 				'ip'        => $user_ip,
@@ -709,20 +708,20 @@  discard block
 block discarded – undo
709 708
 				'account_id'=> $account_id,
710 709
 				'user_agent'=> $_SERVER['HTTP_USER_AGENT'],
711 710
 				'session_dla'    => $now,
712
-				'session_action' => $this->update_dla(false),	// dont update egw_access_log
713
-			),false,__LINE__,__FILE__);
711
+				'session_action' => $this->update_dla(false), // dont update egw_access_log
712
+			), false, __LINE__, __FILE__);
714 713
 
715
-			$ret = $GLOBALS['egw']->db->get_last_insert_id(self::ACCESS_LOG_TABLE,'sessionid');
714
+			$ret = $GLOBALS['egw']->db->get_last_insert_id(self::ACCESS_LOG_TABLE, 'sessionid');
716 715
 
717 716
 			// if we can not store failed login attempts in database, store it in cache
718 717
 			if (!$ret && !$account_id)
719 718
 			{
720 719
 				Cache::setInstance(__CLASS__, self::FALSE_IP_CACHE_PREFIX.$user_ip,
721
-					1+Cache::getInstance(__CLASS__, self::FALSE_IP_CACHE_PREFIX.$user_ip),
720
+					1 + Cache::getInstance(__CLASS__, self::FALSE_IP_CACHE_PREFIX.$user_ip),
722 721
 					$GLOBALS['egw_info']['server']['block_time'] * 60);
723 722
 
724 723
 				Cache::setInstance(__CLASS__, self::FALSE_ID_CACHE_PREFIX.$login,
725
-					1+Cache::getInstance(__CLASS__, self::FALSE_ID_CACHE_PREFIX.$login),
724
+					1 + Cache::getInstance(__CLASS__, self::FALSE_ID_CACHE_PREFIX.$login),
726 725
 					$GLOBALS['egw_info']['server']['block_time'] * 60);
727 726
 			}
728 727
 		}
@@ -732,20 +731,20 @@  discard block
 block discarded – undo
732 731
 			{
733 732
 				$sessionid = $this->sessionid_access_log;
734 733
 			}
735
-			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE,array(
734
+			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE, array(
736 735
 				'lo' => $now
737
-			),is_numeric($sessionid) ? array(
736
+			), is_numeric($sessionid) ? array(
738 737
 				'sessionid' => $sessionid,
739 738
 			) : array(
740 739
 				'session_php' => $sessionid,
741
-			),__LINE__,__FILE__);
740
+			), __LINE__, __FILE__);
742 741
 
743 742
 			// run maintenance only on logout, to not delay login
744 743
 			if ($GLOBALS['egw_info']['server']['max_access_log_age'])
745 744
 			{
746 745
 				$max_age = $now - $GLOBALS['egw_info']['server']['max_access_log_age'] * 24 * 60 * 60;
747 746
 
748
-				$GLOBALS['egw']->db->delete(self::ACCESS_LOG_TABLE,"li < $max_age",__LINE__,__FILE__);
747
+				$GLOBALS['egw']->db->delete(self::ACCESS_LOG_TABLE, "li < $max_age", __LINE__, __FILE__);
749 748
 			}
750 749
 		}
751 750
 		//error_log(__METHOD__."('$sessionid', '$login', '$user_ip', $account_id) returning ".array2string($ret));
@@ -759,12 +758,12 @@  discard block
 block discarded – undo
759 758
 	 * @param string $ip ip of the user
760 759
 	 * @returns bool login blocked?
761 760
 	 */
762
-	private function login_blocked($login,$ip)
761
+	private function login_blocked($login, $ip)
763 762
 	{
764 763
 		$block_time = time() - $GLOBALS['egw_info']['server']['block_time'] * 60;
765 764
 
766 765
 		$false_id = $false_ip = 0;
767
-		foreach($GLOBALS['egw']->db->union(array(
766
+		foreach ($GLOBALS['egw']->db->union(array(
768 767
 			array(
769 768
 				'table' => self::ACCESS_LOG_TABLE,
770 769
 				'cols'  => "'false_ip' AS name,COUNT(*) AS num",
@@ -806,28 +805,28 @@  discard block
 block discarded – undo
806 805
 		//error_log(__METHOD__."('$login', '$ip') false_ip=$false_ip, false_id=$false_id --> blocked=".array2string($blocked));
807 806
 
808 807
 		if ($blocked && $GLOBALS['egw_info']['server']['admin_mails'] &&
809
-			$GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time()-5*60)	// max. one mail every 5mins
808
+			$GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time() - 5 * 60)	// max. one mail every 5mins
810 809
 		{
811 810
 			try {
812 811
 				$mailer = new Mailer();
813 812
 				// notify admin(s) via email
814 813
 				$mailer->setFrom('eGroupWare@'.$GLOBALS['egw_info']['server']['mail_suffix']);
815
-				$mailer->addHeader('Subject', lang("eGroupWare: login blocked for user '%1', IP %2",$login,$ip));
816
-				$mailer->setBody(lang("Too many unsucessful attempts to login: %1 for the user '%2', %3 for the IP %4",$false_id,$login,$false_ip,$ip));
817
-				foreach(preg_split('/,\s*/',$GLOBALS['egw_info']['server']['admin_mails']) as $mail)
814
+				$mailer->addHeader('Subject', lang("eGroupWare: login blocked for user '%1', IP %2", $login, $ip));
815
+				$mailer->setBody(lang("Too many unsucessful attempts to login: %1 for the user '%2', %3 for the IP %4", $false_id, $login, $false_ip, $ip));
816
+				foreach (preg_split('/,\s*/', $GLOBALS['egw_info']['server']['admin_mails']) as $mail)
818 817
 				{
819 818
 					$mailer->addAddress($mail);
820 819
 				}
821 820
 				$mailer->send();
822 821
 			}
823
-			catch(\Exception $e) {
822
+			catch (\Exception $e) {
824 823
 				// ignore exception, but log it, to block the account and give a correct error-message to user
825 824
 				error_log(__METHOD__."('$login', '$ip') ".$e->getMessage());
826 825
 			}
827 826
 			// save time of mail, to not send to many mails
828 827
 			$config = new Config('phpgwapi');
829 828
 			$config->read_repository();
830
-			$config->value('login_blocked_mail_time',time());
829
+			$config->value('login_blocked_mail_time', time());
831 830
 			$config->save_repository();
832 831
 		}
833 832
 		return $blocked;
@@ -848,7 +847,7 @@  discard block
 block discarded – undo
848 847
 	 * @param boolean $only_basic_auth =false return only a basic auth pseudo sessionid, default no
849 848
 	 * @return string
850 849
 	 */
851
-	static function get_sessionid($only_basic_auth=false)
850
+	static function get_sessionid($only_basic_auth = false)
852 851
 	{
853 852
 		// for WebDAV and GroupDAV we use a pseudo sessionid created from md5(user:passwd)
854 853
 		// --> allows this stateless protocolls which use basic auth to use sessions!
@@ -875,11 +874,11 @@  discard block
 block discarded – undo
875 874
 				EGW_SERVER_ROOT.':'.self::getuser_ip().':'.filemtime(EGW_SERVER_ROOT.'/api/setup/setup.inc.php').
876 875
 				':'.$_SERVER['HTTP_USER_AGENT']);
877 876
 		}
878
-		elseif(!$only_basic_auth && isset($_REQUEST[self::EGW_SESSION_NAME]))
877
+		elseif (!$only_basic_auth && isset($_REQUEST[self::EGW_SESSION_NAME]))
879 878
 		{
880 879
 			$sessionid = $_REQUEST[self::EGW_SESSION_NAME];
881 880
 		}
882
-		elseif(!$only_basic_auth && isset($_COOKIE[self::EGW_SESSION_NAME]))
881
+		elseif (!$only_basic_auth && isset($_COOKIE[self::EGW_SESSION_NAME]))
883 882
 		{
884 883
 			$sessionid = $_COOKIE[self::EGW_SESSION_NAME];
885 884
 		}
@@ -887,7 +886,7 @@  discard block
 block discarded – undo
887 886
 		{
888 887
 			$sessionid = false;
889 888
 		}
890
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid,true));
889
+		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid, true));
891 890
 		return $sessionid;
892 891
 	}
893 892
 
@@ -903,9 +902,7 @@  discard block
 block discarded – undo
903 902
 	 */
904 903
 	static function get_request($name)
905 904
 	{
906
-		return isset($_REQUEST[$name]) ? $_REQUEST[$name] :
907
-			(isset($_COOKIE[$name]) ? $_COOKIE[$name] :
908
-			(isset($_COOKIE[$name=ucfirst($name)]) ? $_COOKIE[$name] : null));
905
+		return isset($_REQUEST[$name]) ? $_REQUEST[$name] : (isset($_COOKIE[$name]) ? $_COOKIE[$name] : (isset($_COOKIE[$name = ucfirst($name)]) ? $_COOKIE[$name] : null));
909 906
 	}
910 907
 
911 908
 	/**
@@ -915,13 +912,13 @@  discard block
 block discarded – undo
915 912
 	 * @param string $kp3 ?? to be verified
916 913
 	 * @return bool is the session valid?
917 914
 	 */
918
-	function verify($sessionid=null,$kp3=null)
915
+	function verify($sessionid = null, $kp3 = null)
919 916
 	{
920 917
 		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid','$kp3') ".function_backtrace());
921 918
 
922 919
 		$fill_egw_info_and_repositories = !$GLOBALS['egw_info']['flags']['restored_from_session'];
923 920
 
924
-		if(!$sessionid)
921
+		if (!$sessionid)
925 922
 		{
926 923
 			$sessionid = self::get_sessionid();
927 924
 			$kp3       = self::get_request('kp3');
@@ -957,23 +954,23 @@  discard block
 block discarded – undo
957 954
 			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session does NOT exist!");
958 955
 			return false;
959 956
 		}
960
-		$session =& $_SESSION[self::EGW_SESSION_VAR];
957
+		$session = & $_SESSION[self::EGW_SESSION_VAR];
961 958
 
962 959
 		if ($session['session_dla'] <= time() - $GLOBALS['egw_info']['server']['sessions_timeout'])
963 960
 		{
964 961
 			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session timed out!");
965
-			$this->destroy($sessionid,$kp3);
962
+			$this->destroy($sessionid, $kp3);
966 963
 			return false;
967 964
 		}
968 965
 
969 966
 		$this->session_flags = $session['session_flags'];
970 967
 
971
-		$this->split_login_domain($session['session_lid'],$this->account_lid,$this->account_domain);
968
+		$this->split_login_domain($session['session_lid'], $this->account_lid, $this->account_domain);
972 969
 
973 970
 		// This is to ensure that we authenticate to the correct domain (might not be default)
974
-		if($GLOBALS['egw_info']['user']['domain'] && $this->account_domain != $GLOBALS['egw_info']['user']['domain'])
971
+		if ($GLOBALS['egw_info']['user']['domain'] && $this->account_domain != $GLOBALS['egw_info']['user']['domain'])
975 972
 		{
976
-			return false;	// session not verified, domain changed
973
+			return false; // session not verified, domain changed
977 974
 		}
978 975
 		$GLOBALS['egw_info']['user']['kp3'] = $this->kp3;
979 976
 
@@ -986,7 +983,7 @@  discard block
 block discarded – undo
986 983
 		{
987 984
 			$this->update_notification_heartbeat();
988 985
 		}
989
-		$this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid,'account_lid','u');
986
+		$this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid, 'account_lid', 'u');
990 987
 		if (!$this->account_id)
991 988
 		{
992 989
 			if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) !accounts::name2id('$this->account_lid')");
@@ -1033,7 +1030,7 @@  discard block
 block discarded – undo
1033 1030
 
1034 1031
 		if ($GLOBALS['egw_info']['server']['sessions_checkip'])
1035 1032
 		{
1036
-			if (strtoupper(substr(PHP_OS,0,3)) != 'WIN' && (!$GLOBALS['egw_info']['user']['session_ip'] ||
1033
+			if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN' && (!$GLOBALS['egw_info']['user']['session_ip'] ||
1037 1034
 				$GLOBALS['egw_info']['user']['session_ip'] != $this->getuser_ip()))
1038 1035
 			{
1039 1036
 				if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) wrong IP");
@@ -1056,9 +1053,9 @@  discard block
 block discarded – undo
1056 1053
 		// query accesslog-id, if not set in session (session is made persistent after login!)
1057 1054
 		if (!$this->sessionid_access_log && $this->session_flags != 'A')
1058 1055
 		{
1059
-			$this->sessionid_access_log = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE,'sessionid',array(
1056
+			$this->sessionid_access_log = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, 'sessionid', array(
1060 1057
 				'session_php' => $this->sessionid,
1061
-			),__LINE__,__FILE__)->fetchColumn();
1058
+			), __LINE__, __FILE__)->fetchColumn();
1062 1059
 			//error_log(__METHOD__."() sessionid=$this->sessionid --> sessionid_access_log=$this->sessionid_access_log");
1063 1060
 		}
1064 1061
 
@@ -1069,9 +1066,9 @@  discard block
 block discarded – undo
1069 1066
 			(!isset($_COOKIE[self::EGW_SESSION_NAME]) || $_COOKIE[self::EGW_SESSION_NAME] !== $_REQUEST[self::EGW_SESSION_NAME]))
1070 1067
 		{
1071 1068
 			if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS, but NO required cookies set --> setting them now");
1072
-			self::egw_setcookie(self::EGW_SESSION_NAME,$this->sessionid);
1073
-			self::egw_setcookie('kp3',$this->kp3);
1074
-			self::egw_setcookie('domain',$this->account_domain);
1069
+			self::egw_setcookie(self::EGW_SESSION_NAME, $this->sessionid);
1070
+			self::egw_setcookie('kp3', $this->kp3);
1071
+			self::egw_setcookie('domain', $this->account_domain);
1075 1072
 		}
1076 1073
 
1077 1074
 		if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS");
@@ -1086,27 +1083,27 @@  discard block
 block discarded – undo
1086 1083
 	 * @param string $kp3
1087 1084
 	 * @return boolean true on success, false on error
1088 1085
 	 */
1089
-	function destroy($sessionid, $kp3='')
1086
+	function destroy($sessionid, $kp3 = '')
1090 1087
 	{
1091 1088
 		if (!$sessionid && $kp3)
1092 1089
 		{
1093 1090
 			return false;
1094 1091
 		}
1095
-		$this->log_access($sessionid);	// log logout-time
1092
+		$this->log_access($sessionid); // log logout-time
1096 1093
 
1097 1094
 		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($sessionid,$kp3)");
1098 1095
 
1099 1096
 		if (is_numeric($sessionid))	// do we have a access-log-id --> get PHP session id
1100 1097
 		{
1101
-			$sessionid = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE,'session_php',array(
1098
+			$sessionid = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, 'session_php', array(
1102 1099
 					'sessionid' => $sessionid,
1103
-				),__LINE__,__FILE__)->fetchColumn();
1100
+				), __LINE__, __FILE__)->fetchColumn();
1104 1101
 		}
1105 1102
 
1106 1103
 		Hooks::process(array(
1107 1104
 			'location'  => 'session_destroyed',
1108 1105
 			'sessionid' => $sessionid,
1109
-		),'',true);	// true = run hooks from all apps, not just the ones the current user has perms to run
1106
+		), '', true); // true = run hooks from all apps, not just the ones the current user has perms to run
1110 1107
 
1111 1108
 		// Only do the following, if where working with the current user
1112 1109
 		if (!$GLOBALS['egw_info']['user']['sessionid'] || $sessionid == $GLOBALS['egw_info']['user']['sessionid'])
@@ -1127,7 +1124,7 @@  discard block
 block discarded – undo
1127 1124
 		}
1128 1125
 		else
1129 1126
 		{
1130
-			$this->commit_session();	// close our own session
1127
+			$this->commit_session(); // close our own session
1131 1128
 
1132 1129
 			session_id($sessionid);
1133 1130
 			if (session_start())
@@ -1167,25 +1164,25 @@  discard block
 block discarded – undo
1167 1164
 		// as $webserver_url may be part of $url (as /egw is part of phpgwapi/js/egw_instant_load.html)
1168 1165
 		if (($url[0] != '/' || $webserver_url != '/') && (!$webserver_url || strpos($url, $webserver_url.'/') === false))
1169 1166
 		{
1170
-			if($url[0] != '/' && substr($webserver_url,-1) != '/')
1167
+			if ($url[0] != '/' && substr($webserver_url, -1) != '/')
1171 1168
 			{
1172
-				$url = $webserver_url .'/'. $url;
1169
+				$url = $webserver_url.'/'.$url;
1173 1170
 			}
1174 1171
 			else
1175 1172
 			{
1176
-				$url = $webserver_url . $url;
1173
+				$url = $webserver_url.$url;
1177 1174
 			}
1178 1175
 		}
1179 1176
 
1180
-		if(isset($GLOBALS['egw_info']['server']['enforce_ssl']) && $GLOBALS['egw_info']['server']['enforce_ssl'])
1177
+		if (isset($GLOBALS['egw_info']['server']['enforce_ssl']) && $GLOBALS['egw_info']['server']['enforce_ssl'])
1181 1178
 		{
1182
-			if(substr($url ,0,4) != 'http')
1179
+			if (substr($url, 0, 4) != 'http')
1183 1180
 			{
1184 1181
 				$url = 'https://'.$_SERVER['HTTP_HOST'].$url;
1185 1182
 			}
1186 1183
 			else
1187 1184
 			{
1188
-				$url = str_replace ( 'http:', 'https:', $url);
1185
+				$url = str_replace('http:', 'https:', $url);
1189 1186
 			}
1190 1187
 		}
1191 1188
 		$vars = array();
@@ -1198,7 +1195,7 @@  discard block
 block discarded – undo
1198 1195
 		}
1199 1196
 
1200 1197
 		// check if the url already contains a query and ensure that vars is an array and all strings are in extravars
1201
-		list($ret_url,$othervars) = explode('?', $url, 2);
1198
+		list($ret_url, $othervars) = explode('?', $url, 2);
1202 1199
 		if ($extravars && is_array($extravars))
1203 1200
 		{
1204 1201
 			$vars += $extravars;
@@ -1206,19 +1203,19 @@  discard block
 block discarded – undo
1206 1203
 		}
1207 1204
 		else
1208 1205
 		{
1209
-			if ($othervars) $extravars .= ($extravars?'&':'').$othervars;
1206
+			if ($othervars) $extravars .= ($extravars ? '&' : '').$othervars;
1210 1207
 		}
1211 1208
 
1212 1209
 		// parse extravars string into the vars array
1213 1210
 		if ($extravars)
1214 1211
 		{
1215
-			foreach(explode('&',$extravars) as $expr)
1212
+			foreach (explode('&', $extravars) as $expr)
1216 1213
 			{
1217
-				list($var,$val) = explode('=', $expr,2);
1218
-				if (strpos($val,'%26') != false) $val = str_replace('%26','&',$val);	// make sure to not double encode &
1219
-				if (substr($var,-2) == '[]')
1214
+				list($var, $val) = explode('=', $expr, 2);
1215
+				if (strpos($val, '%26') != false) $val = str_replace('%26', '&', $val); // make sure to not double encode &
1216
+				if (substr($var, -2) == '[]')
1220 1217
 				{
1221
-					$vars[substr($var,0,-2)][] = $val;
1218
+					$vars[substr($var, 0, -2)][] = $val;
1222 1219
 				}
1223 1220
 				else
1224 1221
 				{
@@ -1231,11 +1228,11 @@  discard block
 block discarded – undo
1231 1228
 		if (count($vars))
1232 1229
 		{
1233 1230
 			$query = array();
1234
-			foreach($vars as $key => $value)
1231
+			foreach ($vars as $key => $value)
1235 1232
 			{
1236 1233
 				if (is_array($value))
1237 1234
 				{
1238
-					foreach($value as $val)
1235
+					foreach ($value as $val)
1239 1236
 					{
1240 1237
 						$query[] = $key.'[]='.urlencode($val);
1241 1238
 					}
@@ -1245,7 +1242,7 @@  discard block
 block discarded – undo
1245 1242
 					$query[] = $key.'='.urlencode($value);
1246 1243
 				}
1247 1244
 			}
1248
-			$ret_url .= '?' . implode('&',$query);
1245
+			$ret_url .= '?'.implode('&', $query);
1249 1246
 		}
1250 1247
 		return $ret_url;
1251 1248
 	}
@@ -1290,7 +1287,7 @@  discard block
 block discarded – undo
1290 1287
 	 * @param int $cookietime =0 when cookie should expire, 0 for session only (optional)
1291 1288
 	 * @param string $cookiepath =null optional path (eg. '/') if the eGW install-dir should not be used
1292 1289
 	 */
1293
-	public static function egw_setcookie($cookiename,$cookievalue='',$cookietime=0,$cookiepath=null)
1290
+	public static function egw_setcookie($cookiename, $cookievalue = '', $cookietime = 0, $cookiepath = null)
1294 1291
 	{
1295 1292
 		if (empty(self::$cookie_domain) || empty(self::$cookie_path))
1296 1293
 		{
@@ -1303,11 +1300,11 @@  discard block
 block discarded – undo
1303 1300
 		static $is_iOS = null;
1304 1301
 		if (!$cookietime && !isset($is_iOS)) $is_iOS = (bool)preg_match('/^(iPhone|iPad|iPod)/i', Header\UserAgent::mobile());
1305 1302
 
1306
-		if(!headers_sent())	// gives only a warning, but can not send the cookie anyway
1303
+		if (!headers_sent())	// gives only a warning, but can not send the cookie anyway
1307 1304
 		{
1308 1305
 			setcookie($cookiename, $cookievalue,
1309
-				!$cookietime && $is_iOS ? time()+self::IOS_SESSION_COOKIE_LIFETIME : $cookietime,
1310
-				is_null($cookiepath) ? self::$cookie_path : $cookiepath,self::$cookie_domain,
1306
+				!$cookietime && $is_iOS ? time() + self::IOS_SESSION_COOKIE_LIFETIME : $cookietime,
1307
+				is_null($cookiepath) ? self::$cookie_path : $cookiepath, self::$cookie_domain,
1311 1308
 				// if called via HTTPS, only send cookie for https and only allow cookie access via HTTP (true)
1312 1309
 				empty($GLOBALS['egw_info']['server']['insecure_cookies']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off', true);
1313 1310
 		}
@@ -1326,21 +1323,21 @@  discard block
 block discarded – undo
1326 1323
 		else
1327 1324
 		{
1328 1325
 			// Use HTTP_X_FORWARDED_HOST if set, which is the case behind a none-transparent proxy
1329
-			self::$cookie_domain = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ?  $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST'];
1326
+			self::$cookie_domain = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST'];
1330 1327
 		}
1331 1328
 		// remove port from HTTP_HOST
1332 1329
 		$arr = null;
1333
-		if (preg_match("/^(.*):(.*)$/",self::$cookie_domain,$arr))
1330
+		if (preg_match("/^(.*):(.*)$/", self::$cookie_domain, $arr))
1334 1331
 		{
1335 1332
 			self::$cookie_domain = $arr[1];
1336 1333
 		}
1337
-		if (count(explode('.',self::$cookie_domain)) <= 1)
1334
+		if (count(explode('.', self::$cookie_domain)) <= 1)
1338 1335
 		{
1339 1336
 			// setcookie dont likes domains without dots, leaving it empty, gets setcookie to fill the domain in
1340 1337
 			self::$cookie_domain = '';
1341 1338
 		}
1342 1339
 		if (!$GLOBALS['egw_info']['server']['cookiepath'] ||
1343
-			!(self::$cookie_path = parse_url($GLOBALS['egw_info']['server']['webserver_url'],PHP_URL_PATH)))
1340
+			!(self::$cookie_path = parse_url($GLOBALS['egw_info']['server']['webserver_url'], PHP_URL_PATH)))
1344 1341
 		{
1345 1342
 			self::$cookie_path = '/';
1346 1343
 		}
@@ -1360,7 +1357,7 @@  discard block
 block discarded – undo
1360 1357
 	 * @param array $domains =null defaults to $GLOBALS['egw_domain'] from the header
1361 1358
 	 * @return string $GLOBALS['egw_info']['user']['domain'] set with the domain/instance to use
1362 1359
 	 */
1363
-	public static function search_instance($login,$domain_requested,&$default_domain,$server_names,array $domains=null)
1360
+	public static function search_instance($login, $domain_requested, &$default_domain, $server_names, array $domains = null)
1364 1361
 	{
1365 1362
 		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".".array2string($server_names).".".array2string($domains).")");
1366 1363
 
@@ -1368,10 +1365,10 @@  discard block
 block discarded – undo
1368 1365
 
1369 1366
 		if (!isset($default_domain) || !isset($domains[$default_domain]))	// allow to overwrite the default domain
1370 1367
 		{
1371
-			foreach((array)$server_names as $server_name)
1368
+			foreach ((array)$server_names as $server_name)
1372 1369
 			{
1373
-				list($server_name) = explode(':', $server_name);	// remove port from HTTP_HOST
1374
-				if(isset($domains[$server_name]))
1370
+				list($server_name) = explode(':', $server_name); // remove port from HTTP_HOST
1371
+				if (isset($domains[$server_name]))
1375 1372
 				{
1376 1373
 					$default_domain = $server_name;
1377 1374
 					break;
@@ -1381,7 +1378,7 @@  discard block
 block discarded – undo
1381 1378
 					$parts = explode('.', $server_name);
1382 1379
 					array_shift($parts);
1383 1380
 					$domain_part = implode('.', $parts);
1384
-					if(isset($domains[$domain_part]))
1381
+					if (isset($domains[$domain_part]))
1385 1382
 					{
1386 1383
 						$default_domain = $domain_part;
1387 1384
 						break;
@@ -1397,11 +1394,11 @@  discard block
 block discarded – undo
1397 1394
 		}
1398 1395
 		if (isset($login))	// on login
1399 1396
 		{
1400
-			if (strpos($login,'@') === false || count($domains) == 1)
1397
+			if (strpos($login, '@') === false || count($domains) == 1)
1401 1398
 			{
1402
-				$login .= '@' . (isset($_POST['logindomain']) ? $_POST['logindomain'] : $default_domain);
1399
+				$login .= '@'.(isset($_POST['logindomain']) ? $_POST['logindomain'] : $default_domain);
1403 1400
 			}
1404
-			$parts = explode('@',$login);
1401
+			$parts = explode('@', $login);
1405 1402
 			$domain = array_pop($parts);
1406 1403
 			$GLOBALS['login'] = $login;
1407 1404
 		}
@@ -1434,7 +1431,7 @@  discard block
 block discarded – undo
1434 1431
 	 * @param boolean $update_access_log =false false: dont update egw_access_log table, but set $this->action
1435 1432
 	 * @return string action as written to egw_access_log.session_action
1436 1433
 	 */
1437
-	private function update_dla($update_access_log=false)
1434
+	private function update_dla($update_access_log = false)
1438 1435
 	{
1439 1436
 		// This way XML-RPC users aren't always listed as xmlrpc.php
1440 1437
 		if (!$update_access_log)
@@ -1452,14 +1449,14 @@  discard block
 block discarded – undo
1452 1449
 				$action = $_SERVER['PHP_SELF'];
1453 1450
 				// remove EGroupware path, if not installed in webroot
1454 1451
 				$egw_path = $GLOBALS['egw_info']['server']['webserver_url'];
1455
-				if ($egw_path[0] != '/') $egw_path = parse_url($egw_path,PHP_URL_PATH);
1452
+				if ($egw_path[0] != '/') $egw_path = parse_url($egw_path, PHP_URL_PATH);
1456 1453
 				if ($action == '/Microsoft-Server-ActiveSync')
1457 1454
 				{
1458 1455
 					$action .= '?Cmd='.$_GET['Cmd'].'&DeviceId='.$_GET['DeviceId'];
1459 1456
 				}
1460 1457
 				elseif ($egw_path)
1461 1458
 				{
1462
-					list(,$action) = explode($egw_path,$action,2);
1459
+					list(,$action) = explode($egw_path, $action, 2);
1463 1460
 				}
1464 1461
 			}
1465 1462
 			$this->set_action($action);
@@ -1467,14 +1464,14 @@  discard block
 block discarded – undo
1467 1464
 		// update dla in access-log table, if we have an access-log row (non-anonymous session)
1468 1465
 		if ($this->sessionid_access_log && $update_access_log && is_object($GLOBALS['egw']->db))
1469 1466
 		{
1470
-			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE,array(
1467
+			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE, array(
1471 1468
 				'session_dla' => time(),
1472 1469
 				'session_action' => $this->action,
1473 1470
 			) + ($this->action === '/logout.php' ? array() : array(
1474
-				'lo' => null,	// just in case it was (automatic) timed out before
1475
-			)),array(
1471
+				'lo' => null, // just in case it was (automatic) timed out before
1472
+			)), array(
1476 1473
 				'sessionid' => $this->sessionid_access_log,
1477
-			),__LINE__,__FILE__);
1474
+			), __LINE__, __FILE__);
1478 1475
 		}
1479 1476
 
1480 1477
 		$_SESSION[self::EGW_SESSION_VAR]['session_dla'] = time();
@@ -1492,12 +1489,12 @@  discard block
 block discarded – undo
1492 1489
 		// update dla in access-log table, if we have an access-log row (non-anonymous session)
1493 1490
 		if ($this->sessionid_access_log)
1494 1491
 		{
1495
-			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE,array(
1492
+			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE, array(
1496 1493
 				'notification_heartbeat' => time(),
1497
-			),array(
1494
+			), array(
1498 1495
 				'sessionid' => $this->sessionid_access_log,
1499 1496
 				'lo IS NULL',
1500
-			),__LINE__,__FILE__);
1497
+			), __LINE__, __FILE__);
1501 1498
 		}
1502 1499
 	}
1503 1500
 
@@ -1518,7 +1515,7 @@  discard block
 block discarded – undo
1518 1515
 		{
1519 1516
 			// authentication happens in login.php, which does NOT yet create egw-object in session
1520 1517
 			// --> need to store homedirectory in session
1521
-			if(isset($GLOBALS['auto_create_acct']['homedirectory']))
1518
+			if (isset($GLOBALS['auto_create_acct']['homedirectory']))
1522 1519
 			{
1523 1520
 				Cache::setSession(__CLASS__, 'homedirectory',
1524 1521
 					$user['homedirectory'] = $GLOBALS['auto_create_acct']['homedirectory']);
@@ -1531,7 +1528,7 @@  discard block
 block discarded – undo
1531 1528
 		$user['preferences'] = $GLOBALS['egw']->preferences->read_repository();
1532 1529
 		if (is_object($GLOBALS['egw']->datetime))
1533 1530
 		{
1534
-			$GLOBALS['egw']->datetime->__construct();		// to set tz_offset from the now read prefs
1531
+			$GLOBALS['egw']->datetime->__construct(); // to set tz_offset from the now read prefs
1535 1532
 		}
1536 1533
 		$user['apps']        = $GLOBALS['egw']->applications->read_repository();
1537 1534
 		$user['domain']      = $this->account_domain;
@@ -1554,9 +1551,9 @@  discard block
 block discarded – undo
1554 1551
 	 * @param string &$account_lid returned account_lid (ie. user)
1555 1552
 	 * @param string &$domain returned domain (ie. domain)
1556 1553
 	 */
1557
-	private function split_login_domain($login,&$account_lid,&$domain)
1554
+	private function split_login_domain($login, &$account_lid, &$domain)
1558 1555
 	{
1559
-		$parts = explode('@',$login);
1556
+		$parts = explode('@', $login);
1560 1557
 
1561 1558
 		//conference - for strings like [email protected]@default ,
1562 1559
 		//allows that user have a login that is his e-mail. (viniciuscb)
@@ -1564,11 +1561,11 @@  discard block
 block discarded – undo
1564 1561
 		{
1565 1562
 			$probable_domain = array_pop($parts);
1566 1563
 			//Last part of login string, when separated by @, is a domain name
1567
-			if (in_array($probable_domain,$this->egw_domains))
1564
+			if (in_array($probable_domain, $this->egw_domains))
1568 1565
 			{
1569 1566
 				$got_login = true;
1570 1567
 				$domain = $probable_domain;
1571
-				$account_lid = implode('@',$parts);
1568
+				$account_lid = implode('@', $parts);
1572 1569
 			}
1573 1570
 		}
1574 1571
 
@@ -1591,9 +1588,9 @@  discard block
 block discarded – undo
1591 1588
 	 * @param boolean $allow_password_md5 =false can password alread be an md5 hash
1592 1589
 	 * @return string
1593 1590
 	 */
1594
-	static function user_pw_hash($user,$password,$allow_password_md5=false)
1591
+	static function user_pw_hash($user, $password, $allow_password_md5 = false)
1595 1592
 	{
1596
-		$password_md5 = $allow_password_md5 && preg_match('/^[a-f0-9]{32}$/',$password) ? $password : md5($password);
1593
+		$password_md5 = $allow_password_md5 && preg_match('/^[a-f0-9]{32}$/', $password) ? $password : md5($password);
1597 1594
 
1598 1595
 		$hash = sha1(strtolower($user).$password_md5);
1599 1596
 
@@ -1608,12 +1605,12 @@  discard block
 block discarded – undo
1608 1605
 	 */
1609 1606
 	public static function init_handler()
1610 1607
 	{
1611
-		switch(session_status())
1608
+		switch (session_status())
1612 1609
 		{
1613 1610
 			case PHP_SESSION_DISABLED:
1614 1611
 				throw new \ErrorException('EGroupware requires PHP session extension!');
1615 1612
 			case PHP_SESSION_NONE:
1616
-				ini_set('session.use_cookies',0);	// disable the automatic use of cookies, as it uses the path / by default
1613
+				ini_set('session.use_cookies', 0); // disable the automatic use of cookies, as it uses the path / by default
1617 1614
 				session_name(self::EGW_SESSION_NAME);
1618 1615
 				if (($sessionid = self::get_sessionid()))
1619 1616
 				{
@@ -1626,7 +1623,7 @@  discard block
 block discarded – undo
1626 1623
 				}
1627 1624
 				break;
1628 1625
 			case PHP_SESSION_ACTIVE:
1629
-				return true;	// session created by MServer
1626
+				return true; // session created by MServer
1630 1627
 		}
1631 1628
 		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() no active session!");
1632 1629
 
@@ -1644,7 +1641,7 @@  discard block
 block discarded – undo
1644 1641
 	 * @param int $expire =null expiration time in seconds, default $GLOBALS['egw_info']['flags']['nocachecontrol'] or php.ini session.cache_expire
1645 1642
 	 * @param int $private =null allows to set private caching with given expiration time, by setting it to true
1646 1643
 	 */
1647
-	public static function cache_control($expire=null, $private=null)
1644
+	public static function cache_control($expire = null, $private = null)
1648 1645
 	{
1649 1646
 		if (is_null($expire) && isset($GLOBALS['egw_info']['flags']['nocachecontrol']) && is_int($GLOBALS['egw_info']['flags']['nocachecontrol']))
1650 1647
 		{
@@ -1654,7 +1651,7 @@  discard block
 block discarded – undo
1654 1651
 		if (!isset($_SESSION))
1655 1652
 		{
1656 1653
 			// controling caching and expires header
1657
-			if(!isset($expire) && (!isset($GLOBALS['egw_info']['flags']['nocachecontrol']) ||
1654
+			if (!isset($expire) && (!isset($GLOBALS['egw_info']['flags']['nocachecontrol']) ||
1658 1655
 				!$GLOBALS['egw_info']['flags']['nocachecontrol']))
1659 1656
 			{
1660 1657
 				session_cache_limiter('nocache');
@@ -1664,7 +1661,7 @@  discard block
 block discarded – undo
1664 1661
 				// allow public caching: proxys, cdns, ...
1665 1662
 				if (isset($expire))
1666 1663
 				{
1667
-					session_cache_expire((int)ceil($expire/60));	// in minutes
1664
+					session_cache_expire((int)ceil($expire / 60)); // in minutes
1668 1665
 				}
1669 1666
 				session_cache_limiter($private ? 'private' : 'public');
1670 1667
 			}
@@ -1677,8 +1674,8 @@  discard block
 block discarded – undo
1677 1674
 		// session already started
1678 1675
 		if (isset($_SESSION))
1679 1676
 		{
1680
-			if ($expire && (session_cache_limiter() !== ($expire===true?'private_no_expire':'public') ||
1681
-				is_int($expire) && $expire/60 !== session_cache_expire()))
1677
+			if ($expire && (session_cache_limiter() !== ($expire === true ? 'private_no_expire' : 'public') ||
1678
+				is_int($expire) && $expire / 60 !== session_cache_expire()))
1682 1679
 			{
1683 1680
 				$file = $line = null;
1684 1681
 				if (headers_sent($file, $line))
@@ -1686,20 +1683,20 @@  discard block
 block discarded – undo
1686 1683
 					error_log(__METHOD__."($expire) called, but header already sent in $file: $line");
1687 1684
 					return;
1688 1685
 				}
1689
-				if($expire === true)	// same behavior as session_cache_limiter('private_no_expire')
1686
+				if ($expire === true)	// same behavior as session_cache_limiter('private_no_expire')
1690 1687
 				{
1691
-					header('Cache-Control: private, max-age='.(60*session_cache_expire()));
1688
+					header('Cache-Control: private, max-age='.(60 * session_cache_expire()));
1692 1689
 					header_remove('Expires');
1693 1690
 				}
1694 1691
 				elseif ($private)
1695 1692
 				{
1696 1693
 					header('Cache-Control: private, max-age='.$expire);
1697
-					header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expire) . ' GMT');
1694
+					header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expire).' GMT');
1698 1695
 				}
1699 1696
 				else
1700 1697
 				{
1701 1698
 					header('Cache-Control: public, max-age='.$expire);
1702
-					header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expire) . ' GMT');
1699
+					header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expire).' GMT');
1703 1700
 				}
1704 1701
 				// remove Pragma header, might be set by old header
1705 1702
 				if (function_exists('header_remove'))	// PHP 5.3+
@@ -1724,10 +1721,10 @@  discard block
 block discarded – undo
1724 1721
 	 * @param array $filter =array() extra filter for sessions
1725 1722
 	 * @return array with sessions (values for keys as in $sort)
1726 1723
 	 */
1727
-	public static function session_list($start,$sort='DESC',$order='session_dla',$all_no_sort=False,array $filter=array())
1724
+	public static function session_list($start, $sort = 'DESC', $order = 'session_dla', $all_no_sort = False, array $filter = array())
1728 1725
 	{
1729 1726
 		$sessions = array();
1730
-		if (!preg_match('/^[a-z0-9_ ,]+$/i',$order_by=$order.' '.$sort) || $order_by == ' ')
1727
+		if (!preg_match('/^[a-z0-9_ ,]+$/i', $order_by = $order.' '.$sort) || $order_by == ' ')
1731 1728
 		{
1732 1729
 			$order_by = 'session_dla DESC';
1733 1730
 		}
@@ -1735,7 +1732,7 @@  discard block
 block discarded – undo
1735 1732
 		$filter[] = 'account_id>0';
1736 1733
 		$filter[] = 'session_dla > '.(int)(time() - $GLOBALS['egw_info']['server']['sessions_timeout']);
1737 1734
 		$filter[] = '(notification_heartbeat IS NULL OR notification_heartbeat > '.self::heartbeat_limit().')';
1738
-		foreach($GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, '*', $filter, __LINE__, __FILE__,
1735
+		foreach ($GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, '*', $filter, __LINE__, __FILE__,
1739 1736
 			$all_no_sort ? false : $start, 'ORDER BY '.$order_by) as $row)
1740 1737
 		{
1741 1738
 			$sessions[$row['sessionid']] = $row;
@@ -1749,7 +1746,7 @@  discard block
 block discarded – undo
1749 1746
 	 * @param array $filter =array() extra filter for sessions
1750 1747
 	 * @return int number of active sessions
1751 1748
 	 */
1752
-	public static function session_count(array $filter=array())
1749
+	public static function session_count(array $filter = array())
1753 1750
 	{
1754 1751
 		$filter['lo'] = null;
1755 1752
 		$filter[] = 'account_id>0';
@@ -1765,16 +1762,16 @@  discard block
 block discarded – undo
1765 1762
 	 */
1766 1763
 	public static function heartbeat_limit()
1767 1764
 	{
1768
-		static $limit=null;
1765
+		static $limit = null;
1769 1766
 
1770 1767
 		if (is_null($limit))
1771 1768
 		{
1772 1769
 			$config = Config::read('notifications');
1773
-			if (!($popup_poll_interval  = $config['popup_poll_interval']))
1770
+			if (!($popup_poll_interval = $config['popup_poll_interval']))
1774 1771
 			{
1775 1772
 				$popup_poll_interval = 60;
1776 1773
 			}
1777
-			$limit = (int)(time() - $popup_poll_interval-10);	// 10s grace periode
1774
+			$limit = (int)(time() - $popup_poll_interval - 10); // 10s grace periode
1778 1775
 		}
1779 1776
 		return $limit;
1780 1777
 	}
Please login to merge, or discard this patch.
Braces   +172 added lines, -44 removed lines patch added patch discarded remove patch
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 
249 249
 		// set session_timeout from global php.ini and default to 14400=4h, if not set
250 250
 		if (!($GLOBALS['egw_info']['server']['sessions_timeout'] = ini_get('session.gc_maxlifetime')))
251
-      	{
251
+		{
252 252
       		ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout']=14400);
253 253
       	}
254 254
 	}
@@ -287,7 +287,10 @@  discard block
 block discarded – undo
287 287
 	 */
288 288
 	function commit_session()
289 289
 	{
290
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() sessionid=$this->sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]).' '.function_backtrace());
290
+		if (self::ERROR_LOG_DEBUG)
291
+		{
292
+			error_log(__METHOD__."() sessionid=$this->sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]).' '.function_backtrace());
293
+		}
291 294
 		self::encrypt($this->kp3);
292 295
 
293 296
 		session_write_close();
@@ -349,7 +352,10 @@  discard block
 block discarded – undo
349 352
 	 */
350 353
 	static function log_session_usage(&$arr,$label,$recursion=true,$limit=1000)
351 354
 	{
352
-		if (!is_array($arr)) return;
355
+		if (!is_array($arr))
356
+		{
357
+			return;
358
+		}
353 359
 
354 360
 		$sizes = array();
355 361
 		foreach($arr as $key => &$data)
@@ -364,7 +370,10 @@  discard block
 block discarded – undo
364 370
 			if ($diff > $limit)
365 371
 			{
366 372
 				error_log("strlen({$label}[$key])=".Vfs::hsize($size).", diff=".Vfs::hsize($diff));
367
-				if ($recursion) self::log_session_usage($arr[$key],$label.'['.$key.']',$recursion,$limit);
373
+				if ($recursion)
374
+				{
375
+					self::log_session_usage($arr[$key],$label.'['.$key.']',$recursion,$limit);
376
+				}
368 377
 			}
369 378
 		}
370 379
 	}
@@ -462,7 +471,10 @@  discard block
 block discarded – undo
462 471
 				$this->passwd      = $passwd;
463 472
 				$this->passwd_type = $passwd_type;
464 473
 			}
465
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) starting ...");
474
+			if (self::ERROR_LOG_DEBUG)
475
+			{
476
+				error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) starting ...");
477
+			}
466 478
 
467 479
 			self::split_login_domain($login,$this->account_lid,$this->account_domain);
468 480
 			// add domain to the login, if not already there
@@ -506,7 +518,10 @@  discard block
 block discarded – undo
506 518
 				{
507 519
 					$this->log_access($this->reason,$login,$user_ip,0);	// log unsuccessfull login
508 520
 				}
509
-				if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
521
+				if (self::ERROR_LOG_DEBUG)
522
+				{
523
+					error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
524
+				}
510 525
 				return false;
511 526
 			}
512 527
 			if ($fail_on_forced_password_change && Auth::check_password_change($this->reason) === false)
@@ -556,7 +571,10 @@  discard block
 block discarded – undo
556 571
 				$this->reason = 'account is expired';
557 572
 				$this->cd_reason = self::CD_ACCOUNT_EXPIRED;
558 573
 
559
-				if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
574
+				if (self::ERROR_LOG_DEBUG)
575
+				{
576
+					error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
577
+				}
560 578
 				return false;
561 579
 			}
562 580
 
@@ -580,25 +598,34 @@  discard block
 block discarded – undo
580 598
 				'passwd'         => $this->passwd,
581 599
 				'account_domain' => $this->account_domain,
582 600
 				'user_ip'        => $user_ip,
583
-			),'',true)))	// true = run hooks from all apps, not just the ones the current user has perms to run
601
+			),'',true)))
602
+			{
603
+				// true = run hooks from all apps, not just the ones the current user has perms to run
584 604
 			{
585 605
 				foreach($hook_result as $reason)
586 606
 				{
587 607
 					if ($reason)	// called hook requests to deny the session
588 608
 					{
589 609
 						$this->reason = $this->cd_reason = $reason;
610
+			}
590 611
 						$this->log_access($this->reason,$login,$user_ip,0);		// log unsuccessfull login
591
-						if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
612
+						if (self::ERROR_LOG_DEBUG)
613
+						{
614
+							error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
615
+						}
592 616
 						return false;
593 617
 					}
594 618
 				}
595 619
 			}
596 620
 			$GLOBALS['egw']->db->transaction_begin();
597 621
 			$this->register_session($this->login,$user_ip,$now,$this->session_flags);
598
-			if ($this->session_flags != 'A')		// dont log anonymous sessions
622
+			if ($this->session_flags != 'A')
623
+			{
624
+				// dont log anonymous sessions
599 625
 			{
600 626
 				$this->sessionid_access_log = $this->log_access($this->sessionid,$login,$user_ip,$this->account_id);
601 627
 			}
628
+			}
602 629
 			Cache::setSession('phpgwapi', 'account_previous_login', $GLOBALS['egw']->auth->previous_login);
603 630
 			$GLOBALS['egw']->accounts->update_lastlogin($this->account_id,$user_ip);
604 631
 			$GLOBALS['egw']->db->transaction_commit();
@@ -614,7 +641,10 @@  discard block
 block discarded – undo
614 641
 				self::egw_setcookie('last_loginid', $this->account_lid ,$now+1209600); /* For 2 weeks */
615 642
 				self::egw_setcookie('last_domain',$this->account_domain,$now+1209600);
616 643
 			}
617
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) successfull sessionid=$this->sessionid");
644
+			if (self::ERROR_LOG_DEBUG)
645
+			{
646
+				error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) successfull sessionid=$this->sessionid");
647
+			}
618 648
 
619 649
 			// hook called once session is created
620 650
 			Hooks::process(array(
@@ -806,10 +836,13 @@  discard block
 block discarded – undo
806 836
 		//error_log(__METHOD__."('$login', '$ip') false_ip=$false_ip, false_id=$false_id --> blocked=".array2string($blocked));
807 837
 
808 838
 		if ($blocked && $GLOBALS['egw_info']['server']['admin_mails'] &&
809
-			$GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time()-5*60)	// max. one mail every 5mins
839
+			$GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time()-5*60)
840
+		{
841
+			// max. one mail every 5mins
810 842
 		{
811 843
 			try {
812 844
 				$mailer = new Mailer();
845
+		}
813 846
 				// notify admin(s) via email
814 847
 				$mailer->setFrom('eGroupWare@'.$GLOBALS['egw_info']['server']['mail_suffix']);
815 848
 				$mailer->addHeader('Subject', lang("eGroupWare: login blocked for user '%1', IP %2",$login,$ip));
@@ -887,7 +920,10 @@  discard block
 block discarded – undo
887 920
 		{
888 921
 			$sessionid = false;
889 922
 		}
890
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid,true));
923
+		if (self::ERROR_LOG_DEBUG)
924
+		{
925
+			error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid,true));
926
+		}
891 927
 		return $sessionid;
892 928
 	}
893 929
 
@@ -917,7 +953,10 @@  discard block
 block discarded – undo
917 953
 	 */
918 954
 	function verify($sessionid=null,$kp3=null)
919 955
 	{
920
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid','$kp3') ".function_backtrace());
956
+		if (self::ERROR_LOG_DEBUG)
957
+		{
958
+			error_log(__METHOD__."('$sessionid','$kp3') ".function_backtrace());
959
+		}
921 960
 
922 961
 		$fill_egw_info_and_repositories = !$GLOBALS['egw_info']['flags']['restored_from_session'];
923 962
 
@@ -933,7 +972,10 @@  discard block
 block discarded – undo
933 972
 
934 973
 		if (!$this->sessionid)
935 974
 		{
936
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') get_sessionid()='".self::get_sessionid()."' No session ID");
975
+			if (self::ERROR_LOG_DEBUG)
976
+			{
977
+				error_log(__METHOD__."('$sessionid') get_sessionid()='".self::get_sessionid()."' No session ID");
978
+			}
937 979
 			return false;
938 980
 		}
939 981
 
@@ -954,14 +996,20 @@  discard block
 block discarded – undo
954 996
 		// check if we have a eGroupware session --> return false if not (but dont destroy it!)
955 997
 		if (is_null($_SESSION) || !isset($_SESSION[self::EGW_SESSION_VAR]))
956 998
 		{
957
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session does NOT exist!");
999
+			if (self::ERROR_LOG_DEBUG)
1000
+			{
1001
+				error_log(__METHOD__."('$sessionid') session does NOT exist!");
1002
+			}
958 1003
 			return false;
959 1004
 		}
960 1005
 		$session =& $_SESSION[self::EGW_SESSION_VAR];
961 1006
 
962 1007
 		if ($session['session_dla'] <= time() - $GLOBALS['egw_info']['server']['sessions_timeout'])
963 1008
 		{
964
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session timed out!");
1009
+			if (self::ERROR_LOG_DEBUG)
1010
+			{
1011
+				error_log(__METHOD__."('$sessionid') session timed out!");
1012
+			}
965 1013
 			$this->destroy($sessionid,$kp3);
966 1014
 			return false;
967 1015
 		}
@@ -989,7 +1037,10 @@  discard block
 block discarded – undo
989 1037
 		$this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid,'account_lid','u');
990 1038
 		if (!$this->account_id)
991 1039
 		{
992
-			if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) !accounts::name2id('$this->account_lid')");
1040
+			if (self::ERROR_LOG_DEBUG)
1041
+			{
1042
+				error_log("*** Session::verify($sessionid) !accounts::name2id('$this->account_lid')");
1043
+			}
993 1044
 			return false;
994 1045
 		}
995 1046
 
@@ -1016,7 +1067,10 @@  discard block
 block discarded – undo
1016 1067
 
1017 1068
 		if ($GLOBALS['egw']->accounts->is_expired($GLOBALS['egw_info']['user']))
1018 1069
 		{
1019
-			if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) accounts is expired");
1070
+			if (self::ERROR_LOG_DEBUG)
1071
+			{
1072
+				error_log("*** Session::verify($sessionid) accounts is expired");
1073
+			}
1020 1074
 			return false;
1021 1075
 		}
1022 1076
 		$this->passwd = base64_decode(Cache::getSession('phpgwapi', 'password'));
@@ -1027,7 +1081,10 @@  discard block
 block discarded – undo
1027 1081
 		}
1028 1082
 		if ($this->account_domain != $GLOBALS['egw_info']['user']['domain'])
1029 1083
 		{
1030
-			if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) wrong domain");
1084
+			if (self::ERROR_LOG_DEBUG)
1085
+			{
1086
+				error_log("*** Session::verify($sessionid) wrong domain");
1087
+			}
1031 1088
 			return false;
1032 1089
 		}
1033 1090
 
@@ -1036,7 +1093,10 @@  discard block
 block discarded – undo
1036 1093
 			if (strtoupper(substr(PHP_OS,0,3)) != 'WIN' && (!$GLOBALS['egw_info']['user']['session_ip'] ||
1037 1094
 				$GLOBALS['egw_info']['user']['session_ip'] != $this->getuser_ip()))
1038 1095
 			{
1039
-				if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) wrong IP");
1096
+				if (self::ERROR_LOG_DEBUG)
1097
+				{
1098
+					error_log("*** Session::verify($sessionid) wrong IP");
1099
+				}
1040 1100
 				return false;
1041 1101
 			}
1042 1102
 		}
@@ -1049,7 +1109,10 @@  discard block
 block discarded – undo
1049 1109
 		}
1050 1110
 		if (!$this->account_lid)
1051 1111
 		{
1052
-			if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) !account_lid");
1112
+			if (self::ERROR_LOG_DEBUG)
1113
+			{
1114
+				error_log("*** Session::verify($sessionid) !account_lid");
1115
+			}
1053 1116
 			return false;
1054 1117
 		}
1055 1118
 
@@ -1068,13 +1131,19 @@  discard block
 block discarded – undo
1068 1131
 			$_REQUEST[self::EGW_SESSION_NAME] === $this->sessionid &&
1069 1132
 			(!isset($_COOKIE[self::EGW_SESSION_NAME]) || $_COOKIE[self::EGW_SESSION_NAME] !== $_REQUEST[self::EGW_SESSION_NAME]))
1070 1133
 		{
1071
-			if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS, but NO required cookies set --> setting them now");
1134
+			if (self::ERROR_LOG_DEBUG)
1135
+			{
1136
+				error_log("--> Session::verify($sessionid) SUCCESS, but NO required cookies set --> setting them now");
1137
+			}
1072 1138
 			self::egw_setcookie(self::EGW_SESSION_NAME,$this->sessionid);
1073 1139
 			self::egw_setcookie('kp3',$this->kp3);
1074 1140
 			self::egw_setcookie('domain',$this->account_domain);
1075 1141
 		}
1076 1142
 
1077
-		if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS");
1143
+		if (self::ERROR_LOG_DEBUG)
1144
+		{
1145
+			error_log("--> Session::verify($sessionid) SUCCESS");
1146
+		}
1078 1147
 
1079 1148
 		return true;
1080 1149
 	}
@@ -1094,14 +1163,20 @@  discard block
 block discarded – undo
1094 1163
 		}
1095 1164
 		$this->log_access($sessionid);	// log logout-time
1096 1165
 
1097
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($sessionid,$kp3)");
1166
+		if (self::ERROR_LOG_DEBUG)
1167
+		{
1168
+			error_log(__METHOD__."($sessionid,$kp3)");
1169
+		}
1098 1170
 
1099
-		if (is_numeric($sessionid))	// do we have a access-log-id --> get PHP session id
1171
+		if (is_numeric($sessionid))
1172
+		{
1173
+			// do we have a access-log-id --> get PHP session id
1100 1174
 		{
1101 1175
 			$sessionid = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE,'session_php',array(
1102 1176
 					'sessionid' => $sessionid,
1103 1177
 				),__LINE__,__FILE__)->fetchColumn();
1104 1178
 		}
1179
+		}
1105 1180
 
1106 1181
 		Hooks::process(array(
1107 1182
 			'location'  => 'session_destroyed',
@@ -1111,7 +1186,10 @@  discard block
 block discarded – undo
1111 1186
 		// Only do the following, if where working with the current user
1112 1187
 		if (!$GLOBALS['egw_info']['user']['sessionid'] || $sessionid == $GLOBALS['egw_info']['user']['sessionid'])
1113 1188
 		{
1114
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__." ********* about to call session_destroy!");
1189
+			if (self::ERROR_LOG_DEBUG)
1190
+			{
1191
+				error_log(__METHOD__." ********* about to call session_destroy!");
1192
+			}
1115 1193
 			session_unset();
1116 1194
 			@session_destroy();
1117 1195
 			// we need to (re-)load the eGW session-handler, as session_destroy unloads custom session-handlers
@@ -1206,7 +1284,10 @@  discard block
 block discarded – undo
1206 1284
 		}
1207 1285
 		else
1208 1286
 		{
1209
-			if ($othervars) $extravars .= ($extravars?'&':'').$othervars;
1287
+			if ($othervars)
1288
+			{
1289
+				$extravars .= ($extravars?'&':'').$othervars;
1290
+			}
1210 1291
 		}
1211 1292
 
1212 1293
 		// parse extravars string into the vars array
@@ -1215,7 +1296,11 @@  discard block
 block discarded – undo
1215 1296
 			foreach(explode('&',$extravars) as $expr)
1216 1297
 			{
1217 1298
 				list($var,$val) = explode('=', $expr,2);
1218
-				if (strpos($val,'%26') != false) $val = str_replace('%26','&',$val);	// make sure to not double encode &
1299
+				if (strpos($val,'%26') != false)
1300
+				{
1301
+					$val = str_replace('%26','&',$val);
1302
+				}
1303
+				// make sure to not double encode &
1219 1304
 				if (substr($var,-2) == '[]')
1220 1305
 				{
1221 1306
 					$vars[substr($var,0,-2)][] = $val;
@@ -1296,14 +1381,22 @@  discard block
 block discarded – undo
1296 1381
 		{
1297 1382
 			self::set_cookiedomain();
1298 1383
 		}
1299
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($cookiename,$cookievalue,$cookietime,$cookiepath,".self::$cookie_domain.")");
1384
+		if (self::ERROR_LOG_DEBUG)
1385
+		{
1386
+			error_log(__METHOD__."($cookiename,$cookievalue,$cookietime,$cookiepath,".self::$cookie_domain.")");
1387
+		}
1300 1388
 
1301 1389
 		// if we are installed in iOS as web-app, we must not set a cookietime==0 (session-cookie),
1302 1390
 		// as every change between apps will cause the cookie to get lost
1303 1391
 		static $is_iOS = null;
1304
-		if (!$cookietime && !isset($is_iOS)) $is_iOS = (bool)preg_match('/^(iPhone|iPad|iPod)/i', Header\UserAgent::mobile());
1392
+		if (!$cookietime && !isset($is_iOS))
1393
+		{
1394
+			$is_iOS = (bool)preg_match('/^(iPhone|iPad|iPod)/i', Header\UserAgent::mobile());
1395
+		}
1305 1396
 
1306
-		if(!headers_sent())	// gives only a warning, but can not send the cookie anyway
1397
+		if(!headers_sent())
1398
+		{
1399
+			// gives only a warning, but can not send the cookie anyway
1307 1400
 		{
1308 1401
 			setcookie($cookiename, $cookievalue,
1309 1402
 				!$cookietime && $is_iOS ? time()+self::IOS_SESSION_COOKIE_LIFETIME : $cookietime,
@@ -1311,6 +1404,7 @@  discard block
 block discarded – undo
1311 1404
 				// if called via HTTPS, only send cookie for https and only allow cookie access via HTTP (true)
1312 1405
 				empty($GLOBALS['egw_info']['server']['insecure_cookies']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off', true);
1313 1406
 		}
1407
+		}
1314 1408
 	}
1315 1409
 
1316 1410
 	/**
@@ -1362,15 +1456,25 @@  discard block
 block discarded – undo
1362 1456
 	 */
1363 1457
 	public static function search_instance($login,$domain_requested,&$default_domain,$server_names,array $domains=null)
1364 1458
 	{
1365
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".".array2string($server_names).".".array2string($domains).")");
1459
+		if (self::ERROR_LOG_DEBUG)
1460
+		{
1461
+			error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".".array2string($server_names).".".array2string($domains).")");
1462
+		}
1366 1463
 
1367
-		if (is_null($domains)) $domains = $GLOBALS['egw_domain'];
1464
+		if (is_null($domains))
1465
+		{
1466
+			$domains = $GLOBALS['egw_domain'];
1467
+		}
1368 1468
 
1369
-		if (!isset($default_domain) || !isset($domains[$default_domain]))	// allow to overwrite the default domain
1469
+		if (!isset($default_domain) || !isset($domains[$default_domain]))
1470
+		{
1471
+			// allow to overwrite the default domain
1370 1472
 		{
1371 1473
 			foreach((array)$server_names as $server_name)
1372 1474
 			{
1373
-				list($server_name) = explode(':', $server_name);	// remove port from HTTP_HOST
1475
+				list($server_name) = explode(':', $server_name);
1476
+		}
1477
+		// remove port from HTTP_HOST
1374 1478
 				if(isset($domains[$server_name]))
1375 1479
 				{
1376 1480
 					$default_domain = $server_name;
@@ -1395,11 +1499,14 @@  discard block
 block discarded – undo
1395 1499
 				}
1396 1500
 			}
1397 1501
 		}
1398
-		if (isset($login))	// on login
1502
+		if (isset($login))
1503
+		{
1504
+			// on login
1399 1505
 		{
1400 1506
 			if (strpos($login,'@') === false || count($domains) == 1)
1401 1507
 			{
1402 1508
 				$login .= '@' . (isset($_POST['logindomain']) ? $_POST['logindomain'] : $default_domain);
1509
+		}
1403 1510
 			}
1404 1511
 			$parts = explode('@',$login);
1405 1512
 			$domain = array_pop($parts);
@@ -1413,7 +1520,10 @@  discard block
 block discarded – undo
1413 1520
 		{
1414 1521
 			$domain = $default_domain;
1415 1522
 		}
1416
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() default_domain=".array2string($default_domain).', login='.array2string($login)." returning ".array2string($domain));
1523
+		if (self::ERROR_LOG_DEBUG)
1524
+		{
1525
+			error_log(__METHOD__."() default_domain=".array2string($default_domain).', login='.array2string($login)." returning ".array2string($domain));
1526
+		}
1417 1527
 
1418 1528
 		return $domain;
1419 1529
 	}
@@ -1452,7 +1562,10 @@  discard block
 block discarded – undo
1452 1562
 				$action = $_SERVER['PHP_SELF'];
1453 1563
 				// remove EGroupware path, if not installed in webroot
1454 1564
 				$egw_path = $GLOBALS['egw_info']['server']['webserver_url'];
1455
-				if ($egw_path[0] != '/') $egw_path = parse_url($egw_path,PHP_URL_PATH);
1565
+				if ($egw_path[0] != '/')
1566
+				{
1567
+					$egw_path = parse_url($egw_path,PHP_URL_PATH);
1568
+				}
1456 1569
 				if ($action == '/Microsoft-Server-ActiveSync')
1457 1570
 				{
1458 1571
 					$action .= '?Cmd='.$_GET['Cmd'].'&DeviceId='.$_GET['DeviceId'];
@@ -1479,7 +1592,10 @@  discard block
 block discarded – undo
1479 1592
 
1480 1593
 		$_SESSION[self::EGW_SESSION_VAR]['session_dla'] = time();
1481 1594
 		$_SESSION[self::EGW_SESSION_VAR]['session_action'] = $this->action;
1482
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__.'() _SESSION['.self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]));
1595
+		if (self::ERROR_LOG_DEBUG)
1596
+		{
1597
+			error_log(__METHOD__.'() _SESSION['.self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]));
1598
+		}
1483 1599
 
1484 1600
 		return $this->action;
1485 1601
 	}
@@ -1621,14 +1737,20 @@  discard block
 block discarded – undo
1621 1737
 					self::cache_control();
1622 1738
 					$ok = session_start();
1623 1739
 					self::decrypt();
1624
-					if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() sessionid=$sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]));
1740
+					if (self::ERROR_LOG_DEBUG)
1741
+					{
1742
+						error_log(__METHOD__."() sessionid=$sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]));
1743
+					}
1625 1744
 					return $ok;
1626 1745
 				}
1627 1746
 				break;
1628 1747
 			case PHP_SESSION_ACTIVE:
1629 1748
 				return true;	// session created by MServer
1630 1749
 		}
1631
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() no active session!");
1750
+		if (self::ERROR_LOG_DEBUG)
1751
+		{
1752
+			error_log(__METHOD__."() no active session!");
1753
+		}
1632 1754
 
1633 1755
 		return false;
1634 1756
 	}
@@ -1686,9 +1808,12 @@  discard block
 block discarded – undo
1686 1808
 					error_log(__METHOD__."($expire) called, but header already sent in $file: $line");
1687 1809
 					return;
1688 1810
 				}
1689
-				if($expire === true)	// same behavior as session_cache_limiter('private_no_expire')
1811
+				if($expire === true)
1812
+				{
1813
+					// same behavior as session_cache_limiter('private_no_expire')
1690 1814
 				{
1691 1815
 					header('Cache-Control: private, max-age='.(60*session_cache_expire()));
1816
+				}
1692 1817
 					header_remove('Expires');
1693 1818
 				}
1694 1819
 				elseif ($private)
@@ -1702,10 +1827,13 @@  discard block
 block discarded – undo
1702 1827
 					header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expire) . ' GMT');
1703 1828
 				}
1704 1829
 				// remove Pragma header, might be set by old header
1705
-				if (function_exists('header_remove'))	// PHP 5.3+
1830
+				if (function_exists('header_remove'))
1831
+				{
1832
+					// PHP 5.3+
1706 1833
 				{
1707 1834
 					header_remove('Pragma');
1708 1835
 				}
1836
+				}
1709 1837
 				else
1710 1838
 				{
1711 1839
 					header('Pragma:');
Please login to merge, or discard this patch.
api/src/Storage.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
 	 * @param string $join ='' sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or
367 367
 	 *	"LEFT JOIN table2 ON (x=y)", Note: there's no quoting done on $join!
368 368
 	 * @param boolean $need_full_no_count =false If true an unlimited query is run to determine the total number of rows, default false
369
-	 * @param mixed $only_keys =false, see search
369
+	 * @param boolean $only_keys =false, see search
370 370
 	 * @param string|array $extra_cols =array()
371 371
 	 * @return int total number of rows
372 372
 	 */
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
 	 * Check if cf is stored as 1:N relation in DB and array in memory
735 735
 	 *
736 736
 	 * @param string $name
737
-	 * @return string
737
+	 * @return boolean
738 738
 	 */
739 739
 	function is_multiple($name)
740 740
 	{
Please login to merge, or discard this patch.
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -210,12 +210,12 @@
 block discarded – undo
210 210
 	}
211 211
 
212 212
 	/**
213
-	* saves custom field data
214
-	*
215
-	* @param array $data data to save (cf's have to be prefixed with self::CF_PREFIX = #)
216
-	* @param array $extra_cols =array() extra-data to be saved
217
-	* @return bool false on success, errornumber on failure
218
-	*/
213
+	 * saves custom field data
214
+	 *
215
+	 * @param array $data data to save (cf's have to be prefixed with self::CF_PREFIX = #)
216
+	 * @param array $extra_cols =array() extra-data to be saved
217
+	 * @return bool false on success, errornumber on failure
218
+	 */
219 219
 	function save_customfields(&$data, array $extra_cols=array())
220 220
 	{
221 221
 		$id = isset($data[$this->autoinc_id]) ? $data[$this->autoinc_id] : $data[$this->db_key_cols[$this->autoinc_id]];
Please login to merge, or discard this patch.
Braces   +69 added lines, -16 removed lines patch added patch discarded remove patch
@@ -127,7 +127,11 @@  discard block
 block discarded – undo
127 127
 
128 128
 		$this->allow_multiple_values = $allow_multiple_values;
129 129
 		$this->extra_table = $extra_table;
130
-		if (!$this->extra_id) $this->extra_id = $this->autoinc_id;	// default to auto id of regular table
130
+		if (!$this->extra_id)
131
+		{
132
+			$this->extra_id = $this->autoinc_id;
133
+		}
134
+		// default to auto id of regular table
131 135
 
132 136
 		// if names from columns of extra table are only postfixes (starting with _), prepend column prefix
133 137
 		if (!($prefix=$column_prefix))
@@ -145,7 +149,10 @@  discard block
 block discarded – undo
145 149
 		) as $col => $val)
146 150
 		{
147 151
 			$this->$col = $col_name = $val;
148
-			if ($col_name[0] == '_') $this->$col = $prefix . $val;
152
+			if ($col_name[0] == '_')
153
+			{
154
+				$this->$col = $prefix . $val;
155
+			}
149 156
 		}
150 157
 		// some sanity checks, maybe they should be active only for development
151 158
 		if (!($extra_defs = $this->db->get_table_definitions($app,$extra_table)))
@@ -179,13 +186,23 @@  discard block
 block discarded – undo
179 186
 	 */
180 187
 	function read_customfields($ids,$field_names=null)
181 188
 	{
182
-		if (is_null($field_names)) $field_names = array_keys($this->customfields);
189
+		if (is_null($field_names))
190
+		{
191
+			$field_names = array_keys($this->customfields);
192
+		}
183 193
 
184 194
 		foreach((array)$ids as $key => $id)
185 195
 		{
186
-			if (!(int)$id && is_array($ids)) unset($ids[$key]);
196
+			if (!(int)$id && is_array($ids))
197
+			{
198
+				unset($ids[$key]);
199
+			}
187 200
 		}
188
-		if (!$ids || !$field_names) return array();	// nothing to do
201
+		if (!$ids || !$field_names)
202
+		{
203
+			return array();
204
+		}
205
+		// nothing to do
189 206
 
190 207
 		$entries = array();
191 208
 		foreach($this->db->select($this->extra_table,'*',array(
@@ -194,7 +211,10 @@  discard block
 block discarded – undo
194 211
 		),__LINE__,__FILE__,false,'',$this->app) as $row)
195 212
 		{
196 213
 			$entry =& $entries[$row[$this->extra_id]];
197
-			if (!is_array($entry)) $entry = array();
214
+			if (!is_array($entry))
215
+			{
216
+				$entry = array();
217
+			}
198 218
 			$field = $this->get_cf_field($row[$this->extra_key]);
199 219
 
200 220
 			if ($this->allow_multiple_values && $this->is_multiple($row[$this->extra_key]))
@@ -224,7 +244,10 @@  discard block
 block discarded – undo
224 244
 
225 245
 		foreach (array_keys((array)$this->customfields) as $name)
226 246
 		{
227
-			if (!isset($data[$field = $this->get_cf_field($name)])) continue;
247
+			if (!isset($data[$field = $this->get_cf_field($name)]))
248
+			{
249
+				continue;
250
+			}
228 251
 
229 252
 			$where = array(
230 253
 				$this->extra_id    => $id,
@@ -236,7 +259,11 @@  discard block
 block discarded – undo
236 259
 			if(empty($data[$field]) || $is_multiple || !$this->extra_has_unique_index)
237 260
 			{
238 261
 				$this->db->delete($this->extra_table,$where,__LINE__,__FILE__,$this->app);
239
-				if (empty($data[$field])) continue;	// nothing else to do for empty values
262
+				if (empty($data[$field]))
263
+				{
264
+					continue;
265
+				}
266
+				// nothing else to do for empty values
240 267
 			}
241 268
 			foreach($is_multiple && !is_array($data[$field]) ? explode(',',$data[$field]) :
242 269
 				// regular custom fields (!$is_multiple) eg. addressbook store multiple values comma-separated
@@ -309,9 +336,12 @@  discard block
 block discarded – undo
309 336
 	 */
310 337
 	function save($keys=null,$extra_where=null)
311 338
 	{
312
-		if (is_array($keys) && count($keys) && !isset($keys[0]))	// allow to use an etag, eg array('etag=etag+1')
339
+		if (is_array($keys) && count($keys) && !isset($keys[0]))
340
+		{
341
+			// allow to use an etag, eg array('etag=etag+1')
313 342
 		{
314 343
 			$this->data_merge($keys);
344
+		}
315 345
 			$keys = null;
316 346
 		}
317 347
 		$ret = parent::save($keys,$extra_where);
@@ -344,13 +374,20 @@  discard block
 block discarded – undo
344 374
 				{
345 375
 					$ids[] = $row[$this->autoinc_id];
346 376
 				}
347
-				if (!$ids) return 0;	// no rows affected
377
+				if (!$ids)
378
+				{
379
+					return 0;
380
+				}
381
+				// no rows affected
348 382
 			}
349 383
 			else
350 384
 			{
351 385
 				$ids = (array)$query[$this->autoinc_id];
352 386
 			}
353
-			if ($only_return_ids) return $ids;
387
+			if ($only_return_ids)
388
+			{
389
+				return $ids;
390
+			}
354 391
 			$this->db->delete($this->extra_table,array($this->extra_id => $ids),__LINE__,__FILE__);
355 392
 		}
356 393
 		return parent::delete($keys);
@@ -392,7 +429,10 @@  discard block
 block discarded – undo
392 429
 			{
393 430
 				foreach($selectcols as $col)
394 431
 				{
395
-					if ($this->is_cf($col)) $fields[] = $this->get_cf_name($col);
432
+					if ($this->is_cf($col))
433
+					{
434
+						$fields[] = $this->get_cf_name($col);
435
+					}
396 436
 				}
397 437
 			}
398 438
 			if (($cfs = $this->read_customfields(array_keys($id2keys),$fields)))
@@ -515,7 +555,10 @@  discard block
 block discarded – undo
515 555
 					}
516 556
 				}
517 557
 			}
518
-			if ($cfcriteria && $op =='OR') $criteria[] = implode(' OR ',$cfcriteria);
558
+			if ($cfcriteria && $op =='OR')
559
+			{
560
+				$criteria[] = implode(' OR ',$cfcriteria);
561
+			}
519 562
 		}
520 563
 		if($only_keys === true)
521 564
 		{
@@ -617,11 +660,14 @@  discard block
 block discarded – undo
617 660
 						unset($filter[$name]);
618 661
 						continue;	// ignore unavailable CF
619 662
 					}
620
-					if (!empty($val))	// empty -> dont filter
663
+					if (!empty($val))
664
+					{
665
+						// empty -> dont filter
621 666
 					{
622 667
 						if ($val[0] === '!')	// negative filter
623 668
 						{
624 669
 							$sql_filter = 'extra_filter.'.$this->extra_value.'!='.$this->db->quote(substr($val,1));
670
+					}
625 671
 						}
626 672
 						else	// using Db::expression to allow to use array() with possible values or NULL
627 673
 						{
@@ -658,9 +704,12 @@  discard block
 block discarded – undo
658 704
 					}
659 705
 					unset($filter[$name]);
660 706
 				}
661
-				elseif(is_int($name) && $this->is_cf($val))	// lettersearch: #cfname LIKE 's%'
707
+				elseif(is_int($name) && $this->is_cf($val))
708
+				{
709
+					// lettersearch: #cfname LIKE 's%'
662 710
 				{
663 711
 					$_cf = explode(' ',$val);
712
+				}
664 713
 					foreach($_cf as $cf_np)
665 714
 					{
666 715
 						// building cf_name by glueing parts together (, in case someone used whitespace in their custom field names)
@@ -675,7 +724,11 @@  discard block
 block discarded – undo
675 724
 					}
676 725
 					unset($filter[$name]);
677 726
 					$cf_name = $this->get_cf_name($cf);
678
-					if (!isset($this->customfields[$cf_name])) continue;	// ignore unavailable CF
727
+					if (!isset($this->customfields[$cf_name]))
728
+					{
729
+						continue;
730
+					}
731
+					// ignore unavailable CF
679 732
 					$join .= str_replace('extra_filter','extra_filter'.$extra_filter,$this->extra_join_filter.
680 733
 						' AND extra_filter.'.$this->extra_key.'='.$this->db->quote($cf_name).
681 734
 						' AND '.str_replace($cf,'extra_filter.'.$this->extra_value,$val));
Please login to merge, or discard this patch.
Spacing   +103 added lines, -105 removed lines patch added patch discarded remove patch
@@ -118,41 +118,41 @@  discard block
 block discarded – undo
118 118
 	 * @param boolean $allow_multiple_values =false should we allow AND store multiple values (1:N relations)
119 119
 	 * @param string $timestamp_type =null default null=leave them as is, 'ts'|'integer' use integer unix timestamps, 'object' use DateTime objects
120 120
 	 */
121
-	function __construct($app,$table,$extra_table,$column_prefix='',
122
-		$extra_key='_name',$extra_value='_value',$extra_id='_id',
123
-		Db $db=null,$no_clone=true,$allow_multiple_values=false,$timestamp_type=null)
121
+	function __construct($app, $table, $extra_table, $column_prefix = '',
122
+		$extra_key = '_name', $extra_value = '_value', $extra_id = '_id',
123
+		Db $db = null, $no_clone = true, $allow_multiple_values = false, $timestamp_type = null)
124 124
 	{
125 125
 		// calling the Storage\Base constructor
126
-		parent::__construct($app,$table,$db,$column_prefix,$no_clone,$timestamp_type);
126
+		parent::__construct($app, $table, $db, $column_prefix, $no_clone, $timestamp_type);
127 127
 
128 128
 		$this->allow_multiple_values = $allow_multiple_values;
129 129
 		$this->extra_table = $extra_table;
130
-		if (!$this->extra_id) $this->extra_id = $this->autoinc_id;	// default to auto id of regular table
130
+		if (!$this->extra_id) $this->extra_id = $this->autoinc_id; // default to auto id of regular table
131 131
 
132 132
 		// if names from columns of extra table are only postfixes (starting with _), prepend column prefix
133
-		if (!($prefix=$column_prefix))
133
+		if (!($prefix = $column_prefix))
134 134
 		{
135
-			list($prefix) = explode('_',$this->autoinc_id);
135
+			list($prefix) = explode('_', $this->autoinc_id);
136 136
 		}
137
-		elseif(substr($prefix,-1) == '_')
137
+		elseif (substr($prefix, -1) == '_')
138 138
 		{
139
-			$prefix = substr($prefix,0,-1);	// remove trailing underscore from column prefix parameter
139
+			$prefix = substr($prefix, 0, -1); // remove trailing underscore from column prefix parameter
140 140
 		}
141
-		foreach(array(
141
+		foreach (array(
142 142
 			'extra_id' => $extra_id,
143 143
 			'extra_key' => $extra_key,
144 144
 			'extra_value' => $extra_value
145 145
 		) as $col => $val)
146 146
 		{
147 147
 			$this->$col = $col_name = $val;
148
-			if ($col_name[0] == '_') $this->$col = $prefix . $val;
148
+			if ($col_name[0] == '_') $this->$col = $prefix.$val;
149 149
 		}
150 150
 		// some sanity checks, maybe they should be active only for development
151
-		if (!($extra_defs = $this->db->get_table_definitions($app,$extra_table)))
151
+		if (!($extra_defs = $this->db->get_table_definitions($app, $extra_table)))
152 152
 		{
153 153
 			throw new Exception\WrongParameter("extra table $extra_table is NOT defined!");
154 154
 		}
155
-		foreach(array('extra_id','extra_key','extra_value') as $col)
155
+		foreach (array('extra_id', 'extra_key', 'extra_value') as $col)
156 156
 		{
157 157
 			if (!$this->$col || !isset($extra_defs['fd'][$this->$col]))
158 158
 			{
@@ -177,23 +177,23 @@  discard block
 block discarded – undo
177 177
 	 * @param array $field_names =null custom fields to read, default all
178 178
 	 * @return array id => $this->cf_field(name) => value
179 179
 	 */
180
-	function read_customfields($ids,$field_names=null)
180
+	function read_customfields($ids, $field_names = null)
181 181
 	{
182 182
 		if (is_null($field_names)) $field_names = array_keys($this->customfields);
183 183
 
184
-		foreach((array)$ids as $key => $id)
184
+		foreach ((array)$ids as $key => $id)
185 185
 		{
186 186
 			if (!(int)$id && is_array($ids)) unset($ids[$key]);
187 187
 		}
188
-		if (!$ids || !$field_names) return array();	// nothing to do
188
+		if (!$ids || !$field_names) return array(); // nothing to do
189 189
 
190 190
 		$entries = array();
191
-		foreach($this->db->select($this->extra_table,'*',array(
191
+		foreach ($this->db->select($this->extra_table, '*', array(
192 192
 			$this->extra_id => $ids,
193 193
 			$this->extra_key => $field_names,
194
-		),__LINE__,__FILE__,false,'',$this->app) as $row)
194
+		), __LINE__, __FILE__, false, '', $this->app) as $row)
195 195
 		{
196
-			$entry =& $entries[$row[$this->extra_id]];
196
+			$entry = & $entries[$row[$this->extra_id]];
197 197
 			if (!is_array($entry)) $entry = array();
198 198
 			$field = $this->get_cf_field($row[$this->extra_key]);
199 199
 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 	* @param array $extra_cols =array() extra-data to be saved
217 217
 	* @return bool false on success, errornumber on failure
218 218
 	*/
219
-	function save_customfields(&$data, array $extra_cols=array())
219
+	function save_customfields(&$data, array $extra_cols = array())
220 220
 	{
221 221
 		$id = isset($data[$this->autoinc_id]) ? $data[$this->autoinc_id] : $data[$this->db_key_cols[$this->autoinc_id]];
222 222
 
@@ -233,22 +233,21 @@  discard block
 block discarded – undo
233 233
 			$is_multiple = $this->is_multiple($name);
234 234
 
235 235
 			// we explicitly need to delete fields, if value is empty or field allows multiple values or we have no unique index
236
-			if(empty($data[$field]) || $is_multiple || !$this->extra_has_unique_index)
236
+			if (empty($data[$field]) || $is_multiple || !$this->extra_has_unique_index)
237 237
 			{
238
-				$this->db->delete($this->extra_table,$where,__LINE__,__FILE__,$this->app);
239
-				if (empty($data[$field])) continue;	// nothing else to do for empty values
238
+				$this->db->delete($this->extra_table, $where, __LINE__, __FILE__, $this->app);
239
+				if (empty($data[$field])) continue; // nothing else to do for empty values
240 240
 			}
241
-			foreach($is_multiple && !is_array($data[$field]) ? explode(',',$data[$field]) :
242
-				// regular custom fields (!$is_multiple) eg. addressbook store multiple values comma-separated
241
+			foreach ($is_multiple && !is_array($data[$field]) ? explode(',', $data[$field]) : // regular custom fields (!$is_multiple) eg. addressbook store multiple values comma-separated
243 242
 				(array)(!$is_multiple && is_array($data[$field]) ? implode(',', $data[$field]) : $data[$field]) as $value)
244 243
 			{
245
-				if (!$this->db->insert($this->extra_table,array($this->extra_value => $value)+$extra_cols,$where,__LINE__,__FILE__,$this->app))
244
+				if (!$this->db->insert($this->extra_table, array($this->extra_value => $value) + $extra_cols, $where, __LINE__, __FILE__, $this->app))
246 245
 				{
247 246
 					return $this->db->Errno;
248 247
 				}
249 248
 			}
250 249
 		}
251
-		return false;	// no error
250
+		return false; // no error
252 251
 	}
253 252
 
254 253
 	/**
@@ -264,7 +263,7 @@  discard block
 block discarded – undo
264 263
 
265 264
 		if ($this->customfields)
266 265
 		{
267
-			foreach(array_keys($this->customfields) as $name)
266
+			foreach (array_keys($this->customfields) as $name)
268 267
 			{
269 268
 				if (isset($new[$field = $this->get_cf_field($name)]))
270 269
 				{
@@ -284,16 +283,16 @@  discard block
 block discarded – undo
284 283
 	 * @param string $join sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or
285 284
 	 * @return array|boolean data if row could be retrived else False
286 285
 	 */
287
-	function read($keys,$extra_cols='',$join='')
286
+	function read($keys, $extra_cols = '', $join = '')
288 287
 	{
289
-		if (!parent::read($keys,$extra_cols,$join))
288
+		if (!parent::read($keys, $extra_cols, $join))
290 289
 		{
291 290
 			return false;
292 291
 		}
293 292
 		if (($id = (int)$this->data[$this->db_key_cols[$this->autoinc_id]]) && $this->customfields &&
294 293
 			($cfs = $this->read_customfields($id)))
295 294
 		{
296
-			$this->data = array_merge($this->data,$cfs[$id]);
295
+			$this->data = array_merge($this->data, $cfs[$id]);
297 296
 		}
298 297
 		return $this->data;
299 298
 	}
@@ -307,14 +306,14 @@  discard block
 block discarded – undo
307 306
 	 * @param string|array $extra_where =null extra where clause, eg. to check an etag, returns true if no affected rows!
308 307
 	 * @return int|boolean 0 on success, or errno != 0 on error, or true if $extra_where is given and no rows affected
309 308
 	 */
310
-	function save($keys=null,$extra_where=null)
309
+	function save($keys = null, $extra_where = null)
311 310
 	{
312 311
 		if (is_array($keys) && count($keys) && !isset($keys[0]))	// allow to use an etag, eg array('etag=etag+1')
313 312
 		{
314 313
 			$this->data_merge($keys);
315 314
 			$keys = null;
316 315
 		}
317
-		$ret = parent::save($keys,$extra_where);
316
+		$ret = parent::save($keys, $extra_where);
318 317
 
319 318
 		if ($ret == 0 && $this->customfields)
320 319
 		{
@@ -332,26 +331,26 @@  discard block
 block discarded – undo
332 331
 	 * @param boolean $only_return_ids =false return $ids of delete call to db object, but not run it (can be used by extending classes!)
333 332
 	 * @return int|array affected rows, should be 1 if ok, 0 if an error or array with id's if $only_return_ids
334 333
 	 */
335
-	function delete($keys=null,$only_return_ids=false)
334
+	function delete($keys = null, $only_return_ids = false)
336 335
 	{
337 336
 		if ($this->customfields || $only_return_ids)
338 337
 		{
339
-			$query = parent::delete($keys,true);
338
+			$query = parent::delete($keys, true);
340 339
 			// check if query contains more then the id's
341 340
 			if (!isset($query[$this->autoinc_id]) || count($query) != 1)
342 341
 			{
343
-				foreach($this->db->select($this->table_name,$this->autoinc_id,$query,__LINE__,__FILE__,false,'',$this->app) as $row)
342
+				foreach ($this->db->select($this->table_name, $this->autoinc_id, $query, __LINE__, __FILE__, false, '', $this->app) as $row)
344 343
 				{
345 344
 					$ids[] = $row[$this->autoinc_id];
346 345
 				}
347
-				if (!$ids) return 0;	// no rows affected
346
+				if (!$ids) return 0; // no rows affected
348 347
 			}
349 348
 			else
350 349
 			{
351 350
 				$ids = (array)$query[$this->autoinc_id];
352 351
 			}
353 352
 			if ($only_return_ids) return $ids;
354
-			$this->db->delete($this->extra_table,array($this->extra_id => $ids),__LINE__,__FILE__);
353
+			$this->db->delete($this->extra_table, array($this->extra_id => $ids), __LINE__, __FILE__);
355 354
 		}
356 355
 		return parent::delete($keys);
357 356
 	}
@@ -374,32 +373,32 @@  discard block
 block discarded – undo
374 373
 	 * @param string|array $extra_cols =array()
375 374
 	 * @return int total number of rows
376 375
 	 */
377
-	function get_rows($query,&$rows,&$readonlys,$join='',$need_full_no_count=false,$only_keys=false,$extra_cols=array())
376
+	function get_rows($query, &$rows, &$readonlys, $join = '', $need_full_no_count = false, $only_keys = false, $extra_cols = array())
378 377
 	{
379
-		parent::get_rows($query,$rows,$readonlys,$join,$need_full_no_count,$only_keys,$extra_cols);
378
+		parent::get_rows($query, $rows, $readonlys, $join, $need_full_no_count, $only_keys, $extra_cols);
380 379
 
381
-		$selectcols = $query['selectcols'] ? explode(',',$query['selectcols']) : array();
380
+		$selectcols = $query['selectcols'] ? explode(',', $query['selectcols']) : array();
382 381
 
383
-		if ($rows && $this->customfields && (!$selectcols || in_array('customfields',$selectcols)))
382
+		if ($rows && $this->customfields && (!$selectcols || in_array('customfields', $selectcols)))
384 383
 		{
385 384
 			$id2keys = array();
386
-			foreach($rows as $key => $row)
385
+			foreach ($rows as $key => $row)
387 386
 			{
388 387
 				$id2keys[$row[$this->db_key_cols[$this->autoinc_id]]] = $key;
389 388
 			}
390 389
 			// check if only certain cf's to show
391 390
 			if (!in_array('customfields', $selectcols))
392 391
 			{
393
-				foreach($selectcols as $col)
392
+				foreach ($selectcols as $col)
394 393
 				{
395 394
 					if ($this->is_cf($col)) $fields[] = $this->get_cf_name($col);
396 395
 				}
397 396
 			}
398
-			if (($cfs = $this->read_customfields(array_keys($id2keys),$fields)))
397
+			if (($cfs = $this->read_customfields(array_keys($id2keys), $fields)))
399 398
 			{
400
-				foreach($cfs as $id => $data)
399
+				foreach ($cfs as $id => $data)
401 400
 				{
402
-					$rows[$id2keys[$id]] = array_merge($rows[$id2keys[$id]],$data);
401
+					$rows[$id2keys[$id]] = array_merge($rows[$id2keys[$id]], $data);
403 402
 				}
404 403
 			}
405 404
 		}
@@ -426,7 +425,7 @@  discard block
 block discarded – undo
426 425
 	 * @param boolean $need_full_no_count =false If true an unlimited query is run to determine the total number of rows, default false
427 426
 	 * @return array|NULL array of matching rows (the row is an array of the cols) or NULL
428 427
 	 */
429
-	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)
428
+	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)
430 429
 	{
431 430
 		//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())).')');
432 431
 
@@ -434,7 +433,7 @@  discard block
 block discarded – undo
434 433
 		if (!$this->customfields && strpos($order_by, self::CF_PREFIX) === false &&
435 434
 			strpos(implode(',', array_keys($filter ? $filter : [])), self::CF_PREFIX) === false)
436 435
 		{
437
-			return parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count);
436
+			return parent::search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, $start, $filter, $join, $need_full_no_count);
438 437
 		}
439 438
 		if ($only_keys === false)
440 439
 		{
@@ -443,7 +442,7 @@  discard block
 block discarded – undo
443 442
 		// if string given as criteria --> search in all (or $this->columns_to_search) columns including custom fields
444 443
 		if ($criteria && is_string($criteria))
445 444
 		{
446
-			$criteria = $this->search2criteria($criteria,$wildcard,$op);
445
+			$criteria = $this->search2criteria($criteria, $wildcard, $op);
447 446
 		}
448 447
 		if ($criteria && is_array($criteria))
449 448
 		{
@@ -453,10 +452,10 @@  discard block
 block discarded – undo
453 452
 				// we should check if the CF is (still) available, but that makes the slow search even slower :(
454 453
 				if (($negate = $criteria[$this->extra_value][0] === '!'))
455 454
 				{
456
-					$criteria[$this->extra_value] = substr($criteria[$this->extra_value],1);
455
+					$criteria[$this->extra_value] = substr($criteria[$this->extra_value], 1);
457 456
 				}
458
-				$criteria[] = $this->extra_table.'.'.$this->extra_value . ' ' .($negate ? 'NOT ' : '').
459
-					$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE]. ' ' .
457
+				$criteria[] = $this->extra_table.'.'.$this->extra_value.' '.($negate ? 'NOT ' : '').
458
+					$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.
460 459
 					$this->db->quote($wildcard.$criteria[$this->extra_value].$wildcard);
461 460
 				unset($criteria[$this->extra_value]);
462 461
 			}
@@ -465,14 +464,14 @@  discard block
 block discarded – undo
465 464
 			{
466 465
 				if ($criteria[$this->autoinc_id])
467 466
 				{
468
-					$criteria[] = $this->db->expression($this->table_name,$this->table_name.'.',
467
+					$criteria[] = $this->db->expression($this->table_name, $this->table_name.'.',
469 468
 						array($this->autoinc_id => $criteria[$this->autoinc_id]));
470 469
 				}
471 470
 				unset($criteria[$this->autoinc_id]);
472 471
 			}
473 472
 			// replace ambiguous column with (an exact match of) table_name.column
474 473
 			$extra_join_added = $join && strpos($join, $this->extra_join) !== false;
475
-			foreach($criteria as $name => $val)
474
+			foreach ($criteria as $name => $val)
476 475
 			{
477 476
 				// only add extra_join, if we really need it
478 477
 				if (!$extra_join_added && (
@@ -484,9 +483,9 @@  discard block
 block discarded – undo
484 483
 					$extra_join_added = true;
485 484
 				}
486 485
 				$extra_columns = $this->db->get_table_definitions($this->app, $this->extra_table);
487
-				if(is_string($name) && $extra_columns['fd'][array_search($name, $this->db_cols)])
486
+				if (is_string($name) && $extra_columns['fd'][array_search($name, $this->db_cols)])
488 487
 				{
489
-					$criteria[] = $this->db->expression($this->table_name,$this->table_name.'.',array(
488
+					$criteria[] = $this->db->expression($this->table_name, $this->table_name.'.', array(
490 489
 						array_search($name, $this->db_cols) => $val,
491 490
 					));
492 491
 					unset($criteria[$name]);
@@ -498,12 +497,12 @@  discard block
 block discarded – undo
498 497
 						$name = substr($name, 1);
499 498
 						if (($negate = $criteria[$name][0] === '!'))
500 499
 						{
501
-							$val = substr($val,1);
500
+							$val = substr($val, 1);
502 501
 						}
503
-						$cfcriteria[] = '(' . $this->extra_table.'.'.$this->extra_value . ' ' .($negate ? 'NOT ' : '').
504
-							$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE]. ' ' .
505
-							$this->db->quote($wildcard.$val.$wildcard) . ' AND ' .
506
-							$this->extra_table.'.'.$this->extra_key . ' = ' . $this->db->quote($name) .
502
+						$cfcriteria[] = '('.$this->extra_table.'.'.$this->extra_value.' '.($negate ? 'NOT ' : '').
503
+							$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.
504
+							$this->db->quote($wildcard.$val.$wildcard).' AND '.
505
+							$this->extra_table.'.'.$this->extra_key.' = '.$this->db->quote($name).
507 506
 							')';
508 507
 						unset($criteria[self::CF_PREFIX.$name]);
509 508
 					}
@@ -515,43 +514,43 @@  discard block
 block discarded – undo
515 514
 					}
516 515
 				}
517 516
 			}
518
-			if ($cfcriteria && $op =='OR') $criteria[] = implode(' OR ',$cfcriteria);
517
+			if ($cfcriteria && $op == 'OR') $criteria[] = implode(' OR ', $cfcriteria);
519 518
 		}
520
-		if($only_keys === true)
519
+		if ($only_keys === true)
521 520
 		{
522 521
 			// Expand to keys here, so table_name can be prepended below
523 522
 			$only_keys = array_values($this->db_key_cols);
524 523
 		}
525 524
 		// replace ambiguous column with (an exact match of) table_name.column
526
-		if(is_array($only_keys))
525
+		if (is_array($only_keys))
527 526
 		{
528
-			foreach($only_keys as $key => &$col)
527
+			foreach ($only_keys as $key => &$col)
529 528
 			{
530
-				if(is_numeric($key) && in_array($col, $this->db_cols, true))
529
+				if (is_numeric($key) && in_array($col, $this->db_cols, true))
531 530
 				{
532
-					$col = $this->table_name .'.'.array_search($col, $this->db_cols).' AS '.$col;
531
+					$col = $this->table_name.'.'.array_search($col, $this->db_cols).' AS '.$col;
533 532
 				}
534 533
 			}
535 534
 		}
536 535
 		// check if we order by a custom field --> join cf table for given cf and order by it's value
537
-		if (strpos($order_by,self::CF_PREFIX) !== false)
536
+		if (strpos($order_by, self::CF_PREFIX) !== false)
538 537
 		{
539 538
 			// fields to order by, as cutomfields may have names with spaces, we examine each order by criteria
540
-			$fields2order = explode(',',$order_by);
541
-			foreach($fields2order as $v)
539
+			$fields2order = explode(',', $order_by);
540
+			foreach ($fields2order as $v)
542 541
 			{
543
-				if (strpos($v,self::CF_PREFIX) !== false)
542
+				if (strpos($v, self::CF_PREFIX) !== false)
544 543
 				{
545 544
 					// we found a customfield, so we split that part by space char in order to get Sorting Direction and Fieldname
546
-					$buff = explode(' ',trim($v));
545
+					$buff = explode(' ', trim($v));
547 546
 					$orderDir = array_pop($buff);
548
-					$key = substr(trim(implode(' ',$buff)), 1);
547
+					$key = substr(trim(implode(' ', $buff)), 1);
549 548
 					if (!isset($this->customfields[$key]))
550 549
 					{
551 550
 						$order_by = preg_replace('/'.preg_quote($v, '/').',?/', '', $order_by);
552
-						continue;	// ignore unavaiable CF
551
+						continue; // ignore unavaiable CF
553 552
 					}
554
-					switch($this->customfields[$key]['type'])
553
+					switch ($this->customfields[$key]['type'])
555 554
 					{
556 555
 						case 'int':
557 556
 							$order_by = str_replace($v, 'extra_order.'.$this->extra_value.' IS NULL,'.
@@ -584,26 +583,26 @@  discard block
 block discarded – undo
584 583
 		{
585 584
 			$_cfnames = array_keys($this->customfields);
586 585
 			$extra_filter = null;
587
-			foreach($filter as $name => $val)
586
+			foreach ($filter as $name => $val)
588 587
 			{
589 588
 				// replace ambiguous auto-id with (an exact match of) table_name.autoid
590 589
 				if (is_string($name) && $name == $this->autoinc_id)
591 590
 				{
592 591
 					if ((int)$filter[$this->autoinc_id])
593 592
 					{
594
-						$filter[] = $this->db->expression($this->table_name,$this->table_name.'.',array(
593
+						$filter[] = $this->db->expression($this->table_name, $this->table_name.'.', array(
595 594
 							$this->autoinc_id => $filter[$this->autoinc_id],
596 595
 						));
597 596
 					}
598 597
 					unset($filter[$this->autoinc_id]);
599 598
 				}
600 599
 				// replace ambiguous column with (an exact match of) table_name.column
601
-				elseif (is_string($name) && $val!=null && in_array($name, $this->db_cols))
600
+				elseif (is_string($name) && $val != null && in_array($name, $this->db_cols))
602 601
 				{
603 602
 					$extra_columns = $this->db->get_table_definitions($this->app, $this->extra_table);
604 603
 					if ($extra_columns['fd'][array_search($name, $this->db_cols)])
605 604
 					{
606
-						$filter[] = $this->db->expression($this->table_name,$this->table_name.'.',array(
605
+						$filter[] = $this->db->expression($this->table_name, $this->table_name.'.', array(
607 606
 							array_search($name, $this->db_cols) => $val,
608 607
 						));
609 608
 						unset($filter[$name]);
@@ -615,59 +614,59 @@  discard block
 block discarded – undo
615 614
 					if (!isset($this->customfields[$cf_name]))
616 615
 					{
617 616
 						unset($filter[$name]);
618
-						continue;	// ignore unavailable CF
617
+						continue; // ignore unavailable CF
619 618
 					}
620 619
 					if (!empty($val))	// empty -> dont filter
621 620
 					{
622 621
 						if ($val[0] === '!')	// negative filter
623 622
 						{
624
-							$sql_filter = 'extra_filter.'.$this->extra_value.'!='.$this->db->quote(substr($val,1));
623
+							$sql_filter = 'extra_filter.'.$this->extra_value.'!='.$this->db->quote(substr($val, 1));
625 624
 						}
626 625
 						else	// using Db::expression to allow to use array() with possible values or NULL
627 626
 						{
628
-							if($this->customfields[$cf_name]['type'] == 'select' &&
627
+							if ($this->customfields[$cf_name]['type'] == 'select' &&
629 628
 								$this->customfields[$cf_name]['rows'] > 1)
630 629
 							{
631 630
 								// Multi-select - any entry with the filter value selected matches
632
-								$sql_filter = str_replace($this->extra_value,'extra_filter.'.
633
-									$this->extra_value,$this->db->expression($this->extra_table,array(
634
-										$this->db->concat("','",$this->extra_value,"','").' '.$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote('%,'.$val.',%')
631
+								$sql_filter = str_replace($this->extra_value, 'extra_filter.'.
632
+									$this->extra_value, $this->db->expression($this->extra_table, array(
633
+										$this->db->concat("','", $this->extra_value, "','").' '.$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote('%,'.$val.',%')
635 634
 									))
636 635
 								);
637 636
 							}
638 637
 							elseif ($this->customfields[$cf_name]['type'] == 'text')
639 638
 							{
640
-								$sql_filter = str_replace($this->extra_value,'extra_filter.'.$this->extra_value,
641
-										$this->db->expression($this->extra_table,array(
639
+								$sql_filter = str_replace($this->extra_value, 'extra_filter.'.$this->extra_value,
640
+										$this->db->expression($this->extra_table, array(
642 641
 										$this->extra_value.' '.$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote($wildcard.$val.$wildcard)
643 642
 									))
644 643
 								);
645 644
 							}
646 645
 							else
647 646
 							{
648
-								$sql_filter = str_replace($this->extra_value,'extra_filter.'.
649
-									$this->extra_value,$this->db->expression($this->extra_table,array($this->extra_value => $val)));
647
+								$sql_filter = str_replace($this->extra_value, 'extra_filter.'.
648
+									$this->extra_value, $this->db->expression($this->extra_table, array($this->extra_value => $val)));
650 649
 							}
651 650
 						}
652 651
 						// need to use a LEFT JOIN for negative search or to allow NULL values
653
-						$need_left_join = $val[0] === '!' || strpos($sql_filter,'IS NULL') !== false ? ' LEFT ' : '';
654
-						$join .= str_replace('extra_filter','extra_filter'.$extra_filter,$need_left_join.$this->extra_join_filter.
652
+						$need_left_join = $val[0] === '!' || strpos($sql_filter, 'IS NULL') !== false ? ' LEFT ' : '';
653
+						$join .= str_replace('extra_filter', 'extra_filter'.$extra_filter, $need_left_join.$this->extra_join_filter.
655 654
 							' AND extra_filter.'.$this->extra_key.'='.$this->db->quote($cf_name).
656 655
 							' AND '.$sql_filter);
657 656
 						++$extra_filter;
658 657
 					}
659 658
 					unset($filter[$name]);
660 659
 				}
661
-				elseif(is_int($name) && $this->is_cf($val))	// lettersearch: #cfname LIKE 's%'
660
+				elseif (is_int($name) && $this->is_cf($val))	// lettersearch: #cfname LIKE 's%'
662 661
 				{
663
-					$_cf = explode(' ',$val);
664
-					foreach($_cf as $cf_np)
662
+					$_cf = explode(' ', $val);
663
+					foreach ($_cf as $cf_np)
665 664
 					{
666 665
 						// building cf_name by glueing parts together (, in case someone used whitespace in their custom field names)
667
-						$tcf_name = ($tcf_name?$tcf_name.' ':'').$cf_np;
666
+						$tcf_name = ($tcf_name ? $tcf_name.' ' : '').$cf_np;
668 667
 						// reacts on the first one found that matches an existing customfield, should be better then the old behavior of
669 668
 						// simply splitting by " " and using the first part
670
-						if ($this->is_cf($tcf_name) && ($cfn = $this->get_cf_name($tcf_name)) && array_search($cfn,(array)$_cfnames,true)!==false )
669
+						if ($this->is_cf($tcf_name) && ($cfn = $this->get_cf_name($tcf_name)) && array_search($cfn, (array)$_cfnames, true) !== false)
671 670
 						{
672 671
 							$cf = $tcf_name;
673 672
 							break;
@@ -675,10 +674,10 @@  discard block
 block discarded – undo
675 674
 					}
676 675
 					unset($filter[$name]);
677 676
 					$cf_name = $this->get_cf_name($cf);
678
-					if (!isset($this->customfields[$cf_name])) continue;	// ignore unavailable CF
679
-					$join .= str_replace('extra_filter','extra_filter'.$extra_filter,$this->extra_join_filter.
677
+					if (!isset($this->customfields[$cf_name])) continue; // ignore unavailable CF
678
+					$join .= str_replace('extra_filter', 'extra_filter'.$extra_filter, $this->extra_join_filter.
680 679
 						' AND extra_filter.'.$this->extra_key.'='.$this->db->quote($cf_name).
681
-						' AND '.str_replace($cf,'extra_filter.'.$this->extra_value,$val));
680
+						' AND '.str_replace($cf, 'extra_filter.'.$this->extra_value, $val));
682 681
 					++$extra_filter;
683 682
 				}
684 683
 			}
@@ -689,15 +688,14 @@  discard block
 block discarded – undo
689 688
 			if (is_array($only_keys))
690 689
 			{
691 690
 				$only_keys = array_values($only_keys);
692
-				$only_keys[0] = 'DISTINCT '.($only_keys[0] != $this->autoinc_id ? $only_keys[0] :
693
-					$this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id);
691
+				$only_keys[0] = 'DISTINCT '.($only_keys[0] != $this->autoinc_id ? $only_keys[0] : $this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id);
694 692
 			}
695 693
 			else
696 694
 			{
697 695
 				$only_keys = 'DISTINCT '.$only_keys;
698 696
 			}
699 697
 		}
700
-		return parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count);
698
+		return parent::search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, $start, $filter, $join, $need_full_no_count);
701 699
 	}
702 700
 
703 701
 	/**
@@ -737,7 +735,7 @@  discard block
 block discarded – undo
737 735
 	 */
738 736
 	function get_cf_name($field)
739 737
 	{
740
-		return substr($field,1);
738
+		return substr($field, 1);
741 739
 	}
742 740
 
743 741
 	/**
@@ -759,7 +757,7 @@  discard block
 block discarded – undo
759 757
 	 */
760 758
 	function is_multiple($name)
761 759
 	{
762
-		return $this->allow_multiple_values && in_array($this->customfields[$name]['type'],array('select','select-account')) &&
760
+		return $this->allow_multiple_values && in_array($this->customfields[$name]['type'], array('select', 'select-account')) &&
763 761
 			$this->customfields[$name]['rows'] > 1;
764 762
 	}
765 763
 }
Please login to merge, or discard this patch.
api/src/Storage/History.php 3 patches
Doc Comments   +2 added lines patch added patch discarded remove patch
@@ -112,6 +112,8 @@
 block discarded – undo
112 112
 
113 113
 	/**
114 114
 	 * Static function to add a history record
115
+	 * @param string $field_code
116
+	 * @param string $new_value
115 117
 	 */
116 118
 	public static function static_add($appname, $id, $user, $field_code, $new_value, $old_value = '')
117 119
 	{
Please login to merge, or discard this patch.
Braces   +16 added lines, -5 removed lines patch added patch discarded remove patch
@@ -142,7 +142,10 @@  discard block
 block discarded – undo
142 142
 	 */
143 143
 	function search($filter,$order='history_id',$sort='DESC',$limit=null)
144 144
 	{
145
-		if (!is_array($filter)) $filter = is_numeric($filter) ? array('history_record_id' => $filter) : array();
145
+		if (!is_array($filter))
146
+		{
147
+			$filter = is_numeric($filter) ? array('history_record_id' => $filter) : array();
148
+		}
146 149
 
147 150
 		if (!$order || !preg_match('/^[a-z0-9_]+$/i',$order) || !preg_match('/^(asc|desc)?$/i',$sort))
148 151
 		{
@@ -160,10 +163,16 @@  discard block
 block discarded – undo
160 163
 				unset($filter[$col]);
161 164
 			}
162 165
 		}
163
-		if (!isset($filter['history_appname'])) $filter['history_appname'] = $this->appname;
166
+		if (!isset($filter['history_appname']))
167
+		{
168
+			$filter['history_appname'] = $this->appname;
169
+		}
164 170
 
165 171
 		// do not try to read all history entries of an app
166
-		if (!$filter['history_record_id']) return array();
172
+		if (!$filter['history_record_id'])
173
+		{
174
+			return array();
175
+		}
167 176
 
168 177
 		$rows = array();
169 178
 		foreach($this->db->select(self::TABLE, '*', $filter, __LINE__, __FILE__,
@@ -188,8 +197,10 @@  discard block
 block discarded – undo
188 197
 		$rows = array();
189 198
 		$filter['history_appname'] = $query['appname'];
190 199
 		$filter['history_record_id'] = $query['record_id'];
191
-		if(is_array($query['colfilter'])) {
192
-			foreach($query['colfilter'] as $column => $value) {
200
+		if(is_array($query['colfilter']))
201
+		{
202
+			foreach($query['colfilter'] as $column => $value)
203
+			{
193 204
 				$filter[$column] = $value;
194 205
 			}
195 206
 		}
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 	 * @param string $appname app name this instance operates on
52 52
 	 * @return historylog
53 53
 	 */
54
-	function __construct($appname='',$user=null)
54
+	function __construct($appname = '', $user = null)
55 55
 	{
56 56
 		$this->appname = $appname ? $appname : $GLOBALS['egw_info']['flags']['currentapp'];
57 57
 		$this->user = !is_null($user) ? $user : $GLOBALS['egw_info']['user']['account_id'];
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 		{
81 81
 			$where['history_record_id'] = $record_id;
82 82
 		}
83
-		$this->db->delete(self::TABLE,$where,__LINE__,__FILE__);
83
+		$this->db->delete(self::TABLE, $where, __LINE__, __FILE__);
84 84
 
85 85
 		return $this->db->affected_rows();
86 86
 	}
@@ -93,11 +93,11 @@  discard block
 block discarded – undo
93 93
 	 * @param string $new_value new value
94 94
 	 * @param string $old_value old value
95 95
 	 */
96
-	function add($status,$record_id,$new_value,$old_value)
96
+	function add($status, $record_id, $new_value, $old_value)
97 97
 	{
98 98
 		if ($new_value != $old_value)
99 99
 		{
100
-			$this->db->insert(self::TABLE,array(
100
+			$this->db->insert(self::TABLE, array(
101 101
 				'history_record_id' => $record_id,
102 102
 				'history_appname'   => $this->appname,
103 103
 				'history_owner'     => $this->user,
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 				'history_timestamp' => time(),
108 108
 				'sessionid' => $GLOBALS['egw']->session->sessionid_access_log,
109 109
 				'share_email'       => isset($GLOBALS['egw']->sharing) ? $GLOBALS['egw']->sharing->get_share_with() : '',
110
-			),false,__LINE__,__FILE__);
110
+			), false, __LINE__, __FILE__);
111 111
 		}
112 112
 	}
113 113
 
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 	{
119 119
 		if ($new_value != $old_value)
120 120
 		{
121
-			$GLOBALS['egw']->db->insert(self::TABLE,array(
121
+			$GLOBALS['egw']->db->insert(self::TABLE, array(
122 122
 				'history_record_id' => $id,
123 123
 				'history_appname'   => $appname,
124 124
 				'history_owner'     => (int)$user,
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 				'history_timestamp' => time(),
129 129
 				'sessionid' => $GLOBALS['egw']->session->sessionid_access_log,
130 130
 				'share_email'       => isset($GLOBALS['egw']->sharing) ? $GLOBALS['egw']->sharing->get_share_with() : '',
131
-			),false,__LINE__,__FILE__);
131
+			), false, __LINE__, __FILE__);
132 132
 		}
133 133
 	}
134 134
 
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
 	 * @return array of arrays with keys id, record_id, appname, owner (account_id), status, new_value, old_value,
143 143
 	 * 	timestamp (Y-m-d H:i:s in servertime), user_ts (timestamp in user-time)
144 144
 	 */
145
-	function search($filter,$order='history_id',$sort='DESC',$limit=null)
145
+	function search($filter, $order = 'history_id', $sort = 'DESC', $limit = null)
146 146
 	{
147 147
 		if (!is_array($filter)) $filter = is_numeric($filter) ? array('history_record_id' => $filter) : array();
148 148
 
149
-		if (!$order || !preg_match('/^[a-z0-9_]+$/i',$order) || !preg_match('/^(asc|desc)?$/i',$sort))
149
+		if (!$order || !preg_match('/^[a-z0-9_]+$/i', $order) || !preg_match('/^(asc|desc)?$/i', $sort))
150 150
 		{
151 151
 			$orderby = 'ORDER BY history_id DESC';
152 152
 		}
@@ -154,9 +154,9 @@  discard block
 block discarded – undo
154 154
 		{
155 155
 			$orderby = "ORDER BY $order $sort";
156 156
 		}
157
-		foreach($filter as $col => $value)
157
+		foreach ($filter as $col => $value)
158 158
 		{
159
-			if (!is_numeric($col) && substr($col,0,8) != 'history_')
159
+			if (!is_numeric($col) && substr($col, 0, 8) != 'history_')
160 160
 			{
161 161
 				$filter['history_'.$col] = $value;
162 162
 				unset($filter[$col]);
@@ -168,11 +168,11 @@  discard block
 block discarded – undo
168 168
 		if (!$filter['history_record_id']) return array();
169 169
 
170 170
 		$rows = array();
171
-		foreach($this->db->select(self::TABLE, '*', $filter, __LINE__, __FILE__,
171
+		foreach ($this->db->select(self::TABLE, '*', $filter, __LINE__, __FILE__,
172 172
 			isset($limit) ? 0 : false, $orderby, 'phpgwapi', $limit) as $row)
173 173
 		{
174 174
 			$row['user_ts'] = $this->db->from_timestamp($row['history_timestamp']) + 3600 * $GLOBALS['egw_info']['user']['preferences']['common']['tz_offset'];
175
-			$rows[] = Api\Db::strip_array_keys($row,'history_');
175
+			$rows[] = Api\Db::strip_array_keys($row, 'history_');
176 176
 		}
177 177
 		return $rows;
178 178
 	}
@@ -190,8 +190,8 @@  discard block
 block discarded – undo
190 190
 		$rows = array();
191 191
 		$filter['history_appname'] = $query['appname'];
192 192
 		$filter['history_record_id'] = $query['record_id'];
193
-		if(is_array($query['colfilter'])) {
194
-			foreach($query['colfilter'] as $column => $value) {
193
+		if (is_array($query['colfilter'])) {
194
+			foreach ($query['colfilter'] as $column => $value) {
195 195
 				$filter[$column] = $value;
196 196
 			}
197 197
 		}
@@ -201,13 +201,13 @@  discard block
 block discarded – undo
201 201
 		{
202 202
 			$to_or[] = "history_status NOT LIKE '#%'";
203 203
 			// explicitly allow "##" used to store iCal/vCard X-attributes
204
-			if (in_array($filter['history_appname'], array('calendar','infolog','addressbook')))
204
+			if (in_array($filter['history_appname'], array('calendar', 'infolog', 'addressbook')))
205 205
 			{
206 206
 				$to_or[] = "history_status LIKE '##%'";
207 207
 			}
208 208
 			if (($cfs = Customfields::get($filter['history_appname'])))
209 209
 			{
210
-				$to_or[] =  'history_status IN ('.implode(',', array_map(function($str)
210
+				$to_or[] = 'history_status IN ('.implode(',', array_map(function($str)
211 211
 				{
212 212
 					return $GLOBALS['egw']->db->quote('#'.$str);
213 213
 				}, array_keys($cfs))).')';
@@ -231,21 +231,21 @@  discard block
 block discarded – undo
231 231
 		));
232 232
 
233 233
 		// Add in files, if possible
234
-		if($GLOBALS['egw_info']['user']['apps']['filemanager'] &&
234
+		if ($GLOBALS['egw_info']['user']['apps']['filemanager'] &&
235 235
 			($sqlfs_sw = new Api\Vfs\Sqlfs\StreamWrapper()) &&
236
-			($file = $sqlfs_sw->url_stat("/apps/{$query['appname']}/{$query['record_id']}",STREAM_URL_STAT_LINK)))
236
+			($file = $sqlfs_sw->url_stat("/apps/{$query['appname']}/{$query['record_id']}", STREAM_URL_STAT_LINK)))
237 237
 		{
238 238
 			$_query[] = array(
239 239
 				'table' => Api\Vfs\Sqlfs\StreamWrapper::TABLE,
240
-				'cols' =>array('fs_id', 'fs_dir', "'filemanager'",'COALESCE(fs_modifier,fs_creator)',"'~file~'",'fs_name','fs_modified', 'fs_mime', '"" AS share_email'),
240
+				'cols' =>array('fs_id', 'fs_dir', "'filemanager'", 'COALESCE(fs_modifier,fs_creator)', "'~file~'", 'fs_name', 'fs_modified', 'fs_mime', '"" AS share_email'),
241 241
 				'where' => array('fs_dir' => $file['ino'])
242 242
 			);
243 243
 		}
244 244
 		$new_file_id = array();
245
-		foreach($GLOBALS['egw']->db->union(
245
+		foreach ($GLOBALS['egw']->db->union(
246 246
 			$_query,
247 247
 			__LINE__, __FILE__,
248
-			' ORDER BY ' . ($query['order'] ? $query['order'] : 'history_timestamp') . ' ' . ($query['sort'] ? $query['sort'] : 'DESC'),
248
+			' ORDER BY '.($query['order'] ? $query['order'] : 'history_timestamp').' '.($query['sort'] ? $query['sort'] : 'DESC'),
249 249
 			$query['start'],
250 250
 			$query['num_rows']
251 251
 		) as $row)
@@ -253,15 +253,15 @@  discard block
 block discarded – undo
253 253
 			$row['user_ts'] = $GLOBALS['egw']->db->from_timestamp($row['history_timestamp']) + 3600 * $GLOBALS['egw_info']['user']['preferences']['common']['tz_offset'];
254 254
 
255 255
 			// Explode multi-part values
256
-			foreach(array('history_new_value','history_old_value') as $field)
256
+			foreach (array('history_new_value', 'history_old_value') as $field)
257 257
 			{
258
-				if(strpos($row[$field],Tracking::ONE2N_SEPERATOR) !== false)
258
+				if (strpos($row[$field], Tracking::ONE2N_SEPERATOR) !== false)
259 259
 				{
260
-					$row[$field] = explode(Tracking::ONE2N_SEPERATOR,$row[$field]);
260
+					$row[$field] = explode(Tracking::ONE2N_SEPERATOR, $row[$field]);
261 261
 				}
262 262
 			}
263 263
 			// Get information needed for proper display
264
-			if($row['history_appname'] == 'filemanager')
264
+			if ($row['history_appname'] == 'filemanager')
265 265
 			{
266 266
 				$new_version = $new_file_id[$row['history_new_value']];
267 267
 				$new_file_id[$row['history_new_value']] = count($rows);
@@ -277,14 +277,14 @@  discard block
 block discarded – undo
277 277
 					'mime' => $row['history_old_value']
278 278
 				);
279 279
 				$row['history_old_value'] = '';
280
-				if($new_version !== null)
280
+				if ($new_version !== null)
281 281
 				{
282 282
 					$rows[$new_version]['old_value'] = $row['history_new_value'];
283 283
 				}
284 284
 			}
285
-			$rows[] = Api\Db::strip_array_keys($row,'history_');
285
+			$rows[] = Api\Db::strip_array_keys($row, 'history_');
286 286
 		}
287
-		$total = $GLOBALS['egw']->db->union($_query,__LINE__,__FILE__)->NumRows();
287
+		$total = $GLOBALS['egw']->db->union($_query, __LINE__, __FILE__)->NumRows();
288 288
 
289 289
 		// allow to hook into get_rows of other apps
290 290
 		Api\Hooks::process(array(
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
 			'value'         => &$query,
294 294
 			'rows'          => &$rows,
295 295
 			'total'         => &$total,
296
-		), array(), true);	// true = no permission check
296
+		), array(), true); // true = no permission check
297 297
 
298 298
 		return $total;
299 299
 	}
Please login to merge, or discard this patch.
api/src/Storage/Tracking.php 3 patches
Doc Comments   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -528,7 +528,7 @@  discard block
 block discarded – undo
528 528
 	 * @param array $data current entry
529 529
 	 * @param array $old = null old/last state of the entry or null for a new entry
530 530
 	 * @param boolean $deleted = null can be set to true to let the tracking know the item got deleted or undelted
531
-	 * @param array $email_notified=null if present will return the emails notified, if given emails in that list will not be notified
531
+	 * @param array $email_notified if present will return the emails notified, if given emails in that list will not be notified
532 532
 	 * @return boolean true on success, false on error (error messages are in $this->errors)
533 533
 	 */
534 534
 	public function do_notifications($data,$old,$deleted=null,&$email_notified=null)
@@ -824,7 +824,6 @@  discard block
 block discarded – undo
824 824
 	 * The default implementation prefers depending on the prefer_user_as_sender class-var the user over
825 825
 	 * what is returned by get_config('sender').
826 826
 	 *
827
-	 * @param int $user account_lid of user
828 827
 	 * @param array $data
829 828
 	 * @param array $old
830 829
 	 * @param bool $prefer_id returns the userid rather than email
Please login to merge, or discard this patch.
Braces   +165 added lines, -41 removed lines patch added patch discarded remove patch
@@ -260,11 +260,17 @@  discard block
 block discarded – undo
260 260
 			$header_done = false;
261 261
 			foreach($cfs as $name => $field)
262 262
 			{
263
-				if (in_array($field['type'], Customfields::$non_printable_fields)) continue;
263
+				if (in_array($field['type'], Customfields::$non_printable_fields))
264
+				{
265
+					continue;
266
+				}
264 267
 
265 268
 				// Sometimes cached customfields let private fields the user can access
266 269
 				// leak through.  If no specific user provided, make sure we don't expose them.
267
-				if ($user === false && $field['private']) continue;
270
+				if ($user === false && $field['private'])
271
+				{
272
+					continue;
273
+				}
268 274
 
269 275
 				if (!$header_done)
270 276
 				{
@@ -362,8 +368,14 @@  discard block
 block discarded – undo
362 368
 		{
363 369
 			//error_log(__METHOD__.__LINE__.' Field:'.$name. ' Value (new):'.array2string($data[$name]));
364 370
 			//error_log(__METHOD__.__LINE__.' Field:'.$name. ' Value (old):'.array2string($old[$name]));
365
-			if (is_array($data[$name]) && array_key_exists('id',$data[$name])) $data[$name] = $data[$name]['id'];
366
-			if (is_array($old[$name]) && array_key_exists('id',$old[$name])) $old[$name] = $old[$name]['id'];
371
+			if (is_array($data[$name]) && array_key_exists('id',$data[$name]))
372
+			{
373
+				$data[$name] = $data[$name]['id'];
374
+			}
375
+			if (is_array($old[$name]) && array_key_exists('id',$old[$name]))
376
+			{
377
+				$old[$name] = $old[$name]['id'];
378
+			}
367 379
 			//error_log(__METHOD__.__LINE__.'(After processing) Field:'.$name. ' Value (new):'.array2string($data[$name]));
368 380
 			//error_log(__METHOD__.__LINE__.'(After processing) Field:'.$name. ' Value (old):'.array2string($old[$name]));
369 381
 		}
@@ -377,11 +389,18 @@  discard block
 block discarded – undo
377 389
 			if (!($app = $this->cf_link_fields[$name]))
378 390
 			{
379 391
 				list($app,$id) = explode(':',$id);
380
-				if (!$id) continue;	// can be eg. 'addressbook:', if no contact selected
392
+				if (!$id)
393
+				{
394
+					continue;
395
+				}
396
+				// can be eg. 'addressbook:', if no contact selected
381 397
 			}
382 398
 			$source_id = $data[$this->id_field];
383 399
 			//error_log(__METHOD__.__LINE__.array2string($source_id));
384
-			if ($source_id) Api\Link::link($this->app,$source_id,$app,$id);
400
+			if ($source_id)
401
+			{
402
+				Api\Link::link($this->app,$source_id,$app,$id);
403
+			}
385 404
 			//error_log(__METHOD__.__LINE__."Api\Link::link('$this->app',".array2string($source_id).",'$app',$id);");
386 405
 			//echo "<p>Api\Link::link('$this->app',{$data[$this->id_field]},'$app',$id);</p>\n";
387 406
 		}
@@ -389,14 +408,24 @@  discard block
 block discarded – undo
389 408
 		// unlink removed application entries
390 409
 		foreach(array_diff($old_ids,$current_ids) as $name => $id)
391 410
 		{
392
-			if (!isset($data[$name])) continue;	// ignore not set link cf's, eg. from sync clients
411
+			if (!isset($data[$name]))
412
+			{
413
+				continue;
414
+			}
415
+			// ignore not set link cf's, eg. from sync clients
393 416
 			if (!($app = $this->cf_link_fields[$name]))
394 417
 			{
395 418
 				list($app,$id) = explode(':',$id);
396
-				if (!$id) continue;
419
+				if (!$id)
420
+				{
421
+					continue;
422
+				}
397 423
 			}
398 424
 			$source_id = $data[$this->id_field];
399
-			if ($source_id) Api\Link::unlink(null,$this->app,$source_id,0,$app,$id);
425
+			if ($source_id)
426
+			{
427
+				Api\Link::unlink(null,$this->app,$source_id,0,$app,$id);
428
+			}
400 429
 			//echo "<p>Api\Link::unlink(NULL,'$this->app',{$data[$this->id_field]},0,'$app',$id);</p>\n";
401 430
 		}
402 431
 	}
@@ -421,7 +450,10 @@  discard block
 block discarded – undo
421 450
 			$changed_fields = self::changed_fields($data,$old);
422 451
 			//error_log(__METHOD__.__LINE__.' Changedfields:'.array2string($changed_fields));
423 452
 		}
424
-		if (!$changed_fields && ($old || !$GLOBALS['egw_info']['server']['log_user_agent_action'])) return 0;
453
+		if (!$changed_fields && ($old || !$GLOBALS['egw_info']['server']['log_user_agent_action']))
454
+		{
455
+			return 0;
456
+		}
425 457
 
426 458
 		if (!is_object($this->historylog) || $this->historylog->user != $this->user)
427 459
 		{
@@ -437,10 +469,13 @@  discard block
 block discarded – undo
437 469
 		{
438 470
 			$status = isset($this->field2history[$name]) ? $this->field2history[$name] : $name;
439 471
 			//error_log(__METHOD__.__LINE__." Name $name,".' Status:'.array2string($status));
440
-			if (is_array($status))	// 1:N relation --> remove common rows
472
+			if (is_array($status))
473
+			{
474
+				// 1:N relation --> remove common rows
441 475
 			{
442 476
 				//error_log(__METHOD__.__LINE__.' is Array');
443 477
 				self::compact_1_N_relation($data[$name],$status);
478
+			}
444 479
 				self::compact_1_N_relation($old[$name],$status);
445 480
 				$added = array_values(array_diff($data[$name],$old[$name]));
446 481
 				$removed = array_values(array_diff($old[$name],$data[$name]));
@@ -474,17 +509,31 @@  discard block
 block discarded – undo
474 509
 	 */
475 510
 	public function changed_fields(array $data,array $old=null)
476 511
 	{
477
-		if (is_null($old)) return array_keys($data);
512
+		if (is_null($old))
513
+		{
514
+			return array_keys($data);
515
+		}
478 516
 		$changed_fields = array();
479 517
 		foreach($this->field2history as $name => $status)
480 518
 		{
481
-			if (!$old[$name] && !$data[$name]) continue;	// treat all sorts of empty equally
519
+			if (!$old[$name] && !$data[$name])
520
+			{
521
+				continue;
522
+			}
523
+			// treat all sorts of empty equally
482 524
 
483
-			if ($name[0] == '#' && !isset($data[$name])) continue;	// no set customfields are not stored, therefore not changed
525
+			if ($name[0] == '#' && !isset($data[$name]))
526
+			{
527
+				continue;
528
+			}
529
+			// no set customfields are not stored, therefore not changed
484 530
 
485
-			if (is_array($status))	// 1:N relation
531
+			if (is_array($status))
532
+			{
533
+				// 1:N relation
486 534
 			{
487 535
 				self::compact_1_N_relation($data[$name],$status);
536
+			}
488 537
 				self::compact_1_N_relation($old[$name],$status);
489 538
 			}
490 539
 			if ($old[$name] != $data[$name])
@@ -492,13 +541,22 @@  discard block
 block discarded – undo
492 541
 				// normalize arrays, we do NOT care for the order of multiselections
493 542
 				if (is_array($data[$name]) || is_array($old[$name]))
494 543
 				{
495
-					if (!is_array($data[$name])) $data[$name] = explode(',',$data[$name]);
496
-					if (!is_array($old[$name])) $old[$name] = explode(',',$old[$name]);
544
+					if (!is_array($data[$name]))
545
+					{
546
+						$data[$name] = explode(',',$data[$name]);
547
+					}
548
+					if (!is_array($old[$name]))
549
+					{
550
+						$old[$name] = explode(',',$old[$name]);
551
+					}
497 552
 					if (count($data[$name]) == count($old[$name]))
498 553
 					{
499 554
 						sort($data[$name]);
500 555
 						sort($old[$name]);
501
-						if ($data[$name] == $old[$name]) continue;
556
+						if ($data[$name] == $old[$name])
557
+						{
558
+							continue;
559
+						}
502 560
 					}
503 561
 				}
504 562
 				elseif (str_replace("\r", '', $old[$name]) == str_replace("\r", '', $data[$name]))
@@ -559,13 +617,19 @@  discard block
 block discarded – undo
559 617
 	public function do_notifications($data,$old,$deleted=null,&$email_notified=null)
560 618
 	{
561 619
 		$this->errors = $email_sent = array();
562
-		if (!empty($email_notified) && is_array($email_notified)) $email_sent = $email_notified;
620
+		if (!empty($email_notified) && is_array($email_notified))
621
+		{
622
+			$email_sent = $email_notified;
623
+		}
563 624
 
564
-		if (!$this->notify_current_user && $this->user)		// do we have a current user and should we notify the current user about his own changes
625
+		if (!$this->notify_current_user && $this->user)
626
+		{
627
+			// do we have a current user and should we notify the current user about his own changes
565 628
 		{
566 629
 			//error_log("do_notificaton() adding user=$this->user to email_sent, to not notify him");
567 630
 			$email_sent[] = $GLOBALS['egw']->accounts->id2name($this->user,'account_email');
568 631
 		}
632
+		}
569 633
 		$skip_notify = $this->get_config('skip_notify',$data,$old);
570 634
 		if($skip_notify && is_array($skip_notify))
571 635
 		{
@@ -604,11 +668,14 @@  discard block
 block discarded – undo
604 668
 			//error_log(__METHOD__."() data[$this->assigned_field]=".print_r($data[$this->assigned_field],true).", old[$this->assigned_field]=".print_r($old[$this->assigned_field],true));
605 669
 			$old_assignees = array();
606 670
 			$assignees = $assigned ? $assigned : array();
607
-			if ($data[$this->assigned_field])	// current assignments
671
+			if ($data[$this->assigned_field])
672
+			{
673
+				// current assignments
608 674
 			{
609 675
 				$assignees = is_array($data[$this->assigned_field]) ?
610 676
 					$data[$this->assigned_field] : explode(',',$data[$this->assigned_field]);
611 677
 			}
678
+			}
612 679
 			if ($old && $old[$this->assigned_field])
613 680
 			{
614 681
 				$old_assignees = is_array($old[$this->assigned_field]) ?
@@ -617,7 +684,10 @@  discard block
 block discarded – undo
617 684
 			foreach(array_unique(array_merge($assignees,$old_assignees)) as $assignee)
618 685
 			{
619 686
 				//error_log(__METHOD__."() assignee=$assignee, type=".$GLOBALS['egw']->accounts->get_type($assignee).", email=".$GLOBALS['egw']->accounts->id2name($assignee,'account_email'));
620
-				if (!$assignee) continue;
687
+				if (!$assignee)
688
+				{
689
+					continue;
690
+				}
621 691
 
622 692
 				// item assignee is a user
623 693
 				if ($GLOBALS['egw']->accounts->get_type($assignee) == 'u')
@@ -625,10 +695,13 @@  discard block
 block discarded – undo
625 695
 					if (($email = $GLOBALS['egw']->accounts->id2name($assignee,'account_email')) && !in_array($email, $email_sent))
626 696
 					{
627 697
 						if ($this->send_notification($data,$old,$email,$assignee,'notify_assigned',
628
-							in_array($assignee,$assignees) !== in_array($assignee,$old_assignees) || $deleted))	// assignment changed
698
+							in_array($assignee,$assignees) !== in_array($assignee,$old_assignees) || $deleted))
699
+						{
700
+							// assignment changed
629 701
 						{
630 702
 							$email_sent[] = $email;
631 703
 						}
704
+						}
632 705
 					}
633 706
 				}
634 707
 				else	// item assignee is a group
@@ -638,10 +711,13 @@  discard block
 block discarded – undo
638 711
 						if (($email = $GLOBALS['egw']->accounts->id2name($u,'account_email')) && !in_array($email, $email_sent))
639 712
 						{
640 713
 							if ($this->send_notification($data,$old,$email,$u,'notify_assigned',
641
-								in_array($u,$assignees) !== in_array($u,$old_assignees) || $deleted))	// assignment changed
714
+								in_array($u,$assignees) !== in_array($u,$old_assignees) || $deleted))
715
+							{
716
+								// assignment changed
642 717
 							{
643 718
 								$email_sent[] = $email;
644 719
 							}
720
+							}
645 721
 						}
646 722
 					}
647 723
 				}
@@ -704,26 +780,39 @@  discard block
 block discarded – undo
704 780
 	public function send_notification($data,$old,$email,$user_or_lang,$check=null,$assignment_changed=true,$deleted=null)
705 781
 	{
706 782
 		//error_log(__METHOD__."(,,'$email',$user_or_lang,$check,$assignment_changed,$deleted)");
707
-		if (!$email) return false;
783
+		if (!$email)
784
+		{
785
+			return false;
786
+		}
708 787
 
709 788
 		$save_user = $GLOBALS['egw_info']['user'];
710 789
 		$do_notify = true;
711 790
 		$can_cache = false;
712 791
 
713
-		if (is_numeric($user_or_lang))	// user --> read everything from his prefs
792
+		if (is_numeric($user_or_lang))
793
+		{
794
+			// user --> read everything from his prefs
714 795
 		{
715 796
 			$GLOBALS['egw_info']['user']['account_id'] = $user_or_lang;
797
+		}
716 798
 			$GLOBALS['egw']->preferences->__construct($user_or_lang);
717 799
 			$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false);	// no session prefs!
718 800
 
719
-			if ($check && $this->check2pref) $check = $this->check2pref[$check];
801
+			if ($check && $this->check2pref)
802
+			{
803
+				$check = $this->check2pref[$check];
804
+			}
720 805
 
721 806
 			if ($check && !$GLOBALS['egw_info']['user']['preferences'][$this->app][$check] ||	// no notification requested
722 807
 				// only notification about changed assignment requested
723 808
 				$check && $GLOBALS['egw_info']['user']['preferences'][$this->app][$check] === 'assignment' && !$assignment_changed ||
724
-				$this->user == $user_or_lang && !$this->notify_current_user)  // no popup for own actions
809
+				$this->user == $user_or_lang && !$this->notify_current_user)
810
+			{
811
+				// no popup for own actions
725 812
 			{
726
-				$do_notify = false;	// no notification requested / necessary
813
+				$do_notify = false;
814
+			}
815
+			// no notification requested / necessary
727 816
 			}
728 817
 			$can_cache = (Customfields::get($this->app, true) == Customfields::get($this->app, $user_or_lang));
729 818
 		}
@@ -733,10 +822,13 @@  discard block
 block discarded – undo
733 822
 			$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->default_prefs();
734 823
 			$GLOBALS['egw_info']['user']['preferences']['common']['lang'] = $user_or_lang;
735 824
 		}
736
-		if ($GLOBALS['egw_info']['user']['preferences']['common']['lang'] != Api\Translation::$userlang)	// load the right language if needed
825
+		if ($GLOBALS['egw_info']['user']['preferences']['common']['lang'] != Api\Translation::$userlang)
826
+		{
827
+			// load the right language if needed
737 828
 		{
738 829
 			Api\Translation::init();
739 830
 		}
831
+		}
740 832
 
741 833
 		$receiver = is_numeric($user_or_lang) ? $user_or_lang : $email;
742 834
 
@@ -847,7 +939,10 @@  discard block
 block discarded – undo
847 939
 			$do_time = ($timestamp->format('Hi') != '0000');
848 940
 		}
849 941
 		$format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'];
850
-		if ($do_time) $format .= ' '.($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] != 12 ? 'H:i' : 'h:i a');
942
+		if ($do_time)
943
+		{
944
+			$format .= ' '.($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] != 12 ? 'H:i' : 'h:i a');
945
+		}
851 946
 
852 947
 		return $timestamp->format($format);
853 948
 	}
@@ -877,9 +972,12 @@  discard block
 block discarded – undo
877 972
 		{
878 973
 			$name = $GLOBALS['egw']->accounts->id2name($this->user,'account_fullname');
879 974
 
880
-			if($prefer_id) {
975
+			if($prefer_id)
976
+			{
881 977
 				$sender = $this->user;
882
-			} else {
978
+			}
979
+			else
980
+			{
883 981
 				$sender = $name ? $name.' <'.$email.'>' : $email;
884 982
 			}
885 983
 		}
@@ -971,14 +1069,20 @@  discard block
 block discarded – undo
971 1069
 				$popup = Api\Link::is_popup($this->app,'view');
972 1070
 			}
973 1071
 		}
974
-		if ($link[0] == '/') Api\Framework::getUrl($link);
1072
+		if ($link[0] == '/')
1073
+		{
1074
+			Api\Framework::getUrl($link);
1075
+		}
975 1076
 
976 1077
 		if (!$allow_popup)
977 1078
 		{
978 1079
 			// remove the session-id in the notification mail!
979 1080
 			$link = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/','',$link);
980 1081
 
981
-			if ($popup) $link .= '&nopopup=1';
1082
+			if ($popup)
1083
+			{
1084
+				$link .= '&nopopup=1';
1085
+			}
982 1086
 		}
983 1087
 		//error_log(__METHOD__."(..., $allow_popup, $receiver) returning ".array2string($allow_popup ? array($link,$popup) : $link));
984 1088
 		return $allow_popup ? array($link,$popup) : $link;
@@ -1053,7 +1157,11 @@  discard block
 block discarded – undo
1053 1157
 			// if both values are '', 0 or null, we count them as equal too
1054 1158
 			$modified = $old && $data[$name] != $old[$name] && !(!$data[$name] && !$old[$name]);
1055 1159
 			//if ($modified) error_log("data[$name]=".print_r($data[$name],true).", old[$name]=".print_r($old[$name],true)." --> modified=".(int)$modified);
1056
-			if (empty($detail['value']) && !$modified) continue;	// skip unchanged, empty values
1160
+			if (empty($detail['value']) && !$modified)
1161
+			{
1162
+				continue;
1163
+			}
1164
+			// skip unchanged, empty values
1057 1165
 
1058 1166
 			$body .= $this->format_line($html_email,$detail['type'],$modified,
1059 1167
 				$detail['label'] ? $detail['label'] : '', $detail['value']);
@@ -1087,7 +1195,11 @@  discard block
 block discarded – undo
1087 1195
 
1088 1196
 		if ($html_mail)
1089 1197
 		{
1090
-			if (!$this->html_content_allow) $line = Api\Html::htmlspecialchars($line);	// XSS
1198
+			if (!$this->html_content_allow)
1199
+			{
1200
+				$line = Api\Html::htmlspecialchars($line);
1201
+			}
1202
+			// XSS
1091 1203
 
1092 1204
 			$color = $modified ? 'red' : false;
1093 1205
 			$size  = '110%';
@@ -1126,15 +1238,24 @@  discard block
 block discarded – undo
1126 1238
 		}
1127 1239
 		else	// text-mail
1128 1240
 		{
1129
-			if ($type == 'reply') $content = str_repeat('-',64)."\n";
1241
+			if ($type == 'reply')
1242
+			{
1243
+				$content = str_repeat('-',64)."\n";
1244
+			}
1130 1245
 
1131
-			if ($modified) $content .= '> ';
1246
+			if ($modified)
1247
+			{
1248
+				$content .= '> ';
1249
+			}
1132 1250
 		}
1133 1251
 		$content .= $line;
1134 1252
 
1135 1253
 		if ($html_mail)
1136 1254
 		{
1137
-			if ($line && $data) $content .= '</td><td style="'.$style.'">';
1255
+			if ($line && $data)
1256
+			{
1257
+				$content .= '</td><td style="'.$style.'">';
1258
+			}
1138 1259
 			if ($type == 'link')
1139 1260
 			{
1140 1261
 				// the link is often too long for html boxes chunk-split allows to break lines if needed
@@ -1153,7 +1274,10 @@  discard block
 block discarded – undo
1153 1274
 		{
1154 1275
 			$content .= ($content&&$data?': ':'').$data;
1155 1276
 		}
1156
-		if ($html_mail) $content .= '</td></tr>';
1277
+		if ($html_mail)
1278
+		{
1279
+			$content .= '</td></tr>';
1280
+		}
1157 1281
 
1158 1282
 		$content .= "\n";
1159 1283
 
Please login to merge, or discard this patch.
Spacing   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -200,22 +200,22 @@  discard block
 block discarded – undo
200 200
 	 * @param string $cf_app = null if set, custom field names get added to $field2history
201 201
 	 * @return bo_tracking
202 202
 	 */
203
-	function __construct($cf_app = null, $notification_class=false)
203
+	function __construct($cf_app = null, $notification_class = false)
204 204
 	{
205 205
 		if ($cf_app)
206 206
 		{
207
-			$linkable_cf_types = array('link-entry')+array_keys(Api\Link::app_list());
208
-			foreach(Customfields::get($cf_app, true) as $cf_name => $cf_data)
207
+			$linkable_cf_types = array('link-entry') + array_keys(Api\Link::app_list());
208
+			foreach (Customfields::get($cf_app, true) as $cf_name => $cf_data)
209 209
 			{
210 210
 				$this->field2history['#'.$cf_name] = '#'.$cf_name;
211 211
 
212
-				if (in_array($cf_data['type'],$linkable_cf_types))
212
+				if (in_array($cf_data['type'], $linkable_cf_types))
213 213
 				{
214 214
 					$this->cf_link_fields['#'.$cf_name] = $cf_data['type'] == 'link-entry' ? '' : $cf_data['type'];
215 215
 				}
216 216
 			}
217 217
 		}
218
-		if($notification_class)
218
+		if ($notification_class)
219 219
 		{
220 220
 			$this->notification_class = $notification_class;
221 221
 		}
@@ -230,9 +230,9 @@  discard block
 block discarded – undo
230 230
 	 * @param int|string $receiver nummeric account_id or email address
231 231
 	 * @return array of details as array with values for keys 'label','value','type'
232 232
 	 */
233
-	function get_details($data,$receiver=null)
233
+	function get_details($data, $receiver = null)
234 234
 	{
235
-		unset($data, $receiver);	// not uses as just a stub
235
+		unset($data, $receiver); // not uses as just a stub
236 236
 
237 237
 		return array();
238 238
 	}
@@ -247,10 +247,10 @@  discard block
 block discarded – undo
247 247
 	 *
248 248
 	 * @return array of details as array with values for keys 'label','value','type'
249 249
 	 */
250
-	function get_customfields($data, $only_type2=null, $user = false)
250
+	function get_customfields($data, $only_type2 = null, $user = false)
251 251
 	{
252 252
 		$details = array();
253
-		if(!is_numeric($user))
253
+		if (!is_numeric($user))
254 254
 		{
255 255
 			$user = false;
256 256
 		}
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 		if (($cfs = Customfields::get($this->app, $user, $only_type2)))
259 259
 		{
260 260
 			$header_done = false;
261
-			foreach($cfs as $name => $field)
261
+			foreach ($cfs as $name => $field)
262 262
 			{
263 263
 				if (in_array($field['type'], Customfields::$non_printable_fields)) continue;
264 264
 
@@ -303,9 +303,9 @@  discard block
 block discarded – undo
303 303
 	 * @param array $old = null old/last state of the entry or null for a new entry
304 304
 	 * @return mixed
305 305
 	 */
306
-	protected function get_config($name,$data,$old=null)
306
+	protected function get_config($name, $data, $old = null)
307 307
 	{
308
-		unset($name, $data, $old);	// not used as just a stub
308
+		unset($name, $data, $old); // not used as just a stub
309 309
 
310 310
 		return null;
311 311
 	}
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 	 * @param boolean $skip_notification = false do NOT send any notification
322 322
 	 * @return int|boolean false on error, integer number of changes logged or true for new entries ($old == null)
323 323
 	 */
324
-	public function track(array $data,array $old=null,$user=null,$deleted=null,array $changed_fields=null,$skip_notification=false)
324
+	public function track(array $data, array $old = null, $user = null, $deleted = null, array $changed_fields = null, $skip_notification = false)
325 325
 	{
326 326
 		$this->user = !is_null($user) ? $user : $GLOBALS['egw_info']['user']['account_id'];
327 327
 
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 		if ($old && $this->field2history)
331 331
 		{
332 332
 			//error_log(__METHOD__.__LINE__.' Changedfields:'.print_r($changed_fields,true));
333
-			$changes = $this->save_history($data,$old,$deleted,$changed_fields);
333
+			$changes = $this->save_history($data, $old, $deleted, $changed_fields);
334 334
 			//error_log(__METHOD__.__LINE__.' Changedfields:'.print_r($changed_fields,true));
335 335
 			//error_log(__METHOD__.__LINE__.' Changes:'.print_r($changes,true));
336 336
 		}
@@ -338,10 +338,10 @@  discard block
 block discarded – undo
338 338
 		//error_log(__METHOD__.__LINE__.' LinkFields:'.array2string($this->cf_link_fields));
339 339
 		if ($changes && $this->cf_link_fields)
340 340
 		{
341
-			$this->update_links($data,(array)$old);
341
+			$this->update_links($data, (array)$old);
342 342
 		}
343 343
 		// do not run do_notifications if we have no changes
344
-		if ($changes && !$skip_notification && !$this->do_notifications($data,$old,$deleted))
344
+		if ($changes && !$skip_notification && !$this->do_notifications($data, $old, $deleted))
345 345
 		{
346 346
 			$changes = false;
347 347
 		}
@@ -358,45 +358,45 @@  discard block
 block discarded – undo
358 358
 	{
359 359
 		//error_log(__METHOD__.__LINE__.array2string($data).function_backtrace());
360 360
 		//error_log(__METHOD__.__LINE__.array2string($this->cf_link_fields));
361
-		foreach(array_keys((array)$this->cf_link_fields) as $name)
361
+		foreach (array_keys((array)$this->cf_link_fields) as $name)
362 362
 		{
363 363
 			//error_log(__METHOD__.__LINE__.' Field:'.$name. ' Value (new):'.array2string($data[$name]));
364 364
 			//error_log(__METHOD__.__LINE__.' Field:'.$name. ' Value (old):'.array2string($old[$name]));
365
-			if (is_array($data[$name]) && array_key_exists('id',$data[$name])) $data[$name] = $data[$name]['id'];
366
-			if (is_array($old[$name]) && array_key_exists('id',$old[$name])) $old[$name] = $old[$name]['id'];
365
+			if (is_array($data[$name]) && array_key_exists('id', $data[$name])) $data[$name] = $data[$name]['id'];
366
+			if (is_array($old[$name]) && array_key_exists('id', $old[$name])) $old[$name] = $old[$name]['id'];
367 367
 			//error_log(__METHOD__.__LINE__.'(After processing) Field:'.$name. ' Value (new):'.array2string($data[$name]));
368 368
 			//error_log(__METHOD__.__LINE__.'(After processing) Field:'.$name. ' Value (old):'.array2string($old[$name]));
369 369
 		}
370
-		$current_ids = array_unique(array_diff(array_intersect_key($data,$this->cf_link_fields),array('',0,NULL)));
371
-		$old_ids = $old ? array_unique(array_diff(array_intersect_key($old,$this->cf_link_fields),array('',0,NULL))) : array();
370
+		$current_ids = array_unique(array_diff(array_intersect_key($data, $this->cf_link_fields), array('', 0, NULL)));
371
+		$old_ids = $old ? array_unique(array_diff(array_intersect_key($old, $this->cf_link_fields), array('', 0, NULL))) : array();
372 372
 		//error_log(__METHOD__.__LINE__.array2string($current_ids));
373 373
 		//error_log(__METHOD__.__LINE__.array2string($old_ids));
374 374
 		// create links for added application entry
375
-		foreach(array_diff($current_ids,$old_ids) as $name => $id)
375
+		foreach (array_diff($current_ids, $old_ids) as $name => $id)
376 376
 		{
377 377
 			if (!($app = $this->cf_link_fields[$name]))
378 378
 			{
379
-				list($app,$id) = explode(':',$id);
380
-				if (!$id) continue;	// can be eg. 'addressbook:', if no contact selected
379
+				list($app, $id) = explode(':', $id);
380
+				if (!$id) continue; // can be eg. 'addressbook:', if no contact selected
381 381
 			}
382 382
 			$source_id = $data[$this->id_field];
383 383
 			//error_log(__METHOD__.__LINE__.array2string($source_id));
384
-			if ($source_id) Api\Link::link($this->app,$source_id,$app,$id);
384
+			if ($source_id) Api\Link::link($this->app, $source_id, $app, $id);
385 385
 			//error_log(__METHOD__.__LINE__."Api\Link::link('$this->app',".array2string($source_id).",'$app',$id);");
386 386
 			//echo "<p>Api\Link::link('$this->app',{$data[$this->id_field]},'$app',$id);</p>\n";
387 387
 		}
388 388
 
389 389
 		// unlink removed application entries
390
-		foreach(array_diff($old_ids,$current_ids) as $name => $id)
390
+		foreach (array_diff($old_ids, $current_ids) as $name => $id)
391 391
 		{
392
-			if (!isset($data[$name])) continue;	// ignore not set link cf's, eg. from sync clients
392
+			if (!isset($data[$name])) continue; // ignore not set link cf's, eg. from sync clients
393 393
 			if (!($app = $this->cf_link_fields[$name]))
394 394
 			{
395
-				list($app,$id) = explode(':',$id);
395
+				list($app, $id) = explode(':', $id);
396 396
 				if (!$id) continue;
397 397
 			}
398 398
 			$source_id = $data[$this->id_field];
399
-			if ($source_id) Api\Link::unlink(null,$this->app,$source_id,0,$app,$id);
399
+			if ($source_id) Api\Link::unlink(null, $this->app, $source_id, 0, $app, $id);
400 400
 			//echo "<p>Api\Link::unlink(NULL,'$this->app',{$data[$this->id_field]},0,'$app',$id);</p>\n";
401 401
 		}
402 402
 	}
@@ -411,14 +411,14 @@  discard block
 block discarded – undo
411 411
 	 * @param array $changed_fields = null changed fields from ealier call to $this->changed_fields($data,$old), to not compute it again
412 412
 	 * @return int number of log-entries made
413 413
 	 */
414
-	protected function save_history(array $data,array $old=null,$deleted=null,array $changed_fields=null)
414
+	protected function save_history(array $data, array $old = null, $deleted = null, array $changed_fields = null)
415 415
 	{
416
-		unset($deleted);	// not used, but required by function signature
416
+		unset($deleted); // not used, but required by function signature
417 417
 
418 418
 		//error_log(__METHOD__.__LINE__.' Changedfields:'.array2string($changed_fields));
419 419
 		if (is_null($changed_fields))
420 420
 		{
421
-			$changed_fields = self::changed_fields($data,$old);
421
+			$changed_fields = self::changed_fields($data, $old);
422 422
 			//error_log(__METHOD__.__LINE__.' Changedfields:'.array2string($changed_fields));
423 423
 		}
424 424
 		if (!$changed_fields && ($old || !$GLOBALS['egw_info']['server']['log_user_agent_action'])) return 0;
@@ -433,30 +433,30 @@  discard block
 block discarded – undo
433 433
 			$this->historylog->add('user_agent_action', $data[$this->id_field],
434 434
 				$_SERVER['HTTP_USER_AGENT'], $_SESSION[Api\Session::EGW_SESSION_VAR]['session_action']);
435 435
 		}
436
-		foreach($changed_fields as $name)
436
+		foreach ($changed_fields as $name)
437 437
 		{
438 438
 			$status = isset($this->field2history[$name]) ? $this->field2history[$name] : $name;
439 439
 			//error_log(__METHOD__.__LINE__." Name $name,".' Status:'.array2string($status));
440 440
 			if (is_array($status))	// 1:N relation --> remove common rows
441 441
 			{
442 442
 				//error_log(__METHOD__.__LINE__.' is Array');
443
-				self::compact_1_N_relation($data[$name],$status);
444
-				self::compact_1_N_relation($old[$name],$status);
445
-				$added = array_values(array_diff($data[$name],$old[$name]));
446
-				$removed = array_values(array_diff($old[$name],$data[$name]));
447
-				$n = max(array(count($added),count($removed)));
448
-				for($i = 0; $i < $n; ++$i)
443
+				self::compact_1_N_relation($data[$name], $status);
444
+				self::compact_1_N_relation($old[$name], $status);
445
+				$added = array_values(array_diff($data[$name], $old[$name]));
446
+				$removed = array_values(array_diff($old[$name], $data[$name]));
447
+				$n = max(array(count($added), count($removed)));
448
+				for ($i = 0; $i < $n; ++$i)
449 449
 				{
450 450
 					//error_log(__METHOD__."() $i: historylog->add('$name',data['$this->id_field']={$data[$this->id_field]},".array2string($added[$i]).','.array2string($removed[$i]));
451
-					$this->historylog->add($name,$data[$this->id_field],$added[$i],$removed[$i]);
451
+					$this->historylog->add($name, $data[$this->id_field], $added[$i], $removed[$i]);
452 452
 				}
453 453
 			}
454 454
 			else
455 455
 			{
456 456
 				//error_log(__METHOD__.__LINE__.' IDField:'.array2string($this->id_field).' ->'.$data[$this->id_field].' New:'.$data[$name].' Old:'.$old[$name]);
457
-				$this->historylog->add($status,$data[$this->id_field],
458
-					is_array($data[$name]) ? implode(',',$data[$name]) : $data[$name],
459
-					is_array($old[$name]) ? implode(',',$old[$name]) : $old[$name]);
457
+				$this->historylog->add($status, $data[$this->id_field],
458
+					is_array($data[$name]) ? implode(',', $data[$name]) : $data[$name],
459
+					is_array($old[$name]) ? implode(',', $old[$name]) : $old[$name]);
460 460
 			}
461 461
 		}
462 462
 		//error_log(__METHOD__.__LINE__.' return:'.count($changed_fields));
@@ -472,28 +472,28 @@  discard block
 block discarded – undo
472 472
 	 * @param array $old = null
473 473
 	 * @return array of keys with different values in $data and $old
474 474
 	 */
475
-	public function changed_fields(array $data,array $old=null)
475
+	public function changed_fields(array $data, array $old = null)
476 476
 	{
477 477
 		if (is_null($old)) return array_keys($data);
478 478
 		$changed_fields = array();
479
-		foreach($this->field2history as $name => $status)
479
+		foreach ($this->field2history as $name => $status)
480 480
 		{
481
-			if (!$old[$name] && !$data[$name]) continue;	// treat all sorts of empty equally
481
+			if (!$old[$name] && !$data[$name]) continue; // treat all sorts of empty equally
482 482
 
483
-			if ($name[0] == '#' && !isset($data[$name])) continue;	// no set customfields are not stored, therefore not changed
483
+			if ($name[0] == '#' && !isset($data[$name])) continue; // no set customfields are not stored, therefore not changed
484 484
 
485 485
 			if (is_array($status))	// 1:N relation
486 486
 			{
487
-				self::compact_1_N_relation($data[$name],$status);
488
-				self::compact_1_N_relation($old[$name],$status);
487
+				self::compact_1_N_relation($data[$name], $status);
488
+				self::compact_1_N_relation($old[$name], $status);
489 489
 			}
490 490
 			if ($old[$name] != $data[$name])
491 491
 			{
492 492
 				// normalize arrays, we do NOT care for the order of multiselections
493 493
 				if (is_array($data[$name]) || is_array($old[$name]))
494 494
 				{
495
-					if (!is_array($data[$name])) $data[$name] = explode(',',$data[$name]);
496
-					if (!is_array($old[$name])) $old[$name] = explode(',',$old[$name]);
495
+					if (!is_array($data[$name])) $data[$name] = explode(',', $data[$name]);
496
+					if (!is_array($old[$name])) $old[$name] = explode(',', $old[$name]);
497 497
 					if (count($data[$name]) == count($old[$name]))
498 498
 					{
499 499
 						sort($data[$name]);
@@ -503,13 +503,13 @@  discard block
 block discarded – undo
503 503
 				}
504 504
 				elseif (str_replace("\r", '', $old[$name]) == str_replace("\r", '', $data[$name]))
505 505
 				{
506
-					continue;	// change only in CR (eg. different OS) --> ignore
506
+					continue; // change only in CR (eg. different OS) --> ignore
507 507
 				}
508 508
 				$changed_fields[] = $name;
509 509
 				//echo "<p>$name: ".array2string($data[$name]).' != '.array2string($old[$name])."</p>\n";
510 510
 			}
511 511
 		}
512
-		foreach($data as $name => $value)
512
+		foreach ($data as $name => $value)
513 513
 		{
514 514
 			if ($name[0] == '#' && $name[1] == '#' && $value !== $old[$name])
515 515
 			{
@@ -526,18 +526,18 @@  discard block
 block discarded – undo
526 526
 	 * @param array &$rows rows of the 1:N relation
527 527
 	 * @param array $cols field names as values
528 528
 	 */
529
-	private static function compact_1_N_relation(&$rows,array $cols)
529
+	private static function compact_1_N_relation(&$rows, array $cols)
530 530
 	{
531 531
 		if (is_array($rows))
532 532
 		{
533
-			foreach($rows as &$row)
533
+			foreach ($rows as &$row)
534 534
 			{
535 535
 				$values = array();
536
-				foreach($cols as $col)
536
+				foreach ($cols as $col)
537 537
 				{
538 538
 					$values[] = $row[$col];
539 539
 				}
540
-				$row = implode(self::ONE2N_SEPERATOR,$values);
540
+				$row = implode(self::ONE2N_SEPERATOR, $values);
541 541
 			}
542 542
 		}
543 543
 		else
@@ -556,7 +556,7 @@  discard block
 block discarded – undo
556 556
 	 * @param array $email_notified=null if present will return the emails notified, if given emails in that list will not be notified
557 557
 	 * @return boolean true on success, false on error (error messages are in $this->errors)
558 558
 	 */
559
-	public function do_notifications($data,$old,$deleted=null,&$email_notified=null)
559
+	public function do_notifications($data, $old, $deleted = null, &$email_notified = null)
560 560
 	{
561 561
 		$this->errors = $email_sent = array();
562 562
 		if (!empty($email_notified) && is_array($email_notified)) $email_sent = $email_notified;
@@ -564,19 +564,19 @@  discard block
 block discarded – undo
564 564
 		if (!$this->notify_current_user && $this->user)		// do we have a current user and should we notify the current user about his own changes
565 565
 		{
566 566
 			//error_log("do_notificaton() adding user=$this->user to email_sent, to not notify him");
567
-			$email_sent[] = $GLOBALS['egw']->accounts->id2name($this->user,'account_email');
567
+			$email_sent[] = $GLOBALS['egw']->accounts->id2name($this->user, 'account_email');
568 568
 		}
569
-		$skip_notify = $this->get_config('skip_notify',$data,$old);
570
-		if($skip_notify && is_array($skip_notify))
569
+		$skip_notify = $this->get_config('skip_notify', $data, $old);
570
+		if ($skip_notify && is_array($skip_notify))
571 571
 		{
572 572
 			$email_sent = array_merge($email_sent, $skip_notify);
573 573
 		}
574 574
 
575 575
 		// entry creator
576
-		if ($this->creator_field && ($email = $GLOBALS['egw']->accounts->id2name($data[$this->creator_field],'account_email')) &&
576
+		if ($this->creator_field && ($email = $GLOBALS['egw']->accounts->id2name($data[$this->creator_field], 'account_email')) &&
577 577
 			!in_array($email, $email_sent))
578 578
 		{
579
-			if ($this->send_notification($data,$old,$email,$data[$this->creator_field],'notify_creator'))
579
+			if ($this->send_notification($data, $old, $email, $data[$this->creator_field], 'notify_creator'))
580 580
 			{
581 581
 				$email_sent[] = $email;
582 582
 			}
@@ -585,12 +585,12 @@  discard block
 block discarded – undo
585 585
 		// members of group when entry owned by group
586 586
 		if ($this->creator_field && $GLOBALS['egw']->accounts->get_type($data[$this->creator_field]) == 'g')
587 587
 		{
588
-			foreach($GLOBALS['egw']->accounts->members($data[$this->creator_field],true) as $u)
588
+			foreach ($GLOBALS['egw']->accounts->members($data[$this->creator_field], true) as $u)
589 589
 			{
590
-				if (($email = $GLOBALS['egw']->accounts->id2name($u,'account_email')) &&
590
+				if (($email = $GLOBALS['egw']->accounts->id2name($u, 'account_email')) &&
591 591
 					!in_array($email, $email_sent))
592 592
 				{
593
-					if ($this->send_notification($data,$old,$email,$u,'notify_owner_group_member'))
593
+					if ($this->send_notification($data, $old, $email, $u, 'notify_owner_group_member'))
594 594
 					{
595 595
 						$email_sent[] = $email;
596 596
 					}
@@ -607,14 +607,14 @@  discard block
 block discarded – undo
607 607
 			if ($data[$this->assigned_field])	// current assignments
608 608
 			{
609 609
 				$assignees = is_array($data[$this->assigned_field]) ?
610
-					$data[$this->assigned_field] : explode(',',$data[$this->assigned_field]);
610
+					$data[$this->assigned_field] : explode(',', $data[$this->assigned_field]);
611 611
 			}
612 612
 			if ($old && $old[$this->assigned_field])
613 613
 			{
614 614
 				$old_assignees = is_array($old[$this->assigned_field]) ?
615
-					$old[$this->assigned_field] : explode(',',$old[$this->assigned_field]);
615
+					$old[$this->assigned_field] : explode(',', $old[$this->assigned_field]);
616 616
 			}
617
-			foreach(array_unique(array_merge($assignees,$old_assignees)) as $assignee)
617
+			foreach (array_unique(array_merge($assignees, $old_assignees)) as $assignee)
618 618
 			{
619 619
 				//error_log(__METHOD__."() assignee=$assignee, type=".$GLOBALS['egw']->accounts->get_type($assignee).", email=".$GLOBALS['egw']->accounts->id2name($assignee,'account_email'));
620 620
 				if (!$assignee) continue;
@@ -622,10 +622,10 @@  discard block
 block discarded – undo
622 622
 				// item assignee is a user
623 623
 				if ($GLOBALS['egw']->accounts->get_type($assignee) == 'u')
624 624
 				{
625
-					if (($email = $GLOBALS['egw']->accounts->id2name($assignee,'account_email')) && !in_array($email, $email_sent))
625
+					if (($email = $GLOBALS['egw']->accounts->id2name($assignee, 'account_email')) && !in_array($email, $email_sent))
626 626
 					{
627
-						if ($this->send_notification($data,$old,$email,$assignee,'notify_assigned',
628
-							in_array($assignee,$assignees) !== in_array($assignee,$old_assignees) || $deleted))	// assignment changed
627
+						if ($this->send_notification($data, $old, $email, $assignee, 'notify_assigned',
628
+							in_array($assignee, $assignees) !== in_array($assignee, $old_assignees) || $deleted))	// assignment changed
629 629
 						{
630 630
 							$email_sent[] = $email;
631 631
 						}
@@ -633,12 +633,12 @@  discard block
 block discarded – undo
633 633
 				}
634 634
 				else	// item assignee is a group
635 635
 				{
636
-					foreach($GLOBALS['egw']->accounts->members($assignee,true) as $u)
636
+					foreach ($GLOBALS['egw']->accounts->members($assignee, true) as $u)
637 637
 					{
638
-						if (($email = $GLOBALS['egw']->accounts->id2name($u,'account_email')) && !in_array($email, $email_sent))
638
+						if (($email = $GLOBALS['egw']->accounts->id2name($u, 'account_email')) && !in_array($email, $email_sent))
639 639
 						{
640
-							if ($this->send_notification($data,$old,$email,$u,'notify_assigned',
641
-								in_array($u,$assignees) !== in_array($u,$old_assignees) || $deleted))	// assignment changed
640
+							if ($this->send_notification($data, $old, $email, $u, 'notify_assigned',
641
+								in_array($u, $assignees) !== in_array($u, $old_assignees) || $deleted))	// assignment changed
642 642
 							{
643 643
 								$email_sent[] = $email;
644 644
 							}
@@ -649,14 +649,14 @@  discard block
 block discarded – undo
649 649
 		}
650 650
 
651 651
 		// notification copies
652
-		if (($copies = $this->get_config('copy',$data,$old)))
652
+		if (($copies = $this->get_config('copy', $data, $old)))
653 653
 		{
654
-			$lang = $this->get_config('lang',$data,$old);
655
-			foreach($copies as $email)
654
+			$lang = $this->get_config('lang', $data, $old);
655
+			foreach ($copies as $email)
656 656
 			{
657
-				if (strchr($email,'@') !== false && !in_array($email, $email_sent))
657
+				if (strchr($email, '@') !== false && !in_array($email, $email_sent))
658 658
 				{
659
-					if ($this->send_notification($data,$old,$email,$lang,'notify_copy'))
659
+					if ($this->send_notification($data, $old, $email, $lang, 'notify_copy'))
660 660
 					{
661 661
 						$email_sent[] = $email;
662 662
 					}
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
 	 * @param boolean $deleted = null can be set to true to let the tracking know the item got deleted or undelted
702 702
 	 * @return boolean true on success or false if notification not requested or error (error-message is in $this->errors)
703 703
 	 */
704
-	public function send_notification($data,$old,$email,$user_or_lang,$check=null,$assignment_changed=true,$deleted=null)
704
+	public function send_notification($data, $old, $email, $user_or_lang, $check = null, $assignment_changed = true, $deleted = null)
705 705
 	{
706 706
 		//error_log(__METHOD__."(,,'$email',$user_or_lang,$check,$assignment_changed,$deleted)");
707 707
 		if (!$email) return false;
@@ -714,16 +714,16 @@  discard block
 block discarded – undo
714 714
 		{
715 715
 			$GLOBALS['egw_info']['user']['account_id'] = $user_or_lang;
716 716
 			$GLOBALS['egw']->preferences->__construct($user_or_lang);
717
-			$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false);	// no session prefs!
717
+			$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false); // no session prefs!
718 718
 
719 719
 			if ($check && $this->check2pref) $check = $this->check2pref[$check];
720 720
 
721
-			if ($check && !$GLOBALS['egw_info']['user']['preferences'][$this->app][$check] ||	// no notification requested
721
+			if ($check && !$GLOBALS['egw_info']['user']['preferences'][$this->app][$check] || // no notification requested
722 722
 				// only notification about changed assignment requested
723 723
 				$check && $GLOBALS['egw_info']['user']['preferences'][$this->app][$check] === 'assignment' && !$assignment_changed ||
724 724
 				$this->user == $user_or_lang && !$this->notify_current_user)  // no popup for own actions
725 725
 			{
726
-				$do_notify = false;	// no notification requested / necessary
726
+				$do_notify = false; // no notification requested / necessary
727 727
 			}
728 728
 			$can_cache = (Customfields::get($this->app, true) == Customfields::get($this->app, $user_or_lang));
729 729
 		}
@@ -747,36 +747,36 @@  discard block
 block discarded – undo
747 747
 
748 748
 			// Cache message body to not have to re-generate it every time
749 749
 			$lang = Api\Translation::$userlang;
750
-			$date_format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'] .
750
+			$date_format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'].
751 751
 				$GLOBALS['egw_info']['user']['preferences']['common']['timeformat'];
752 752
 
753 753
 			// Cache text body, if there's no private custom fields we might reveal
754
-			if($can_cache)
754
+			if ($can_cache)
755 755
 			{
756
-				$body_cache =& $this->body_cache[$data[$this->id_field]][$lang][$date_format];
756
+				$body_cache = & $this->body_cache[$data[$this->id_field]][$lang][$date_format];
757 757
 			}
758
-			if(empty($data[$this->id_field]) || !isset($body_cache['text']))
758
+			if (empty($data[$this->id_field]) || !isset($body_cache['text']))
759 759
 			{
760
-				$body_cache['text'] = $this->get_body(false,$data,$old,false,$receiver);
760
+				$body_cache['text'] = $this->get_body(false, $data, $old, false, $receiver);
761 761
 			}
762 762
 			// Cache HTML body
763
-			if(empty($data[$this->id_field]) || !isset($body_cache['html']))
763
+			if (empty($data[$this->id_field]) || !isset($body_cache['html']))
764 764
 			{
765
-				$body_cache['html'] = $this->get_body(true,$data,$old,false,$receiver);
765
+				$body_cache['html'] = $this->get_body(true, $data, $old, false, $receiver);
766 766
 			}
767 767
 
768 768
 			// get rest of notification message
769
-			$sender = $this->get_sender($data,$old,true,$receiver);
770
-			$subject = $this->get_subject($data,$old,$deleted,$receiver);
771
-			$link = $this->get_notification_link($data,$old,$receiver);
772
-			$attachments = $this->get_attachments($data,$old,$receiver);
769
+			$sender = $this->get_sender($data, $old, true, $receiver);
770
+			$subject = $this->get_subject($data, $old, $deleted, $receiver);
771
+			$link = $this->get_notification_link($data, $old, $receiver);
772
+			$attachments = $this->get_attachments($data, $old, $receiver);
773 773
 		}
774 774
 
775 775
 		// restore user enviroment BEFORE calling notification class or returning
776 776
 		$GLOBALS['egw_info']['user'] = $save_user;
777 777
 		// need to call preferences constructor and read_repository, to set user timezone again
778 778
 		$GLOBALS['egw']->preferences->__construct($GLOBALS['egw_info']['user']['account_id']);
779
-		$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false);	// no session prefs!
779
+		$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false); // no session prefs!
780 780
 
781 781
 		// Re-load date/time preferences
782 782
 		Api\DateTime::init();
@@ -835,11 +835,11 @@  discard block
 block discarded – undo
835 835
 	 *
836 836
 	 * @return string
837 837
 	 */
838
-	public function datetime($timestamp,$do_time=true)
838
+	public function datetime($timestamp, $do_time = true)
839 839
 	{
840
-		if (!is_a($timestamp,'DateTime'))
840
+		if (!is_a($timestamp, 'DateTime'))
841 841
 		{
842
-			$timestamp = new Api\DateTime($timestamp,Api\DateTime::$server_timezone);
842
+			$timestamp = new Api\DateTime($timestamp, Api\DateTime::$server_timezone);
843 843
 		}
844 844
 		$timestamp->setTimezone(Api\DateTime::$user_timezone);
845 845
 		if (is_null($do_time))
@@ -865,25 +865,25 @@  discard block
 block discarded – undo
865 865
 	 * @param int|string $receiver nummeric account_id or email address
866 866
 	 * @return string or userid
867 867
 	 */
868
-	protected function get_sender($data,$old,$prefer_id=false,$receiver=null)
868
+	protected function get_sender($data, $old, $prefer_id = false, $receiver = null)
869 869
 	{
870
-		unset($receiver);	// not used, but required by function signature
870
+		unset($receiver); // not used, but required by function signature
871 871
 
872
-		$sender = $this->get_config('sender',$data,$old);
872
+		$sender = $this->get_config('sender', $data, $old);
873 873
 		//echo "<p>".__METHOD__."() get_config('sender',...)='".htmlspecialchars($sender)."'</p>\n";
874 874
 
875 875
 		if (($this->prefer_user_as_sender || !$sender) && $this->user &&
876
-			($email = $GLOBALS['egw']->accounts->id2name($this->user,'account_email')))
876
+			($email = $GLOBALS['egw']->accounts->id2name($this->user, 'account_email')))
877 877
 		{
878
-			$name = $GLOBALS['egw']->accounts->id2name($this->user,'account_fullname');
878
+			$name = $GLOBALS['egw']->accounts->id2name($this->user, 'account_fullname');
879 879
 
880
-			if($prefer_id) {
880
+			if ($prefer_id) {
881 881
 				$sender = $this->user;
882 882
 			} else {
883 883
 				$sender = $name ? $name.' <'.$email.'>' : $email;
884 884
 			}
885 885
 		}
886
-		elseif(!$sender)
886
+		elseif (!$sender)
887 887
 		{
888 888
 			$sender = 'EGroupware '.lang($this->app).' <noreply@'.$GLOBALS['egw_info']['server']['mail_suffix'].'>';
889 889
 		}
@@ -898,11 +898,11 @@  discard block
 block discarded – undo
898 898
 	 * @param array $old
899 899
 	 * @return string
900 900
 	 */
901
-	protected function get_title($data,$old)
901
+	protected function get_title($data, $old)
902 902
 	{
903
-		unset($old);	// not used, but required by function signature
903
+		unset($old); // not used, but required by function signature
904 904
 
905
-		return Api\Link::title($this->app,$data[$this->id_field]);
905
+		return Api\Link::title($this->app, $data[$this->id_field]);
906 906
 	}
907 907
 
908 908
 	/**
@@ -916,11 +916,11 @@  discard block
 block discarded – undo
916 916
 	 * @param int|string $receiver nummeric account_id or email address
917 917
 	 * @return string
918 918
 	 */
919
-	protected function get_subject($data,$old,$deleted=null,$receiver=null)
919
+	protected function get_subject($data, $old, $deleted = null, $receiver = null)
920 920
 	{
921
-		unset($old, $deleted, $receiver);	// not used, but required by function signature
921
+		unset($old, $deleted, $receiver); // not used, but required by function signature
922 922
 
923
-		return Api\Link::title($this->app,$data[$this->id_field]);
923
+		return Api\Link::title($this->app, $data[$this->id_field]);
924 924
 	}
925 925
 
926 926
 	/**
@@ -933,9 +933,9 @@  discard block
 block discarded – undo
933 933
 	 * @param int|string $receiver nummeric account_id or email address
934 934
 	 * @return string
935 935
 	 */
936
-	protected function get_message($data,$old,$receiver=null)
936
+	protected function get_message($data, $old, $receiver = null)
937 937
 	{
938
-		unset($data, $old, $receiver);	// not used, but required by function signature
938
+		unset($data, $old, $receiver); // not used, but required by function signature
939 939
 
940 940
 		return '';
941 941
 	}
@@ -951,24 +951,24 @@  discard block
 block discarded – undo
951 951
 	 * @param int|string $receiver nummeric account_id or email address
952 952
 	 * @return string|array string with link (!$allow_popup) or array(link,popup-size), popup size is something like '640x480'
953 953
 	 */
954
-	protected function get_link($data,$old,$allow_popup=false,$receiver=null)
954
+	protected function get_link($data, $old, $allow_popup = false, $receiver = null)
955 955
 	{
956
-		unset($receiver);	// not used, but required by function signature
956
+		unset($receiver); // not used, but required by function signature
957 957
 
958
-		if (($link = $this->get_config('link',$data,$old)))
958
+		if (($link = $this->get_config('link', $data, $old)))
959 959
 		{
960
-			if (!$this->get_config('link_no_id', $data) && strpos($link,$this->id_field.'=') === false && isset($data[$this->id_field]))
960
+			if (!$this->get_config('link_no_id', $data) && strpos($link, $this->id_field.'=') === false && isset($data[$this->id_field]))
961 961
 			{
962
-				$link .= strpos($link,'?') === false ? '?' : '&';
962
+				$link .= strpos($link, '?') === false ? '?' : '&';
963 963
 				$link .= $this->id_field.'='.$data[$this->id_field];
964 964
 			}
965 965
 		}
966 966
 		else
967 967
 		{
968
-			if (($view = Api\Link::view($this->app,$data[$this->id_field])))
968
+			if (($view = Api\Link::view($this->app, $data[$this->id_field])))
969 969
 			{
970
-				$link = Api\Framework::link('/index.php',$view);
971
-				$popup = Api\Link::is_popup($this->app,'view');
970
+				$link = Api\Framework::link('/index.php', $view);
971
+				$popup = Api\Link::is_popup($this->app, 'view');
972 972
 			}
973 973
 		}
974 974
 		if ($link[0] == '/') Api\Framework::getUrl($link);
@@ -976,12 +976,12 @@  discard block
 block discarded – undo
976 976
 		if (!$allow_popup)
977 977
 		{
978 978
 			// remove the session-id in the notification mail!
979
-			$link = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/','',$link);
979
+			$link = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/', '', $link);
980 980
 
981 981
 			if ($popup) $link .= '&nopopup=1';
982 982
 		}
983 983
 		//error_log(__METHOD__."(..., $allow_popup, $receiver) returning ".array2string($allow_popup ? array($link,$popup) : $link));
984
-		return $allow_popup ? array($link,$popup) : $link;
984
+		return $allow_popup ? array($link, $popup) : $link;
985 985
 	}
986 986
 
987 987
 	/**
@@ -992,18 +992,18 @@  discard block
 block discarded – undo
992 992
 	 * @param int|string $receiver nummeric account_id or email address
993 993
 	 * @return array with link
994 994
 	 */
995
-	protected function get_notification_link($data,$old,$receiver=null)
995
+	protected function get_notification_link($data, $old, $receiver = null)
996 996
 	{
997
-		unset($receiver);	// not used, but required by function signature
997
+		unset($receiver); // not used, but required by function signature
998 998
 
999
-		if (($view = Api\Link::view($this->app,$data[$this->id_field])))
999
+		if (($view = Api\Link::view($this->app, $data[$this->id_field])))
1000 1000
 		{
1001 1001
 			return array(
1002
-				'text' 	=> $this->get_title($data,$old),
1002
+				'text' 	=> $this->get_title($data, $old),
1003 1003
 				'app'	=> $this->app,
1004 1004
 				'id'	=> $data[$this->id_field],
1005 1005
 				'view' 	=> $view,
1006
-				'popup'	=> Api\Link::is_popup($this->app,'view'),
1006
+				'popup'	=> Api\Link::is_popup($this->app, 'view'),
1007 1007
 			);
1008 1008
 		}
1009 1009
 		return false;
@@ -1019,15 +1019,15 @@  discard block
 block discarded – undo
1019 1019
 	 * @param int|string $receiver nummeric account_id or email address
1020 1020
 	 * @return string
1021 1021
 	 */
1022
-	public function get_body($html_email,$data,$old,$integrate_link = true,$receiver=null)
1022
+	public function get_body($html_email, $data, $old, $integrate_link = true, $receiver = null)
1023 1023
 	{
1024 1024
 		$body = '';
1025
-		if($this->get_config(self::CUSTOM_NOTIFICATION, $data, $old))
1025
+		if ($this->get_config(self::CUSTOM_NOTIFICATION, $data, $old))
1026 1026
 		{
1027
-			$body = $this->get_custom_message($data,$old,null,$receiver);
1028
-			if(($sig = $this->get_signature($data,$old,$receiver)))
1027
+			$body = $this->get_custom_message($data, $old, null, $receiver);
1028
+			if (($sig = $this->get_signature($data, $old, $receiver)))
1029 1029
 			{
1030
-				$body .= ($html_email ? '<br />':'') . "\n$sig";
1030
+				$body .= ($html_email ? '<br />' : '')."\n$sig";
1031 1031
 			}
1032 1032
 			return $body;
1033 1033
 		}
@@ -1036,35 +1036,35 @@  discard block
 block discarded – undo
1036 1036
 			$body = '<table cellspacing="2" cellpadding="0" border="0" width="100%">'."\n";
1037 1037
 		}
1038 1038
 		// new or modified message
1039
-		if (($message = $this->get_message($data,$old,$receiver)))
1039
+		if (($message = $this->get_message($data, $old, $receiver)))
1040 1040
 		{
1041 1041
 			foreach ((array)$message as $_message)
1042 1042
 			{
1043
-				$body .= $this->format_line($html_email,'message',false,($_message=='---'?($html_email?'<hr/>':$_message):$_message));
1043
+				$body .= $this->format_line($html_email, 'message', false, ($_message == '---' ? ($html_email ? '<hr/>' : $_message) : $_message));
1044 1044
 			}
1045 1045
 		}
1046
-		if ($integrate_link && ($link = $this->get_link($data,$old,false,$receiver)))
1046
+		if ($integrate_link && ($link = $this->get_link($data, $old, false, $receiver)))
1047 1047
 		{
1048
-			$body .= $this->format_line($html_email,'link',false,$integrate_link === true ? lang('You can respond by visiting:') : $integrate_link,$link);
1048
+			$body .= $this->format_line($html_email, 'link', false, $integrate_link === true ? lang('You can respond by visiting:') : $integrate_link, $link);
1049 1049
 		}
1050
-		foreach($this->get_details($data,$receiver) as $name => $detail)
1050
+		foreach ($this->get_details($data, $receiver) as $name => $detail)
1051 1051
 		{
1052 1052
 			// if there's no old entry, the entry is not modified by definition
1053 1053
 			// if both values are '', 0 or null, we count them as equal too
1054 1054
 			$modified = $old && $data[$name] != $old[$name] && !(!$data[$name] && !$old[$name]);
1055 1055
 			//if ($modified) error_log("data[$name]=".print_r($data[$name],true).", old[$name]=".print_r($old[$name],true)." --> modified=".(int)$modified);
1056
-			if (empty($detail['value']) && !$modified) continue;	// skip unchanged, empty values
1056
+			if (empty($detail['value']) && !$modified) continue; // skip unchanged, empty values
1057 1057
 
1058
-			$body .= $this->format_line($html_email,$detail['type'],$modified,
1058
+			$body .= $this->format_line($html_email, $detail['type'], $modified,
1059 1059
 				$detail['label'] ? $detail['label'] : '', $detail['value']);
1060 1060
 		}
1061 1061
 		if ($html_email)
1062 1062
 		{
1063 1063
 			$body .= "</table>\n";
1064 1064
 		}
1065
-		if(($sig = $this->get_signature($data,$old,$receiver)))
1065
+		if (($sig = $this->get_signature($data, $old, $receiver)))
1066 1066
 		{
1067
-			$body .= ($html_email ? '<br />':'') . "\n$sig";
1067
+			$body .= ($html_email ? '<br />' : '')."\n$sig";
1068 1068
 		}
1069 1069
 		if (!$html_email && $data['tr_edit_mode'] == 'html')
1070 1070
 		{
@@ -1084,20 +1084,20 @@  discard block
 block discarded – undo
1084 1084
 	 * @param string $data = null data or null to display just $line over 2 columns
1085 1085
 	 * @return string
1086 1086
 	 */
1087
-	protected function format_line($html_mail,$type,$modified,$line,$data=null)
1087
+	protected function format_line($html_mail, $type, $modified, $line, $data = null)
1088 1088
 	{
1089 1089
 		//error_log(__METHOD__.'('.array2string($html_mail).",'$type',".array2string($modified).",'$line',".array2string($data).')');
1090 1090
 		$content = '';
1091 1091
 
1092 1092
 		if ($html_mail)
1093 1093
 		{
1094
-			if (!$this->html_content_allow) $line = Api\Html::htmlspecialchars($line);	// XSS
1094
+			if (!$this->html_content_allow) $line = Api\Html::htmlspecialchars($line); // XSS
1095 1095
 
1096 1096
 			$color = $modified ? 'red' : false;
1097 1097
 			$size  = '110%';
1098 1098
 			$bold = false;
1099 1099
 			$background = '#FFFFF1';
1100
-			switch($type)
1100
+			switch ($type)
1101 1101
 			{
1102 1102
 				case 'message':
1103 1103
 					$background = '#D3DCE3;';
@@ -1115,7 +1115,7 @@  discard block
 block discarded – undo
1115 1115
 					if (strpos($data, '<br') === false)
1116 1116
 					{
1117 1117
 						$data = nl2br($this->html_content_allow ? $data : Api\Html::htmlspecialchars($data));
1118
-						$this->html_content_allow = true;	// to NOT do htmlspecialchars again
1118
+						$this->html_content_allow = true; // to NOT do htmlspecialchars again
1119 1119
 					}
1120 1120
 					break;
1121 1121
 				case 'reply':
@@ -1124,13 +1124,13 @@  discard block
 block discarded – undo
1124 1124
 				default:
1125 1125
 					$size = false;
1126 1126
 			}
1127
-			$style = ($bold ? 'font-weight:bold;' : '').($size ? 'font-size:'.$size.';' : '').($color?'color:'.$color:'');
1127
+			$style = ($bold ? 'font-weight:bold;' : '').($size ? 'font-size:'.$size.';' : '').($color ? 'color:'.$color : '');
1128 1128
 
1129
-			$content = '<tr style="background-color: '.$background.';"><td style="'.$style.($line && $data?'" width="20%':'" colspan="2').'">';
1129
+			$content = '<tr style="background-color: '.$background.';"><td style="'.$style.($line && $data ? '" width="20%' : '" colspan="2').'">';
1130 1130
 		}
1131 1131
 		else	// text-mail
1132 1132
 		{
1133
-			if ($type == 'reply') $content = str_repeat('-',64)."\n";
1133
+			if ($type == 'reply') $content = str_repeat('-', 64)."\n";
1134 1134
 
1135 1135
 			if ($modified) $content .= '> ';
1136 1136
 		}
@@ -1142,7 +1142,7 @@  discard block
 block discarded – undo
1142 1142
 			if ($type == 'link')
1143 1143
 			{
1144 1144
 				// the link is often too long for html boxes chunk-split allows to break lines if needed
1145
-				$content .= Api\Html::a_href(chunk_split(rawurldecode($data),40,'&#8203;'),$data,'','target="_blank"');
1145
+				$content .= Api\Html::a_href(chunk_split(rawurldecode($data), 40, '&#8203;'), $data, '', 'target="_blank"');
1146 1146
 			}
1147 1147
 			elseif ($this->html_content_allow)
1148 1148
 			{
@@ -1155,7 +1155,7 @@  discard block
 block discarded – undo
1155 1155
 		}
1156 1156
 		else
1157 1157
 		{
1158
-			$content .= ($content&&$data?': ':'').$data;
1158
+			$content .= ($content && $data ? ': ' : '').$data;
1159 1159
 		}
1160 1160
 		if ($html_mail) $content .= '</td></tr>';
1161 1161
 
@@ -1172,9 +1172,9 @@  discard block
 block discarded – undo
1172 1172
 	 * @param int|string $receiver nummeric account_id or email address
1173 1173
 	 * @return array or array with values for either 'string' or 'path' and optionally (mime-)'type', 'filename' and 'encoding'
1174 1174
 	 */
1175
-	protected function get_attachments($data,$old,$receiver=null)
1175
+	protected function get_attachments($data, $old, $receiver = null)
1176 1176
 	{
1177
-		unset($data, $old, $receiver);	// not used, but required by function signature
1177
+		unset($data, $old, $receiver); // not used, but required by function signature
1178 1178
 
1179 1179
 	 	return array();
1180 1180
 	}
@@ -1187,20 +1187,20 @@  discard block
 block discarded – undo
1187 1187
 	 */
1188 1188
 	protected function get_signature($data, $old, $receiver)
1189 1189
 	{
1190
-		unset($old, $receiver);	// not used, but required by function signature
1190
+		unset($old, $receiver); // not used, but required by function signature
1191 1191
 
1192 1192
 		$config = Api\Config::read('notifications');
1193
-		if(!isset($data[$this->id_field]))
1193
+		if (!isset($data[$this->id_field]))
1194 1194
 		{
1195
-			error_log($this->app . ' did not properly implement bo_tracking->id_field.  Merge skipped.');
1195
+			error_log($this->app.' did not properly implement bo_tracking->id_field.  Merge skipped.');
1196 1196
 		}
1197
-		elseif(class_exists($this->app. '_merge'))
1197
+		elseif (class_exists($this->app.'_merge'))
1198 1198
 		{
1199 1199
 			$merge_class = $this->app.'_merge';
1200 1200
 			$merge = new $merge_class();
1201 1201
 			$error = null;
1202 1202
 			$sig = $merge->merge_string($config['signature'], array($data[$this->id_field]), $error, 'text/html');
1203
-			if($error)
1203
+			if ($error)
1204 1204
 			{
1205 1205
 				error_log($error);
1206 1206
 				return $config['signature'];
@@ -1217,7 +1217,7 @@  discard block
 block discarded – undo
1217 1217
 	protected function get_custom_message($data, $old, $merge_class = null, $receiver = false)
1218 1218
 	{
1219 1219
 		$message = $this->get_config(self::CUSTOM_NOTIFICATION, $data, $old);
1220
-		if(!$message)
1220
+		if (!$message)
1221 1221
 		{
1222 1222
 			return '';
1223 1223
 		}
@@ -1226,21 +1226,21 @@  discard block
 block discarded – undo
1226 1226
 		$message = $this->sanitize_custom_message($message, $receiver);
1227 1227
 
1228 1228
 		// Automatically set merge class from naming conventions
1229
-		if($merge_class == null)
1229
+		if ($merge_class == null)
1230 1230
 		{
1231 1231
 			$merge_class = $this->app.'_merge';
1232 1232
 		}
1233
-		if(!isset($data[$this->id_field]))
1233
+		if (!isset($data[$this->id_field]))
1234 1234
 		{
1235
-			error_log($this->app . ' did not properly implement bo_tracking->id_field.  Merge skipped.');
1235
+			error_log($this->app.' did not properly implement bo_tracking->id_field.  Merge skipped.');
1236 1236
 			return $message;
1237 1237
 		}
1238
-		elseif(class_exists($merge_class))
1238
+		elseif (class_exists($merge_class))
1239 1239
 		{
1240 1240
 			$merge = new $merge_class();
1241 1241
 			$error = null;
1242 1242
 			$merged_message = $merge->merge_string($message, array($data[$this->id_field]), $error, 'text/html');
1243
-			if($error)
1243
+			if ($error)
1244 1244
 			{
1245 1245
 				error_log($error);
1246 1246
 				return $message;
@@ -1262,7 +1262,7 @@  discard block
 block discarded – undo
1262 1262
 	 */
1263 1263
 	protected function sanitize_custom_message($message, $receiver)
1264 1264
 	{
1265
-		if(!is_numeric($receiver))
1265
+		if (!is_numeric($receiver))
1266 1266
 		{
1267 1267
 			$receiver = false;
1268 1268
 		}
@@ -1272,14 +1272,14 @@  discard block
 block discarded – undo
1272 1272
 
1273 1273
 		// If we have a specific user and they're the same then there are
1274 1274
 		// no private fields so nothing needs to be done
1275
-		if($receiver && $all_cfs == $cfs)
1275
+		if ($receiver && $all_cfs == $cfs)
1276 1276
 		{
1277 1277
 			return $message;
1278 1278
 		}
1279 1279
 
1280 1280
 		// Replace any placeholders that use the private field, or any sub-keys
1281 1281
 		// of the field
1282
-		foreach($all_cfs as $name => $field)
1282
+		foreach ($all_cfs as $name => $field)
1283 1283
 		{
1284 1284
 			if ($receiver === false && $field['private'] || !$cfs[$name])
1285 1285
 			{
Please login to merge, or discard this patch.