@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * Construtor |
141 | 141 | * |
142 | 142 | * @param array |
143 | - * @param bool|int|string $_adminConnection create admin connection if true or account_id or imap username |
|
143 | + * @param boolean|string $_adminConnection create admin connection if true or account_id or imap username |
|
144 | 144 | * @param int $_timeout =null timeout in secs, if none given fmail pref or default of 20 is used |
145 | 145 | * @return void |
146 | 146 | */ |
@@ -564,7 +564,7 @@ discard block |
||
564 | 564 | * Returns an array containing the names of the selected mailboxes |
565 | 565 | * |
566 | 566 | * @param string $reference base mailbox to start the search (default is current mailbox) |
567 | - * @param string $restriction_search false or 0 means return all mailboxes |
|
567 | + * @param integer $restriction_search false or 0 means return all mailboxes |
|
568 | 568 | * true or 1 return only the mailbox that contains that exact name |
569 | 569 | * 2 return all mailboxes in that hierarchy level |
570 | 570 | * @param string $returnAttributes true means return an assoc array containing mailbox names and mailbox attributes |
@@ -648,7 +648,7 @@ discard block |
||
648 | 648 | * Returns an array containing the names of the subscribed selected mailboxes |
649 | 649 | * |
650 | 650 | * @param string $reference base mailbox to start the search |
651 | - * @param string $restriction_search false or 0 means return all mailboxes |
|
651 | + * @param integer $restriction_search false or 0 means return all mailboxes |
|
652 | 652 | * true or 1 return only the mailbox that contains that exact name |
653 | 653 | * 2 return all mailboxes in that hierarchy level |
654 | 654 | * @param string $returnAttributes true means return an assoc array containing mailbox names and mailbox attributes |
@@ -716,7 +716,7 @@ discard block |
||
716 | 716 | * Returns an array containing the names of the selected unsubscribed mailboxes |
717 | 717 | * |
718 | 718 | * @param string $reference base mailbox to start the search |
719 | - * @param string $restriction_search false or 0 means return all mailboxes |
|
719 | + * @param integer $restriction_search false or 0 means return all mailboxes |
|
720 | 720 | * true or 1 return only the mailbox that contains that exact name |
721 | 721 | * 2 return all mailboxes in that hierarchy level |
722 | 722 | * |
@@ -894,6 +894,7 @@ discard block |
||
894 | 894 | * |
895 | 895 | * @var array $_nameSpace |
896 | 896 | * @var string $_folderName |
897 | + * @param string $_folderName |
|
897 | 898 | * @return string the prefix (may be an empty string) |
898 | 899 | */ |
899 | 900 | static function getFolderPrefixFromNamespace($_nameSpace, $_folderName) |
@@ -912,7 +913,7 @@ discard block |
||
912 | 913 | * @param string $_mailbox |
913 | 914 | * @param string $delimiter |
914 | 915 | * @param string $prefix |
915 | - * @param string $reclevel = 0, counter to keep track of the current recursionlevel |
|
916 | + * @param integer $reclevel = 0, counter to keep track of the current recursionlevel |
|
916 | 917 | * @return array of mailboxes |
917 | 918 | */ |
918 | 919 | function getMailBoxesRecursive($_mailbox, $delimiter, $prefix, $reclevel=0) |
@@ -1344,7 +1345,7 @@ discard block |
||
1344 | 1345 | /** |
1345 | 1346 | * Get vacation message for given user |
1346 | 1347 | * |
1347 | - * @param int|string $_euser nummeric account_id or imap username |
|
1348 | + * @param string|null $_euser nummeric account_id or imap username |
|
1348 | 1349 | * @param string $_scriptName =null |
1349 | 1350 | * @throws Exception on connection error or authentication failure |
1350 | 1351 | * @return array |
@@ -580,16 +580,16 @@ discard block |
||
580 | 580 | $mailbox = ''; |
581 | 581 | if ( is_int( $restriction_search ) ){ |
582 | 582 | switch ( $restriction_search ) { |
583 | - case 0: |
|
584 | - $searchstring = $reference."*"; |
|
585 | - break; |
|
586 | - case 1: |
|
587 | - $mailbox = $searchstring = $reference; |
|
588 | - //$reference = '%'; |
|
589 | - break; |
|
590 | - case 2: |
|
591 | - $searchstring = $reference."%"; |
|
592 | - break; |
|
583 | + case 0: |
|
584 | + $searchstring = $reference."*"; |
|
585 | + break; |
|
586 | + case 1: |
|
587 | + $mailbox = $searchstring = $reference; |
|
588 | + //$reference = '%'; |
|
589 | + break; |
|
590 | + case 2: |
|
591 | + $searchstring = $reference."%"; |
|
592 | + break; |
|
593 | 593 | } |
594 | 594 | }else{ |
595 | 595 | if ( is_string( $restriction_search ) ){ |
@@ -664,16 +664,16 @@ discard block |
||
664 | 664 | $mailbox = ''; |
665 | 665 | if ( is_int( $restriction_search ) ){ |
666 | 666 | switch ( $restriction_search ) { |
667 | - case 0: |
|
668 | - $searchstring = $reference."*"; |
|
669 | - break; |
|
670 | - case 1: |
|
671 | - $mailbox = $searchstring = $reference; |
|
672 | - //$reference = '%'; |
|
673 | - break; |
|
674 | - case 2: |
|
675 | - $searchstring = $reference."%"; |
|
676 | - break; |
|
667 | + case 0: |
|
668 | + $searchstring = $reference."*"; |
|
669 | + break; |
|
670 | + case 1: |
|
671 | + $mailbox = $searchstring = $reference; |
|
672 | + //$reference = '%'; |
|
673 | + break; |
|
674 | + case 2: |
|
675 | + $searchstring = $reference."%"; |
|
676 | + break; |
|
677 | 677 | } |
678 | 678 | }else{ |
679 | 679 | if ( is_string( $restriction_search ) ){ |
@@ -730,16 +730,16 @@ discard block |
||
730 | 730 | |
731 | 731 | if ( is_int( $restriction_search ) ){ |
732 | 732 | switch ( $restriction_search ) { |
733 | - case 0: |
|
734 | - $mailbox = $reference."*"; |
|
735 | - break; |
|
736 | - case 1: |
|
737 | - $mailbox = $reference; |
|
738 | - $reference = '%'; |
|
739 | - break; |
|
740 | - case 2: |
|
741 | - $mailbox = "%"; |
|
742 | - break; |
|
733 | + case 0: |
|
734 | + $mailbox = $reference."*"; |
|
735 | + break; |
|
736 | + case 1: |
|
737 | + $mailbox = $reference; |
|
738 | + $reference = '%'; |
|
739 | + break; |
|
740 | + case 2: |
|
741 | + $mailbox = "%"; |
|
742 | + break; |
|
743 | 743 | } |
744 | 744 | }else{ |
745 | 745 | if ( is_string( $restriction_search ) ){ |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | static public $default_params = array( |
67 | 67 | //'debug' => '/tmp/imap.log', // uncomment to log communitcation with IMAP server |
68 | 68 | //'debug_literal' => true, // uncomment to log mail contents returned by IMAP server |
69 | - 'cache' => true, // default caching via Cache / Api\Cache |
|
69 | + 'cache' => true, // default caching via Cache / Api\Cache |
|
70 | 70 | ); |
71 | 71 | |
72 | 72 | /** |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @param int $_timeout =null timeout in secs, if none given fmail pref or default of 20 is used |
145 | 145 | * @return void |
146 | 146 | */ |
147 | - function __construct(array $params, $_adminConnection=false, $_timeout=null) |
|
147 | + function __construct(array $params, $_adminConnection = false, $_timeout = null) |
|
148 | 148 | { |
149 | 149 | if (function_exists('mb_convert_encoding')) |
150 | 150 | { |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | $this->loginType = $this->params['acc_imap_logintype']; |
157 | 157 | $this->domainName = $this->params['acc_domain']; |
158 | 158 | |
159 | - if (is_null($_timeout)) $_timeout = $this->params['acc_imap_timeout']?$this->params['acc_imap_timeout']:self::getTimeOut (); |
|
159 | + if (is_null($_timeout)) $_timeout = $this->params['acc_imap_timeout'] ? $this->params['acc_imap_timeout'] : self::getTimeOut(); |
|
160 | 160 | |
161 | 161 | // Horde use locale for translation of error messages |
162 | 162 | Api\Preferences::setlocale(LC_MESSAGES); |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | 'port' => $this->params['acc_imap_port'], |
176 | 176 | 'secure' => Account::ssl2secure($this->params['acc_imap_ssl']), |
177 | 177 | 'timeout' => $_timeout, |
178 | - )+self::$default_params; |
|
178 | + ) + self::$default_params; |
|
179 | 179 | |
180 | 180 | if ($parent_params['cache'] === true) |
181 | 181 | { |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | // as we have no way to tell this apart we ignore BINARY this affects |
200 | 200 | // Horde_Imap_Client_Fetch_Query::bodyPart for its fetch parameter decode=true is ignored |
201 | 201 | // (other functionality depending on BINARY is, of cause, affected too) |
202 | - $parent_params['capability_ignore']= array_merge((array)$parent_params['capability_ignore'],array('BINARY')); |
|
202 | + $parent_params['capability_ignore'] = array_merge((array)$parent_params['capability_ignore'], array('BINARY')); |
|
203 | 203 | break; |
204 | 204 | } |
205 | 205 | parent::__construct($parent_params); |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | * |
213 | 213 | * @param string $_username =true create an admin connection for given user or $this->acc_imap_username |
214 | 214 | */ |
215 | - function adminConnection($_username=true) |
|
215 | + function adminConnection($_username = true) |
|
216 | 216 | { |
217 | 217 | if ($this->isAdminConnection !== $_username) |
218 | 218 | { |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | * @param string $_username =null create an admin connection for given user or $this->acc_imap_username |
230 | 230 | * @throws Horde_IMAP_Client_Exception |
231 | 231 | */ |
232 | - public function checkAdminConnection($_username=true) |
|
232 | + public function checkAdminConnection($_username = true) |
|
233 | 233 | { |
234 | 234 | if ($this->acc_imap_administration) |
235 | 235 | { |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | */ |
247 | 247 | public function __get($name) |
248 | 248 | { |
249 | - switch($name) |
|
249 | + switch ($name) |
|
250 | 250 | { |
251 | 251 | case 'acc_imap_administration': |
252 | 252 | return !empty($this->params['acc_imap_admin_username']); |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | { |
265 | 265 | return $this->$name; |
266 | 266 | } |
267 | - if (array_key_exists($name,$this->params)) |
|
267 | + if (array_key_exists($name, $this->params)) |
|
268 | 268 | { |
269 | 269 | return $this->params[$name]; |
270 | 270 | } |
@@ -285,9 +285,9 @@ discard block |
||
285 | 285 | * @deprecated allready called by constructor automatic, parameters must be passed to constructor! |
286 | 286 | * @throws Api\Exception\WrongParameter |
287 | 287 | */ |
288 | - function openConnection($_adminConnection=false, $_timeout=null) |
|
288 | + function openConnection($_adminConnection = false, $_timeout = null) |
|
289 | 289 | { |
290 | - unset($_timeout); // not used |
|
290 | + unset($_timeout); // not used |
|
291 | 291 | if ($_adminConnection !== $this->params['adminConnection']) |
292 | 292 | { |
293 | 293 | throw new Api\Exception\WrongParameter('need to set parameters on calling Account->imapServer()!'); |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | * @param string _use decide if the use is for IMAP or SIEVE, by now only the default differs |
301 | 301 | * @return int - timeout (either set or default 20/10) |
302 | 302 | */ |
303 | - static function getTimeOut($_use='IMAP') |
|
303 | + static function getTimeOut($_use = 'IMAP') |
|
304 | 304 | { |
305 | 305 | $timeout = $GLOBALS['egw_info']['user']['preferences']['mail']['connectionTimeout']; |
306 | 306 | if (empty($timeout) || !($timeout > 0)) $timeout = $_use == 'SIEVE' ? 10 : 20; // this is the default value |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | */ |
326 | 326 | function addAccount($_hookValues) |
327 | 327 | { |
328 | - unset($_hookValues); // not used |
|
328 | + unset($_hookValues); // not used |
|
329 | 329 | return true; |
330 | 330 | } |
331 | 331 | |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | */ |
338 | 338 | function updateAccount($_hookValues) |
339 | 339 | { |
340 | - unset($_hookValues); // not used |
|
340 | + unset($_hookValues); // not used |
|
341 | 341 | return true; |
342 | 342 | } |
343 | 343 | |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | */ |
350 | 350 | function deleteAccount($_hookValues) |
351 | 351 | { |
352 | - unset($_hookValues); // not used |
|
352 | + unset($_hookValues); // not used |
|
353 | 353 | return true; |
354 | 354 | } |
355 | 355 | |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | */ |
367 | 367 | function encodeFolderName($_folderName) |
368 | 368 | { |
369 | - if($this->mbAvailable) { |
|
369 | + if ($this->mbAvailable) { |
|
370 | 370 | return mb_convert_encoding($_folderName, "UTF7-IMAP", Api\Translation::charset()); |
371 | 371 | } |
372 | 372 | |
@@ -383,17 +383,17 @@ discard block |
||
383 | 383 | */ |
384 | 384 | function getMailbox($mailbox) |
385 | 385 | { |
386 | - $mailboxes = $this->listMailboxes($mailbox,Horde_Imap_Client::MBOX_ALL); |
|
387 | - if (empty($mailboxes)) $mailboxes = $this->listMailboxes($mailbox,Horde_Imap_Client::MBOX_UNSUBSCRIBED); |
|
386 | + $mailboxes = $this->listMailboxes($mailbox, Horde_Imap_Client::MBOX_ALL); |
|
387 | + if (empty($mailboxes)) $mailboxes = $this->listMailboxes($mailbox, Horde_Imap_Client::MBOX_UNSUBSCRIBED); |
|
388 | 388 | //error_log(__METHOD__.__LINE__.'->'.$mailbox.'/'.array2string($mailboxes)); |
389 | 389 | $mboxes = new Horde_Imap_Client_Mailbox_List($mailboxes); |
390 | 390 | //_debug_array($mboxes->count()); |
391 | 391 | foreach ($mboxes->getIterator() as $k =>$box) |
392 | 392 | { |
393 | 393 | //error_log(__METHOD__.__LINE__.'->'.$k); |
394 | - if ($k!='user' && $k != '' && $k==$mailbox) return $box['mailbox']; //_debug_array(array($k => $client->status($k))); |
|
394 | + if ($k != 'user' && $k != '' && $k == $mailbox) return $box['mailbox']; //_debug_array(array($k => $client->status($k))); |
|
395 | 395 | } |
396 | - return ($this->mailboxExist($mailbox)?$mailbox:false); |
|
396 | + return ($this->mailboxExist($mailbox) ? $mailbox : false); |
|
397 | 397 | } |
398 | 398 | |
399 | 399 | /** |
@@ -409,23 +409,23 @@ discard block |
||
409 | 409 | //error_log(__METHOD__.__LINE__.':'.$mailbox); |
410 | 410 | $currentMailbox = $this->currentMailbox(); |
411 | 411 | } |
412 | - catch(\Exception $e) |
|
412 | + catch (\Exception $e) |
|
413 | 413 | { |
414 | 414 | //error_log(__METHOD__.__LINE__.' failed detecting currentMailbox:'.$currentMailbox.':'.$e->getMessage()); |
415 | - $currentMailbox=null; |
|
415 | + $currentMailbox = null; |
|
416 | 416 | unset($e); |
417 | 417 | } |
418 | 418 | try |
419 | 419 | { |
420 | 420 | //error_log(__METHOD__.__LINE__.':'.$mailbox); |
421 | 421 | $this->openMailbox($mailbox); |
422 | - $returnvalue=true; |
|
422 | + $returnvalue = true; |
|
423 | 423 | } |
424 | - catch(\Exception $e) |
|
424 | + catch (\Exception $e) |
|
425 | 425 | { |
426 | 426 | //error_log(__METHOD__.__LINE__.' failed opening:'.$mailbox.':'.$e->getMessage().' Called by:'.function_backtrace()); |
427 | 427 | unset($e); |
428 | - $returnvalue=false; |
|
428 | + $returnvalue = false; |
|
429 | 429 | } |
430 | 430 | if (!empty($currentMailbox) && $currentMailbox['mailbox'] != $mailbox) |
431 | 431 | { |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | //error_log(__METHOD__.__LINE__.':'.$currentMailbox .'<->'.$mailbox); |
435 | 435 | $this->openMailbox($currentMailbox['mailbox']); |
436 | 436 | } |
437 | - catch(\Exception $e) |
|
437 | + catch (\Exception $e) |
|
438 | 438 | { |
439 | 439 | //error_log(__METHOD__.__LINE__.' failed reopening:'.$currentMailbox.':'.$e->getMessage()); |
440 | 440 | unset($e); |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | { |
455 | 455 | $mailbox = $this->currentMailbox(); |
456 | 456 | } |
457 | - catch(\Exception $e) |
|
457 | + catch (\Exception $e) |
|
458 | 458 | { |
459 | 459 | error_log(__METHOD__.' ('.__LINE__.') failed fetching currentMailbox:'.$e->getMessage()); |
460 | 460 | //throw new egw_exception(__METHOD__.' ('.__LINE__.") failed to ".__METHOD__." :".$e->getMessage()); |
@@ -472,16 +472,16 @@ discard block |
||
472 | 472 | */ |
473 | 473 | function getSpecialUseFolders() |
474 | 474 | { |
475 | - $mailboxes = $this->getMailboxes('',0,true); |
|
475 | + $mailboxes = $this->getMailboxes('', 0, true); |
|
476 | 476 | $suF = array(); |
477 | 477 | foreach ($mailboxes as $box) |
478 | 478 | { |
479 | - if ($box['MAILBOX']!='user' && $box['MAILBOX'] != '') |
|
479 | + if ($box['MAILBOX'] != 'user' && $box['MAILBOX'] != '') |
|
480 | 480 | { |
481 | 481 | //error_log(__METHOD__.__LINE__.$k.'->'.array2string($box)); |
482 | - if (isset($box['ATTRIBUTES'])&&!empty($box['ATTRIBUTES'])&& |
|
483 | - stripos(strtolower(array2string($box['ATTRIBUTES'])),'\noselect')=== false&& |
|
484 | - stripos(strtolower(array2string($box['ATTRIBUTES'])),'\nonexistent')=== false) |
|
482 | + if (isset($box['ATTRIBUTES']) && !empty($box['ATTRIBUTES']) && |
|
483 | + stripos(strtolower(array2string($box['ATTRIBUTES'])), '\noselect') === false && |
|
484 | + stripos(strtolower(array2string($box['ATTRIBUTES'])), '\nonexistent') === false) |
|
485 | 485 | { |
486 | 486 | $suF[$box['MAILBOX']] = $box; |
487 | 487 | } |
@@ -503,7 +503,7 @@ discard block |
||
503 | 503 | $status = $this->status($mailbox); |
504 | 504 | foreach ($status as $key => $v) |
505 | 505 | { |
506 | - $_status[strtoupper($key)]=$v; |
|
506 | + $_status[strtoupper($key)] = $v; |
|
507 | 507 | } |
508 | 508 | return $_status; |
509 | 509 | } |
@@ -521,9 +521,9 @@ discard block |
||
521 | 521 | * @param ignoreStatusCache bool ignore the cache used for counters |
522 | 522 | * @return array with counters |
523 | 523 | */ |
524 | - function getStatus($mailbox, $ignoreStatusCache=false) |
|
524 | + function getStatus($mailbox, $ignoreStatusCache = false) |
|
525 | 525 | { |
526 | - $mailboxes = $this->listMailboxes($mailbox,Horde_Imap_Client::MBOX_ALL,array( |
|
526 | + $mailboxes = $this->listMailboxes($mailbox, Horde_Imap_Client::MBOX_ALL, array( |
|
527 | 527 | 'attributes'=>true, |
528 | 528 | 'children'=>true, //child info |
529 | 529 | 'delimiter'=>true, |
@@ -537,16 +537,16 @@ discard block |
||
537 | 537 | //error_log(__METHOD__.__LINE__.array2string($mboxes->count())); |
538 | 538 | foreach ($mboxes->getIterator() as $k =>$box) |
539 | 539 | { |
540 | - if ($k!='user' && $k != '' && $k==$mailbox) |
|
540 | + if ($k != 'user' && $k != '' && $k == $mailbox) |
|
541 | 541 | { |
542 | - if (stripos(array2string($box['attributes']),'\noselect')=== false) |
|
542 | + if (stripos(array2string($box['attributes']), '\noselect') === false) |
|
543 | 543 | { |
544 | 544 | $status = $this->status($k, $flags); |
545 | 545 | foreach ($status as $key => $v) |
546 | 546 | { |
547 | - $_status[strtoupper($key)]=$v; |
|
547 | + $_status[strtoupper($key)] = $v; |
|
548 | 548 | } |
549 | - $_status['HIERACHY_DELIMITER'] = $_status['delimiter'] = ($box['delimiter']?$box['delimiter']:$this->getDelimiter('personal')); |
|
549 | + $_status['HIERACHY_DELIMITER'] = $_status['delimiter'] = ($box['delimiter'] ? $box['delimiter'] : $this->getDelimiter('personal')); |
|
550 | 550 | $_status['ATTRIBUTES'] = $box['attributes']; |
551 | 551 | //error_log(__METHOD__.__LINE__.$k.'->'.array2string($_status)); |
552 | 552 | return $_status; |
@@ -572,14 +572,14 @@ discard block |
||
572 | 572 | * |
573 | 573 | * @return mixed array of mailboxes |
574 | 574 | */ |
575 | - function getMailboxes($reference = '' , $restriction_search = 0, $returnAttributes = false) |
|
575 | + function getMailboxes($reference = '', $restriction_search = 0, $returnAttributes = false) |
|
576 | 576 | { |
577 | - if ( is_bool($restriction_search) ){ |
|
578 | - $restriction_search = (int) $restriction_search; |
|
577 | + if (is_bool($restriction_search)) { |
|
578 | + $restriction_search = (int)$restriction_search; |
|
579 | 579 | } |
580 | 580 | $mailbox = ''; |
581 | - if ( is_int( $restriction_search ) ){ |
|
582 | - switch ( $restriction_search ) { |
|
581 | + if (is_int($restriction_search)) { |
|
582 | + switch ($restriction_search) { |
|
583 | 583 | case 0: |
584 | 584 | $searchstring = $reference."*"; |
585 | 585 | break; |
@@ -591,8 +591,8 @@ discard block |
||
591 | 591 | $searchstring = $reference."%"; |
592 | 592 | break; |
593 | 593 | } |
594 | - }else{ |
|
595 | - if ( is_string( $restriction_search ) ){ |
|
594 | + } else { |
|
595 | + if (is_string($restriction_search)) { |
|
596 | 596 | $mailbox = $searchstring = $restriction_search; |
597 | 597 | } |
598 | 598 | } |
@@ -605,35 +605,35 @@ discard block |
||
605 | 605 | 'special_use'=>true, |
606 | 606 | 'sort'=>true, |
607 | 607 | ); |
608 | - if ($returnAttributes==false) |
|
608 | + if ($returnAttributes == false) |
|
609 | 609 | { |
610 | 610 | unset($options['attributes']); |
611 | 611 | unset($options['children']); |
612 | 612 | unset($options['special_use']); |
613 | 613 | } |
614 | - $mailboxes = $this->listMailboxes($searchstring,Horde_Imap_Client::MBOX_ALL, $options); |
|
614 | + $mailboxes = $this->listMailboxes($searchstring, Horde_Imap_Client::MBOX_ALL, $options); |
|
615 | 615 | //$mboxes = new Horde_Imap_Client_Mailbox_List($mailboxes); |
616 | 616 | //_debug_array($mboxes->count()); |
617 | 617 | foreach ((array)$mailboxes as $k =>$box) |
618 | 618 | { |
619 | 619 | //error_log(__METHOD__.__LINE__.' Box:'.$k.'->'.array2string($box)); |
620 | - $ret[$k]=array('MAILBOX'=>$k,'ATTRIBUTES'=>$box['attributes'],'delimiter'=>($box['delimiter']?$box['delimiter']:$this->getDelimiter('personal')),'SUBSCRIBED'=>true); |
|
620 | + $ret[$k] = array('MAILBOX'=>$k, 'ATTRIBUTES'=>$box['attributes'], 'delimiter'=>($box['delimiter'] ? $box['delimiter'] : $this->getDelimiter('personal')), 'SUBSCRIBED'=>true); |
|
621 | 621 | } |
622 | 622 | // for unknown reasons on ALL, UNSUBSCRIBED are not returned |
623 | 623 | //always fetch unsubscribed, think about only fetching it when $options['attributes'] is set |
624 | 624 | //but then allMailboxes are not all, .... |
625 | 625 | //if (!empty($mailbox) && !isset($ret[$mailbox])) |
626 | 626 | { |
627 | - $unsub_mailboxes = $this->listMailboxes($searchstring,Horde_Imap_Client::MBOX_UNSUBSCRIBED, $options); |
|
627 | + $unsub_mailboxes = $this->listMailboxes($searchstring, Horde_Imap_Client::MBOX_UNSUBSCRIBED, $options); |
|
628 | 628 | //$mboxes = new Horde_Imap_Client_Mailbox_List($mailboxes); |
629 | 629 | //_debug_array($mboxes->count()); |
630 | 630 | //error_log(__METHOD__.__LINE__.' '.$mailbox.':'.count((array)$mailboxes).'->'.function_backtrace()); |
631 | 631 | foreach ((array)$unsub_mailboxes as $k =>$box) |
632 | 632 | { |
633 | 633 | //error_log(__METHOD__.__LINE__.' Box:'.$k.' already In?'.array_key_exists($k,$boxexists).'->'.array2string($box)); |
634 | - if(!array_key_exists($k,$ret)) |
|
634 | + if (!array_key_exists($k, $ret)) |
|
635 | 635 | { |
636 | - $ret[$k]=array('MAILBOX'=>$k,'ATTRIBUTES'=>$box['attributes'],'delimiter'=>($box['delimiter']?$box['delimiter']:$this->getDelimiter('personal')),'SUBSCRIBED'=>false); |
|
636 | + $ret[$k] = array('MAILBOX'=>$k, 'ATTRIBUTES'=>$box['attributes'], 'delimiter'=>($box['delimiter'] ? $box['delimiter'] : $this->getDelimiter('personal')), 'SUBSCRIBED'=>false); |
|
637 | 637 | } |
638 | 638 | else |
639 | 639 | { |
@@ -656,14 +656,14 @@ discard block |
||
656 | 656 | * |
657 | 657 | * @return mixed array of mailboxes |
658 | 658 | */ |
659 | - function listSubscribedMailboxes($reference = '' , $restriction_search = 0, $returnAttributes = false) |
|
659 | + function listSubscribedMailboxes($reference = '', $restriction_search = 0, $returnAttributes = false) |
|
660 | 660 | { |
661 | - if ( is_bool($restriction_search) ){ |
|
662 | - $restriction_search = (int) $restriction_search; |
|
661 | + if (is_bool($restriction_search)) { |
|
662 | + $restriction_search = (int)$restriction_search; |
|
663 | 663 | } |
664 | 664 | $mailbox = ''; |
665 | - if ( is_int( $restriction_search ) ){ |
|
666 | - switch ( $restriction_search ) { |
|
665 | + if (is_int($restriction_search)) { |
|
666 | + switch ($restriction_search) { |
|
667 | 667 | case 0: |
668 | 668 | $searchstring = $reference."*"; |
669 | 669 | break; |
@@ -675,8 +675,8 @@ discard block |
||
675 | 675 | $searchstring = $reference."%"; |
676 | 676 | break; |
677 | 677 | } |
678 | - }else{ |
|
679 | - if ( is_string( $restriction_search ) ){ |
|
678 | + } else { |
|
679 | + if (is_string($restriction_search)) { |
|
680 | 680 | $mailbox = $searchstring = $restriction_search; |
681 | 681 | } |
682 | 682 | } |
@@ -688,25 +688,25 @@ discard block |
||
688 | 688 | 'special_use'=>true, |
689 | 689 | 'sort'=>true, |
690 | 690 | ); |
691 | - if ($returnAttributes==false) |
|
691 | + if ($returnAttributes == false) |
|
692 | 692 | { |
693 | 693 | unset($options['attributes']); |
694 | 694 | unset($options['children']); |
695 | 695 | unset($options['special_use']); |
696 | 696 | } |
697 | - $mailboxes = $this->listMailboxes($searchstring,Horde_Imap_Client::MBOX_SUBSCRIBED_EXISTS, $options); |
|
697 | + $mailboxes = $this->listMailboxes($searchstring, Horde_Imap_Client::MBOX_SUBSCRIBED_EXISTS, $options); |
|
698 | 698 | //$mboxes = new Horde_Imap_Client_Mailbox_List($mailboxes); |
699 | 699 | //_debug_array($mboxes->count()); |
700 | 700 | foreach ((array)$mailboxes as $k =>$box) |
701 | 701 | { |
702 | 702 | //error_log(__METHOD__.__LINE__.' Searched for:'.$mailbox.' got Box:'.$k.'->'.array2string($box).function_backtrace()); |
703 | - if ($returnAttributes==false) |
|
703 | + if ($returnAttributes == false) |
|
704 | 704 | { |
705 | - $ret[]=$k; |
|
705 | + $ret[] = $k; |
|
706 | 706 | } |
707 | 707 | else |
708 | 708 | { |
709 | - $ret[$k]=array('MAILBOX'=>$k,'ATTRIBUTES'=>$box['attributes'],'delimiter'=>($box['delimiter']?$box['delimiter']:$this->getDelimiter('personal')),'SUBSCRIBED'=>true); |
|
709 | + $ret[$k] = array('MAILBOX'=>$k, 'ATTRIBUTES'=>$box['attributes'], 'delimiter'=>($box['delimiter'] ? $box['delimiter'] : $this->getDelimiter('personal')), 'SUBSCRIBED'=>true); |
|
710 | 710 | } |
711 | 711 | } |
712 | 712 | return $ret; |
@@ -722,14 +722,14 @@ discard block |
||
722 | 722 | * |
723 | 723 | * @return mixed array of mailboxes |
724 | 724 | */ |
725 | - function listUnSubscribedMailboxes($reference = '' , $restriction_search = 0) |
|
725 | + function listUnSubscribedMailboxes($reference = '', $restriction_search = 0) |
|
726 | 726 | { |
727 | - if ( is_bool($restriction_search) ){ |
|
728 | - $restriction_search = (int) $restriction_search; |
|
727 | + if (is_bool($restriction_search)) { |
|
728 | + $restriction_search = (int)$restriction_search; |
|
729 | 729 | } |
730 | 730 | |
731 | - if ( is_int( $restriction_search ) ){ |
|
732 | - switch ( $restriction_search ) { |
|
731 | + if (is_int($restriction_search)) { |
|
732 | + switch ($restriction_search) { |
|
733 | 733 | case 0: |
734 | 734 | $mailbox = $reference."*"; |
735 | 735 | break; |
@@ -741,8 +741,8 @@ discard block |
||
741 | 741 | $mailbox = "%"; |
742 | 742 | break; |
743 | 743 | } |
744 | - }else{ |
|
745 | - if ( is_string( $restriction_search ) ){ |
|
744 | + } else { |
|
745 | + if (is_string($restriction_search)) { |
|
746 | 746 | $mailbox = $restriction_search; |
747 | 747 | } |
748 | 748 | } |
@@ -751,17 +751,17 @@ discard block |
||
751 | 751 | 'sort'=>true, |
752 | 752 | //'flat'=>true, |
753 | 753 | ); |
754 | - $mailboxes = $this->listMailboxes($mailbox,Horde_Imap_Client::MBOX_SUBSCRIBED_EXISTS, $options); |
|
754 | + $mailboxes = $this->listMailboxes($mailbox, Horde_Imap_Client::MBOX_SUBSCRIBED_EXISTS, $options); |
|
755 | 755 | foreach ($mailboxes as $box) |
756 | 756 | { |
757 | 757 | //error_log(__METHOD__.__LINE__.' Box:'.$k.'->'.array2string($box['mailbox']->utf8)); |
758 | - $sret[]=$box['mailbox']->utf8; |
|
758 | + $sret[] = $box['mailbox']->utf8; |
|
759 | 759 | } |
760 | - $unsubscribed = $this->listMailboxes($mailbox,Horde_Imap_Client::MBOX_UNSUBSCRIBED, $options); |
|
760 | + $unsubscribed = $this->listMailboxes($mailbox, Horde_Imap_Client::MBOX_UNSUBSCRIBED, $options); |
|
761 | 761 | foreach ($unsubscribed as $box) |
762 | 762 | { |
763 | 763 | //error_log(__METHOD__.__LINE__.' Box:'.$k.'->'.array2string($box['mailbox']->utf8)); |
764 | - if (!in_array($box['mailbox']->utf8,$sret) && $box['mailbox']->utf8!='INBOX') $ret[]=$box['mailbox']->utf8; |
|
764 | + if (!in_array($box['mailbox']->utf8, $sret) && $box['mailbox']->utf8 != 'INBOX') $ret[] = $box['mailbox']->utf8; |
|
765 | 765 | } |
766 | 766 | return $ret; |
767 | 767 | } |
@@ -773,12 +773,12 @@ discard block |
||
773 | 773 | * @param int $flags =null default Horde_Imap_Client::STATUS_ALL | Horde_Imap_Client::STATUS_FLAGS | Horde_Imap_Client::STATUS_PERMFLAGS |
774 | 774 | * @return array of counters for mailbox |
775 | 775 | */ |
776 | - function examineMailbox($mailbox, $flags=null) |
|
776 | + function examineMailbox($mailbox, $flags = null) |
|
777 | 777 | { |
778 | - if ($mailbox=='') return false; |
|
778 | + if ($mailbox == '') return false; |
|
779 | 779 | $mailboxes = $this->listMailboxes($mailbox); |
780 | 780 | |
781 | - if (is_null($flags)) $flags = Horde_Imap_Client::STATUS_ALL | Horde_Imap_Client::STATUS_FLAGS | Horde_Imap_Client::STATUS_PERMFLAGS; |
|
781 | + if (is_null($flags)) $flags = Horde_Imap_Client::STATUS_ALL|Horde_Imap_Client::STATUS_FLAGS|Horde_Imap_Client::STATUS_PERMFLAGS; |
|
782 | 782 | |
783 | 783 | $mboxes = new Horde_Imap_Client_Mailbox_List($mailboxes); |
784 | 784 | //_debug_array($mboxes->count()); |
@@ -786,18 +786,18 @@ discard block |
||
786 | 786 | { |
787 | 787 | //error_log(__METHOD__.__LINE__.array2string($box)); |
788 | 788 | unset($box); |
789 | - if ($k!='user' && $k != '' && $k==$mailbox) |
|
789 | + if ($k != 'user' && $k != '' && $k == $mailbox) |
|
790 | 790 | { |
791 | 791 | $status = $this->status($k, $flags); |
792 | 792 | //error_log(__METHOD__.__LINE__.array2string($status)); |
793 | 793 | foreach ($status as $key => $v) |
794 | 794 | { |
795 | - $_status[strtoupper($key)]=$v; |
|
795 | + $_status[strtoupper($key)] = $v; |
|
796 | 796 | } |
797 | - if ($flags & (Horde_Imap_Client::STATUS_FLAGS|Horde_Imap_Client::STATUS_PERMFLAGS)) |
|
797 | + if ($flags&(Horde_Imap_Client::STATUS_FLAGS|Horde_Imap_Client::STATUS_PERMFLAGS)) |
|
798 | 798 | { |
799 | 799 | self::$supports_keywords[$this->ImapServerId] = stripos(implode('', $status['flags']), '$label') !== false || |
800 | - in_array('\\*', $status['permflags']); // arbitrary keyswords also allow keywords |
|
800 | + in_array('\\*', $status['permflags']); // arbitrary keyswords also allow keywords |
|
801 | 801 | } |
802 | 802 | return $_status; |
803 | 803 | } |
@@ -836,7 +836,7 @@ discard block |
||
836 | 836 | */ |
837 | 837 | function hasCapability($capability) |
838 | 838 | { |
839 | - if ($capability=='SUPPORTS_KEYWORDS') |
|
839 | + if ($capability == 'SUPPORTS_KEYWORDS') |
|
840 | 840 | { |
841 | 841 | // if pseudo-flag is not set, call examineMailbox now to set it (no STATUS_ALL = counters necessary) |
842 | 842 | if (!isset(self::$supports_keywords[$this->ImapServerId])) |
@@ -848,7 +848,7 @@ discard block |
||
848 | 848 | catch (\Exception $e) |
849 | 849 | { |
850 | 850 | error_log(__METHOD__.__LINE__.' (examineServer for detection) '.$capability.'->'.array2string(self::$supports_keywords).' failed '.function_backtrace()); |
851 | - self::$supports_keywords[$this->ImapServerId]=false; |
|
851 | + self::$supports_keywords[$this->ImapServerId] = false; |
|
852 | 852 | } |
853 | 853 | } |
854 | 854 | //error_log(__METHOD__.__LINE__.' '.$capability.'->'.array2string(self::$supports_keywords).' '.function_backtrace()); |
@@ -898,9 +898,9 @@ discard block |
||
898 | 898 | */ |
899 | 899 | static function getFolderPrefixFromNamespace($_nameSpace, $_folderName) |
900 | 900 | { |
901 | - foreach($_nameSpace as &$singleNameSpace) |
|
901 | + foreach ($_nameSpace as &$singleNameSpace) |
|
902 | 902 | { |
903 | - if (substr($_folderName,0,strlen($singleNameSpace['prefix'])) == $singleNameSpace['prefix']) return $singleNameSpace['prefix']; |
|
903 | + if (substr($_folderName, 0, strlen($singleNameSpace['prefix'])) == $singleNameSpace['prefix']) return $singleNameSpace['prefix']; |
|
904 | 904 | } |
905 | 905 | return ""; |
906 | 906 | } |
@@ -915,33 +915,33 @@ discard block |
||
915 | 915 | * @param string $reclevel = 0, counter to keep track of the current recursionlevel |
916 | 916 | * @return array of mailboxes |
917 | 917 | */ |
918 | - function getMailBoxesRecursive($_mailbox, $delimiter, $prefix, $reclevel=0) |
|
918 | + function getMailBoxesRecursive($_mailbox, $delimiter, $prefix, $reclevel = 0) |
|
919 | 919 | { |
920 | 920 | if ($reclevel > 25) { |
921 | - error_log( __METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter "); |
|
921 | + error_log(__METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter "); |
|
922 | 922 | return array(); |
923 | 923 | } |
924 | 924 | $reclevel++; |
925 | 925 | // clean up double delimiters |
926 | - $mailbox = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$_mailbox); |
|
926 | + $mailbox = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter : $delimiter).'+~s', $delimiter, $_mailbox); |
|
927 | 927 | //get that mailbox in question |
928 | - $mbx = $this->getMailboxes($mailbox,1,true); |
|
928 | + $mbx = $this->getMailboxes($mailbox, 1, true); |
|
929 | 929 | $mbxkeys = array_keys($mbx); |
930 | 930 | |
931 | 931 | // Example: Array([INBOX/GaGa] => Array([MAILBOX] => INBOX/GaGa[ATTRIBUTES] => Array([0] => \\unmarked)[delimiter] => /)) |
932 | - if (is_array($mbx[$mbxkeys[0]]["ATTRIBUTES"]) && (in_array('\HasChildren',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Haschildren',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\haschildren',$mbx[$mbxkeys[0]]["ATTRIBUTES"]))) |
|
932 | + if (is_array($mbx[$mbxkeys[0]]["ATTRIBUTES"]) && (in_array('\HasChildren', $mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Haschildren', $mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\haschildren', $mbx[$mbxkeys[0]]["ATTRIBUTES"]))) |
|
933 | 933 | { |
934 | - $buff = $this->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'].($mbx[$mbxkeys[0]]['MAILBOX'] == $prefix ? '':$delimiter),2,false); |
|
934 | + $buff = $this->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'].($mbx[$mbxkeys[0]]['MAILBOX'] == $prefix ? '' : $delimiter), 2, false); |
|
935 | 935 | $allMailboxes = array(); |
936 | 936 | foreach ($buff as $mbxname) { |
937 | - $mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$mbxname['MAILBOX']); |
|
937 | + $mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter : $delimiter).'+~s', $delimiter, $mbxname['MAILBOX']); |
|
938 | 938 | #echo "About to recur in level $reclevel:".$mbxname."<br>"; |
939 | - if ( $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'] && $mbxname != $prefix && $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'].$delimiter) |
|
939 | + if ($mbxname != $mbx[$mbxkeys[0]]['MAILBOX'] && $mbxname != $prefix && $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'].$delimiter) |
|
940 | 940 | { |
941 | 941 | $allMailboxes = array_merge($allMailboxes, self::getMailBoxesRecursive($mbxname, $delimiter, $prefix, $reclevel)); |
942 | 942 | } |
943 | 943 | } |
944 | - if (!(in_array('\NoSelect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]))) $allMailboxes[] = $mbx[$mbxkeys[0]]['MAILBOX']; |
|
944 | + if (!(in_array('\NoSelect', $mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Noselect', $mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\noselect', $mbx[$mbxkeys[0]]["ATTRIBUTES"]))) $allMailboxes[] = $mbx[$mbxkeys[0]]['MAILBOX']; |
|
945 | 945 | return $allMailboxes; |
946 | 946 | } |
947 | 947 | else |
@@ -960,24 +960,24 @@ discard block |
||
960 | 960 | */ |
961 | 961 | function getNameSpace() |
962 | 962 | { |
963 | - static $nameSpace=null; |
|
963 | + static $nameSpace = null; |
|
964 | 964 | $foldersNameSpace = array(); |
965 | 965 | $delimiter = $this->getDelimiter(); |
966 | - if (empty($delimiter)) $delimiter='/'; |
|
966 | + if (empty($delimiter)) $delimiter = '/'; |
|
967 | 967 | if (is_null($nameSpace)) $nameSpace = $this->getNameSpaceArray(); |
968 | 968 | if (is_array($nameSpace)) { |
969 | - foreach($nameSpace as $type => $singleNameSpaceArray) |
|
969 | + foreach ($nameSpace as $type => $singleNameSpaceArray) |
|
970 | 970 | { |
971 | 971 | foreach ($singleNameSpaceArray as $singleNameSpace) |
972 | 972 | { |
973 | 973 | $_foldersNameSpace = array(); |
974 | - if($type == 'personal' && $singleNameSpace['name'] == '#mh/' && ($this->folderExists('Mail')||$this->folderExists('INBOX'))) |
|
974 | + if ($type == 'personal' && $singleNameSpace['name'] == '#mh/' && ($this->folderExists('Mail') || $this->folderExists('INBOX'))) |
|
975 | 975 | { |
976 | 976 | $_foldersNameSpace['prefix_present'] = 'forced'; |
977 | 977 | // uw-imap server with mailbox prefix or dovecot maybe |
978 | - $_foldersNameSpace['prefix'] = ($this->folderExists('Mail')?'Mail':(!empty($singleNameSpace['name'])?$singleNameSpace['name']:'')); |
|
978 | + $_foldersNameSpace['prefix'] = ($this->folderExists('Mail') ? 'Mail' : (!empty($singleNameSpace['name']) ? $singleNameSpace['name'] : '')); |
|
979 | 979 | } |
980 | - elseif($type == 'personal' && ($singleNameSpace['name'] == '#mh/') && $this->folderExists('mail')) |
|
980 | + elseif ($type == 'personal' && ($singleNameSpace['name'] == '#mh/') && $this->folderExists('mail')) |
|
981 | 981 | { |
982 | 982 | $_foldersNameSpace['prefix_present'] = 'forced'; |
983 | 983 | // uw-imap server with mailbox prefix or dovecot maybe |
@@ -986,9 +986,9 @@ discard block |
||
986 | 986 | $_foldersNameSpace['prefix_present'] = !empty($singleNameSpace['name']); |
987 | 987 | $_foldersNameSpace['prefix'] = $singleNameSpace['name']; |
988 | 988 | } |
989 | - $_foldersNameSpace['delimiter'] = ($singleNameSpace['delimiter']?$singleNameSpace['delimiter']:$delimiter); |
|
989 | + $_foldersNameSpace['delimiter'] = ($singleNameSpace['delimiter'] ? $singleNameSpace['delimiter'] : $delimiter); |
|
990 | 990 | $_foldersNameSpace['type'] = $type; |
991 | - $foldersNameSpace[] =$_foldersNameSpace; |
|
991 | + $foldersNameSpace[] = $_foldersNameSpace; |
|
992 | 992 | } |
993 | 993 | } |
994 | 994 | } |
@@ -1000,29 +1000,29 @@ discard block |
||
1000 | 1000 | * @param mixed _type (1=personal, 2=user/other, 3=shared) |
1001 | 1001 | * @return string the delimimiter |
1002 | 1002 | */ |
1003 | - function getDelimiter($_type=1) |
|
1003 | + function getDelimiter($_type = 1) |
|
1004 | 1004 | { |
1005 | 1005 | switch ($_type) |
1006 | 1006 | { |
1007 | 1007 | case 'user': |
1008 | 1008 | case 'other': |
1009 | 1009 | case 2: |
1010 | - $type=2; |
|
1010 | + $type = 2; |
|
1011 | 1011 | break; |
1012 | 1012 | case 'shared': |
1013 | 1013 | case '': |
1014 | 1014 | case 3: |
1015 | - $type=3; |
|
1015 | + $type = 3; |
|
1016 | 1016 | break; |
1017 | 1017 | case 'personal': |
1018 | 1018 | case 1: |
1019 | 1019 | default: |
1020 | - $type=1; |
|
1020 | + $type = 1; |
|
1021 | 1021 | } |
1022 | 1022 | $namespaces = $this->getNamespaces(); |
1023 | 1023 | foreach ($namespaces as $nsp) |
1024 | 1024 | { |
1025 | - if ($nsp['type']==$type && $nsp['delimiter']) return $nsp['delimiter']; |
|
1025 | + if ($nsp['type'] == $type && $nsp['delimiter']) return $nsp['delimiter']; |
|
1026 | 1026 | } |
1027 | 1027 | return "/"; |
1028 | 1028 | } |
@@ -1059,11 +1059,11 @@ discard block |
||
1059 | 1059 | switch ($this->loginType) |
1060 | 1060 | { |
1061 | 1061 | case 'email': |
1062 | - $accountemail = $GLOBALS['egw']->accounts->id2name($accountID,'account_email'); |
|
1062 | + $accountemail = $GLOBALS['egw']->accounts->id2name($accountID, 'account_email'); |
|
1063 | 1063 | //$accountemail = $GLOBALS['egw']->accounts->read($GLOBALS['egw']->accounts->name2id($_username,'account_email')); |
1064 | 1064 | if (!empty($accountemail)) |
1065 | 1065 | { |
1066 | - list($lusername,$domain) = explode('@',$accountemail,2); |
|
1066 | + list($lusername, $domain) = explode('@', $accountemail, 2); |
|
1067 | 1067 | if (strtolower($domain) == strtolower($this->domainName) && !empty($lusername)) |
1068 | 1068 | { |
1069 | 1069 | $_username = $lusername; |
@@ -1082,8 +1082,8 @@ discard block |
||
1082 | 1082 | if (empty($this->loginType)) |
1083 | 1083 | { |
1084 | 1084 | // try to figure out by params['acc_imap_username'] |
1085 | - list($lusername,$domain) = explode('@',$this->params['acc_imap_username'],2); |
|
1086 | - if (strpos($_username,'@')===false && !empty($domain) && !empty($lusername)) |
|
1085 | + list($lusername, $domain) = explode('@', $this->params['acc_imap_username'], 2); |
|
1086 | + if (strpos($_username, '@') === false && !empty($domain) && !empty($lusername)) |
|
1087 | 1087 | { |
1088 | 1088 | $_username = $_username.'@'.$domain; |
1089 | 1089 | } |
@@ -1127,20 +1127,20 @@ discard block |
||
1127 | 1127 | * @param string $_folderName='' |
1128 | 1128 | * @return string utf-7 encoded (done in getMailboxName) |
1129 | 1129 | */ |
1130 | - function getUserMailboxString($_username, $_folderName='') |
|
1130 | + function getUserMailboxString($_username, $_folderName = '') |
|
1131 | 1131 | { |
1132 | 1132 | $nameSpaces = $this->getNameSpaceArray(); |
1133 | 1133 | |
1134 | - if(!isset($nameSpaces['others'])) { |
|
1134 | + if (!isset($nameSpaces['others'])) { |
|
1135 | 1135 | return false; |
1136 | 1136 | } |
1137 | 1137 | |
1138 | 1138 | $username = $this->getMailBoxUserName($_username); |
1139 | - if($this->loginType == 'vmailmgr' || $this->loginType == 'email' || $this->loginType == 'uidNumber') { |
|
1140 | - $username .= '@'. $this->domainName; |
|
1139 | + if ($this->loginType == 'vmailmgr' || $this->loginType == 'email' || $this->loginType == 'uidNumber') { |
|
1140 | + $username .= '@'.$this->domainName; |
|
1141 | 1141 | } |
1142 | 1142 | |
1143 | - $mailboxString = $nameSpaces['others'][0]['name'] . $username . (!empty($_folderName) ? ($nameSpaces['others'][0]['delimiter']?$nameSpaces['others'][0]['delimiter']:'/') . $_folderName : ''); |
|
1143 | + $mailboxString = $nameSpaces['others'][0]['name'].$username.(!empty($_folderName) ? ($nameSpaces['others'][0]['delimiter'] ? $nameSpaces['others'][0]['delimiter'] : '/').$_folderName : ''); |
|
1144 | 1144 | |
1145 | 1145 | return $mailboxString; |
1146 | 1146 | } |
@@ -1159,7 +1159,7 @@ discard block |
||
1159 | 1159 | ); |
1160 | 1160 | //error_log(__METHOD__.__LINE__.array2string($types)); |
1161 | 1161 | $result = array(); |
1162 | - foreach($this->getNamespaces() as $data) |
|
1162 | + foreach ($this->getNamespaces() as $data) |
|
1163 | 1163 | { |
1164 | 1164 | //error_log(__METHOD__.__LINE__.array2string($data)); |
1165 | 1165 | if (isset($types[$data['type']])) |
@@ -1169,7 +1169,7 @@ discard block |
||
1169 | 1169 | 'name' => $data['name'], |
1170 | 1170 | 'prefix' => $data['name'], |
1171 | 1171 | 'prefix_present' => !empty($data['name']), |
1172 | - 'delimiter' => ($data['delimiter']?$data['delimiter']:'/'), |
|
1172 | + 'delimiter' => ($data['delimiter'] ? $data['delimiter'] : '/'), |
|
1173 | 1173 | ); |
1174 | 1174 | } |
1175 | 1175 | } |
@@ -1190,7 +1190,7 @@ discard block |
||
1190 | 1190 | { |
1191 | 1191 | if ($qInfo['storage']) |
1192 | 1192 | { |
1193 | - return array('USED'=>$qInfo['storage']['usage'],'QMAX'=>$qInfo['storage']['limit']); |
|
1193 | + return array('USED'=>$qInfo['storage']['usage'], 'QMAX'=>$qInfo['storage']['limit']); |
|
1194 | 1194 | } |
1195 | 1195 | } |
1196 | 1196 | return false; |
@@ -1204,7 +1204,7 @@ discard block |
||
1204 | 1204 | * @param string $_what - what to retrieve either limit/QMAX, usage/USED or ALL is supported |
1205 | 1205 | * @return int|array|boolean the quota for specified user (by what) or array with values for "limit" and "usage", or false |
1206 | 1206 | */ |
1207 | - function getQuotaByUser($_username, $_what='QMAX') |
|
1207 | + function getQuotaByUser($_username, $_what = 'QMAX') |
|
1208 | 1208 | { |
1209 | 1209 | $mailboxName = $this->getUserMailboxString($_username); |
1210 | 1210 | $storageQuota = $this->getQuotaRoot($mailboxName); |
@@ -1213,7 +1213,7 @@ discard block |
||
1213 | 1213 | if (is_array($storageQuota) && isset($storageQuota[$mailboxName]) && is_array($storageQuota[$mailboxName]) && |
1214 | 1214 | isset($storageQuota[$mailboxName]['storage']) && is_array($storageQuota[$mailboxName]['storage'])) |
1215 | 1215 | { |
1216 | - switch($_what) |
|
1216 | + switch ($_what) |
|
1217 | 1217 | { |
1218 | 1218 | case 'QMAX': |
1219 | 1219 | $_what = 'limit'; |
@@ -1239,7 +1239,7 @@ discard block |
||
1239 | 1239 | */ |
1240 | 1240 | function getUserData($_username) |
1241 | 1241 | { |
1242 | - unset($_username); // not used |
|
1242 | + unset($_username); // not used |
|
1243 | 1243 | return array(); |
1244 | 1244 | } |
1245 | 1245 | |
@@ -1252,7 +1252,7 @@ discard block |
||
1252 | 1252 | */ |
1253 | 1253 | function setUserData($_username, $_quota) |
1254 | 1254 | { |
1255 | - unset($_username, $_quota); // not used |
|
1255 | + unset($_username, $_quota); // not used |
|
1256 | 1256 | return true; |
1257 | 1257 | } |
1258 | 1258 | |
@@ -1286,10 +1286,10 @@ discard block |
||
1286 | 1286 | * @param array $params |
1287 | 1287 | * @throws Api\Exception\WrongParameter |
1288 | 1288 | */ |
1289 | - public function __call($name,array $params=null) |
|
1289 | + public function __call($name, array $params = null) |
|
1290 | 1290 | { |
1291 | 1291 | if ($this->debug) error_log(__METHOD__.'->'.$name.' with params:'.array2string($params)); |
1292 | - switch($name) |
|
1292 | + switch ($name) |
|
1293 | 1293 | { |
1294 | 1294 | case 'installScript': |
1295 | 1295 | case 'getScript': |
@@ -1304,9 +1304,9 @@ discard block |
||
1304 | 1304 | if (is_null($this->sieve)) |
1305 | 1305 | { |
1306 | 1306 | $this->sieve = new Sieve($this); |
1307 | - $this->error =& $this->sieve->error; |
|
1307 | + $this->error = & $this->sieve->error; |
|
1308 | 1308 | } |
1309 | - $ret = call_user_func_array(array($this->sieve,$name),$params); |
|
1309 | + $ret = call_user_func_array(array($this->sieve, $name), $params); |
|
1310 | 1310 | //error_log(__CLASS__.'->'.$name.'('.array2string($params).') returns '.array2string($ret)); |
1311 | 1311 | return $ret; |
1312 | 1312 | } |
@@ -1321,7 +1321,7 @@ discard block |
||
1321 | 1321 | * @param string $_scriptName =null |
1322 | 1322 | * @return boolean |
1323 | 1323 | */ |
1324 | - public function setVacationUser($_euser, array $_vacation, $_scriptName=null) |
|
1324 | + public function setVacationUser($_euser, array $_vacation, $_scriptName = null) |
|
1325 | 1325 | { |
1326 | 1326 | if ($this->debug) error_log(__METHOD__.' User:'.array2string($_euser).' Scriptname:'.array2string($_scriptName).' VacationMessage:'.array2string($_vacation)); |
1327 | 1327 | |
@@ -1333,8 +1333,8 @@ discard block |
||
1333 | 1333 | { |
1334 | 1334 | $this->adminConnection($_euser); |
1335 | 1335 | $this->sieve = new Sieve($this, $_euser, $_scriptName); |
1336 | - $this->scriptName =& $this->sieve->scriptName; |
|
1337 | - $this->error =& $this->sieve->error; |
|
1336 | + $this->scriptName = & $this->sieve->scriptName; |
|
1337 | + $this->error = & $this->sieve->error; |
|
1338 | 1338 | } |
1339 | 1339 | $ret = $this->setVacation($_vacation, $_scriptName); |
1340 | 1340 | |
@@ -1349,7 +1349,7 @@ discard block |
||
1349 | 1349 | * @throws Exception on connection error or authentication failure |
1350 | 1350 | * @return array |
1351 | 1351 | */ |
1352 | - public function getVacationUser($_euser, $_scriptName=null) |
|
1352 | + public function getVacationUser($_euser, $_scriptName = null) |
|
1353 | 1353 | { |
1354 | 1354 | if ($this->debug) error_log(__METHOD__.' User:'.array2string($_euser)); |
1355 | 1355 | |
@@ -1361,8 +1361,8 @@ discard block |
||
1361 | 1361 | { |
1362 | 1362 | $this->adminConnection($_euser); |
1363 | 1363 | $this->sieve = new Sieve($this, $_euser, $_scriptName); |
1364 | - $this->error =& $this->sieve->error; |
|
1365 | - $this->scriptName =& $this->sieve->scriptName; |
|
1364 | + $this->error = & $this->sieve->error; |
|
1365 | + $this->scriptName = & $this->sieve->scriptName; |
|
1366 | 1366 | } |
1367 | 1367 | return $this->sieve->getVacation(); |
1368 | 1368 | } |
@@ -1382,7 +1382,7 @@ discard block |
||
1382 | 1382 | */ |
1383 | 1383 | public static function init_static() |
1384 | 1384 | { |
1385 | - self::$supports_keywords =& Api\Cache::getSession (__CLASS__, 'supports_keywords'); |
|
1385 | + self::$supports_keywords = & Api\Cache::getSession(__CLASS__, 'supports_keywords'); |
|
1386 | 1386 | } |
1387 | 1387 | } |
1388 | 1388 | Imap::init_static(); |
@@ -156,7 +156,10 @@ discard block |
||
156 | 156 | $this->loginType = $this->params['acc_imap_logintype']; |
157 | 157 | $this->domainName = $this->params['acc_domain']; |
158 | 158 | |
159 | - if (is_null($_timeout)) $_timeout = $this->params['acc_imap_timeout']?$this->params['acc_imap_timeout']:self::getTimeOut (); |
|
159 | + if (is_null($_timeout)) |
|
160 | + { |
|
161 | + $_timeout = $this->params['acc_imap_timeout']?$this->params['acc_imap_timeout']:self::getTimeOut (); |
|
162 | + } |
|
160 | 163 | |
161 | 164 | // Horde use locale for translation of error messages |
162 | 165 | Api\Preferences::setlocale(LC_MESSAGES); |
@@ -167,7 +170,10 @@ discard block |
||
167 | 170 | { |
168 | 171 | $username = $this->getMailBoxUserName($username); |
169 | 172 | } |
170 | - if ($_adminConnection) $this->adminConnection($username); |
|
173 | + if ($_adminConnection) |
|
174 | + { |
|
175 | + $this->adminConnection($username); |
|
176 | + } |
|
171 | 177 | $parent_params = array( |
172 | 178 | 'username' => $this->params[$_adminConnection ? 'acc_imap_admin_username' : 'acc_imap_username'], |
173 | 179 | 'password' => $this->params[$_adminConnection ? 'acc_imap_admin_password' : 'acc_imap_password'], |
@@ -303,7 +309,11 @@ discard block |
||
303 | 309 | static function getTimeOut($_use='IMAP') |
304 | 310 | { |
305 | 311 | $timeout = $GLOBALS['egw_info']['user']['preferences']['mail']['connectionTimeout']; |
306 | - if (empty($timeout) || !($timeout > 0)) $timeout = $_use == 'SIEVE' ? 10 : 20; // this is the default value |
|
312 | + if (empty($timeout) || !($timeout > 0)) |
|
313 | + { |
|
314 | + $timeout = $_use == 'SIEVE' ? 10 : 20; |
|
315 | + } |
|
316 | + // this is the default value |
|
307 | 317 | return $timeout; |
308 | 318 | } |
309 | 319 | |
@@ -366,7 +376,8 @@ discard block |
||
366 | 376 | */ |
367 | 377 | function encodeFolderName($_folderName) |
368 | 378 | { |
369 | - if($this->mbAvailable) { |
|
379 | + if($this->mbAvailable) |
|
380 | + { |
|
370 | 381 | return mb_convert_encoding($_folderName, "UTF7-IMAP", Api\Translation::charset()); |
371 | 382 | } |
372 | 383 | |
@@ -384,14 +395,21 @@ discard block |
||
384 | 395 | function getMailbox($mailbox) |
385 | 396 | { |
386 | 397 | $mailboxes = $this->listMailboxes($mailbox,Horde_Imap_Client::MBOX_ALL); |
387 | - if (empty($mailboxes)) $mailboxes = $this->listMailboxes($mailbox,Horde_Imap_Client::MBOX_UNSUBSCRIBED); |
|
398 | + if (empty($mailboxes)) |
|
399 | + { |
|
400 | + $mailboxes = $this->listMailboxes($mailbox,Horde_Imap_Client::MBOX_UNSUBSCRIBED); |
|
401 | + } |
|
388 | 402 | //error_log(__METHOD__.__LINE__.'->'.$mailbox.'/'.array2string($mailboxes)); |
389 | 403 | $mboxes = new Horde_Imap_Client_Mailbox_List($mailboxes); |
390 | 404 | //_debug_array($mboxes->count()); |
391 | 405 | foreach ($mboxes->getIterator() as $k =>$box) |
392 | 406 | { |
393 | 407 | //error_log(__METHOD__.__LINE__.'->'.$k); |
394 | - if ($k!='user' && $k != '' && $k==$mailbox) return $box['mailbox']; //_debug_array(array($k => $client->status($k))); |
|
408 | + if ($k!='user' && $k != '' && $k==$mailbox) |
|
409 | + { |
|
410 | + return $box['mailbox']; |
|
411 | + } |
|
412 | + //_debug_array(array($k => $client->status($k))); |
|
395 | 413 | } |
396 | 414 | return ($this->mailboxExist($mailbox)?$mailbox:false); |
397 | 415 | } |
@@ -460,8 +478,14 @@ discard block |
||
460 | 478 | //throw new egw_exception(__METHOD__.' ('.__LINE__.") failed to ".__METHOD__." :".$e->getMessage()); |
461 | 479 | unset($e); |
462 | 480 | } |
463 | - if (!empty($mailbox)) return $mailbox['mailbox']; |
|
464 | - if (empty($mailbox) && $this->mailboxExist('INBOX')) return 'INBOX'; |
|
481 | + if (!empty($mailbox)) |
|
482 | + { |
|
483 | + return $mailbox['mailbox']; |
|
484 | + } |
|
485 | + if (empty($mailbox) && $this->mailboxExist('INBOX')) |
|
486 | + { |
|
487 | + return 'INBOX'; |
|
488 | + } |
|
465 | 489 | return null; |
466 | 490 | } |
467 | 491 | |
@@ -531,7 +555,10 @@ discard block |
||
531 | 555 | )); |
532 | 556 | |
533 | 557 | $flags = Horde_Imap_Client::STATUS_ALL; |
534 | - if ($ignoreStatusCache) $flags |= Horde_Imap_Client::STATUS_FORCE_REFRESH; |
|
558 | + if ($ignoreStatusCache) |
|
559 | + { |
|
560 | + $flags |= Horde_Imap_Client::STATUS_FORCE_REFRESH; |
|
561 | + } |
|
535 | 562 | |
536 | 563 | $mboxes = new Horde_Imap_Client_Mailbox_List($mailboxes); |
537 | 564 | //error_log(__METHOD__.__LINE__.array2string($mboxes->count())); |
@@ -574,12 +601,15 @@ discard block |
||
574 | 601 | */ |
575 | 602 | function getMailboxes($reference = '' , $restriction_search = 0, $returnAttributes = false) |
576 | 603 | { |
577 | - if ( is_bool($restriction_search) ){ |
|
604 | + if ( is_bool($restriction_search) ) |
|
605 | + { |
|
578 | 606 | $restriction_search = (int) $restriction_search; |
579 | 607 | } |
580 | 608 | $mailbox = ''; |
581 | - if ( is_int( $restriction_search ) ){ |
|
582 | - switch ( $restriction_search ) { |
|
609 | + if ( is_int( $restriction_search ) ) |
|
610 | + { |
|
611 | + switch ( $restriction_search ) |
|
612 | + { |
|
583 | 613 | case 0: |
584 | 614 | $searchstring = $reference."*"; |
585 | 615 | break; |
@@ -591,8 +621,11 @@ discard block |
||
591 | 621 | $searchstring = $reference."%"; |
592 | 622 | break; |
593 | 623 | } |
594 | - }else{ |
|
595 | - if ( is_string( $restriction_search ) ){ |
|
624 | + } |
|
625 | + else |
|
626 | + { |
|
627 | + if ( is_string( $restriction_search ) ) |
|
628 | + { |
|
596 | 629 | $mailbox = $searchstring = $restriction_search; |
597 | 630 | } |
598 | 631 | } |
@@ -658,12 +691,15 @@ discard block |
||
658 | 691 | */ |
659 | 692 | function listSubscribedMailboxes($reference = '' , $restriction_search = 0, $returnAttributes = false) |
660 | 693 | { |
661 | - if ( is_bool($restriction_search) ){ |
|
694 | + if ( is_bool($restriction_search) ) |
|
695 | + { |
|
662 | 696 | $restriction_search = (int) $restriction_search; |
663 | 697 | } |
664 | 698 | $mailbox = ''; |
665 | - if ( is_int( $restriction_search ) ){ |
|
666 | - switch ( $restriction_search ) { |
|
699 | + if ( is_int( $restriction_search ) ) |
|
700 | + { |
|
701 | + switch ( $restriction_search ) |
|
702 | + { |
|
667 | 703 | case 0: |
668 | 704 | $searchstring = $reference."*"; |
669 | 705 | break; |
@@ -675,8 +711,11 @@ discard block |
||
675 | 711 | $searchstring = $reference."%"; |
676 | 712 | break; |
677 | 713 | } |
678 | - }else{ |
|
679 | - if ( is_string( $restriction_search ) ){ |
|
714 | + } |
|
715 | + else |
|
716 | + { |
|
717 | + if ( is_string( $restriction_search ) ) |
|
718 | + { |
|
680 | 719 | $mailbox = $searchstring = $restriction_search; |
681 | 720 | } |
682 | 721 | } |
@@ -724,12 +763,15 @@ discard block |
||
724 | 763 | */ |
725 | 764 | function listUnSubscribedMailboxes($reference = '' , $restriction_search = 0) |
726 | 765 | { |
727 | - if ( is_bool($restriction_search) ){ |
|
766 | + if ( is_bool($restriction_search) ) |
|
767 | + { |
|
728 | 768 | $restriction_search = (int) $restriction_search; |
729 | 769 | } |
730 | 770 | |
731 | - if ( is_int( $restriction_search ) ){ |
|
732 | - switch ( $restriction_search ) { |
|
771 | + if ( is_int( $restriction_search ) ) |
|
772 | + { |
|
773 | + switch ( $restriction_search ) |
|
774 | + { |
|
733 | 775 | case 0: |
734 | 776 | $mailbox = $reference."*"; |
735 | 777 | break; |
@@ -741,8 +783,11 @@ discard block |
||
741 | 783 | $mailbox = "%"; |
742 | 784 | break; |
743 | 785 | } |
744 | - }else{ |
|
745 | - if ( is_string( $restriction_search ) ){ |
|
786 | + } |
|
787 | + else |
|
788 | + { |
|
789 | + if ( is_string( $restriction_search ) ) |
|
790 | + { |
|
746 | 791 | $mailbox = $restriction_search; |
747 | 792 | } |
748 | 793 | } |
@@ -761,7 +806,10 @@ discard block |
||
761 | 806 | foreach ($unsubscribed as $box) |
762 | 807 | { |
763 | 808 | //error_log(__METHOD__.__LINE__.' Box:'.$k.'->'.array2string($box['mailbox']->utf8)); |
764 | - if (!in_array($box['mailbox']->utf8,$sret) && $box['mailbox']->utf8!='INBOX') $ret[]=$box['mailbox']->utf8; |
|
809 | + if (!in_array($box['mailbox']->utf8,$sret) && $box['mailbox']->utf8!='INBOX') |
|
810 | + { |
|
811 | + $ret[]=$box['mailbox']->utf8; |
|
812 | + } |
|
765 | 813 | } |
766 | 814 | return $ret; |
767 | 815 | } |
@@ -775,10 +823,16 @@ discard block |
||
775 | 823 | */ |
776 | 824 | function examineMailbox($mailbox, $flags=null) |
777 | 825 | { |
778 | - if ($mailbox=='') return false; |
|
826 | + if ($mailbox=='') |
|
827 | + { |
|
828 | + return false; |
|
829 | + } |
|
779 | 830 | $mailboxes = $this->listMailboxes($mailbox); |
780 | 831 | |
781 | - if (is_null($flags)) $flags = Horde_Imap_Client::STATUS_ALL | Horde_Imap_Client::STATUS_FLAGS | Horde_Imap_Client::STATUS_PERMFLAGS; |
|
832 | + if (is_null($flags)) |
|
833 | + { |
|
834 | + $flags = Horde_Imap_Client::STATUS_ALL | Horde_Imap_Client::STATUS_FLAGS | Horde_Imap_Client::STATUS_PERMFLAGS; |
|
835 | + } |
|
782 | 836 | |
783 | 837 | $mboxes = new Horde_Imap_Client_Mailbox_List($mailboxes); |
784 | 838 | //_debug_array($mboxes->count()); |
@@ -860,7 +914,10 @@ discard block |
||
860 | 914 | } |
861 | 915 | catch (\Exception $e) |
862 | 916 | { |
863 | - if ($this->debug) error_log(__METHOD__.__LINE__.' error querying for capability:'.$capability.' ->'.$e->getMessage()); |
|
917 | + if ($this->debug) |
|
918 | + { |
|
919 | + error_log(__METHOD__.__LINE__.' error querying for capability:'.$capability.' ->'.$e->getMessage()); |
|
920 | + } |
|
864 | 921 | return false; |
865 | 922 | } |
866 | 923 | if (!is_array($cap)) |
@@ -900,7 +957,10 @@ discard block |
||
900 | 957 | { |
901 | 958 | foreach($_nameSpace as &$singleNameSpace) |
902 | 959 | { |
903 | - if (substr($_folderName,0,strlen($singleNameSpace['prefix'])) == $singleNameSpace['prefix']) return $singleNameSpace['prefix']; |
|
960 | + if (substr($_folderName,0,strlen($singleNameSpace['prefix'])) == $singleNameSpace['prefix']) |
|
961 | + { |
|
962 | + return $singleNameSpace['prefix']; |
|
963 | + } |
|
904 | 964 | } |
905 | 965 | return ""; |
906 | 966 | } |
@@ -917,7 +977,8 @@ discard block |
||
917 | 977 | */ |
918 | 978 | function getMailBoxesRecursive($_mailbox, $delimiter, $prefix, $reclevel=0) |
919 | 979 | { |
920 | - if ($reclevel > 25) { |
|
980 | + if ($reclevel > 25) |
|
981 | + { |
|
921 | 982 | error_log( __METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter "); |
922 | 983 | return array(); |
923 | 984 | } |
@@ -933,7 +994,8 @@ discard block |
||
933 | 994 | { |
934 | 995 | $buff = $this->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'].($mbx[$mbxkeys[0]]['MAILBOX'] == $prefix ? '':$delimiter),2,false); |
935 | 996 | $allMailboxes = array(); |
936 | - foreach ($buff as $mbxname) { |
|
997 | + foreach ($buff as $mbxname) |
|
998 | + { |
|
937 | 999 | $mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$mbxname['MAILBOX']); |
938 | 1000 | #echo "About to recur in level $reclevel:".$mbxname."<br>"; |
939 | 1001 | if ( $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'] && $mbxname != $prefix && $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'].$delimiter) |
@@ -941,7 +1003,10 @@ discard block |
||
941 | 1003 | $allMailboxes = array_merge($allMailboxes, self::getMailBoxesRecursive($mbxname, $delimiter, $prefix, $reclevel)); |
942 | 1004 | } |
943 | 1005 | } |
944 | - if (!(in_array('\NoSelect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]))) $allMailboxes[] = $mbx[$mbxkeys[0]]['MAILBOX']; |
|
1006 | + if (!(in_array('\NoSelect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]))) |
|
1007 | + { |
|
1008 | + $allMailboxes[] = $mbx[$mbxkeys[0]]['MAILBOX']; |
|
1009 | + } |
|
945 | 1010 | return $allMailboxes; |
946 | 1011 | } |
947 | 1012 | else |
@@ -963,9 +1028,16 @@ discard block |
||
963 | 1028 | static $nameSpace=null; |
964 | 1029 | $foldersNameSpace = array(); |
965 | 1030 | $delimiter = $this->getDelimiter(); |
966 | - if (empty($delimiter)) $delimiter='/'; |
|
967 | - if (is_null($nameSpace)) $nameSpace = $this->getNameSpaceArray(); |
|
968 | - if (is_array($nameSpace)) { |
|
1031 | + if (empty($delimiter)) |
|
1032 | + { |
|
1033 | + $delimiter='/'; |
|
1034 | + } |
|
1035 | + if (is_null($nameSpace)) |
|
1036 | + { |
|
1037 | + $nameSpace = $this->getNameSpaceArray(); |
|
1038 | + } |
|
1039 | + if (is_array($nameSpace)) |
|
1040 | + { |
|
969 | 1041 | foreach($nameSpace as $type => $singleNameSpaceArray) |
970 | 1042 | { |
971 | 1043 | foreach ($singleNameSpaceArray as $singleNameSpace) |
@@ -982,7 +1054,9 @@ discard block |
||
982 | 1054 | $_foldersNameSpace['prefix_present'] = 'forced'; |
983 | 1055 | // uw-imap server with mailbox prefix or dovecot maybe |
984 | 1056 | $_foldersNameSpace['prefix'] = 'mail'; |
985 | - } else { |
|
1057 | + } |
|
1058 | + else |
|
1059 | + { |
|
986 | 1060 | $_foldersNameSpace['prefix_present'] = !empty($singleNameSpace['name']); |
987 | 1061 | $_foldersNameSpace['prefix'] = $singleNameSpace['name']; |
988 | 1062 | } |
@@ -1022,7 +1096,10 @@ discard block |
||
1022 | 1096 | $namespaces = $this->getNamespaces(); |
1023 | 1097 | foreach ($namespaces as $nsp) |
1024 | 1098 | { |
1025 | - if ($nsp['type']==$type && $nsp['delimiter']) return $nsp['delimiter']; |
|
1099 | + if ($nsp['type']==$type && $nsp['delimiter']) |
|
1100 | + { |
|
1101 | + return $nsp['delimiter']; |
|
1102 | + } |
|
1026 | 1103 | } |
1027 | 1104 | return "/"; |
1028 | 1105 | } |
@@ -1131,12 +1208,14 @@ discard block |
||
1131 | 1208 | { |
1132 | 1209 | $nameSpaces = $this->getNameSpaceArray(); |
1133 | 1210 | |
1134 | - if(!isset($nameSpaces['others'])) { |
|
1211 | + if(!isset($nameSpaces['others'])) |
|
1212 | + { |
|
1135 | 1213 | return false; |
1136 | 1214 | } |
1137 | 1215 | |
1138 | 1216 | $username = $this->getMailBoxUserName($_username); |
1139 | - if($this->loginType == 'vmailmgr' || $this->loginType == 'email' || $this->loginType == 'uidNumber') { |
|
1217 | + if($this->loginType == 'vmailmgr' || $this->loginType == 'email' || $this->loginType == 'uidNumber') |
|
1218 | + { |
|
1140 | 1219 | $username .= '@'. $this->domainName; |
1141 | 1220 | } |
1142 | 1221 | |
@@ -1288,7 +1367,10 @@ discard block |
||
1288 | 1367 | */ |
1289 | 1368 | public function __call($name,array $params=null) |
1290 | 1369 | { |
1291 | - if ($this->debug) error_log(__METHOD__.'->'.$name.' with params:'.array2string($params)); |
|
1370 | + if ($this->debug) |
|
1371 | + { |
|
1372 | + error_log(__METHOD__.'->'.$name.' with params:'.array2string($params)); |
|
1373 | + } |
|
1292 | 1374 | switch($name) |
1293 | 1375 | { |
1294 | 1376 | case 'installScript': |
@@ -1323,7 +1405,10 @@ discard block |
||
1323 | 1405 | */ |
1324 | 1406 | public function setVacationUser($_euser, array $_vacation, $_scriptName=null) |
1325 | 1407 | { |
1326 | - if ($this->debug) error_log(__METHOD__.' User:'.array2string($_euser).' Scriptname:'.array2string($_scriptName).' VacationMessage:'.array2string($_vacation)); |
|
1408 | + if ($this->debug) |
|
1409 | + { |
|
1410 | + error_log(__METHOD__.' User:'.array2string($_euser).' Scriptname:'.array2string($_scriptName).' VacationMessage:'.array2string($_vacation)); |
|
1411 | + } |
|
1327 | 1412 | |
1328 | 1413 | if (is_numeric($_euser)) |
1329 | 1414 | { |
@@ -1351,7 +1436,10 @@ discard block |
||
1351 | 1436 | */ |
1352 | 1437 | public function getVacationUser($_euser, $_scriptName=null) |
1353 | 1438 | { |
1354 | - if ($this->debug) error_log(__METHOD__.' User:'.array2string($_euser)); |
|
1439 | + if ($this->debug) |
|
1440 | + { |
|
1441 | + error_log(__METHOD__.' User:'.array2string($_euser)); |
|
1442 | + } |
|
1355 | 1443 | |
1356 | 1444 | if (is_numeric($_euser)) |
1357 | 1445 | { |
@@ -121,6 +121,7 @@ |
||
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 |
@@ -14,9 +14,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -82,7 +82,7 @@ discard block |
||
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 |
||
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 | { |
@@ -37,28 +37,28 @@ discard block |
||
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 |
||
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; |
@@ -84,7 +84,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -104,21 +104,30 @@ discard block |
||
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 |
||
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 | } |
@@ -156,7 +156,7 @@ |
||
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") |
@@ -79,7 +79,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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': |
@@ -235,8 +235,14 @@ discard block |
||
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 |
||
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 |
@@ -628,7 +628,7 @@ |
||
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 | { |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @param string $defaultDomain =null |
159 | 159 | */ |
160 | - function __construct($defaultDomain=null) |
|
160 | + function __construct($defaultDomain = null) |
|
161 | 161 | { |
162 | 162 | parent::__construct($defaultDomain); |
163 | 163 | |
@@ -205,9 +205,8 @@ discard block |
||
205 | 205 | */ |
206 | 206 | function addAccount($_hookValues) |
207 | 207 | { |
208 | - $mailLocalAddress = $_hookValues['account_email'] ? $_hookValues['account_email'] : |
|
209 | - Api\Accounts::email($_hookValues['account_firstname'], |
|
210 | - $_hookValues['account_lastname'],$_hookValues['account_lid'],$this->defaultDomain); |
|
208 | + $mailLocalAddress = $_hookValues['account_email'] ? $_hookValues['account_email'] : Api\Accounts::email($_hookValues['account_firstname'], |
|
209 | + $_hookValues['account_lastname'], $_hookValues['account_lid'], $this->defaultDomain); |
|
211 | 210 | |
212 | 211 | $ds = $this->getLdapConnection(); |
213 | 212 | |
@@ -219,13 +218,13 @@ discard block |
||
219 | 218 | } |
220 | 219 | $allValues = ldap_get_entries($ds, $sri); |
221 | 220 | $accountDN = $allValues[0]['dn']; |
222 | - $objectClasses = $allValues[0]['objectclass']; |
|
221 | + $objectClasses = $allValues[0]['objectclass']; |
|
223 | 222 | unset($objectClasses['count']); |
224 | 223 | |
225 | 224 | // add our mail schema, if not already set |
226 | - if(!in_array(static::SCHEMA,$objectClasses) && !in_array(strtolower(static::SCHEMA),$objectClasses)) |
|
225 | + if (!in_array(static::SCHEMA, $objectClasses) && !in_array(strtolower(static::SCHEMA), $objectClasses)) |
|
227 | 226 | { |
228 | - $objectClasses[] = static::SCHEMA; |
|
227 | + $objectClasses[] = static::SCHEMA; |
|
229 | 228 | } |
230 | 229 | // the new code for postfix+cyrus+ldap |
231 | 230 | $newData = array( |
@@ -256,7 +255,7 @@ discard block |
||
256 | 255 | { |
257 | 256 | error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'$accountDN',". |
258 | 257 | array2string($newData).') returning '.array2string($ret). |
259 | - (!$ret?' ('.ldap_error($ds).')':'')); |
|
258 | + (!$ret ? ' ('.ldap_error($ds).')' : '')); |
|
260 | 259 | } |
261 | 260 | return $ret; |
262 | 261 | } |
@@ -270,7 +269,7 @@ discard block |
||
270 | 269 | */ |
271 | 270 | function addAccountExtra(array $_hookValues, array $allValues, array &$newData) |
272 | 271 | { |
273 | - unset($_hookValues, $allValues, $newData); // not used, but required by function signature |
|
272 | + unset($_hookValues, $allValues, $newData); // not used, but required by function signature |
|
274 | 273 | } |
275 | 274 | |
276 | 275 | /** |
@@ -281,24 +280,24 @@ discard block |
||
281 | 280 | */ |
282 | 281 | function getAccountEmailAddress($_accountName) |
283 | 282 | { |
284 | - $emailAddresses = array(); |
|
283 | + $emailAddresses = array(); |
|
285 | 284 | $ds = $this->getLdapConnection(); |
286 | 285 | $filter = '(&'.static::USER_FILTER.'('.static::USER_ATTR.'='.Api\Ldap::quote($_accountName).'))'; |
287 | - $attributes = array('dn', static::MAIL_ATTR, static::ALIAS_ATTR); |
|
286 | + $attributes = array('dn', static::MAIL_ATTR, static::ALIAS_ATTR); |
|
288 | 287 | $sri = @ldap_search($ds, $this->search_base, $filter, $attributes); |
289 | 288 | |
290 | 289 | if ($sri) |
291 | 290 | { |
292 | - $realName = trim($GLOBALS['egw_info']['user']['account_firstname'] . (!empty($GLOBALS['egw_info']['user']['account_firstname']) ? ' ' : '') . $GLOBALS['egw_info']['user']['account_lastname']); |
|
291 | + $realName = trim($GLOBALS['egw_info']['user']['account_firstname'].(!empty($GLOBALS['egw_info']['user']['account_firstname']) ? ' ' : '').$GLOBALS['egw_info']['user']['account_lastname']); |
|
293 | 292 | $allValues = ldap_get_entries($ds, $sri); |
294 | 293 | |
295 | - if(isset($allValues[0][static::MAIL_ATTR])) |
|
294 | + if (isset($allValues[0][static::MAIL_ATTR])) |
|
296 | 295 | { |
297 | - foreach($allValues[0][static::MAIL_ATTR] as $key => $value) |
|
296 | + foreach ($allValues[0][static::MAIL_ATTR] as $key => $value) |
|
298 | 297 | { |
299 | 298 | if ($key === 'count') continue; |
300 | 299 | |
301 | - $emailAddresses[] = array ( |
|
300 | + $emailAddresses[] = array( |
|
302 | 301 | 'name' => $realName, |
303 | 302 | 'address' => $value, |
304 | 303 | 'type' => !$key ? 'default' : 'alternate', |
@@ -307,7 +306,7 @@ discard block |
||
307 | 306 | } |
308 | 307 | if (static::ALIAS_ATTR && isset($allValues[0][static::ALIAS_ATTR])) |
309 | 308 | { |
310 | - foreach(self::getAttributePrefix($allValues[0][static::ALIAS_ATTR], static::ALIAS_PREFIX) as $value) |
|
309 | + foreach (self::getAttributePrefix($allValues[0][static::ALIAS_ATTR], static::ALIAS_PREFIX) as $value) |
|
311 | 310 | { |
312 | 311 | $emailAddresses[] = array( |
313 | 312 | 'name' => $realName, |
@@ -334,7 +333,7 @@ discard block |
||
334 | 333 | * @return array with values for keys 'mailLocalAddress', 'mailAlternateAddress' (array), 'mailForwardingAddress' (array), |
335 | 334 | * 'accountStatus' ("active"), 'quotaLimit' and 'deliveryMode' ("forwardOnly") |
336 | 335 | */ |
337 | - function getUserData($user, $match_uid_at_domain=false) |
|
336 | + function getUserData($user, $match_uid_at_domain = false) |
|
338 | 337 | { |
339 | 338 | $userData = array( |
340 | 339 | 'mailbox' => array(), |
@@ -394,7 +393,7 @@ discard block |
||
394 | 393 | $allValues = ldap_get_entries($ldap, $sri); |
395 | 394 | if ($this->debug) error_log(__METHOD__."('$user') --> ldap_search(, '$this->search_base', '$filter') --> ldap_get_entries=".array2string($allValues[0])); |
396 | 395 | |
397 | - foreach($allValues as $key => $values) |
|
396 | + foreach ($allValues as $key => $values) |
|
398 | 397 | { |
399 | 398 | if ($key === 'count') continue; |
400 | 399 | |
@@ -477,16 +476,16 @@ discard block |
||
477 | 476 | |
478 | 477 | if (static::FORWARD_ATTR) |
479 | 478 | { |
480 | - $userData['mailForwardingAddress'] = self::getAttributePrefix($values[static::FORWARD_ATTR], static::FORWARD_PREFIX); |
|
479 | + $userData['mailForwardingAddress'] = self::getAttributePrefix($values[static::FORWARD_ATTR], static::FORWARD_PREFIX); |
|
481 | 480 | } |
482 | 481 | |
483 | - if (static::MAILBOX_ATTR) $userData['mailMessageStore'] = $values[static::MAILBOX_ATTR][0]; |
|
482 | + if (static::MAILBOX_ATTR) $userData['mailMessageStore'] = $values[static::MAILBOX_ATTR][0]; |
|
484 | 483 | |
485 | 484 | $userData['deliveryMode'] = $deliveryMode; |
486 | 485 | |
487 | 486 | // eg. suse stores all email addresses as aliases |
488 | 487 | if (static::REQUIRE_MAIL_AS_ALIAS && |
489 | - ($k = array_search($userData['mailLocalAddress'],$userData['mailAlternateAddress'])) !== false) |
|
488 | + ($k = array_search($userData['mailLocalAddress'], $userData['mailAlternateAddress'])) !== false) |
|
490 | 489 | { |
491 | 490 | unset($userData['mailAlternateAddress'][$k]); |
492 | 491 | } |
@@ -519,9 +518,9 @@ discard block |
||
519 | 518 | * @return boolean true on success, false on error writing to ldap |
520 | 519 | */ |
521 | 520 | function setUserData($_uidnumber, array $_mailAlternateAddress, array $_mailForwardingAddress, $_deliveryMode, |
522 | - $_accountStatus, $_mailLocalAddress, $_quota, $_forwarding_only=false, $_setMailbox=null) |
|
521 | + $_accountStatus, $_mailLocalAddress, $_quota, $_forwarding_only = false, $_setMailbox = null) |
|
523 | 522 | { |
524 | - unset($_forwarding_only); // not used |
|
523 | + unset($_forwarding_only); // not used |
|
525 | 524 | |
526 | 525 | if (static::USERID_ATTR) |
527 | 526 | { |
@@ -541,15 +540,15 @@ discard block |
||
541 | 540 | $allValues = ldap_get_entries($ldap, $sri); |
542 | 541 | |
543 | 542 | $accountDN = $allValues[0]['dn']; |
544 | - $uid = $allValues[0][static::USER_ATTR][0]; |
|
545 | - $objectClasses = $allValues[0]['objectclass']; |
|
543 | + $uid = $allValues[0][static::USER_ATTR][0]; |
|
544 | + $objectClasses = $allValues[0]['objectclass']; |
|
546 | 545 | |
547 | 546 | unset($objectClasses['count']); |
548 | 547 | |
549 | - if(!in_array(static::SCHEMA,$objectClasses) && !in_array(strtolower(static::SCHEMA),$objectClasses)) |
|
548 | + if (!in_array(static::SCHEMA, $objectClasses) && !in_array(strtolower(static::SCHEMA), $objectClasses)) |
|
550 | 549 | { |
551 | - $objectClasses[] = static::SCHEMA; |
|
552 | - $newData['objectclass'] = $objectClasses; |
|
550 | + $objectClasses[] = static::SCHEMA; |
|
551 | + $newData['objectclass'] = $objectClasses; |
|
553 | 552 | } |
554 | 553 | |
555 | 554 | sort($_mailAlternateAddress); |
@@ -562,7 +561,7 @@ discard block |
||
562 | 561 | self::setAttributePrefix($newData[static::ALIAS_ATTR], $_mailAlternateAddress, static::ALIAS_PREFIX); |
563 | 562 | |
564 | 563 | // all email must be stored as alias for suse |
565 | - if (static::REQUIRE_MAIL_AS_ALIAS && !in_array($_mailLocalAddress,(array)$_mailAlternateAddress)) |
|
564 | + if (static::REQUIRE_MAIL_AS_ALIAS && !in_array($_mailLocalAddress, (array)$_mailAlternateAddress)) |
|
566 | 565 | { |
567 | 566 | self::setAttributePrefix($newData[static::ALIAS_ATTR], $_mailLocalAddress, static::ALIAS_PREFIX); |
568 | 567 | } |
@@ -595,12 +594,12 @@ discard block |
||
595 | 594 | if (static::QUOTA_ATTR) |
596 | 595 | { |
597 | 596 | self::setAttributePrefix($newData[static::QUOTA_ATTR], |
598 | - (int)$_quota > 0 ? (int)$_quota*static::QUOTA_FACTOR : array(), static::QUOTA_PREFIX); |
|
597 | + (int)$_quota > 0 ? (int)$_quota * static::QUOTA_FACTOR : array(), static::QUOTA_PREFIX); |
|
599 | 598 | } |
600 | 599 | // does schema support enabling/disabling mail via attribute |
601 | 600 | if (static::MAIL_ENABLE_ATTR) |
602 | 601 | { |
603 | - $newData[static::MAIL_ENABLE_ATTR] = $_accountStatus ? |
|
602 | + $newData[static::MAIL_ENABLE_ATTR] = $_accountStatus ? |
|
604 | 603 | (static::MAIL_ENABLED == self::MAIL_ENABLED_USE_MAIL ? $_mailLocalAddress : static::MAIL_ENABLED) : array(); |
605 | 604 | } |
606 | 605 | // if we have no mail-enabled attribute, but require primary mail in aliases-attr |
@@ -642,7 +641,7 @@ discard block |
||
642 | 641 | $uid = $GLOBALS['egw']->accounts->id2name($_accountID); |
643 | 642 | $filter = '(&'.static::USER_FILTER.'('.static::USER_ATTR.'='.Api\Ldap::quote($uid).'))'; |
644 | 643 | } |
645 | - $attributes = array('dn', static::FORWARD_ATTR, 'objectclass'); |
|
644 | + $attributes = array('dn', static::FORWARD_ATTR, 'objectclass'); |
|
646 | 645 | if (static::FORWARD_ONLY_ATTR) |
647 | 646 | { |
648 | 647 | $attributes[] = static::FORWARD_ONLY_ATTR; |
@@ -653,12 +652,12 @@ discard block |
||
653 | 652 | { |
654 | 653 | $newData = array(); |
655 | 654 | $allValues = ldap_get_entries($ds, $sri); |
656 | - $objectClasses = $allValues[0]['objectclass']; |
|
657 | - $newData['objectclass'] = $allValues[0]['objectclass']; |
|
655 | + $objectClasses = $allValues[0]['objectclass']; |
|
656 | + $newData['objectclass'] = $allValues[0]['objectclass']; |
|
658 | 657 | |
659 | 658 | unset($newData['objectclass']['count']); |
660 | 659 | |
661 | - if(!in_array(static::SCHEMA,$objectClasses)) |
|
660 | + if (!in_array(static::SCHEMA, $objectClasses)) |
|
662 | 661 | { |
663 | 662 | $newData['objectclass'][] = static::SCHEMA; |
664 | 663 | } |
@@ -668,9 +667,9 @@ discard block |
||
668 | 667 | $newData[static::FORWARD_ATTR] = $allValues[0][static::FORWARD_ATTR]; |
669 | 668 | $forwards = self::getAttributePrefix($newData[static::FORWARD_ATTR], static::FORWARD_PREFIX); |
670 | 669 | |
671 | - if(!empty($_forwardingAddress)) |
|
670 | + if (!empty($_forwardingAddress)) |
|
672 | 671 | { |
673 | - if($forwards) |
|
672 | + if ($forwards) |
|
674 | 673 | { |
675 | 674 | if (!is_array($_forwardingAddress)) |
676 | 675 | { |
@@ -702,7 +701,7 @@ discard block |
||
702 | 701 | } |
703 | 702 | if ($this->debug) error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'{$allValues[0]['dn']}',".array2string($newData).')'); |
704 | 703 | |
705 | - return ldap_modify ($ds, $allValues[0]['dn'], $newData); |
|
704 | + return ldap_modify($ds, $allValues[0]['dn'], $newData); |
|
706 | 705 | } |
707 | 706 | } |
708 | 707 | |
@@ -744,9 +743,9 @@ discard block |
||
744 | 743 | unset($entries['count']); |
745 | 744 | |
746 | 745 | $mailboxes = array(); |
747 | - foreach($entries as $entry) |
|
746 | + foreach ($entries as $entry) |
|
748 | 747 | { |
749 | - if ($entry[static::USER_ATTR][0] == 'anonymous') continue; // anonymous is never a mail-user! |
|
748 | + if ($entry[static::USER_ATTR][0] == 'anonymous') continue; // anonymous is never a mail-user! |
|
750 | 749 | list($mailbox) = explode('@', $entry[static::MAILBOX_ATTR ? static::MAILBOX_ATTR : static::MAIL_ATTR][0]); |
751 | 750 | $mailboxes[$entry[static::USER_ATTR][0]] = $mailbox; |
752 | 751 | } |
@@ -760,13 +759,13 @@ discard block |
||
760 | 759 | * @param string|array $values value(s) to set |
761 | 760 | * @param string $prefix ='' prefix to use or '' |
762 | 761 | */ |
763 | - protected static function setAttributePrefix(&$attribute, $values, $prefix='') |
|
762 | + protected static function setAttributePrefix(&$attribute, $values, $prefix = '') |
|
764 | 763 | { |
765 | 764 | //$attribute_in = $attribute; |
766 | 765 | if (empty($attribute)) $attribute = array(); |
767 | 766 | if (!is_array($attribute)) $attribute = (array)$attribute; |
768 | 767 | |
769 | - foreach((array)$values as $value) |
|
768 | + foreach ((array)$values as $value) |
|
770 | 769 | { |
771 | 770 | $attribute[] = $prefix.$value; |
772 | 771 | } |
@@ -781,7 +780,7 @@ discard block |
||
781 | 780 | * @param boolean $remove =true remove returned values from $attribute |
782 | 781 | * @return array with values (prefix removed) or array() if nothing found |
783 | 782 | */ |
784 | - protected static function getAttributePrefix(&$attribute, $prefix='', $remove=true) |
|
783 | + protected static function getAttributePrefix(&$attribute, $prefix = '', $remove = true) |
|
785 | 784 | { |
786 | 785 | //$attribute_in = $attribute; |
787 | 786 | $values = array(); |
@@ -790,7 +789,7 @@ discard block |
||
790 | 789 | { |
791 | 790 | unset($attribute['count']); |
792 | 791 | |
793 | - foreach($attribute as $key => $value) |
|
792 | + foreach ($attribute as $key => $value) |
|
794 | 793 | { |
795 | 794 | if (!$prefix || stripos($value, $prefix) === 0) |
796 | 795 | { |
@@ -296,7 +296,10 @@ discard block |
||
296 | 296 | { |
297 | 297 | foreach($allValues[0][static::MAIL_ATTR] as $key => $value) |
298 | 298 | { |
299 | - if ($key === 'count') continue; |
|
299 | + if ($key === 'count') |
|
300 | + { |
|
301 | + continue; |
|
302 | + } |
|
300 | 303 | |
301 | 304 | $emailAddresses[] = array ( |
302 | 305 | 'name' => $realName, |
@@ -317,7 +320,10 @@ discard block |
||
317 | 320 | } |
318 | 321 | } |
319 | 322 | } |
320 | - if ($this->debug) error_log(__METHOD__."('$_accountName') returning ".array2string($emailAddresses)); |
|
323 | + if ($this->debug) |
|
324 | + { |
|
325 | + error_log(__METHOD__."('$_accountName') returning ".array2string($emailAddresses)); |
|
326 | + } |
|
321 | 327 | |
322 | 328 | return $emailAddresses; |
323 | 329 | } |
@@ -350,7 +356,10 @@ discard block |
||
350 | 356 | } |
351 | 357 | elseif (strpos($user, '@') === false) |
352 | 358 | { |
353 | - if (is_numeric($user)) $user = $GLOBALS['egw']->accounts->id2name($user); |
|
359 | + if (is_numeric($user)) |
|
360 | + { |
|
361 | + $user = $GLOBALS['egw']->accounts->id2name($user); |
|
362 | + } |
|
354 | 363 | $filter = '(&'.static::USER_FILTER.'('.static::USER_ATTR.'='.Api\Ldap::quote($user).'))'; |
355 | 364 | } |
356 | 365 | else // email address --> build filter by attributes defined in config |
@@ -367,7 +376,10 @@ discard block |
||
367 | 376 | else |
368 | 377 | { |
369 | 378 | $to_or = array('('.static::MAIL_ATTR.'='.Api\Ldap::quote($user).')'); |
370 | - if ($match_uid_at_domain) $to_or[] = '('.static::USER_ATTR.'='.Api\Ldap::quote($namepart).')'; |
|
379 | + if ($match_uid_at_domain) |
|
380 | + { |
|
381 | + $to_or[] = '('.static::USER_ATTR.'='.Api\Ldap::quote($namepart).')'; |
|
382 | + } |
|
371 | 383 | if (static::ALIAS_ATTR) |
372 | 384 | { |
373 | 385 | $to_or[] = '('.static::ALIAS_ATTR.'='.static::ALIAS_PREFIX.Api\Ldap::quote($user).')'; |
@@ -392,11 +404,17 @@ discard block |
||
392 | 404 | if ($sri) |
393 | 405 | { |
394 | 406 | $allValues = ldap_get_entries($ldap, $sri); |
395 | - if ($this->debug) error_log(__METHOD__."('$user') --> ldap_search(, '$this->search_base', '$filter') --> ldap_get_entries=".array2string($allValues[0])); |
|
407 | + if ($this->debug) |
|
408 | + { |
|
409 | + error_log(__METHOD__."('$user') --> ldap_search(, '$this->search_base', '$filter') --> ldap_get_entries=".array2string($allValues[0])); |
|
410 | + } |
|
396 | 411 | |
397 | 412 | foreach($allValues as $key => $values) |
398 | 413 | { |
399 | - if ($key === 'count') continue; |
|
414 | + if ($key === 'count') |
|
415 | + { |
|
416 | + continue; |
|
417 | + } |
|
400 | 418 | |
401 | 419 | // groups are always active (if they have an email) and allways forwardOnly |
402 | 420 | if (in_array(static::GROUP_SCHEMA, $values['objectclass'])) |
@@ -421,11 +439,14 @@ discard block |
||
421 | 439 | } |
422 | 440 | if (static::FORWARD_ONLY_ATTR) |
423 | 441 | { |
424 | - if (static::FORWARD_ONLY) // check caseinsensitiv for existence of that value |
|
442 | + if (static::FORWARD_ONLY) |
|
443 | + { |
|
444 | + // check caseinsensitiv for existence of that value |
|
425 | 445 | { |
426 | 446 | $deliveryMode = self::getAttributePrefix($values[static::FORWARD_ONLY_ATTR], static::FORWARD_ONLY) ? |
427 | 447 | Mail\Smtp::FORWARD_ONLY : ''; |
428 | 448 | } |
449 | + } |
|
429 | 450 | else // check for existence of any value |
430 | 451 | { |
431 | 452 | $deliveryMode = $values[static::FORWARD_ONLY_ATTR]['count'] > 0 ? |
@@ -458,7 +479,10 @@ discard block |
||
458 | 479 | } |
459 | 480 | |
460 | 481 | // regular user-data can only be from users, NOT groups |
461 | - if (in_array(static::GROUP_SCHEMA, $values['objectclass'])) continue; |
|
482 | + if (in_array(static::GROUP_SCHEMA, $values['objectclass'])) |
|
483 | + { |
|
484 | + continue; |
|
485 | + } |
|
462 | 486 | |
463 | 487 | $userData['mailLocalAddress'] = $values[static::MAIL_ATTR][0]; |
464 | 488 | $userData['accountStatus'] = $accountStatus; |
@@ -480,7 +504,10 @@ discard block |
||
480 | 504 | $userData['mailForwardingAddress'] = self::getAttributePrefix($values[static::FORWARD_ATTR], static::FORWARD_PREFIX); |
481 | 505 | } |
482 | 506 | |
483 | - if (static::MAILBOX_ATTR) $userData['mailMessageStore'] = $values[static::MAILBOX_ATTR][0]; |
|
507 | + if (static::MAILBOX_ATTR) |
|
508 | + { |
|
509 | + $userData['mailMessageStore'] = $values[static::MAILBOX_ATTR][0]; |
|
510 | + } |
|
484 | 511 | |
485 | 512 | $userData['deliveryMode'] = $deliveryMode; |
486 | 513 | |
@@ -499,7 +526,10 @@ discard block |
||
499 | 526 | } |
500 | 527 | } |
501 | 528 | } |
502 | - if ($this->debug) error_log(__METHOD__."('$user') returning ".array2string($userData)); |
|
529 | + if ($this->debug) |
|
530 | + { |
|
531 | + error_log(__METHOD__."('$user') returning ".array2string($userData)); |
|
532 | + } |
|
503 | 533 | |
504 | 534 | return $userData; |
505 | 535 | } |
@@ -617,7 +647,10 @@ discard block |
||
617 | 647 | |
618 | 648 | $this->addAccountExtra(array('location' => 'setUserData'), $allValues[0], $newData); |
619 | 649 | |
620 | - if ($this->debug) error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'$accountDN',".array2string($newData).')'); |
|
650 | + if ($this->debug) |
|
651 | + { |
|
652 | + error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'$accountDN',".array2string($newData).')'); |
|
653 | + } |
|
621 | 654 | |
622 | 655 | return ldap_mod_replace($ldap, $accountDN, $newData); |
623 | 656 | } |
@@ -700,7 +733,10 @@ discard block |
||
700 | 733 | // merge in again all new set forwards incl. opt. prefix |
701 | 734 | self::setAttributePrefix($newData[static::FORWARD_ATTR], $forwards, static::FORWARD_PREFIX); |
702 | 735 | } |
703 | - if ($this->debug) error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'{$allValues[0]['dn']}',".array2string($newData).')'); |
|
736 | + if ($this->debug) |
|
737 | + { |
|
738 | + error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'{$allValues[0]['dn']}',".array2string($newData).')'); |
|
739 | + } |
|
704 | 740 | |
705 | 741 | return ldap_modify ($ds, $allValues[0]['dn'], $newData); |
706 | 742 | } |
@@ -746,7 +782,11 @@ discard block |
||
746 | 782 | $mailboxes = array(); |
747 | 783 | foreach($entries as $entry) |
748 | 784 | { |
749 | - if ($entry[static::USER_ATTR][0] == 'anonymous') continue; // anonymous is never a mail-user! |
|
785 | + if ($entry[static::USER_ATTR][0] == 'anonymous') |
|
786 | + { |
|
787 | + continue; |
|
788 | + } |
|
789 | + // anonymous is never a mail-user! |
|
750 | 790 | list($mailbox) = explode('@', $entry[static::MAILBOX_ATTR ? static::MAILBOX_ATTR : static::MAIL_ATTR][0]); |
751 | 791 | $mailboxes[$entry[static::USER_ATTR][0]] = $mailbox; |
752 | 792 | } |
@@ -763,8 +803,14 @@ discard block |
||
763 | 803 | protected static function setAttributePrefix(&$attribute, $values, $prefix='') |
764 | 804 | { |
765 | 805 | //$attribute_in = $attribute; |
766 | - if (empty($attribute)) $attribute = array(); |
|
767 | - if (!is_array($attribute)) $attribute = (array)$attribute; |
|
806 | + if (empty($attribute)) |
|
807 | + { |
|
808 | + $attribute = array(); |
|
809 | + } |
|
810 | + if (!is_array($attribute)) |
|
811 | + { |
|
812 | + $attribute = (array)$attribute; |
|
813 | + } |
|
768 | 814 | |
769 | 815 | foreach((array)$values as $value) |
770 | 816 | { |
@@ -794,12 +840,18 @@ discard block |
||
794 | 840 | { |
795 | 841 | if (!$prefix || stripos($value, $prefix) === 0) |
796 | 842 | { |
797 | - if ($remove) unset($attribute[$key]); |
|
843 | + if ($remove) |
|
844 | + { |
|
845 | + unset($attribute[$key]); |
|
846 | + } |
|
798 | 847 | $values[] = substr($value, strlen($prefix)); |
799 | 848 | } |
800 | 849 | } |
801 | 850 | // reindex $attribute, if neccessary |
802 | - if ($values && $attribute) $attribute = array_values($attribute); |
|
851 | + if ($values && $attribute) |
|
852 | + { |
|
853 | + $attribute = array_values($attribute); |
|
854 | + } |
|
803 | 855 | } |
804 | 856 | //error_log(__METHOD__."(".array2string($attribute_in).", '$prefix', $remove) attribute=".array2string($attribute).' returning '.array2string($values)); |
805 | 857 | return $values; |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | /** |
252 | 252 | * Add one or multiple addresses to Cc |
253 | 253 | * |
254 | - * @param string|array|Horde_Mail_Rfc822_List $address |
|
254 | + * @param string $address |
|
255 | 255 | * @param string $personal ='' only used if $address is a string |
256 | 256 | */ |
257 | 257 | function addCc($address, $personal=null) |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | /** |
271 | 271 | * Add one or multiple addresses to Bcc |
272 | 272 | * |
273 | - * @param string|array|Horde_Mail_Rfc822_List $address |
|
273 | + * @param string $address |
|
274 | 274 | * @param string $personal ='' only used if $address is a string |
275 | 275 | */ |
276 | 276 | function addBcc($address, $personal=null) |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | /** |
382 | 382 | * Adds an embedded image or other inline attachment |
383 | 383 | * |
384 | - * @param string|resource $data Path to the attachment or open file-descriptor |
|
384 | + * @param string $data Path to the attachment or open file-descriptor |
|
385 | 385 | * @param string $cid Content ID of the attachment. Use this to identify |
386 | 386 | * the Id for accessing the image in an HTML form. |
387 | 387 | * @param string $name Overrides the attachment name. |
@@ -481,10 +481,10 @@ discard block |
||
481 | 481 | * Log mails to log file specified in $GLOBALS['egw_info']['server']['log_mail'] |
482 | 482 | * or regular error_log for true (can be set either in DB or header.inc.php). |
483 | 483 | * |
484 | - * @param Horde_Mail_Transport $transport =null using transport from mail-account |
|
484 | + * @param Horde_Mail_Transport $transport =null using transport from mail-account |
|
485 | 485 | * specified in construct, or default one, if not specified |
486 | - * @param boolean $resend =true allways true in EGroupware! |
|
487 | - * @param boolean $flowed =null send message in flowed text format, |
|
486 | + * @param boolean $resend =true allways true in EGroupware! |
|
487 | + * @param boolean $flowed =null send message in flowed text format, |
|
488 | 488 | * default null used flowed by default for everything but multipart/encrypted, |
489 | 489 | * unless disabled in site configuration ("disable_rfc3676_flowed") |
490 | 490 | * |
@@ -642,15 +642,15 @@ discard block |
||
642 | 642 | } |
643 | 643 | |
644 | 644 | /** |
645 | - * Get the raw email data sent by this object. |
|
646 | - * |
|
645 | + * Get the raw email data sent by this object. |
|
646 | + * |
|
647 | 647 | * Reimplement to be able to call it for saveAsDraft by calling |
648 | 648 | * $this->send(new Horde_Mail_Transport_Null()), |
649 | 649 | * if no base-part is set, because send is not called before. |
650 | 650 | * |
651 | - * @param boolean $stream If true, return a stream resource, otherwise |
|
652 | - * @return stream|string The raw email data. |
|
653 | - */ |
|
651 | + * @param boolean $stream If true, return a stream resource, otherwise |
|
652 | + * @return stream|string The raw email data. |
|
653 | + */ |
|
654 | 654 | function getRaw($stream=true) |
655 | 655 | { |
656 | 656 | try { |
@@ -663,20 +663,20 @@ discard block |
||
663 | 663 | } |
664 | 664 | // code copied from Horde_Mime_Mail::getRaw(), as there is no way to inject charset in |
665 | 665 | // _headers->toString(), which is required to encode headers containing non-ascii chars correct |
666 | - if ($stream) { |
|
667 | - $hdr = new Horde_Stream(); |
|
668 | - $hdr->add($this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)), true); |
|
669 | - return Horde_Stream_Wrapper_Combine::getStream( |
|
670 | - array($hdr->stream, |
|
671 | - $this->getBasePart()->toString( |
|
672 | - array('stream' => true, 'canonical' => true, 'encode' => Horde_Mime_Part::ENCODE_7BIT | Horde_Mime_Part::ENCODE_8BIT | Horde_Mime_Part::ENCODE_BINARY)) |
|
673 | - ) |
|
674 | - ); |
|
675 | - } |
|
676 | - |
|
677 | - return $this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)) . |
|
666 | + if ($stream) { |
|
667 | + $hdr = new Horde_Stream(); |
|
668 | + $hdr->add($this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)), true); |
|
669 | + return Horde_Stream_Wrapper_Combine::getStream( |
|
670 | + array($hdr->stream, |
|
671 | + $this->getBasePart()->toString( |
|
672 | + array('stream' => true, 'canonical' => true, 'encode' => Horde_Mime_Part::ENCODE_7BIT | Horde_Mime_Part::ENCODE_8BIT | Horde_Mime_Part::ENCODE_BINARY)) |
|
673 | + ) |
|
674 | + ); |
|
675 | + } |
|
676 | + |
|
677 | + return $this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)) . |
|
678 | 678 | $this->getBasePart()->toString(array('canonical' => true)); |
679 | - } |
|
679 | + } |
|
680 | 680 | |
681 | 681 | /** |
682 | 682 | * Convert charset of text-parts of message to utf-8 |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @param int|Mail\Account|boolean $account =null mail account to use, default use Mail\Account::get_default($smtp=true) |
67 | 67 | * false: no NOT initialise account and set other EGroupware specific headers, used to parse mails (not sending them!) |
68 | 68 | */ |
69 | - function __construct($account=null) |
|
69 | + function __construct($account = null) |
|
70 | 70 | { |
71 | 71 | // Horde use locale for translation of error messages |
72 | 72 | Preferences::setlocale(LC_MESSAGES); |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * @param int|Mail\Account $account =null mail account to use, default use Mail\Account::get_default($smtp=true) |
106 | 106 | * @throws Exception\NotFound if account was not found (or not valid for current user) |
107 | 107 | */ |
108 | - function setAccount($account=null) |
|
108 | + function setAccount($account = null) |
|
109 | 109 | { |
110 | 110 | if (is_a($account, 'Mail\Account')) |
111 | 111 | { |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | { |
128 | 128 | $identity = Mail\Account::read_identity($this->account->ident_id, true, null, $this->account); |
129 | 129 | } |
130 | - catch(Exception $e) |
|
130 | + catch (Exception $e) |
|
131 | 131 | { |
132 | 132 | unset($e); |
133 | 133 | error_log(__METHOD__.__LINE__.' Could not read_identity for account:'.$account['acc_id'].' with IdentID:'.$account['ident_id']); |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @param string $address |
150 | 150 | * @param string $personal ='' |
151 | 151 | */ |
152 | - public function setFrom($address, $personal='') |
|
152 | + public function setFrom($address, $personal = '') |
|
153 | 153 | { |
154 | 154 | $this->addHeader('From', self::add_personal($address, $personal)); |
155 | 155 | } |
@@ -161,13 +161,13 @@ discard block |
||
161 | 161 | * @param string $personal ='' only used if $address is a string |
162 | 162 | * @param string $type ='to' type of address to add "to", "cc", "bcc" or "replyto" |
163 | 163 | */ |
164 | - function addAddress($address, $personal='', $type='to') |
|
164 | + function addAddress($address, $personal = '', $type = 'to') |
|
165 | 165 | { |
166 | 166 | if (!isset(self::$type2header[$type])) |
167 | 167 | { |
168 | 168 | throw new Exception\WrongParameter("Unknown type '$type'!"); |
169 | 169 | } |
170 | - if ($personal) $address = self::add_personal ($address, $personal); |
|
170 | + if ($personal) $address = self::add_personal($address, $personal); |
|
171 | 171 | |
172 | 172 | // add to our local list |
173 | 173 | $this->$type->add($address); |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * |
182 | 182 | * @param string $type ='to' type of address to add "to", "cc", "bcc" or "replyto" |
183 | 183 | */ |
184 | - function clearAddresses($type='to') |
|
184 | + function clearAddresses($type = 'to') |
|
185 | 185 | { |
186 | 186 | $this->$type = new Horde_Mail_Rfc822_List(); |
187 | 187 | |
@@ -195,12 +195,12 @@ discard block |
||
195 | 195 | * @param boolean $return_array =false true: return array of string, false: Horde_Mail_Rfc822_List |
196 | 196 | * @return array|Horde_Mail_Rfc822_List supporting arrayAccess and Iterable |
197 | 197 | */ |
198 | - function getAddresses($type='to', $return_array=false) |
|
198 | + function getAddresses($type = 'to', $return_array = false) |
|
199 | 199 | { |
200 | 200 | if ($return_array) |
201 | 201 | { |
202 | 202 | $addresses = array(); |
203 | - foreach($this->$type as $addr) |
|
203 | + foreach ($this->$type as $addr) |
|
204 | 204 | { |
205 | 205 | $addresses[] = (string)$addr; |
206 | 206 | } |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | //if (!preg_match('/^[!#$%&\'*+/0-9=?A-Z^_`a-z{|}~-]+$/u', $personal)) // that's how I read the rfc(2)822 |
242 | 242 | if ($personal && !preg_match('/^[0-9A-Z -]*$/iu', $personal)) // but quoting is never wrong, so quote more then necessary |
243 | 243 | { |
244 | - $personal = '"'.str_replace(array('\\', '"'),array('\\\\', '\\"'), $personal).'"'; |
|
244 | + $personal = '"'.str_replace(array('\\', '"'), array('\\\\', '\\"'), $personal).'"'; |
|
245 | 245 | } |
246 | 246 | $address = ($personal ? $personal.' <' : '').$address.($personal ? '>' : ''); |
247 | 247 | } |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | * @param string|array|Horde_Mail_Rfc822_List $address |
255 | 255 | * @param string $personal ='' only used if $address is a string |
256 | 256 | */ |
257 | - function addCc($address, $personal=null) |
|
257 | + function addCc($address, $personal = null) |
|
258 | 258 | { |
259 | 259 | $this->addAddress($address, $personal, 'cc'); |
260 | 260 | } |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | * @param string|array|Horde_Mail_Rfc822_List $address |
274 | 274 | * @param string $personal ='' only used if $address is a string |
275 | 275 | */ |
276 | - function addBcc($address, $personal=null) |
|
276 | + function addBcc($address, $personal = null) |
|
277 | 277 | { |
278 | 278 | $this->addAddress($address, $personal, 'bcc'); |
279 | 279 | } |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | * @param string|array|Horde_Mail_Rfc822_List $address |
293 | 293 | * @param string $personal ='' only used if $address is a string |
294 | 294 | */ |
295 | - function addReplyTo($address, $personal=null) |
|
295 | + function addReplyTo($address, $personal = null) |
|
296 | 296 | { |
297 | 297 | $this->addAddress($address, $personal, 'replyto'); |
298 | 298 | } |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | * @return integer part-number |
328 | 328 | * @throws Exception\NotFound if $file could not be opened for reading |
329 | 329 | */ |
330 | - public function addAttachment($data, $name = null, $type = null, $old_type=null) |
|
330 | + public function addAttachment($data, $name = null, $type = null, $old_type = null) |
|
331 | 331 | { |
332 | 332 | // deprecated PHPMailer::AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') call |
333 | 333 | if ($type === 'base64') |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | // set content-type parameters, which get ignored by setType |
361 | 361 | if (preg_match_all('/;\s*([^=]+)=([^;]*)/', $type, $matches)) |
362 | 362 | { |
363 | - foreach($matches[1] as $n => $label) |
|
363 | + foreach ($matches[1] as $n => $label) |
|
364 | 364 | { |
365 | 365 | $part->setContentTypeParameter($label, $matches[2][$n]); |
366 | 366 | } |
@@ -462,11 +462,11 @@ discard block |
||
462 | 462 | * @param array $parameters =array() eg. array('method' => 'REQUEST') |
463 | 463 | * @param string $charset =null default to $this->_charset="utf-8" |
464 | 464 | */ |
465 | - function setAlternativBody($content, $type, $parameters=array(), $charset=null) |
|
465 | + function setAlternativBody($content, $type, $parameters = array(), $charset = null) |
|
466 | 466 | { |
467 | 467 | $this->_alternativBody = new Horde_Mime_Part(); |
468 | 468 | $this->_alternativBody->setType($type); |
469 | - foreach($parameters as $label => $data) |
|
469 | + foreach ($parameters as $label => $data) |
|
470 | 470 | { |
471 | 471 | $this->_alternativBody->setContentTypeParameter($label, $data); |
472 | 472 | } |
@@ -491,9 +491,9 @@ discard block |
||
491 | 491 | * @throws Exception\NotFound for no smtp account available |
492 | 492 | * @throws Horde_Mime_Exception |
493 | 493 | */ |
494 | - function send(Horde_Mail_Transport $transport=null, $resend=true, $flowed=null) |
|
494 | + function send(Horde_Mail_Transport $transport = null, $resend = true, $flowed = null) |
|
495 | 495 | { |
496 | - unset($resend); // parameter is not used, but required by function signature |
|
496 | + unset($resend); // parameter is not used, but required by function signature |
|
497 | 497 | |
498 | 498 | if (!($message_id = $this->getHeader('Message-ID')) && |
499 | 499 | class_exists('Horde_Mime_Headers_MessageId')) // since 2.5.0 |
@@ -501,24 +501,24 @@ discard block |
||
501 | 501 | $message_id = Horde_Mime_Headers_MessageId::create('EGroupware'); |
502 | 502 | $this->addHeader('Message-ID', $message_id); |
503 | 503 | } |
504 | - $body_sha1 = null; // skip sha1, it requires whole mail in memory, which we traing to avoid now |
|
504 | + $body_sha1 = null; // skip sha1, it requires whole mail in memory, which we traing to avoid now |
|
505 | 505 | |
506 | 506 | $mail_id = Hooks::process(array( |
507 | 507 | 'location' => 'send_mail', |
508 | - 'subject' => $subject=$this->getHeader('Subject'), |
|
508 | + 'subject' => $subject = $this->getHeader('Subject'), |
|
509 | 509 | 'from' => $this->getHeader('Return-Path') ? $this->getHeader('Return-Path') : $this->getHeader('From'), |
510 | - 'to' => $to=$this->getAddresses('to', true), |
|
511 | - 'cc' => $cc=$this->getAddresses('cc', true), |
|
512 | - 'bcc' => $bcc=$this->getAddresses('bcc', true), |
|
510 | + 'to' => $to = $this->getAddresses('to', true), |
|
511 | + 'cc' => $cc = $this->getAddresses('cc', true), |
|
512 | + 'bcc' => $bcc = $this->getAddresses('bcc', true), |
|
513 | 513 | 'body_sha1' => $body_sha1, |
514 | 514 | 'message_id' => (string)$message_id, |
515 | - ), array(), true); // true = call all apps |
|
515 | + ), array(), true); // true = call all apps |
|
516 | 516 | |
517 | 517 | // check if we are sending an html mail with inline images |
518 | 518 | if (!empty($this->_htmlBody) && count($this->_parts)) |
519 | 519 | { |
520 | 520 | $related = null; |
521 | - foreach($this->_parts as $n => $part) |
|
521 | + foreach ($this->_parts as $n => $part) |
|
522 | 522 | { |
523 | 523 | if ($part->getDisposition() == 'inline' && $part->getContentId()) |
524 | 524 | { |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | $this->_body = $body; |
575 | 575 | $flowed = false; |
576 | 576 | } |
577 | - parent::send($transport ? $transport : $this->account->smtpTransport(), true, $flowed); // true: keep Message-ID |
|
577 | + parent::send($transport ? $transport : $this->account->smtpTransport(), true, $flowed); // true: keep Message-ID |
|
578 | 578 | } |
579 | 579 | catch (\Exception $e) { |
580 | 580 | // in case of errors/exceptions call hook again with previous returned mail_id and error-message to log |
@@ -589,7 +589,7 @@ discard block |
||
589 | 589 | 'message_id' => (string)$message_id, |
590 | 590 | 'mail_id' => $mail_id, |
591 | 591 | 'error' => $e->getMessage(), |
592 | - ), array(), true); // true = call all apps |
|
592 | + ), array(), true); // true = call all apps |
|
593 | 593 | } |
594 | 594 | |
595 | 595 | // log mails to file specified in $GLOBALS['egw_info']['server']['log_mail'] or error_log for true |
@@ -602,7 +602,7 @@ discard block |
||
602 | 602 | $msg .= ' from instance '.$GLOBALS['egw_info']['user']['domain'].' and IP '.Session::getuser_ip(); |
603 | 603 | $msg .= ' from user #'.$GLOBALS['egw_info']['user']['account_id']; |
604 | 604 | |
605 | - if ($GLOBALS['egw_info']['user']['account_id'] && class_exists(__NAMESPACE__.'\\Accounts',false)) |
|
605 | + if ($GLOBALS['egw_info']['user']['account_id'] && class_exists(__NAMESPACE__.'\\Accounts', false)) |
|
606 | 606 | { |
607 | 607 | $msg .= ' ('.Accounts::username($GLOBALS['egw_info']['user']['account_id']).')'; |
608 | 608 | } |
@@ -614,7 +614,7 @@ discard block |
||
614 | 614 | $msg .= ' cc='.implode(', ', $cc).', bcc='.implode(', ', $bcc); |
615 | 615 | if ($GLOBALS['egw_info']['server']['log_mail'] !== true) $msg .= "\n\n"; |
616 | 616 | |
617 | - error_log($msg,$GLOBALS['egw_info']['server']['log_mail'] === true ? 0 : 3, |
|
617 | + error_log($msg, $GLOBALS['egw_info']['server']['log_mail'] === true ? 0 : 3, |
|
618 | 618 | $GLOBALS['egw_info']['server']['log_mail']); |
619 | 619 | } |
620 | 620 | // rethrow error |
@@ -651,15 +651,15 @@ discard block |
||
651 | 651 | * @param boolean $stream If true, return a stream resource, otherwise |
652 | 652 | * @return stream|string The raw email data. |
653 | 653 | */ |
654 | - function getRaw($stream=true) |
|
654 | + function getRaw($stream = true) |
|
655 | 655 | { |
656 | 656 | try { |
657 | 657 | $this->getBasePart(); |
658 | 658 | } |
659 | - catch(Horde_Mail_Exception $e) |
|
659 | + catch (Horde_Mail_Exception $e) |
|
660 | 660 | { |
661 | 661 | unset($e); |
662 | - parent::send(new Horde_Mail_Transport_Null(), true); // true: keep Message-ID |
|
662 | + parent::send(new Horde_Mail_Transport_Null(), true); // true: keep Message-ID |
|
663 | 663 | } |
664 | 664 | // code copied from Horde_Mime_Mail::getRaw(), as there is no way to inject charset in |
665 | 665 | // _headers->toString(), which is required to encode headers containing non-ascii chars correct |
@@ -669,12 +669,12 @@ discard block |
||
669 | 669 | return Horde_Stream_Wrapper_Combine::getStream( |
670 | 670 | array($hdr->stream, |
671 | 671 | $this->getBasePart()->toString( |
672 | - array('stream' => true, 'canonical' => true, 'encode' => Horde_Mime_Part::ENCODE_7BIT | Horde_Mime_Part::ENCODE_8BIT | Horde_Mime_Part::ENCODE_BINARY)) |
|
672 | + array('stream' => true, 'canonical' => true, 'encode' => Horde_Mime_Part::ENCODE_7BIT|Horde_Mime_Part::ENCODE_8BIT|Horde_Mime_Part::ENCODE_BINARY)) |
|
673 | 673 | ) |
674 | 674 | ); |
675 | 675 | } |
676 | 676 | |
677 | - return $this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)) . |
|
677 | + return $this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)). |
|
678 | 678 | $this->getBasePart()->toString(array('canonical' => true)); |
679 | 679 | } |
680 | 680 | |
@@ -687,23 +687,23 @@ discard block |
||
687 | 687 | * @param boolean &$converted =false on return if conversation was necessary |
688 | 688 | * @return string|stream |
689 | 689 | */ |
690 | - static function convert($message, $stream=false, $charset='utf-8', &$converted=false) |
|
690 | + static function convert($message, $stream = false, $charset = 'utf-8', &$converted = false) |
|
691 | 691 | { |
692 | - $mailer = new Mailer(false); // false = no default headers and mail account |
|
692 | + $mailer = new Mailer(false); // false = no default headers and mail account |
|
693 | 693 | $mailer->addHeaders(Horde_Mime_Headers::parseHeaders($message)); |
694 | 694 | $base = Horde_Mime_Part::parseMessage($message); |
695 | - foreach($base->partIterator() as $part) |
|
695 | + foreach ($base->partIterator() as $part) |
|
696 | 696 | { |
697 | - if ($part->getPrimaryType()== 'text') |
|
697 | + if ($part->getPrimaryType() == 'text') |
|
698 | 698 | { |
699 | 699 | $charset = $part->getContentTypeParameter('charset'); |
700 | 700 | if ($charset && $charset != 'utf-8') |
701 | 701 | { |
702 | 702 | $content = Translation::convert($part->toString(array( |
703 | - 'encode' => Horde_Mime_Part::ENCODE_BINARY, // otherwise we cant recode charset |
|
703 | + 'encode' => Horde_Mime_Part::ENCODE_BINARY, // otherwise we cant recode charset |
|
704 | 704 | )), $charset, 'utf-8'); |
705 | 705 | $part->setContents($content, array( |
706 | - 'encode' => Horde_Mime_Part::ENCODE_BINARY, // $content is NOT encoded |
|
706 | + 'encode' => Horde_Mime_Part::ENCODE_BINARY, // $content is NOT encoded |
|
707 | 707 | )); |
708 | 708 | $part->setContentTypeParameter('charset', 'utf-8'); |
709 | 709 | if ($part === $base) |
@@ -736,7 +736,7 @@ discard block |
||
736 | 736 | * @param string $subtype =null |
737 | 737 | * @return Horde_Mime_Part part with body or null |
738 | 738 | */ |
739 | - function findBody($subtype=null) |
|
739 | + function findBody($subtype = null) |
|
740 | 740 | { |
741 | 741 | try { |
742 | 742 | $base = $this->getBasePart(); |
@@ -768,11 +768,11 @@ discard block |
||
768 | 768 | $this->_body = $this->_htmlBody = $this->_alternativBody = null; |
769 | 769 | $this->clearParts(); |
770 | 770 | |
771 | - foreach($base->partIterator() as $part) |
|
771 | + foreach ($base->partIterator() as $part) |
|
772 | 772 | { |
773 | 773 | $id = $part->getMimeId(); |
774 | 774 | //error_log(__METHOD__."() plain=$plain_id, html=$html_id: $id: ".$part->getType()); |
775 | - switch($id) |
|
775 | + switch ($id) |
|
776 | 776 | { |
777 | 777 | case '0': // base-part itself |
778 | 778 | continue 2; |
@@ -816,11 +816,11 @@ discard block |
||
816 | 816 | $this->_body = $this->_htmlBody = $this->_alternativBody = null; |
817 | 817 | $this->clearParts(); |
818 | 818 | |
819 | - foreach($base->partIterator() as $part) |
|
819 | + foreach ($base->partIterator() as $part) |
|
820 | 820 | { |
821 | 821 | $id = $part->getMimeId(); |
822 | 822 | //error_log(__METHOD__."() plain=$plain_id, html=$html_id: $id: ".$part->getType()); |
823 | - switch($id) |
|
823 | + switch ($id) |
|
824 | 824 | { |
825 | 825 | case '0': // base-part itself |
826 | 826 | continue 2; |
@@ -892,7 +892,7 @@ discard block |
||
892 | 892 | */ |
893 | 893 | function clearCustomHeaders() |
894 | 894 | { |
895 | - foreach($this->_headers->toArray() as $header => $value) |
|
895 | + foreach ($this->_headers->toArray() as $header => $value) |
|
896 | 896 | { |
897 | 897 | if (stripos($header, 'x-') === 0 || $header == 'Received') |
898 | 898 | { |
@@ -117,10 +117,13 @@ discard block |
||
117 | 117 | } |
118 | 118 | else |
119 | 119 | { |
120 | - if (!($this->account = Mail\Account::get_default(true))) // true = need an SMTP (not just IMAP) account |
|
120 | + if (!($this->account = Mail\Account::get_default(true))) |
|
121 | + { |
|
122 | + // true = need an SMTP (not just IMAP) account |
|
121 | 123 | { |
122 | 124 | throw new Exception\NotFound('SMTP: '.lang('Account not found!')); |
123 | 125 | } |
126 | + } |
|
124 | 127 | } |
125 | 128 | |
126 | 129 | try |
@@ -167,7 +170,10 @@ discard block |
||
167 | 170 | { |
168 | 171 | throw new Exception\WrongParameter("Unknown type '$type'!"); |
169 | 172 | } |
170 | - if ($personal) $address = self::add_personal ($address, $personal); |
|
173 | + if ($personal) |
|
174 | + { |
|
175 | + $address = self::add_personal ($address, $personal); |
|
176 | + } |
|
171 | 177 | |
172 | 178 | // add to our local list |
173 | 179 | $this->$type->add($address); |
@@ -239,10 +245,13 @@ discard block |
||
239 | 245 | if (is_string($address) && !empty($personal)) |
240 | 246 | { |
241 | 247 | //if (!preg_match('/^[!#$%&\'*+/0-9=?A-Z^_`a-z{|}~-]+$/u', $personal)) // that's how I read the rfc(2)822 |
242 | - if ($personal && !preg_match('/^[0-9A-Z -]*$/iu', $personal)) // but quoting is never wrong, so quote more then necessary |
|
248 | + if ($personal && !preg_match('/^[0-9A-Z -]*$/iu', $personal)) |
|
249 | + { |
|
250 | + // but quoting is never wrong, so quote more then necessary |
|
243 | 251 | { |
244 | 252 | $personal = '"'.str_replace(array('\\', '"'),array('\\\\', '\\"'), $personal).'"'; |
245 | 253 | } |
254 | + } |
|
246 | 255 | $address = ($personal ? $personal.' <' : '').$address.($personal ? '>' : ''); |
247 | 256 | } |
248 | 257 | return $address; |
@@ -345,7 +354,10 @@ discard block |
||
345 | 354 | throw new Exception\NotFound("File '$data' not found!"); |
346 | 355 | } |
347 | 356 | |
348 | - if (empty($type) && !is_resource($data)) $type = Vfs::mime_content_type($data); |
|
357 | + if (empty($type) && !is_resource($data)) |
|
358 | + { |
|
359 | + $type = Vfs::mime_content_type($data); |
|
360 | + } |
|
349 | 361 | |
350 | 362 | // set "text/calendar; method=*" as alternativ body |
351 | 363 | $matches = null; |
@@ -368,11 +380,17 @@ discard block |
||
368 | 380 | $part->setContents($resource); |
369 | 381 | |
370 | 382 | // setting name, also sets content-disposition attachment (!), therefore we have to do it after "text/calendar; method=" handling |
371 | - if ($name || !is_resource($data)) $part->setName($name ? $name : Vfs::basename($data)); |
|
383 | + if ($name || !is_resource($data)) |
|
384 | + { |
|
385 | + $part->setName($name ? $name : Vfs::basename($data)); |
|
386 | + } |
|
372 | 387 | |
373 | 388 | // this should not be necessary, because binary data get detected by mime-type, |
374 | 389 | // but at least Cyrus complains about NUL characters |
375 | - if (substr($type, 0, 5) != 'text/') $part->setTransferEncoding('base64', array('send' => true)); |
|
390 | + if (substr($type, 0, 5) != 'text/') |
|
391 | + { |
|
392 | + $part->setTransferEncoding('base64', array('send' => true)); |
|
393 | + } |
|
376 | 394 | $part->setDisposition('attachment'); |
377 | 395 | |
378 | 396 | return $this->addMimePart($part); |
@@ -496,9 +514,12 @@ discard block |
||
496 | 514 | unset($resend); // parameter is not used, but required by function signature |
497 | 515 | |
498 | 516 | if (!($message_id = $this->getHeader('Message-ID')) && |
499 | - class_exists('Horde_Mime_Headers_MessageId')) // since 2.5.0 |
|
517 | + class_exists('Horde_Mime_Headers_MessageId')) |
|
518 | + { |
|
519 | + // since 2.5.0 |
|
500 | 520 | { |
501 | 521 | $message_id = Horde_Mime_Headers_MessageId::create('EGroupware'); |
522 | + } |
|
502 | 523 | $this->addHeader('Message-ID', $message_id); |
503 | 524 | } |
504 | 525 | $body_sha1 = null; // skip sha1, it requires whole mail in memory, which we traing to avoid now |
@@ -538,7 +559,10 @@ discard block |
||
538 | 559 | |
539 | 560 | try { |
540 | 561 | // no flowed for encrypted messages |
541 | - if (!isset($flowed)) $flowed = $this->_body && $this->_body->getType() != 'multipart/encrypted'; |
|
562 | + if (!isset($flowed)) |
|
563 | + { |
|
564 | + $flowed = $this->_body && $this->_body->getType() != 'multipart/encrypted'; |
|
565 | + } |
|
542 | 566 | |
543 | 567 | // check if flowed is disabled in mail site configuration |
544 | 568 | if (($config = Config::read('mail')) && $config['disable_rfc3676_flowed']) |
@@ -612,13 +636,19 @@ discard block |
||
612 | 636 | $msg .= 'ERROR '.$e->getMessage(); |
613 | 637 | } |
614 | 638 | $msg .= ' cc='.implode(', ', $cc).', bcc='.implode(', ', $bcc); |
615 | - if ($GLOBALS['egw_info']['server']['log_mail'] !== true) $msg .= "\n\n"; |
|
639 | + if ($GLOBALS['egw_info']['server']['log_mail'] !== true) |
|
640 | + { |
|
641 | + $msg .= "\n\n"; |
|
642 | + } |
|
616 | 643 | |
617 | 644 | error_log($msg,$GLOBALS['egw_info']['server']['log_mail'] === true ? 0 : 3, |
618 | 645 | $GLOBALS['egw_info']['server']['log_mail']); |
619 | 646 | } |
620 | 647 | // rethrow error |
621 | - if (isset($e)) throw $e; |
|
648 | + if (isset($e)) |
|
649 | + { |
|
650 | + throw $e; |
|
651 | + } |
|
622 | 652 | } |
623 | 653 | |
624 | 654 | |
@@ -663,7 +693,8 @@ discard block |
||
663 | 693 | } |
664 | 694 | // code copied from Horde_Mime_Mail::getRaw(), as there is no way to inject charset in |
665 | 695 | // _headers->toString(), which is required to encode headers containing non-ascii chars correct |
666 | - if ($stream) { |
|
696 | + if ($stream) |
|
697 | + { |
|
667 | 698 | $hdr = new Horde_Stream(); |
668 | 699 | $hdr->add($this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)), true); |
669 | 700 | return Horde_Stream_Wrapper_Combine::getStream( |
@@ -740,7 +771,10 @@ discard block |
||
740 | 771 | { |
741 | 772 | try { |
742 | 773 | $base = $this->getBasePart(); |
743 | - if (!($part_id = $base->findBody($subtype))) return null; |
|
774 | + if (!($part_id = $base->findBody($subtype))) |
|
775 | + { |
|
776 | + return null; |
|
777 | + } |
|
744 | 778 | return $base->getPart($part_id); |
745 | 779 | } |
746 | 780 | catch (Exception $e) { |
@@ -854,7 +888,10 @@ discard block |
||
854 | 888 | */ |
855 | 889 | public function addMimePart($part) |
856 | 890 | { |
857 | - if ($this->_base) $this->parseBasePart(); |
|
891 | + if ($this->_base) |
|
892 | + { |
|
893 | + $this->parseBasePart(); |
|
894 | + } |
|
858 | 895 | |
859 | 896 | return parent::addMimePart($part); |
860 | 897 | } |
@@ -968,7 +968,7 @@ |
||
968 | 968 | * |
969 | 969 | * This method uses the language and nationalty set in the users common prefs. |
970 | 970 | * |
971 | - * @param $category =LC_ALL category to set, see setlocal function |
|
971 | + * @param integer $category =LC_ALL category to set, see setlocal function |
|
972 | 972 | * @param $charset =null default system charset |
973 | 973 | * @return string the local (or best estimate) set |
974 | 974 | */ |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | const TABLE = 'egw_preferences'; |
96 | 96 | var $table = self::TABLE; |
97 | 97 | |
98 | - var $values,$vars; // standard notify substitues, will be set by standard_substitues() |
|
98 | + var $values, $vars; // standard notify substitues, will be set by standard_substitues() |
|
99 | 99 | |
100 | 100 | /** |
101 | 101 | * Contstructor |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | case self::FORCED_ID: |
164 | 164 | return 'forced'; |
165 | 165 | } |
166 | - return $this->account_id < self::DEFAULT_ID ? $this->account_id-self::DEFAULT_ID : $this->account_id; |
|
166 | + return $this->account_id < self::DEFAULT_ID ? $this->account_id - self::DEFAULT_ID : $this->account_id; |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -193,21 +193,21 @@ discard block |
||
193 | 193 | { |
194 | 194 | $prefs = Cache::getInstance(__CLASS__, $ids); |
195 | 195 | $db_read = array(); |
196 | - foreach((array)$ids as $id) |
|
196 | + foreach ((array)$ids as $id) |
|
197 | 197 | { |
198 | 198 | // if prefs are not returned, null or not an array, read them from db |
199 | 199 | if (!isset($prefs[$id]) && !is_array($prefs[$id])) $db_read[] = $id; |
200 | 200 | } |
201 | 201 | if ($db_read) |
202 | 202 | { |
203 | - foreach($this->db->select($this->table,'*',array('preference_owner' => $db_read),__LINE__,__FILE__) as $row) |
|
203 | + foreach ($this->db->select($this->table, '*', array('preference_owner' => $db_read), __LINE__, __FILE__) as $row) |
|
204 | 204 | { |
205 | 205 | // The following replacement is required for PostgreSQL to work |
206 | 206 | $app = trim($row['preference_app']); |
207 | 207 | |
208 | 208 | $prefs[$row['preference_owner']][$app] = self::unserialize($row['preference_value']); |
209 | 209 | } |
210 | - foreach($db_read as $id) |
|
210 | + foreach ($db_read as $id) |
|
211 | 211 | { |
212 | 212 | if (!isset($prefs[$id])) $prefs[$id] = array(); |
213 | 213 | Cache::setInstance(__CLASS__, $id, $prefs[$id]); |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | * @param boolean $use_standard_values =true should the standard values are used |
227 | 227 | * @return string with parsed notify-msg |
228 | 228 | */ |
229 | - function parse_notify($msg,$values=array(),$use_standard_values=True) |
|
229 | + function parse_notify($msg, $values = array(), $use_standard_values = True) |
|
230 | 230 | { |
231 | 231 | $vals = $values ? $values : array(); |
232 | 232 | |
@@ -235,13 +235,13 @@ discard block |
||
235 | 235 | $vals += $this->values; |
236 | 236 | } |
237 | 237 | $replace = $with = array(); |
238 | - foreach($vals as $key => $val) |
|
238 | + foreach ($vals as $key => $val) |
|
239 | 239 | { |
240 | 240 | if ($this->debug) error_log(__METHOD__." replacing \$\$$key\$\$ with $val "); |
241 | 241 | $replace[] = '$$'.$key.'$$'; |
242 | 242 | $with[] = $val; |
243 | 243 | } |
244 | - return str_replace($replace,$with,$msg); |
|
244 | + return str_replace($replace, $with, $msg); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -253,9 +253,9 @@ discard block |
||
253 | 253 | * @param boolean $un_lang =false if true translate back |
254 | 254 | * @return string |
255 | 255 | */ |
256 | - function lang_notify($msg,$vals=array(),$un_lang=False) |
|
256 | + function lang_notify($msg, $vals = array(), $un_lang = False) |
|
257 | 257 | { |
258 | - foreach(array_keys($vals) as $key) |
|
258 | + foreach (array_keys($vals) as $key) |
|
259 | 259 | { |
260 | 260 | $lname = ($lname = lang($key)) == $key.'*' ? $key : $lname; |
261 | 261 | if ($un_lang) |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | $langs[$key] = '$$'.$lname.'$$'; |
268 | 268 | } |
269 | 269 | } |
270 | - return $this->parse_notify($msg,$langs,False); |
|
270 | + return $this->parse_notify($msg, $langs, False); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | if ($this->debug) error_log(__METHOD__." is called "); |
279 | 279 | if (!is_array(@$GLOBALS['egw_info']['user']['preferences'])) |
280 | 280 | { |
281 | - $GLOBALS['egw_info']['user']['preferences'] = $this->data; // else no lang() |
|
281 | + $GLOBALS['egw_info']['user']['preferences'] = $this->data; // else no lang() |
|
282 | 282 | } |
283 | 283 | // we cant use egw_info/user/fullname, as it's not set when we run |
284 | 284 | $this->values = array( // standard notify replacements |
@@ -287,37 +287,37 @@ discard block |
||
287 | 287 | 'lastname' => Accounts::id2name($this->account_id, 'account_lastname'), |
288 | 288 | 'domain' => $GLOBALS['egw_info']['server']['mail_suffix'], |
289 | 289 | 'email' => $this->email_address($this->account_id), |
290 | - 'date' => DateTime::to('now',$GLOBALS['egw_info']['user']['preferences']['common']['dateformat']), |
|
290 | + 'date' => DateTime::to('now', $GLOBALS['egw_info']['user']['preferences']['common']['dateformat']), |
|
291 | 291 | ); |
292 | 292 | // do this first, as it might be already contain some substitues |
293 | 293 | // |
294 | 294 | $this->values['email'] = $this->parse_notify($this->values['email']); |
295 | 295 | |
296 | 296 | $this->vars = array( // langs have to be in common !!! |
297 | - 'fullname' => lang('name of the user, eg. "%1"',$this->values['fullname']), |
|
298 | - 'firstname' => lang('first name of the user, eg. "%1"',$this->values['firstname']), |
|
299 | - 'lastname' => lang('last name of the user, eg. "%1"',$this->values['lastname']), |
|
300 | - 'domain' => lang('domain name for mail-address, eg. "%1"',$this->values['domain']), |
|
301 | - 'email' => lang('email-address of the user, eg. "%1"',$this->values['email']), |
|
302 | - 'date' => lang('todays date, eg. "%1"',$this->values['date']), |
|
297 | + 'fullname' => lang('name of the user, eg. "%1"', $this->values['fullname']), |
|
298 | + 'firstname' => lang('first name of the user, eg. "%1"', $this->values['firstname']), |
|
299 | + 'lastname' => lang('last name of the user, eg. "%1"', $this->values['lastname']), |
|
300 | + 'domain' => lang('domain name for mail-address, eg. "%1"', $this->values['domain']), |
|
301 | + 'email' => lang('email-address of the user, eg. "%1"', $this->values['email']), |
|
302 | + 'date' => lang('todays date, eg. "%1"', $this->values['date']), |
|
303 | 303 | ); |
304 | - if ($this->debug) error_log(__METHOD__.print_r($this->vars,true)); |
|
304 | + if ($this->debug) error_log(__METHOD__.print_r($this->vars, true)); |
|
305 | 305 | // do the substituetion in the effective prefs (data) |
306 | 306 | // |
307 | - foreach($this->data as $app => $data) |
|
307 | + foreach ($this->data as $app => $data) |
|
308 | 308 | { |
309 | - if(!is_array($data)) continue; |
|
310 | - foreach($data as $key => $val) |
|
309 | + if (!is_array($data)) continue; |
|
310 | + foreach ($data as $key => $val) |
|
311 | 311 | { |
312 | - if (!is_array($val) && strpos($val,'$$') !== False) |
|
312 | + if (!is_array($val) && strpos($val, '$$') !== False) |
|
313 | 313 | { |
314 | 314 | $this->data[$app][$key] = $this->parse_notify($val); |
315 | 315 | } |
316 | 316 | elseif (is_array($val)) |
317 | 317 | { |
318 | - foreach($val as $k => $v) |
|
318 | + foreach ($val as $k => $v) |
|
319 | 319 | { |
320 | - if (!is_array($v) && strpos($v,'$$') !== False) |
|
320 | + if (!is_array($v) && strpos($v, '$$') !== False) |
|
321 | 321 | { |
322 | 322 | $this->data[$app][$key][$k] = $this->parse_notify($v); |
323 | 323 | } |
@@ -342,12 +342,12 @@ discard block |
||
342 | 342 | } |
343 | 343 | // handling of old PHP serialized and addslashed prefs |
344 | 344 | $data = php_safe_unserialize($str); |
345 | - if($data === false) |
|
345 | + if ($data === false) |
|
346 | 346 | { |
347 | 347 | // manually retrieve the string lengths of the serialized array if unserialize failed |
348 | 348 | $data = php_safe_unserialize(preg_replace_callback('!s:(\d+):"(.*?)";!s', function($matches) |
349 | 349 | { |
350 | - return 's:'.mb_strlen($matches[2],'8bit').':"'.$matches[2].'";'; |
|
350 | + return 's:'.mb_strlen($matches[2], '8bit').':"'.$matches[2].'";'; |
|
351 | 351 | }, $str)); |
352 | 352 | } |
353 | 353 | self::unquote($data); |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | $arr = stripslashes($arr); |
367 | 367 | return; |
368 | 368 | } |
369 | - foreach($arr as $key => $value) |
|
369 | + foreach ($arr as $key => $value) |
|
370 | 370 | { |
371 | 371 | if (is_array($value)) |
372 | 372 | { |
@@ -387,27 +387,27 @@ discard block |
||
387 | 387 | * @param boolean $use_session =true should the session prefs get used (default true) or not (false) |
388 | 388 | * @return array with effective prefs ($this->data) |
389 | 389 | */ |
390 | - function read_repository($use_session=true) |
|
390 | + function read_repository($use_session = true) |
|
391 | 391 | { |
392 | - $this->session = $use_session ? Cache::getSession('preferences','preferences') : array(); |
|
392 | + $this->session = $use_session ? Cache::getSession('preferences', 'preferences') : array(); |
|
393 | 393 | if (!is_array($this->session)) |
394 | 394 | { |
395 | 395 | $this->session = array(); |
396 | 396 | } |
397 | 397 | $this->forced = $this->default = $this->user = $this->group = array(); |
398 | - $to_read = array(self::DEFAULT_ID,self::FORCED_ID,$this->account_id); |
|
398 | + $to_read = array(self::DEFAULT_ID, self::FORCED_ID, $this->account_id); |
|
399 | 399 | if ($this->account_id > 0) |
400 | 400 | { |
401 | 401 | $primary_group = Accounts::id2name($this->account_id, 'account_primary_group'); |
402 | - foreach((array)$GLOBALS['egw']->accounts->memberships($this->account_id, true) as $gid) |
|
402 | + foreach ((array)$GLOBALS['egw']->accounts->memberships($this->account_id, true) as $gid) |
|
403 | 403 | { |
404 | - if ($gid != $primary_group) $to_read[] = $gid + self::DEFAULT_ID; // need to offset it with DEFAULT_ID = -2! |
|
404 | + if ($gid != $primary_group) $to_read[] = $gid + self::DEFAULT_ID; // need to offset it with DEFAULT_ID = -2! |
|
405 | 405 | } |
406 | 406 | $to_read[] = $primary_group + self::DEFAULT_ID; |
407 | 407 | } |
408 | - foreach($this->cache_read($to_read) as $id => $values) |
|
408 | + foreach ($this->cache_read($to_read) as $id => $values) |
|
409 | 409 | { |
410 | - switch($id) |
|
410 | + switch ($id) |
|
411 | 411 | { |
412 | 412 | case self::FORCED_ID: |
413 | 413 | $this->forced = $values; |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | $this->user = $values; |
420 | 420 | break; |
421 | 421 | default: |
422 | - foreach($values as $app => $vals) |
|
422 | + foreach ($values as $app => $vals) |
|
423 | 423 | { |
424 | 424 | $this->group[$app] = (array)$vals + (array)$this->group[$app]; |
425 | 425 | } |
@@ -430,9 +430,9 @@ discard block |
||
430 | 430 | |
431 | 431 | // let the (temp.) session prefs. override the user prefs. |
432 | 432 | // |
433 | - foreach($this->session as $app => $values) |
|
433 | + foreach ($this->session as $app => $values) |
|
434 | 434 | { |
435 | - foreach($values as $var => $value) |
|
435 | + foreach ($values as $var => $value) |
|
436 | 436 | { |
437 | 437 | $this->data[$app][$var] = $value; |
438 | 438 | } |
@@ -440,9 +440,9 @@ discard block |
||
440 | 440 | |
441 | 441 | // now use (primary) group defaults if needed (user-value unset or empty) |
442 | 442 | // |
443 | - foreach((array)$this->group as $app => $values) |
|
443 | + foreach ((array)$this->group as $app => $values) |
|
444 | 444 | { |
445 | - foreach((array)$values as $var => $value) |
|
445 | + foreach ((array)$values as $var => $value) |
|
446 | 446 | { |
447 | 447 | if (!isset($this->data[$app][$var]) || $this->data[$app][$var] === '') |
448 | 448 | { |
@@ -452,9 +452,9 @@ discard block |
||
452 | 452 | } |
453 | 453 | // now use defaults if needed (user-value unset or empty) |
454 | 454 | // |
455 | - foreach((array)$this->default as $app => $values) |
|
455 | + foreach ((array)$this->default as $app => $values) |
|
456 | 456 | { |
457 | - foreach((array)$values as $var => $value) |
|
457 | + foreach ((array)$values as $var => $value) |
|
458 | 458 | { |
459 | 459 | if (!isset($this->data[$app][$var]) || $this->data[$app][$var] === '') |
460 | 460 | { |
@@ -465,9 +465,9 @@ discard block |
||
465 | 465 | } |
466 | 466 | // now set/force forced values |
467 | 467 | // |
468 | - foreach((array)$this->forced as $app => $values) |
|
468 | + foreach ((array)$this->forced as $app => $values) |
|
469 | 469 | { |
470 | - foreach((array)$values as $var => $value) |
|
470 | + foreach ((array)$values as $var => $value) |
|
471 | 471 | { |
472 | 472 | $this->data[$app][$var] = $value; |
473 | 473 | } |
@@ -483,12 +483,12 @@ discard block |
||
483 | 483 | { |
484 | 484 | reset($this->data); |
485 | 485 | } |
486 | - if (isset($this->debug) && substr($GLOBALS['egw_info']['flags']['currentapp'],0,3) != 'log') |
|
486 | + if (isset($this->debug) && substr($GLOBALS['egw_info']['flags']['currentapp'], 0, 3) != 'log') |
|
487 | 487 | { |
488 | - echo 'user<pre>'; print_r($this->user); echo "</pre>\n"; |
|
489 | - echo 'forced<pre>'; print_r($this->forced); echo "</pre>\n"; |
|
490 | - echo 'default<pre>'; print_r($this->default); echo "</pre>\n"; |
|
491 | - echo 'group<pre>'; print_r($this->group); echo "</pre>\n"; |
|
488 | + echo 'user<pre>'; print_r($this->user); echo "</pre>\n"; |
|
489 | + echo 'forced<pre>'; print_r($this->forced); echo "</pre>\n"; |
|
490 | + echo 'default<pre>'; print_r($this->default); echo "</pre>\n"; |
|
491 | + echo 'group<pre>'; print_r($this->group); echo "</pre>\n"; |
|
492 | 492 | echo 'effectiv<pre>'; print_r($this->data); echo "</pre>\n"; |
493 | 493 | } |
494 | 494 | $this->check_set_tz_offset(); |
@@ -503,7 +503,7 @@ discard block |
||
503 | 503 | * @param string $name =null |
504 | 504 | * @return mixed |
505 | 505 | */ |
506 | - function default_prefs($app=null,$name=null) |
|
506 | + function default_prefs($app = null, $name = null) |
|
507 | 507 | { |
508 | 508 | // Etemplate::complete_array_merge() is identical to PHP >= 5.3 array_replace_recursive() |
509 | 509 | $default = Etemplate::complete_array_merge($this->default, $this->forced); |
@@ -521,19 +521,19 @@ discard block |
||
521 | 521 | */ |
522 | 522 | function check_set_tz_offset() |
523 | 523 | { |
524 | - $prefs =& $GLOBALS['egw_info']['user']['preferences']['common']; |
|
524 | + $prefs = & $GLOBALS['egw_info']['user']['preferences']['common']; |
|
525 | 525 | |
526 | 526 | if (!empty($prefs['tz'])) |
527 | 527 | { |
528 | - DateTime::setUserPrefs($prefs['tz'],$prefs['dateformat'],$prefs['timeformat']); |
|
528 | + DateTime::setUserPrefs($prefs['tz'], $prefs['dateformat'], $prefs['timeformat']); |
|
529 | 529 | // set the old preference for compatibilty with old code |
530 | - $prefs['tz_offset'] = DateTime::tz_offset_s()/3600; |
|
530 | + $prefs['tz_offset'] = DateTime::tz_offset_s() / 3600; |
|
531 | 531 | //echo "<p>".__METHOD__."() tz=$prefs[tz] --> tz_offset=$prefs[tz_offset]</p>\n"; |
532 | 532 | |
533 | 533 | // ToDo: get rid of that |
534 | 534 | if (isset($GLOBALS['egw']) && ($GLOBALS['egw'] instanceof egw)) |
535 | 535 | { |
536 | - $GLOBALS['egw']->unset_datetime(); // to force an update |
|
536 | + $GLOBALS['egw']->unset_datetime(); // to force an update |
|
537 | 537 | } |
538 | 538 | } |
539 | 539 | } |
@@ -558,7 +558,7 @@ discard block |
||
558 | 558 | { |
559 | 559 | $this->read_repository(); |
560 | 560 | } |
561 | - reset ($this->data); |
|
561 | + reset($this->data); |
|
562 | 562 | return $this->data; |
563 | 563 | } |
564 | 564 | |
@@ -573,7 +573,7 @@ discard block |
||
573 | 573 | * @param string $type ='user' of preference to set: forced, default, user |
574 | 574 | * @return array with new effective prefs (even when forced or default prefs are set !) |
575 | 575 | */ |
576 | - function add($app_name,$var,$value = '##undef##',$type='user') |
|
576 | + function add($app_name, $var, $value = '##undef##', $type = 'user') |
|
577 | 577 | { |
578 | 578 | //echo "<p>add('$app_name','$var','$value')</p>\n"; |
579 | 579 | if ($value === '##undef##') |
@@ -587,10 +587,10 @@ discard block |
||
587 | 587 | if (!isset($this->forced[$app_name][$var]) || $this->forced[$app_name][$var] === '') |
588 | 588 | { |
589 | 589 | $this->session[$app_name][$var] = $this->data[$app_name][$var] = $value; |
590 | - Cache::setSession('preferences','preferences',$this->session); |
|
591 | - if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
590 | + Cache::setSession('preferences', 'preferences', $this->session); |
|
591 | + if (method_exists($GLOBALS['egw'], 'invalidate_session_cache')) // egw object in setup is limited |
|
592 | 592 | { |
593 | - $GLOBALS['egw']->invalidate_session_cache(); // in case with cache the egw_info array in the session |
|
593 | + $GLOBALS['egw']->invalidate_session_cache(); // in case with cache the egw_info array in the session |
|
594 | 594 | } |
595 | 595 | } |
596 | 596 | break; |
@@ -631,13 +631,13 @@ discard block |
||
631 | 631 | * @param string $type ='user' of preference to set: forced, default, user |
632 | 632 | * @return array with new effective prefs (even when forced or default prefs are deleted!) |
633 | 633 | */ |
634 | - function delete($app_name, $var = False,$type = 'user') |
|
634 | + function delete($app_name, $var = False, $type = 'user') |
|
635 | 635 | { |
636 | 636 | //echo "<p>delete('$app_name','$var','$type')</p>\n"; |
637 | 637 | $set_via = array( |
638 | - 'forced' => array('user','default'), |
|
639 | - 'default' => array('forced','user'), |
|
640 | - 'user' => array('forced','group','default'), |
|
638 | + 'forced' => array('user', 'default'), |
|
639 | + 'default' => array('forced', 'user'), |
|
640 | + 'user' => array('forced', 'group', 'default'), |
|
641 | 641 | 'group' => array('forced'), |
642 | 642 | ); |
643 | 643 | if (!isset($set_via[$type])) |
@@ -671,7 +671,7 @@ discard block |
||
671 | 671 | } |
672 | 672 | else |
673 | 673 | { |
674 | - if($var && @isset($arr[$app_name][$var]) && $arr[$app_name][$var] !== '') |
|
674 | + if ($var && @isset($arr[$app_name][$var]) && $arr[$app_name][$var] !== '') |
|
675 | 675 | { |
676 | 676 | $this->data[$app_name][$var] = $arr[$app_name][$var]; |
677 | 677 | break; |
@@ -679,7 +679,7 @@ discard block |
||
679 | 679 | } |
680 | 680 | unset($arr); |
681 | 681 | } |
682 | - reset ($this->data); |
|
682 | + reset($this->data); |
|
683 | 683 | return $this->data; |
684 | 684 | } |
685 | 685 | |
@@ -692,7 +692,7 @@ discard block |
||
692 | 692 | { |
693 | 693 | if ($accountid > 0) |
694 | 694 | { |
695 | - $this->db->delete($this->table,array('preference_owner' => $accountid),__LINE__,__FILE__); |
|
695 | + $this->db->delete($this->table, array('preference_owner' => $accountid), __LINE__, __FILE__); |
|
696 | 696 | |
697 | 697 | Cache::unsetInstance(__CLASS__, $accountid); |
698 | 698 | } |
@@ -707,9 +707,9 @@ discard block |
||
707 | 707 | { |
708 | 708 | if ($accountid < 0) |
709 | 709 | { |
710 | - $this->db->delete($this->table,array('preference_owner' => $accountid+self::DEFAULT_ID),__LINE__,__FILE__); |
|
710 | + $this->db->delete($this->table, array('preference_owner' => $accountid + self::DEFAULT_ID), __LINE__, __FILE__); |
|
711 | 711 | |
712 | - Cache::unsetInstance(__CLASS__, $accountid+self::DEFAULT_ID); |
|
712 | + Cache::unsetInstance(__CLASS__, $accountid + self::DEFAULT_ID); |
|
713 | 713 | } |
714 | 714 | } |
715 | 715 | |
@@ -722,14 +722,14 @@ discard block |
||
722 | 722 | * @param string $old_value if given, only change if that's current value |
723 | 723 | * @param string $type if given limit to "user", "forced", "default", "group" |
724 | 724 | */ |
725 | - public static function change_preference($app, $name, $value, $old_value=null, $type=null) |
|
725 | + public static function change_preference($app, $name, $value, $old_value = null, $type = null) |
|
726 | 726 | { |
727 | 727 | $db = isset($GLOBALS['egw_setup']->db) ? $GLOBALS['egw_setup']->db : $GLOBALS['egw']->db; |
728 | 728 | |
729 | 729 | $where = array(); |
730 | 730 | if ($app) $where['preference_app'] = $app; |
731 | 731 | |
732 | - switch($type) |
|
732 | + switch ($type) |
|
733 | 733 | { |
734 | 734 | case 'forced': |
735 | 735 | $where['preference_owner'] = self::FORCED_ID; |
@@ -744,10 +744,10 @@ discard block |
||
744 | 744 | $where[] = 'preference_owner < '.self::DEFAULT_ID; |
745 | 745 | break; |
746 | 746 | } |
747 | - foreach($db->select(self::TABLE, '*', $where, __LINE__, __FILE__) as $row) |
|
747 | + foreach ($db->select(self::TABLE, '*', $where, __LINE__, __FILE__) as $row) |
|
748 | 748 | { |
749 | 749 | $prefs = self::unserialize($row['preference_value']); |
750 | - if (!is_array($prefs)) $prefs = array(); // would stall update otherwise |
|
750 | + if (!is_array($prefs)) $prefs = array(); // would stall update otherwise |
|
751 | 751 | |
752 | 752 | if ($name[0] == '/' && substr($name, -1) == '/') |
753 | 753 | { |
@@ -762,7 +762,7 @@ discard block |
||
762 | 762 | } |
763 | 763 | |
764 | 764 | $updated = false; |
765 | - foreach($attrs as $attr) |
|
765 | + foreach ($attrs as $attr) |
|
766 | 766 | { |
767 | 767 | if (isset($old_value) && $prefs[$attr] != $old_value) continue; |
768 | 768 | |
@@ -791,7 +791,7 @@ discard block |
||
791 | 791 | |
792 | 792 | // update instance-wide cache |
793 | 793 | $cached = Cache::getInstance(__CLASS__, $row['preference_owner']); |
794 | - if($cached && $cached[$row['preference_app']]) |
|
794 | + if ($cached && $cached[$row['preference_app']]) |
|
795 | 795 | { |
796 | 796 | $cached[$row['preference_app']] = $prefs; |
797 | 797 | Cache::setInstance(__CLASS__, $row['preference_owner'], $cached); |
@@ -807,7 +807,7 @@ discard block |
||
807 | 807 | * @param string $name Preference name |
808 | 808 | * @param string $type ='user' of preference to set: forced, default, user |
809 | 809 | */ |
810 | - public static function delete_preference($app, $name, $type='user') |
|
810 | + public static function delete_preference($app, $name, $type = 'user') |
|
811 | 811 | { |
812 | 812 | self::change_preference($app, $name, null, null, $type); |
813 | 813 | } |
@@ -819,12 +819,12 @@ discard block |
||
819 | 819 | * @param string $to_app |
820 | 820 | * @param array $names =null array of names to copy or null for all |
821 | 821 | */ |
822 | - public static function copy_preferences($from_app, $to_app, array $names=null) |
|
822 | + public static function copy_preferences($from_app, $to_app, array $names = null) |
|
823 | 823 | { |
824 | 824 | //error_log(__METHOD__."('$from_app', '$to_app', ".array2string($names).')'); |
825 | 825 | $db = isset($GLOBALS['egw_setup']->db) ? $GLOBALS['egw_setup']->db : $GLOBALS['egw']->db; |
826 | 826 | |
827 | - foreach($db->select(self::TABLE, '*', array('preference_app' => $from_app), __LINE__, __FILE__) as $row) |
|
827 | + foreach ($db->select(self::TABLE, '*', array('preference_app' => $from_app), __LINE__, __FILE__) as $row) |
|
828 | 828 | { |
829 | 829 | $prefs = self::unserialize($row['preference_value']); |
830 | 830 | |
@@ -832,7 +832,7 @@ discard block |
||
832 | 832 | { |
833 | 833 | $prefs = array_intersect_key($prefs, array_flip($names)); |
834 | 834 | } |
835 | - if (!$prefs) continue; // nothing to change, as nothing set |
|
835 | + if (!$prefs) continue; // nothing to change, as nothing set |
|
836 | 836 | |
837 | 837 | $row['preference_app'] = $to_app; |
838 | 838 | unset($row['preference_value']); |
@@ -866,11 +866,11 @@ discard block |
||
866 | 866 | * @param boolean $invalid_cache =true should we invalidate the cache, default true (not used anymore) |
867 | 867 | * @return array with new effective prefs (even when forced or default prefs are deleted!) |
868 | 868 | */ |
869 | - function save_repository($update_session_info = False,$type='user',$invalid_cache=true) |
|
869 | + function save_repository($update_session_info = False, $type = 'user', $invalid_cache = true) |
|
870 | 870 | { |
871 | - unset($update_session_info, $invalid_cache); // no longer used |
|
871 | + unset($update_session_info, $invalid_cache); // no longer used |
|
872 | 872 | |
873 | - switch($type) |
|
873 | + switch ($type) |
|
874 | 874 | { |
875 | 875 | case 'forced': |
876 | 876 | $account_id = self::FORCED_ID; |
@@ -885,17 +885,17 @@ discard block |
||
885 | 885 | |
886 | 886 | default: |
887 | 887 | $account_id = (int)$this->account_id; |
888 | - $prefs = &$this->user; // we use the user-array as data contains default values too |
|
888 | + $prefs = &$this->user; // we use the user-array as data contains default values too |
|
889 | 889 | break; |
890 | 890 | } |
891 | 891 | //echo "<p>preferences::save_repository(,$type): account_id=$account_id, prefs="; print_r($prefs); echo "</p>\n"; |
892 | 892 | |
893 | - if (isset($GLOBALS['egw_setup']) || !$GLOBALS['egw']->acl->check('session_only_preferences',1,'preferences') && |
|
893 | + if (isset($GLOBALS['egw_setup']) || !$GLOBALS['egw']->acl->check('session_only_preferences', 1, 'preferences') && |
|
894 | 894 | (!($old_prefs = $this->cache_read($account_id)) || $old_prefs != $prefs)) |
895 | 895 | { |
896 | 896 | //error_log(__METHOD__."(type=$type) saved, because old_prefs[$account_id] != prefs=".array2string($prefs)); |
897 | 897 | $changed = 0; |
898 | - foreach($prefs as $app => $value) |
|
898 | + foreach ($prefs as $app => $value) |
|
899 | 899 | { |
900 | 900 | // check if app preferences have changed, if not no need to save them |
901 | 901 | if ($old_prefs && $old_prefs[$app] == $value) continue; |
@@ -912,12 +912,12 @@ discard block |
||
912 | 912 | } |
913 | 913 | else |
914 | 914 | { |
915 | - $this->db->insert($this->table,array( |
|
915 | + $this->db->insert($this->table, array( |
|
916 | 916 | 'preference_value' => json_encode($value), |
917 | - ),array( |
|
917 | + ), array( |
|
918 | 918 | 'preference_owner' => $account_id, |
919 | 919 | 'preference_app' => $app, |
920 | - ),__LINE__,__FILE__); |
|
920 | + ), __LINE__, __FILE__); |
|
921 | 921 | } |
922 | 922 | } |
923 | 923 | if ($changed) |
@@ -944,21 +944,21 @@ discard block |
||
944 | 944 | * @param int $account_id as determined in and/or passed to "create_email_preferences" |
945 | 945 | * @return string with email-address |
946 | 946 | */ |
947 | - function email_address($account_id='') |
|
947 | + function email_address($account_id = '') |
|
948 | 948 | { |
949 | 949 | if (isset($this->data['email']['address'])) |
950 | 950 | { |
951 | 951 | return $this->data['email']['address']; |
952 | 952 | } |
953 | 953 | // if email-address is set in the account, return it |
954 | - if (($email = Accounts::id2name($account_id,'account_email'))) |
|
954 | + if (($email = Accounts::id2name($account_id, 'account_email'))) |
|
955 | 955 | { |
956 | 956 | return $email; |
957 | 957 | } |
958 | 958 | $prefs_email_address = Accounts::id2name($account_id); |
959 | - if ($prefs_email_address && strpos($prefs_email_address,'@') === False) |
|
959 | + if ($prefs_email_address && strpos($prefs_email_address, '@') === False) |
|
960 | 960 | { |
961 | - $prefs_email_address .= '@' . $GLOBALS['egw_info']['server']['mail_suffix']; |
|
961 | + $prefs_email_address .= '@'.$GLOBALS['egw_info']['server']['mail_suffix']; |
|
962 | 962 | } |
963 | 963 | return $prefs_email_address; |
964 | 964 | } |
@@ -972,7 +972,7 @@ discard block |
||
972 | 972 | * @param $charset =null default system charset |
973 | 973 | * @return string the local (or best estimate) set |
974 | 974 | */ |
975 | - static function setlocale($category=LC_ALL,$charset=null) |
|
975 | + static function setlocale($category = LC_ALL, $charset = null) |
|
976 | 976 | { |
977 | 977 | $lang = $GLOBALS['egw_info']['user']['preferences']['common']['lang']; |
978 | 978 | $country = $GLOBALS['egw_info']['user']['preferences']['common']['country']; |
@@ -983,12 +983,12 @@ discard block |
||
983 | 983 | } |
984 | 984 | else |
985 | 985 | { |
986 | - list($lang,$lang2) = explode('-',$lang); |
|
986 | + list($lang, $lang2) = explode('-', $lang); |
|
987 | 987 | $country_from_lang = strtoupper($lang2); |
988 | 988 | } |
989 | 989 | if (is_null($charset)) $charset = Translation::charset(); |
990 | 990 | |
991 | - foreach(array( |
|
991 | + foreach (array( |
|
992 | 992 | $lang.'_'.$country, |
993 | 993 | $lang.'_'.$country_from_lang, |
994 | 994 | $lang, |
@@ -996,14 +996,14 @@ discard block |
||
996 | 996 | 'C', |
997 | 997 | ) as $local) |
998 | 998 | { |
999 | - if (($ret = setlocale($category,$local.'@'.$charset)) || |
|
1000 | - ($ret = setlocale($category,$local))) |
|
999 | + if (($ret = setlocale($category, $local.'@'.$charset)) || |
|
1000 | + ($ret = setlocale($category, $local))) |
|
1001 | 1001 | { |
1002 | 1002 | //error_log(__METHOD__."($category,$charset) lang=$lang, country=$country, country_from_lang=$country_from_lang: returning '$ret'"); |
1003 | 1003 | return $ret; |
1004 | 1004 | } |
1005 | 1005 | } |
1006 | 1006 | error_log(__METHOD__."($category,$charset) lang=$lang, country=$country, country_from_lang=$country_from_lang: Could not set local!"); |
1007 | - return false; // should not happen, as the 'C' local should at least be available everywhere |
|
1007 | + return false; // should not happen, as the 'C' local should at least be available everywhere |
|
1008 | 1008 | } |
1009 | 1009 | } |
@@ -196,7 +196,10 @@ discard block |
||
196 | 196 | foreach((array)$ids as $id) |
197 | 197 | { |
198 | 198 | // if prefs are not returned, null or not an array, read them from db |
199 | - if (!isset($prefs[$id]) && !is_array($prefs[$id])) $db_read[] = $id; |
|
199 | + if (!isset($prefs[$id]) && !is_array($prefs[$id])) |
|
200 | + { |
|
201 | + $db_read[] = $id; |
|
202 | + } |
|
200 | 203 | } |
201 | 204 | if ($db_read) |
202 | 205 | { |
@@ -209,7 +212,10 @@ discard block |
||
209 | 212 | } |
210 | 213 | foreach($db_read as $id) |
211 | 214 | { |
212 | - if (!isset($prefs[$id])) $prefs[$id] = array(); |
|
215 | + if (!isset($prefs[$id])) |
|
216 | + { |
|
217 | + $prefs[$id] = array(); |
|
218 | + } |
|
213 | 219 | Cache::setInstance(__CLASS__, $id, $prefs[$id]); |
214 | 220 | } |
215 | 221 | } |
@@ -237,7 +243,10 @@ discard block |
||
237 | 243 | $replace = $with = array(); |
238 | 244 | foreach($vals as $key => $val) |
239 | 245 | { |
240 | - if ($this->debug) error_log(__METHOD__." replacing \$\$$key\$\$ with $val "); |
|
246 | + if ($this->debug) |
|
247 | + { |
|
248 | + error_log(__METHOD__." replacing \$\$$key\$\$ with $val "); |
|
249 | + } |
|
241 | 250 | $replace[] = '$$'.$key.'$$'; |
242 | 251 | $with[] = $val; |
243 | 252 | } |
@@ -275,7 +284,10 @@ discard block |
||
275 | 284 | */ |
276 | 285 | function standard_substitutes() |
277 | 286 | { |
278 | - if ($this->debug) error_log(__METHOD__." is called "); |
|
287 | + if ($this->debug) |
|
288 | + { |
|
289 | + error_log(__METHOD__." is called "); |
|
290 | + } |
|
279 | 291 | if (!is_array(@$GLOBALS['egw_info']['user']['preferences'])) |
280 | 292 | { |
281 | 293 | $GLOBALS['egw_info']['user']['preferences'] = $this->data; // else no lang() |
@@ -301,12 +313,18 @@ discard block |
||
301 | 313 | 'email' => lang('email-address of the user, eg. "%1"',$this->values['email']), |
302 | 314 | 'date' => lang('todays date, eg. "%1"',$this->values['date']), |
303 | 315 | ); |
304 | - if ($this->debug) error_log(__METHOD__.print_r($this->vars,true)); |
|
316 | + if ($this->debug) |
|
317 | + { |
|
318 | + error_log(__METHOD__.print_r($this->vars,true)); |
|
319 | + } |
|
305 | 320 | // do the substituetion in the effective prefs (data) |
306 | 321 | // |
307 | 322 | foreach($this->data as $app => $data) |
308 | 323 | { |
309 | - if(!is_array($data)) continue; |
|
324 | + if(!is_array($data)) |
|
325 | + { |
|
326 | + continue; |
|
327 | + } |
|
310 | 328 | foreach($data as $key => $val) |
311 | 329 | { |
312 | 330 | if (!is_array($val) && strpos($val,'$$') !== False) |
@@ -401,7 +419,11 @@ discard block |
||
401 | 419 | $primary_group = Accounts::id2name($this->account_id, 'account_primary_group'); |
402 | 420 | foreach((array)$GLOBALS['egw']->accounts->memberships($this->account_id, true) as $gid) |
403 | 421 | { |
404 | - if ($gid != $primary_group) $to_read[] = $gid + self::DEFAULT_ID; // need to offset it with DEFAULT_ID = -2! |
|
422 | + if ($gid != $primary_group) |
|
423 | + { |
|
424 | + $to_read[] = $gid + self::DEFAULT_ID; |
|
425 | + } |
|
426 | + // need to offset it with DEFAULT_ID = -2! |
|
405 | 427 | } |
406 | 428 | $to_read[] = $primary_group + self::DEFAULT_ID; |
407 | 429 | } |
@@ -508,9 +530,15 @@ discard block |
||
508 | 530 | // Etemplate::complete_array_merge() is identical to PHP >= 5.3 array_replace_recursive() |
509 | 531 | $default = Etemplate::complete_array_merge($this->default, $this->forced); |
510 | 532 | |
511 | - if ($app) $default = $default[$app]; |
|
533 | + if ($app) |
|
534 | + { |
|
535 | + $default = $default[$app]; |
|
536 | + } |
|
512 | 537 | |
513 | - if ($name && is_array($default)) $default = $default[$name]; |
|
538 | + if ($name && is_array($default)) |
|
539 | + { |
|
540 | + $default = $default[$name]; |
|
541 | + } |
|
514 | 542 | |
515 | 543 | return $default; |
516 | 544 | } |
@@ -588,9 +616,13 @@ discard block |
||
588 | 616 | { |
589 | 617 | $this->session[$app_name][$var] = $this->data[$app_name][$var] = $value; |
590 | 618 | Cache::setSession('preferences','preferences',$this->session); |
591 | - if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
619 | + if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) |
|
620 | + { |
|
621 | + // egw object in setup is limited |
|
592 | 622 | { |
593 | - $GLOBALS['egw']->invalidate_session_cache(); // in case with cache the egw_info array in the session |
|
623 | + $GLOBALS['egw']->invalidate_session_cache(); |
|
624 | + } |
|
625 | + // in case with cache the egw_info array in the session |
|
594 | 626 | } |
595 | 627 | } |
596 | 628 | break; |
@@ -646,9 +678,12 @@ discard block |
||
646 | 678 | } |
647 | 679 | $pref = &$this->$type; |
648 | 680 | |
649 | - if (($all = empty($var))) // to check if $var is regarded as empty (false, 0, '', null, array() should do the trick |
|
681 | + if (($all = empty($var))) |
|
682 | + { |
|
683 | + // to check if $var is regarded as empty (false, 0, '', null, array() should do the trick |
|
650 | 684 | { |
651 | 685 | unset($pref[$app_name]); |
686 | + } |
|
652 | 687 | unset($this->data[$app_name]); |
653 | 688 | } |
654 | 689 | else |
@@ -727,7 +762,10 @@ discard block |
||
727 | 762 | $db = isset($GLOBALS['egw_setup']->db) ? $GLOBALS['egw_setup']->db : $GLOBALS['egw']->db; |
728 | 763 | |
729 | 764 | $where = array(); |
730 | - if ($app) $where['preference_app'] = $app; |
|
765 | + if ($app) |
|
766 | + { |
|
767 | + $where['preference_app'] = $app; |
|
768 | + } |
|
731 | 769 | |
732 | 770 | switch($type) |
733 | 771 | { |
@@ -747,7 +785,11 @@ discard block |
||
747 | 785 | foreach($db->select(self::TABLE, '*', $where, __LINE__, __FILE__) as $row) |
748 | 786 | { |
749 | 787 | $prefs = self::unserialize($row['preference_value']); |
750 | - if (!is_array($prefs)) $prefs = array(); // would stall update otherwise |
|
788 | + if (!is_array($prefs)) |
|
789 | + { |
|
790 | + $prefs = array(); |
|
791 | + } |
|
792 | + // would stall update otherwise |
|
751 | 793 | |
752 | 794 | if ($name[0] == '/' && substr($name, -1) == '/') |
753 | 795 | { |
@@ -764,10 +806,16 @@ discard block |
||
764 | 806 | $updated = false; |
765 | 807 | foreach($attrs as $attr) |
766 | 808 | { |
767 | - if (isset($old_value) && $prefs[$attr] != $old_value) continue; |
|
809 | + if (isset($old_value) && $prefs[$attr] != $old_value) |
|
810 | + { |
|
811 | + continue; |
|
812 | + } |
|
768 | 813 | |
769 | 814 | $val = is_callable($value) ? call_user_func($value, $attr, $prefs[$attr], $row['preference_owner']) : $value; |
770 | - if ($val === $prefs[$attr]) continue; |
|
815 | + if ($val === $prefs[$attr]) |
|
816 | + { |
|
817 | + continue; |
|
818 | + } |
|
771 | 819 | |
772 | 820 | $updated = true; |
773 | 821 | if ((string)$val !== '') |
@@ -832,7 +880,11 @@ discard block |
||
832 | 880 | { |
833 | 881 | $prefs = array_intersect_key($prefs, array_flip($names)); |
834 | 882 | } |
835 | - if (!$prefs) continue; // nothing to change, as nothing set |
|
883 | + if (!$prefs) |
|
884 | + { |
|
885 | + continue; |
|
886 | + } |
|
887 | + // nothing to change, as nothing set |
|
836 | 888 | |
837 | 889 | $row['preference_app'] = $to_app; |
838 | 890 | unset($row['preference_value']); |
@@ -898,9 +950,15 @@ discard block |
||
898 | 950 | foreach($prefs as $app => $value) |
899 | 951 | { |
900 | 952 | // check if app preferences have changed, if not no need to save them |
901 | - if ($old_prefs && $old_prefs[$app] == $value) continue; |
|
953 | + if ($old_prefs && $old_prefs[$app] == $value) |
|
954 | + { |
|
955 | + continue; |
|
956 | + } |
|
902 | 957 | |
903 | - if (!$changed++) $this->db->transaction_begin(); |
|
958 | + if (!$changed++) |
|
959 | + { |
|
960 | + $this->db->transaction_begin(); |
|
961 | + } |
|
904 | 962 | |
905 | 963 | if (!is_array($value) || !$value) |
906 | 964 | { |
@@ -986,7 +1044,10 @@ discard block |
||
986 | 1044 | list($lang,$lang2) = explode('-',$lang); |
987 | 1045 | $country_from_lang = strtoupper($lang2); |
988 | 1046 | } |
989 | - if (is_null($charset)) $charset = Translation::charset(); |
|
1047 | + if (is_null($charset)) |
|
1048 | + { |
|
1049 | + $charset = Translation::charset(); |
|
1050 | + } |
|
990 | 1051 | |
991 | 1052 | foreach(array( |
992 | 1053 | $lang.'_'.$country, |
@@ -311,6 +311,7 @@ discard block |
||
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 |
||
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 |
||
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 | */ |
@@ -80,60 +80,60 @@ discard block |
||
80 | 80 | const MCRYPT_MODE = MCRYPT_MODE_ECB; |
81 | 81 | |
82 | 82 | /** |
83 | - * current user login (account_lid@domain) |
|
84 | - * |
|
85 | - * @var string |
|
86 | - */ |
|
83 | + * current user login (account_lid@domain) |
|
84 | + * |
|
85 | + * @var string |
|
86 | + */ |
|
87 | 87 | var $login; |
88 | 88 | |
89 | 89 | /** |
90 | - * current user password |
|
91 | - * |
|
92 | - * @var string |
|
93 | - */ |
|
90 | + * current user password |
|
91 | + * |
|
92 | + * @var string |
|
93 | + */ |
|
94 | 94 | var $passwd; |
95 | 95 | |
96 | 96 | /** |
97 | - * current user db/ldap account id |
|
98 | - * |
|
99 | - * @var int |
|
100 | - */ |
|
97 | + * current user db/ldap account id |
|
98 | + * |
|
99 | + * @var int |
|
100 | + */ |
|
101 | 101 | var $account_id; |
102 | 102 | |
103 | 103 | /** |
104 | - * current user account login id (without the eGW-domain/-instance part |
|
105 | - * |
|
106 | - * @var string |
|
107 | - */ |
|
104 | + * current user account login id (without the eGW-domain/-instance part |
|
105 | + * |
|
106 | + * @var string |
|
107 | + */ |
|
108 | 108 | var $account_lid; |
109 | 109 | |
110 | 110 | /** |
111 | - * domain for current user |
|
112 | - * |
|
113 | - * @var string |
|
114 | - */ |
|
111 | + * domain for current user |
|
112 | + * |
|
113 | + * @var string |
|
114 | + */ |
|
115 | 115 | var $account_domain; |
116 | 116 | |
117 | 117 | /** |
118 | - * type flag, A - anonymous session, N - None, normal session |
|
119 | - * |
|
120 | - * @var string |
|
121 | - */ |
|
118 | + * type flag, A - anonymous session, N - None, normal session |
|
119 | + * |
|
120 | + * @var string |
|
121 | + */ |
|
122 | 122 | var $session_flags; |
123 | 123 | |
124 | 124 | /** |
125 | - * current user session id |
|
126 | - * |
|
127 | - * @var string |
|
128 | - */ |
|
125 | + * current user session id |
|
126 | + * |
|
127 | + * @var string |
|
128 | + */ |
|
129 | 129 | var $sessionid; |
130 | 130 | |
131 | 131 | /** |
132 | - * an other session specific id (md5 from a random string), |
|
133 | - * used together with the sessionid for xmlrpc basic auth and the encryption of session-data (if that's enabled) |
|
134 | - * |
|
135 | - * @var string |
|
136 | - */ |
|
132 | + * an other session specific id (md5 from a random string), |
|
133 | + * used together with the sessionid for xmlrpc basic auth and the encryption of session-data (if that's enabled) |
|
134 | + * |
|
135 | + * @var string |
|
136 | + */ |
|
137 | 137 | var $kp3; |
138 | 138 | |
139 | 139 | /** |
@@ -144,17 +144,17 @@ discard block |
||
144 | 144 | var $sessionid_access_log; |
145 | 145 | |
146 | 146 | /** |
147 | - * name of XML-RPC/SOAP method called |
|
148 | - * |
|
149 | - * @var string |
|
150 | - */ |
|
147 | + * name of XML-RPC/SOAP method called |
|
148 | + * |
|
149 | + * @var string |
|
150 | + */ |
|
151 | 151 | var $xmlrpc_method_called; |
152 | 152 | |
153 | 153 | /** |
154 | - * Array with the name of the system domains |
|
155 | - * |
|
156 | - * @var array |
|
157 | - */ |
|
154 | + * Array with the name of the system domains |
|
155 | + * |
|
156 | + * @var array |
|
157 | + */ |
|
158 | 158 | private $egw_domains; |
159 | 159 | |
160 | 160 | /** |
@@ -248,9 +248,9 @@ discard block |
||
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 | - { |
|
252 | - ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout']=14400); |
|
253 | - } |
|
251 | + { |
|
252 | + ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout']=14400); |
|
253 | + } |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | /** |
@@ -661,14 +661,14 @@ discard block |
||
661 | 661 | const ACCESS_LOG_TABLE = 'egw_access_log'; |
662 | 662 | |
663 | 663 | /** |
664 | - * Write or update (for logout) the access_log |
|
665 | - * |
|
666 | - * @param string|int $sessionid nummeric or PHP session id or 0 for unsuccessful logins |
|
667 | - * @param string $login ='' account_lid (evtl. with domain) or '' for setting the logout-time |
|
668 | - * @param string $user_ip ='' ip to log |
|
669 | - * @param int $account_id =0 numerical account_id |
|
670 | - * @return int $sessionid primary key of egw_access_log for login, null otherwise |
|
671 | - */ |
|
664 | + * Write or update (for logout) the access_log |
|
665 | + * |
|
666 | + * @param string|int $sessionid nummeric or PHP session id or 0 for unsuccessful logins |
|
667 | + * @param string $login ='' account_lid (evtl. with domain) or '' for setting the logout-time |
|
668 | + * @param string $user_ip ='' ip to log |
|
669 | + * @param int $account_id =0 numerical account_id |
|
670 | + * @return int $sessionid primary key of egw_access_log for login, null otherwise |
|
671 | + */ |
|
672 | 672 | private function log_access($sessionid,$login='',$user_ip='',$account_id=0) |
673 | 673 | { |
674 | 674 | $now = time(); |
@@ -716,7 +716,7 @@ discard block |
||
716 | 716 | |
717 | 717 | /** |
718 | 718 | * Protect against brute force attacks, block login if too many unsuccessful login attmepts |
719 | - * |
|
719 | + * |
|
720 | 720 | * @param string $login account_lid (evtl. with domain) |
721 | 721 | * @param string $ip ip of the user |
722 | 722 | * @returns bool login blocked? |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | const CD_BAD_LOGIN_OR_PASSWORD = 5; |
174 | 174 | const CD_FORCE_PASSWORD_CHANGE = 97; |
175 | 175 | const CD_ACCOUNT_EXPIRED = 98; |
176 | - const CD_BLOCKED = 99; // to many failed attempts to loing |
|
176 | + const CD_BLOCKED = 99; // to many failed attempts to loing |
|
177 | 177 | |
178 | 178 | /** |
179 | 179 | * Verbose reason why session creation failed |
@@ -187,7 +187,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 | |
@@ -319,15 +319,15 @@ discard block |
||
319 | 319 | |
320 | 320 | if (!isset($_SESSION[self::EGW_SESSION_ENCRYPTED]) && self::init_crypt($kp3)) |
321 | 321 | { |
322 | - foreach(self::$egw_session_vars as $name) |
|
322 | + foreach (self::$egw_session_vars as $name) |
|
323 | 323 | { |
324 | 324 | if (isset($_SESSION[$name])) |
325 | 325 | { |
326 | - $_SESSION[$name] = mcrypt_generic(self::$mcrypt,serialize($_SESSION[$name])); |
|
326 | + $_SESSION[$name] = mcrypt_generic(self::$mcrypt, serialize($_SESSION[$name])); |
|
327 | 327 | //error_log(__METHOD__."() 'encrypting' session var: $name, len=".strlen($_SESSION[$name])); |
328 | 328 | } |
329 | 329 | } |
330 | - $_SESSION[self::EGW_SESSION_ENCRYPTED] = true; // flag session as encrypted |
|
330 | + $_SESSION[self::EGW_SESSION_ENCRYPTED] = true; // flag session as encrypted |
|
331 | 331 | |
332 | 332 | mcrypt_generic_deinit(self::$mcrypt); |
333 | 333 | self::$mcrypt = null; |
@@ -342,24 +342,24 @@ discard block |
||
342 | 342 | * @param boolean $recursion =true if true call itself for every item > $limit |
343 | 343 | * @param int $limit =1000 log only differences > $limit |
344 | 344 | */ |
345 | - static function log_session_usage(&$arr,$label,$recursion=true,$limit=1000) |
|
345 | + static function log_session_usage(&$arr, $label, $recursion = true, $limit = 1000) |
|
346 | 346 | { |
347 | 347 | if (!is_array($arr)) return; |
348 | 348 | |
349 | 349 | $sizes = array(); |
350 | - foreach($arr as $key => &$data) |
|
350 | + foreach ($arr as $key => &$data) |
|
351 | 351 | { |
352 | 352 | $sizes[$key] = strlen(serialize($data)); |
353 | 353 | } |
354 | - arsort($sizes,SORT_NUMERIC); |
|
355 | - foreach($sizes as $key => $size) |
|
354 | + arsort($sizes, SORT_NUMERIC); |
|
355 | + foreach ($sizes as $key => $size) |
|
356 | 356 | { |
357 | 357 | $diff = $size - (int)$_SESSION[$label.'-sizes'][$key]; |
358 | 358 | $_SESSION[$label.'-sizes'][$key] = $size; |
359 | 359 | if ($diff > $limit) |
360 | 360 | { |
361 | 361 | error_log("strlen({$label}[$key])=".Vfs::hsize($size).", diff=".Vfs::hsize($diff)); |
362 | - if ($recursion) self::log_session_usage($arr[$key],$label.'['.$key.']',$recursion,$limit); |
|
362 | + if ($recursion) self::log_session_usage($arr[$key], $label.'['.$key.']', $recursion, $limit); |
|
363 | 363 | } |
364 | 364 | } |
365 | 365 | } |
@@ -374,15 +374,15 @@ discard block |
||
374 | 374 | { |
375 | 375 | if ($_SESSION[self::EGW_SESSION_ENCRYPTED] && self::init_crypt(self::get_request('kp3'))) |
376 | 376 | { |
377 | - foreach(self::$egw_session_vars as $name) |
|
377 | + foreach (self::$egw_session_vars as $name) |
|
378 | 378 | { |
379 | 379 | if (isset($_SESSION[$name])) |
380 | 380 | { |
381 | - $_SESSION[$name] = unserialize(trim(mdecrypt_generic(self::$mcrypt,$_SESSION[$name]))); |
|
381 | + $_SESSION[$name] = unserialize(trim(mdecrypt_generic(self::$mcrypt, $_SESSION[$name]))); |
|
382 | 382 | //error_log(__METHOD__."() 'decrypting' session var $name: gettype($name) = ".gettype($_SESSION[$name])); |
383 | 383 | } |
384 | 384 | } |
385 | - unset($_SESSION[self::EGW_SESSION_ENCRYPTED]); // delete encryption flag |
|
385 | + unset($_SESSION[self::EGW_SESSION_ENCRYPTED]); // delete encryption flag |
|
386 | 386 | } |
387 | 387 | } |
388 | 388 | |
@@ -395,15 +395,15 @@ discard block |
||
395 | 395 | * @param string $mode =self::MCRYPT_MODE |
396 | 396 | * @return boolean true if encryption is used, false otherwise |
397 | 397 | */ |
398 | - static private function init_crypt($kp3,$algo=self::MCRYPT_ALGO,$mode=self::MCRYPT_MODE) |
|
398 | + static private function init_crypt($kp3, $algo = self::MCRYPT_ALGO, $mode = self::MCRYPT_MODE) |
|
399 | 399 | { |
400 | - if(!$GLOBALS['egw_info']['server']['mcrypt_enabled']) |
|
400 | + if (!$GLOBALS['egw_info']['server']['mcrypt_enabled']) |
|
401 | 401 | { |
402 | - return false; // session encryption is switched off |
|
402 | + return false; // session encryption is switched off |
|
403 | 403 | } |
404 | 404 | if ($GLOBALS['egw_info']['currentapp'] == 'syncml' || !$kp3) |
405 | 405 | { |
406 | - $kp3 = 'staticsyncmlkp3'; // syncml has no kp3! |
|
406 | + $kp3 = 'staticsyncmlkp3'; // syncml has no kp3! |
|
407 | 407 | } |
408 | 408 | if (is_null(self::$mcrypt)) |
409 | 409 | { |
@@ -419,9 +419,9 @@ discard block |
||
419 | 419 | } |
420 | 420 | $iv_size = mcrypt_enc_get_iv_size(self::$mcrypt); |
421 | 421 | $iv = !isset($GLOBALS['egw_info']['server']['mcrypt_iv']) || strlen($GLOBALS['egw_info']['server']['mcrypt_iv']) < $iv_size ? |
422 | - mcrypt_create_iv ($iv_size, MCRYPT_RAND) : substr($GLOBALS['egw_info']['server']['mcrypt_iv'],0,$iv_size); |
|
422 | + mcrypt_create_iv($iv_size, MCRYPT_RAND) : substr($GLOBALS['egw_info']['server']['mcrypt_iv'], 0, $iv_size); |
|
423 | 423 | |
424 | - if (mcrypt_generic_init(self::$mcrypt,$kp3, $iv) < 0) |
|
424 | + if (mcrypt_generic_init(self::$mcrypt, $kp3, $iv) < 0) |
|
425 | 425 | { |
426 | 426 | error_log(__METHOD__."() could not initialise mcrypt, sessions get NOT encrypted!"); |
427 | 427 | return self::$mcrypt = false; |
@@ -441,7 +441,7 @@ discard block |
||
441 | 441 | * @param boolean $fail_on_forced_password_change =false true: do NOT create session, if password change requested |
442 | 442 | * @return string|boolean session id or false if session was not created, $this->(cd_)reason contains cause |
443 | 443 | */ |
444 | - function create($login,$passwd = '',$passwd_type = '',$no_session=false,$auth_check=true,$fail_on_forced_password_change=false) |
|
444 | + function create($login, $passwd = '', $passwd_type = '', $no_session = false, $auth_check = true, $fail_on_forced_password_change = false) |
|
445 | 445 | { |
446 | 446 | try { |
447 | 447 | if (is_array($login)) |
@@ -459,9 +459,9 @@ discard block |
||
459 | 459 | } |
460 | 460 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) starting ..."); |
461 | 461 | |
462 | - self::split_login_domain($login,$this->account_lid,$this->account_domain); |
|
462 | + self::split_login_domain($login, $this->account_lid, $this->account_domain); |
|
463 | 463 | // add domain to the login, if not already there |
464 | - if (substr($this->login,-strlen($this->account_domain)-1) != '@'.$this->account_domain) |
|
464 | + if (substr($this->login, -strlen($this->account_domain) - 1) != '@'.$this->account_domain) |
|
465 | 465 | { |
466 | 466 | $this->login .= '@'.$this->account_domain; |
467 | 467 | } |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | { |
479 | 479 | $this->account_domain = $GLOBALS['egw_info']['user']['domain']; |
480 | 480 | } |
481 | - elseif($this->account_domain != $GLOBALS['egw_info']['user']['domain']) |
|
481 | + elseif ($this->account_domain != $GLOBALS['egw_info']['user']['domain']) |
|
482 | 482 | { |
483 | 483 | throw new Exception("Wrong domain! '$this->account_domain' != '{$GLOBALS['egw_info']['user']['domain']}'"); |
484 | 484 | } |
@@ -486,9 +486,9 @@ discard block |
||
486 | 486 | |
487 | 487 | $user_ip = self::getuser_ip(); |
488 | 488 | |
489 | - $this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid,'account_lid','u'); |
|
489 | + $this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid, 'account_lid', 'u'); |
|
490 | 490 | |
491 | - if (($blocked = $this->login_blocked($login,$user_ip)) || // too many unsuccessful attempts |
|
491 | + if (($blocked = $this->login_blocked($login, $user_ip)) || // too many unsuccessful attempts |
|
492 | 492 | $GLOBALS['egw_info']['server']['global_denied_users'][$this->account_lid] || |
493 | 493 | $auth_check && !$GLOBALS['egw']->auth->authenticate($this->account_lid, $this->passwd, $this->passwd_type) || |
494 | 494 | $this->account_id && $GLOBALS['egw']->accounts->get_type($this->account_id) == 'g') |
@@ -497,9 +497,9 @@ discard block |
||
497 | 497 | $this->cd_reason = $blocked ? self::CD_BLOCKED : self::CD_BAD_LOGIN_OR_PASSWORD; |
498 | 498 | |
499 | 499 | // we dont log anon users as it would block the website |
500 | - if (!$GLOBALS['egw']->acl->get_specific_rights_for_account($this->account_id,'anonymous','phpgwapi')) |
|
500 | + if (!$GLOBALS['egw']->acl->get_specific_rights_for_account($this->account_id, 'anonymous', 'phpgwapi')) |
|
501 | 501 | { |
502 | - $this->log_access($this->reason,$login,$user_ip,0); // log unsuccessfull login |
|
502 | + $this->log_access($this->reason, $login, $user_ip, 0); // log unsuccessfull login |
|
503 | 503 | } |
504 | 504 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
505 | 505 | return false; |
@@ -521,7 +521,7 @@ discard block |
||
521 | 521 | if ($this->account_lid != ($lid = $GLOBALS['egw']->accounts->id2name($this->account_id))) |
522 | 522 | { |
523 | 523 | $this->account_lid = $lid; |
524 | - $this->login = $lid.substr($this->login,strlen($lid)); |
|
524 | + $this->login = $lid.substr($this->login, strlen($lid)); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | $GLOBALS['egw_info']['user']['account_id'] = $this->account_id; |
@@ -543,7 +543,7 @@ discard block |
||
543 | 543 | } |
544 | 544 | $this->sessionid = session_id(); |
545 | 545 | } |
546 | - $this->kp3 = Auth::randomstring(24); |
|
546 | + $this->kp3 = Auth::randomstring(24); |
|
547 | 547 | |
548 | 548 | $GLOBALS['egw_info']['user'] = $this->read_repositories(); |
549 | 549 | if ($GLOBALS['egw']->accounts->is_expired($GLOBALS['egw_info']['user'])) |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | |
558 | 558 | Cache::setSession('phpgwapi', 'password', base64_encode($this->passwd)); |
559 | 559 | |
560 | - if ($GLOBALS['egw']->acl->check('anonymous',1,'phpgwapi')) |
|
560 | + if ($GLOBALS['egw']->acl->check('anonymous', 1, 'phpgwapi')) |
|
561 | 561 | { |
562 | 562 | $this->session_flags = 'A'; |
563 | 563 | } |
@@ -575,46 +575,46 @@ discard block |
||
575 | 575 | 'passwd' => $this->passwd, |
576 | 576 | 'account_domain' => $this->account_domain, |
577 | 577 | 'user_ip' => $user_ip, |
578 | - ),'',true))) // true = run hooks from all apps, not just the ones the current user has perms to run |
|
578 | + ), '', true))) // true = run hooks from all apps, not just the ones the current user has perms to run |
|
579 | 579 | { |
580 | - foreach($hook_result as $reason) |
|
580 | + foreach ($hook_result as $reason) |
|
581 | 581 | { |
582 | 582 | if ($reason) // called hook requests to deny the session |
583 | 583 | { |
584 | 584 | $this->reason = $this->cd_reason = $reason; |
585 | - $this->log_access($this->reason,$login,$user_ip,0); // log unsuccessfull login |
|
585 | + $this->log_access($this->reason, $login, $user_ip, 0); // log unsuccessfull login |
|
586 | 586 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
587 | 587 | return false; |
588 | 588 | } |
589 | 589 | } |
590 | 590 | } |
591 | 591 | $GLOBALS['egw']->db->transaction_begin(); |
592 | - $this->register_session($this->login,$user_ip,$now,$this->session_flags); |
|
592 | + $this->register_session($this->login, $user_ip, $now, $this->session_flags); |
|
593 | 593 | if ($this->session_flags != 'A') // dont log anonymous sessions |
594 | 594 | { |
595 | - $this->sessionid_access_log = $this->log_access($this->sessionid,$login,$user_ip,$this->account_id); |
|
595 | + $this->sessionid_access_log = $this->log_access($this->sessionid, $login, $user_ip, $this->account_id); |
|
596 | 596 | } |
597 | 597 | Cache::setSession('phpgwapi', 'account_previous_login', $GLOBALS['egw']->auth->previous_login); |
598 | - $GLOBALS['egw']->accounts->update_lastlogin($this->account_id,$user_ip); |
|
598 | + $GLOBALS['egw']->accounts->update_lastlogin($this->account_id, $user_ip); |
|
599 | 599 | $GLOBALS['egw']->db->transaction_commit(); |
600 | 600 | |
601 | 601 | if ($GLOBALS['egw_info']['server']['usecookies'] && !$no_session) |
602 | 602 | { |
603 | - self::egw_setcookie(self::EGW_SESSION_NAME,$this->sessionid); |
|
604 | - self::egw_setcookie('kp3',$this->kp3); |
|
605 | - self::egw_setcookie('domain',$this->account_domain); |
|
603 | + self::egw_setcookie(self::EGW_SESSION_NAME, $this->sessionid); |
|
604 | + self::egw_setcookie('kp3', $this->kp3); |
|
605 | + self::egw_setcookie('domain', $this->account_domain); |
|
606 | 606 | } |
607 | 607 | if ($GLOBALS['egw_info']['server']['usecookies'] && !$no_session || isset($_COOKIE['last_loginid'])) |
608 | 608 | { |
609 | - self::egw_setcookie('last_loginid', $this->account_lid ,$now+1209600); /* For 2 weeks */ |
|
610 | - self::egw_setcookie('last_domain',$this->account_domain,$now+1209600); |
|
609 | + self::egw_setcookie('last_loginid', $this->account_lid, $now + 1209600); /* For 2 weeks */ |
|
610 | + self::egw_setcookie('last_domain', $this->account_domain, $now + 1209600); |
|
611 | 611 | } |
612 | 612 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) successfull sessionid=$this->sessionid"); |
613 | 613 | |
614 | 614 | return $this->sessionid; |
615 | 615 | } |
616 | 616 | // catch all exceptions, as their (allways logged) trace (eg. on a database error) would contain the user password |
617 | - catch(Exception $e) { |
|
617 | + catch (Exception $e) { |
|
618 | 618 | $this->reason = $this->cd_reason = $e->getMessage(); |
619 | 619 | error_log(__METHOD__."('$login', ".array2string(str_repeat('*', strlen($passwd))). |
620 | 620 | ", '$passwd_type', no_session=".array2string($no_session). |
@@ -633,13 +633,12 @@ discard block |
||
633 | 633 | * @param int $now |
634 | 634 | * @param string $session_flags |
635 | 635 | */ |
636 | - private function register_session($login,$user_ip,$now,$session_flags) |
|
636 | + private function register_session($login, $user_ip, $now, $session_flags) |
|
637 | 637 | { |
638 | 638 | // restore session vars set before session was started |
639 | 639 | if (is_array($this->required_files)) |
640 | 640 | { |
641 | - $_SESSION[self::EGW_REQUIRED_FILES] = !is_array($_SESSION[self::EGW_REQUIRED_FILES]) ? $this->required_files : |
|
642 | - array_unique(array_merge($_SESSION[self::EGW_REQUIRED_FILES],$this->required_files)); |
|
641 | + $_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)); |
|
643 | 642 | unset($this->required_files); |
644 | 643 | } |
645 | 644 | $_SESSION[self::EGW_SESSION_VAR] = array( |
@@ -669,13 +668,13 @@ discard block |
||
669 | 668 | * @param int $account_id =0 numerical account_id |
670 | 669 | * @return int $sessionid primary key of egw_access_log for login, null otherwise |
671 | 670 | */ |
672 | - private function log_access($sessionid,$login='',$user_ip='',$account_id=0) |
|
671 | + private function log_access($sessionid, $login = '', $user_ip = '', $account_id = 0) |
|
673 | 672 | { |
674 | 673 | $now = time(); |
675 | 674 | |
676 | 675 | if ($login) |
677 | 676 | { |
678 | - $GLOBALS['egw']->db->insert(self::ACCESS_LOG_TABLE,array( |
|
677 | + $GLOBALS['egw']->db->insert(self::ACCESS_LOG_TABLE, array( |
|
679 | 678 | 'session_php' => $sessionid, |
680 | 679 | 'loginid' => $login, |
681 | 680 | 'ip' => $user_ip, |
@@ -683,10 +682,10 @@ discard block |
||
683 | 682 | 'account_id'=> $account_id, |
684 | 683 | 'user_agent'=> $_SERVER['HTTP_USER_AGENT'], |
685 | 684 | 'session_dla' => $now, |
686 | - 'session_action' => $this->update_dla(false), // dont update egw_access_log |
|
687 | - ),false,__LINE__,__FILE__); |
|
685 | + 'session_action' => $this->update_dla(false), // dont update egw_access_log |
|
686 | + ), false, __LINE__, __FILE__); |
|
688 | 687 | |
689 | - $ret = $GLOBALS['egw']->db->get_last_insert_id(self::ACCESS_LOG_TABLE,'sessionid'); |
|
688 | + $ret = $GLOBALS['egw']->db->get_last_insert_id(self::ACCESS_LOG_TABLE, 'sessionid'); |
|
690 | 689 | } |
691 | 690 | else |
692 | 691 | { |
@@ -694,20 +693,20 @@ discard block |
||
694 | 693 | { |
695 | 694 | $sessionid = $this->sessionid_access_log; |
696 | 695 | } |
697 | - $GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE,array( |
|
696 | + $GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE, array( |
|
698 | 697 | 'lo' => $now |
699 | - ),is_numeric($sessionid) ? array( |
|
698 | + ), is_numeric($sessionid) ? array( |
|
700 | 699 | 'sessionid' => $sessionid, |
701 | 700 | ) : array( |
702 | 701 | 'session_php' => $sessionid, |
703 | - ),__LINE__,__FILE__); |
|
702 | + ), __LINE__, __FILE__); |
|
704 | 703 | |
705 | 704 | // run maintenance only on logout, to not delay login |
706 | 705 | if ($GLOBALS['egw_info']['server']['max_access_log_age']) |
707 | 706 | { |
708 | 707 | $max_age = $now - $GLOBALS['egw_info']['server']['max_access_log_age'] * 24 * 60 * 60; |
709 | 708 | |
710 | - $GLOBALS['egw']->db->delete(self::ACCESS_LOG_TABLE,"li < $max_age",__LINE__,__FILE__); |
|
709 | + $GLOBALS['egw']->db->delete(self::ACCESS_LOG_TABLE, "li < $max_age", __LINE__, __FILE__); |
|
711 | 710 | } |
712 | 711 | } |
713 | 712 | //error_log(__METHOD__."('$sessionid', '$login', '$user_ip', $account_id) returning ".array2string($ret)); |
@@ -721,12 +720,12 @@ discard block |
||
721 | 720 | * @param string $ip ip of the user |
722 | 721 | * @returns bool login blocked? |
723 | 722 | */ |
724 | - private function login_blocked($login,$ip) |
|
723 | + private function login_blocked($login, $ip) |
|
725 | 724 | { |
726 | 725 | $block_time = time() - $GLOBALS['egw_info']['server']['block_time'] * 60; |
727 | 726 | |
728 | 727 | $false_id = $false_ip = 0; |
729 | - foreach($GLOBALS['egw']->db->union(array( |
|
728 | + foreach ($GLOBALS['egw']->db->union(array( |
|
730 | 729 | array( |
731 | 730 | 'table' => self::ACCESS_LOG_TABLE, |
732 | 731 | 'cols' => "'false_ip' AS name,COUNT(*) AS num", |
@@ -763,28 +762,28 @@ discard block |
||
763 | 762 | //error_log(__METHOD__."('$login', '$ip') false_ip=$false_ip, false_id=$false_id --> blocked=".array2string($blocked)); |
764 | 763 | |
765 | 764 | if ($blocked && $GLOBALS['egw_info']['server']['admin_mails'] && |
766 | - $GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time()-5*60) // max. one mail every 5mins |
|
765 | + $GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time() - 5 * 60) // max. one mail every 5mins |
|
767 | 766 | { |
768 | 767 | try { |
769 | 768 | $mailer = new Mailer(); |
770 | 769 | // notify admin(s) via email |
771 | 770 | $mailer->setFrom('eGroupWare@'.$GLOBALS['egw_info']['server']['mail_suffix']); |
772 | - $mailer->addHeader('Subject', lang("eGroupWare: login blocked for user '%1', IP %2",$login,$ip)); |
|
773 | - $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)); |
|
774 | - foreach(preg_split('/,\s*/',$GLOBALS['egw_info']['server']['admin_mails']) as $mail) |
|
771 | + $mailer->addHeader('Subject', lang("eGroupWare: login blocked for user '%1', IP %2", $login, $ip)); |
|
772 | + $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)); |
|
773 | + foreach (preg_split('/,\s*/', $GLOBALS['egw_info']['server']['admin_mails']) as $mail) |
|
775 | 774 | { |
776 | 775 | $mailer->addAddress($mail); |
777 | 776 | } |
778 | 777 | $mailer->send(); |
779 | 778 | } |
780 | - catch(Exception $e) { |
|
779 | + catch (Exception $e) { |
|
781 | 780 | // ignore exception, but log it, to block the account and give a correct error-message to user |
782 | 781 | error_log(__METHOD__."('$login', '$ip') ".$e->getMessage()); |
783 | 782 | } |
784 | 783 | // save time of mail, to not send to many mails |
785 | 784 | $config = new Config('phpgwapi'); |
786 | 785 | $config->read_repository(); |
787 | - $config->value('login_blocked_mail_time',time()); |
|
786 | + $config->value('login_blocked_mail_time', time()); |
|
788 | 787 | $config->save_repository(); |
789 | 788 | } |
790 | 789 | return $blocked; |
@@ -805,7 +804,7 @@ discard block |
||
805 | 804 | * @param boolean $only_basic_auth =false return only a basic auth pseudo sessionid, default no |
806 | 805 | * @return string |
807 | 806 | */ |
808 | - static function get_sessionid($only_basic_auth=false) |
|
807 | + static function get_sessionid($only_basic_auth = false) |
|
809 | 808 | { |
810 | 809 | // for WebDAV and GroupDAV we use a pseudo sessionid created from md5(user:passwd) |
811 | 810 | // --> allows this stateless protocolls which use basic auth to use sessions! |
@@ -832,11 +831,11 @@ discard block |
||
832 | 831 | EGW_SERVER_ROOT.':'.self::getuser_ip().':'.filemtime(EGW_SERVER_ROOT.'/phpgwapi/setup/setup.inc.php'). |
833 | 832 | ':'.$_SERVER['HTTP_USER_AGENT']); |
834 | 833 | } |
835 | - elseif(!$only_basic_auth && isset($_REQUEST[self::EGW_SESSION_NAME])) |
|
834 | + elseif (!$only_basic_auth && isset($_REQUEST[self::EGW_SESSION_NAME])) |
|
836 | 835 | { |
837 | 836 | $sessionid = $_REQUEST[self::EGW_SESSION_NAME]; |
838 | 837 | } |
839 | - elseif(!$only_basic_auth && isset($_COOKIE[self::EGW_SESSION_NAME])) |
|
838 | + elseif (!$only_basic_auth && isset($_COOKIE[self::EGW_SESSION_NAME])) |
|
840 | 839 | { |
841 | 840 | $sessionid = $_COOKIE[self::EGW_SESSION_NAME]; |
842 | 841 | } |
@@ -844,7 +843,7 @@ discard block |
||
844 | 843 | { |
845 | 844 | $sessionid = false; |
846 | 845 | } |
847 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid,true)); |
|
846 | + if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid, true)); |
|
848 | 847 | return $sessionid; |
849 | 848 | } |
850 | 849 | |
@@ -860,9 +859,7 @@ discard block |
||
860 | 859 | */ |
861 | 860 | static function get_request($name) |
862 | 861 | { |
863 | - return isset($_REQUEST[$name]) ? $_REQUEST[$name] : |
|
864 | - (isset($_COOKIE[$name]) ? $_COOKIE[$name] : |
|
865 | - (isset($_COOKIE[$name=ucfirst($name)]) ? $_COOKIE[$name] : null)); |
|
862 | + return isset($_REQUEST[$name]) ? $_REQUEST[$name] : (isset($_COOKIE[$name]) ? $_COOKIE[$name] : (isset($_COOKIE[$name = ucfirst($name)]) ? $_COOKIE[$name] : null)); |
|
866 | 863 | } |
867 | 864 | |
868 | 865 | /** |
@@ -872,13 +869,13 @@ discard block |
||
872 | 869 | * @param string $kp3 ?? to be verified |
873 | 870 | * @return bool is the session valid? |
874 | 871 | */ |
875 | - function verify($sessionid=null,$kp3=null) |
|
872 | + function verify($sessionid = null, $kp3 = null) |
|
876 | 873 | { |
877 | 874 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid','$kp3') ".function_backtrace()); |
878 | 875 | |
879 | 876 | $fill_egw_info_and_repositories = !$GLOBALS['egw_info']['flags']['restored_from_session']; |
880 | 877 | |
881 | - if(!$sessionid) |
|
878 | + if (!$sessionid) |
|
882 | 879 | { |
883 | 880 | $sessionid = self::get_sessionid(); |
884 | 881 | $kp3 = self::get_request('kp3'); |
@@ -905,23 +902,23 @@ discard block |
||
905 | 902 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session does NOT exist!"); |
906 | 903 | return false; |
907 | 904 | } |
908 | - $session =& $_SESSION[self::EGW_SESSION_VAR]; |
|
905 | + $session = & $_SESSION[self::EGW_SESSION_VAR]; |
|
909 | 906 | |
910 | 907 | if ($session['session_dla'] <= time() - $GLOBALS['egw_info']['server']['sessions_timeout']) |
911 | 908 | { |
912 | 909 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session timed out!"); |
913 | - $this->destroy($sessionid,$kp3); |
|
910 | + $this->destroy($sessionid, $kp3); |
|
914 | 911 | return false; |
915 | 912 | } |
916 | 913 | |
917 | 914 | $this->session_flags = $session['session_flags']; |
918 | 915 | |
919 | - $this->split_login_domain($session['session_lid'],$this->account_lid,$this->account_domain); |
|
916 | + $this->split_login_domain($session['session_lid'], $this->account_lid, $this->account_domain); |
|
920 | 917 | |
921 | 918 | // This is to ensure that we authenticate to the correct domain (might not be default) |
922 | - if($GLOBALS['egw_info']['user']['domain'] && $this->account_domain != $GLOBALS['egw_info']['user']['domain']) |
|
919 | + if ($GLOBALS['egw_info']['user']['domain'] && $this->account_domain != $GLOBALS['egw_info']['user']['domain']) |
|
923 | 920 | { |
924 | - return false; // session not verified, domain changed |
|
921 | + return false; // session not verified, domain changed |
|
925 | 922 | } |
926 | 923 | $GLOBALS['egw_info']['user']['kp3'] = $this->kp3; |
927 | 924 | |
@@ -934,7 +931,7 @@ discard block |
||
934 | 931 | { |
935 | 932 | $this->update_notification_heartbeat(); |
936 | 933 | } |
937 | - $this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid,'account_lid','u'); |
|
934 | + $this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid, 'account_lid', 'u'); |
|
938 | 935 | if (!$this->account_id) |
939 | 936 | { |
940 | 937 | if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) !accounts::name2id('$this->account_lid')"); |
@@ -972,7 +969,7 @@ discard block |
||
972 | 969 | |
973 | 970 | if ($GLOBALS['egw_info']['server']['sessions_checkip']) |
974 | 971 | { |
975 | - if (strtoupper(substr(PHP_OS,0,3)) != 'WIN' && (!$GLOBALS['egw_info']['user']['session_ip'] || |
|
972 | + if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN' && (!$GLOBALS['egw_info']['user']['session_ip'] || |
|
976 | 973 | $GLOBALS['egw_info']['user']['session_ip'] != $this->getuser_ip())) |
977 | 974 | { |
978 | 975 | if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) wrong IP"); |
@@ -995,9 +992,9 @@ discard block |
||
995 | 992 | // query accesslog-id, if not set in session (session is made persistent after login!) |
996 | 993 | if (!$this->sessionid_access_log && $this->session_flags != 'A') |
997 | 994 | { |
998 | - $this->sessionid_access_log = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE,'sessionid',array( |
|
995 | + $this->sessionid_access_log = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, 'sessionid', array( |
|
999 | 996 | 'session_php' => $this->sessionid, |
1000 | - ),__LINE__,__FILE__)->fetchColumn(); |
|
997 | + ), __LINE__, __FILE__)->fetchColumn(); |
|
1001 | 998 | //error_log(__METHOD__."() sessionid=$this->sessionid --> sessionid_access_log=$this->sessionid_access_log"); |
1002 | 999 | } |
1003 | 1000 | |
@@ -1008,9 +1005,9 @@ discard block |
||
1008 | 1005 | (!isset($_COOKIE[self::EGW_SESSION_NAME]) || $_COOKIE[self::EGW_SESSION_NAME] !== $_REQUEST[self::EGW_SESSION_NAME])) |
1009 | 1006 | { |
1010 | 1007 | if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS, but NO required cookies set --> setting them now"); |
1011 | - self::egw_setcookie(self::EGW_SESSION_NAME,$this->sessionid); |
|
1012 | - self::egw_setcookie('kp3',$this->kp3); |
|
1013 | - self::egw_setcookie('domain',$this->account_domain); |
|
1008 | + self::egw_setcookie(self::EGW_SESSION_NAME, $this->sessionid); |
|
1009 | + self::egw_setcookie('kp3', $this->kp3); |
|
1010 | + self::egw_setcookie('domain', $this->account_domain); |
|
1014 | 1011 | } |
1015 | 1012 | |
1016 | 1013 | if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS"); |
@@ -1025,27 +1022,27 @@ discard block |
||
1025 | 1022 | * @param string $kp3 |
1026 | 1023 | * @return boolean true on success, false on error |
1027 | 1024 | */ |
1028 | - function destroy($sessionid, $kp3='') |
|
1025 | + function destroy($sessionid, $kp3 = '') |
|
1029 | 1026 | { |
1030 | 1027 | if (!$sessionid && $kp3) |
1031 | 1028 | { |
1032 | 1029 | return false; |
1033 | 1030 | } |
1034 | - $this->log_access($sessionid); // log logout-time |
|
1031 | + $this->log_access($sessionid); // log logout-time |
|
1035 | 1032 | |
1036 | 1033 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($sessionid,$kp3)"); |
1037 | 1034 | |
1038 | 1035 | if (is_numeric($sessionid)) // do we have a access-log-id --> get PHP session id |
1039 | 1036 | { |
1040 | - $sessionid = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE,'session_php',array( |
|
1037 | + $sessionid = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, 'session_php', array( |
|
1041 | 1038 | 'sessionid' => $sessionid, |
1042 | - ),__LINE__,__FILE__)->fetchColumn(); |
|
1039 | + ), __LINE__, __FILE__)->fetchColumn(); |
|
1043 | 1040 | } |
1044 | 1041 | |
1045 | 1042 | Hooks::process(array( |
1046 | 1043 | 'location' => 'session_destroyed', |
1047 | 1044 | 'sessionid' => $sessionid, |
1048 | - ),'',true); // true = run hooks from all apps, not just the ones the current user has perms to run |
|
1045 | + ), '', true); // true = run hooks from all apps, not just the ones the current user has perms to run |
|
1049 | 1046 | |
1050 | 1047 | // Only do the following, if where working with the current user |
1051 | 1048 | if (!$GLOBALS['egw_info']['user']['sessionid'] || $sessionid == $GLOBALS['egw_info']['user']['sessionid']) |
@@ -1066,7 +1063,7 @@ discard block |
||
1066 | 1063 | } |
1067 | 1064 | else |
1068 | 1065 | { |
1069 | - $this->commit_session(); // close our own session |
|
1066 | + $this->commit_session(); // close our own session |
|
1070 | 1067 | |
1071 | 1068 | session_id($sessionid); |
1072 | 1069 | if (session_start()) |
@@ -1106,25 +1103,25 @@ discard block |
||
1106 | 1103 | // as $webserver_url may be part of $url (as /egw is part of phpgwapi/js/egw_instant_load.html) |
1107 | 1104 | if (($url[0] != '/' || $webserver_url != '/') && (!$webserver_url || strpos($url, $webserver_url.'/') === false)) |
1108 | 1105 | { |
1109 | - if($url[0] != '/' && substr($webserver_url,-1) != '/') |
|
1106 | + if ($url[0] != '/' && substr($webserver_url, -1) != '/') |
|
1110 | 1107 | { |
1111 | - $url = $webserver_url .'/'. $url; |
|
1108 | + $url = $webserver_url.'/'.$url; |
|
1112 | 1109 | } |
1113 | 1110 | else |
1114 | 1111 | { |
1115 | - $url = $webserver_url . $url; |
|
1112 | + $url = $webserver_url.$url; |
|
1116 | 1113 | } |
1117 | 1114 | } |
1118 | 1115 | |
1119 | - if(isset($GLOBALS['egw_info']['server']['enforce_ssl']) && $GLOBALS['egw_info']['server']['enforce_ssl']) |
|
1116 | + if (isset($GLOBALS['egw_info']['server']['enforce_ssl']) && $GLOBALS['egw_info']['server']['enforce_ssl']) |
|
1120 | 1117 | { |
1121 | - if(substr($url ,0,4) != 'http') |
|
1118 | + if (substr($url, 0, 4) != 'http') |
|
1122 | 1119 | { |
1123 | 1120 | $url = 'https://'.$_SERVER['HTTP_HOST'].$url; |
1124 | 1121 | } |
1125 | 1122 | else |
1126 | 1123 | { |
1127 | - $url = str_replace ( 'http:', 'https:', $url); |
|
1124 | + $url = str_replace('http:', 'https:', $url); |
|
1128 | 1125 | } |
1129 | 1126 | } |
1130 | 1127 | $vars = array(); |
@@ -1137,7 +1134,7 @@ discard block |
||
1137 | 1134 | } |
1138 | 1135 | |
1139 | 1136 | // check if the url already contains a query and ensure that vars is an array and all strings are in extravars |
1140 | - list($ret_url,$othervars) = explode('?', $url, 2); |
|
1137 | + list($ret_url, $othervars) = explode('?', $url, 2); |
|
1141 | 1138 | if ($extravars && is_array($extravars)) |
1142 | 1139 | { |
1143 | 1140 | $vars += $extravars; |
@@ -1145,19 +1142,19 @@ discard block |
||
1145 | 1142 | } |
1146 | 1143 | else |
1147 | 1144 | { |
1148 | - if ($othervars) $extravars .= ($extravars?'&':'').$othervars; |
|
1145 | + if ($othervars) $extravars .= ($extravars ? '&' : '').$othervars; |
|
1149 | 1146 | } |
1150 | 1147 | |
1151 | 1148 | // parse extravars string into the vars array |
1152 | 1149 | if ($extravars) |
1153 | 1150 | { |
1154 | - foreach(explode('&',$extravars) as $expr) |
|
1151 | + foreach (explode('&', $extravars) as $expr) |
|
1155 | 1152 | { |
1156 | - list($var,$val) = explode('=', $expr,2); |
|
1157 | - if (strpos($val,'%26') != false) $val = str_replace('%26','&',$val); // make sure to not double encode & |
|
1158 | - if (substr($var,-2) == '[]') |
|
1153 | + list($var, $val) = explode('=', $expr, 2); |
|
1154 | + if (strpos($val, '%26') != false) $val = str_replace('%26', '&', $val); // make sure to not double encode & |
|
1155 | + if (substr($var, -2) == '[]') |
|
1159 | 1156 | { |
1160 | - $vars[substr($var,0,-2)][] = $val; |
|
1157 | + $vars[substr($var, 0, -2)][] = $val; |
|
1161 | 1158 | } |
1162 | 1159 | else |
1163 | 1160 | { |
@@ -1170,11 +1167,11 @@ discard block |
||
1170 | 1167 | if (count($vars)) |
1171 | 1168 | { |
1172 | 1169 | $query = array(); |
1173 | - foreach($vars as $key => $value) |
|
1170 | + foreach ($vars as $key => $value) |
|
1174 | 1171 | { |
1175 | 1172 | if (is_array($value)) |
1176 | 1173 | { |
1177 | - foreach($value as $val) |
|
1174 | + foreach ($value as $val) |
|
1178 | 1175 | { |
1179 | 1176 | $query[] = $key.'[]='.urlencode($val); |
1180 | 1177 | } |
@@ -1184,7 +1181,7 @@ discard block |
||
1184 | 1181 | $query[] = $key.'='.urlencode($value); |
1185 | 1182 | } |
1186 | 1183 | } |
1187 | - $ret_url .= '?' . implode('&',$query); |
|
1184 | + $ret_url .= '?'.implode('&', $query); |
|
1188 | 1185 | } |
1189 | 1186 | return $ret_url; |
1190 | 1187 | } |
@@ -1229,7 +1226,7 @@ discard block |
||
1229 | 1226 | * @param int $cookietime =0 when cookie should expire, 0 for session only (optional) |
1230 | 1227 | * @param string $cookiepath =null optional path (eg. '/') if the eGW install-dir should not be used |
1231 | 1228 | */ |
1232 | - public static function egw_setcookie($cookiename,$cookievalue='',$cookietime=0,$cookiepath=null) |
|
1229 | + public static function egw_setcookie($cookiename, $cookievalue = '', $cookietime = 0, $cookiepath = null) |
|
1233 | 1230 | { |
1234 | 1231 | if (empty(self::$cookie_domain) || empty(self::$cookie_path)) |
1235 | 1232 | { |
@@ -1242,11 +1239,11 @@ discard block |
||
1242 | 1239 | static $is_iOS = null; |
1243 | 1240 | if (!$cookietime && !isset($is_iOS)) $is_iOS = (bool)preg_match('/^(iPhone|iPad|iPod)/i', Header\UserAgent::mobile()); |
1244 | 1241 | |
1245 | - if(!headers_sent()) // gives only a warning, but can not send the cookie anyway |
|
1242 | + if (!headers_sent()) // gives only a warning, but can not send the cookie anyway |
|
1246 | 1243 | { |
1247 | 1244 | setcookie($cookiename, $cookievalue, |
1248 | - !$cookietime && $is_iOS ? time()+self::IOS_SESSION_COOKIE_LIFETIME : $cookietime, |
|
1249 | - is_null($cookiepath) ? self::$cookie_path : $cookiepath,self::$cookie_domain, |
|
1245 | + !$cookietime && $is_iOS ? time() + self::IOS_SESSION_COOKIE_LIFETIME : $cookietime, |
|
1246 | + is_null($cookiepath) ? self::$cookie_path : $cookiepath, self::$cookie_domain, |
|
1250 | 1247 | // if called via HTTPS, only send cookie for https and only allow cookie access via HTTP (true) |
1251 | 1248 | empty($GLOBALS['egw_info']['server']['insecure_cookies']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off', true); |
1252 | 1249 | } |
@@ -1265,21 +1262,21 @@ discard block |
||
1265 | 1262 | else |
1266 | 1263 | { |
1267 | 1264 | // Use HTTP_X_FORWARDED_HOST if set, which is the case behind a none-transparent proxy |
1268 | - self::$cookie_domain = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST']; |
|
1265 | + self::$cookie_domain = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST']; |
|
1269 | 1266 | } |
1270 | 1267 | // remove port from HTTP_HOST |
1271 | 1268 | $arr = null; |
1272 | - if (preg_match("/^(.*):(.*)$/",self::$cookie_domain,$arr)) |
|
1269 | + if (preg_match("/^(.*):(.*)$/", self::$cookie_domain, $arr)) |
|
1273 | 1270 | { |
1274 | 1271 | self::$cookie_domain = $arr[1]; |
1275 | 1272 | } |
1276 | - if (count(explode('.',self::$cookie_domain)) <= 1) |
|
1273 | + if (count(explode('.', self::$cookie_domain)) <= 1) |
|
1277 | 1274 | { |
1278 | 1275 | // setcookie dont likes domains without dots, leaving it empty, gets setcookie to fill the domain in |
1279 | 1276 | self::$cookie_domain = ''; |
1280 | 1277 | } |
1281 | 1278 | if (!$GLOBALS['egw_info']['server']['cookiepath'] || |
1282 | - !(self::$cookie_path = parse_url($GLOBALS['egw_info']['server']['webserver_url'],PHP_URL_PATH))) |
|
1279 | + !(self::$cookie_path = parse_url($GLOBALS['egw_info']['server']['webserver_url'], PHP_URL_PATH))) |
|
1283 | 1280 | { |
1284 | 1281 | self::$cookie_path = '/'; |
1285 | 1282 | } |
@@ -1299,7 +1296,7 @@ discard block |
||
1299 | 1296 | * @param array $domains =null defaults to $GLOBALS['egw_domain'] from the header |
1300 | 1297 | * @return string $GLOBALS['egw_info']['user']['domain'] set with the domain/instance to use |
1301 | 1298 | */ |
1302 | - public static function search_instance($login,$domain_requested,&$default_domain,$server_names,array $domains=null) |
|
1299 | + public static function search_instance($login, $domain_requested, &$default_domain, $server_names, array $domains = null) |
|
1303 | 1300 | { |
1304 | 1301 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".".array2string($server_names).".".array2string($domains).")"); |
1305 | 1302 | |
@@ -1307,10 +1304,10 @@ discard block |
||
1307 | 1304 | |
1308 | 1305 | if (!isset($default_domain) || !isset($domains[$default_domain])) // allow to overwrite the default domain |
1309 | 1306 | { |
1310 | - foreach((array)$server_names as $server_name) |
|
1307 | + foreach ((array)$server_names as $server_name) |
|
1311 | 1308 | { |
1312 | - list($server_name) = explode(':', $server_name); // remove port from HTTP_HOST |
|
1313 | - if(isset($domains[$server_name])) |
|
1309 | + list($server_name) = explode(':', $server_name); // remove port from HTTP_HOST |
|
1310 | + if (isset($domains[$server_name])) |
|
1314 | 1311 | { |
1315 | 1312 | $default_domain = $server_name; |
1316 | 1313 | break; |
@@ -1320,7 +1317,7 @@ discard block |
||
1320 | 1317 | $parts = explode('.', $server_name); |
1321 | 1318 | array_shift($parts); |
1322 | 1319 | $domain_part = implode('.', $parts); |
1323 | - if(isset($domains[$domain_part])) |
|
1320 | + if (isset($domains[$domain_part])) |
|
1324 | 1321 | { |
1325 | 1322 | $default_domain = $domain_part; |
1326 | 1323 | break; |
@@ -1336,11 +1333,11 @@ discard block |
||
1336 | 1333 | } |
1337 | 1334 | if (isset($login)) // on login |
1338 | 1335 | { |
1339 | - if (strpos($login,'@') === false || count($domains) == 1) |
|
1336 | + if (strpos($login, '@') === false || count($domains) == 1) |
|
1340 | 1337 | { |
1341 | - $login .= '@' . (isset($_POST['logindomain']) ? $_POST['logindomain'] : $default_domain); |
|
1338 | + $login .= '@'.(isset($_POST['logindomain']) ? $_POST['logindomain'] : $default_domain); |
|
1342 | 1339 | } |
1343 | - $parts = explode('@',$login); |
|
1340 | + $parts = explode('@', $login); |
|
1344 | 1341 | $domain = array_pop($parts); |
1345 | 1342 | $GLOBALS['login'] = $login; |
1346 | 1343 | } |
@@ -1363,7 +1360,7 @@ discard block |
||
1363 | 1360 | * @param boolean $update_access_log =true false: dont update egw_access_log table |
1364 | 1361 | * @return string action as written to egw_access_log.session_action |
1365 | 1362 | */ |
1366 | - private function update_dla($update_access_log=true) |
|
1363 | + private function update_dla($update_access_log = true) |
|
1367 | 1364 | { |
1368 | 1365 | // This way XML-RPC users aren't always listed as xmlrpc.php |
1369 | 1366 | if ($this->xmlrpc_method_called) |
@@ -1379,27 +1376,27 @@ discard block |
||
1379 | 1376 | $action = $_SERVER['PHP_SELF']; |
1380 | 1377 | // remove EGroupware path, if not installed in webroot |
1381 | 1378 | $egw_path = $GLOBALS['egw_info']['server']['webserver_url']; |
1382 | - if ($egw_path[0] != '/') $egw_path = parse_url($egw_path,PHP_URL_PATH); |
|
1379 | + if ($egw_path[0] != '/') $egw_path = parse_url($egw_path, PHP_URL_PATH); |
|
1383 | 1380 | if ($action == '/Microsoft-Server-ActiveSync') |
1384 | 1381 | { |
1385 | 1382 | $action .= '?Cmd='.$_GET['Cmd'].'&DeviceId='.$_GET['DeviceId']; |
1386 | 1383 | } |
1387 | 1384 | elseif ($egw_path) |
1388 | 1385 | { |
1389 | - list(,$action) = explode($egw_path,$action,2); |
|
1386 | + list(,$action) = explode($egw_path, $action, 2); |
|
1390 | 1387 | } |
1391 | 1388 | } |
1392 | 1389 | |
1393 | 1390 | // update dla in access-log table, if we have an access-log row (non-anonymous session) |
1394 | 1391 | if ($this->sessionid_access_log && $update_access_log) |
1395 | 1392 | { |
1396 | - $GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE,array( |
|
1393 | + $GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE, array( |
|
1397 | 1394 | 'session_dla' => time(), |
1398 | 1395 | 'session_action' => $action, |
1399 | - 'lo' => null, // just in case it was (automatic) timed out before |
|
1400 | - ),array( |
|
1396 | + 'lo' => null, // just in case it was (automatic) timed out before |
|
1397 | + ), array( |
|
1401 | 1398 | 'sessionid' => $this->sessionid_access_log, |
1402 | - ),__LINE__,__FILE__); |
|
1399 | + ), __LINE__, __FILE__); |
|
1403 | 1400 | } |
1404 | 1401 | |
1405 | 1402 | $_SESSION[self::EGW_SESSION_VAR]['session_dla'] = time(); |
@@ -1417,12 +1414,12 @@ discard block |
||
1417 | 1414 | // update dla in access-log table, if we have an access-log row (non-anonymous session) |
1418 | 1415 | if ($this->sessionid_access_log) |
1419 | 1416 | { |
1420 | - $GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE,array( |
|
1417 | + $GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE, array( |
|
1421 | 1418 | 'notification_heartbeat' => time(), |
1422 | - ),array( |
|
1419 | + ), array( |
|
1423 | 1420 | 'sessionid' => $this->sessionid_access_log, |
1424 | 1421 | 'lo IS NULL', |
1425 | - ),__LINE__,__FILE__); |
|
1422 | + ), __LINE__, __FILE__); |
|
1426 | 1423 | } |
1427 | 1424 | } |
1428 | 1425 | |
@@ -1443,7 +1440,7 @@ discard block |
||
1443 | 1440 | { |
1444 | 1441 | // authentication happens in login.php, which does NOT yet create egw-object in session |
1445 | 1442 | // --> need to store homedirectory in session |
1446 | - if(isset($GLOBALS['auto_create_acct']['homedirectory'])) |
|
1443 | + if (isset($GLOBALS['auto_create_acct']['homedirectory'])) |
|
1447 | 1444 | { |
1448 | 1445 | Cache::setSession(__CLASS__, 'homedirectory', |
1449 | 1446 | $user['homedirectory'] = $GLOBALS['auto_create_acct']['homedirectory']); |
@@ -1456,7 +1453,7 @@ discard block |
||
1456 | 1453 | $user['preferences'] = $GLOBALS['egw']->preferences->read_repository(); |
1457 | 1454 | if (is_object($GLOBALS['egw']->datetime)) |
1458 | 1455 | { |
1459 | - $GLOBALS['egw']->datetime->__construct(); // to set tz_offset from the now read prefs |
|
1456 | + $GLOBALS['egw']->datetime->__construct(); // to set tz_offset from the now read prefs |
|
1460 | 1457 | } |
1461 | 1458 | $user['apps'] = $GLOBALS['egw']->applications->read_repository(); |
1462 | 1459 | $user['domain'] = $this->account_domain; |
@@ -1479,9 +1476,9 @@ discard block |
||
1479 | 1476 | * @param string &$account_lid returned account_lid (ie. user) |
1480 | 1477 | * @param string &$domain returned domain (ie. domain) |
1481 | 1478 | */ |
1482 | - private function split_login_domain($login,&$account_lid,&$domain) |
|
1479 | + private function split_login_domain($login, &$account_lid, &$domain) |
|
1483 | 1480 | { |
1484 | - $parts = explode('@',$login); |
|
1481 | + $parts = explode('@', $login); |
|
1485 | 1482 | |
1486 | 1483 | //conference - for strings like [email protected]@default , |
1487 | 1484 | //allows that user have a login that is his e-mail. (viniciuscb) |
@@ -1489,11 +1486,11 @@ discard block |
||
1489 | 1486 | { |
1490 | 1487 | $probable_domain = array_pop($parts); |
1491 | 1488 | //Last part of login string, when separated by @, is a domain name |
1492 | - if (in_array($probable_domain,$this->egw_domains)) |
|
1489 | + if (in_array($probable_domain, $this->egw_domains)) |
|
1493 | 1490 | { |
1494 | 1491 | $got_login = true; |
1495 | 1492 | $domain = $probable_domain; |
1496 | - $account_lid = implode('@',$parts); |
|
1493 | + $account_lid = implode('@', $parts); |
|
1497 | 1494 | } |
1498 | 1495 | } |
1499 | 1496 | |
@@ -1516,9 +1513,9 @@ discard block |
||
1516 | 1513 | * @param boolean $allow_password_md5 =false can password alread be an md5 hash |
1517 | 1514 | * @return string |
1518 | 1515 | */ |
1519 | - static function user_pw_hash($user,$password,$allow_password_md5=false) |
|
1516 | + static function user_pw_hash($user, $password, $allow_password_md5 = false) |
|
1520 | 1517 | { |
1521 | - $password_md5 = $allow_password_md5 && preg_match('/^[a-f0-9]{32}$/',$password) ? $password : md5($password); |
|
1518 | + $password_md5 = $allow_password_md5 && preg_match('/^[a-f0-9]{32}$/', $password) ? $password : md5($password); |
|
1522 | 1519 | |
1523 | 1520 | $hash = sha1(strtolower($user).$password_md5); |
1524 | 1521 | |
@@ -1532,7 +1529,7 @@ discard block |
||
1532 | 1529 | { |
1533 | 1530 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__.'() session_handler='.self::$session_handler.', egw_info[server][session_handler]='.$GLOBALS['egw_info']['server']['session_handler'].' called from:'.function_backtrace()); |
1534 | 1531 | |
1535 | - ini_set('session.use_cookies',0); // disable the automatic use of cookies, as it uses the path / by default |
|
1532 | + ini_set('session.use_cookies', 0); // disable the automatic use of cookies, as it uses the path / by default |
|
1536 | 1533 | session_name(self::EGW_SESSION_NAME); |
1537 | 1534 | if (($sessionid = self::get_sessionid())) |
1538 | 1535 | { |
@@ -1559,7 +1556,7 @@ discard block |
||
1559 | 1556 | * @param int $expire =null expiration time in seconds, default $GLOBALS['egw_info']['flags']['nocachecontrol'] or php.ini session.cache_expire |
1560 | 1557 | * @param int $private =null allows to set private caching with given expiration time, by setting it to true |
1561 | 1558 | */ |
1562 | - public static function cache_control($expire=null, $private=null) |
|
1559 | + public static function cache_control($expire = null, $private = null) |
|
1563 | 1560 | { |
1564 | 1561 | if (is_null($expire) && isset($GLOBALS['egw_info']['flags']['nocachecontrol']) && is_int($GLOBALS['egw_info']['flags']['nocachecontrol'])) |
1565 | 1562 | { |
@@ -1569,7 +1566,7 @@ discard block |
||
1569 | 1566 | if (!isset($_SESSION)) |
1570 | 1567 | { |
1571 | 1568 | // controling caching and expires header |
1572 | - if(!isset($expire) && (!isset($GLOBALS['egw_info']['flags']['nocachecontrol']) || |
|
1569 | + if (!isset($expire) && (!isset($GLOBALS['egw_info']['flags']['nocachecontrol']) || |
|
1573 | 1570 | !$GLOBALS['egw_info']['flags']['nocachecontrol'])) |
1574 | 1571 | { |
1575 | 1572 | session_cache_limiter('nocache'); |
@@ -1579,7 +1576,7 @@ discard block |
||
1579 | 1576 | // allow public caching: proxys, cdns, ... |
1580 | 1577 | if (isset($expire)) |
1581 | 1578 | { |
1582 | - session_cache_expire((int)ceil($expire/60)); // in minutes |
|
1579 | + session_cache_expire((int)ceil($expire / 60)); // in minutes |
|
1583 | 1580 | } |
1584 | 1581 | session_cache_limiter($private ? 'private' : 'public'); |
1585 | 1582 | } |
@@ -1592,8 +1589,8 @@ discard block |
||
1592 | 1589 | // session already started |
1593 | 1590 | if (isset($_SESSION)) |
1594 | 1591 | { |
1595 | - if ($expire && (session_cache_limiter() !== ($expire===true?'private_no_expire':'public') || |
|
1596 | - is_int($expire) && $expire/60 !== session_cache_expire())) |
|
1592 | + if ($expire && (session_cache_limiter() !== ($expire === true ? 'private_no_expire' : 'public') || |
|
1593 | + is_int($expire) && $expire / 60 !== session_cache_expire())) |
|
1597 | 1594 | { |
1598 | 1595 | $file = $line = null; |
1599 | 1596 | if (headers_sent($file, $line)) |
@@ -1601,20 +1598,20 @@ discard block |
||
1601 | 1598 | error_log(__METHOD__."($expire) called, but header already sent in $file: $line"); |
1602 | 1599 | return; |
1603 | 1600 | } |
1604 | - if($expire === true) // same behavior as session_cache_limiter('private_no_expire') |
|
1601 | + if ($expire === true) // same behavior as session_cache_limiter('private_no_expire') |
|
1605 | 1602 | { |
1606 | - header('Cache-Control: private, max-age='.(60*session_cache_expire())); |
|
1603 | + header('Cache-Control: private, max-age='.(60 * session_cache_expire())); |
|
1607 | 1604 | header_remove('Expires'); |
1608 | 1605 | } |
1609 | 1606 | elseif ($private) |
1610 | 1607 | { |
1611 | 1608 | header('Cache-Control: private, max-age='.$expire); |
1612 | - header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expire) . ' GMT'); |
|
1609 | + header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expire).' GMT'); |
|
1613 | 1610 | } |
1614 | 1611 | else |
1615 | 1612 | { |
1616 | 1613 | header('Cache-Control: public, max-age='.$expire); |
1617 | - header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expire) . ' GMT'); |
|
1614 | + header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expire).' GMT'); |
|
1618 | 1615 | } |
1619 | 1616 | // remove Pragma header, might be set by old header |
1620 | 1617 | if (function_exists('header_remove')) // PHP 5.3+ |
@@ -1639,10 +1636,10 @@ discard block |
||
1639 | 1636 | * @param array $filter =array() extra filter for sessions |
1640 | 1637 | * @return array with sessions (values for keys as in $sort) |
1641 | 1638 | */ |
1642 | - public static function session_list($start,$sort='DESC',$order='session_dla',$all_no_sort=False,array $filter=array()) |
|
1639 | + public static function session_list($start, $sort = 'DESC', $order = 'session_dla', $all_no_sort = False, array $filter = array()) |
|
1643 | 1640 | { |
1644 | 1641 | $sessions = array(); |
1645 | - if (!preg_match('/^[a-z0-9_ ,]+$/i',$order_by=$order.' '.$sort) || $order_by == ' ') |
|
1642 | + if (!preg_match('/^[a-z0-9_ ,]+$/i', $order_by = $order.' '.$sort) || $order_by == ' ') |
|
1646 | 1643 | { |
1647 | 1644 | $order_by = 'session_dla DESC'; |
1648 | 1645 | } |
@@ -1650,7 +1647,7 @@ discard block |
||
1650 | 1647 | $filter[] = 'account_id>0'; |
1651 | 1648 | $filter[] = 'session_dla > '.(int)(time() - $GLOBALS['egw_info']['server']['sessions_timeout']); |
1652 | 1649 | $filter[] = '(notification_heartbeat IS NULL OR notification_heartbeat > '.self::heartbeat_limit().')'; |
1653 | - foreach($GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, '*', $filter, __LINE__, __FILE__, |
|
1650 | + foreach ($GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, '*', $filter, __LINE__, __FILE__, |
|
1654 | 1651 | $all_no_sort ? false : $start, 'ORDER BY '.$order_by) as $row) |
1655 | 1652 | { |
1656 | 1653 | $sessions[$row['sessionid']] = $row; |
@@ -1664,7 +1661,7 @@ discard block |
||
1664 | 1661 | * @param array $filter =array() extra filter for sessions |
1665 | 1662 | * @return int number of active sessions |
1666 | 1663 | */ |
1667 | - public static function session_count(array $filter=array()) |
|
1664 | + public static function session_count(array $filter = array()) |
|
1668 | 1665 | { |
1669 | 1666 | $filter['lo'] = null; |
1670 | 1667 | $filter[] = 'account_id>0'; |
@@ -1680,16 +1677,16 @@ discard block |
||
1680 | 1677 | */ |
1681 | 1678 | public static function heartbeat_limit() |
1682 | 1679 | { |
1683 | - static $limit=null; |
|
1680 | + static $limit = null; |
|
1684 | 1681 | |
1685 | 1682 | if (is_null($limit)) |
1686 | 1683 | { |
1687 | 1684 | $config = Config::read('notifications'); |
1688 | - if (!($popup_poll_interval = $config['popup_poll_interval'])) |
|
1685 | + if (!($popup_poll_interval = $config['popup_poll_interval'])) |
|
1689 | 1686 | { |
1690 | 1687 | $popup_poll_interval = 60; |
1691 | 1688 | } |
1692 | - $limit = (int)(time() - $popup_poll_interval-10); // 10s grace periode |
|
1689 | + $limit = (int)(time() - $popup_poll_interval - 10); // 10s grace periode |
|
1693 | 1690 | } |
1694 | 1691 | return $limit; |
1695 | 1692 | } |
@@ -248,7 +248,7 @@ discard block |
||
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 | } |
@@ -282,7 +282,10 @@ discard block |
||
282 | 282 | */ |
283 | 283 | function commit_session() |
284 | 284 | { |
285 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() sessionid=$this->sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]).' '.function_backtrace()); |
|
285 | + if (self::ERROR_LOG_DEBUG) |
|
286 | + { |
|
287 | + error_log(__METHOD__."() sessionid=$this->sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]).' '.function_backtrace()); |
|
288 | + } |
|
286 | 289 | self::encrypt($this->kp3); |
287 | 290 | |
288 | 291 | session_write_close(); |
@@ -344,7 +347,10 @@ discard block |
||
344 | 347 | */ |
345 | 348 | static function log_session_usage(&$arr,$label,$recursion=true,$limit=1000) |
346 | 349 | { |
347 | - if (!is_array($arr)) return; |
|
350 | + if (!is_array($arr)) |
|
351 | + { |
|
352 | + return; |
|
353 | + } |
|
348 | 354 | |
349 | 355 | $sizes = array(); |
350 | 356 | foreach($arr as $key => &$data) |
@@ -359,7 +365,10 @@ discard block |
||
359 | 365 | if ($diff > $limit) |
360 | 366 | { |
361 | 367 | error_log("strlen({$label}[$key])=".Vfs::hsize($size).", diff=".Vfs::hsize($diff)); |
362 | - if ($recursion) self::log_session_usage($arr[$key],$label.'['.$key.']',$recursion,$limit); |
|
368 | + if ($recursion) |
|
369 | + { |
|
370 | + self::log_session_usage($arr[$key],$label.'['.$key.']',$recursion,$limit); |
|
371 | + } |
|
363 | 372 | } |
364 | 373 | } |
365 | 374 | } |
@@ -457,7 +466,10 @@ discard block |
||
457 | 466 | $this->passwd = $passwd; |
458 | 467 | $this->passwd_type = $passwd_type; |
459 | 468 | } |
460 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) starting ..."); |
|
469 | + if (self::ERROR_LOG_DEBUG) |
|
470 | + { |
|
471 | + error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) starting ..."); |
|
472 | + } |
|
461 | 473 | |
462 | 474 | self::split_login_domain($login,$this->account_lid,$this->account_domain); |
463 | 475 | // add domain to the login, if not already there |
@@ -501,7 +513,10 @@ discard block |
||
501 | 513 | { |
502 | 514 | $this->log_access($this->reason,$login,$user_ip,0); // log unsuccessfull login |
503 | 515 | } |
504 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
|
516 | + if (self::ERROR_LOG_DEBUG) |
|
517 | + { |
|
518 | + error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
|
519 | + } |
|
505 | 520 | return false; |
506 | 521 | } |
507 | 522 | if ($fail_on_forced_password_change && Auth::check_password_change($this->reason) === false) |
@@ -551,7 +566,10 @@ discard block |
||
551 | 566 | $this->reason = 'account is expired'; |
552 | 567 | $this->cd_reason = self::CD_ACCOUNT_EXPIRED; |
553 | 568 | |
554 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
|
569 | + if (self::ERROR_LOG_DEBUG) |
|
570 | + { |
|
571 | + error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
|
572 | + } |
|
555 | 573 | return false; |
556 | 574 | } |
557 | 575 | |
@@ -575,25 +593,34 @@ discard block |
||
575 | 593 | 'passwd' => $this->passwd, |
576 | 594 | 'account_domain' => $this->account_domain, |
577 | 595 | 'user_ip' => $user_ip, |
578 | - ),'',true))) // true = run hooks from all apps, not just the ones the current user has perms to run |
|
596 | + ),'',true))) |
|
597 | + { |
|
598 | + // true = run hooks from all apps, not just the ones the current user has perms to run |
|
579 | 599 | { |
580 | 600 | foreach($hook_result as $reason) |
581 | 601 | { |
582 | 602 | if ($reason) // called hook requests to deny the session |
583 | 603 | { |
584 | 604 | $this->reason = $this->cd_reason = $reason; |
605 | + } |
|
585 | 606 | $this->log_access($this->reason,$login,$user_ip,0); // log unsuccessfull login |
586 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
|
607 | + if (self::ERROR_LOG_DEBUG) |
|
608 | + { |
|
609 | + error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
|
610 | + } |
|
587 | 611 | return false; |
588 | 612 | } |
589 | 613 | } |
590 | 614 | } |
591 | 615 | $GLOBALS['egw']->db->transaction_begin(); |
592 | 616 | $this->register_session($this->login,$user_ip,$now,$this->session_flags); |
593 | - if ($this->session_flags != 'A') // dont log anonymous sessions |
|
617 | + if ($this->session_flags != 'A') |
|
618 | + { |
|
619 | + // dont log anonymous sessions |
|
594 | 620 | { |
595 | 621 | $this->sessionid_access_log = $this->log_access($this->sessionid,$login,$user_ip,$this->account_id); |
596 | 622 | } |
623 | + } |
|
597 | 624 | Cache::setSession('phpgwapi', 'account_previous_login', $GLOBALS['egw']->auth->previous_login); |
598 | 625 | $GLOBALS['egw']->accounts->update_lastlogin($this->account_id,$user_ip); |
599 | 626 | $GLOBALS['egw']->db->transaction_commit(); |
@@ -609,7 +636,10 @@ discard block |
||
609 | 636 | self::egw_setcookie('last_loginid', $this->account_lid ,$now+1209600); /* For 2 weeks */ |
610 | 637 | self::egw_setcookie('last_domain',$this->account_domain,$now+1209600); |
611 | 638 | } |
612 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) successfull sessionid=$this->sessionid"); |
|
639 | + if (self::ERROR_LOG_DEBUG) |
|
640 | + { |
|
641 | + error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) successfull sessionid=$this->sessionid"); |
|
642 | + } |
|
613 | 643 | |
614 | 644 | return $this->sessionid; |
615 | 645 | } |
@@ -763,10 +793,13 @@ discard block |
||
763 | 793 | //error_log(__METHOD__."('$login', '$ip') false_ip=$false_ip, false_id=$false_id --> blocked=".array2string($blocked)); |
764 | 794 | |
765 | 795 | if ($blocked && $GLOBALS['egw_info']['server']['admin_mails'] && |
766 | - $GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time()-5*60) // max. one mail every 5mins |
|
796 | + $GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time()-5*60) |
|
797 | + { |
|
798 | + // max. one mail every 5mins |
|
767 | 799 | { |
768 | 800 | try { |
769 | 801 | $mailer = new Mailer(); |
802 | + } |
|
770 | 803 | // notify admin(s) via email |
771 | 804 | $mailer->setFrom('eGroupWare@'.$GLOBALS['egw_info']['server']['mail_suffix']); |
772 | 805 | $mailer->addHeader('Subject', lang("eGroupWare: login blocked for user '%1', IP %2",$login,$ip)); |
@@ -844,7 +877,10 @@ discard block |
||
844 | 877 | { |
845 | 878 | $sessionid = false; |
846 | 879 | } |
847 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid,true)); |
|
880 | + if (self::ERROR_LOG_DEBUG) |
|
881 | + { |
|
882 | + error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid,true)); |
|
883 | + } |
|
848 | 884 | return $sessionid; |
849 | 885 | } |
850 | 886 | |
@@ -874,7 +910,10 @@ discard block |
||
874 | 910 | */ |
875 | 911 | function verify($sessionid=null,$kp3=null) |
876 | 912 | { |
877 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid','$kp3') ".function_backtrace()); |
|
913 | + if (self::ERROR_LOG_DEBUG) |
|
914 | + { |
|
915 | + error_log(__METHOD__."('$sessionid','$kp3') ".function_backtrace()); |
|
916 | + } |
|
878 | 917 | |
879 | 918 | $fill_egw_info_and_repositories = !$GLOBALS['egw_info']['flags']['restored_from_session']; |
880 | 919 | |
@@ -890,7 +929,10 @@ discard block |
||
890 | 929 | |
891 | 930 | if (!$this->sessionid) |
892 | 931 | { |
893 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') get_sessionid()='".self::get_sessionid()."' No session ID"); |
|
932 | + if (self::ERROR_LOG_DEBUG) |
|
933 | + { |
|
934 | + error_log(__METHOD__."('$sessionid') get_sessionid()='".self::get_sessionid()."' No session ID"); |
|
935 | + } |
|
894 | 936 | return false; |
895 | 937 | } |
896 | 938 | |
@@ -902,14 +944,20 @@ discard block |
||
902 | 944 | // check if we have a eGroupware session --> return false if not (but dont destroy it!) |
903 | 945 | if (is_null($_SESSION) || !isset($_SESSION[self::EGW_SESSION_VAR])) |
904 | 946 | { |
905 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session does NOT exist!"); |
|
947 | + if (self::ERROR_LOG_DEBUG) |
|
948 | + { |
|
949 | + error_log(__METHOD__."('$sessionid') session does NOT exist!"); |
|
950 | + } |
|
906 | 951 | return false; |
907 | 952 | } |
908 | 953 | $session =& $_SESSION[self::EGW_SESSION_VAR]; |
909 | 954 | |
910 | 955 | if ($session['session_dla'] <= time() - $GLOBALS['egw_info']['server']['sessions_timeout']) |
911 | 956 | { |
912 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session timed out!"); |
|
957 | + if (self::ERROR_LOG_DEBUG) |
|
958 | + { |
|
959 | + error_log(__METHOD__."('$sessionid') session timed out!"); |
|
960 | + } |
|
913 | 961 | $this->destroy($sessionid,$kp3); |
914 | 962 | return false; |
915 | 963 | } |
@@ -937,7 +985,10 @@ discard block |
||
937 | 985 | $this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid,'account_lid','u'); |
938 | 986 | if (!$this->account_id) |
939 | 987 | { |
940 | - if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) !accounts::name2id('$this->account_lid')"); |
|
988 | + if (self::ERROR_LOG_DEBUG) |
|
989 | + { |
|
990 | + error_log("*** Session::verify($sessionid) !accounts::name2id('$this->account_lid')"); |
|
991 | + } |
|
941 | 992 | return false; |
942 | 993 | } |
943 | 994 | |
@@ -955,7 +1006,10 @@ discard block |
||
955 | 1006 | |
956 | 1007 | if ($GLOBALS['egw']->accounts->is_expired($GLOBALS['egw_info']['user'])) |
957 | 1008 | { |
958 | - if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) accounts is expired"); |
|
1009 | + if (self::ERROR_LOG_DEBUG) |
|
1010 | + { |
|
1011 | + error_log("*** Session::verify($sessionid) accounts is expired"); |
|
1012 | + } |
|
959 | 1013 | return false; |
960 | 1014 | } |
961 | 1015 | $this->passwd = base64_decode(Cache::getSession('phpgwapi', 'password')); |
@@ -966,7 +1020,10 @@ discard block |
||
966 | 1020 | } |
967 | 1021 | if ($this->account_domain != $GLOBALS['egw_info']['user']['domain']) |
968 | 1022 | { |
969 | - if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) wrong domain"); |
|
1023 | + if (self::ERROR_LOG_DEBUG) |
|
1024 | + { |
|
1025 | + error_log("*** Session::verify($sessionid) wrong domain"); |
|
1026 | + } |
|
970 | 1027 | return false; |
971 | 1028 | } |
972 | 1029 | |
@@ -975,7 +1032,10 @@ discard block |
||
975 | 1032 | if (strtoupper(substr(PHP_OS,0,3)) != 'WIN' && (!$GLOBALS['egw_info']['user']['session_ip'] || |
976 | 1033 | $GLOBALS['egw_info']['user']['session_ip'] != $this->getuser_ip())) |
977 | 1034 | { |
978 | - if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) wrong IP"); |
|
1035 | + if (self::ERROR_LOG_DEBUG) |
|
1036 | + { |
|
1037 | + error_log("*** Session::verify($sessionid) wrong IP"); |
|
1038 | + } |
|
979 | 1039 | return false; |
980 | 1040 | } |
981 | 1041 | } |
@@ -988,7 +1048,10 @@ discard block |
||
988 | 1048 | } |
989 | 1049 | if (!$this->account_lid) |
990 | 1050 | { |
991 | - if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) !account_lid"); |
|
1051 | + if (self::ERROR_LOG_DEBUG) |
|
1052 | + { |
|
1053 | + error_log("*** Session::verify($sessionid) !account_lid"); |
|
1054 | + } |
|
992 | 1055 | return false; |
993 | 1056 | } |
994 | 1057 | |
@@ -1007,13 +1070,19 @@ discard block |
||
1007 | 1070 | $_REQUEST[self::EGW_SESSION_NAME] === $this->sessionid && |
1008 | 1071 | (!isset($_COOKIE[self::EGW_SESSION_NAME]) || $_COOKIE[self::EGW_SESSION_NAME] !== $_REQUEST[self::EGW_SESSION_NAME])) |
1009 | 1072 | { |
1010 | - if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS, but NO required cookies set --> setting them now"); |
|
1073 | + if (self::ERROR_LOG_DEBUG) |
|
1074 | + { |
|
1075 | + error_log("--> Session::verify($sessionid) SUCCESS, but NO required cookies set --> setting them now"); |
|
1076 | + } |
|
1011 | 1077 | self::egw_setcookie(self::EGW_SESSION_NAME,$this->sessionid); |
1012 | 1078 | self::egw_setcookie('kp3',$this->kp3); |
1013 | 1079 | self::egw_setcookie('domain',$this->account_domain); |
1014 | 1080 | } |
1015 | 1081 | |
1016 | - if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS"); |
|
1082 | + if (self::ERROR_LOG_DEBUG) |
|
1083 | + { |
|
1084 | + error_log("--> Session::verify($sessionid) SUCCESS"); |
|
1085 | + } |
|
1017 | 1086 | |
1018 | 1087 | return true; |
1019 | 1088 | } |
@@ -1033,14 +1102,20 @@ discard block |
||
1033 | 1102 | } |
1034 | 1103 | $this->log_access($sessionid); // log logout-time |
1035 | 1104 | |
1036 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($sessionid,$kp3)"); |
|
1105 | + if (self::ERROR_LOG_DEBUG) |
|
1106 | + { |
|
1107 | + error_log(__METHOD__."($sessionid,$kp3)"); |
|
1108 | + } |
|
1037 | 1109 | |
1038 | - if (is_numeric($sessionid)) // do we have a access-log-id --> get PHP session id |
|
1110 | + if (is_numeric($sessionid)) |
|
1111 | + { |
|
1112 | + // do we have a access-log-id --> get PHP session id |
|
1039 | 1113 | { |
1040 | 1114 | $sessionid = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE,'session_php',array( |
1041 | 1115 | 'sessionid' => $sessionid, |
1042 | 1116 | ),__LINE__,__FILE__)->fetchColumn(); |
1043 | 1117 | } |
1118 | + } |
|
1044 | 1119 | |
1045 | 1120 | Hooks::process(array( |
1046 | 1121 | 'location' => 'session_destroyed', |
@@ -1050,7 +1125,10 @@ discard block |
||
1050 | 1125 | // Only do the following, if where working with the current user |
1051 | 1126 | if (!$GLOBALS['egw_info']['user']['sessionid'] || $sessionid == $GLOBALS['egw_info']['user']['sessionid']) |
1052 | 1127 | { |
1053 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__." ********* about to call session_destroy!"); |
|
1128 | + if (self::ERROR_LOG_DEBUG) |
|
1129 | + { |
|
1130 | + error_log(__METHOD__." ********* about to call session_destroy!"); |
|
1131 | + } |
|
1054 | 1132 | session_unset(); |
1055 | 1133 | @session_destroy(); |
1056 | 1134 | // we need to (re-)load the eGW session-handler, as session_destroy unloads custom session-handlers |
@@ -1145,7 +1223,10 @@ discard block |
||
1145 | 1223 | } |
1146 | 1224 | else |
1147 | 1225 | { |
1148 | - if ($othervars) $extravars .= ($extravars?'&':'').$othervars; |
|
1226 | + if ($othervars) |
|
1227 | + { |
|
1228 | + $extravars .= ($extravars?'&':'').$othervars; |
|
1229 | + } |
|
1149 | 1230 | } |
1150 | 1231 | |
1151 | 1232 | // parse extravars string into the vars array |
@@ -1154,7 +1235,11 @@ discard block |
||
1154 | 1235 | foreach(explode('&',$extravars) as $expr) |
1155 | 1236 | { |
1156 | 1237 | list($var,$val) = explode('=', $expr,2); |
1157 | - if (strpos($val,'%26') != false) $val = str_replace('%26','&',$val); // make sure to not double encode & |
|
1238 | + if (strpos($val,'%26') != false) |
|
1239 | + { |
|
1240 | + $val = str_replace('%26','&',$val); |
|
1241 | + } |
|
1242 | + // make sure to not double encode & |
|
1158 | 1243 | if (substr($var,-2) == '[]') |
1159 | 1244 | { |
1160 | 1245 | $vars[substr($var,0,-2)][] = $val; |
@@ -1235,14 +1320,22 @@ discard block |
||
1235 | 1320 | { |
1236 | 1321 | self::set_cookiedomain(); |
1237 | 1322 | } |
1238 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($cookiename,$cookievalue,$cookietime,$cookiepath,".self::$cookie_domain.")"); |
|
1323 | + if (self::ERROR_LOG_DEBUG) |
|
1324 | + { |
|
1325 | + error_log(__METHOD__."($cookiename,$cookievalue,$cookietime,$cookiepath,".self::$cookie_domain.")"); |
|
1326 | + } |
|
1239 | 1327 | |
1240 | 1328 | // if we are installed in iOS as web-app, we must not set a cookietime==0 (session-cookie), |
1241 | 1329 | // as every change between apps will cause the cookie to get lost |
1242 | 1330 | static $is_iOS = null; |
1243 | - if (!$cookietime && !isset($is_iOS)) $is_iOS = (bool)preg_match('/^(iPhone|iPad|iPod)/i', Header\UserAgent::mobile()); |
|
1331 | + if (!$cookietime && !isset($is_iOS)) |
|
1332 | + { |
|
1333 | + $is_iOS = (bool)preg_match('/^(iPhone|iPad|iPod)/i', Header\UserAgent::mobile()); |
|
1334 | + } |
|
1244 | 1335 | |
1245 | - if(!headers_sent()) // gives only a warning, but can not send the cookie anyway |
|
1336 | + if(!headers_sent()) |
|
1337 | + { |
|
1338 | + // gives only a warning, but can not send the cookie anyway |
|
1246 | 1339 | { |
1247 | 1340 | setcookie($cookiename, $cookievalue, |
1248 | 1341 | !$cookietime && $is_iOS ? time()+self::IOS_SESSION_COOKIE_LIFETIME : $cookietime, |
@@ -1250,6 +1343,7 @@ discard block |
||
1250 | 1343 | // if called via HTTPS, only send cookie for https and only allow cookie access via HTTP (true) |
1251 | 1344 | empty($GLOBALS['egw_info']['server']['insecure_cookies']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off', true); |
1252 | 1345 | } |
1346 | + } |
|
1253 | 1347 | } |
1254 | 1348 | |
1255 | 1349 | /** |
@@ -1301,15 +1395,25 @@ discard block |
||
1301 | 1395 | */ |
1302 | 1396 | public static function search_instance($login,$domain_requested,&$default_domain,$server_names,array $domains=null) |
1303 | 1397 | { |
1304 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".".array2string($server_names).".".array2string($domains).")"); |
|
1398 | + if (self::ERROR_LOG_DEBUG) |
|
1399 | + { |
|
1400 | + error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".".array2string($server_names).".".array2string($domains).")"); |
|
1401 | + } |
|
1305 | 1402 | |
1306 | - if (is_null($domains)) $domains = $GLOBALS['egw_domain']; |
|
1403 | + if (is_null($domains)) |
|
1404 | + { |
|
1405 | + $domains = $GLOBALS['egw_domain']; |
|
1406 | + } |
|
1307 | 1407 | |
1308 | - if (!isset($default_domain) || !isset($domains[$default_domain])) // allow to overwrite the default domain |
|
1408 | + if (!isset($default_domain) || !isset($domains[$default_domain])) |
|
1409 | + { |
|
1410 | + // allow to overwrite the default domain |
|
1309 | 1411 | { |
1310 | 1412 | foreach((array)$server_names as $server_name) |
1311 | 1413 | { |
1312 | - list($server_name) = explode(':', $server_name); // remove port from HTTP_HOST |
|
1414 | + list($server_name) = explode(':', $server_name); |
|
1415 | + } |
|
1416 | + // remove port from HTTP_HOST |
|
1313 | 1417 | if(isset($domains[$server_name])) |
1314 | 1418 | { |
1315 | 1419 | $default_domain = $server_name; |
@@ -1334,11 +1438,14 @@ discard block |
||
1334 | 1438 | } |
1335 | 1439 | } |
1336 | 1440 | } |
1337 | - if (isset($login)) // on login |
|
1441 | + if (isset($login)) |
|
1442 | + { |
|
1443 | + // on login |
|
1338 | 1444 | { |
1339 | 1445 | if (strpos($login,'@') === false || count($domains) == 1) |
1340 | 1446 | { |
1341 | 1447 | $login .= '@' . (isset($_POST['logindomain']) ? $_POST['logindomain'] : $default_domain); |
1448 | + } |
|
1342 | 1449 | } |
1343 | 1450 | $parts = explode('@',$login); |
1344 | 1451 | $domain = array_pop($parts); |
@@ -1352,7 +1459,10 @@ discard block |
||
1352 | 1459 | { |
1353 | 1460 | $domain = $default_domain; |
1354 | 1461 | } |
1355 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() default_domain=".array2string($default_domain).', login='.array2string($login)." returning ".array2string($domain)); |
|
1462 | + if (self::ERROR_LOG_DEBUG) |
|
1463 | + { |
|
1464 | + error_log(__METHOD__."() default_domain=".array2string($default_domain).', login='.array2string($login)." returning ".array2string($domain)); |
|
1465 | + } |
|
1356 | 1466 | |
1357 | 1467 | return $domain; |
1358 | 1468 | } |
@@ -1379,7 +1489,10 @@ discard block |
||
1379 | 1489 | $action = $_SERVER['PHP_SELF']; |
1380 | 1490 | // remove EGroupware path, if not installed in webroot |
1381 | 1491 | $egw_path = $GLOBALS['egw_info']['server']['webserver_url']; |
1382 | - if ($egw_path[0] != '/') $egw_path = parse_url($egw_path,PHP_URL_PATH); |
|
1492 | + if ($egw_path[0] != '/') |
|
1493 | + { |
|
1494 | + $egw_path = parse_url($egw_path,PHP_URL_PATH); |
|
1495 | + } |
|
1383 | 1496 | if ($action == '/Microsoft-Server-ActiveSync') |
1384 | 1497 | { |
1385 | 1498 | $action .= '?Cmd='.$_GET['Cmd'].'&DeviceId='.$_GET['DeviceId']; |
@@ -1404,7 +1517,10 @@ discard block |
||
1404 | 1517 | |
1405 | 1518 | $_SESSION[self::EGW_SESSION_VAR]['session_dla'] = time(); |
1406 | 1519 | $_SESSION[self::EGW_SESSION_VAR]['session_action'] = $action; |
1407 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__.'() _SESSION['.self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR])); |
|
1520 | + if (self::ERROR_LOG_DEBUG) |
|
1521 | + { |
|
1522 | + error_log(__METHOD__.'() _SESSION['.self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR])); |
|
1523 | + } |
|
1408 | 1524 | |
1409 | 1525 | return $action; |
1410 | 1526 | } |
@@ -1530,7 +1646,10 @@ discard block |
||
1530 | 1646 | */ |
1531 | 1647 | public static function init_handler() |
1532 | 1648 | { |
1533 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__.'() session_handler='.self::$session_handler.', egw_info[server][session_handler]='.$GLOBALS['egw_info']['server']['session_handler'].' called from:'.function_backtrace()); |
|
1649 | + if (self::ERROR_LOG_DEBUG) |
|
1650 | + { |
|
1651 | + error_log(__METHOD__.'() session_handler='.self::$session_handler.', egw_info[server][session_handler]='.$GLOBALS['egw_info']['server']['session_handler'].' called from:'.function_backtrace()); |
|
1652 | + } |
|
1534 | 1653 | |
1535 | 1654 | ini_set('session.use_cookies',0); // disable the automatic use of cookies, as it uses the path / by default |
1536 | 1655 | session_name(self::EGW_SESSION_NAME); |
@@ -1540,10 +1659,16 @@ discard block |
||
1540 | 1659 | self::cache_control(); |
1541 | 1660 | $ok = session_start(); |
1542 | 1661 | self::decrypt(); |
1543 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() sessionid=$sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR])); |
|
1662 | + if (self::ERROR_LOG_DEBUG) |
|
1663 | + { |
|
1664 | + error_log(__METHOD__."() sessionid=$sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR])); |
|
1665 | + } |
|
1544 | 1666 | return $ok; |
1545 | 1667 | } |
1546 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() no active session!"); |
|
1668 | + if (self::ERROR_LOG_DEBUG) |
|
1669 | + { |
|
1670 | + error_log(__METHOD__."() no active session!"); |
|
1671 | + } |
|
1547 | 1672 | |
1548 | 1673 | return false; |
1549 | 1674 | } |
@@ -1601,9 +1726,12 @@ discard block |
||
1601 | 1726 | error_log(__METHOD__."($expire) called, but header already sent in $file: $line"); |
1602 | 1727 | return; |
1603 | 1728 | } |
1604 | - if($expire === true) // same behavior as session_cache_limiter('private_no_expire') |
|
1729 | + if($expire === true) |
|
1730 | + { |
|
1731 | + // same behavior as session_cache_limiter('private_no_expire') |
|
1605 | 1732 | { |
1606 | 1733 | header('Cache-Control: private, max-age='.(60*session_cache_expire())); |
1734 | + } |
|
1607 | 1735 | header_remove('Expires'); |
1608 | 1736 | } |
1609 | 1737 | elseif ($private) |
@@ -1617,10 +1745,13 @@ discard block |
||
1617 | 1745 | header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expire) . ' GMT'); |
1618 | 1746 | } |
1619 | 1747 | // remove Pragma header, might be set by old header |
1620 | - if (function_exists('header_remove')) // PHP 5.3+ |
|
1748 | + if (function_exists('header_remove')) |
|
1749 | + { |
|
1750 | + // PHP 5.3+ |
|
1621 | 1751 | { |
1622 | 1752 | header_remove('Pragma'); |
1623 | 1753 | } |
1754 | + } |
|
1624 | 1755 | else |
1625 | 1756 | { |
1626 | 1757 | header('Pragma:'); |
@@ -366,7 +366,7 @@ discard block |
||
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 |
||
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 | { |
@@ -210,12 +210,12 @@ |
||
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 | foreach (array_keys((array)$this->customfields) as $name) |
@@ -118,41 +118,41 @@ discard block |
||
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 |
||
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 |
||
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 | foreach (array_keys((array)$this->customfields) as $name) |
222 | 222 | { |
@@ -229,22 +229,21 @@ discard block |
||
229 | 229 | $is_multiple = $this->is_multiple($name); |
230 | 230 | |
231 | 231 | // we explicitly need to delete fields, if value is empty or field allows multiple values or we have no unique index |
232 | - if(empty($data[$field]) || $is_multiple || !$this->extra_has_unique_index) |
|
232 | + if (empty($data[$field]) || $is_multiple || !$this->extra_has_unique_index) |
|
233 | 233 | { |
234 | - $this->db->delete($this->extra_table,$where,__LINE__,__FILE__,$this->app); |
|
235 | - if (empty($data[$field])) continue; // nothing else to do for empty values |
|
234 | + $this->db->delete($this->extra_table, $where, __LINE__, __FILE__, $this->app); |
|
235 | + if (empty($data[$field])) continue; // nothing else to do for empty values |
|
236 | 236 | } |
237 | - foreach($is_multiple && !is_array($data[$field]) ? explode(',',$data[$field]) : |
|
238 | - // regular custom fields (!$is_multiple) eg. addressbook store multiple values comma-separated |
|
237 | + foreach ($is_multiple && !is_array($data[$field]) ? explode(',', $data[$field]) : // regular custom fields (!$is_multiple) eg. addressbook store multiple values comma-separated |
|
239 | 238 | (array)(!$is_multiple && is_array($data[$field]) ? implode(',', $data[$field]) : $data[$field]) as $value) |
240 | 239 | { |
241 | - if (!$this->db->insert($this->extra_table,array($this->extra_value => $value)+$extra_cols,$where,__LINE__,__FILE__,$this->app)) |
|
240 | + if (!$this->db->insert($this->extra_table, array($this->extra_value => $value) + $extra_cols, $where, __LINE__, __FILE__, $this->app)) |
|
242 | 241 | { |
243 | 242 | return $this->db->Errno; |
244 | 243 | } |
245 | 244 | } |
246 | 245 | } |
247 | - return false; // no error |
|
246 | + return false; // no error |
|
248 | 247 | } |
249 | 248 | |
250 | 249 | /** |
@@ -260,7 +259,7 @@ discard block |
||
260 | 259 | |
261 | 260 | if ($this->customfields) |
262 | 261 | { |
263 | - foreach(array_keys($this->customfields) as $name) |
|
262 | + foreach (array_keys($this->customfields) as $name) |
|
264 | 263 | { |
265 | 264 | if (isset($new[$field = $this->get_cf_field($name)])) |
266 | 265 | { |
@@ -280,16 +279,16 @@ discard block |
||
280 | 279 | * @param string $join sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or |
281 | 280 | * @return array|boolean data if row could be retrived else False |
282 | 281 | */ |
283 | - function read($keys,$extra_cols='',$join='') |
|
282 | + function read($keys, $extra_cols = '', $join = '') |
|
284 | 283 | { |
285 | - if (!parent::read($keys,$extra_cols,$join)) |
|
284 | + if (!parent::read($keys, $extra_cols, $join)) |
|
286 | 285 | { |
287 | 286 | return false; |
288 | 287 | } |
289 | 288 | if (($id = (int)$this->data[$this->db_key_cols[$this->autoinc_id]]) && $this->customfields && |
290 | 289 | ($cfs = $this->read_customfields($id))) |
291 | 290 | { |
292 | - $this->data = array_merge($this->data,$cfs[$id]); |
|
291 | + $this->data = array_merge($this->data, $cfs[$id]); |
|
293 | 292 | } |
294 | 293 | return $this->data; |
295 | 294 | } |
@@ -303,14 +302,14 @@ discard block |
||
303 | 302 | * @param string|array $extra_where =null extra where clause, eg. to check an etag, returns true if no affected rows! |
304 | 303 | * @return int|boolean 0 on success, or errno != 0 on error, or true if $extra_where is given and no rows affected |
305 | 304 | */ |
306 | - function save($keys=null,$extra_where=null) |
|
305 | + function save($keys = null, $extra_where = null) |
|
307 | 306 | { |
308 | 307 | if (is_array($keys) && count($keys) && !isset($keys[0])) // allow to use an etag, eg array('etag=etag+1') |
309 | 308 | { |
310 | 309 | $this->data_merge($keys); |
311 | 310 | $keys = null; |
312 | 311 | } |
313 | - $ret = parent::save($keys,$extra_where); |
|
312 | + $ret = parent::save($keys, $extra_where); |
|
314 | 313 | |
315 | 314 | if ($ret == 0 && $this->customfields) |
316 | 315 | { |
@@ -328,26 +327,26 @@ discard block |
||
328 | 327 | * @param boolean $only_return_ids =false return $ids of delete call to db object, but not run it (can be used by extending classes!) |
329 | 328 | * @return int|array affected rows, should be 1 if ok, 0 if an error or array with id's if $only_return_ids |
330 | 329 | */ |
331 | - function delete($keys=null,$only_return_ids=false) |
|
330 | + function delete($keys = null, $only_return_ids = false) |
|
332 | 331 | { |
333 | 332 | if ($this->customfields || $only_return_ids) |
334 | 333 | { |
335 | - $query = parent::delete($keys,true); |
|
334 | + $query = parent::delete($keys, true); |
|
336 | 335 | // check if query contains more then the id's |
337 | 336 | if (!isset($query[$this->autoinc_id]) || count($query) != 1) |
338 | 337 | { |
339 | - foreach($this->db->select($this->table_name,$this->autoinc_id,$query,__LINE__,__FILE__,false,'',$this->app) as $row) |
|
338 | + foreach ($this->db->select($this->table_name, $this->autoinc_id, $query, __LINE__, __FILE__, false, '', $this->app) as $row) |
|
340 | 339 | { |
341 | 340 | $ids[] = $row[$this->autoinc_id]; |
342 | 341 | } |
343 | - if (!$ids) return 0; // no rows affected |
|
342 | + if (!$ids) return 0; // no rows affected |
|
344 | 343 | } |
345 | 344 | else |
346 | 345 | { |
347 | 346 | $ids = (array)$query[$this->autoinc_id]; |
348 | 347 | } |
349 | 348 | if ($only_return_ids) return $ids; |
350 | - $this->db->delete($this->extra_table,array($this->extra_id => $ids),__LINE__,__FILE__); |
|
349 | + $this->db->delete($this->extra_table, array($this->extra_id => $ids), __LINE__, __FILE__); |
|
351 | 350 | } |
352 | 351 | return parent::delete($keys); |
353 | 352 | } |
@@ -370,32 +369,32 @@ discard block |
||
370 | 369 | * @param string|array $extra_cols =array() |
371 | 370 | * @return int total number of rows |
372 | 371 | */ |
373 | - function get_rows($query,&$rows,&$readonlys,$join='',$need_full_no_count=false,$only_keys=false,$extra_cols=array()) |
|
372 | + function get_rows($query, &$rows, &$readonlys, $join = '', $need_full_no_count = false, $only_keys = false, $extra_cols = array()) |
|
374 | 373 | { |
375 | - parent::get_rows($query,$rows,$readonlys,$join,$need_full_no_count,$only_keys,$extra_cols); |
|
374 | + parent::get_rows($query, $rows, $readonlys, $join, $need_full_no_count, $only_keys, $extra_cols); |
|
376 | 375 | |
377 | - $selectcols = $query['selectcols'] ? explode(',',$query['selectcols']) : array(); |
|
376 | + $selectcols = $query['selectcols'] ? explode(',', $query['selectcols']) : array(); |
|
378 | 377 | |
379 | - if ($rows && $this->customfields && (!$selectcols || in_array('customfields',$selectcols))) |
|
378 | + if ($rows && $this->customfields && (!$selectcols || in_array('customfields', $selectcols))) |
|
380 | 379 | { |
381 | 380 | $id2keys = array(); |
382 | - foreach($rows as $key => $row) |
|
381 | + foreach ($rows as $key => $row) |
|
383 | 382 | { |
384 | 383 | $id2keys[$row[$this->db_key_cols[$this->autoinc_id]]] = $key; |
385 | 384 | } |
386 | 385 | // check if only certain cf's to show |
387 | 386 | if (!in_array('customfields', $selectcols)) |
388 | 387 | { |
389 | - foreach($selectcols as $col) |
|
388 | + foreach ($selectcols as $col) |
|
390 | 389 | { |
391 | 390 | if ($this->is_cf($col)) $fields[] = $this->get_cf_name($col); |
392 | 391 | } |
393 | 392 | } |
394 | - if (($cfs = $this->read_customfields(array_keys($id2keys),$fields))) |
|
393 | + if (($cfs = $this->read_customfields(array_keys($id2keys), $fields))) |
|
395 | 394 | { |
396 | - foreach($cfs as $id => $data) |
|
395 | + foreach ($cfs as $id => $data) |
|
397 | 396 | { |
398 | - $rows[$id2keys[$id]] = array_merge($rows[$id2keys[$id]],$data); |
|
397 | + $rows[$id2keys[$id]] = array_merge($rows[$id2keys[$id]], $data); |
|
399 | 398 | } |
400 | 399 | } |
401 | 400 | } |
@@ -422,12 +421,12 @@ discard block |
||
422 | 421 | * @param boolean $need_full_no_count =false If true an unlimited query is run to determine the total number of rows, default false |
423 | 422 | * @return array|NULL array of matching rows (the row is an array of the cols) or NULL |
424 | 423 | */ |
425 | - 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) |
|
424 | + 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) |
|
426 | 425 | { |
427 | 426 | //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())).')'); |
428 | 427 | if (!$this->customfields) |
429 | 428 | { |
430 | - return parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count); |
|
429 | + return parent::search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, $start, $filter, $join, $need_full_no_count); |
|
431 | 430 | } |
432 | 431 | if ($only_keys === false) |
433 | 432 | { |
@@ -436,7 +435,7 @@ discard block |
||
436 | 435 | // if string given as criteria --> search in all (or $this->columns_to_search) columns including custom fields |
437 | 436 | if ($criteria && is_string($criteria)) |
438 | 437 | { |
439 | - $criteria = $this->search2criteria($criteria,$wildcard,$op); |
|
438 | + $criteria = $this->search2criteria($criteria, $wildcard, $op); |
|
440 | 439 | } |
441 | 440 | if ($criteria && is_array($criteria)) |
442 | 441 | { |
@@ -445,10 +444,10 @@ discard block |
||
445 | 444 | { |
446 | 445 | if (($negate = $criteria[$this->extra_value][0] === '!')) |
447 | 446 | { |
448 | - $criteria[$this->extra_value] = substr($criteria[$this->extra_value],1); |
|
447 | + $criteria[$this->extra_value] = substr($criteria[$this->extra_value], 1); |
|
449 | 448 | } |
450 | - $criteria[] = $this->extra_table.'.'.$this->extra_value . ' ' .($negate ? 'NOT ' : ''). |
|
451 | - $this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE]. ' ' . |
|
449 | + $criteria[] = $this->extra_table.'.'.$this->extra_value.' '.($negate ? 'NOT ' : ''). |
|
450 | + $this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '. |
|
452 | 451 | $this->db->quote($wildcard.$criteria[$this->extra_value].$wildcard); |
453 | 452 | unset($criteria[$this->extra_value]); |
454 | 453 | } |
@@ -457,14 +456,14 @@ discard block |
||
457 | 456 | { |
458 | 457 | if ($criteria[$this->autoinc_id]) |
459 | 458 | { |
460 | - $criteria[] = $this->db->expression($this->table_name,$this->table_name.'.', |
|
459 | + $criteria[] = $this->db->expression($this->table_name, $this->table_name.'.', |
|
461 | 460 | array($this->autoinc_id => $criteria[$this->autoinc_id])); |
462 | 461 | } |
463 | 462 | unset($criteria[$this->autoinc_id]); |
464 | 463 | } |
465 | 464 | // replace ambiguous column with (an exact match of) table_name.column |
466 | 465 | $extra_join_added = $join && strpos($join, $this->extra_join) !== false; |
467 | - foreach($criteria as $name => $val) |
|
466 | + foreach ($criteria as $name => $val) |
|
468 | 467 | { |
469 | 468 | // only add extra_join, if we really need it |
470 | 469 | if (!$extra_join_added && ( |
@@ -476,9 +475,9 @@ discard block |
||
476 | 475 | $extra_join_added = true; |
477 | 476 | } |
478 | 477 | $extra_columns = $this->db->get_table_definitions($this->app, $this->extra_table); |
479 | - if(is_string($name) && $extra_columns['fd'][array_search($name, $this->db_cols)]) |
|
478 | + if (is_string($name) && $extra_columns['fd'][array_search($name, $this->db_cols)]) |
|
480 | 479 | { |
481 | - $criteria[] = $this->db->expression($this->table_name,$this->table_name.'.',array( |
|
480 | + $criteria[] = $this->db->expression($this->table_name, $this->table_name.'.', array( |
|
482 | 481 | array_search($name, $this->db_cols) => $val, |
483 | 482 | )); |
484 | 483 | unset($criteria[$name]); |
@@ -490,12 +489,12 @@ discard block |
||
490 | 489 | $name = substr($name, 1); |
491 | 490 | if (($negate = $criteria[$name][0] === '!')) |
492 | 491 | { |
493 | - $val = substr($val,1); |
|
492 | + $val = substr($val, 1); |
|
494 | 493 | } |
495 | - $cfcriteria[] = '(' . $this->extra_table.'.'.$this->extra_value . ' ' .($negate ? 'NOT ' : ''). |
|
496 | - $this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE]. ' ' . |
|
497 | - $this->db->quote($wildcard.$val.$wildcard) . ' AND ' . |
|
498 | - $this->extra_table.'.'.$this->extra_key . ' = ' . $this->db->quote($name) . |
|
494 | + $cfcriteria[] = '('.$this->extra_table.'.'.$this->extra_value.' '.($negate ? 'NOT ' : ''). |
|
495 | + $this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '. |
|
496 | + $this->db->quote($wildcard.$val.$wildcard).' AND '. |
|
497 | + $this->extra_table.'.'.$this->extra_key.' = '.$this->db->quote($name). |
|
499 | 498 | ')'; |
500 | 499 | unset($criteria[self::CF_PREFIX.$name]); |
501 | 500 | } |
@@ -507,38 +506,38 @@ discard block |
||
507 | 506 | } |
508 | 507 | } |
509 | 508 | } |
510 | - if ($cfcriteria && $op =='OR') $criteria[] = implode(' OR ',$cfcriteria); |
|
509 | + if ($cfcriteria && $op == 'OR') $criteria[] = implode(' OR ', $cfcriteria); |
|
511 | 510 | } |
512 | - if($only_keys === true) |
|
511 | + if ($only_keys === true) |
|
513 | 512 | { |
514 | 513 | // Expand to keys here, so table_name can be prepended below |
515 | 514 | $only_keys = array_values($this->db_key_cols); |
516 | 515 | } |
517 | 516 | // replace ambiguous column with (an exact match of) table_name.column |
518 | - if(is_array($only_keys)) |
|
517 | + if (is_array($only_keys)) |
|
519 | 518 | { |
520 | - foreach($only_keys as $key => &$col) |
|
519 | + foreach ($only_keys as $key => &$col) |
|
521 | 520 | { |
522 | - if(is_numeric($key) && in_array($col, $this->db_cols, true)) |
|
521 | + if (is_numeric($key) && in_array($col, $this->db_cols, true)) |
|
523 | 522 | { |
524 | - $col = $this->table_name .'.'.array_search($col, $this->db_cols).' AS '.$col; |
|
523 | + $col = $this->table_name.'.'.array_search($col, $this->db_cols).' AS '.$col; |
|
525 | 524 | } |
526 | 525 | } |
527 | 526 | } |
528 | 527 | // check if we order by a custom field --> join cf table for given cf and order by it's value |
529 | - if (strpos($order_by,self::CF_PREFIX) !== false) |
|
528 | + if (strpos($order_by, self::CF_PREFIX) !== false) |
|
530 | 529 | { |
531 | 530 | // fields to order by, as cutomfields may have names with spaces, we examine each order by criteria |
532 | - $fields2order = explode(',',$order_by); |
|
533 | - foreach($fields2order as $v) |
|
531 | + $fields2order = explode(',', $order_by); |
|
532 | + foreach ($fields2order as $v) |
|
534 | 533 | { |
535 | - if (strpos($v,self::CF_PREFIX) !== false) |
|
534 | + if (strpos($v, self::CF_PREFIX) !== false) |
|
536 | 535 | { |
537 | 536 | // we found a customfield, so we split that part by space char in order to get Sorting Direction and Fieldname |
538 | - $buff = explode(' ',trim($v)); |
|
537 | + $buff = explode(' ', trim($v)); |
|
539 | 538 | $orderDir = array_pop($buff); |
540 | - $key = substr(trim(implode(' ',$buff)), 1); |
|
541 | - switch($this->customfields[$key]['type']) |
|
539 | + $key = substr(trim(implode(' ', $buff)), 1); |
|
540 | + switch ($this->customfields[$key]['type']) |
|
542 | 541 | { |
543 | 542 | case 'int': |
544 | 543 | $order_by = str_replace($v, 'extra_order.'.$this->extra_value.' IS NULL,'. |
@@ -571,26 +570,26 @@ discard block |
||
571 | 570 | { |
572 | 571 | $_cfnames = array_keys($this->customfields); |
573 | 572 | $extra_filter = null; |
574 | - foreach($filter as $name => $val) |
|
573 | + foreach ($filter as $name => $val) |
|
575 | 574 | { |
576 | 575 | // replace ambiguous auto-id with (an exact match of) table_name.autoid |
577 | 576 | if (is_string($name) && $name == $this->autoinc_id) |
578 | 577 | { |
579 | 578 | if ((int)$filter[$this->autoinc_id]) |
580 | 579 | { |
581 | - $filter[] = $this->db->expression($this->table_name,$this->table_name.'.',array( |
|
580 | + $filter[] = $this->db->expression($this->table_name, $this->table_name.'.', array( |
|
582 | 581 | $this->autoinc_id => $filter[$this->autoinc_id], |
583 | 582 | )); |
584 | 583 | } |
585 | 584 | unset($filter[$this->autoinc_id]); |
586 | 585 | } |
587 | 586 | // replace ambiguous column with (an exact match of) table_name.column |
588 | - elseif (is_string($name) && $val!=null && in_array($name, $this->db_cols)) |
|
587 | + elseif (is_string($name) && $val != null && in_array($name, $this->db_cols)) |
|
589 | 588 | { |
590 | 589 | $extra_columns = $this->db->get_table_definitions($this->app, $this->extra_table); |
591 | 590 | if ($extra_columns['fd'][array_search($name, $this->db_cols)]) |
592 | 591 | { |
593 | - $filter[] = $this->db->expression($this->table_name,$this->table_name.'.',array( |
|
592 | + $filter[] = $this->db->expression($this->table_name, $this->table_name.'.', array( |
|
594 | 593 | array_search($name, $this->db_cols) => $val, |
595 | 594 | )); |
596 | 595 | unset($filter[$name]); |
@@ -602,61 +601,61 @@ discard block |
||
602 | 601 | { |
603 | 602 | if ($val[0] === '!') // negative filter |
604 | 603 | { |
605 | - $sql_filter = 'extra_filter.'.$this->extra_value.'!='.$this->db->quote(substr($val,1)); |
|
604 | + $sql_filter = 'extra_filter.'.$this->extra_value.'!='.$this->db->quote(substr($val, 1)); |
|
606 | 605 | } |
607 | 606 | else // using Db::expression to allow to use array() with possible values or NULL |
608 | 607 | { |
609 | - if($this->customfields[$this->get_cf_name($name)]['type'] == 'select' && |
|
608 | + if ($this->customfields[$this->get_cf_name($name)]['type'] == 'select' && |
|
610 | 609 | $this->customfields[$this->get_cf_name($name)]['rows'] > 1) |
611 | 610 | { |
612 | 611 | // Multi-select - any entry with the filter value selected matches |
613 | - $sql_filter = str_replace($this->extra_value,'extra_filter.'. |
|
614 | - $this->extra_value,$this->db->expression($this->extra_table,array( |
|
615 | - $this->db->concat("','",$this->extra_value,"','").' '.$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote('%,'.$val.',%') |
|
612 | + $sql_filter = str_replace($this->extra_value, 'extra_filter.'. |
|
613 | + $this->extra_value, $this->db->expression($this->extra_table, array( |
|
614 | + $this->db->concat("','", $this->extra_value, "','").' '.$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote('%,'.$val.',%') |
|
616 | 615 | )) |
617 | 616 | ); |
618 | 617 | } |
619 | 618 | elseif ($this->customfields[$this->get_cf_name($name)]['type'] == 'text') |
620 | 619 | { |
621 | - $sql_filter = str_replace($this->extra_value,'extra_filter.'.$this->extra_value, |
|
622 | - $this->db->expression($this->extra_table,array( |
|
620 | + $sql_filter = str_replace($this->extra_value, 'extra_filter.'.$this->extra_value, |
|
621 | + $this->db->expression($this->extra_table, array( |
|
623 | 622 | $this->extra_value.' '.$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote($wildcard.$val.$wildcard) |
624 | 623 | )) |
625 | 624 | ); |
626 | 625 | } |
627 | 626 | else |
628 | 627 | { |
629 | - $sql_filter = str_replace($this->extra_value,'extra_filter.'. |
|
630 | - $this->extra_value,$this->db->expression($this->extra_table,array($this->extra_value => $val))); |
|
628 | + $sql_filter = str_replace($this->extra_value, 'extra_filter.'. |
|
629 | + $this->extra_value, $this->db->expression($this->extra_table, array($this->extra_value => $val))); |
|
631 | 630 | } |
632 | 631 | } |
633 | 632 | // need to use a LEFT JOIN for negative search or to allow NULL values |
634 | - $need_left_join = $val[0] === '!' || strpos($sql_filter,'IS NULL') !== false ? ' LEFT ' : ''; |
|
635 | - $join .= str_replace('extra_filter','extra_filter'.$extra_filter,$need_left_join.$this->extra_join_filter. |
|
633 | + $need_left_join = $val[0] === '!' || strpos($sql_filter, 'IS NULL') !== false ? ' LEFT ' : ''; |
|
634 | + $join .= str_replace('extra_filter', 'extra_filter'.$extra_filter, $need_left_join.$this->extra_join_filter. |
|
636 | 635 | ' AND extra_filter.'.$this->extra_key.'='.$this->db->quote($this->get_cf_name($name)). |
637 | 636 | ' AND '.$sql_filter); |
638 | 637 | ++$extra_filter; |
639 | 638 | } |
640 | 639 | unset($filter[$name]); |
641 | 640 | } |
642 | - elseif(is_int($name) && $this->is_cf($val)) // lettersearch: #cfname LIKE 's%' |
|
641 | + elseif (is_int($name) && $this->is_cf($val)) // lettersearch: #cfname LIKE 's%' |
|
643 | 642 | { |
644 | - $_cf = explode(' ',$val); |
|
645 | - foreach($_cf as $cf_np) |
|
643 | + $_cf = explode(' ', $val); |
|
644 | + foreach ($_cf as $cf_np) |
|
646 | 645 | { |
647 | 646 | // building cf_name by glueing parts together (, in case someone used whitespace in their custom field names) |
648 | - $tcf_name = ($tcf_name?$tcf_name.' ':'').$cf_np; |
|
647 | + $tcf_name = ($tcf_name ? $tcf_name.' ' : '').$cf_np; |
|
649 | 648 | // reacts on the first one found that matches an existing customfield, should be better then the old behavior of |
650 | 649 | // simply splitting by " " and using the first part |
651 | - if ($this->is_cf($tcf_name) && ($cfn = $this->get_cf_name($tcf_name)) && array_search($cfn,(array)$_cfnames,true)!==false ) |
|
650 | + if ($this->is_cf($tcf_name) && ($cfn = $this->get_cf_name($tcf_name)) && array_search($cfn, (array)$_cfnames, true) !== false) |
|
652 | 651 | { |
653 | 652 | $cf = $tcf_name; |
654 | 653 | break; |
655 | 654 | } |
656 | 655 | } |
657 | - $join .= str_replace('extra_filter','extra_filter'.$extra_filter,$this->extra_join_filter. |
|
656 | + $join .= str_replace('extra_filter', 'extra_filter'.$extra_filter, $this->extra_join_filter. |
|
658 | 657 | ' AND extra_filter.'.$this->extra_key.'='.$this->db->quote($this->get_cf_name($cf)). |
659 | - ' AND '.str_replace($cf,'extra_filter.'.$this->extra_value,$val)); |
|
658 | + ' AND '.str_replace($cf, 'extra_filter.'.$this->extra_value, $val)); |
|
660 | 659 | ++$extra_filter; |
661 | 660 | unset($filter[$name]); |
662 | 661 | } |
@@ -668,15 +667,14 @@ discard block |
||
668 | 667 | if (is_array($only_keys)) |
669 | 668 | { |
670 | 669 | $only_keys = array_values($only_keys); |
671 | - $only_keys[0] = 'DISTINCT '.($only_keys[0] != $this->autoinc_id ? $only_keys[0] : |
|
672 | - $this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id); |
|
670 | + $only_keys[0] = 'DISTINCT '.($only_keys[0] != $this->autoinc_id ? $only_keys[0] : $this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id); |
|
673 | 671 | } |
674 | 672 | else |
675 | 673 | { |
676 | 674 | $only_keys = 'DISTINCT '.$only_keys; |
677 | 675 | } |
678 | 676 | } |
679 | - return parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count); |
|
677 | + return parent::search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, $start, $filter, $join, $need_full_no_count); |
|
680 | 678 | } |
681 | 679 | |
682 | 680 | /** |
@@ -716,7 +714,7 @@ discard block |
||
716 | 714 | */ |
717 | 715 | function get_cf_name($field) |
718 | 716 | { |
719 | - return substr($field,1); |
|
717 | + return substr($field, 1); |
|
720 | 718 | } |
721 | 719 | |
722 | 720 | /** |
@@ -738,7 +736,7 @@ discard block |
||
738 | 736 | */ |
739 | 737 | function is_multiple($name) |
740 | 738 | { |
741 | - return $this->allow_multiple_values && in_array($this->customfields[$name]['type'],array('select','select-account')) && |
|
739 | + return $this->allow_multiple_values && in_array($this->customfields[$name]['type'], array('select', 'select-account')) && |
|
742 | 740 | $this->customfields[$name]['rows'] > 1; |
743 | 741 | } |
744 | 742 | } |
@@ -127,7 +127,11 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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])) |
@@ -220,7 +240,10 @@ discard block |
||
220 | 240 | { |
221 | 241 | foreach (array_keys((array)$this->customfields) as $name) |
222 | 242 | { |
223 | - if (!isset($data[$field = $this->get_cf_field($name)])) continue; |
|
243 | + if (!isset($data[$field = $this->get_cf_field($name)])) |
|
244 | + { |
|
245 | + continue; |
|
246 | + } |
|
224 | 247 | |
225 | 248 | $where = array( |
226 | 249 | $this->extra_id => isset($data[$this->autoinc_id]) ? $data[$this->autoinc_id] : $data[$this->db_key_cols[$this->autoinc_id]], |
@@ -232,7 +255,11 @@ discard block |
||
232 | 255 | if(empty($data[$field]) || $is_multiple || !$this->extra_has_unique_index) |
233 | 256 | { |
234 | 257 | $this->db->delete($this->extra_table,$where,__LINE__,__FILE__,$this->app); |
235 | - if (empty($data[$field])) continue; // nothing else to do for empty values |
|
258 | + if (empty($data[$field])) |
|
259 | + { |
|
260 | + continue; |
|
261 | + } |
|
262 | + // nothing else to do for empty values |
|
236 | 263 | } |
237 | 264 | foreach($is_multiple && !is_array($data[$field]) ? explode(',',$data[$field]) : |
238 | 265 | // regular custom fields (!$is_multiple) eg. addressbook store multiple values comma-separated |
@@ -305,9 +332,12 @@ discard block |
||
305 | 332 | */ |
306 | 333 | function save($keys=null,$extra_where=null) |
307 | 334 | { |
308 | - if (is_array($keys) && count($keys) && !isset($keys[0])) // allow to use an etag, eg array('etag=etag+1') |
|
335 | + if (is_array($keys) && count($keys) && !isset($keys[0])) |
|
336 | + { |
|
337 | + // allow to use an etag, eg array('etag=etag+1') |
|
309 | 338 | { |
310 | 339 | $this->data_merge($keys); |
340 | + } |
|
311 | 341 | $keys = null; |
312 | 342 | } |
313 | 343 | $ret = parent::save($keys,$extra_where); |
@@ -340,13 +370,20 @@ discard block |
||
340 | 370 | { |
341 | 371 | $ids[] = $row[$this->autoinc_id]; |
342 | 372 | } |
343 | - if (!$ids) return 0; // no rows affected |
|
373 | + if (!$ids) |
|
374 | + { |
|
375 | + return 0; |
|
376 | + } |
|
377 | + // no rows affected |
|
344 | 378 | } |
345 | 379 | else |
346 | 380 | { |
347 | 381 | $ids = (array)$query[$this->autoinc_id]; |
348 | 382 | } |
349 | - if ($only_return_ids) return $ids; |
|
383 | + if ($only_return_ids) |
|
384 | + { |
|
385 | + return $ids; |
|
386 | + } |
|
350 | 387 | $this->db->delete($this->extra_table,array($this->extra_id => $ids),__LINE__,__FILE__); |
351 | 388 | } |
352 | 389 | return parent::delete($keys); |
@@ -388,7 +425,10 @@ discard block |
||
388 | 425 | { |
389 | 426 | foreach($selectcols as $col) |
390 | 427 | { |
391 | - if ($this->is_cf($col)) $fields[] = $this->get_cf_name($col); |
|
428 | + if ($this->is_cf($col)) |
|
429 | + { |
|
430 | + $fields[] = $this->get_cf_name($col); |
|
431 | + } |
|
392 | 432 | } |
393 | 433 | } |
394 | 434 | if (($cfs = $this->read_customfields(array_keys($id2keys),$fields))) |
@@ -507,7 +547,10 @@ discard block |
||
507 | 547 | } |
508 | 548 | } |
509 | 549 | } |
510 | - if ($cfcriteria && $op =='OR') $criteria[] = implode(' OR ',$cfcriteria); |
|
550 | + if ($cfcriteria && $op =='OR') |
|
551 | + { |
|
552 | + $criteria[] = implode(' OR ',$cfcriteria); |
|
553 | + } |
|
511 | 554 | } |
512 | 555 | if($only_keys === true) |
513 | 556 | { |
@@ -598,11 +641,14 @@ discard block |
||
598 | 641 | } |
599 | 642 | elseif (is_string($name) && $this->is_cf($name)) |
600 | 643 | { |
601 | - if (!empty($val)) // empty -> dont filter |
|
644 | + if (!empty($val)) |
|
645 | + { |
|
646 | + // empty -> dont filter |
|
602 | 647 | { |
603 | 648 | if ($val[0] === '!') // negative filter |
604 | 649 | { |
605 | 650 | $sql_filter = 'extra_filter.'.$this->extra_value.'!='.$this->db->quote(substr($val,1)); |
651 | + } |
|
606 | 652 | } |
607 | 653 | else // using Db::expression to allow to use array() with possible values or NULL |
608 | 654 | { |
@@ -639,9 +685,12 @@ discard block |
||
639 | 685 | } |
640 | 686 | unset($filter[$name]); |
641 | 687 | } |
642 | - elseif(is_int($name) && $this->is_cf($val)) // lettersearch: #cfname LIKE 's%' |
|
688 | + elseif(is_int($name) && $this->is_cf($val)) |
|
689 | + { |
|
690 | + // lettersearch: #cfname LIKE 's%' |
|
643 | 691 | { |
644 | 692 | $_cf = explode(' ',$val); |
693 | + } |
|
645 | 694 | foreach($_cf as $cf_np) |
646 | 695 | { |
647 | 696 | // building cf_name by glueing parts together (, in case someone used whitespace in their custom field names) |