@@ -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 | { |
@@ -303,7 +303,10 @@ discard block |
||
303 | 303 | { |
304 | 304 | foreach($allValues[0][static::MAIL_ATTR] as $key => $value) |
305 | 305 | { |
306 | - if ($key === 'count') continue; |
|
306 | + if ($key === 'count') |
|
307 | + { |
|
308 | + continue; |
|
309 | + } |
|
307 | 310 | |
308 | 311 | $emailAddresses[] = array ( |
309 | 312 | 'name' => $realName, |
@@ -324,7 +327,10 @@ discard block |
||
324 | 327 | } |
325 | 328 | } |
326 | 329 | } |
327 | - if ($this->debug) error_log(__METHOD__."('$_accountName') returning ".array2string($emailAddresses)); |
|
330 | + if ($this->debug) |
|
331 | + { |
|
332 | + error_log(__METHOD__."('$_accountName') returning ".array2string($emailAddresses)); |
|
333 | + } |
|
328 | 334 | |
329 | 335 | return $emailAddresses; |
330 | 336 | } |
@@ -357,7 +363,10 @@ discard block |
||
357 | 363 | } |
358 | 364 | elseif (strpos($user, '@') === false) |
359 | 365 | { |
360 | - if (is_numeric($user)) $user = $GLOBALS['egw']->accounts->id2name($user); |
|
366 | + if (is_numeric($user)) |
|
367 | + { |
|
368 | + $user = $GLOBALS['egw']->accounts->id2name($user); |
|
369 | + } |
|
361 | 370 | $filter = '(&'.static::USER_FILTER.'('.static::USER_ATTR.'='.Api\Ldap::quote($user).'))'; |
362 | 371 | } |
363 | 372 | else // email address --> build filter by attributes defined in config |
@@ -374,7 +383,10 @@ discard block |
||
374 | 383 | else |
375 | 384 | { |
376 | 385 | $to_or = array('('.static::MAIL_ATTR.'='.Api\Ldap::quote($user).')'); |
377 | - if ($match_uid_at_domain) $to_or[] = '('.static::USER_ATTR.'='.Api\Ldap::quote($namepart).')'; |
|
386 | + if ($match_uid_at_domain) |
|
387 | + { |
|
388 | + $to_or[] = '('.static::USER_ATTR.'='.Api\Ldap::quote($namepart).')'; |
|
389 | + } |
|
378 | 390 | if (static::ALIAS_ATTR) |
379 | 391 | { |
380 | 392 | $to_or[] = '('.static::ALIAS_ATTR.'='.static::ALIAS_PREFIX.Api\Ldap::quote($user).')'; |
@@ -399,11 +411,17 @@ discard block |
||
399 | 411 | if ($sri) |
400 | 412 | { |
401 | 413 | $allValues = ldap_get_entries($ldap, $sri); |
402 | - if ($this->debug) error_log(__METHOD__."('$user') --> ldap_search(, '$this->search_base', '$filter') --> ldap_get_entries=".array2string($allValues[0])); |
|
414 | + if ($this->debug) |
|
415 | + { |
|
416 | + error_log(__METHOD__."('$user') --> ldap_search(, '$this->search_base', '$filter') --> ldap_get_entries=".array2string($allValues[0])); |
|
417 | + } |
|
403 | 418 | |
404 | 419 | foreach($allValues as $key => $values) |
405 | 420 | { |
406 | - if ($key === 'count') continue; |
|
421 | + if ($key === 'count') |
|
422 | + { |
|
423 | + continue; |
|
424 | + } |
|
407 | 425 | |
408 | 426 | // groups are always active (if they have an email) and allways forwardOnly |
409 | 427 | if (in_array(static::GROUP_SCHEMA, $values['objectclass'])) |
@@ -445,11 +463,14 @@ discard block |
||
445 | 463 | } |
446 | 464 | } |
447 | 465 | } |
448 | - elseif (static::FORWARD_ONLY) // check caseinsensitiv for existence of that value |
|
466 | + elseif (static::FORWARD_ONLY) |
|
467 | + { |
|
468 | + // check caseinsensitiv for existence of that value |
|
449 | 469 | { |
450 | 470 | $deliveryMode = self::getAttributePrefix($values[static::FORWARD_ONLY_ATTR], static::FORWARD_ONLY) ? |
451 | 471 | Mail\Smtp::FORWARD_ONLY : ''; |
452 | 472 | } |
473 | + } |
|
453 | 474 | else // check for existence of any value |
454 | 475 | { |
455 | 476 | $deliveryMode = $values[static::FORWARD_ONLY_ATTR]['count'] > 0 ? |
@@ -482,7 +503,10 @@ discard block |
||
482 | 503 | } |
483 | 504 | |
484 | 505 | // regular user-data can only be from users, NOT groups |
485 | - if (in_array(static::GROUP_SCHEMA, $values['objectclass'])) continue; |
|
506 | + if (in_array(static::GROUP_SCHEMA, $values['objectclass'])) |
|
507 | + { |
|
508 | + continue; |
|
509 | + } |
|
486 | 510 | |
487 | 511 | $userData['mailLocalAddress'] = $values[static::MAIL_ATTR][0]; |
488 | 512 | $userData['accountStatus'] = $accountStatus; |
@@ -507,7 +531,10 @@ discard block |
||
507 | 531 | $userData['mailForwardingAddress'] = self::getAttributePrefix($values[static::FORWARD_ATTR], static::FORWARD_PREFIX); |
508 | 532 | } |
509 | 533 | |
510 | - if (static::MAILBOX_ATTR) $userData['mailMessageStore'] = $values[static::MAILBOX_ATTR][0]; |
|
534 | + if (static::MAILBOX_ATTR) |
|
535 | + { |
|
536 | + $userData['mailMessageStore'] = $values[static::MAILBOX_ATTR][0]; |
|
537 | + } |
|
511 | 538 | |
512 | 539 | $userData['deliveryMode'] = $deliveryMode; |
513 | 540 | |
@@ -526,7 +553,10 @@ discard block |
||
526 | 553 | } |
527 | 554 | } |
528 | 555 | } |
529 | - if ($this->debug) error_log(__METHOD__."('$user') returning ".array2string($userData)); |
|
556 | + if ($this->debug) |
|
557 | + { |
|
558 | + error_log(__METHOD__."('$user') returning ".array2string($userData)); |
|
559 | + } |
|
530 | 560 | |
531 | 561 | return $userData; |
532 | 562 | } |
@@ -649,7 +679,10 @@ discard block |
||
649 | 679 | |
650 | 680 | $this->addAccountExtra(array('location' => 'setUserData'), $allValues[0], $newData); |
651 | 681 | |
652 | - if ($this->debug) error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'$accountDN',".array2string($newData).')'); |
|
682 | + if ($this->debug) |
|
683 | + { |
|
684 | + error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'$accountDN',".array2string($newData).')'); |
|
685 | + } |
|
653 | 686 | |
654 | 687 | if (!($ret = @ldap_mod_replace($ldap, $accountDN, $newData)) && static::CHECK_FORWARD_ATTR) |
655 | 688 | { |
@@ -749,7 +782,10 @@ discard block |
||
749 | 782 | // merge in again all new set forwards incl. opt. prefix |
750 | 783 | self::setAttributePrefix($newData[static::FORWARD_ATTR], $forwards, static::FORWARD_PREFIX); |
751 | 784 | } |
752 | - if ($this->debug) error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'{$allValues[0]['dn']}',".array2string($newData).')'); |
|
785 | + if ($this->debug) |
|
786 | + { |
|
787 | + error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'{$allValues[0]['dn']}',".array2string($newData).')'); |
|
788 | + } |
|
753 | 789 | |
754 | 790 | return ldap_modify ($ds, $allValues[0]['dn'], $newData); |
755 | 791 | } |
@@ -795,7 +831,11 @@ discard block |
||
795 | 831 | $mailboxes = array(); |
796 | 832 | foreach($entries as $entry) |
797 | 833 | { |
798 | - if ($entry[static::USER_ATTR][0] == 'anonymous') continue; // anonymous is never a mail-user! |
|
834 | + if ($entry[static::USER_ATTR][0] == 'anonymous') |
|
835 | + { |
|
836 | + continue; |
|
837 | + } |
|
838 | + // anonymous is never a mail-user! |
|
799 | 839 | list($mailbox) = explode('@', $entry[static::MAILBOX_ATTR ? static::MAILBOX_ATTR : static::MAIL_ATTR][0]); |
800 | 840 | $mailboxes[$entry[static::USER_ATTR][0]] = $mailbox; |
801 | 841 | } |
@@ -812,8 +852,14 @@ discard block |
||
812 | 852 | protected static function setAttributePrefix(&$attribute, $values, $prefix='') |
813 | 853 | { |
814 | 854 | //$attribute_in = $attribute; |
815 | - if (empty($attribute)) $attribute = array(); |
|
816 | - if (!is_array($attribute)) $attribute = (array)$attribute; |
|
855 | + if (empty($attribute)) |
|
856 | + { |
|
857 | + $attribute = array(); |
|
858 | + } |
|
859 | + if (!is_array($attribute)) |
|
860 | + { |
|
861 | + $attribute = (array)$attribute; |
|
862 | + } |
|
817 | 863 | |
818 | 864 | foreach((array)$values as $value) |
819 | 865 | { |
@@ -843,12 +889,18 @@ discard block |
||
843 | 889 | { |
844 | 890 | if (!$prefix || stripos($value, $prefix) === 0) |
845 | 891 | { |
846 | - if ($remove) unset($attribute[$key]); |
|
892 | + if ($remove) |
|
893 | + { |
|
894 | + unset($attribute[$key]); |
|
895 | + } |
|
847 | 896 | $values[] = substr($value, strlen($prefix)); |
848 | 897 | } |
849 | 898 | } |
850 | 899 | // reindex $attribute, if neccessary |
851 | - if ($values && $attribute) $attribute = array_values($attribute); |
|
900 | + if ($values && $attribute) |
|
901 | + { |
|
902 | + $attribute = array_values($attribute); |
|
903 | + } |
|
852 | 904 | } |
853 | 905 | //error_log(__METHOD__."(".array2string($attribute_in).", '$prefix', $remove) attribute=".array2string($attribute).' returning '.array2string($values)); |
854 | 906 | return $values; |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | * |
165 | 165 | * @param string $defaultDomain =null |
166 | 166 | */ |
167 | - function __construct($defaultDomain=null) |
|
167 | + function __construct($defaultDomain = null) |
|
168 | 168 | { |
169 | 169 | parent::__construct($defaultDomain); |
170 | 170 | |
@@ -212,9 +212,8 @@ discard block |
||
212 | 212 | */ |
213 | 213 | function addAccount($_hookValues) |
214 | 214 | { |
215 | - $mailLocalAddress = $_hookValues['account_email'] ? $_hookValues['account_email'] : |
|
216 | - Api\Accounts::email($_hookValues['account_firstname'], |
|
217 | - $_hookValues['account_lastname'],$_hookValues['account_lid'],$this->defaultDomain); |
|
215 | + $mailLocalAddress = $_hookValues['account_email'] ? $_hookValues['account_email'] : Api\Accounts::email($_hookValues['account_firstname'], |
|
216 | + $_hookValues['account_lastname'], $_hookValues['account_lid'], $this->defaultDomain); |
|
218 | 217 | |
219 | 218 | $ds = $this->getLdapConnection(); |
220 | 219 | |
@@ -226,13 +225,13 @@ discard block |
||
226 | 225 | } |
227 | 226 | $allValues = ldap_get_entries($ds, $sri); |
228 | 227 | $accountDN = $allValues[0]['dn']; |
229 | - $objectClasses = $allValues[0]['objectclass']; |
|
228 | + $objectClasses = $allValues[0]['objectclass']; |
|
230 | 229 | unset($objectClasses['count']); |
231 | 230 | |
232 | 231 | // add our mail schema, if not already set |
233 | - if(!in_array(static::SCHEMA,$objectClasses) && !in_array(strtolower(static::SCHEMA),$objectClasses)) |
|
232 | + if (!in_array(static::SCHEMA, $objectClasses) && !in_array(strtolower(static::SCHEMA), $objectClasses)) |
|
234 | 233 | { |
235 | - $objectClasses[] = static::SCHEMA; |
|
234 | + $objectClasses[] = static::SCHEMA; |
|
236 | 235 | } |
237 | 236 | // the new code for postfix+cyrus+ldap |
238 | 237 | $newData = array( |
@@ -263,7 +262,7 @@ discard block |
||
263 | 262 | { |
264 | 263 | error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'$accountDN',". |
265 | 264 | array2string($newData).') returning '.array2string($ret). |
266 | - (!$ret?' ('.ldap_error($ds).')':'')); |
|
265 | + (!$ret ? ' ('.ldap_error($ds).')' : '')); |
|
267 | 266 | } |
268 | 267 | return $ret; |
269 | 268 | } |
@@ -277,7 +276,7 @@ discard block |
||
277 | 276 | */ |
278 | 277 | function addAccountExtra(array $_hookValues, array $allValues, array &$newData) |
279 | 278 | { |
280 | - unset($_hookValues, $allValues, $newData); // not used, but required by function signature |
|
279 | + unset($_hookValues, $allValues, $newData); // not used, but required by function signature |
|
281 | 280 | } |
282 | 281 | |
283 | 282 | /** |
@@ -288,24 +287,24 @@ discard block |
||
288 | 287 | */ |
289 | 288 | function getAccountEmailAddress($_accountName) |
290 | 289 | { |
291 | - $emailAddresses = array(); |
|
290 | + $emailAddresses = array(); |
|
292 | 291 | $ds = $this->getLdapConnection(); |
293 | 292 | $filter = '(&'.static::USER_FILTER.'('.static::USER_ATTR.'='.Api\Ldap::quote($_accountName).'))'; |
294 | - $attributes = array('dn', static::MAIL_ATTR, static::ALIAS_ATTR); |
|
293 | + $attributes = array('dn', static::MAIL_ATTR, static::ALIAS_ATTR); |
|
295 | 294 | $sri = @ldap_search($ds, $this->search_base, $filter, $attributes); |
296 | 295 | |
297 | 296 | if ($sri) |
298 | 297 | { |
299 | - $realName = trim($GLOBALS['egw_info']['user']['account_firstname'] . (!empty($GLOBALS['egw_info']['user']['account_firstname']) ? ' ' : '') . $GLOBALS['egw_info']['user']['account_lastname']); |
|
298 | + $realName = trim($GLOBALS['egw_info']['user']['account_firstname'].(!empty($GLOBALS['egw_info']['user']['account_firstname']) ? ' ' : '').$GLOBALS['egw_info']['user']['account_lastname']); |
|
300 | 299 | $allValues = ldap_get_entries($ds, $sri); |
301 | 300 | |
302 | - if(isset($allValues[0][static::MAIL_ATTR])) |
|
301 | + if (isset($allValues[0][static::MAIL_ATTR])) |
|
303 | 302 | { |
304 | - foreach($allValues[0][static::MAIL_ATTR] as $key => $value) |
|
303 | + foreach ($allValues[0][static::MAIL_ATTR] as $key => $value) |
|
305 | 304 | { |
306 | 305 | if ($key === 'count') continue; |
307 | 306 | |
308 | - $emailAddresses[] = array ( |
|
307 | + $emailAddresses[] = array( |
|
309 | 308 | 'name' => $realName, |
310 | 309 | 'address' => $value, |
311 | 310 | 'type' => !$key ? 'default' : 'alternate', |
@@ -314,7 +313,7 @@ discard block |
||
314 | 313 | } |
315 | 314 | if (static::ALIAS_ATTR && isset($allValues[0][static::ALIAS_ATTR])) |
316 | 315 | { |
317 | - foreach(self::getAttributePrefix($allValues[0][static::ALIAS_ATTR], static::ALIAS_PREFIX) as $value) |
|
316 | + foreach (self::getAttributePrefix($allValues[0][static::ALIAS_ATTR], static::ALIAS_PREFIX) as $value) |
|
318 | 317 | { |
319 | 318 | $emailAddresses[] = array( |
320 | 319 | 'name' => $realName, |
@@ -341,7 +340,7 @@ discard block |
||
341 | 340 | * @return array with values for keys 'mailLocalAddress', 'mailAlternateAddress' (array), 'mailForwardingAddress' (array), |
342 | 341 | * 'accountStatus' ("active"), 'quotaLimit' and 'deliveryMode' ("forwardOnly") |
343 | 342 | */ |
344 | - function getUserData($user, $match_uid_at_domain=false) |
|
343 | + function getUserData($user, $match_uid_at_domain = false) |
|
345 | 344 | { |
346 | 345 | $userData = array( |
347 | 346 | 'mailbox' => array(), |
@@ -401,7 +400,7 @@ discard block |
||
401 | 400 | $allValues = ldap_get_entries($ldap, $sri); |
402 | 401 | if ($this->debug) error_log(__METHOD__."('$user') --> ldap_search(, '$this->search_base', '$filter') --> ldap_get_entries=".array2string($allValues[0])); |
403 | 402 | |
404 | - foreach($allValues as $key => $values) |
|
403 | + foreach ($allValues as $key => $values) |
|
405 | 404 | { |
406 | 405 | if ($key === 'count') continue; |
407 | 406 | |
@@ -504,16 +503,16 @@ discard block |
||
504 | 503 | // remember if server returned forward-attribute |
505 | 504 | $this->forward_attr_returned = isset($values[static::FORWARD_ATTR]); |
506 | 505 | |
507 | - $userData['mailForwardingAddress'] = self::getAttributePrefix($values[static::FORWARD_ATTR], static::FORWARD_PREFIX); |
|
506 | + $userData['mailForwardingAddress'] = self::getAttributePrefix($values[static::FORWARD_ATTR], static::FORWARD_PREFIX); |
|
508 | 507 | } |
509 | 508 | |
510 | - if (static::MAILBOX_ATTR) $userData['mailMessageStore'] = $values[static::MAILBOX_ATTR][0]; |
|
509 | + if (static::MAILBOX_ATTR) $userData['mailMessageStore'] = $values[static::MAILBOX_ATTR][0]; |
|
511 | 510 | |
512 | 511 | $userData['deliveryMode'] = $deliveryMode; |
513 | 512 | |
514 | 513 | // eg. suse stores all email addresses as aliases |
515 | 514 | if (static::REQUIRE_MAIL_AS_ALIAS && |
516 | - ($k = array_search($userData['mailLocalAddress'],$userData['mailAlternateAddress'])) !== false) |
|
515 | + ($k = array_search($userData['mailLocalAddress'], $userData['mailAlternateAddress'])) !== false) |
|
517 | 516 | { |
518 | 517 | unset($userData['mailAlternateAddress'][$k]); |
519 | 518 | $userData['mailAlternateAddress'] = array_values($userData['mailAlternateAddress']); |
@@ -547,9 +546,9 @@ discard block |
||
547 | 546 | * @return boolean true on success, false on error writing to ldap |
548 | 547 | */ |
549 | 548 | function setUserData($_uidnumber, array $_mailAlternateAddress, array $_mailForwardingAddress, $_deliveryMode, |
550 | - $_accountStatus, $_mailLocalAddress, $_quota, $_forwarding_only=false, $_setMailbox=null) |
|
549 | + $_accountStatus, $_mailLocalAddress, $_quota, $_forwarding_only = false, $_setMailbox = null) |
|
551 | 550 | { |
552 | - unset($_forwarding_only); // not used |
|
551 | + unset($_forwarding_only); // not used |
|
553 | 552 | |
554 | 553 | if (static::USERID_ATTR) |
555 | 554 | { |
@@ -569,15 +568,15 @@ discard block |
||
569 | 568 | $allValues = ldap_get_entries($ldap, $sri); |
570 | 569 | |
571 | 570 | $accountDN = $allValues[0]['dn']; |
572 | - $uid = $allValues[0][static::USER_ATTR][0]; |
|
573 | - $objectClasses = $allValues[0]['objectclass']; |
|
571 | + $uid = $allValues[0][static::USER_ATTR][0]; |
|
572 | + $objectClasses = $allValues[0]['objectclass']; |
|
574 | 573 | |
575 | 574 | unset($objectClasses['count']); |
576 | 575 | |
577 | - if(!in_array(static::SCHEMA,$objectClasses) && !in_array(strtolower(static::SCHEMA),$objectClasses)) |
|
576 | + if (!in_array(static::SCHEMA, $objectClasses) && !in_array(strtolower(static::SCHEMA), $objectClasses)) |
|
578 | 577 | { |
579 | - $objectClasses[] = static::SCHEMA; |
|
580 | - $newData['objectclass'] = $objectClasses; |
|
578 | + $objectClasses[] = static::SCHEMA; |
|
579 | + $newData['objectclass'] = $objectClasses; |
|
581 | 580 | } |
582 | 581 | |
583 | 582 | sort($_mailAlternateAddress); |
@@ -590,7 +589,7 @@ discard block |
||
590 | 589 | self::setAttributePrefix($newData[static::ALIAS_ATTR], $_mailAlternateAddress, static::ALIAS_PREFIX); |
591 | 590 | |
592 | 591 | // all email must be stored as alias for suse |
593 | - if (static::REQUIRE_MAIL_AS_ALIAS && !in_array($_mailLocalAddress,(array)$_mailAlternateAddress)) |
|
592 | + if (static::REQUIRE_MAIL_AS_ALIAS && !in_array($_mailLocalAddress, (array)$_mailAlternateAddress)) |
|
594 | 593 | { |
595 | 594 | self::setAttributePrefix($newData[static::ALIAS_ATTR], $_mailLocalAddress, static::ALIAS_PREFIX); |
596 | 595 | } |
@@ -628,12 +627,12 @@ discard block |
||
628 | 627 | if (static::QUOTA_ATTR) |
629 | 628 | { |
630 | 629 | self::setAttributePrefix($newData[static::QUOTA_ATTR], |
631 | - (int)$_quota > 0 ? (int)$_quota*static::QUOTA_FACTOR : array(), static::QUOTA_PREFIX); |
|
630 | + (int)$_quota > 0 ? (int)$_quota * static::QUOTA_FACTOR : array(), static::QUOTA_PREFIX); |
|
632 | 631 | } |
633 | 632 | // does schema support enabling/disabling mail via attribute |
634 | 633 | if (static::MAIL_ENABLE_ATTR) |
635 | 634 | { |
636 | - $newData[static::MAIL_ENABLE_ATTR] = $_accountStatus ? |
|
635 | + $newData[static::MAIL_ENABLE_ATTR] = $_accountStatus ? |
|
637 | 636 | (static::MAIL_ENABLED == self::MAIL_ENABLED_USE_MAIL ? $_mailLocalAddress : static::MAIL_ENABLED) : array(); |
638 | 637 | } |
639 | 638 | // if we have no mail-enabled attribute, but require primary mail in aliases-attr |
@@ -681,7 +680,7 @@ discard block |
||
681 | 680 | $uid = $GLOBALS['egw']->accounts->id2name($_accountID); |
682 | 681 | $filter = '(&'.static::USER_FILTER.'('.static::USER_ATTR.'='.Api\Ldap::quote($uid).'))'; |
683 | 682 | } |
684 | - $attributes = array('dn', static::MAIL_ATTR, static::FORWARD_ATTR, 'objectclass'); |
|
683 | + $attributes = array('dn', static::MAIL_ATTR, static::FORWARD_ATTR, 'objectclass'); |
|
685 | 684 | if (static::FORWARD_ONLY_ATTR) |
686 | 685 | { |
687 | 686 | $attributes[] = static::FORWARD_ONLY_ATTR; |
@@ -692,12 +691,12 @@ discard block |
||
692 | 691 | { |
693 | 692 | $newData = array(); |
694 | 693 | $allValues = ldap_get_entries($ds, $sri); |
695 | - $objectClasses = $allValues[0]['objectclass']; |
|
696 | - $newData['objectclass'] = $allValues[0]['objectclass']; |
|
694 | + $objectClasses = $allValues[0]['objectclass']; |
|
695 | + $newData['objectclass'] = $allValues[0]['objectclass']; |
|
697 | 696 | |
698 | 697 | unset($newData['objectclass']['count']); |
699 | 698 | |
700 | - if(!in_array(static::SCHEMA,$objectClasses)) |
|
699 | + if (!in_array(static::SCHEMA, $objectClasses)) |
|
701 | 700 | { |
702 | 701 | $newData['objectclass'][] = static::SCHEMA; |
703 | 702 | } |
@@ -707,9 +706,9 @@ discard block |
||
707 | 706 | $newData[static::FORWARD_ATTR] = $allValues[0][static::FORWARD_ATTR]; |
708 | 707 | $forwards = self::getAttributePrefix($newData[static::FORWARD_ATTR], static::FORWARD_PREFIX); |
709 | 708 | |
710 | - if(!empty($_forwardingAddress)) |
|
709 | + if (!empty($_forwardingAddress)) |
|
711 | 710 | { |
712 | - if($forwards) |
|
711 | + if ($forwards) |
|
713 | 712 | { |
714 | 713 | if (!is_array($_forwardingAddress)) |
715 | 714 | { |
@@ -752,7 +751,7 @@ discard block |
||
752 | 751 | } |
753 | 752 | if ($this->debug) error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'{$allValues[0]['dn']}',".array2string($newData).')'); |
754 | 753 | |
755 | - return ldap_modify ($ds, $allValues[0]['dn'], $newData); |
|
754 | + return ldap_modify($ds, $allValues[0]['dn'], $newData); |
|
756 | 755 | } |
757 | 756 | } |
758 | 757 | |
@@ -794,9 +793,9 @@ discard block |
||
794 | 793 | unset($entries['count']); |
795 | 794 | |
796 | 795 | $mailboxes = array(); |
797 | - foreach($entries as $entry) |
|
796 | + foreach ($entries as $entry) |
|
798 | 797 | { |
799 | - if ($entry[static::USER_ATTR][0] == 'anonymous') continue; // anonymous is never a mail-user! |
|
798 | + if ($entry[static::USER_ATTR][0] == 'anonymous') continue; // anonymous is never a mail-user! |
|
800 | 799 | list($mailbox) = explode('@', $entry[static::MAILBOX_ATTR ? static::MAILBOX_ATTR : static::MAIL_ATTR][0]); |
801 | 800 | $mailboxes[$entry[static::USER_ATTR][0]] = $mailbox; |
802 | 801 | } |
@@ -810,13 +809,13 @@ discard block |
||
810 | 809 | * @param string|array $values value(s) to set |
811 | 810 | * @param string $prefix ='' prefix to use or '' |
812 | 811 | */ |
813 | - protected static function setAttributePrefix(&$attribute, $values, $prefix='') |
|
812 | + protected static function setAttributePrefix(&$attribute, $values, $prefix = '') |
|
814 | 813 | { |
815 | 814 | //$attribute_in = $attribute; |
816 | 815 | if (empty($attribute)) $attribute = array(); |
817 | 816 | if (!is_array($attribute)) $attribute = (array)$attribute; |
818 | 817 | |
819 | - foreach((array)$values as $value) |
|
818 | + foreach ((array)$values as $value) |
|
820 | 819 | { |
821 | 820 | $attribute[] = $prefix.$value; |
822 | 821 | } |
@@ -831,7 +830,7 @@ discard block |
||
831 | 830 | * @param boolean $remove =true remove returned values from $attribute |
832 | 831 | * @return array with values (prefix removed) or array() if nothing found |
833 | 832 | */ |
834 | - protected static function getAttributePrefix(&$attribute, $prefix='', $remove=true) |
|
833 | + protected static function getAttributePrefix(&$attribute, $prefix = '', $remove = true) |
|
835 | 834 | { |
836 | 835 | //$attribute_in = $attribute; |
837 | 836 | $values = array(); |
@@ -840,7 +839,7 @@ discard block |
||
840 | 839 | { |
841 | 840 | unset($attribute['count']); |
842 | 841 | |
843 | - foreach($attribute as $key => $value) |
|
842 | + foreach ($attribute as $key => $value) |
|
844 | 843 | { |
845 | 844 | if (!$prefix || stripos($value, $prefix) === 0) |
846 | 845 | { |
@@ -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 | */ |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | const CD_BAD_LOGIN_OR_PASSWORD = 5; |
168 | 168 | const CD_FORCE_PASSWORD_CHANGE = 97; |
169 | 169 | const CD_ACCOUNT_EXPIRED = 98; |
170 | - const CD_BLOCKED = 99; // to many failed attempts to loing |
|
170 | + const CD_BLOCKED = 99; // to many failed attempts to loing |
|
171 | 171 | |
172 | 172 | /** |
173 | 173 | * Verbose reason why session creation failed |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * |
189 | 189 | * @param array $domain_names =null domain-names used in this install |
190 | 190 | */ |
191 | - function __construct(array $domain_names=null) |
|
191 | + function __construct(array $domain_names = null) |
|
192 | 192 | { |
193 | 193 | $this->required_files = $_SESSION[self::EGW_REQUIRED_FILES]; |
194 | 194 | |
@@ -204,27 +204,27 @@ discard block |
||
204 | 204 | $save_rep = false; |
205 | 205 | if (!isset($GLOBALS['egw_info']['server']['max_access_log_age'])) |
206 | 206 | { |
207 | - $GLOBALS['egw_info']['server']['max_access_log_age'] = 90; // default 90 days |
|
207 | + $GLOBALS['egw_info']['server']['max_access_log_age'] = 90; // default 90 days |
|
208 | 208 | $save_rep = true; |
209 | 209 | } |
210 | 210 | if (!isset($GLOBALS['egw_info']['server']['block_time'])) |
211 | 211 | { |
212 | - $GLOBALS['egw_info']['server']['block_time'] = 1; // default 1min, its enough to slow down brute force attacks |
|
212 | + $GLOBALS['egw_info']['server']['block_time'] = 1; // default 1min, its enough to slow down brute force attacks |
|
213 | 213 | $save_rep = true; |
214 | 214 | } |
215 | 215 | if (!isset($GLOBALS['egw_info']['server']['num_unsuccessful_id'])) |
216 | 216 | { |
217 | - $GLOBALS['egw_info']['server']['num_unsuccessful_id'] = 3; // default 3 trys per id |
|
217 | + $GLOBALS['egw_info']['server']['num_unsuccessful_id'] = 3; // default 3 trys per id |
|
218 | 218 | $save_rep = true; |
219 | 219 | } |
220 | 220 | if (!isset($GLOBALS['egw_info']['server']['num_unsuccessful_ip'])) |
221 | 221 | { |
222 | - $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 | + $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 |
|
223 | 223 | $save_rep = true; |
224 | 224 | } |
225 | 225 | if (!isset($GLOBALS['egw_info']['server']['install_id'])) |
226 | 226 | { |
227 | - $GLOBALS['egw_info']['server']['install_id'] = md5(Auth::randomstring(15)); |
|
227 | + $GLOBALS['egw_info']['server']['install_id'] = md5(Auth::randomstring(15)); |
|
228 | 228 | } |
229 | 229 | if (!isset($GLOBALS['egw_info']['server']['max_history'])) |
230 | 230 | { |
@@ -236,12 +236,12 @@ discard block |
||
236 | 236 | { |
237 | 237 | $config = new Config('phpgwapi'); |
238 | 238 | $config->read_repository(); |
239 | - $config->value('max_access_log_age',$GLOBALS['egw_info']['server']['max_access_log_age']); |
|
240 | - $config->value('block_time',$GLOBALS['egw_info']['server']['block_time']); |
|
241 | - $config->value('num_unsuccessful_id',$GLOBALS['egw_info']['server']['num_unsuccessful_id']); |
|
242 | - $config->value('num_unsuccessful_ip',$GLOBALS['egw_info']['server']['num_unsuccessful_ip']); |
|
243 | - $config->value('install_id',$GLOBALS['egw_info']['server']['install_id']); |
|
244 | - $config->value('max_history',$GLOBALS['egw_info']['server']['max_history']); |
|
239 | + $config->value('max_access_log_age', $GLOBALS['egw_info']['server']['max_access_log_age']); |
|
240 | + $config->value('block_time', $GLOBALS['egw_info']['server']['block_time']); |
|
241 | + $config->value('num_unsuccessful_id', $GLOBALS['egw_info']['server']['num_unsuccessful_id']); |
|
242 | + $config->value('num_unsuccessful_ip', $GLOBALS['egw_info']['server']['num_unsuccessful_ip']); |
|
243 | + $config->value('install_id', $GLOBALS['egw_info']['server']['install_id']); |
|
244 | + $config->value('max_history', $GLOBALS['egw_info']['server']['max_history']); |
|
245 | 245 | $config->save_repository(); |
246 | 246 | } |
247 | 247 | } |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | // set session_timeout from global php.ini and default to 14400=4h, if not set |
251 | 251 | if (!($GLOBALS['egw_info']['server']['sessions_timeout'] = ini_get('session.gc_maxlifetime'))) |
252 | 252 | { |
253 | - ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout']=14400); |
|
253 | + ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout'] = 14400); |
|
254 | 254 | } |
255 | 255 | } |
256 | 256 | |
@@ -325,15 +325,15 @@ discard block |
||
325 | 325 | |
326 | 326 | if (!isset($_SESSION[self::EGW_SESSION_ENCRYPTED]) && self::init_crypt($kp3)) |
327 | 327 | { |
328 | - foreach(self::$egw_session_vars as $name) |
|
328 | + foreach (self::$egw_session_vars as $name) |
|
329 | 329 | { |
330 | 330 | if (isset($_SESSION[$name])) |
331 | 331 | { |
332 | - $_SESSION[$name] = mcrypt_generic(self::$mcrypt,serialize($_SESSION[$name])); |
|
332 | + $_SESSION[$name] = mcrypt_generic(self::$mcrypt, serialize($_SESSION[$name])); |
|
333 | 333 | //error_log(__METHOD__."() 'encrypting' session var: $name, len=".strlen($_SESSION[$name])); |
334 | 334 | } |
335 | 335 | } |
336 | - $_SESSION[self::EGW_SESSION_ENCRYPTED] = true; // flag session as encrypted |
|
336 | + $_SESSION[self::EGW_SESSION_ENCRYPTED] = true; // flag session as encrypted |
|
337 | 337 | |
338 | 338 | mcrypt_generic_deinit(self::$mcrypt); |
339 | 339 | self::$mcrypt = null; |
@@ -348,24 +348,24 @@ discard block |
||
348 | 348 | * @param boolean $recursion =true if true call itself for every item > $limit |
349 | 349 | * @param int $limit =1000 log only differences > $limit |
350 | 350 | */ |
351 | - static function log_session_usage(&$arr,$label,$recursion=true,$limit=1000) |
|
351 | + static function log_session_usage(&$arr, $label, $recursion = true, $limit = 1000) |
|
352 | 352 | { |
353 | 353 | if (!is_array($arr)) return; |
354 | 354 | |
355 | 355 | $sizes = array(); |
356 | - foreach($arr as $key => &$data) |
|
356 | + foreach ($arr as $key => &$data) |
|
357 | 357 | { |
358 | 358 | $sizes[$key] = strlen(serialize($data)); |
359 | 359 | } |
360 | - arsort($sizes,SORT_NUMERIC); |
|
361 | - foreach($sizes as $key => $size) |
|
360 | + arsort($sizes, SORT_NUMERIC); |
|
361 | + foreach ($sizes as $key => $size) |
|
362 | 362 | { |
363 | 363 | $diff = $size - (int)$_SESSION[$label.'-sizes'][$key]; |
364 | 364 | $_SESSION[$label.'-sizes'][$key] = $size; |
365 | 365 | if ($diff > $limit) |
366 | 366 | { |
367 | 367 | error_log("strlen({$label}[$key])=".Vfs::hsize($size).", diff=".Vfs::hsize($diff)); |
368 | - if ($recursion) self::log_session_usage($arr[$key],$label.'['.$key.']',$recursion,$limit); |
|
368 | + if ($recursion) self::log_session_usage($arr[$key], $label.'['.$key.']', $recursion, $limit); |
|
369 | 369 | } |
370 | 370 | } |
371 | 371 | } |
@@ -380,15 +380,15 @@ discard block |
||
380 | 380 | { |
381 | 381 | if ($_SESSION[self::EGW_SESSION_ENCRYPTED] && self::init_crypt(self::get_request('kp3'))) |
382 | 382 | { |
383 | - foreach(self::$egw_session_vars as $name) |
|
383 | + foreach (self::$egw_session_vars as $name) |
|
384 | 384 | { |
385 | 385 | if (isset($_SESSION[$name])) |
386 | 386 | { |
387 | - $_SESSION[$name] = unserialize(trim(mdecrypt_generic(self::$mcrypt,$_SESSION[$name]))); |
|
387 | + $_SESSION[$name] = unserialize(trim(mdecrypt_generic(self::$mcrypt, $_SESSION[$name]))); |
|
388 | 388 | //error_log(__METHOD__."() 'decrypting' session var $name: gettype($name) = ".gettype($_SESSION[$name])); |
389 | 389 | } |
390 | 390 | } |
391 | - unset($_SESSION[self::EGW_SESSION_ENCRYPTED]); // delete encryption flag |
|
391 | + unset($_SESSION[self::EGW_SESSION_ENCRYPTED]); // delete encryption flag |
|
392 | 392 | } |
393 | 393 | } |
394 | 394 | |
@@ -403,13 +403,13 @@ discard block |
||
403 | 403 | */ |
404 | 404 | static private function init_crypt($kp3) |
405 | 405 | { |
406 | - if(!$GLOBALS['egw_info']['server']['mcrypt_enabled']) |
|
406 | + if (!$GLOBALS['egw_info']['server']['mcrypt_enabled']) |
|
407 | 407 | { |
408 | - return false; // session encryption is switched off |
|
408 | + return false; // session encryption is switched off |
|
409 | 409 | } |
410 | 410 | if ($GLOBALS['egw_info']['currentapp'] == 'syncml' || !$kp3) |
411 | 411 | { |
412 | - $kp3 = 'staticsyncmlkp3'; // syncml has no kp3! |
|
412 | + $kp3 = 'staticsyncmlkp3'; // syncml has no kp3! |
|
413 | 413 | } |
414 | 414 | if (is_null(self::$mcrypt)) |
415 | 415 | { |
@@ -425,9 +425,9 @@ discard block |
||
425 | 425 | } |
426 | 426 | $iv_size = mcrypt_enc_get_iv_size(self::$mcrypt); |
427 | 427 | $iv = !isset($GLOBALS['egw_info']['server']['mcrypt_iv']) || strlen($GLOBALS['egw_info']['server']['mcrypt_iv']) < $iv_size ? |
428 | - mcrypt_create_iv ($iv_size, MCRYPT_RAND) : substr($GLOBALS['egw_info']['server']['mcrypt_iv'],0,$iv_size); |
|
428 | + mcrypt_create_iv ($iv_size, MCRYPT_RAND) : substr($GLOBALS['egw_info']['server']['mcrypt_iv'], 0, $iv_size); |
|
429 | 429 | |
430 | - if (mcrypt_generic_init(self::$mcrypt,$kp3, $iv) < 0) |
|
430 | + if (mcrypt_generic_init(self::$mcrypt, $kp3, $iv) < 0) |
|
431 | 431 | { |
432 | 432 | error_log(__METHOD__."() could not initialise mcrypt, sessions get NOT encrypted!"); |
433 | 433 | return self::$mcrypt = false; |
@@ -447,7 +447,7 @@ discard block |
||
447 | 447 | * @param boolean $fail_on_forced_password_change =false true: do NOT create session, if password change requested |
448 | 448 | * @return string|boolean session id or false if session was not created, $this->(cd_)reason contains cause |
449 | 449 | */ |
450 | - function create($login,$passwd = '',$passwd_type = '',$no_session=false,$auth_check=true,$fail_on_forced_password_change=false) |
|
450 | + function create($login, $passwd = '', $passwd_type = '', $no_session = false, $auth_check = true, $fail_on_forced_password_change = false) |
|
451 | 451 | { |
452 | 452 | try { |
453 | 453 | if (is_array($login)) |
@@ -465,9 +465,9 @@ discard block |
||
465 | 465 | } |
466 | 466 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) starting ..."); |
467 | 467 | |
468 | - self::split_login_domain($login,$this->account_lid,$this->account_domain); |
|
468 | + self::split_login_domain($login, $this->account_lid, $this->account_domain); |
|
469 | 469 | // add domain to the login, if not already there |
470 | - if (substr($this->login,-strlen($this->account_domain)-1) != '@'.$this->account_domain) |
|
470 | + if (substr($this->login, -strlen($this->account_domain) - 1) != '@'.$this->account_domain) |
|
471 | 471 | { |
472 | 472 | $this->login .= '@'.$this->account_domain; |
473 | 473 | } |
@@ -484,7 +484,7 @@ discard block |
||
484 | 484 | { |
485 | 485 | $this->account_domain = $GLOBALS['egw_info']['user']['domain']; |
486 | 486 | } |
487 | - elseif($this->account_domain != $GLOBALS['egw_info']['user']['domain']) |
|
487 | + elseif ($this->account_domain != $GLOBALS['egw_info']['user']['domain']) |
|
488 | 488 | { |
489 | 489 | throw new Exception("Wrong domain! '$this->account_domain' != '{$GLOBALS['egw_info']['user']['domain']}'"); |
490 | 490 | } |
@@ -492,9 +492,9 @@ discard block |
||
492 | 492 | |
493 | 493 | $user_ip = self::getuser_ip(); |
494 | 494 | |
495 | - $this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid,'account_lid','u'); |
|
495 | + $this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid, 'account_lid', 'u'); |
|
496 | 496 | |
497 | - if (($blocked = $this->login_blocked($login,$user_ip)) || // too many unsuccessful attempts |
|
497 | + if (($blocked = $this->login_blocked($login, $user_ip)) || // too many unsuccessful attempts |
|
498 | 498 | $GLOBALS['egw_info']['server']['global_denied_users'][$this->account_lid] || |
499 | 499 | $auth_check && !$GLOBALS['egw']->auth->authenticate($this->account_lid, $this->passwd, $this->passwd_type) || |
500 | 500 | $this->account_id && $GLOBALS['egw']->accounts->get_type($this->account_id) == 'g') |
@@ -503,9 +503,9 @@ discard block |
||
503 | 503 | $this->cd_reason = $blocked ? self::CD_BLOCKED : self::CD_BAD_LOGIN_OR_PASSWORD; |
504 | 504 | |
505 | 505 | // we dont log anon users as it would block the website |
506 | - if (!$GLOBALS['egw']->acl->get_specific_rights_for_account($this->account_id,'anonymous','phpgwapi')) |
|
506 | + if (!$GLOBALS['egw']->acl->get_specific_rights_for_account($this->account_id, 'anonymous', 'phpgwapi')) |
|
507 | 507 | { |
508 | - $this->log_access($this->reason,$login,$user_ip,0); // log unsuccessfull login |
|
508 | + $this->log_access($this->reason, $login, $user_ip, 0); // log unsuccessfull login |
|
509 | 509 | } |
510 | 510 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
511 | 511 | return false; |
@@ -527,7 +527,7 @@ discard block |
||
527 | 527 | if ($this->account_lid != ($lid = $GLOBALS['egw']->accounts->id2name($this->account_id))) |
528 | 528 | { |
529 | 529 | $this->account_lid = $lid; |
530 | - $this->login = $lid.substr($this->login,strlen($lid)); |
|
530 | + $this->login = $lid.substr($this->login, strlen($lid)); |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | $GLOBALS['egw_info']['user']['account_id'] = $this->account_id; |
@@ -549,7 +549,7 @@ discard block |
||
549 | 549 | } |
550 | 550 | $this->sessionid = session_id(); |
551 | 551 | } |
552 | - $this->kp3 = Auth::randomstring(24); |
|
552 | + $this->kp3 = Auth::randomstring(24); |
|
553 | 553 | |
554 | 554 | $GLOBALS['egw_info']['user'] = $this->read_repositories(); |
555 | 555 | if ($GLOBALS['egw']->accounts->is_expired($GLOBALS['egw_info']['user'])) |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | |
564 | 564 | Cache::setSession('phpgwapi', 'password', base64_encode($this->passwd)); |
565 | 565 | |
566 | - if ($GLOBALS['egw']->acl->check('anonymous',1,'phpgwapi')) |
|
566 | + if ($GLOBALS['egw']->acl->check('anonymous', 1, 'phpgwapi')) |
|
567 | 567 | { |
568 | 568 | $this->session_flags = 'A'; |
569 | 569 | } |
@@ -581,46 +581,46 @@ discard block |
||
581 | 581 | 'passwd' => $this->passwd, |
582 | 582 | 'account_domain' => $this->account_domain, |
583 | 583 | 'user_ip' => $user_ip, |
584 | - ),'',true))) // true = run hooks from all apps, not just the ones the current user has perms to run |
|
584 | + ), '', true))) // true = run hooks from all apps, not just the ones the current user has perms to run |
|
585 | 585 | { |
586 | - foreach($hook_result as $reason) |
|
586 | + foreach ($hook_result as $reason) |
|
587 | 587 | { |
588 | 588 | if ($reason) // called hook requests to deny the session |
589 | 589 | { |
590 | 590 | $this->reason = $this->cd_reason = $reason; |
591 | - $this->log_access($this->reason,$login,$user_ip,0); // log unsuccessfull login |
|
591 | + $this->log_access($this->reason, $login, $user_ip, 0); // log unsuccessfull login |
|
592 | 592 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
593 | 593 | return false; |
594 | 594 | } |
595 | 595 | } |
596 | 596 | } |
597 | 597 | $GLOBALS['egw']->db->transaction_begin(); |
598 | - $this->register_session($this->login,$user_ip,$now,$this->session_flags); |
|
598 | + $this->register_session($this->login, $user_ip, $now, $this->session_flags); |
|
599 | 599 | if ($this->session_flags != 'A') // dont log anonymous sessions |
600 | 600 | { |
601 | - $this->sessionid_access_log = $this->log_access($this->sessionid,$login,$user_ip,$this->account_id); |
|
601 | + $this->sessionid_access_log = $this->log_access($this->sessionid, $login, $user_ip, $this->account_id); |
|
602 | 602 | } |
603 | 603 | Cache::setSession('phpgwapi', 'account_previous_login', $GLOBALS['egw']->auth->previous_login); |
604 | - $GLOBALS['egw']->accounts->update_lastlogin($this->account_id,$user_ip); |
|
604 | + $GLOBALS['egw']->accounts->update_lastlogin($this->account_id, $user_ip); |
|
605 | 605 | $GLOBALS['egw']->db->transaction_commit(); |
606 | 606 | |
607 | 607 | if ($GLOBALS['egw_info']['server']['usecookies'] && !$no_session) |
608 | 608 | { |
609 | - self::egw_setcookie(self::EGW_SESSION_NAME,$this->sessionid); |
|
610 | - self::egw_setcookie('kp3',$this->kp3); |
|
611 | - self::egw_setcookie('domain',$this->account_domain); |
|
609 | + self::egw_setcookie(self::EGW_SESSION_NAME, $this->sessionid); |
|
610 | + self::egw_setcookie('kp3', $this->kp3); |
|
611 | + self::egw_setcookie('domain', $this->account_domain); |
|
612 | 612 | } |
613 | 613 | if ($GLOBALS['egw_info']['server']['usecookies'] && !$no_session || isset($_COOKIE['last_loginid'])) |
614 | 614 | { |
615 | - self::egw_setcookie('last_loginid', $this->account_lid ,$now+1209600); /* For 2 weeks */ |
|
616 | - self::egw_setcookie('last_domain',$this->account_domain,$now+1209600); |
|
615 | + self::egw_setcookie('last_loginid', $this->account_lid, $now + 1209600); /* For 2 weeks */ |
|
616 | + self::egw_setcookie('last_domain', $this->account_domain, $now + 1209600); |
|
617 | 617 | } |
618 | 618 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) successfull sessionid=$this->sessionid"); |
619 | 619 | |
620 | 620 | return $this->sessionid; |
621 | 621 | } |
622 | 622 | // catch all exceptions, as their (allways logged) trace (eg. on a database error) would contain the user password |
623 | - catch(Exception $e) { |
|
623 | + catch (Exception $e) { |
|
624 | 624 | $this->reason = $this->cd_reason = $e->getMessage(); |
625 | 625 | error_log(__METHOD__."('$login', ".array2string(str_repeat('*', strlen($passwd))). |
626 | 626 | ", '$passwd_type', no_session=".array2string($no_session). |
@@ -639,13 +639,12 @@ discard block |
||
639 | 639 | * @param int $now |
640 | 640 | * @param string $session_flags |
641 | 641 | */ |
642 | - private function register_session($login,$user_ip,$now,$session_flags) |
|
642 | + private function register_session($login, $user_ip, $now, $session_flags) |
|
643 | 643 | { |
644 | 644 | // restore session vars set before session was started |
645 | 645 | if (is_array($this->required_files)) |
646 | 646 | { |
647 | - $_SESSION[self::EGW_REQUIRED_FILES] = !is_array($_SESSION[self::EGW_REQUIRED_FILES]) ? $this->required_files : |
|
648 | - array_unique(array_merge($_SESSION[self::EGW_REQUIRED_FILES],$this->required_files)); |
|
647 | + $_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)); |
|
649 | 648 | unset($this->required_files); |
650 | 649 | } |
651 | 650 | $_SESSION[self::EGW_SESSION_VAR] = array( |
@@ -681,13 +680,13 @@ discard block |
||
681 | 680 | * @param int $account_id =0 numerical account_id |
682 | 681 | * @return int $sessionid primary key of egw_access_log for login, null otherwise |
683 | 682 | */ |
684 | - private function log_access($sessionid,$login='',$user_ip='',$account_id=0) |
|
683 | + private function log_access($sessionid, $login = '', $user_ip = '', $account_id = 0) |
|
685 | 684 | { |
686 | 685 | $now = time(); |
687 | 686 | |
688 | 687 | if ($login) |
689 | 688 | { |
690 | - $GLOBALS['egw']->db->insert(self::ACCESS_LOG_TABLE,array( |
|
689 | + $GLOBALS['egw']->db->insert(self::ACCESS_LOG_TABLE, array( |
|
691 | 690 | 'session_php' => $sessionid, |
692 | 691 | 'loginid' => $login, |
693 | 692 | 'ip' => $user_ip, |
@@ -695,20 +694,20 @@ discard block |
||
695 | 694 | 'account_id'=> $account_id, |
696 | 695 | 'user_agent'=> $_SERVER['HTTP_USER_AGENT'], |
697 | 696 | 'session_dla' => $now, |
698 | - 'session_action' => $this->update_dla(false), // dont update egw_access_log |
|
699 | - ),false,__LINE__,__FILE__); |
|
697 | + 'session_action' => $this->update_dla(false), // dont update egw_access_log |
|
698 | + ), false, __LINE__, __FILE__); |
|
700 | 699 | |
701 | - $ret = $GLOBALS['egw']->db->get_last_insert_id(self::ACCESS_LOG_TABLE,'sessionid'); |
|
700 | + $ret = $GLOBALS['egw']->db->get_last_insert_id(self::ACCESS_LOG_TABLE, 'sessionid'); |
|
702 | 701 | |
703 | 702 | // if we can not store failed login attempts in database, store it in cache |
704 | 703 | if (!$ret && !$account_id) |
705 | 704 | { |
706 | 705 | Cache::setInstance(__CLASS__, self::FALSE_IP_CACHE_PREFIX.$user_ip, |
707 | - 1+Cache::getInstance(__CLASS__, self::FALSE_IP_CACHE_PREFIX.$user_ip), |
|
706 | + 1 + Cache::getInstance(__CLASS__, self::FALSE_IP_CACHE_PREFIX.$user_ip), |
|
708 | 707 | $GLOBALS['egw_info']['server']['block_time'] * 60); |
709 | 708 | |
710 | 709 | Cache::setInstance(__CLASS__, self::FALSE_ID_CACHE_PREFIX.$login, |
711 | - 1+Cache::getInstance(__CLASS__, self::FALSE_ID_CACHE_PREFIX.$login), |
|
710 | + 1 + Cache::getInstance(__CLASS__, self::FALSE_ID_CACHE_PREFIX.$login), |
|
712 | 711 | $GLOBALS['egw_info']['server']['block_time'] * 60); |
713 | 712 | } |
714 | 713 | } |
@@ -718,20 +717,20 @@ discard block |
||
718 | 717 | { |
719 | 718 | $sessionid = $this->sessionid_access_log; |
720 | 719 | } |
721 | - $GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE,array( |
|
720 | + $GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE, array( |
|
722 | 721 | 'lo' => $now |
723 | - ),is_numeric($sessionid) ? array( |
|
722 | + ), is_numeric($sessionid) ? array( |
|
724 | 723 | 'sessionid' => $sessionid, |
725 | 724 | ) : array( |
726 | 725 | 'session_php' => $sessionid, |
727 | - ),__LINE__,__FILE__); |
|
726 | + ), __LINE__, __FILE__); |
|
728 | 727 | |
729 | 728 | // run maintenance only on logout, to not delay login |
730 | 729 | if ($GLOBALS['egw_info']['server']['max_access_log_age']) |
731 | 730 | { |
732 | 731 | $max_age = $now - $GLOBALS['egw_info']['server']['max_access_log_age'] * 24 * 60 * 60; |
733 | 732 | |
734 | - $GLOBALS['egw']->db->delete(self::ACCESS_LOG_TABLE,"li < $max_age",__LINE__,__FILE__); |
|
733 | + $GLOBALS['egw']->db->delete(self::ACCESS_LOG_TABLE, "li < $max_age", __LINE__, __FILE__); |
|
735 | 734 | } |
736 | 735 | } |
737 | 736 | //error_log(__METHOD__."('$sessionid', '$login', '$user_ip', $account_id) returning ".array2string($ret)); |
@@ -745,12 +744,12 @@ discard block |
||
745 | 744 | * @param string $ip ip of the user |
746 | 745 | * @returns bool login blocked? |
747 | 746 | */ |
748 | - private function login_blocked($login,$ip) |
|
747 | + private function login_blocked($login, $ip) |
|
749 | 748 | { |
750 | 749 | $block_time = time() - $GLOBALS['egw_info']['server']['block_time'] * 60; |
751 | 750 | |
752 | 751 | $false_id = $false_ip = 0; |
753 | - foreach($GLOBALS['egw']->db->union(array( |
|
752 | + foreach ($GLOBALS['egw']->db->union(array( |
|
754 | 753 | array( |
755 | 754 | 'table' => self::ACCESS_LOG_TABLE, |
756 | 755 | 'cols' => "'false_ip' AS name,COUNT(*) AS num", |
@@ -792,28 +791,28 @@ discard block |
||
792 | 791 | //error_log(__METHOD__."('$login', '$ip') false_ip=$false_ip, false_id=$false_id --> blocked=".array2string($blocked)); |
793 | 792 | |
794 | 793 | if ($blocked && $GLOBALS['egw_info']['server']['admin_mails'] && |
795 | - $GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time()-5*60) // max. one mail every 5mins |
|
794 | + $GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time() - 5 * 60) // max. one mail every 5mins |
|
796 | 795 | { |
797 | 796 | try { |
798 | 797 | $mailer = new Mailer(); |
799 | 798 | // notify admin(s) via email |
800 | 799 | $mailer->setFrom('eGroupWare@'.$GLOBALS['egw_info']['server']['mail_suffix']); |
801 | - $mailer->addHeader('Subject', lang("eGroupWare: login blocked for user '%1', IP %2",$login,$ip)); |
|
802 | - $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)); |
|
803 | - foreach(preg_split('/,\s*/',$GLOBALS['egw_info']['server']['admin_mails']) as $mail) |
|
800 | + $mailer->addHeader('Subject', lang("eGroupWare: login blocked for user '%1', IP %2", $login, $ip)); |
|
801 | + $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)); |
|
802 | + foreach (preg_split('/,\s*/', $GLOBALS['egw_info']['server']['admin_mails']) as $mail) |
|
804 | 803 | { |
805 | 804 | $mailer->addAddress($mail); |
806 | 805 | } |
807 | 806 | $mailer->send(); |
808 | 807 | } |
809 | - catch(\Exception $e) { |
|
808 | + catch (\Exception $e) { |
|
810 | 809 | // ignore exception, but log it, to block the account and give a correct error-message to user |
811 | 810 | error_log(__METHOD__."('$login', '$ip') ".$e->getMessage()); |
812 | 811 | } |
813 | 812 | // save time of mail, to not send to many mails |
814 | 813 | $config = new Config('phpgwapi'); |
815 | 814 | $config->read_repository(); |
816 | - $config->value('login_blocked_mail_time',time()); |
|
815 | + $config->value('login_blocked_mail_time', time()); |
|
817 | 816 | $config->save_repository(); |
818 | 817 | } |
819 | 818 | return $blocked; |
@@ -834,7 +833,7 @@ discard block |
||
834 | 833 | * @param boolean $only_basic_auth =false return only a basic auth pseudo sessionid, default no |
835 | 834 | * @return string |
836 | 835 | */ |
837 | - static function get_sessionid($only_basic_auth=false) |
|
836 | + static function get_sessionid($only_basic_auth = false) |
|
838 | 837 | { |
839 | 838 | // for WebDAV and GroupDAV we use a pseudo sessionid created from md5(user:passwd) |
840 | 839 | // --> allows this stateless protocolls which use basic auth to use sessions! |
@@ -861,11 +860,11 @@ discard block |
||
861 | 860 | EGW_SERVER_ROOT.':'.self::getuser_ip().':'.filemtime(EGW_SERVER_ROOT.'/api/setup/setup.inc.php'). |
862 | 861 | ':'.$_SERVER['HTTP_USER_AGENT']); |
863 | 862 | } |
864 | - elseif(!$only_basic_auth && isset($_REQUEST[self::EGW_SESSION_NAME])) |
|
863 | + elseif (!$only_basic_auth && isset($_REQUEST[self::EGW_SESSION_NAME])) |
|
865 | 864 | { |
866 | 865 | $sessionid = $_REQUEST[self::EGW_SESSION_NAME]; |
867 | 866 | } |
868 | - elseif(!$only_basic_auth && isset($_COOKIE[self::EGW_SESSION_NAME])) |
|
867 | + elseif (!$only_basic_auth && isset($_COOKIE[self::EGW_SESSION_NAME])) |
|
869 | 868 | { |
870 | 869 | $sessionid = $_COOKIE[self::EGW_SESSION_NAME]; |
871 | 870 | } |
@@ -873,7 +872,7 @@ discard block |
||
873 | 872 | { |
874 | 873 | $sessionid = false; |
875 | 874 | } |
876 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid,true)); |
|
875 | + if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid, true)); |
|
877 | 876 | return $sessionid; |
878 | 877 | } |
879 | 878 | |
@@ -889,9 +888,7 @@ discard block |
||
889 | 888 | */ |
890 | 889 | static function get_request($name) |
891 | 890 | { |
892 | - return isset($_REQUEST[$name]) ? $_REQUEST[$name] : |
|
893 | - (isset($_COOKIE[$name]) ? $_COOKIE[$name] : |
|
894 | - (isset($_COOKIE[$name=ucfirst($name)]) ? $_COOKIE[$name] : null)); |
|
891 | + return isset($_REQUEST[$name]) ? $_REQUEST[$name] : (isset($_COOKIE[$name]) ? $_COOKIE[$name] : (isset($_COOKIE[$name = ucfirst($name)]) ? $_COOKIE[$name] : null)); |
|
895 | 892 | } |
896 | 893 | |
897 | 894 | /** |
@@ -901,13 +898,13 @@ discard block |
||
901 | 898 | * @param string $kp3 ?? to be verified |
902 | 899 | * @return bool is the session valid? |
903 | 900 | */ |
904 | - function verify($sessionid=null,$kp3=null) |
|
901 | + function verify($sessionid = null, $kp3 = null) |
|
905 | 902 | { |
906 | 903 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid','$kp3') ".function_backtrace()); |
907 | 904 | |
908 | 905 | $fill_egw_info_and_repositories = !$GLOBALS['egw_info']['flags']['restored_from_session']; |
909 | 906 | |
910 | - if(!$sessionid) |
|
907 | + if (!$sessionid) |
|
911 | 908 | { |
912 | 909 | $sessionid = self::get_sessionid(); |
913 | 910 | $kp3 = self::get_request('kp3'); |
@@ -943,23 +940,23 @@ discard block |
||
943 | 940 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session does NOT exist!"); |
944 | 941 | return false; |
945 | 942 | } |
946 | - $session =& $_SESSION[self::EGW_SESSION_VAR]; |
|
943 | + $session = & $_SESSION[self::EGW_SESSION_VAR]; |
|
947 | 944 | |
948 | 945 | if ($session['session_dla'] <= time() - $GLOBALS['egw_info']['server']['sessions_timeout']) |
949 | 946 | { |
950 | 947 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session timed out!"); |
951 | - $this->destroy($sessionid,$kp3); |
|
948 | + $this->destroy($sessionid, $kp3); |
|
952 | 949 | return false; |
953 | 950 | } |
954 | 951 | |
955 | 952 | $this->session_flags = $session['session_flags']; |
956 | 953 | |
957 | - $this->split_login_domain($session['session_lid'],$this->account_lid,$this->account_domain); |
|
954 | + $this->split_login_domain($session['session_lid'], $this->account_lid, $this->account_domain); |
|
958 | 955 | |
959 | 956 | // This is to ensure that we authenticate to the correct domain (might not be default) |
960 | - if($GLOBALS['egw_info']['user']['domain'] && $this->account_domain != $GLOBALS['egw_info']['user']['domain']) |
|
957 | + if ($GLOBALS['egw_info']['user']['domain'] && $this->account_domain != $GLOBALS['egw_info']['user']['domain']) |
|
961 | 958 | { |
962 | - return false; // session not verified, domain changed |
|
959 | + return false; // session not verified, domain changed |
|
963 | 960 | } |
964 | 961 | $GLOBALS['egw_info']['user']['kp3'] = $this->kp3; |
965 | 962 | |
@@ -972,7 +969,7 @@ discard block |
||
972 | 969 | { |
973 | 970 | $this->update_notification_heartbeat(); |
974 | 971 | } |
975 | - $this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid,'account_lid','u'); |
|
972 | + $this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid, 'account_lid', 'u'); |
|
976 | 973 | if (!$this->account_id) |
977 | 974 | { |
978 | 975 | if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) !accounts::name2id('$this->account_lid')"); |
@@ -1019,7 +1016,7 @@ discard block |
||
1019 | 1016 | |
1020 | 1017 | if ($GLOBALS['egw_info']['server']['sessions_checkip']) |
1021 | 1018 | { |
1022 | - if (strtoupper(substr(PHP_OS,0,3)) != 'WIN' && (!$GLOBALS['egw_info']['user']['session_ip'] || |
|
1019 | + if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN' && (!$GLOBALS['egw_info']['user']['session_ip'] || |
|
1023 | 1020 | $GLOBALS['egw_info']['user']['session_ip'] != $this->getuser_ip())) |
1024 | 1021 | { |
1025 | 1022 | if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) wrong IP"); |
@@ -1042,9 +1039,9 @@ discard block |
||
1042 | 1039 | // query accesslog-id, if not set in session (session is made persistent after login!) |
1043 | 1040 | if (!$this->sessionid_access_log && $this->session_flags != 'A') |
1044 | 1041 | { |
1045 | - $this->sessionid_access_log = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE,'sessionid',array( |
|
1042 | + $this->sessionid_access_log = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, 'sessionid', array( |
|
1046 | 1043 | 'session_php' => $this->sessionid, |
1047 | - ),__LINE__,__FILE__)->fetchColumn(); |
|
1044 | + ), __LINE__, __FILE__)->fetchColumn(); |
|
1048 | 1045 | //error_log(__METHOD__."() sessionid=$this->sessionid --> sessionid_access_log=$this->sessionid_access_log"); |
1049 | 1046 | } |
1050 | 1047 | |
@@ -1055,9 +1052,9 @@ discard block |
||
1055 | 1052 | (!isset($_COOKIE[self::EGW_SESSION_NAME]) || $_COOKIE[self::EGW_SESSION_NAME] !== $_REQUEST[self::EGW_SESSION_NAME])) |
1056 | 1053 | { |
1057 | 1054 | if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS, but NO required cookies set --> setting them now"); |
1058 | - self::egw_setcookie(self::EGW_SESSION_NAME,$this->sessionid); |
|
1059 | - self::egw_setcookie('kp3',$this->kp3); |
|
1060 | - self::egw_setcookie('domain',$this->account_domain); |
|
1055 | + self::egw_setcookie(self::EGW_SESSION_NAME, $this->sessionid); |
|
1056 | + self::egw_setcookie('kp3', $this->kp3); |
|
1057 | + self::egw_setcookie('domain', $this->account_domain); |
|
1061 | 1058 | } |
1062 | 1059 | |
1063 | 1060 | if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS"); |
@@ -1072,27 +1069,27 @@ discard block |
||
1072 | 1069 | * @param string $kp3 |
1073 | 1070 | * @return boolean true on success, false on error |
1074 | 1071 | */ |
1075 | - function destroy($sessionid, $kp3='') |
|
1072 | + function destroy($sessionid, $kp3 = '') |
|
1076 | 1073 | { |
1077 | 1074 | if (!$sessionid && $kp3) |
1078 | 1075 | { |
1079 | 1076 | return false; |
1080 | 1077 | } |
1081 | - $this->log_access($sessionid); // log logout-time |
|
1078 | + $this->log_access($sessionid); // log logout-time |
|
1082 | 1079 | |
1083 | 1080 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($sessionid,$kp3)"); |
1084 | 1081 | |
1085 | 1082 | if (is_numeric($sessionid)) // do we have a access-log-id --> get PHP session id |
1086 | 1083 | { |
1087 | - $sessionid = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE,'session_php',array( |
|
1084 | + $sessionid = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, 'session_php', array( |
|
1088 | 1085 | 'sessionid' => $sessionid, |
1089 | - ),__LINE__,__FILE__)->fetchColumn(); |
|
1086 | + ), __LINE__, __FILE__)->fetchColumn(); |
|
1090 | 1087 | } |
1091 | 1088 | |
1092 | 1089 | Hooks::process(array( |
1093 | 1090 | 'location' => 'session_destroyed', |
1094 | 1091 | 'sessionid' => $sessionid, |
1095 | - ),'',true); // true = run hooks from all apps, not just the ones the current user has perms to run |
|
1092 | + ), '', true); // true = run hooks from all apps, not just the ones the current user has perms to run |
|
1096 | 1093 | |
1097 | 1094 | // Only do the following, if where working with the current user |
1098 | 1095 | if (!$GLOBALS['egw_info']['user']['sessionid'] || $sessionid == $GLOBALS['egw_info']['user']['sessionid']) |
@@ -1113,7 +1110,7 @@ discard block |
||
1113 | 1110 | } |
1114 | 1111 | else |
1115 | 1112 | { |
1116 | - $this->commit_session(); // close our own session |
|
1113 | + $this->commit_session(); // close our own session |
|
1117 | 1114 | |
1118 | 1115 | session_id($sessionid); |
1119 | 1116 | if (session_start()) |
@@ -1153,25 +1150,25 @@ discard block |
||
1153 | 1150 | // as $webserver_url may be part of $url (as /egw is part of phpgwapi/js/egw_instant_load.html) |
1154 | 1151 | if (($url[0] != '/' || $webserver_url != '/') && (!$webserver_url || strpos($url, $webserver_url.'/') === false)) |
1155 | 1152 | { |
1156 | - if($url[0] != '/' && substr($webserver_url,-1) != '/') |
|
1153 | + if ($url[0] != '/' && substr($webserver_url, -1) != '/') |
|
1157 | 1154 | { |
1158 | - $url = $webserver_url .'/'. $url; |
|
1155 | + $url = $webserver_url.'/'.$url; |
|
1159 | 1156 | } |
1160 | 1157 | else |
1161 | 1158 | { |
1162 | - $url = $webserver_url . $url; |
|
1159 | + $url = $webserver_url.$url; |
|
1163 | 1160 | } |
1164 | 1161 | } |
1165 | 1162 | |
1166 | - if(isset($GLOBALS['egw_info']['server']['enforce_ssl']) && $GLOBALS['egw_info']['server']['enforce_ssl']) |
|
1163 | + if (isset($GLOBALS['egw_info']['server']['enforce_ssl']) && $GLOBALS['egw_info']['server']['enforce_ssl']) |
|
1167 | 1164 | { |
1168 | - if(substr($url ,0,4) != 'http') |
|
1165 | + if (substr($url, 0, 4) != 'http') |
|
1169 | 1166 | { |
1170 | 1167 | $url = 'https://'.$_SERVER['HTTP_HOST'].$url; |
1171 | 1168 | } |
1172 | 1169 | else |
1173 | 1170 | { |
1174 | - $url = str_replace ( 'http:', 'https:', $url); |
|
1171 | + $url = str_replace('http:', 'https:', $url); |
|
1175 | 1172 | } |
1176 | 1173 | } |
1177 | 1174 | $vars = array(); |
@@ -1184,7 +1181,7 @@ discard block |
||
1184 | 1181 | } |
1185 | 1182 | |
1186 | 1183 | // check if the url already contains a query and ensure that vars is an array and all strings are in extravars |
1187 | - list($ret_url,$othervars) = explode('?', $url, 2); |
|
1184 | + list($ret_url, $othervars) = explode('?', $url, 2); |
|
1188 | 1185 | if ($extravars && is_array($extravars)) |
1189 | 1186 | { |
1190 | 1187 | $vars += $extravars; |
@@ -1192,19 +1189,19 @@ discard block |
||
1192 | 1189 | } |
1193 | 1190 | else |
1194 | 1191 | { |
1195 | - if ($othervars) $extravars .= ($extravars?'&':'').$othervars; |
|
1192 | + if ($othervars) $extravars .= ($extravars ? '&' : '').$othervars; |
|
1196 | 1193 | } |
1197 | 1194 | |
1198 | 1195 | // parse extravars string into the vars array |
1199 | 1196 | if ($extravars) |
1200 | 1197 | { |
1201 | - foreach(explode('&',$extravars) as $expr) |
|
1198 | + foreach (explode('&', $extravars) as $expr) |
|
1202 | 1199 | { |
1203 | - list($var,$val) = explode('=', $expr,2); |
|
1204 | - if (strpos($val,'%26') != false) $val = str_replace('%26','&',$val); // make sure to not double encode & |
|
1205 | - if (substr($var,-2) == '[]') |
|
1200 | + list($var, $val) = explode('=', $expr, 2); |
|
1201 | + if (strpos($val, '%26') != false) $val = str_replace('%26', '&', $val); // make sure to not double encode & |
|
1202 | + if (substr($var, -2) == '[]') |
|
1206 | 1203 | { |
1207 | - $vars[substr($var,0,-2)][] = $val; |
|
1204 | + $vars[substr($var, 0, -2)][] = $val; |
|
1208 | 1205 | } |
1209 | 1206 | else |
1210 | 1207 | { |
@@ -1217,11 +1214,11 @@ discard block |
||
1217 | 1214 | if (count($vars)) |
1218 | 1215 | { |
1219 | 1216 | $query = array(); |
1220 | - foreach($vars as $key => $value) |
|
1217 | + foreach ($vars as $key => $value) |
|
1221 | 1218 | { |
1222 | 1219 | if (is_array($value)) |
1223 | 1220 | { |
1224 | - foreach($value as $val) |
|
1221 | + foreach ($value as $val) |
|
1225 | 1222 | { |
1226 | 1223 | $query[] = $key.'[]='.urlencode($val); |
1227 | 1224 | } |
@@ -1231,7 +1228,7 @@ discard block |
||
1231 | 1228 | $query[] = $key.'='.urlencode($value); |
1232 | 1229 | } |
1233 | 1230 | } |
1234 | - $ret_url .= '?' . implode('&',$query); |
|
1231 | + $ret_url .= '?'.implode('&', $query); |
|
1235 | 1232 | } |
1236 | 1233 | return $ret_url; |
1237 | 1234 | } |
@@ -1276,7 +1273,7 @@ discard block |
||
1276 | 1273 | * @param int $cookietime =0 when cookie should expire, 0 for session only (optional) |
1277 | 1274 | * @param string $cookiepath =null optional path (eg. '/') if the eGW install-dir should not be used |
1278 | 1275 | */ |
1279 | - public static function egw_setcookie($cookiename,$cookievalue='',$cookietime=0,$cookiepath=null) |
|
1276 | + public static function egw_setcookie($cookiename, $cookievalue = '', $cookietime = 0, $cookiepath = null) |
|
1280 | 1277 | { |
1281 | 1278 | if (empty(self::$cookie_domain) || empty(self::$cookie_path)) |
1282 | 1279 | { |
@@ -1289,11 +1286,11 @@ discard block |
||
1289 | 1286 | static $is_iOS = null; |
1290 | 1287 | if (!$cookietime && !isset($is_iOS)) $is_iOS = (bool)preg_match('/^(iPhone|iPad|iPod)/i', Header\UserAgent::mobile()); |
1291 | 1288 | |
1292 | - if(!headers_sent()) // gives only a warning, but can not send the cookie anyway |
|
1289 | + if (!headers_sent()) // gives only a warning, but can not send the cookie anyway |
|
1293 | 1290 | { |
1294 | 1291 | setcookie($cookiename, $cookievalue, |
1295 | - !$cookietime && $is_iOS ? time()+self::IOS_SESSION_COOKIE_LIFETIME : $cookietime, |
|
1296 | - is_null($cookiepath) ? self::$cookie_path : $cookiepath,self::$cookie_domain, |
|
1292 | + !$cookietime && $is_iOS ? time() + self::IOS_SESSION_COOKIE_LIFETIME : $cookietime, |
|
1293 | + is_null($cookiepath) ? self::$cookie_path : $cookiepath, self::$cookie_domain, |
|
1297 | 1294 | // if called via HTTPS, only send cookie for https and only allow cookie access via HTTP (true) |
1298 | 1295 | empty($GLOBALS['egw_info']['server']['insecure_cookies']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off', true); |
1299 | 1296 | } |
@@ -1312,21 +1309,21 @@ discard block |
||
1312 | 1309 | else |
1313 | 1310 | { |
1314 | 1311 | // Use HTTP_X_FORWARDED_HOST if set, which is the case behind a none-transparent proxy |
1315 | - self::$cookie_domain = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST']; |
|
1312 | + self::$cookie_domain = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST']; |
|
1316 | 1313 | } |
1317 | 1314 | // remove port from HTTP_HOST |
1318 | 1315 | $arr = null; |
1319 | - if (preg_match("/^(.*):(.*)$/",self::$cookie_domain,$arr)) |
|
1316 | + if (preg_match("/^(.*):(.*)$/", self::$cookie_domain, $arr)) |
|
1320 | 1317 | { |
1321 | 1318 | self::$cookie_domain = $arr[1]; |
1322 | 1319 | } |
1323 | - if (count(explode('.',self::$cookie_domain)) <= 1) |
|
1320 | + if (count(explode('.', self::$cookie_domain)) <= 1) |
|
1324 | 1321 | { |
1325 | 1322 | // setcookie dont likes domains without dots, leaving it empty, gets setcookie to fill the domain in |
1326 | 1323 | self::$cookie_domain = ''; |
1327 | 1324 | } |
1328 | 1325 | if (!$GLOBALS['egw_info']['server']['cookiepath'] || |
1329 | - !(self::$cookie_path = parse_url($GLOBALS['egw_info']['server']['webserver_url'],PHP_URL_PATH))) |
|
1326 | + !(self::$cookie_path = parse_url($GLOBALS['egw_info']['server']['webserver_url'], PHP_URL_PATH))) |
|
1330 | 1327 | { |
1331 | 1328 | self::$cookie_path = '/'; |
1332 | 1329 | } |
@@ -1346,7 +1343,7 @@ discard block |
||
1346 | 1343 | * @param array $domains =null defaults to $GLOBALS['egw_domain'] from the header |
1347 | 1344 | * @return string $GLOBALS['egw_info']['user']['domain'] set with the domain/instance to use |
1348 | 1345 | */ |
1349 | - public static function search_instance($login,$domain_requested,&$default_domain,$server_names,array $domains=null) |
|
1346 | + public static function search_instance($login, $domain_requested, &$default_domain, $server_names, array $domains = null) |
|
1350 | 1347 | { |
1351 | 1348 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".".array2string($server_names).".".array2string($domains).")"); |
1352 | 1349 | |
@@ -1354,10 +1351,10 @@ discard block |
||
1354 | 1351 | |
1355 | 1352 | if (!isset($default_domain) || !isset($domains[$default_domain])) // allow to overwrite the default domain |
1356 | 1353 | { |
1357 | - foreach((array)$server_names as $server_name) |
|
1354 | + foreach ((array)$server_names as $server_name) |
|
1358 | 1355 | { |
1359 | - list($server_name) = explode(':', $server_name); // remove port from HTTP_HOST |
|
1360 | - if(isset($domains[$server_name])) |
|
1356 | + list($server_name) = explode(':', $server_name); // remove port from HTTP_HOST |
|
1357 | + if (isset($domains[$server_name])) |
|
1361 | 1358 | { |
1362 | 1359 | $default_domain = $server_name; |
1363 | 1360 | break; |
@@ -1367,7 +1364,7 @@ discard block |
||
1367 | 1364 | $parts = explode('.', $server_name); |
1368 | 1365 | array_shift($parts); |
1369 | 1366 | $domain_part = implode('.', $parts); |
1370 | - if(isset($domains[$domain_part])) |
|
1367 | + if (isset($domains[$domain_part])) |
|
1371 | 1368 | { |
1372 | 1369 | $default_domain = $domain_part; |
1373 | 1370 | break; |
@@ -1383,11 +1380,11 @@ discard block |
||
1383 | 1380 | } |
1384 | 1381 | if (isset($login)) // on login |
1385 | 1382 | { |
1386 | - if (strpos($login,'@') === false || count($domains) == 1) |
|
1383 | + if (strpos($login, '@') === false || count($domains) == 1) |
|
1387 | 1384 | { |
1388 | - $login .= '@' . (isset($_POST['logindomain']) ? $_POST['logindomain'] : $default_domain); |
|
1385 | + $login .= '@'.(isset($_POST['logindomain']) ? $_POST['logindomain'] : $default_domain); |
|
1389 | 1386 | } |
1390 | - $parts = explode('@',$login); |
|
1387 | + $parts = explode('@', $login); |
|
1391 | 1388 | $domain = array_pop($parts); |
1392 | 1389 | $GLOBALS['login'] = $login; |
1393 | 1390 | } |
@@ -1420,7 +1417,7 @@ discard block |
||
1420 | 1417 | * @param boolean $update_access_log =false false: dont update egw_access_log table, but set $this->action |
1421 | 1418 | * @return string action as written to egw_access_log.session_action |
1422 | 1419 | */ |
1423 | - private function update_dla($update_access_log=false) |
|
1420 | + private function update_dla($update_access_log = false) |
|
1424 | 1421 | { |
1425 | 1422 | // This way XML-RPC users aren't always listed as xmlrpc.php |
1426 | 1423 | if (!$update_access_log) |
@@ -1438,14 +1435,14 @@ discard block |
||
1438 | 1435 | $action = $_SERVER['PHP_SELF']; |
1439 | 1436 | // remove EGroupware path, if not installed in webroot |
1440 | 1437 | $egw_path = $GLOBALS['egw_info']['server']['webserver_url']; |
1441 | - if ($egw_path[0] != '/') $egw_path = parse_url($egw_path,PHP_URL_PATH); |
|
1438 | + if ($egw_path[0] != '/') $egw_path = parse_url($egw_path, PHP_URL_PATH); |
|
1442 | 1439 | if ($action == '/Microsoft-Server-ActiveSync') |
1443 | 1440 | { |
1444 | 1441 | $action .= '?Cmd='.$_GET['Cmd'].'&DeviceId='.$_GET['DeviceId']; |
1445 | 1442 | } |
1446 | 1443 | elseif ($egw_path) |
1447 | 1444 | { |
1448 | - list(,$action) = explode($egw_path,$action,2); |
|
1445 | + list(,$action) = explode($egw_path, $action, 2); |
|
1449 | 1446 | } |
1450 | 1447 | } |
1451 | 1448 | $this->set_action($action); |
@@ -1453,14 +1450,14 @@ discard block |
||
1453 | 1450 | // update dla in access-log table, if we have an access-log row (non-anonymous session) |
1454 | 1451 | if ($this->sessionid_access_log && $update_access_log && is_object($GLOBALS['egw']->db)) |
1455 | 1452 | { |
1456 | - $GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE,array( |
|
1453 | + $GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE, array( |
|
1457 | 1454 | 'session_dla' => time(), |
1458 | 1455 | 'session_action' => $this->action, |
1459 | 1456 | ) + ($this->action === '/logout.php' ? array() : array( |
1460 | - 'lo' => null, // just in case it was (automatic) timed out before |
|
1461 | - )),array( |
|
1457 | + 'lo' => null, // just in case it was (automatic) timed out before |
|
1458 | + )), array( |
|
1462 | 1459 | 'sessionid' => $this->sessionid_access_log, |
1463 | - ),__LINE__,__FILE__); |
|
1460 | + ), __LINE__, __FILE__); |
|
1464 | 1461 | } |
1465 | 1462 | |
1466 | 1463 | $_SESSION[self::EGW_SESSION_VAR]['session_dla'] = time(); |
@@ -1478,12 +1475,12 @@ discard block |
||
1478 | 1475 | // update dla in access-log table, if we have an access-log row (non-anonymous session) |
1479 | 1476 | if ($this->sessionid_access_log) |
1480 | 1477 | { |
1481 | - $GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE,array( |
|
1478 | + $GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE, array( |
|
1482 | 1479 | 'notification_heartbeat' => time(), |
1483 | - ),array( |
|
1480 | + ), array( |
|
1484 | 1481 | 'sessionid' => $this->sessionid_access_log, |
1485 | 1482 | 'lo IS NULL', |
1486 | - ),__LINE__,__FILE__); |
|
1483 | + ), __LINE__, __FILE__); |
|
1487 | 1484 | } |
1488 | 1485 | } |
1489 | 1486 | |
@@ -1504,7 +1501,7 @@ discard block |
||
1504 | 1501 | { |
1505 | 1502 | // authentication happens in login.php, which does NOT yet create egw-object in session |
1506 | 1503 | // --> need to store homedirectory in session |
1507 | - if(isset($GLOBALS['auto_create_acct']['homedirectory'])) |
|
1504 | + if (isset($GLOBALS['auto_create_acct']['homedirectory'])) |
|
1508 | 1505 | { |
1509 | 1506 | Cache::setSession(__CLASS__, 'homedirectory', |
1510 | 1507 | $user['homedirectory'] = $GLOBALS['auto_create_acct']['homedirectory']); |
@@ -1517,7 +1514,7 @@ discard block |
||
1517 | 1514 | $user['preferences'] = $GLOBALS['egw']->preferences->read_repository(); |
1518 | 1515 | if (is_object($GLOBALS['egw']->datetime)) |
1519 | 1516 | { |
1520 | - $GLOBALS['egw']->datetime->__construct(); // to set tz_offset from the now read prefs |
|
1517 | + $GLOBALS['egw']->datetime->__construct(); // to set tz_offset from the now read prefs |
|
1521 | 1518 | } |
1522 | 1519 | $user['apps'] = $GLOBALS['egw']->applications->read_repository(); |
1523 | 1520 | $user['domain'] = $this->account_domain; |
@@ -1540,9 +1537,9 @@ discard block |
||
1540 | 1537 | * @param string &$account_lid returned account_lid (ie. user) |
1541 | 1538 | * @param string &$domain returned domain (ie. domain) |
1542 | 1539 | */ |
1543 | - private function split_login_domain($login,&$account_lid,&$domain) |
|
1540 | + private function split_login_domain($login, &$account_lid, &$domain) |
|
1544 | 1541 | { |
1545 | - $parts = explode('@',$login); |
|
1542 | + $parts = explode('@', $login); |
|
1546 | 1543 | |
1547 | 1544 | //conference - for strings like [email protected]@default , |
1548 | 1545 | //allows that user have a login that is his e-mail. (viniciuscb) |
@@ -1550,11 +1547,11 @@ discard block |
||
1550 | 1547 | { |
1551 | 1548 | $probable_domain = array_pop($parts); |
1552 | 1549 | //Last part of login string, when separated by @, is a domain name |
1553 | - if (in_array($probable_domain,$this->egw_domains)) |
|
1550 | + if (in_array($probable_domain, $this->egw_domains)) |
|
1554 | 1551 | { |
1555 | 1552 | $got_login = true; |
1556 | 1553 | $domain = $probable_domain; |
1557 | - $account_lid = implode('@',$parts); |
|
1554 | + $account_lid = implode('@', $parts); |
|
1558 | 1555 | } |
1559 | 1556 | } |
1560 | 1557 | |
@@ -1577,9 +1574,9 @@ discard block |
||
1577 | 1574 | * @param boolean $allow_password_md5 =false can password alread be an md5 hash |
1578 | 1575 | * @return string |
1579 | 1576 | */ |
1580 | - static function user_pw_hash($user,$password,$allow_password_md5=false) |
|
1577 | + static function user_pw_hash($user, $password, $allow_password_md5 = false) |
|
1581 | 1578 | { |
1582 | - $password_md5 = $allow_password_md5 && preg_match('/^[a-f0-9]{32}$/',$password) ? $password : md5($password); |
|
1579 | + $password_md5 = $allow_password_md5 && preg_match('/^[a-f0-9]{32}$/', $password) ? $password : md5($password); |
|
1583 | 1580 | |
1584 | 1581 | $hash = sha1(strtolower($user).$password_md5); |
1585 | 1582 | |
@@ -1594,12 +1591,12 @@ discard block |
||
1594 | 1591 | */ |
1595 | 1592 | public static function init_handler() |
1596 | 1593 | { |
1597 | - switch(session_status()) |
|
1594 | + switch (session_status()) |
|
1598 | 1595 | { |
1599 | 1596 | case PHP_SESSION_DISABLED: |
1600 | 1597 | throw new \ErrorException('EGroupware requires PHP session extension!'); |
1601 | 1598 | case PHP_SESSION_NONE: |
1602 | - ini_set('session.use_cookies',0); // disable the automatic use of cookies, as it uses the path / by default |
|
1599 | + ini_set('session.use_cookies', 0); // disable the automatic use of cookies, as it uses the path / by default |
|
1603 | 1600 | session_name(self::EGW_SESSION_NAME); |
1604 | 1601 | if (($sessionid = self::get_sessionid())) |
1605 | 1602 | { |
@@ -1612,7 +1609,7 @@ discard block |
||
1612 | 1609 | } |
1613 | 1610 | break; |
1614 | 1611 | case PHP_SESSION_ACTIVE: |
1615 | - return true; // session created by MServer |
|
1612 | + return true; // session created by MServer |
|
1616 | 1613 | } |
1617 | 1614 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() no active session!"); |
1618 | 1615 | |
@@ -1630,7 +1627,7 @@ discard block |
||
1630 | 1627 | * @param int $expire =null expiration time in seconds, default $GLOBALS['egw_info']['flags']['nocachecontrol'] or php.ini session.cache_expire |
1631 | 1628 | * @param int $private =null allows to set private caching with given expiration time, by setting it to true |
1632 | 1629 | */ |
1633 | - public static function cache_control($expire=null, $private=null) |
|
1630 | + public static function cache_control($expire = null, $private = null) |
|
1634 | 1631 | { |
1635 | 1632 | if (is_null($expire) && isset($GLOBALS['egw_info']['flags']['nocachecontrol']) && is_int($GLOBALS['egw_info']['flags']['nocachecontrol'])) |
1636 | 1633 | { |
@@ -1640,7 +1637,7 @@ discard block |
||
1640 | 1637 | if (!isset($_SESSION)) |
1641 | 1638 | { |
1642 | 1639 | // controling caching and expires header |
1643 | - if(!isset($expire) && (!isset($GLOBALS['egw_info']['flags']['nocachecontrol']) || |
|
1640 | + if (!isset($expire) && (!isset($GLOBALS['egw_info']['flags']['nocachecontrol']) || |
|
1644 | 1641 | !$GLOBALS['egw_info']['flags']['nocachecontrol'])) |
1645 | 1642 | { |
1646 | 1643 | session_cache_limiter('nocache'); |
@@ -1650,7 +1647,7 @@ discard block |
||
1650 | 1647 | // allow public caching: proxys, cdns, ... |
1651 | 1648 | if (isset($expire)) |
1652 | 1649 | { |
1653 | - session_cache_expire((int)ceil($expire/60)); // in minutes |
|
1650 | + session_cache_expire((int)ceil($expire / 60)); // in minutes |
|
1654 | 1651 | } |
1655 | 1652 | session_cache_limiter($private ? 'private' : 'public'); |
1656 | 1653 | } |
@@ -1663,8 +1660,8 @@ discard block |
||
1663 | 1660 | // session already started |
1664 | 1661 | if (isset($_SESSION)) |
1665 | 1662 | { |
1666 | - if ($expire && (session_cache_limiter() !== ($expire===true?'private_no_expire':'public') || |
|
1667 | - is_int($expire) && $expire/60 !== session_cache_expire())) |
|
1663 | + if ($expire && (session_cache_limiter() !== ($expire === true ? 'private_no_expire' : 'public') || |
|
1664 | + is_int($expire) && $expire / 60 !== session_cache_expire())) |
|
1668 | 1665 | { |
1669 | 1666 | $file = $line = null; |
1670 | 1667 | if (headers_sent($file, $line)) |
@@ -1672,20 +1669,20 @@ discard block |
||
1672 | 1669 | error_log(__METHOD__."($expire) called, but header already sent in $file: $line"); |
1673 | 1670 | return; |
1674 | 1671 | } |
1675 | - if($expire === true) // same behavior as session_cache_limiter('private_no_expire') |
|
1672 | + if ($expire === true) // same behavior as session_cache_limiter('private_no_expire') |
|
1676 | 1673 | { |
1677 | - header('Cache-Control: private, max-age='.(60*session_cache_expire())); |
|
1674 | + header('Cache-Control: private, max-age='.(60 * session_cache_expire())); |
|
1678 | 1675 | header_remove('Expires'); |
1679 | 1676 | } |
1680 | 1677 | elseif ($private) |
1681 | 1678 | { |
1682 | 1679 | header('Cache-Control: private, max-age='.$expire); |
1683 | - header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expire) . ' GMT'); |
|
1680 | + header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expire).' GMT'); |
|
1684 | 1681 | } |
1685 | 1682 | else |
1686 | 1683 | { |
1687 | 1684 | header('Cache-Control: public, max-age='.$expire); |
1688 | - header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expire) . ' GMT'); |
|
1685 | + header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expire).' GMT'); |
|
1689 | 1686 | } |
1690 | 1687 | // remove Pragma header, might be set by old header |
1691 | 1688 | if (function_exists('header_remove')) // PHP 5.3+ |
@@ -1710,10 +1707,10 @@ discard block |
||
1710 | 1707 | * @param array $filter =array() extra filter for sessions |
1711 | 1708 | * @return array with sessions (values for keys as in $sort) |
1712 | 1709 | */ |
1713 | - public static function session_list($start,$sort='DESC',$order='session_dla',$all_no_sort=False,array $filter=array()) |
|
1710 | + public static function session_list($start, $sort = 'DESC', $order = 'session_dla', $all_no_sort = False, array $filter = array()) |
|
1714 | 1711 | { |
1715 | 1712 | $sessions = array(); |
1716 | - if (!preg_match('/^[a-z0-9_ ,]+$/i',$order_by=$order.' '.$sort) || $order_by == ' ') |
|
1713 | + if (!preg_match('/^[a-z0-9_ ,]+$/i', $order_by = $order.' '.$sort) || $order_by == ' ') |
|
1717 | 1714 | { |
1718 | 1715 | $order_by = 'session_dla DESC'; |
1719 | 1716 | } |
@@ -1721,7 +1718,7 @@ discard block |
||
1721 | 1718 | $filter[] = 'account_id>0'; |
1722 | 1719 | $filter[] = 'session_dla > '.(int)(time() - $GLOBALS['egw_info']['server']['sessions_timeout']); |
1723 | 1720 | $filter[] = '(notification_heartbeat IS NULL OR notification_heartbeat > '.self::heartbeat_limit().')'; |
1724 | - foreach($GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, '*', $filter, __LINE__, __FILE__, |
|
1721 | + foreach ($GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, '*', $filter, __LINE__, __FILE__, |
|
1725 | 1722 | $all_no_sort ? false : $start, 'ORDER BY '.$order_by) as $row) |
1726 | 1723 | { |
1727 | 1724 | $sessions[$row['sessionid']] = $row; |
@@ -1735,7 +1732,7 @@ discard block |
||
1735 | 1732 | * @param array $filter =array() extra filter for sessions |
1736 | 1733 | * @return int number of active sessions |
1737 | 1734 | */ |
1738 | - public static function session_count(array $filter=array()) |
|
1735 | + public static function session_count(array $filter = array()) |
|
1739 | 1736 | { |
1740 | 1737 | $filter['lo'] = null; |
1741 | 1738 | $filter[] = 'account_id>0'; |
@@ -1751,16 +1748,16 @@ discard block |
||
1751 | 1748 | */ |
1752 | 1749 | public static function heartbeat_limit() |
1753 | 1750 | { |
1754 | - static $limit=null; |
|
1751 | + static $limit = null; |
|
1755 | 1752 | |
1756 | 1753 | if (is_null($limit)) |
1757 | 1754 | { |
1758 | 1755 | $config = Config::read('notifications'); |
1759 | - if (!($popup_poll_interval = $config['popup_poll_interval'])) |
|
1756 | + if (!($popup_poll_interval = $config['popup_poll_interval'])) |
|
1760 | 1757 | { |
1761 | 1758 | $popup_poll_interval = 60; |
1762 | 1759 | } |
1763 | - $limit = (int)(time() - $popup_poll_interval-10); // 10s grace periode |
|
1760 | + $limit = (int)(time() - $popup_poll_interval - 10); // 10s grace periode |
|
1764 | 1761 | } |
1765 | 1762 | return $limit; |
1766 | 1763 | } |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | |
250 | 250 | // set session_timeout from global php.ini and default to 14400=4h, if not set |
251 | 251 | if (!($GLOBALS['egw_info']['server']['sessions_timeout'] = ini_get('session.gc_maxlifetime'))) |
252 | - { |
|
252 | + { |
|
253 | 253 | ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout']=14400); |
254 | 254 | } |
255 | 255 | } |
@@ -288,7 +288,10 @@ discard block |
||
288 | 288 | */ |
289 | 289 | function commit_session() |
290 | 290 | { |
291 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() sessionid=$this->sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]).' '.function_backtrace()); |
|
291 | + if (self::ERROR_LOG_DEBUG) |
|
292 | + { |
|
293 | + error_log(__METHOD__."() sessionid=$this->sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]).' '.function_backtrace()); |
|
294 | + } |
|
292 | 295 | self::encrypt($this->kp3); |
293 | 296 | |
294 | 297 | session_write_close(); |
@@ -350,7 +353,10 @@ discard block |
||
350 | 353 | */ |
351 | 354 | static function log_session_usage(&$arr,$label,$recursion=true,$limit=1000) |
352 | 355 | { |
353 | - if (!is_array($arr)) return; |
|
356 | + if (!is_array($arr)) |
|
357 | + { |
|
358 | + return; |
|
359 | + } |
|
354 | 360 | |
355 | 361 | $sizes = array(); |
356 | 362 | foreach($arr as $key => &$data) |
@@ -365,7 +371,10 @@ discard block |
||
365 | 371 | if ($diff > $limit) |
366 | 372 | { |
367 | 373 | error_log("strlen({$label}[$key])=".Vfs::hsize($size).", diff=".Vfs::hsize($diff)); |
368 | - if ($recursion) self::log_session_usage($arr[$key],$label.'['.$key.']',$recursion,$limit); |
|
374 | + if ($recursion) |
|
375 | + { |
|
376 | + self::log_session_usage($arr[$key],$label.'['.$key.']',$recursion,$limit); |
|
377 | + } |
|
369 | 378 | } |
370 | 379 | } |
371 | 380 | } |
@@ -463,7 +472,10 @@ discard block |
||
463 | 472 | $this->passwd = $passwd; |
464 | 473 | $this->passwd_type = $passwd_type; |
465 | 474 | } |
466 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) starting ..."); |
|
475 | + if (self::ERROR_LOG_DEBUG) |
|
476 | + { |
|
477 | + error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) starting ..."); |
|
478 | + } |
|
467 | 479 | |
468 | 480 | self::split_login_domain($login,$this->account_lid,$this->account_domain); |
469 | 481 | // add domain to the login, if not already there |
@@ -507,7 +519,10 @@ discard block |
||
507 | 519 | { |
508 | 520 | $this->log_access($this->reason,$login,$user_ip,0); // log unsuccessfull login |
509 | 521 | } |
510 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
|
522 | + if (self::ERROR_LOG_DEBUG) |
|
523 | + { |
|
524 | + error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
|
525 | + } |
|
511 | 526 | return false; |
512 | 527 | } |
513 | 528 | if ($fail_on_forced_password_change && Auth::check_password_change($this->reason) === false) |
@@ -557,7 +572,10 @@ discard block |
||
557 | 572 | $this->reason = 'account is expired'; |
558 | 573 | $this->cd_reason = self::CD_ACCOUNT_EXPIRED; |
559 | 574 | |
560 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
|
575 | + if (self::ERROR_LOG_DEBUG) |
|
576 | + { |
|
577 | + error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
|
578 | + } |
|
561 | 579 | return false; |
562 | 580 | } |
563 | 581 | |
@@ -581,25 +599,34 @@ discard block |
||
581 | 599 | 'passwd' => $this->passwd, |
582 | 600 | 'account_domain' => $this->account_domain, |
583 | 601 | 'user_ip' => $user_ip, |
584 | - ),'',true))) // true = run hooks from all apps, not just the ones the current user has perms to run |
|
602 | + ),'',true))) |
|
603 | + { |
|
604 | + // true = run hooks from all apps, not just the ones the current user has perms to run |
|
585 | 605 | { |
586 | 606 | foreach($hook_result as $reason) |
587 | 607 | { |
588 | 608 | if ($reason) // called hook requests to deny the session |
589 | 609 | { |
590 | 610 | $this->reason = $this->cd_reason = $reason; |
611 | + } |
|
591 | 612 | $this->log_access($this->reason,$login,$user_ip,0); // log unsuccessfull login |
592 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
|
613 | + if (self::ERROR_LOG_DEBUG) |
|
614 | + { |
|
615 | + error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
|
616 | + } |
|
593 | 617 | return false; |
594 | 618 | } |
595 | 619 | } |
596 | 620 | } |
597 | 621 | $GLOBALS['egw']->db->transaction_begin(); |
598 | 622 | $this->register_session($this->login,$user_ip,$now,$this->session_flags); |
599 | - if ($this->session_flags != 'A') // dont log anonymous sessions |
|
623 | + if ($this->session_flags != 'A') |
|
624 | + { |
|
625 | + // dont log anonymous sessions |
|
600 | 626 | { |
601 | 627 | $this->sessionid_access_log = $this->log_access($this->sessionid,$login,$user_ip,$this->account_id); |
602 | 628 | } |
629 | + } |
|
603 | 630 | Cache::setSession('phpgwapi', 'account_previous_login', $GLOBALS['egw']->auth->previous_login); |
604 | 631 | $GLOBALS['egw']->accounts->update_lastlogin($this->account_id,$user_ip); |
605 | 632 | $GLOBALS['egw']->db->transaction_commit(); |
@@ -615,7 +642,10 @@ discard block |
||
615 | 642 | self::egw_setcookie('last_loginid', $this->account_lid ,$now+1209600); /* For 2 weeks */ |
616 | 643 | self::egw_setcookie('last_domain',$this->account_domain,$now+1209600); |
617 | 644 | } |
618 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) successfull sessionid=$this->sessionid"); |
|
645 | + if (self::ERROR_LOG_DEBUG) |
|
646 | + { |
|
647 | + error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) successfull sessionid=$this->sessionid"); |
|
648 | + } |
|
619 | 649 | |
620 | 650 | return $this->sessionid; |
621 | 651 | } |
@@ -792,10 +822,13 @@ discard block |
||
792 | 822 | //error_log(__METHOD__."('$login', '$ip') false_ip=$false_ip, false_id=$false_id --> blocked=".array2string($blocked)); |
793 | 823 | |
794 | 824 | if ($blocked && $GLOBALS['egw_info']['server']['admin_mails'] && |
795 | - $GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time()-5*60) // max. one mail every 5mins |
|
825 | + $GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time()-5*60) |
|
826 | + { |
|
827 | + // max. one mail every 5mins |
|
796 | 828 | { |
797 | 829 | try { |
798 | 830 | $mailer = new Mailer(); |
831 | + } |
|
799 | 832 | // notify admin(s) via email |
800 | 833 | $mailer->setFrom('eGroupWare@'.$GLOBALS['egw_info']['server']['mail_suffix']); |
801 | 834 | $mailer->addHeader('Subject', lang("eGroupWare: login blocked for user '%1', IP %2",$login,$ip)); |
@@ -873,7 +906,10 @@ discard block |
||
873 | 906 | { |
874 | 907 | $sessionid = false; |
875 | 908 | } |
876 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid,true)); |
|
909 | + if (self::ERROR_LOG_DEBUG) |
|
910 | + { |
|
911 | + error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid,true)); |
|
912 | + } |
|
877 | 913 | return $sessionid; |
878 | 914 | } |
879 | 915 | |
@@ -903,7 +939,10 @@ discard block |
||
903 | 939 | */ |
904 | 940 | function verify($sessionid=null,$kp3=null) |
905 | 941 | { |
906 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid','$kp3') ".function_backtrace()); |
|
942 | + if (self::ERROR_LOG_DEBUG) |
|
943 | + { |
|
944 | + error_log(__METHOD__."('$sessionid','$kp3') ".function_backtrace()); |
|
945 | + } |
|
907 | 946 | |
908 | 947 | $fill_egw_info_and_repositories = !$GLOBALS['egw_info']['flags']['restored_from_session']; |
909 | 948 | |
@@ -919,7 +958,10 @@ discard block |
||
919 | 958 | |
920 | 959 | if (!$this->sessionid) |
921 | 960 | { |
922 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') get_sessionid()='".self::get_sessionid()."' No session ID"); |
|
961 | + if (self::ERROR_LOG_DEBUG) |
|
962 | + { |
|
963 | + error_log(__METHOD__."('$sessionid') get_sessionid()='".self::get_sessionid()."' No session ID"); |
|
964 | + } |
|
923 | 965 | return false; |
924 | 966 | } |
925 | 967 | |
@@ -940,14 +982,20 @@ discard block |
||
940 | 982 | // check if we have a eGroupware session --> return false if not (but dont destroy it!) |
941 | 983 | if (is_null($_SESSION) || !isset($_SESSION[self::EGW_SESSION_VAR])) |
942 | 984 | { |
943 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session does NOT exist!"); |
|
985 | + if (self::ERROR_LOG_DEBUG) |
|
986 | + { |
|
987 | + error_log(__METHOD__."('$sessionid') session does NOT exist!"); |
|
988 | + } |
|
944 | 989 | return false; |
945 | 990 | } |
946 | 991 | $session =& $_SESSION[self::EGW_SESSION_VAR]; |
947 | 992 | |
948 | 993 | if ($session['session_dla'] <= time() - $GLOBALS['egw_info']['server']['sessions_timeout']) |
949 | 994 | { |
950 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session timed out!"); |
|
995 | + if (self::ERROR_LOG_DEBUG) |
|
996 | + { |
|
997 | + error_log(__METHOD__."('$sessionid') session timed out!"); |
|
998 | + } |
|
951 | 999 | $this->destroy($sessionid,$kp3); |
952 | 1000 | return false; |
953 | 1001 | } |
@@ -975,7 +1023,10 @@ discard block |
||
975 | 1023 | $this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid,'account_lid','u'); |
976 | 1024 | if (!$this->account_id) |
977 | 1025 | { |
978 | - if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) !accounts::name2id('$this->account_lid')"); |
|
1026 | + if (self::ERROR_LOG_DEBUG) |
|
1027 | + { |
|
1028 | + error_log("*** Session::verify($sessionid) !accounts::name2id('$this->account_lid')"); |
|
1029 | + } |
|
979 | 1030 | return false; |
980 | 1031 | } |
981 | 1032 | |
@@ -1002,7 +1053,10 @@ discard block |
||
1002 | 1053 | |
1003 | 1054 | if ($GLOBALS['egw']->accounts->is_expired($GLOBALS['egw_info']['user'])) |
1004 | 1055 | { |
1005 | - if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) accounts is expired"); |
|
1056 | + if (self::ERROR_LOG_DEBUG) |
|
1057 | + { |
|
1058 | + error_log("*** Session::verify($sessionid) accounts is expired"); |
|
1059 | + } |
|
1006 | 1060 | return false; |
1007 | 1061 | } |
1008 | 1062 | $this->passwd = base64_decode(Cache::getSession('phpgwapi', 'password')); |
@@ -1013,7 +1067,10 @@ discard block |
||
1013 | 1067 | } |
1014 | 1068 | if ($this->account_domain != $GLOBALS['egw_info']['user']['domain']) |
1015 | 1069 | { |
1016 | - if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) wrong domain"); |
|
1070 | + if (self::ERROR_LOG_DEBUG) |
|
1071 | + { |
|
1072 | + error_log("*** Session::verify($sessionid) wrong domain"); |
|
1073 | + } |
|
1017 | 1074 | return false; |
1018 | 1075 | } |
1019 | 1076 | |
@@ -1022,7 +1079,10 @@ discard block |
||
1022 | 1079 | if (strtoupper(substr(PHP_OS,0,3)) != 'WIN' && (!$GLOBALS['egw_info']['user']['session_ip'] || |
1023 | 1080 | $GLOBALS['egw_info']['user']['session_ip'] != $this->getuser_ip())) |
1024 | 1081 | { |
1025 | - if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) wrong IP"); |
|
1082 | + if (self::ERROR_LOG_DEBUG) |
|
1083 | + { |
|
1084 | + error_log("*** Session::verify($sessionid) wrong IP"); |
|
1085 | + } |
|
1026 | 1086 | return false; |
1027 | 1087 | } |
1028 | 1088 | } |
@@ -1035,7 +1095,10 @@ discard block |
||
1035 | 1095 | } |
1036 | 1096 | if (!$this->account_lid) |
1037 | 1097 | { |
1038 | - if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) !account_lid"); |
|
1098 | + if (self::ERROR_LOG_DEBUG) |
|
1099 | + { |
|
1100 | + error_log("*** Session::verify($sessionid) !account_lid"); |
|
1101 | + } |
|
1039 | 1102 | return false; |
1040 | 1103 | } |
1041 | 1104 | |
@@ -1054,13 +1117,19 @@ discard block |
||
1054 | 1117 | $_REQUEST[self::EGW_SESSION_NAME] === $this->sessionid && |
1055 | 1118 | (!isset($_COOKIE[self::EGW_SESSION_NAME]) || $_COOKIE[self::EGW_SESSION_NAME] !== $_REQUEST[self::EGW_SESSION_NAME])) |
1056 | 1119 | { |
1057 | - if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS, but NO required cookies set --> setting them now"); |
|
1120 | + if (self::ERROR_LOG_DEBUG) |
|
1121 | + { |
|
1122 | + error_log("--> Session::verify($sessionid) SUCCESS, but NO required cookies set --> setting them now"); |
|
1123 | + } |
|
1058 | 1124 | self::egw_setcookie(self::EGW_SESSION_NAME,$this->sessionid); |
1059 | 1125 | self::egw_setcookie('kp3',$this->kp3); |
1060 | 1126 | self::egw_setcookie('domain',$this->account_domain); |
1061 | 1127 | } |
1062 | 1128 | |
1063 | - if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS"); |
|
1129 | + if (self::ERROR_LOG_DEBUG) |
|
1130 | + { |
|
1131 | + error_log("--> Session::verify($sessionid) SUCCESS"); |
|
1132 | + } |
|
1064 | 1133 | |
1065 | 1134 | return true; |
1066 | 1135 | } |
@@ -1080,14 +1149,20 @@ discard block |
||
1080 | 1149 | } |
1081 | 1150 | $this->log_access($sessionid); // log logout-time |
1082 | 1151 | |
1083 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($sessionid,$kp3)"); |
|
1152 | + if (self::ERROR_LOG_DEBUG) |
|
1153 | + { |
|
1154 | + error_log(__METHOD__."($sessionid,$kp3)"); |
|
1155 | + } |
|
1084 | 1156 | |
1085 | - if (is_numeric($sessionid)) // do we have a access-log-id --> get PHP session id |
|
1157 | + if (is_numeric($sessionid)) |
|
1158 | + { |
|
1159 | + // do we have a access-log-id --> get PHP session id |
|
1086 | 1160 | { |
1087 | 1161 | $sessionid = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE,'session_php',array( |
1088 | 1162 | 'sessionid' => $sessionid, |
1089 | 1163 | ),__LINE__,__FILE__)->fetchColumn(); |
1090 | 1164 | } |
1165 | + } |
|
1091 | 1166 | |
1092 | 1167 | Hooks::process(array( |
1093 | 1168 | 'location' => 'session_destroyed', |
@@ -1097,7 +1172,10 @@ discard block |
||
1097 | 1172 | // Only do the following, if where working with the current user |
1098 | 1173 | if (!$GLOBALS['egw_info']['user']['sessionid'] || $sessionid == $GLOBALS['egw_info']['user']['sessionid']) |
1099 | 1174 | { |
1100 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__." ********* about to call session_destroy!"); |
|
1175 | + if (self::ERROR_LOG_DEBUG) |
|
1176 | + { |
|
1177 | + error_log(__METHOD__." ********* about to call session_destroy!"); |
|
1178 | + } |
|
1101 | 1179 | session_unset(); |
1102 | 1180 | @session_destroy(); |
1103 | 1181 | // we need to (re-)load the eGW session-handler, as session_destroy unloads custom session-handlers |
@@ -1192,7 +1270,10 @@ discard block |
||
1192 | 1270 | } |
1193 | 1271 | else |
1194 | 1272 | { |
1195 | - if ($othervars) $extravars .= ($extravars?'&':'').$othervars; |
|
1273 | + if ($othervars) |
|
1274 | + { |
|
1275 | + $extravars .= ($extravars?'&':'').$othervars; |
|
1276 | + } |
|
1196 | 1277 | } |
1197 | 1278 | |
1198 | 1279 | // parse extravars string into the vars array |
@@ -1201,7 +1282,11 @@ discard block |
||
1201 | 1282 | foreach(explode('&',$extravars) as $expr) |
1202 | 1283 | { |
1203 | 1284 | list($var,$val) = explode('=', $expr,2); |
1204 | - if (strpos($val,'%26') != false) $val = str_replace('%26','&',$val); // make sure to not double encode & |
|
1285 | + if (strpos($val,'%26') != false) |
|
1286 | + { |
|
1287 | + $val = str_replace('%26','&',$val); |
|
1288 | + } |
|
1289 | + // make sure to not double encode & |
|
1205 | 1290 | if (substr($var,-2) == '[]') |
1206 | 1291 | { |
1207 | 1292 | $vars[substr($var,0,-2)][] = $val; |
@@ -1282,14 +1367,22 @@ discard block |
||
1282 | 1367 | { |
1283 | 1368 | self::set_cookiedomain(); |
1284 | 1369 | } |
1285 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($cookiename,$cookievalue,$cookietime,$cookiepath,".self::$cookie_domain.")"); |
|
1370 | + if (self::ERROR_LOG_DEBUG) |
|
1371 | + { |
|
1372 | + error_log(__METHOD__."($cookiename,$cookievalue,$cookietime,$cookiepath,".self::$cookie_domain.")"); |
|
1373 | + } |
|
1286 | 1374 | |
1287 | 1375 | // if we are installed in iOS as web-app, we must not set a cookietime==0 (session-cookie), |
1288 | 1376 | // as every change between apps will cause the cookie to get lost |
1289 | 1377 | static $is_iOS = null; |
1290 | - if (!$cookietime && !isset($is_iOS)) $is_iOS = (bool)preg_match('/^(iPhone|iPad|iPod)/i', Header\UserAgent::mobile()); |
|
1378 | + if (!$cookietime && !isset($is_iOS)) |
|
1379 | + { |
|
1380 | + $is_iOS = (bool)preg_match('/^(iPhone|iPad|iPod)/i', Header\UserAgent::mobile()); |
|
1381 | + } |
|
1291 | 1382 | |
1292 | - if(!headers_sent()) // gives only a warning, but can not send the cookie anyway |
|
1383 | + if(!headers_sent()) |
|
1384 | + { |
|
1385 | + // gives only a warning, but can not send the cookie anyway |
|
1293 | 1386 | { |
1294 | 1387 | setcookie($cookiename, $cookievalue, |
1295 | 1388 | !$cookietime && $is_iOS ? time()+self::IOS_SESSION_COOKIE_LIFETIME : $cookietime, |
@@ -1297,6 +1390,7 @@ discard block |
||
1297 | 1390 | // if called via HTTPS, only send cookie for https and only allow cookie access via HTTP (true) |
1298 | 1391 | empty($GLOBALS['egw_info']['server']['insecure_cookies']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off', true); |
1299 | 1392 | } |
1393 | + } |
|
1300 | 1394 | } |
1301 | 1395 | |
1302 | 1396 | /** |
@@ -1348,15 +1442,25 @@ discard block |
||
1348 | 1442 | */ |
1349 | 1443 | public static function search_instance($login,$domain_requested,&$default_domain,$server_names,array $domains=null) |
1350 | 1444 | { |
1351 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".".array2string($server_names).".".array2string($domains).")"); |
|
1445 | + if (self::ERROR_LOG_DEBUG) |
|
1446 | + { |
|
1447 | + error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".".array2string($server_names).".".array2string($domains).")"); |
|
1448 | + } |
|
1352 | 1449 | |
1353 | - if (is_null($domains)) $domains = $GLOBALS['egw_domain']; |
|
1450 | + if (is_null($domains)) |
|
1451 | + { |
|
1452 | + $domains = $GLOBALS['egw_domain']; |
|
1453 | + } |
|
1354 | 1454 | |
1355 | - if (!isset($default_domain) || !isset($domains[$default_domain])) // allow to overwrite the default domain |
|
1455 | + if (!isset($default_domain) || !isset($domains[$default_domain])) |
|
1456 | + { |
|
1457 | + // allow to overwrite the default domain |
|
1356 | 1458 | { |
1357 | 1459 | foreach((array)$server_names as $server_name) |
1358 | 1460 | { |
1359 | - list($server_name) = explode(':', $server_name); // remove port from HTTP_HOST |
|
1461 | + list($server_name) = explode(':', $server_name); |
|
1462 | + } |
|
1463 | + // remove port from HTTP_HOST |
|
1360 | 1464 | if(isset($domains[$server_name])) |
1361 | 1465 | { |
1362 | 1466 | $default_domain = $server_name; |
@@ -1381,11 +1485,14 @@ discard block |
||
1381 | 1485 | } |
1382 | 1486 | } |
1383 | 1487 | } |
1384 | - if (isset($login)) // on login |
|
1488 | + if (isset($login)) |
|
1489 | + { |
|
1490 | + // on login |
|
1385 | 1491 | { |
1386 | 1492 | if (strpos($login,'@') === false || count($domains) == 1) |
1387 | 1493 | { |
1388 | 1494 | $login .= '@' . (isset($_POST['logindomain']) ? $_POST['logindomain'] : $default_domain); |
1495 | + } |
|
1389 | 1496 | } |
1390 | 1497 | $parts = explode('@',$login); |
1391 | 1498 | $domain = array_pop($parts); |
@@ -1399,7 +1506,10 @@ discard block |
||
1399 | 1506 | { |
1400 | 1507 | $domain = $default_domain; |
1401 | 1508 | } |
1402 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() default_domain=".array2string($default_domain).', login='.array2string($login)." returning ".array2string($domain)); |
|
1509 | + if (self::ERROR_LOG_DEBUG) |
|
1510 | + { |
|
1511 | + error_log(__METHOD__."() default_domain=".array2string($default_domain).', login='.array2string($login)." returning ".array2string($domain)); |
|
1512 | + } |
|
1403 | 1513 | |
1404 | 1514 | return $domain; |
1405 | 1515 | } |
@@ -1438,7 +1548,10 @@ discard block |
||
1438 | 1548 | $action = $_SERVER['PHP_SELF']; |
1439 | 1549 | // remove EGroupware path, if not installed in webroot |
1440 | 1550 | $egw_path = $GLOBALS['egw_info']['server']['webserver_url']; |
1441 | - if ($egw_path[0] != '/') $egw_path = parse_url($egw_path,PHP_URL_PATH); |
|
1551 | + if ($egw_path[0] != '/') |
|
1552 | + { |
|
1553 | + $egw_path = parse_url($egw_path,PHP_URL_PATH); |
|
1554 | + } |
|
1442 | 1555 | if ($action == '/Microsoft-Server-ActiveSync') |
1443 | 1556 | { |
1444 | 1557 | $action .= '?Cmd='.$_GET['Cmd'].'&DeviceId='.$_GET['DeviceId']; |
@@ -1465,7 +1578,10 @@ discard block |
||
1465 | 1578 | |
1466 | 1579 | $_SESSION[self::EGW_SESSION_VAR]['session_dla'] = time(); |
1467 | 1580 | $_SESSION[self::EGW_SESSION_VAR]['session_action'] = $this->action; |
1468 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__.'() _SESSION['.self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR])); |
|
1581 | + if (self::ERROR_LOG_DEBUG) |
|
1582 | + { |
|
1583 | + error_log(__METHOD__.'() _SESSION['.self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR])); |
|
1584 | + } |
|
1469 | 1585 | |
1470 | 1586 | return $this->action; |
1471 | 1587 | } |
@@ -1607,14 +1723,20 @@ discard block |
||
1607 | 1723 | self::cache_control(); |
1608 | 1724 | $ok = session_start(); |
1609 | 1725 | self::decrypt(); |
1610 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() sessionid=$sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR])); |
|
1726 | + if (self::ERROR_LOG_DEBUG) |
|
1727 | + { |
|
1728 | + error_log(__METHOD__."() sessionid=$sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR])); |
|
1729 | + } |
|
1611 | 1730 | return $ok; |
1612 | 1731 | } |
1613 | 1732 | break; |
1614 | 1733 | case PHP_SESSION_ACTIVE: |
1615 | 1734 | return true; // session created by MServer |
1616 | 1735 | } |
1617 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() no active session!"); |
|
1736 | + if (self::ERROR_LOG_DEBUG) |
|
1737 | + { |
|
1738 | + error_log(__METHOD__."() no active session!"); |
|
1739 | + } |
|
1618 | 1740 | |
1619 | 1741 | return false; |
1620 | 1742 | } |
@@ -1672,9 +1794,12 @@ discard block |
||
1672 | 1794 | error_log(__METHOD__."($expire) called, but header already sent in $file: $line"); |
1673 | 1795 | return; |
1674 | 1796 | } |
1675 | - if($expire === true) // same behavior as session_cache_limiter('private_no_expire') |
|
1797 | + if($expire === true) |
|
1798 | + { |
|
1799 | + // same behavior as session_cache_limiter('private_no_expire') |
|
1676 | 1800 | { |
1677 | 1801 | header('Cache-Control: private, max-age='.(60*session_cache_expire())); |
1802 | + } |
|
1678 | 1803 | header_remove('Expires'); |
1679 | 1804 | } |
1680 | 1805 | elseif ($private) |
@@ -1688,10 +1813,13 @@ discard block |
||
1688 | 1813 | header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expire) . ' GMT'); |
1689 | 1814 | } |
1690 | 1815 | // remove Pragma header, might be set by old header |
1691 | - if (function_exists('header_remove')) // PHP 5.3+ |
|
1816 | + if (function_exists('header_remove')) |
|
1817 | + { |
|
1818 | + // PHP 5.3+ |
|
1692 | 1819 | { |
1693 | 1820 | header_remove('Pragma'); |
1694 | 1821 | } |
1822 | + } |
|
1695 | 1823 | else |
1696 | 1824 | { |
1697 | 1825 | header('Pragma:'); |
@@ -73,60 +73,60 @@ discard block |
||
73 | 73 | const EGW_SESSION_NAME = 'sessionid'; |
74 | 74 | |
75 | 75 | /** |
76 | - * current user login (account_lid@domain) |
|
77 | - * |
|
78 | - * @var string |
|
79 | - */ |
|
76 | + * current user login (account_lid@domain) |
|
77 | + * |
|
78 | + * @var string |
|
79 | + */ |
|
80 | 80 | var $login; |
81 | 81 | |
82 | 82 | /** |
83 | - * current user password |
|
84 | - * |
|
85 | - * @var string |
|
86 | - */ |
|
83 | + * current user password |
|
84 | + * |
|
85 | + * @var string |
|
86 | + */ |
|
87 | 87 | var $passwd; |
88 | 88 | |
89 | 89 | /** |
90 | - * current user db/ldap account id |
|
91 | - * |
|
92 | - * @var int |
|
93 | - */ |
|
90 | + * current user db/ldap account id |
|
91 | + * |
|
92 | + * @var int |
|
93 | + */ |
|
94 | 94 | var $account_id; |
95 | 95 | |
96 | 96 | /** |
97 | - * current user account login id (without the eGW-domain/-instance part |
|
98 | - * |
|
99 | - * @var string |
|
100 | - */ |
|
97 | + * current user account login id (without the eGW-domain/-instance part |
|
98 | + * |
|
99 | + * @var string |
|
100 | + */ |
|
101 | 101 | var $account_lid; |
102 | 102 | |
103 | 103 | /** |
104 | - * domain for current user |
|
105 | - * |
|
106 | - * @var string |
|
107 | - */ |
|
104 | + * domain for current user |
|
105 | + * |
|
106 | + * @var string |
|
107 | + */ |
|
108 | 108 | var $account_domain; |
109 | 109 | |
110 | 110 | /** |
111 | - * type flag, A - anonymous session, N - None, normal session |
|
112 | - * |
|
113 | - * @var string |
|
114 | - */ |
|
111 | + * type flag, A - anonymous session, N - None, normal session |
|
112 | + * |
|
113 | + * @var string |
|
114 | + */ |
|
115 | 115 | var $session_flags; |
116 | 116 | |
117 | 117 | /** |
118 | - * current user session id |
|
119 | - * |
|
120 | - * @var string |
|
121 | - */ |
|
118 | + * current user session id |
|
119 | + * |
|
120 | + * @var string |
|
121 | + */ |
|
122 | 122 | var $sessionid; |
123 | 123 | |
124 | 124 | /** |
125 | - * an other session specific id (md5 from a random string), |
|
126 | - * used together with the sessionid for xmlrpc basic auth and the encryption of session-data (if that's enabled) |
|
127 | - * |
|
128 | - * @var string |
|
129 | - */ |
|
125 | + * an other session specific id (md5 from a random string), |
|
126 | + * used together with the sessionid for xmlrpc basic auth and the encryption of session-data (if that's enabled) |
|
127 | + * |
|
128 | + * @var string |
|
129 | + */ |
|
130 | 130 | var $kp3; |
131 | 131 | |
132 | 132 | /** |
@@ -137,17 +137,17 @@ discard block |
||
137 | 137 | var $sessionid_access_log; |
138 | 138 | |
139 | 139 | /** |
140 | - * name of XML-RPC/SOAP method called |
|
141 | - * |
|
142 | - * @var string |
|
143 | - */ |
|
140 | + * name of XML-RPC/SOAP method called |
|
141 | + * |
|
142 | + * @var string |
|
143 | + */ |
|
144 | 144 | var $xmlrpc_method_called; |
145 | 145 | |
146 | 146 | /** |
147 | - * Array with the name of the system domains |
|
148 | - * |
|
149 | - * @var array |
|
150 | - */ |
|
147 | + * Array with the name of the system domains |
|
148 | + * |
|
149 | + * @var array |
|
150 | + */ |
|
151 | 151 | private $egw_domains; |
152 | 152 | |
153 | 153 | /** |
@@ -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 | /** |
@@ -687,14 +687,14 @@ discard block |
||
687 | 687 | const FALSE_ID_CACHE_PREFIX = 'false_id-'; |
688 | 688 | |
689 | 689 | /** |
690 | - * Write or update (for logout) the access_log |
|
691 | - * |
|
692 | - * @param string|int $sessionid nummeric or PHP session id or error-message for unsuccessful logins |
|
693 | - * @param string $login ='' account_lid (evtl. with domain) or '' for setting the logout-time |
|
694 | - * @param string $user_ip ='' ip to log |
|
695 | - * @param int $account_id =0 numerical account_id |
|
696 | - * @return int $sessionid primary key of egw_access_log for login, null otherwise |
|
697 | - */ |
|
690 | + * Write or update (for logout) the access_log |
|
691 | + * |
|
692 | + * @param string|int $sessionid nummeric or PHP session id or error-message for unsuccessful logins |
|
693 | + * @param string $login ='' account_lid (evtl. with domain) or '' for setting the logout-time |
|
694 | + * @param string $user_ip ='' ip to log |
|
695 | + * @param int $account_id =0 numerical account_id |
|
696 | + * @return int $sessionid primary key of egw_access_log for login, null otherwise |
|
697 | + */ |
|
698 | 698 | private function log_access($sessionid,$login='',$user_ip='',$account_id=0) |
699 | 699 | { |
700 | 700 | $now = time(); |
@@ -761,7 +761,7 @@ discard block |
||
761 | 761 | |
762 | 762 | /** |
763 | 763 | * Protect against brute force attacks, block login if too many unsuccessful login attmepts |
764 | - * |
|
764 | + * |
|
765 | 765 | * @param string $login account_lid (evtl. with domain) |
766 | 766 | * @param string $ip ip of the user |
767 | 767 | * @returns bool login blocked? |
@@ -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 | $id = isset($data[$this->autoinc_id]) ? $data[$this->autoinc_id] : $data[$this->db_key_cols[$this->autoinc_id]]; |
@@ -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])) |
@@ -224,7 +244,10 @@ discard block |
||
224 | 244 | |
225 | 245 | foreach (array_keys((array)$this->customfields) as $name) |
226 | 246 | { |
227 | - if (!isset($data[$field = $this->get_cf_field($name)])) continue; |
|
247 | + if (!isset($data[$field = $this->get_cf_field($name)])) |
|
248 | + { |
|
249 | + continue; |
|
250 | + } |
|
228 | 251 | |
229 | 252 | $where = array( |
230 | 253 | $this->extra_id => $id, |
@@ -236,7 +259,11 @@ discard block |
||
236 | 259 | if(empty($data[$field]) || $is_multiple || !$this->extra_has_unique_index) |
237 | 260 | { |
238 | 261 | $this->db->delete($this->extra_table,$where,__LINE__,__FILE__,$this->app); |
239 | - if (empty($data[$field])) continue; // nothing else to do for empty values |
|
262 | + if (empty($data[$field])) |
|
263 | + { |
|
264 | + continue; |
|
265 | + } |
|
266 | + // nothing else to do for empty values |
|
240 | 267 | } |
241 | 268 | foreach($is_multiple && !is_array($data[$field]) ? explode(',',$data[$field]) : |
242 | 269 | // regular custom fields (!$is_multiple) eg. addressbook store multiple values comma-separated |
@@ -309,9 +336,12 @@ discard block |
||
309 | 336 | */ |
310 | 337 | function save($keys=null,$extra_where=null) |
311 | 338 | { |
312 | - if (is_array($keys) && count($keys) && !isset($keys[0])) // allow to use an etag, eg array('etag=etag+1') |
|
339 | + if (is_array($keys) && count($keys) && !isset($keys[0])) |
|
340 | + { |
|
341 | + // allow to use an etag, eg array('etag=etag+1') |
|
313 | 342 | { |
314 | 343 | $this->data_merge($keys); |
344 | + } |
|
315 | 345 | $keys = null; |
316 | 346 | } |
317 | 347 | $ret = parent::save($keys,$extra_where); |
@@ -344,13 +374,20 @@ discard block |
||
344 | 374 | { |
345 | 375 | $ids[] = $row[$this->autoinc_id]; |
346 | 376 | } |
347 | - if (!$ids) return 0; // no rows affected |
|
377 | + if (!$ids) |
|
378 | + { |
|
379 | + return 0; |
|
380 | + } |
|
381 | + // no rows affected |
|
348 | 382 | } |
349 | 383 | else |
350 | 384 | { |
351 | 385 | $ids = (array)$query[$this->autoinc_id]; |
352 | 386 | } |
353 | - if ($only_return_ids) return $ids; |
|
387 | + if ($only_return_ids) |
|
388 | + { |
|
389 | + return $ids; |
|
390 | + } |
|
354 | 391 | $this->db->delete($this->extra_table,array($this->extra_id => $ids),__LINE__,__FILE__); |
355 | 392 | } |
356 | 393 | return parent::delete($keys); |
@@ -392,7 +429,10 @@ discard block |
||
392 | 429 | { |
393 | 430 | foreach($selectcols as $col) |
394 | 431 | { |
395 | - if ($this->is_cf($col)) $fields[] = $this->get_cf_name($col); |
|
432 | + if ($this->is_cf($col)) |
|
433 | + { |
|
434 | + $fields[] = $this->get_cf_name($col); |
|
435 | + } |
|
396 | 436 | } |
397 | 437 | } |
398 | 438 | if (($cfs = $this->read_customfields(array_keys($id2keys),$fields))) |
@@ -515,7 +555,10 @@ discard block |
||
515 | 555 | } |
516 | 556 | } |
517 | 557 | } |
518 | - if ($cfcriteria && $op =='OR') $criteria[] = implode(' OR ',$cfcriteria); |
|
558 | + if ($cfcriteria && $op =='OR') |
|
559 | + { |
|
560 | + $criteria[] = implode(' OR ',$cfcriteria); |
|
561 | + } |
|
519 | 562 | } |
520 | 563 | if($only_keys === true) |
521 | 564 | { |
@@ -617,11 +660,14 @@ discard block |
||
617 | 660 | unset($filter[$name]); |
618 | 661 | continue; // ignore unavailable CF |
619 | 662 | } |
620 | - if (!empty($val)) // empty -> dont filter |
|
663 | + if (!empty($val)) |
|
664 | + { |
|
665 | + // empty -> dont filter |
|
621 | 666 | { |
622 | 667 | if ($val[0] === '!') // negative filter |
623 | 668 | { |
624 | 669 | $sql_filter = 'extra_filter.'.$this->extra_value.'!='.$this->db->quote(substr($val,1)); |
670 | + } |
|
625 | 671 | } |
626 | 672 | else // using Db::expression to allow to use array() with possible values or NULL |
627 | 673 | { |
@@ -658,9 +704,12 @@ discard block |
||
658 | 704 | } |
659 | 705 | unset($filter[$name]); |
660 | 706 | } |
661 | - elseif(is_int($name) && $this->is_cf($val)) // lettersearch: #cfname LIKE 's%' |
|
707 | + elseif(is_int($name) && $this->is_cf($val)) |
|
708 | + { |
|
709 | + // lettersearch: #cfname LIKE 's%' |
|
662 | 710 | { |
663 | 711 | $_cf = explode(' ',$val); |
712 | + } |
|
664 | 713 | foreach($_cf as $cf_np) |
665 | 714 | { |
666 | 715 | // building cf_name by glueing parts together (, in case someone used whitespace in their custom field names) |
@@ -675,7 +724,11 @@ discard block |
||
675 | 724 | } |
676 | 725 | unset($filter[$name]); |
677 | 726 | $cf_name = $this->get_cf_name($cf); |
678 | - if (!isset($this->customfields[$cf_name])) continue; // ignore unavailable CF |
|
727 | + if (!isset($this->customfields[$cf_name])) |
|
728 | + { |
|
729 | + continue; |
|
730 | + } |
|
731 | + // ignore unavailable CF |
|
679 | 732 | $join .= str_replace('extra_filter','extra_filter'.$extra_filter,$this->extra_join_filter. |
680 | 733 | ' AND extra_filter.'.$this->extra_key.'='.$this->db->quote($cf_name). |
681 | 734 | ' AND '.str_replace($cf,'extra_filter.'.$this->extra_value,$val)); |
@@ -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 | $id = isset($data[$this->autoinc_id]) ? $data[$this->autoinc_id] : $data[$this->db_key_cols[$this->autoinc_id]]; |
222 | 222 | |
@@ -233,22 +233,21 @@ discard block |
||
233 | 233 | $is_multiple = $this->is_multiple($name); |
234 | 234 | |
235 | 235 | // we explicitly need to delete fields, if value is empty or field allows multiple values or we have no unique index |
236 | - if(empty($data[$field]) || $is_multiple || !$this->extra_has_unique_index) |
|
236 | + if (empty($data[$field]) || $is_multiple || !$this->extra_has_unique_index) |
|
237 | 237 | { |
238 | - $this->db->delete($this->extra_table,$where,__LINE__,__FILE__,$this->app); |
|
239 | - if (empty($data[$field])) continue; // nothing else to do for empty values |
|
238 | + $this->db->delete($this->extra_table, $where, __LINE__, __FILE__, $this->app); |
|
239 | + if (empty($data[$field])) continue; // nothing else to do for empty values |
|
240 | 240 | } |
241 | - foreach($is_multiple && !is_array($data[$field]) ? explode(',',$data[$field]) : |
|
242 | - // regular custom fields (!$is_multiple) eg. addressbook store multiple values comma-separated |
|
241 | + foreach ($is_multiple && !is_array($data[$field]) ? explode(',', $data[$field]) : // regular custom fields (!$is_multiple) eg. addressbook store multiple values comma-separated |
|
243 | 242 | (array)(!$is_multiple && is_array($data[$field]) ? implode(',', $data[$field]) : $data[$field]) as $value) |
244 | 243 | { |
245 | - if (!$this->db->insert($this->extra_table,array($this->extra_value => $value)+$extra_cols,$where,__LINE__,__FILE__,$this->app)) |
|
244 | + if (!$this->db->insert($this->extra_table, array($this->extra_value => $value) + $extra_cols, $where, __LINE__, __FILE__, $this->app)) |
|
246 | 245 | { |
247 | 246 | return $this->db->Errno; |
248 | 247 | } |
249 | 248 | } |
250 | 249 | } |
251 | - return false; // no error |
|
250 | + return false; // no error |
|
252 | 251 | } |
253 | 252 | |
254 | 253 | /** |
@@ -264,7 +263,7 @@ discard block |
||
264 | 263 | |
265 | 264 | if ($this->customfields) |
266 | 265 | { |
267 | - foreach(array_keys($this->customfields) as $name) |
|
266 | + foreach (array_keys($this->customfields) as $name) |
|
268 | 267 | { |
269 | 268 | if (isset($new[$field = $this->get_cf_field($name)])) |
270 | 269 | { |
@@ -284,16 +283,16 @@ discard block |
||
284 | 283 | * @param string $join sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or |
285 | 284 | * @return array|boolean data if row could be retrived else False |
286 | 285 | */ |
287 | - function read($keys,$extra_cols='',$join='') |
|
286 | + function read($keys, $extra_cols = '', $join = '') |
|
288 | 287 | { |
289 | - if (!parent::read($keys,$extra_cols,$join)) |
|
288 | + if (!parent::read($keys, $extra_cols, $join)) |
|
290 | 289 | { |
291 | 290 | return false; |
292 | 291 | } |
293 | 292 | if (($id = (int)$this->data[$this->db_key_cols[$this->autoinc_id]]) && $this->customfields && |
294 | 293 | ($cfs = $this->read_customfields($id))) |
295 | 294 | { |
296 | - $this->data = array_merge($this->data,$cfs[$id]); |
|
295 | + $this->data = array_merge($this->data, $cfs[$id]); |
|
297 | 296 | } |
298 | 297 | return $this->data; |
299 | 298 | } |
@@ -307,14 +306,14 @@ discard block |
||
307 | 306 | * @param string|array $extra_where =null extra where clause, eg. to check an etag, returns true if no affected rows! |
308 | 307 | * @return int|boolean 0 on success, or errno != 0 on error, or true if $extra_where is given and no rows affected |
309 | 308 | */ |
310 | - function save($keys=null,$extra_where=null) |
|
309 | + function save($keys = null, $extra_where = null) |
|
311 | 310 | { |
312 | 311 | if (is_array($keys) && count($keys) && !isset($keys[0])) // allow to use an etag, eg array('etag=etag+1') |
313 | 312 | { |
314 | 313 | $this->data_merge($keys); |
315 | 314 | $keys = null; |
316 | 315 | } |
317 | - $ret = parent::save($keys,$extra_where); |
|
316 | + $ret = parent::save($keys, $extra_where); |
|
318 | 317 | |
319 | 318 | if ($ret == 0 && $this->customfields) |
320 | 319 | { |
@@ -332,26 +331,26 @@ discard block |
||
332 | 331 | * @param boolean $only_return_ids =false return $ids of delete call to db object, but not run it (can be used by extending classes!) |
333 | 332 | * @return int|array affected rows, should be 1 if ok, 0 if an error or array with id's if $only_return_ids |
334 | 333 | */ |
335 | - function delete($keys=null,$only_return_ids=false) |
|
334 | + function delete($keys = null, $only_return_ids = false) |
|
336 | 335 | { |
337 | 336 | if ($this->customfields || $only_return_ids) |
338 | 337 | { |
339 | - $query = parent::delete($keys,true); |
|
338 | + $query = parent::delete($keys, true); |
|
340 | 339 | // check if query contains more then the id's |
341 | 340 | if (!isset($query[$this->autoinc_id]) || count($query) != 1) |
342 | 341 | { |
343 | - foreach($this->db->select($this->table_name,$this->autoinc_id,$query,__LINE__,__FILE__,false,'',$this->app) as $row) |
|
342 | + foreach ($this->db->select($this->table_name, $this->autoinc_id, $query, __LINE__, __FILE__, false, '', $this->app) as $row) |
|
344 | 343 | { |
345 | 344 | $ids[] = $row[$this->autoinc_id]; |
346 | 345 | } |
347 | - if (!$ids) return 0; // no rows affected |
|
346 | + if (!$ids) return 0; // no rows affected |
|
348 | 347 | } |
349 | 348 | else |
350 | 349 | { |
351 | 350 | $ids = (array)$query[$this->autoinc_id]; |
352 | 351 | } |
353 | 352 | if ($only_return_ids) return $ids; |
354 | - $this->db->delete($this->extra_table,array($this->extra_id => $ids),__LINE__,__FILE__); |
|
353 | + $this->db->delete($this->extra_table, array($this->extra_id => $ids), __LINE__, __FILE__); |
|
355 | 354 | } |
356 | 355 | return parent::delete($keys); |
357 | 356 | } |
@@ -374,32 +373,32 @@ discard block |
||
374 | 373 | * @param string|array $extra_cols =array() |
375 | 374 | * @return int total number of rows |
376 | 375 | */ |
377 | - function get_rows($query,&$rows,&$readonlys,$join='',$need_full_no_count=false,$only_keys=false,$extra_cols=array()) |
|
376 | + function get_rows($query, &$rows, &$readonlys, $join = '', $need_full_no_count = false, $only_keys = false, $extra_cols = array()) |
|
378 | 377 | { |
379 | - parent::get_rows($query,$rows,$readonlys,$join,$need_full_no_count,$only_keys,$extra_cols); |
|
378 | + parent::get_rows($query, $rows, $readonlys, $join, $need_full_no_count, $only_keys, $extra_cols); |
|
380 | 379 | |
381 | - $selectcols = $query['selectcols'] ? explode(',',$query['selectcols']) : array(); |
|
380 | + $selectcols = $query['selectcols'] ? explode(',', $query['selectcols']) : array(); |
|
382 | 381 | |
383 | - if ($rows && $this->customfields && (!$selectcols || in_array('customfields',$selectcols))) |
|
382 | + if ($rows && $this->customfields && (!$selectcols || in_array('customfields', $selectcols))) |
|
384 | 383 | { |
385 | 384 | $id2keys = array(); |
386 | - foreach($rows as $key => $row) |
|
385 | + foreach ($rows as $key => $row) |
|
387 | 386 | { |
388 | 387 | $id2keys[$row[$this->db_key_cols[$this->autoinc_id]]] = $key; |
389 | 388 | } |
390 | 389 | // check if only certain cf's to show |
391 | 390 | if (!in_array('customfields', $selectcols)) |
392 | 391 | { |
393 | - foreach($selectcols as $col) |
|
392 | + foreach ($selectcols as $col) |
|
394 | 393 | { |
395 | 394 | if ($this->is_cf($col)) $fields[] = $this->get_cf_name($col); |
396 | 395 | } |
397 | 396 | } |
398 | - if (($cfs = $this->read_customfields(array_keys($id2keys),$fields))) |
|
397 | + if (($cfs = $this->read_customfields(array_keys($id2keys), $fields))) |
|
399 | 398 | { |
400 | - foreach($cfs as $id => $data) |
|
399 | + foreach ($cfs as $id => $data) |
|
401 | 400 | { |
402 | - $rows[$id2keys[$id]] = array_merge($rows[$id2keys[$id]],$data); |
|
401 | + $rows[$id2keys[$id]] = array_merge($rows[$id2keys[$id]], $data); |
|
403 | 402 | } |
404 | 403 | } |
405 | 404 | } |
@@ -426,7 +425,7 @@ discard block |
||
426 | 425 | * @param boolean $need_full_no_count =false If true an unlimited query is run to determine the total number of rows, default false |
427 | 426 | * @return array|NULL array of matching rows (the row is an array of the cols) or NULL |
428 | 427 | */ |
429 | - function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false) |
|
428 | + function &search($criteria, $only_keys = True, $order_by = '', $extra_cols = '', $wildcard = '', $empty = False, $op = 'AND', $start = false, $filter = null, $join = '', $need_full_no_count = false) |
|
430 | 429 | { |
431 | 430 | //error_log(__METHOD__.'('.array2string(array_combine(array_slice(array('criteria','only_keys','order_by','extra_cols','wildcard','empty','op','start','filter','join','need_full_no_count'), 0, count(func_get_args())), func_get_args())).')'); |
432 | 431 | |
@@ -434,7 +433,7 @@ discard block |
||
434 | 433 | if (!$this->customfields && strpos($order_by, self::CF_PREFIX) === false && |
435 | 434 | (empty($filter) || strpos(implode(',', array_keys($filter)), self::CF_PREFIX) === false)) |
436 | 435 | { |
437 | - return parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count); |
|
436 | + return parent::search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, $start, $filter, $join, $need_full_no_count); |
|
438 | 437 | } |
439 | 438 | if ($only_keys === false) |
440 | 439 | { |
@@ -443,7 +442,7 @@ discard block |
||
443 | 442 | // if string given as criteria --> search in all (or $this->columns_to_search) columns including custom fields |
444 | 443 | if ($criteria && is_string($criteria)) |
445 | 444 | { |
446 | - $criteria = $this->search2criteria($criteria,$wildcard,$op); |
|
445 | + $criteria = $this->search2criteria($criteria, $wildcard, $op); |
|
447 | 446 | } |
448 | 447 | if ($criteria && is_array($criteria)) |
449 | 448 | { |
@@ -453,10 +452,10 @@ discard block |
||
453 | 452 | // we should check if the CF is (still) available, but that makes the slow search even slower :( |
454 | 453 | if (($negate = $criteria[$this->extra_value][0] === '!')) |
455 | 454 | { |
456 | - $criteria[$this->extra_value] = substr($criteria[$this->extra_value],1); |
|
455 | + $criteria[$this->extra_value] = substr($criteria[$this->extra_value], 1); |
|
457 | 456 | } |
458 | - $criteria[] = $this->extra_table.'.'.$this->extra_value . ' ' .($negate ? 'NOT ' : ''). |
|
459 | - $this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE]. ' ' . |
|
457 | + $criteria[] = $this->extra_table.'.'.$this->extra_value.' '.($negate ? 'NOT ' : ''). |
|
458 | + $this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '. |
|
460 | 459 | $this->db->quote($wildcard.$criteria[$this->extra_value].$wildcard); |
461 | 460 | unset($criteria[$this->extra_value]); |
462 | 461 | } |
@@ -465,14 +464,14 @@ discard block |
||
465 | 464 | { |
466 | 465 | if ($criteria[$this->autoinc_id]) |
467 | 466 | { |
468 | - $criteria[] = $this->db->expression($this->table_name,$this->table_name.'.', |
|
467 | + $criteria[] = $this->db->expression($this->table_name, $this->table_name.'.', |
|
469 | 468 | array($this->autoinc_id => $criteria[$this->autoinc_id])); |
470 | 469 | } |
471 | 470 | unset($criteria[$this->autoinc_id]); |
472 | 471 | } |
473 | 472 | // replace ambiguous column with (an exact match of) table_name.column |
474 | 473 | $extra_join_added = $join && strpos($join, $this->extra_join) !== false; |
475 | - foreach($criteria as $name => $val) |
|
474 | + foreach ($criteria as $name => $val) |
|
476 | 475 | { |
477 | 476 | // only add extra_join, if we really need it |
478 | 477 | if (!$extra_join_added && ( |
@@ -484,9 +483,9 @@ discard block |
||
484 | 483 | $extra_join_added = true; |
485 | 484 | } |
486 | 485 | $extra_columns = $this->db->get_table_definitions($this->app, $this->extra_table); |
487 | - if(is_string($name) && $extra_columns['fd'][array_search($name, $this->db_cols)]) |
|
486 | + if (is_string($name) && $extra_columns['fd'][array_search($name, $this->db_cols)]) |
|
488 | 487 | { |
489 | - $criteria[] = $this->db->expression($this->table_name,$this->table_name.'.',array( |
|
488 | + $criteria[] = $this->db->expression($this->table_name, $this->table_name.'.', array( |
|
490 | 489 | array_search($name, $this->db_cols) => $val, |
491 | 490 | )); |
492 | 491 | unset($criteria[$name]); |
@@ -498,12 +497,12 @@ discard block |
||
498 | 497 | $name = substr($name, 1); |
499 | 498 | if (($negate = $criteria[$name][0] === '!')) |
500 | 499 | { |
501 | - $val = substr($val,1); |
|
500 | + $val = substr($val, 1); |
|
502 | 501 | } |
503 | - $cfcriteria[] = '(' . $this->extra_table.'.'.$this->extra_value . ' ' .($negate ? 'NOT ' : ''). |
|
504 | - $this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE]. ' ' . |
|
505 | - $this->db->quote($wildcard.$val.$wildcard) . ' AND ' . |
|
506 | - $this->extra_table.'.'.$this->extra_key . ' = ' . $this->db->quote($name) . |
|
502 | + $cfcriteria[] = '('.$this->extra_table.'.'.$this->extra_value.' '.($negate ? 'NOT ' : ''). |
|
503 | + $this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '. |
|
504 | + $this->db->quote($wildcard.$val.$wildcard).' AND '. |
|
505 | + $this->extra_table.'.'.$this->extra_key.' = '.$this->db->quote($name). |
|
507 | 506 | ')'; |
508 | 507 | unset($criteria[self::CF_PREFIX.$name]); |
509 | 508 | } |
@@ -515,49 +514,49 @@ discard block |
||
515 | 514 | } |
516 | 515 | } |
517 | 516 | } |
518 | - if ($cfcriteria && $op =='OR') $criteria[] = implode(' OR ',$cfcriteria); |
|
517 | + if ($cfcriteria && $op == 'OR') $criteria[] = implode(' OR ', $cfcriteria); |
|
519 | 518 | } |
520 | - if($only_keys === true) |
|
519 | + if ($only_keys === true) |
|
521 | 520 | { |
522 | 521 | // Expand to keys here, so table_name can be prepended below |
523 | 522 | $only_keys = array_values($this->db_key_cols); |
524 | 523 | } |
525 | 524 | // replace ambiguous column with (an exact match of) table_name.column |
526 | - if(is_array($only_keys)) |
|
525 | + if (is_array($only_keys)) |
|
527 | 526 | { |
528 | - foreach($only_keys as $key => &$col) |
|
527 | + foreach ($only_keys as $key => &$col) |
|
529 | 528 | { |
530 | - if(is_numeric($key) && in_array($col, $this->db_cols, true)) |
|
529 | + if (is_numeric($key) && in_array($col, $this->db_cols, true)) |
|
531 | 530 | { |
532 | - $col = $this->table_name .'.'.array_search($col, $this->db_cols).' AS '.$col; |
|
531 | + $col = $this->table_name.'.'.array_search($col, $this->db_cols).' AS '.$col; |
|
533 | 532 | } |
534 | 533 | } |
535 | 534 | } |
536 | 535 | // check if we order by a custom field --> join cf table for given cf and order by it's value |
537 | - if (strpos($order_by,self::CF_PREFIX) !== false) |
|
536 | + if (strpos($order_by, self::CF_PREFIX) !== false) |
|
538 | 537 | { |
539 | 538 | // if $order_by contains more then order by columns (eg. group by) split it off before |
540 | 539 | if (($pos = stripos($order_by, 'order by')) !== false) |
541 | 540 | { |
542 | - $group_by = substr($order_by, 0, $pos+9); |
|
543 | - $order_by = substr($order_by, $pos+9); |
|
541 | + $group_by = substr($order_by, 0, $pos + 9); |
|
542 | + $order_by = substr($order_by, $pos + 9); |
|
544 | 543 | } |
545 | 544 | // fields to order by, as cutomfields may have names with spaces, we examine each order by criteria |
546 | - $fields2order = explode(',',$order_by); |
|
547 | - foreach($fields2order as $v) |
|
545 | + $fields2order = explode(',', $order_by); |
|
546 | + foreach ($fields2order as $v) |
|
548 | 547 | { |
549 | - if (strpos($v,self::CF_PREFIX) !== false) |
|
548 | + if (strpos($v, self::CF_PREFIX) !== false) |
|
550 | 549 | { |
551 | 550 | // we found a customfield, so we split that part by space char in order to get Sorting Direction and Fieldname |
552 | - $buff = explode(' ',trim($v)); |
|
551 | + $buff = explode(' ', trim($v)); |
|
553 | 552 | $orderDir = array_pop($buff); |
554 | - $key = substr(trim(implode(' ',$buff)), 1); |
|
553 | + $key = substr(trim(implode(' ', $buff)), 1); |
|
555 | 554 | if (!isset($this->customfields[$key])) |
556 | 555 | { |
557 | 556 | $order_by = preg_replace('/'.preg_quote($v, '/').',?/', '', $order_by); |
558 | - continue; // ignore unavaiable CF |
|
557 | + continue; // ignore unavaiable CF |
|
559 | 558 | } |
560 | - switch($this->customfields[$key]['type']) |
|
559 | + switch ($this->customfields[$key]['type']) |
|
561 | 560 | { |
562 | 561 | case 'int': |
563 | 562 | $order_by = str_replace($v, 'extra_order.'.$this->extra_value.' IS NULL,'. |
@@ -595,26 +594,26 @@ discard block |
||
595 | 594 | { |
596 | 595 | $_cfnames = array_keys($this->customfields); |
597 | 596 | $extra_filter = null; |
598 | - foreach($filter as $name => $val) |
|
597 | + foreach ($filter as $name => $val) |
|
599 | 598 | { |
600 | 599 | // replace ambiguous auto-id with (an exact match of) table_name.autoid |
601 | 600 | if (is_string($name) && $name == $this->autoinc_id) |
602 | 601 | { |
603 | 602 | if ((int)$filter[$this->autoinc_id]) |
604 | 603 | { |
605 | - $filter[] = $this->db->expression($this->table_name,$this->table_name.'.',array( |
|
604 | + $filter[] = $this->db->expression($this->table_name, $this->table_name.'.', array( |
|
606 | 605 | $this->autoinc_id => $filter[$this->autoinc_id], |
607 | 606 | )); |
608 | 607 | } |
609 | 608 | unset($filter[$this->autoinc_id]); |
610 | 609 | } |
611 | 610 | // replace ambiguous column with (an exact match of) table_name.column |
612 | - elseif (is_string($name) && $val!=null && in_array($name, $this->db_cols)) |
|
611 | + elseif (is_string($name) && $val != null && in_array($name, $this->db_cols)) |
|
613 | 612 | { |
614 | 613 | $extra_columns = $this->db->get_table_definitions($this->app, $this->extra_table); |
615 | 614 | if ($extra_columns['fd'][array_search($name, $this->db_cols)]) |
616 | 615 | { |
617 | - $filter[] = $this->db->expression($this->table_name,$this->table_name.'.',array( |
|
616 | + $filter[] = $this->db->expression($this->table_name, $this->table_name.'.', array( |
|
618 | 617 | array_search($name, $this->db_cols) => $val, |
619 | 618 | )); |
620 | 619 | unset($filter[$name]); |
@@ -626,59 +625,59 @@ discard block |
||
626 | 625 | if (!isset($this->customfields[$cf_name])) |
627 | 626 | { |
628 | 627 | unset($filter[$name]); |
629 | - continue; // ignore unavailable CF |
|
628 | + continue; // ignore unavailable CF |
|
630 | 629 | } |
631 | 630 | if (!empty($val)) // empty -> dont filter |
632 | 631 | { |
633 | 632 | if ($val[0] === '!') // negative filter |
634 | 633 | { |
635 | - $sql_filter = 'extra_filter.'.$this->extra_value.'!='.$this->db->quote(substr($val,1)); |
|
634 | + $sql_filter = 'extra_filter.'.$this->extra_value.'!='.$this->db->quote(substr($val, 1)); |
|
636 | 635 | } |
637 | 636 | else // using Db::expression to allow to use array() with possible values or NULL |
638 | 637 | { |
639 | - if($this->customfields[$cf_name]['type'] == 'select' && |
|
638 | + if ($this->customfields[$cf_name]['type'] == 'select' && |
|
640 | 639 | $this->customfields[$cf_name]['rows'] > 1) |
641 | 640 | { |
642 | 641 | // Multi-select - any entry with the filter value selected matches |
643 | - $sql_filter = str_replace($this->extra_value,'extra_filter.'. |
|
644 | - $this->extra_value,$this->db->expression($this->extra_table,array( |
|
645 | - $this->db->concat("','",$this->extra_value,"','").' '.$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote('%,'.$val.',%') |
|
642 | + $sql_filter = str_replace($this->extra_value, 'extra_filter.'. |
|
643 | + $this->extra_value, $this->db->expression($this->extra_table, array( |
|
644 | + $this->db->concat("','", $this->extra_value, "','").' '.$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote('%,'.$val.',%') |
|
646 | 645 | )) |
647 | 646 | ); |
648 | 647 | } |
649 | 648 | elseif ($this->customfields[$cf_name]['type'] == 'text') |
650 | 649 | { |
651 | - $sql_filter = str_replace($this->extra_value,'extra_filter.'.$this->extra_value, |
|
652 | - $this->db->expression($this->extra_table,array( |
|
650 | + $sql_filter = str_replace($this->extra_value, 'extra_filter.'.$this->extra_value, |
|
651 | + $this->db->expression($this->extra_table, array( |
|
653 | 652 | $this->extra_value.' '.$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote($wildcard.$val.$wildcard) |
654 | 653 | )) |
655 | 654 | ); |
656 | 655 | } |
657 | 656 | else |
658 | 657 | { |
659 | - $sql_filter = str_replace($this->extra_value,'extra_filter.'. |
|
660 | - $this->extra_value,$this->db->expression($this->extra_table,array($this->extra_value => $val))); |
|
658 | + $sql_filter = str_replace($this->extra_value, 'extra_filter.'. |
|
659 | + $this->extra_value, $this->db->expression($this->extra_table, array($this->extra_value => $val))); |
|
661 | 660 | } |
662 | 661 | } |
663 | 662 | // need to use a LEFT JOIN for negative search or to allow NULL values |
664 | - $need_left_join = $val[0] === '!' || strpos($sql_filter,'IS NULL') !== false ? ' LEFT ' : ''; |
|
665 | - $join .= str_replace('extra_filter','extra_filter'.$extra_filter,$need_left_join.$this->extra_join_filter. |
|
663 | + $need_left_join = $val[0] === '!' || strpos($sql_filter, 'IS NULL') !== false ? ' LEFT ' : ''; |
|
664 | + $join .= str_replace('extra_filter', 'extra_filter'.$extra_filter, $need_left_join.$this->extra_join_filter. |
|
666 | 665 | ' AND extra_filter.'.$this->extra_key.'='.$this->db->quote($cf_name). |
667 | 666 | ' AND '.$sql_filter); |
668 | 667 | ++$extra_filter; |
669 | 668 | } |
670 | 669 | unset($filter[$name]); |
671 | 670 | } |
672 | - elseif(is_int($name) && $this->is_cf($val)) // lettersearch: #cfname LIKE 's%' |
|
671 | + elseif (is_int($name) && $this->is_cf($val)) // lettersearch: #cfname LIKE 's%' |
|
673 | 672 | { |
674 | - $_cf = explode(' ',$val); |
|
675 | - foreach($_cf as $cf_np) |
|
673 | + $_cf = explode(' ', $val); |
|
674 | + foreach ($_cf as $cf_np) |
|
676 | 675 | { |
677 | 676 | // building cf_name by glueing parts together (, in case someone used whitespace in their custom field names) |
678 | - $tcf_name = ($tcf_name?$tcf_name.' ':'').$cf_np; |
|
677 | + $tcf_name = ($tcf_name ? $tcf_name.' ' : '').$cf_np; |
|
679 | 678 | // reacts on the first one found that matches an existing customfield, should be better then the old behavior of |
680 | 679 | // simply splitting by " " and using the first part |
681 | - if ($this->is_cf($tcf_name) && ($cfn = $this->get_cf_name($tcf_name)) && array_search($cfn,(array)$_cfnames,true)!==false ) |
|
680 | + if ($this->is_cf($tcf_name) && ($cfn = $this->get_cf_name($tcf_name)) && array_search($cfn, (array)$_cfnames, true) !== false) |
|
682 | 681 | { |
683 | 682 | $cf = $tcf_name; |
684 | 683 | break; |
@@ -686,10 +685,10 @@ discard block |
||
686 | 685 | } |
687 | 686 | unset($filter[$name]); |
688 | 687 | $cf_name = $this->get_cf_name($cf); |
689 | - if (!isset($this->customfields[$cf_name])) continue; // ignore unavailable CF |
|
690 | - $join .= str_replace('extra_filter','extra_filter'.$extra_filter,$this->extra_join_filter. |
|
688 | + if (!isset($this->customfields[$cf_name])) continue; // ignore unavailable CF |
|
689 | + $join .= str_replace('extra_filter', 'extra_filter'.$extra_filter, $this->extra_join_filter. |
|
691 | 690 | ' AND extra_filter.'.$this->extra_key.'='.$this->db->quote($cf_name). |
692 | - ' AND '.str_replace($cf,'extra_filter.'.$this->extra_value,$val)); |
|
691 | + ' AND '.str_replace($cf, 'extra_filter.'.$this->extra_value, $val)); |
|
693 | 692 | ++$extra_filter; |
694 | 693 | } |
695 | 694 | } |
@@ -700,15 +699,14 @@ discard block |
||
700 | 699 | if (is_array($only_keys)) |
701 | 700 | { |
702 | 701 | $only_keys = array_values($only_keys); |
703 | - $only_keys[0] = 'DISTINCT '.($only_keys[0] != $this->autoinc_id ? $only_keys[0] : |
|
704 | - $this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id); |
|
702 | + $only_keys[0] = 'DISTINCT '.($only_keys[0] != $this->autoinc_id ? $only_keys[0] : $this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id); |
|
705 | 703 | } |
706 | 704 | else |
707 | 705 | { |
708 | 706 | $only_keys = 'DISTINCT '.$only_keys; |
709 | 707 | } |
710 | 708 | } |
711 | - return parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count); |
|
709 | + return parent::search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, $start, $filter, $join, $need_full_no_count); |
|
712 | 710 | } |
713 | 711 | |
714 | 712 | /** |
@@ -748,7 +746,7 @@ discard block |
||
748 | 746 | */ |
749 | 747 | function get_cf_name($field) |
750 | 748 | { |
751 | - return substr($field,1); |
|
749 | + return substr($field, 1); |
|
752 | 750 | } |
753 | 751 | |
754 | 752 | /** |
@@ -770,7 +768,7 @@ discard block |
||
770 | 768 | */ |
771 | 769 | function is_multiple($name) |
772 | 770 | { |
773 | - return $this->allow_multiple_values && in_array($this->customfields[$name]['type'],array('select','select-account')) && |
|
771 | + return $this->allow_multiple_values && in_array($this->customfields[$name]['type'], array('select', 'select-account')) && |
|
774 | 772 | $this->customfields[$name]['rows'] > 1; |
775 | 773 | } |
776 | 774 | } |
@@ -112,6 +112,8 @@ |
||
112 | 112 | |
113 | 113 | /** |
114 | 114 | * Static function to add a history record |
115 | + * @param string $field_code |
|
116 | + * @param string $new_value |
|
115 | 117 | */ |
116 | 118 | public static function static_add($appname, $id, $user, $field_code, $new_value, $old_value = '') |
117 | 119 | { |
@@ -142,7 +142,10 @@ discard block |
||
142 | 142 | */ |
143 | 143 | function search($filter,$order='history_id',$sort='DESC',$limit=null) |
144 | 144 | { |
145 | - if (!is_array($filter)) $filter = is_numeric($filter) ? array('history_record_id' => $filter) : array(); |
|
145 | + if (!is_array($filter)) |
|
146 | + { |
|
147 | + $filter = is_numeric($filter) ? array('history_record_id' => $filter) : array(); |
|
148 | + } |
|
146 | 149 | |
147 | 150 | if (!$order || !preg_match('/^[a-z0-9_]+$/i',$order) || !preg_match('/^(asc|desc)?$/i',$sort)) |
148 | 151 | { |
@@ -160,10 +163,16 @@ discard block |
||
160 | 163 | unset($filter[$col]); |
161 | 164 | } |
162 | 165 | } |
163 | - if (!isset($filter['history_appname'])) $filter['history_appname'] = $this->appname; |
|
166 | + if (!isset($filter['history_appname'])) |
|
167 | + { |
|
168 | + $filter['history_appname'] = $this->appname; |
|
169 | + } |
|
164 | 170 | |
165 | 171 | // do not try to read all history entries of an app |
166 | - if (!$filter['history_record_id']) return array(); |
|
172 | + if (!$filter['history_record_id']) |
|
173 | + { |
|
174 | + return array(); |
|
175 | + } |
|
167 | 176 | |
168 | 177 | $rows = array(); |
169 | 178 | foreach($this->db->select(self::TABLE, '*', $filter, __LINE__, __FILE__, |
@@ -188,8 +197,10 @@ discard block |
||
188 | 197 | $rows = array(); |
189 | 198 | $filter['history_appname'] = $query['appname']; |
190 | 199 | $filter['history_record_id'] = $query['record_id']; |
191 | - if(is_array($query['colfilter'])) { |
|
192 | - foreach($query['colfilter'] as $column => $value) { |
|
200 | + if(is_array($query['colfilter'])) |
|
201 | + { |
|
202 | + foreach($query['colfilter'] as $column => $value) |
|
203 | + { |
|
193 | 204 | $filter[$column] = $value; |
194 | 205 | } |
195 | 206 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * @param string $appname app name this instance operates on |
52 | 52 | * @return historylog |
53 | 53 | */ |
54 | - function __construct($appname='',$user=null) |
|
54 | + function __construct($appname = '', $user = null) |
|
55 | 55 | { |
56 | 56 | $this->appname = $appname ? $appname : $GLOBALS['egw_info']['flags']['currentapp']; |
57 | 57 | $this->user = !is_null($user) ? $user : $GLOBALS['egw_info']['user']['account_id']; |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | { |
81 | 81 | $where['history_record_id'] = $record_id; |
82 | 82 | } |
83 | - $this->db->delete(self::TABLE,$where,__LINE__,__FILE__); |
|
83 | + $this->db->delete(self::TABLE, $where, __LINE__, __FILE__); |
|
84 | 84 | |
85 | 85 | return $this->db->affected_rows(); |
86 | 86 | } |
@@ -93,11 +93,11 @@ discard block |
||
93 | 93 | * @param string $new_value new value |
94 | 94 | * @param string $old_value old value |
95 | 95 | */ |
96 | - function add($status,$record_id,$new_value,$old_value) |
|
96 | + function add($status, $record_id, $new_value, $old_value) |
|
97 | 97 | { |
98 | 98 | if ($new_value != $old_value) |
99 | 99 | { |
100 | - $this->db->insert(self::TABLE,array( |
|
100 | + $this->db->insert(self::TABLE, array( |
|
101 | 101 | 'history_record_id' => $record_id, |
102 | 102 | 'history_appname' => $this->appname, |
103 | 103 | 'history_owner' => $this->user, |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | 'history_old_value' => $old_value, |
107 | 107 | 'history_timestamp' => time(), |
108 | 108 | 'sessionid' => $GLOBALS['egw']->session->sessionid_access_log, |
109 | - ),false,__LINE__,__FILE__); |
|
109 | + ), false, __LINE__, __FILE__); |
|
110 | 110 | } |
111 | 111 | } |
112 | 112 | |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | { |
118 | 118 | if ($new_value != $old_value) |
119 | 119 | { |
120 | - $GLOBALS['egw']->db->insert(self::TABLE,array( |
|
120 | + $GLOBALS['egw']->db->insert(self::TABLE, array( |
|
121 | 121 | 'history_record_id' => $id, |
122 | 122 | 'history_appname' => $appname, |
123 | 123 | 'history_owner' => (int)$user, |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | 'history_old_value' => $old_value, |
127 | 127 | 'history_timestamp' => time(), |
128 | 128 | 'sessionid' => $GLOBALS['egw']->session->sessionid_access_log, |
129 | - ),false,__LINE__,__FILE__); |
|
129 | + ), false, __LINE__, __FILE__); |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
@@ -140,11 +140,11 @@ discard block |
||
140 | 140 | * @return array of arrays with keys id, record_id, appname, owner (account_id), status, new_value, old_value, |
141 | 141 | * timestamp (Y-m-d H:i:s in servertime), user_ts (timestamp in user-time) |
142 | 142 | */ |
143 | - function search($filter,$order='history_id',$sort='DESC',$limit=null) |
|
143 | + function search($filter, $order = 'history_id', $sort = 'DESC', $limit = null) |
|
144 | 144 | { |
145 | 145 | if (!is_array($filter)) $filter = is_numeric($filter) ? array('history_record_id' => $filter) : array(); |
146 | 146 | |
147 | - if (!$order || !preg_match('/^[a-z0-9_]+$/i',$order) || !preg_match('/^(asc|desc)?$/i',$sort)) |
|
147 | + if (!$order || !preg_match('/^[a-z0-9_]+$/i', $order) || !preg_match('/^(asc|desc)?$/i', $sort)) |
|
148 | 148 | { |
149 | 149 | $orderby = 'ORDER BY history_id DESC'; |
150 | 150 | } |
@@ -152,9 +152,9 @@ discard block |
||
152 | 152 | { |
153 | 153 | $orderby = "ORDER BY $order $sort"; |
154 | 154 | } |
155 | - foreach($filter as $col => $value) |
|
155 | + foreach ($filter as $col => $value) |
|
156 | 156 | { |
157 | - if (!is_numeric($col) && substr($col,0,8) != 'history_') |
|
157 | + if (!is_numeric($col) && substr($col, 0, 8) != 'history_') |
|
158 | 158 | { |
159 | 159 | $filter['history_'.$col] = $value; |
160 | 160 | unset($filter[$col]); |
@@ -166,11 +166,11 @@ discard block |
||
166 | 166 | if (!$filter['history_record_id']) return array(); |
167 | 167 | |
168 | 168 | $rows = array(); |
169 | - foreach($this->db->select(self::TABLE, '*', $filter, __LINE__, __FILE__, |
|
169 | + foreach ($this->db->select(self::TABLE, '*', $filter, __LINE__, __FILE__, |
|
170 | 170 | isset($limit) ? 0 : false, $orderby, 'phpgwapi', $limit) as $row) |
171 | 171 | { |
172 | 172 | $row['user_ts'] = $this->db->from_timestamp($row['history_timestamp']) + 3600 * $GLOBALS['egw_info']['user']['preferences']['common']['tz_offset']; |
173 | - $rows[] = Api\Db::strip_array_keys($row,'history_'); |
|
173 | + $rows[] = Api\Db::strip_array_keys($row, 'history_'); |
|
174 | 174 | } |
175 | 175 | return $rows; |
176 | 176 | } |
@@ -188,8 +188,8 @@ discard block |
||
188 | 188 | $rows = array(); |
189 | 189 | $filter['history_appname'] = $query['appname']; |
190 | 190 | $filter['history_record_id'] = $query['record_id']; |
191 | - if(is_array($query['colfilter'])) { |
|
192 | - foreach($query['colfilter'] as $column => $value) { |
|
191 | + if (is_array($query['colfilter'])) { |
|
192 | + foreach ($query['colfilter'] as $column => $value) { |
|
193 | 193 | $filter[$column] = $value; |
194 | 194 | } |
195 | 195 | } |
@@ -199,20 +199,20 @@ discard block |
||
199 | 199 | } |
200 | 200 | else |
201 | 201 | { |
202 | - $total = $GLOBALS['egw']->db->select(self::TABLE,'COUNT(*)',$filter,__LINE__,__FILE__,false,'','phpgwapi',0)->fetchColumn(); |
|
202 | + $total = $GLOBALS['egw']->db->select(self::TABLE, 'COUNT(*)', $filter, __LINE__, __FILE__, false, '', 'phpgwapi', 0)->fetchColumn(); |
|
203 | 203 | } |
204 | 204 | // filter out private (or no longer defined) custom fields |
205 | 205 | if ($filter['history_appname']) |
206 | 206 | { |
207 | 207 | $to_or[] = "history_status NOT LIKE '#%'"; |
208 | 208 | // explicitly allow "##" used to store iCal/vCard X-attributes |
209 | - if (in_array($filter['history_appname'], array('calendar','infolog','addressbook'))) |
|
209 | + if (in_array($filter['history_appname'], array('calendar', 'infolog', 'addressbook'))) |
|
210 | 210 | { |
211 | 211 | $to_or[] = "history_status LIKE '##%'"; |
212 | 212 | } |
213 | 213 | if (($cfs = Customfields::get($filter['history_appname']))) |
214 | 214 | { |
215 | - $to_or[] = 'history_status IN ('.implode(',', array_map(function($str) |
|
215 | + $to_or[] = 'history_status IN ('.implode(',', array_map(function($str) |
|
216 | 216 | { |
217 | 217 | return $GLOBALS['egw']->db->quote('#'.$str); |
218 | 218 | }, array_keys($cfs))).')'; |
@@ -221,26 +221,26 @@ discard block |
||
221 | 221 | } |
222 | 222 | $_query = array(array( |
223 | 223 | 'table' => self::TABLE, |
224 | - 'cols' => array('history_id', 'history_record_id','history_appname','history_owner','history_status','history_new_value', 'history_timestamp','history_old_value'), |
|
224 | + 'cols' => array('history_id', 'history_record_id', 'history_appname', 'history_owner', 'history_status', 'history_new_value', 'history_timestamp', 'history_old_value'), |
|
225 | 225 | 'where' => $filter, |
226 | 226 | )); |
227 | 227 | |
228 | 228 | // Add in files, if possible |
229 | - if($GLOBALS['egw_info']['user']['apps']['filemanager'] && |
|
229 | + if ($GLOBALS['egw_info']['user']['apps']['filemanager'] && |
|
230 | 230 | ($sqlfs_sw = new Api\Vfs\Sqlfs\StreamWrapper()) && |
231 | - ($file = $sqlfs_sw->url_stat("/apps/{$query['appname']}/{$query['record_id']}",STREAM_URL_STAT_LINK))) |
|
231 | + ($file = $sqlfs_sw->url_stat("/apps/{$query['appname']}/{$query['record_id']}", STREAM_URL_STAT_LINK))) |
|
232 | 232 | { |
233 | 233 | $_query[] = array( |
234 | 234 | 'table' => Api\Vfs\Sqlfs\StreamWrapper::TABLE, |
235 | - 'cols' =>array('fs_id', 'fs_dir', "'filemanager'",'COALESCE(fs_modifier,fs_creator)',"'~file~'",'fs_name','fs_modified', 'fs_mime'), |
|
235 | + 'cols' =>array('fs_id', 'fs_dir', "'filemanager'", 'COALESCE(fs_modifier,fs_creator)', "'~file~'", 'fs_name', 'fs_modified', 'fs_mime'), |
|
236 | 236 | 'where' => array('fs_dir' => $file['ino']) |
237 | 237 | ); |
238 | 238 | } |
239 | 239 | $new_file_id = array(); |
240 | - foreach($GLOBALS['egw']->db->union( |
|
240 | + foreach ($GLOBALS['egw']->db->union( |
|
241 | 241 | $_query, |
242 | 242 | __LINE__, __FILE__, |
243 | - ' ORDER BY ' . ($query['order'] ? $query['order'] : 'history_timestamp') . ' ' . ($query['sort'] ? $query['sort'] : 'DESC'), |
|
243 | + ' ORDER BY '.($query['order'] ? $query['order'] : 'history_timestamp').' '.($query['sort'] ? $query['sort'] : 'DESC'), |
|
244 | 244 | $query['start'], |
245 | 245 | $query['num_rows'] |
246 | 246 | ) as $row) |
@@ -248,15 +248,15 @@ discard block |
||
248 | 248 | $row['user_ts'] = $GLOBALS['egw']->db->from_timestamp($row['history_timestamp']) + 3600 * $GLOBALS['egw_info']['user']['preferences']['common']['tz_offset']; |
249 | 249 | |
250 | 250 | // Explode multi-part values |
251 | - foreach(array('history_new_value','history_old_value') as $field) |
|
251 | + foreach (array('history_new_value', 'history_old_value') as $field) |
|
252 | 252 | { |
253 | - if(strpos($row[$field],Tracking::ONE2N_SEPERATOR) !== false) |
|
253 | + if (strpos($row[$field], Tracking::ONE2N_SEPERATOR) !== false) |
|
254 | 254 | { |
255 | - $row[$field] = explode(Tracking::ONE2N_SEPERATOR,$row[$field]); |
|
255 | + $row[$field] = explode(Tracking::ONE2N_SEPERATOR, $row[$field]); |
|
256 | 256 | } |
257 | 257 | } |
258 | 258 | // Get information needed for proper display |
259 | - if($row['history_appname'] == 'filemanager') |
|
259 | + if ($row['history_appname'] == 'filemanager') |
|
260 | 260 | { |
261 | 261 | $new_version = $new_file_id[$row['history_new_value']]; |
262 | 262 | $new_file_id[$row['history_new_value']] = count($rows); |
@@ -272,14 +272,14 @@ discard block |
||
272 | 272 | 'mime' => $row['history_old_value'] |
273 | 273 | ); |
274 | 274 | $row['history_old_value'] = ''; |
275 | - if($new_version !== null) |
|
275 | + if ($new_version !== null) |
|
276 | 276 | { |
277 | 277 | $rows[$new_version]['old_value'] = $row['history_new_value']; |
278 | 278 | } |
279 | 279 | } |
280 | - $rows[] = Api\Db::strip_array_keys($row,'history_'); |
|
280 | + $rows[] = Api\Db::strip_array_keys($row, 'history_'); |
|
281 | 281 | } |
282 | - $total = $GLOBALS['egw']->db->union($_query,__LINE__,__FILE__)->NumRows(); |
|
282 | + $total = $GLOBALS['egw']->db->union($_query, __LINE__, __FILE__)->NumRows(); |
|
283 | 283 | |
284 | 284 | return $total; |
285 | 285 | } |
@@ -528,7 +528,7 @@ discard block |
||
528 | 528 | * @param array $data current entry |
529 | 529 | * @param array $old = null old/last state of the entry or null for a new entry |
530 | 530 | * @param boolean $deleted = null can be set to true to let the tracking know the item got deleted or undelted |
531 | - * @param array $email_notified=null if present will return the emails notified, if given emails in that list will not be notified |
|
531 | + * @param array $email_notified if present will return the emails notified, if given emails in that list will not be notified |
|
532 | 532 | * @return boolean true on success, false on error (error messages are in $this->errors) |
533 | 533 | */ |
534 | 534 | public function do_notifications($data,$old,$deleted=null,&$email_notified=null) |
@@ -824,7 +824,6 @@ discard block |
||
824 | 824 | * The default implementation prefers depending on the prefer_user_as_sender class-var the user over |
825 | 825 | * what is returned by get_config('sender'). |
826 | 826 | * |
827 | - * @param int $user account_lid of user |
|
828 | 827 | * @param array $data |
829 | 828 | * @param array $old |
830 | 829 | * @param bool $prefer_id returns the userid rather than email |
@@ -260,11 +260,17 @@ discard block |
||
260 | 260 | $header_done = false; |
261 | 261 | foreach($cfs as $name => $field) |
262 | 262 | { |
263 | - if (in_array($field['type'], Customfields::$non_printable_fields)) continue; |
|
263 | + if (in_array($field['type'], Customfields::$non_printable_fields)) |
|
264 | + { |
|
265 | + continue; |
|
266 | + } |
|
264 | 267 | |
265 | 268 | // Sometimes cached customfields let private fields the user can access |
266 | 269 | // leak through. If no specific user provided, make sure we don't expose them. |
267 | - if ($user === false && $field['private']) continue; |
|
270 | + if ($user === false && $field['private']) |
|
271 | + { |
|
272 | + continue; |
|
273 | + } |
|
268 | 274 | |
269 | 275 | if (!$header_done) |
270 | 276 | { |
@@ -362,8 +368,14 @@ discard block |
||
362 | 368 | { |
363 | 369 | //error_log(__METHOD__.__LINE__.' Field:'.$name. ' Value (new):'.array2string($data[$name])); |
364 | 370 | //error_log(__METHOD__.__LINE__.' Field:'.$name. ' Value (old):'.array2string($old[$name])); |
365 | - if (is_array($data[$name]) && array_key_exists('id',$data[$name])) $data[$name] = $data[$name]['id']; |
|
366 | - if (is_array($old[$name]) && array_key_exists('id',$old[$name])) $old[$name] = $old[$name]['id']; |
|
371 | + if (is_array($data[$name]) && array_key_exists('id',$data[$name])) |
|
372 | + { |
|
373 | + $data[$name] = $data[$name]['id']; |
|
374 | + } |
|
375 | + if (is_array($old[$name]) && array_key_exists('id',$old[$name])) |
|
376 | + { |
|
377 | + $old[$name] = $old[$name]['id']; |
|
378 | + } |
|
367 | 379 | //error_log(__METHOD__.__LINE__.'(After processing) Field:'.$name. ' Value (new):'.array2string($data[$name])); |
368 | 380 | //error_log(__METHOD__.__LINE__.'(After processing) Field:'.$name. ' Value (old):'.array2string($old[$name])); |
369 | 381 | } |
@@ -377,11 +389,18 @@ discard block |
||
377 | 389 | if (!($app = $this->cf_link_fields[$name])) |
378 | 390 | { |
379 | 391 | list($app,$id) = explode(':',$id); |
380 | - if (!$id) continue; // can be eg. 'addressbook:', if no contact selected |
|
392 | + if (!$id) |
|
393 | + { |
|
394 | + continue; |
|
395 | + } |
|
396 | + // can be eg. 'addressbook:', if no contact selected |
|
381 | 397 | } |
382 | 398 | $source_id = $data[$this->id_field]; |
383 | 399 | //error_log(__METHOD__.__LINE__.array2string($source_id)); |
384 | - if ($source_id) Api\Link::link($this->app,$source_id,$app,$id); |
|
400 | + if ($source_id) |
|
401 | + { |
|
402 | + Api\Link::link($this->app,$source_id,$app,$id); |
|
403 | + } |
|
385 | 404 | //error_log(__METHOD__.__LINE__."Api\Link::link('$this->app',".array2string($source_id).",'$app',$id);"); |
386 | 405 | //echo "<p>Api\Link::link('$this->app',{$data[$this->id_field]},'$app',$id);</p>\n"; |
387 | 406 | } |
@@ -389,14 +408,24 @@ discard block |
||
389 | 408 | // unlink removed application entries |
390 | 409 | foreach(array_diff($old_ids,$current_ids) as $name => $id) |
391 | 410 | { |
392 | - if (!isset($data[$name])) continue; // ignore not set link cf's, eg. from sync clients |
|
411 | + if (!isset($data[$name])) |
|
412 | + { |
|
413 | + continue; |
|
414 | + } |
|
415 | + // ignore not set link cf's, eg. from sync clients |
|
393 | 416 | if (!($app = $this->cf_link_fields[$name])) |
394 | 417 | { |
395 | 418 | list($app,$id) = explode(':',$id); |
396 | - if (!$id) continue; |
|
419 | + if (!$id) |
|
420 | + { |
|
421 | + continue; |
|
422 | + } |
|
397 | 423 | } |
398 | 424 | $source_id = $data[$this->id_field]; |
399 | - if ($source_id) Api\Link::unlink(null,$this->app,$source_id,0,$app,$id); |
|
425 | + if ($source_id) |
|
426 | + { |
|
427 | + Api\Link::unlink(null,$this->app,$source_id,0,$app,$id); |
|
428 | + } |
|
400 | 429 | //echo "<p>Api\Link::unlink(NULL,'$this->app',{$data[$this->id_field]},0,'$app',$id);</p>\n"; |
401 | 430 | } |
402 | 431 | } |
@@ -421,7 +450,10 @@ discard block |
||
421 | 450 | $changed_fields = self::changed_fields($data,$old); |
422 | 451 | //error_log(__METHOD__.__LINE__.' Changedfields:'.array2string($changed_fields)); |
423 | 452 | } |
424 | - if (!$changed_fields && ($old || !$GLOBALS['egw_info']['server']['log_user_agent_action'])) return 0; |
|
453 | + if (!$changed_fields && ($old || !$GLOBALS['egw_info']['server']['log_user_agent_action'])) |
|
454 | + { |
|
455 | + return 0; |
|
456 | + } |
|
425 | 457 | |
426 | 458 | if (!is_object($this->historylog) || $this->historylog->user != $this->user) |
427 | 459 | { |
@@ -437,10 +469,13 @@ discard block |
||
437 | 469 | { |
438 | 470 | $status = isset($this->field2history[$name]) ? $this->field2history[$name] : $name; |
439 | 471 | //error_log(__METHOD__.__LINE__." Name $name,".' Status:'.array2string($status)); |
440 | - if (is_array($status)) // 1:N relation --> remove common rows |
|
472 | + if (is_array($status)) |
|
473 | + { |
|
474 | + // 1:N relation --> remove common rows |
|
441 | 475 | { |
442 | 476 | //error_log(__METHOD__.__LINE__.' is Array'); |
443 | 477 | self::compact_1_N_relation($data[$name],$status); |
478 | + } |
|
444 | 479 | self::compact_1_N_relation($old[$name],$status); |
445 | 480 | $added = array_values(array_diff($data[$name],$old[$name])); |
446 | 481 | $removed = array_values(array_diff($old[$name],$data[$name])); |
@@ -474,17 +509,31 @@ discard block |
||
474 | 509 | */ |
475 | 510 | public function changed_fields(array $data,array $old=null) |
476 | 511 | { |
477 | - if (is_null($old)) return array_keys($data); |
|
512 | + if (is_null($old)) |
|
513 | + { |
|
514 | + return array_keys($data); |
|
515 | + } |
|
478 | 516 | $changed_fields = array(); |
479 | 517 | foreach($this->field2history as $name => $status) |
480 | 518 | { |
481 | - if (!$old[$name] && !$data[$name]) continue; // treat all sorts of empty equally |
|
519 | + if (!$old[$name] && !$data[$name]) |
|
520 | + { |
|
521 | + continue; |
|
522 | + } |
|
523 | + // treat all sorts of empty equally |
|
482 | 524 | |
483 | - if ($name[0] == '#' && !isset($data[$name])) continue; // no set customfields are not stored, therefore not changed |
|
525 | + if ($name[0] == '#' && !isset($data[$name])) |
|
526 | + { |
|
527 | + continue; |
|
528 | + } |
|
529 | + // no set customfields are not stored, therefore not changed |
|
484 | 530 | |
485 | - if (is_array($status)) // 1:N relation |
|
531 | + if (is_array($status)) |
|
532 | + { |
|
533 | + // 1:N relation |
|
486 | 534 | { |
487 | 535 | self::compact_1_N_relation($data[$name],$status); |
536 | + } |
|
488 | 537 | self::compact_1_N_relation($old[$name],$status); |
489 | 538 | } |
490 | 539 | if ($old[$name] != $data[$name]) |
@@ -492,13 +541,22 @@ discard block |
||
492 | 541 | // normalize arrays, we do NOT care for the order of multiselections |
493 | 542 | if (is_array($data[$name]) || is_array($old[$name])) |
494 | 543 | { |
495 | - if (!is_array($data[$name])) $data[$name] = explode(',',$data[$name]); |
|
496 | - if (!is_array($old[$name])) $old[$name] = explode(',',$old[$name]); |
|
544 | + if (!is_array($data[$name])) |
|
545 | + { |
|
546 | + $data[$name] = explode(',',$data[$name]); |
|
547 | + } |
|
548 | + if (!is_array($old[$name])) |
|
549 | + { |
|
550 | + $old[$name] = explode(',',$old[$name]); |
|
551 | + } |
|
497 | 552 | if (count($data[$name]) == count($old[$name])) |
498 | 553 | { |
499 | 554 | sort($data[$name]); |
500 | 555 | sort($old[$name]); |
501 | - if ($data[$name] == $old[$name]) continue; |
|
556 | + if ($data[$name] == $old[$name]) |
|
557 | + { |
|
558 | + continue; |
|
559 | + } |
|
502 | 560 | } |
503 | 561 | } |
504 | 562 | elseif (str_replace("\r", '', $old[$name]) == str_replace("\r", '', $data[$name])) |
@@ -559,13 +617,19 @@ discard block |
||
559 | 617 | public function do_notifications($data,$old,$deleted=null,&$email_notified=null) |
560 | 618 | { |
561 | 619 | $this->errors = $email_sent = array(); |
562 | - if (!empty($email_notified) && is_array($email_notified)) $email_sent = $email_notified; |
|
620 | + if (!empty($email_notified) && is_array($email_notified)) |
|
621 | + { |
|
622 | + $email_sent = $email_notified; |
|
623 | + } |
|
563 | 624 | |
564 | - if (!$this->notify_current_user && $this->user) // do we have a current user and should we notify the current user about his own changes |
|
625 | + if (!$this->notify_current_user && $this->user) |
|
626 | + { |
|
627 | + // do we have a current user and should we notify the current user about his own changes |
|
565 | 628 | { |
566 | 629 | //error_log("do_notificaton() adding user=$this->user to email_sent, to not notify him"); |
567 | 630 | $email_sent[] = $GLOBALS['egw']->accounts->id2name($this->user,'account_email'); |
568 | 631 | } |
632 | + } |
|
569 | 633 | $skip_notify = $this->get_config('skip_notify',$data,$old); |
570 | 634 | if($skip_notify && is_array($skip_notify)) |
571 | 635 | { |
@@ -604,11 +668,14 @@ discard block |
||
604 | 668 | //error_log(__METHOD__."() data[$this->assigned_field]=".print_r($data[$this->assigned_field],true).", old[$this->assigned_field]=".print_r($old[$this->assigned_field],true)); |
605 | 669 | $old_assignees = array(); |
606 | 670 | $assignees = $assigned ? $assigned : array(); |
607 | - if ($data[$this->assigned_field]) // current assignments |
|
671 | + if ($data[$this->assigned_field]) |
|
672 | + { |
|
673 | + // current assignments |
|
608 | 674 | { |
609 | 675 | $assignees = is_array($data[$this->assigned_field]) ? |
610 | 676 | $data[$this->assigned_field] : explode(',',$data[$this->assigned_field]); |
611 | 677 | } |
678 | + } |
|
612 | 679 | if ($old && $old[$this->assigned_field]) |
613 | 680 | { |
614 | 681 | $old_assignees = is_array($old[$this->assigned_field]) ? |
@@ -617,7 +684,10 @@ discard block |
||
617 | 684 | foreach(array_unique(array_merge($assignees,$old_assignees)) as $assignee) |
618 | 685 | { |
619 | 686 | //error_log(__METHOD__."() assignee=$assignee, type=".$GLOBALS['egw']->accounts->get_type($assignee).", email=".$GLOBALS['egw']->accounts->id2name($assignee,'account_email')); |
620 | - if (!$assignee) continue; |
|
687 | + if (!$assignee) |
|
688 | + { |
|
689 | + continue; |
|
690 | + } |
|
621 | 691 | |
622 | 692 | // item assignee is a user |
623 | 693 | if ($GLOBALS['egw']->accounts->get_type($assignee) == 'u') |
@@ -625,10 +695,13 @@ discard block |
||
625 | 695 | if (($email = $GLOBALS['egw']->accounts->id2name($assignee,'account_email')) && !in_array($email, $email_sent)) |
626 | 696 | { |
627 | 697 | if ($this->send_notification($data,$old,$email,$assignee,'notify_assigned', |
628 | - in_array($assignee,$assignees) !== in_array($assignee,$old_assignees) || $deleted)) // assignment changed |
|
698 | + in_array($assignee,$assignees) !== in_array($assignee,$old_assignees) || $deleted)) |
|
699 | + { |
|
700 | + // assignment changed |
|
629 | 701 | { |
630 | 702 | $email_sent[] = $email; |
631 | 703 | } |
704 | + } |
|
632 | 705 | } |
633 | 706 | } |
634 | 707 | else // item assignee is a group |
@@ -638,10 +711,13 @@ discard block |
||
638 | 711 | if (($email = $GLOBALS['egw']->accounts->id2name($u,'account_email')) && !in_array($email, $email_sent)) |
639 | 712 | { |
640 | 713 | if ($this->send_notification($data,$old,$email,$u,'notify_assigned', |
641 | - in_array($u,$assignees) !== in_array($u,$old_assignees) || $deleted)) // assignment changed |
|
714 | + in_array($u,$assignees) !== in_array($u,$old_assignees) || $deleted)) |
|
715 | + { |
|
716 | + // assignment changed |
|
642 | 717 | { |
643 | 718 | $email_sent[] = $email; |
644 | 719 | } |
720 | + } |
|
645 | 721 | } |
646 | 722 | } |
647 | 723 | } |
@@ -704,26 +780,39 @@ discard block |
||
704 | 780 | public function send_notification($data,$old,$email,$user_or_lang,$check=null,$assignment_changed=true,$deleted=null) |
705 | 781 | { |
706 | 782 | //error_log(__METHOD__."(,,'$email',$user_or_lang,$check,$assignment_changed,$deleted)"); |
707 | - if (!$email) return false; |
|
783 | + if (!$email) |
|
784 | + { |
|
785 | + return false; |
|
786 | + } |
|
708 | 787 | |
709 | 788 | $save_user = $GLOBALS['egw_info']['user']; |
710 | 789 | $do_notify = true; |
711 | 790 | $can_cache = false; |
712 | 791 | |
713 | - if (is_numeric($user_or_lang)) // user --> read everything from his prefs |
|
792 | + if (is_numeric($user_or_lang)) |
|
793 | + { |
|
794 | + // user --> read everything from his prefs |
|
714 | 795 | { |
715 | 796 | $GLOBALS['egw_info']['user']['account_id'] = $user_or_lang; |
797 | + } |
|
716 | 798 | $GLOBALS['egw']->preferences->__construct($user_or_lang); |
717 | 799 | $GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false); // no session prefs! |
718 | 800 | |
719 | - if ($check && $this->check2pref) $check = $this->check2pref[$check]; |
|
801 | + if ($check && $this->check2pref) |
|
802 | + { |
|
803 | + $check = $this->check2pref[$check]; |
|
804 | + } |
|
720 | 805 | |
721 | 806 | if ($check && !$GLOBALS['egw_info']['user']['preferences'][$this->app][$check] || // no notification requested |
722 | 807 | // only notification about changed assignment requested |
723 | 808 | $check && $GLOBALS['egw_info']['user']['preferences'][$this->app][$check] === 'assignment' && !$assignment_changed || |
724 | - $this->user == $user_or_lang && !$this->notify_current_user) // no popup for own actions |
|
809 | + $this->user == $user_or_lang && !$this->notify_current_user) |
|
810 | + { |
|
811 | + // no popup for own actions |
|
725 | 812 | { |
726 | - $do_notify = false; // no notification requested / necessary |
|
813 | + $do_notify = false; |
|
814 | + } |
|
815 | + // no notification requested / necessary |
|
727 | 816 | } |
728 | 817 | $can_cache = (Customfields::get($this->app, true) == Customfields::get($this->app, $user_or_lang)); |
729 | 818 | } |
@@ -733,10 +822,13 @@ discard block |
||
733 | 822 | $GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->default_prefs(); |
734 | 823 | $GLOBALS['egw_info']['user']['preferences']['common']['lang'] = $user_or_lang; |
735 | 824 | } |
736 | - if ($GLOBALS['egw_info']['user']['preferences']['common']['lang'] != Api\Translation::$userlang) // load the right language if needed |
|
825 | + if ($GLOBALS['egw_info']['user']['preferences']['common']['lang'] != Api\Translation::$userlang) |
|
826 | + { |
|
827 | + // load the right language if needed |
|
737 | 828 | { |
738 | 829 | Api\Translation::init(); |
739 | 830 | } |
831 | + } |
|
740 | 832 | |
741 | 833 | $receiver = is_numeric($user_or_lang) ? $user_or_lang : $email; |
742 | 834 | |
@@ -847,7 +939,10 @@ discard block |
||
847 | 939 | $do_time = ($timestamp->format('Hi') != '0000'); |
848 | 940 | } |
849 | 941 | $format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat']; |
850 | - if ($do_time) $format .= ' '.($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] != 12 ? 'H:i' : 'h:i a'); |
|
942 | + if ($do_time) |
|
943 | + { |
|
944 | + $format .= ' '.($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] != 12 ? 'H:i' : 'h:i a'); |
|
945 | + } |
|
851 | 946 | |
852 | 947 | return $timestamp->format($format); |
853 | 948 | } |
@@ -877,9 +972,12 @@ discard block |
||
877 | 972 | { |
878 | 973 | $name = $GLOBALS['egw']->accounts->id2name($this->user,'account_fullname'); |
879 | 974 | |
880 | - if($prefer_id) { |
|
975 | + if($prefer_id) |
|
976 | + { |
|
881 | 977 | $sender = $this->user; |
882 | - } else { |
|
978 | + } |
|
979 | + else |
|
980 | + { |
|
883 | 981 | $sender = $name ? $name.' <'.$email.'>' : $email; |
884 | 982 | } |
885 | 983 | } |
@@ -971,14 +1069,20 @@ discard block |
||
971 | 1069 | $popup = Api\Link::is_popup($this->app,'view'); |
972 | 1070 | } |
973 | 1071 | } |
974 | - if ($link[0] == '/') Api\Framework::getUrl($link); |
|
1072 | + if ($link[0] == '/') |
|
1073 | + { |
|
1074 | + Api\Framework::getUrl($link); |
|
1075 | + } |
|
975 | 1076 | |
976 | 1077 | if (!$allow_popup) |
977 | 1078 | { |
978 | 1079 | // remove the session-id in the notification mail! |
979 | 1080 | $link = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/','',$link); |
980 | 1081 | |
981 | - if ($popup) $link .= '&nopopup=1'; |
|
1082 | + if ($popup) |
|
1083 | + { |
|
1084 | + $link .= '&nopopup=1'; |
|
1085 | + } |
|
982 | 1086 | } |
983 | 1087 | //error_log(__METHOD__."(..., $allow_popup, $receiver) returning ".array2string($allow_popup ? array($link,$popup) : $link)); |
984 | 1088 | return $allow_popup ? array($link,$popup) : $link; |
@@ -1053,7 +1157,11 @@ discard block |
||
1053 | 1157 | // if both values are '', 0 or null, we count them as equal too |
1054 | 1158 | $modified = $old && $data[$name] != $old[$name] && !(!$data[$name] && !$old[$name]); |
1055 | 1159 | //if ($modified) error_log("data[$name]=".print_r($data[$name],true).", old[$name]=".print_r($old[$name],true)." --> modified=".(int)$modified); |
1056 | - if (empty($detail['value']) && !$modified) continue; // skip unchanged, empty values |
|
1160 | + if (empty($detail['value']) && !$modified) |
|
1161 | + { |
|
1162 | + continue; |
|
1163 | + } |
|
1164 | + // skip unchanged, empty values |
|
1057 | 1165 | |
1058 | 1166 | $body .= $this->format_line($html_email,$detail['type'],$modified, |
1059 | 1167 | $detail['label'] ? $detail['label'] : '', $detail['value']); |
@@ -1087,7 +1195,11 @@ discard block |
||
1087 | 1195 | |
1088 | 1196 | if ($html_mail) |
1089 | 1197 | { |
1090 | - if (!$this->html_content_allow) $line = Api\Html::htmlspecialchars($line); // XSS |
|
1198 | + if (!$this->html_content_allow) |
|
1199 | + { |
|
1200 | + $line = Api\Html::htmlspecialchars($line); |
|
1201 | + } |
|
1202 | + // XSS |
|
1091 | 1203 | |
1092 | 1204 | $color = $modified ? 'red' : false; |
1093 | 1205 | $size = '110%'; |
@@ -1126,15 +1238,24 @@ discard block |
||
1126 | 1238 | } |
1127 | 1239 | else // text-mail |
1128 | 1240 | { |
1129 | - if ($type == 'reply') $content = str_repeat('-',64)."\n"; |
|
1241 | + if ($type == 'reply') |
|
1242 | + { |
|
1243 | + $content = str_repeat('-',64)."\n"; |
|
1244 | + } |
|
1130 | 1245 | |
1131 | - if ($modified) $content .= '> '; |
|
1246 | + if ($modified) |
|
1247 | + { |
|
1248 | + $content .= '> '; |
|
1249 | + } |
|
1132 | 1250 | } |
1133 | 1251 | $content .= $line; |
1134 | 1252 | |
1135 | 1253 | if ($html_mail) |
1136 | 1254 | { |
1137 | - if ($line && $data) $content .= '</td><td style="'.$style.'">'; |
|
1255 | + if ($line && $data) |
|
1256 | + { |
|
1257 | + $content .= '</td><td style="'.$style.'">'; |
|
1258 | + } |
|
1138 | 1259 | if ($type == 'link') |
1139 | 1260 | { |
1140 | 1261 | // the link is often too long for html boxes chunk-split allows to break lines if needed |
@@ -1153,7 +1274,10 @@ discard block |
||
1153 | 1274 | { |
1154 | 1275 | $content .= ($content&&$data?': ':'').$data; |
1155 | 1276 | } |
1156 | - if ($html_mail) $content .= '</td></tr>'; |
|
1277 | + if ($html_mail) |
|
1278 | + { |
|
1279 | + $content .= '</td></tr>'; |
|
1280 | + } |
|
1157 | 1281 | |
1158 | 1282 | $content .= "\n"; |
1159 | 1283 |
@@ -200,22 +200,22 @@ discard block |
||
200 | 200 | * @param string $cf_app = null if set, custom field names get added to $field2history |
201 | 201 | * @return bo_tracking |
202 | 202 | */ |
203 | - function __construct($cf_app = null, $notification_class=false) |
|
203 | + function __construct($cf_app = null, $notification_class = false) |
|
204 | 204 | { |
205 | 205 | if ($cf_app) |
206 | 206 | { |
207 | - $linkable_cf_types = array('link-entry')+array_keys(Api\Link::app_list()); |
|
208 | - foreach(Customfields::get($cf_app, true) as $cf_name => $cf_data) |
|
207 | + $linkable_cf_types = array('link-entry') + array_keys(Api\Link::app_list()); |
|
208 | + foreach (Customfields::get($cf_app, true) as $cf_name => $cf_data) |
|
209 | 209 | { |
210 | 210 | $this->field2history['#'.$cf_name] = '#'.$cf_name; |
211 | 211 | |
212 | - if (in_array($cf_data['type'],$linkable_cf_types)) |
|
212 | + if (in_array($cf_data['type'], $linkable_cf_types)) |
|
213 | 213 | { |
214 | 214 | $this->cf_link_fields['#'.$cf_name] = $cf_data['type'] == 'link-entry' ? '' : $cf_data['type']; |
215 | 215 | } |
216 | 216 | } |
217 | 217 | } |
218 | - if($notification_class) |
|
218 | + if ($notification_class) |
|
219 | 219 | { |
220 | 220 | $this->notification_class = $notification_class; |
221 | 221 | } |
@@ -230,9 +230,9 @@ discard block |
||
230 | 230 | * @param int|string $receiver nummeric account_id or email address |
231 | 231 | * @return array of details as array with values for keys 'label','value','type' |
232 | 232 | */ |
233 | - function get_details($data,$receiver=null) |
|
233 | + function get_details($data, $receiver = null) |
|
234 | 234 | { |
235 | - unset($data, $receiver); // not uses as just a stub |
|
235 | + unset($data, $receiver); // not uses as just a stub |
|
236 | 236 | |
237 | 237 | return array(); |
238 | 238 | } |
@@ -247,10 +247,10 @@ discard block |
||
247 | 247 | * |
248 | 248 | * @return array of details as array with values for keys 'label','value','type' |
249 | 249 | */ |
250 | - function get_customfields($data, $only_type2=null, $user = false) |
|
250 | + function get_customfields($data, $only_type2 = null, $user = false) |
|
251 | 251 | { |
252 | 252 | $details = array(); |
253 | - if(!is_numeric($user)) |
|
253 | + if (!is_numeric($user)) |
|
254 | 254 | { |
255 | 255 | $user = false; |
256 | 256 | } |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | if (($cfs = Customfields::get($this->app, $user, $only_type2))) |
259 | 259 | { |
260 | 260 | $header_done = false; |
261 | - foreach($cfs as $name => $field) |
|
261 | + foreach ($cfs as $name => $field) |
|
262 | 262 | { |
263 | 263 | if (in_array($field['type'], Customfields::$non_printable_fields)) continue; |
264 | 264 | |
@@ -303,9 +303,9 @@ discard block |
||
303 | 303 | * @param array $old = null old/last state of the entry or null for a new entry |
304 | 304 | * @return mixed |
305 | 305 | */ |
306 | - protected function get_config($name,$data,$old=null) |
|
306 | + protected function get_config($name, $data, $old = null) |
|
307 | 307 | { |
308 | - unset($name, $data, $old); // not used as just a stub |
|
308 | + unset($name, $data, $old); // not used as just a stub |
|
309 | 309 | |
310 | 310 | return null; |
311 | 311 | } |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | * @param boolean $skip_notification = false do NOT send any notification |
322 | 322 | * @return int|boolean false on error, integer number of changes logged or true for new entries ($old == null) |
323 | 323 | */ |
324 | - public function track(array $data,array $old=null,$user=null,$deleted=null,array $changed_fields=null,$skip_notification=false) |
|
324 | + public function track(array $data, array $old = null, $user = null, $deleted = null, array $changed_fields = null, $skip_notification = false) |
|
325 | 325 | { |
326 | 326 | $this->user = !is_null($user) ? $user : $GLOBALS['egw_info']['user']['account_id']; |
327 | 327 | |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | if ($old && $this->field2history) |
331 | 331 | { |
332 | 332 | //error_log(__METHOD__.__LINE__.' Changedfields:'.print_r($changed_fields,true)); |
333 | - $changes = $this->save_history($data,$old,$deleted,$changed_fields); |
|
333 | + $changes = $this->save_history($data, $old, $deleted, $changed_fields); |
|
334 | 334 | //error_log(__METHOD__.__LINE__.' Changedfields:'.print_r($changed_fields,true)); |
335 | 335 | //error_log(__METHOD__.__LINE__.' Changes:'.print_r($changes,true)); |
336 | 336 | } |
@@ -338,10 +338,10 @@ discard block |
||
338 | 338 | //error_log(__METHOD__.__LINE__.' LinkFields:'.array2string($this->cf_link_fields)); |
339 | 339 | if ($changes && $this->cf_link_fields) |
340 | 340 | { |
341 | - $this->update_links($data,(array)$old); |
|
341 | + $this->update_links($data, (array)$old); |
|
342 | 342 | } |
343 | 343 | // do not run do_notifications if we have no changes |
344 | - if ($changes && !$skip_notification && !$this->do_notifications($data,$old,$deleted)) |
|
344 | + if ($changes && !$skip_notification && !$this->do_notifications($data, $old, $deleted)) |
|
345 | 345 | { |
346 | 346 | $changes = false; |
347 | 347 | } |
@@ -358,45 +358,45 @@ discard block |
||
358 | 358 | { |
359 | 359 | //error_log(__METHOD__.__LINE__.array2string($data).function_backtrace()); |
360 | 360 | //error_log(__METHOD__.__LINE__.array2string($this->cf_link_fields)); |
361 | - foreach(array_keys((array)$this->cf_link_fields) as $name) |
|
361 | + foreach (array_keys((array)$this->cf_link_fields) as $name) |
|
362 | 362 | { |
363 | 363 | //error_log(__METHOD__.__LINE__.' Field:'.$name. ' Value (new):'.array2string($data[$name])); |
364 | 364 | //error_log(__METHOD__.__LINE__.' Field:'.$name. ' Value (old):'.array2string($old[$name])); |
365 | - if (is_array($data[$name]) && array_key_exists('id',$data[$name])) $data[$name] = $data[$name]['id']; |
|
366 | - if (is_array($old[$name]) && array_key_exists('id',$old[$name])) $old[$name] = $old[$name]['id']; |
|
365 | + if (is_array($data[$name]) && array_key_exists('id', $data[$name])) $data[$name] = $data[$name]['id']; |
|
366 | + if (is_array($old[$name]) && array_key_exists('id', $old[$name])) $old[$name] = $old[$name]['id']; |
|
367 | 367 | //error_log(__METHOD__.__LINE__.'(After processing) Field:'.$name. ' Value (new):'.array2string($data[$name])); |
368 | 368 | //error_log(__METHOD__.__LINE__.'(After processing) Field:'.$name. ' Value (old):'.array2string($old[$name])); |
369 | 369 | } |
370 | - $current_ids = array_unique(array_diff(array_intersect_key($data,$this->cf_link_fields),array('',0,NULL))); |
|
371 | - $old_ids = $old ? array_unique(array_diff(array_intersect_key($old,$this->cf_link_fields),array('',0,NULL))) : array(); |
|
370 | + $current_ids = array_unique(array_diff(array_intersect_key($data, $this->cf_link_fields), array('', 0, NULL))); |
|
371 | + $old_ids = $old ? array_unique(array_diff(array_intersect_key($old, $this->cf_link_fields), array('', 0, NULL))) : array(); |
|
372 | 372 | //error_log(__METHOD__.__LINE__.array2string($current_ids)); |
373 | 373 | //error_log(__METHOD__.__LINE__.array2string($old_ids)); |
374 | 374 | // create links for added application entry |
375 | - foreach(array_diff($current_ids,$old_ids) as $name => $id) |
|
375 | + foreach (array_diff($current_ids, $old_ids) as $name => $id) |
|
376 | 376 | { |
377 | 377 | if (!($app = $this->cf_link_fields[$name])) |
378 | 378 | { |
379 | - list($app,$id) = explode(':',$id); |
|
380 | - if (!$id) continue; // can be eg. 'addressbook:', if no contact selected |
|
379 | + list($app, $id) = explode(':', $id); |
|
380 | + if (!$id) continue; // can be eg. 'addressbook:', if no contact selected |
|
381 | 381 | } |
382 | 382 | $source_id = $data[$this->id_field]; |
383 | 383 | //error_log(__METHOD__.__LINE__.array2string($source_id)); |
384 | - if ($source_id) Api\Link::link($this->app,$source_id,$app,$id); |
|
384 | + if ($source_id) Api\Link::link($this->app, $source_id, $app, $id); |
|
385 | 385 | //error_log(__METHOD__.__LINE__."Api\Link::link('$this->app',".array2string($source_id).",'$app',$id);"); |
386 | 386 | //echo "<p>Api\Link::link('$this->app',{$data[$this->id_field]},'$app',$id);</p>\n"; |
387 | 387 | } |
388 | 388 | |
389 | 389 | // unlink removed application entries |
390 | - foreach(array_diff($old_ids,$current_ids) as $name => $id) |
|
390 | + foreach (array_diff($old_ids, $current_ids) as $name => $id) |
|
391 | 391 | { |
392 | - if (!isset($data[$name])) continue; // ignore not set link cf's, eg. from sync clients |
|
392 | + if (!isset($data[$name])) continue; // ignore not set link cf's, eg. from sync clients |
|
393 | 393 | if (!($app = $this->cf_link_fields[$name])) |
394 | 394 | { |
395 | - list($app,$id) = explode(':',$id); |
|
395 | + list($app, $id) = explode(':', $id); |
|
396 | 396 | if (!$id) continue; |
397 | 397 | } |
398 | 398 | $source_id = $data[$this->id_field]; |
399 | - if ($source_id) Api\Link::unlink(null,$this->app,$source_id,0,$app,$id); |
|
399 | + if ($source_id) Api\Link::unlink(null, $this->app, $source_id, 0, $app, $id); |
|
400 | 400 | //echo "<p>Api\Link::unlink(NULL,'$this->app',{$data[$this->id_field]},0,'$app',$id);</p>\n"; |
401 | 401 | } |
402 | 402 | } |
@@ -411,14 +411,14 @@ discard block |
||
411 | 411 | * @param array $changed_fields = null changed fields from ealier call to $this->changed_fields($data,$old), to not compute it again |
412 | 412 | * @return int number of log-entries made |
413 | 413 | */ |
414 | - protected function save_history(array $data,array $old=null,$deleted=null,array $changed_fields=null) |
|
414 | + protected function save_history(array $data, array $old = null, $deleted = null, array $changed_fields = null) |
|
415 | 415 | { |
416 | - unset($deleted); // not used, but required by function signature |
|
416 | + unset($deleted); // not used, but required by function signature |
|
417 | 417 | |
418 | 418 | //error_log(__METHOD__.__LINE__.' Changedfields:'.array2string($changed_fields)); |
419 | 419 | if (is_null($changed_fields)) |
420 | 420 | { |
421 | - $changed_fields = self::changed_fields($data,$old); |
|
421 | + $changed_fields = self::changed_fields($data, $old); |
|
422 | 422 | //error_log(__METHOD__.__LINE__.' Changedfields:'.array2string($changed_fields)); |
423 | 423 | } |
424 | 424 | if (!$changed_fields && ($old || !$GLOBALS['egw_info']['server']['log_user_agent_action'])) return 0; |
@@ -433,30 +433,30 @@ discard block |
||
433 | 433 | $this->historylog->add('user_agent_action', $data[$this->id_field], |
434 | 434 | $_SERVER['HTTP_USER_AGENT'], $_SESSION[Api\Session::EGW_SESSION_VAR]['session_action']); |
435 | 435 | } |
436 | - foreach($changed_fields as $name) |
|
436 | + foreach ($changed_fields as $name) |
|
437 | 437 | { |
438 | 438 | $status = isset($this->field2history[$name]) ? $this->field2history[$name] : $name; |
439 | 439 | //error_log(__METHOD__.__LINE__." Name $name,".' Status:'.array2string($status)); |
440 | 440 | if (is_array($status)) // 1:N relation --> remove common rows |
441 | 441 | { |
442 | 442 | //error_log(__METHOD__.__LINE__.' is Array'); |
443 | - self::compact_1_N_relation($data[$name],$status); |
|
444 | - self::compact_1_N_relation($old[$name],$status); |
|
445 | - $added = array_values(array_diff($data[$name],$old[$name])); |
|
446 | - $removed = array_values(array_diff($old[$name],$data[$name])); |
|
447 | - $n = max(array(count($added),count($removed))); |
|
448 | - for($i = 0; $i < $n; ++$i) |
|
443 | + self::compact_1_N_relation($data[$name], $status); |
|
444 | + self::compact_1_N_relation($old[$name], $status); |
|
445 | + $added = array_values(array_diff($data[$name], $old[$name])); |
|
446 | + $removed = array_values(array_diff($old[$name], $data[$name])); |
|
447 | + $n = max(array(count($added), count($removed))); |
|
448 | + for ($i = 0; $i < $n; ++$i) |
|
449 | 449 | { |
450 | 450 | //error_log(__METHOD__."() $i: historylog->add('$name',data['$this->id_field']={$data[$this->id_field]},".array2string($added[$i]).','.array2string($removed[$i])); |
451 | - $this->historylog->add($name,$data[$this->id_field],$added[$i],$removed[$i]); |
|
451 | + $this->historylog->add($name, $data[$this->id_field], $added[$i], $removed[$i]); |
|
452 | 452 | } |
453 | 453 | } |
454 | 454 | else |
455 | 455 | { |
456 | 456 | //error_log(__METHOD__.__LINE__.' IDField:'.array2string($this->id_field).' ->'.$data[$this->id_field].' New:'.$data[$name].' Old:'.$old[$name]); |
457 | - $this->historylog->add($status,$data[$this->id_field], |
|
458 | - is_array($data[$name]) ? implode(',',$data[$name]) : $data[$name], |
|
459 | - is_array($old[$name]) ? implode(',',$old[$name]) : $old[$name]); |
|
457 | + $this->historylog->add($status, $data[$this->id_field], |
|
458 | + is_array($data[$name]) ? implode(',', $data[$name]) : $data[$name], |
|
459 | + is_array($old[$name]) ? implode(',', $old[$name]) : $old[$name]); |
|
460 | 460 | } |
461 | 461 | } |
462 | 462 | //error_log(__METHOD__.__LINE__.' return:'.count($changed_fields)); |
@@ -472,28 +472,28 @@ discard block |
||
472 | 472 | * @param array $old = null |
473 | 473 | * @return array of keys with different values in $data and $old |
474 | 474 | */ |
475 | - public function changed_fields(array $data,array $old=null) |
|
475 | + public function changed_fields(array $data, array $old = null) |
|
476 | 476 | { |
477 | 477 | if (is_null($old)) return array_keys($data); |
478 | 478 | $changed_fields = array(); |
479 | - foreach($this->field2history as $name => $status) |
|
479 | + foreach ($this->field2history as $name => $status) |
|
480 | 480 | { |
481 | - if (!$old[$name] && !$data[$name]) continue; // treat all sorts of empty equally |
|
481 | + if (!$old[$name] && !$data[$name]) continue; // treat all sorts of empty equally |
|
482 | 482 | |
483 | - if ($name[0] == '#' && !isset($data[$name])) continue; // no set customfields are not stored, therefore not changed |
|
483 | + if ($name[0] == '#' && !isset($data[$name])) continue; // no set customfields are not stored, therefore not changed |
|
484 | 484 | |
485 | 485 | if (is_array($status)) // 1:N relation |
486 | 486 | { |
487 | - self::compact_1_N_relation($data[$name],$status); |
|
488 | - self::compact_1_N_relation($old[$name],$status); |
|
487 | + self::compact_1_N_relation($data[$name], $status); |
|
488 | + self::compact_1_N_relation($old[$name], $status); |
|
489 | 489 | } |
490 | 490 | if ($old[$name] != $data[$name]) |
491 | 491 | { |
492 | 492 | // normalize arrays, we do NOT care for the order of multiselections |
493 | 493 | if (is_array($data[$name]) || is_array($old[$name])) |
494 | 494 | { |
495 | - if (!is_array($data[$name])) $data[$name] = explode(',',$data[$name]); |
|
496 | - if (!is_array($old[$name])) $old[$name] = explode(',',$old[$name]); |
|
495 | + if (!is_array($data[$name])) $data[$name] = explode(',', $data[$name]); |
|
496 | + if (!is_array($old[$name])) $old[$name] = explode(',', $old[$name]); |
|
497 | 497 | if (count($data[$name]) == count($old[$name])) |
498 | 498 | { |
499 | 499 | sort($data[$name]); |
@@ -503,13 +503,13 @@ discard block |
||
503 | 503 | } |
504 | 504 | elseif (str_replace("\r", '', $old[$name]) == str_replace("\r", '', $data[$name])) |
505 | 505 | { |
506 | - continue; // change only in CR (eg. different OS) --> ignore |
|
506 | + continue; // change only in CR (eg. different OS) --> ignore |
|
507 | 507 | } |
508 | 508 | $changed_fields[] = $name; |
509 | 509 | //echo "<p>$name: ".array2string($data[$name]).' != '.array2string($old[$name])."</p>\n"; |
510 | 510 | } |
511 | 511 | } |
512 | - foreach($data as $name => $value) |
|
512 | + foreach ($data as $name => $value) |
|
513 | 513 | { |
514 | 514 | if ($name[0] == '#' && $name[1] == '#' && $value !== $old[$name]) |
515 | 515 | { |
@@ -526,18 +526,18 @@ discard block |
||
526 | 526 | * @param array &$rows rows of the 1:N relation |
527 | 527 | * @param array $cols field names as values |
528 | 528 | */ |
529 | - private static function compact_1_N_relation(&$rows,array $cols) |
|
529 | + private static function compact_1_N_relation(&$rows, array $cols) |
|
530 | 530 | { |
531 | 531 | if (is_array($rows)) |
532 | 532 | { |
533 | - foreach($rows as &$row) |
|
533 | + foreach ($rows as &$row) |
|
534 | 534 | { |
535 | 535 | $values = array(); |
536 | - foreach($cols as $col) |
|
536 | + foreach ($cols as $col) |
|
537 | 537 | { |
538 | 538 | $values[] = $row[$col]; |
539 | 539 | } |
540 | - $row = implode(self::ONE2N_SEPERATOR,$values); |
|
540 | + $row = implode(self::ONE2N_SEPERATOR, $values); |
|
541 | 541 | } |
542 | 542 | } |
543 | 543 | else |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | * @param array $email_notified=null if present will return the emails notified, if given emails in that list will not be notified |
557 | 557 | * @return boolean true on success, false on error (error messages are in $this->errors) |
558 | 558 | */ |
559 | - public function do_notifications($data,$old,$deleted=null,&$email_notified=null) |
|
559 | + public function do_notifications($data, $old, $deleted = null, &$email_notified = null) |
|
560 | 560 | { |
561 | 561 | $this->errors = $email_sent = array(); |
562 | 562 | if (!empty($email_notified) && is_array($email_notified)) $email_sent = $email_notified; |
@@ -564,19 +564,19 @@ discard block |
||
564 | 564 | if (!$this->notify_current_user && $this->user) // do we have a current user and should we notify the current user about his own changes |
565 | 565 | { |
566 | 566 | //error_log("do_notificaton() adding user=$this->user to email_sent, to not notify him"); |
567 | - $email_sent[] = $GLOBALS['egw']->accounts->id2name($this->user,'account_email'); |
|
567 | + $email_sent[] = $GLOBALS['egw']->accounts->id2name($this->user, 'account_email'); |
|
568 | 568 | } |
569 | - $skip_notify = $this->get_config('skip_notify',$data,$old); |
|
570 | - if($skip_notify && is_array($skip_notify)) |
|
569 | + $skip_notify = $this->get_config('skip_notify', $data, $old); |
|
570 | + if ($skip_notify && is_array($skip_notify)) |
|
571 | 571 | { |
572 | 572 | $email_sent = array_merge($email_sent, $skip_notify); |
573 | 573 | } |
574 | 574 | |
575 | 575 | // entry creator |
576 | - if ($this->creator_field && ($email = $GLOBALS['egw']->accounts->id2name($data[$this->creator_field],'account_email')) && |
|
576 | + if ($this->creator_field && ($email = $GLOBALS['egw']->accounts->id2name($data[$this->creator_field], 'account_email')) && |
|
577 | 577 | !in_array($email, $email_sent)) |
578 | 578 | { |
579 | - if ($this->send_notification($data,$old,$email,$data[$this->creator_field],'notify_creator')) |
|
579 | + if ($this->send_notification($data, $old, $email, $data[$this->creator_field], 'notify_creator')) |
|
580 | 580 | { |
581 | 581 | $email_sent[] = $email; |
582 | 582 | } |
@@ -585,12 +585,12 @@ discard block |
||
585 | 585 | // members of group when entry owned by group |
586 | 586 | if ($this->creator_field && $GLOBALS['egw']->accounts->get_type($data[$this->creator_field]) == 'g') |
587 | 587 | { |
588 | - foreach($GLOBALS['egw']->accounts->members($data[$this->creator_field],true) as $u) |
|
588 | + foreach ($GLOBALS['egw']->accounts->members($data[$this->creator_field], true) as $u) |
|
589 | 589 | { |
590 | - if (($email = $GLOBALS['egw']->accounts->id2name($u,'account_email')) && |
|
590 | + if (($email = $GLOBALS['egw']->accounts->id2name($u, 'account_email')) && |
|
591 | 591 | !in_array($email, $email_sent)) |
592 | 592 | { |
593 | - if ($this->send_notification($data,$old,$email,$u,'notify_owner_group_member')) |
|
593 | + if ($this->send_notification($data, $old, $email, $u, 'notify_owner_group_member')) |
|
594 | 594 | { |
595 | 595 | $email_sent[] = $email; |
596 | 596 | } |
@@ -607,14 +607,14 @@ discard block |
||
607 | 607 | if ($data[$this->assigned_field]) // current assignments |
608 | 608 | { |
609 | 609 | $assignees = is_array($data[$this->assigned_field]) ? |
610 | - $data[$this->assigned_field] : explode(',',$data[$this->assigned_field]); |
|
610 | + $data[$this->assigned_field] : explode(',', $data[$this->assigned_field]); |
|
611 | 611 | } |
612 | 612 | if ($old && $old[$this->assigned_field]) |
613 | 613 | { |
614 | 614 | $old_assignees = is_array($old[$this->assigned_field]) ? |
615 | - $old[$this->assigned_field] : explode(',',$old[$this->assigned_field]); |
|
615 | + $old[$this->assigned_field] : explode(',', $old[$this->assigned_field]); |
|
616 | 616 | } |
617 | - foreach(array_unique(array_merge($assignees,$old_assignees)) as $assignee) |
|
617 | + foreach (array_unique(array_merge($assignees, $old_assignees)) as $assignee) |
|
618 | 618 | { |
619 | 619 | //error_log(__METHOD__."() assignee=$assignee, type=".$GLOBALS['egw']->accounts->get_type($assignee).", email=".$GLOBALS['egw']->accounts->id2name($assignee,'account_email')); |
620 | 620 | if (!$assignee) continue; |
@@ -622,10 +622,10 @@ discard block |
||
622 | 622 | // item assignee is a user |
623 | 623 | if ($GLOBALS['egw']->accounts->get_type($assignee) == 'u') |
624 | 624 | { |
625 | - if (($email = $GLOBALS['egw']->accounts->id2name($assignee,'account_email')) && !in_array($email, $email_sent)) |
|
625 | + if (($email = $GLOBALS['egw']->accounts->id2name($assignee, 'account_email')) && !in_array($email, $email_sent)) |
|
626 | 626 | { |
627 | - if ($this->send_notification($data,$old,$email,$assignee,'notify_assigned', |
|
628 | - in_array($assignee,$assignees) !== in_array($assignee,$old_assignees) || $deleted)) // assignment changed |
|
627 | + if ($this->send_notification($data, $old, $email, $assignee, 'notify_assigned', |
|
628 | + in_array($assignee, $assignees) !== in_array($assignee, $old_assignees) || $deleted)) // assignment changed |
|
629 | 629 | { |
630 | 630 | $email_sent[] = $email; |
631 | 631 | } |
@@ -633,12 +633,12 @@ discard block |
||
633 | 633 | } |
634 | 634 | else // item assignee is a group |
635 | 635 | { |
636 | - foreach($GLOBALS['egw']->accounts->members($assignee,true) as $u) |
|
636 | + foreach ($GLOBALS['egw']->accounts->members($assignee, true) as $u) |
|
637 | 637 | { |
638 | - if (($email = $GLOBALS['egw']->accounts->id2name($u,'account_email')) && !in_array($email, $email_sent)) |
|
638 | + if (($email = $GLOBALS['egw']->accounts->id2name($u, 'account_email')) && !in_array($email, $email_sent)) |
|
639 | 639 | { |
640 | - if ($this->send_notification($data,$old,$email,$u,'notify_assigned', |
|
641 | - in_array($u,$assignees) !== in_array($u,$old_assignees) || $deleted)) // assignment changed |
|
640 | + if ($this->send_notification($data, $old, $email, $u, 'notify_assigned', |
|
641 | + in_array($u, $assignees) !== in_array($u, $old_assignees) || $deleted)) // assignment changed |
|
642 | 642 | { |
643 | 643 | $email_sent[] = $email; |
644 | 644 | } |
@@ -649,14 +649,14 @@ discard block |
||
649 | 649 | } |
650 | 650 | |
651 | 651 | // notification copies |
652 | - if (($copies = $this->get_config('copy',$data,$old))) |
|
652 | + if (($copies = $this->get_config('copy', $data, $old))) |
|
653 | 653 | { |
654 | - $lang = $this->get_config('lang',$data,$old); |
|
655 | - foreach($copies as $email) |
|
654 | + $lang = $this->get_config('lang', $data, $old); |
|
655 | + foreach ($copies as $email) |
|
656 | 656 | { |
657 | - if (strchr($email,'@') !== false && !in_array($email, $email_sent)) |
|
657 | + if (strchr($email, '@') !== false && !in_array($email, $email_sent)) |
|
658 | 658 | { |
659 | - if ($this->send_notification($data,$old,$email,$lang,'notify_copy')) |
|
659 | + if ($this->send_notification($data, $old, $email, $lang, 'notify_copy')) |
|
660 | 660 | { |
661 | 661 | $email_sent[] = $email; |
662 | 662 | } |
@@ -701,7 +701,7 @@ discard block |
||
701 | 701 | * @param boolean $deleted = null can be set to true to let the tracking know the item got deleted or undelted |
702 | 702 | * @return boolean true on success or false if notification not requested or error (error-message is in $this->errors) |
703 | 703 | */ |
704 | - public function send_notification($data,$old,$email,$user_or_lang,$check=null,$assignment_changed=true,$deleted=null) |
|
704 | + public function send_notification($data, $old, $email, $user_or_lang, $check = null, $assignment_changed = true, $deleted = null) |
|
705 | 705 | { |
706 | 706 | //error_log(__METHOD__."(,,'$email',$user_or_lang,$check,$assignment_changed,$deleted)"); |
707 | 707 | if (!$email) return false; |
@@ -714,16 +714,16 @@ discard block |
||
714 | 714 | { |
715 | 715 | $GLOBALS['egw_info']['user']['account_id'] = $user_or_lang; |
716 | 716 | $GLOBALS['egw']->preferences->__construct($user_or_lang); |
717 | - $GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false); // no session prefs! |
|
717 | + $GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false); // no session prefs! |
|
718 | 718 | |
719 | 719 | if ($check && $this->check2pref) $check = $this->check2pref[$check]; |
720 | 720 | |
721 | - if ($check && !$GLOBALS['egw_info']['user']['preferences'][$this->app][$check] || // no notification requested |
|
721 | + if ($check && !$GLOBALS['egw_info']['user']['preferences'][$this->app][$check] || // no notification requested |
|
722 | 722 | // only notification about changed assignment requested |
723 | 723 | $check && $GLOBALS['egw_info']['user']['preferences'][$this->app][$check] === 'assignment' && !$assignment_changed || |
724 | 724 | $this->user == $user_or_lang && !$this->notify_current_user) // no popup for own actions |
725 | 725 | { |
726 | - $do_notify = false; // no notification requested / necessary |
|
726 | + $do_notify = false; // no notification requested / necessary |
|
727 | 727 | } |
728 | 728 | $can_cache = (Customfields::get($this->app, true) == Customfields::get($this->app, $user_or_lang)); |
729 | 729 | } |
@@ -747,36 +747,36 @@ discard block |
||
747 | 747 | |
748 | 748 | // Cache message body to not have to re-generate it every time |
749 | 749 | $lang = Api\Translation::$userlang; |
750 | - $date_format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'] . |
|
750 | + $date_format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat']. |
|
751 | 751 | $GLOBALS['egw_info']['user']['preferences']['common']['timeformat']; |
752 | 752 | |
753 | 753 | // Cache text body, if there's no private custom fields we might reveal |
754 | - if($can_cache) |
|
754 | + if ($can_cache) |
|
755 | 755 | { |
756 | - $body_cache =& $this->body_cache[$data[$this->id_field]][$lang][$date_format]; |
|
756 | + $body_cache = & $this->body_cache[$data[$this->id_field]][$lang][$date_format]; |
|
757 | 757 | } |
758 | - if(empty($data[$this->id_field]) || !isset($body_cache['text'])) |
|
758 | + if (empty($data[$this->id_field]) || !isset($body_cache['text'])) |
|
759 | 759 | { |
760 | - $body_cache['text'] = $this->get_body(false,$data,$old,false,$receiver); |
|
760 | + $body_cache['text'] = $this->get_body(false, $data, $old, false, $receiver); |
|
761 | 761 | } |
762 | 762 | // Cache HTML body |
763 | - if(empty($data[$this->id_field]) || !isset($body_cache['html'])) |
|
763 | + if (empty($data[$this->id_field]) || !isset($body_cache['html'])) |
|
764 | 764 | { |
765 | - $body_cache['html'] = $this->get_body(true,$data,$old,false,$receiver); |
|
765 | + $body_cache['html'] = $this->get_body(true, $data, $old, false, $receiver); |
|
766 | 766 | } |
767 | 767 | |
768 | 768 | // get rest of notification message |
769 | - $sender = $this->get_sender($data,$old,true,$receiver); |
|
770 | - $subject = $this->get_subject($data,$old,$deleted,$receiver); |
|
771 | - $link = $this->get_notification_link($data,$old,$receiver); |
|
772 | - $attachments = $this->get_attachments($data,$old,$receiver); |
|
769 | + $sender = $this->get_sender($data, $old, true, $receiver); |
|
770 | + $subject = $this->get_subject($data, $old, $deleted, $receiver); |
|
771 | + $link = $this->get_notification_link($data, $old, $receiver); |
|
772 | + $attachments = $this->get_attachments($data, $old, $receiver); |
|
773 | 773 | } |
774 | 774 | |
775 | 775 | // restore user enviroment BEFORE calling notification class or returning |
776 | 776 | $GLOBALS['egw_info']['user'] = $save_user; |
777 | 777 | // need to call preferences constructor and read_repository, to set user timezone again |
778 | 778 | $GLOBALS['egw']->preferences->__construct($GLOBALS['egw_info']['user']['account_id']); |
779 | - $GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false); // no session prefs! |
|
779 | + $GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false); // no session prefs! |
|
780 | 780 | |
781 | 781 | // Re-load date/time preferences |
782 | 782 | Api\DateTime::init(); |
@@ -835,11 +835,11 @@ discard block |
||
835 | 835 | * |
836 | 836 | * @return string |
837 | 837 | */ |
838 | - public function datetime($timestamp,$do_time=true) |
|
838 | + public function datetime($timestamp, $do_time = true) |
|
839 | 839 | { |
840 | - if (!is_a($timestamp,'DateTime')) |
|
840 | + if (!is_a($timestamp, 'DateTime')) |
|
841 | 841 | { |
842 | - $timestamp = new Api\DateTime($timestamp,Api\DateTime::$server_timezone); |
|
842 | + $timestamp = new Api\DateTime($timestamp, Api\DateTime::$server_timezone); |
|
843 | 843 | } |
844 | 844 | $timestamp->setTimezone(Api\DateTime::$user_timezone); |
845 | 845 | if (is_null($do_time)) |
@@ -865,25 +865,25 @@ discard block |
||
865 | 865 | * @param int|string $receiver nummeric account_id or email address |
866 | 866 | * @return string or userid |
867 | 867 | */ |
868 | - protected function get_sender($data,$old,$prefer_id=false,$receiver=null) |
|
868 | + protected function get_sender($data, $old, $prefer_id = false, $receiver = null) |
|
869 | 869 | { |
870 | - unset($receiver); // not used, but required by function signature |
|
870 | + unset($receiver); // not used, but required by function signature |
|
871 | 871 | |
872 | - $sender = $this->get_config('sender',$data,$old); |
|
872 | + $sender = $this->get_config('sender', $data, $old); |
|
873 | 873 | //echo "<p>".__METHOD__."() get_config('sender',...)='".htmlspecialchars($sender)."'</p>\n"; |
874 | 874 | |
875 | 875 | if (($this->prefer_user_as_sender || !$sender) && $this->user && |
876 | - ($email = $GLOBALS['egw']->accounts->id2name($this->user,'account_email'))) |
|
876 | + ($email = $GLOBALS['egw']->accounts->id2name($this->user, 'account_email'))) |
|
877 | 877 | { |
878 | - $name = $GLOBALS['egw']->accounts->id2name($this->user,'account_fullname'); |
|
878 | + $name = $GLOBALS['egw']->accounts->id2name($this->user, 'account_fullname'); |
|
879 | 879 | |
880 | - if($prefer_id) { |
|
880 | + if ($prefer_id) { |
|
881 | 881 | $sender = $this->user; |
882 | 882 | } else { |
883 | 883 | $sender = $name ? $name.' <'.$email.'>' : $email; |
884 | 884 | } |
885 | 885 | } |
886 | - elseif(!$sender) |
|
886 | + elseif (!$sender) |
|
887 | 887 | { |
888 | 888 | $sender = 'EGroupware '.lang($this->app).' <noreply@'.$GLOBALS['egw_info']['server']['mail_suffix'].'>'; |
889 | 889 | } |
@@ -898,11 +898,11 @@ discard block |
||
898 | 898 | * @param array $old |
899 | 899 | * @return string |
900 | 900 | */ |
901 | - protected function get_title($data,$old) |
|
901 | + protected function get_title($data, $old) |
|
902 | 902 | { |
903 | - unset($old); // not used, but required by function signature |
|
903 | + unset($old); // not used, but required by function signature |
|
904 | 904 | |
905 | - return Api\Link::title($this->app,$data[$this->id_field]); |
|
905 | + return Api\Link::title($this->app, $data[$this->id_field]); |
|
906 | 906 | } |
907 | 907 | |
908 | 908 | /** |
@@ -916,11 +916,11 @@ discard block |
||
916 | 916 | * @param int|string $receiver nummeric account_id or email address |
917 | 917 | * @return string |
918 | 918 | */ |
919 | - protected function get_subject($data,$old,$deleted=null,$receiver=null) |
|
919 | + protected function get_subject($data, $old, $deleted = null, $receiver = null) |
|
920 | 920 | { |
921 | - unset($old, $deleted, $receiver); // not used, but required by function signature |
|
921 | + unset($old, $deleted, $receiver); // not used, but required by function signature |
|
922 | 922 | |
923 | - return Api\Link::title($this->app,$data[$this->id_field]); |
|
923 | + return Api\Link::title($this->app, $data[$this->id_field]); |
|
924 | 924 | } |
925 | 925 | |
926 | 926 | /** |
@@ -933,9 +933,9 @@ discard block |
||
933 | 933 | * @param int|string $receiver nummeric account_id or email address |
934 | 934 | * @return string |
935 | 935 | */ |
936 | - protected function get_message($data,$old,$receiver=null) |
|
936 | + protected function get_message($data, $old, $receiver = null) |
|
937 | 937 | { |
938 | - unset($data, $old, $receiver); // not used, but required by function signature |
|
938 | + unset($data, $old, $receiver); // not used, but required by function signature |
|
939 | 939 | |
940 | 940 | return ''; |
941 | 941 | } |
@@ -951,24 +951,24 @@ discard block |
||
951 | 951 | * @param int|string $receiver nummeric account_id or email address |
952 | 952 | * @return string|array string with link (!$allow_popup) or array(link,popup-size), popup size is something like '640x480' |
953 | 953 | */ |
954 | - protected function get_link($data,$old,$allow_popup=false,$receiver=null) |
|
954 | + protected function get_link($data, $old, $allow_popup = false, $receiver = null) |
|
955 | 955 | { |
956 | - unset($receiver); // not used, but required by function signature |
|
956 | + unset($receiver); // not used, but required by function signature |
|
957 | 957 | |
958 | - if (($link = $this->get_config('link',$data,$old))) |
|
958 | + if (($link = $this->get_config('link', $data, $old))) |
|
959 | 959 | { |
960 | - if (!$this->get_config('link_no_id', $data) && strpos($link,$this->id_field.'=') === false && isset($data[$this->id_field])) |
|
960 | + if (!$this->get_config('link_no_id', $data) && strpos($link, $this->id_field.'=') === false && isset($data[$this->id_field])) |
|
961 | 961 | { |
962 | - $link .= strpos($link,'?') === false ? '?' : '&'; |
|
962 | + $link .= strpos($link, '?') === false ? '?' : '&'; |
|
963 | 963 | $link .= $this->id_field.'='.$data[$this->id_field]; |
964 | 964 | } |
965 | 965 | } |
966 | 966 | else |
967 | 967 | { |
968 | - if (($view = Api\Link::view($this->app,$data[$this->id_field]))) |
|
968 | + if (($view = Api\Link::view($this->app, $data[$this->id_field]))) |
|
969 | 969 | { |
970 | - $link = Api\Framework::link('/index.php',$view); |
|
971 | - $popup = Api\Link::is_popup($this->app,'view'); |
|
970 | + $link = Api\Framework::link('/index.php', $view); |
|
971 | + $popup = Api\Link::is_popup($this->app, 'view'); |
|
972 | 972 | } |
973 | 973 | } |
974 | 974 | if ($link[0] == '/') Api\Framework::getUrl($link); |
@@ -976,12 +976,12 @@ discard block |
||
976 | 976 | if (!$allow_popup) |
977 | 977 | { |
978 | 978 | // remove the session-id in the notification mail! |
979 | - $link = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/','',$link); |
|
979 | + $link = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/', '', $link); |
|
980 | 980 | |
981 | 981 | if ($popup) $link .= '&nopopup=1'; |
982 | 982 | } |
983 | 983 | //error_log(__METHOD__."(..., $allow_popup, $receiver) returning ".array2string($allow_popup ? array($link,$popup) : $link)); |
984 | - return $allow_popup ? array($link,$popup) : $link; |
|
984 | + return $allow_popup ? array($link, $popup) : $link; |
|
985 | 985 | } |
986 | 986 | |
987 | 987 | /** |
@@ -992,18 +992,18 @@ discard block |
||
992 | 992 | * @param int|string $receiver nummeric account_id or email address |
993 | 993 | * @return array with link |
994 | 994 | */ |
995 | - protected function get_notification_link($data,$old,$receiver=null) |
|
995 | + protected function get_notification_link($data, $old, $receiver = null) |
|
996 | 996 | { |
997 | - unset($receiver); // not used, but required by function signature |
|
997 | + unset($receiver); // not used, but required by function signature |
|
998 | 998 | |
999 | - if (($view = Api\Link::view($this->app,$data[$this->id_field]))) |
|
999 | + if (($view = Api\Link::view($this->app, $data[$this->id_field]))) |
|
1000 | 1000 | { |
1001 | 1001 | return array( |
1002 | - 'text' => $this->get_title($data,$old), |
|
1002 | + 'text' => $this->get_title($data, $old), |
|
1003 | 1003 | 'app' => $this->app, |
1004 | 1004 | 'id' => $data[$this->id_field], |
1005 | 1005 | 'view' => $view, |
1006 | - 'popup' => Api\Link::is_popup($this->app,'view'), |
|
1006 | + 'popup' => Api\Link::is_popup($this->app, 'view'), |
|
1007 | 1007 | ); |
1008 | 1008 | } |
1009 | 1009 | return false; |
@@ -1019,15 +1019,15 @@ discard block |
||
1019 | 1019 | * @param int|string $receiver nummeric account_id or email address |
1020 | 1020 | * @return string |
1021 | 1021 | */ |
1022 | - public function get_body($html_email,$data,$old,$integrate_link = true,$receiver=null) |
|
1022 | + public function get_body($html_email, $data, $old, $integrate_link = true, $receiver = null) |
|
1023 | 1023 | { |
1024 | 1024 | $body = ''; |
1025 | - if($this->get_config(self::CUSTOM_NOTIFICATION, $data, $old)) |
|
1025 | + if ($this->get_config(self::CUSTOM_NOTIFICATION, $data, $old)) |
|
1026 | 1026 | { |
1027 | - $body = $this->get_custom_message($data,$old,null,$receiver); |
|
1028 | - if(($sig = $this->get_signature($data,$old,$receiver))) |
|
1027 | + $body = $this->get_custom_message($data, $old, null, $receiver); |
|
1028 | + if (($sig = $this->get_signature($data, $old, $receiver))) |
|
1029 | 1029 | { |
1030 | - $body .= ($html_email ? '<br />':'') . "\n$sig"; |
|
1030 | + $body .= ($html_email ? '<br />' : '')."\n$sig"; |
|
1031 | 1031 | } |
1032 | 1032 | return $body; |
1033 | 1033 | } |
@@ -1036,35 +1036,35 @@ discard block |
||
1036 | 1036 | $body = '<table cellspacing="2" cellpadding="0" border="0" width="100%">'."\n"; |
1037 | 1037 | } |
1038 | 1038 | // new or modified message |
1039 | - if (($message = $this->get_message($data,$old,$receiver))) |
|
1039 | + if (($message = $this->get_message($data, $old, $receiver))) |
|
1040 | 1040 | { |
1041 | 1041 | foreach ((array)$message as $_message) |
1042 | 1042 | { |
1043 | - $body .= $this->format_line($html_email,'message',false,($_message=='---'?($html_email?'<hr/>':$_message):$_message)); |
|
1043 | + $body .= $this->format_line($html_email, 'message', false, ($_message == '---' ? ($html_email ? '<hr/>' : $_message) : $_message)); |
|
1044 | 1044 | } |
1045 | 1045 | } |
1046 | - if ($integrate_link && ($link = $this->get_link($data,$old,false,$receiver))) |
|
1046 | + if ($integrate_link && ($link = $this->get_link($data, $old, false, $receiver))) |
|
1047 | 1047 | { |
1048 | - $body .= $this->format_line($html_email,'link',false,$integrate_link === true ? lang('You can respond by visiting:') : $integrate_link,$link); |
|
1048 | + $body .= $this->format_line($html_email, 'link', false, $integrate_link === true ? lang('You can respond by visiting:') : $integrate_link, $link); |
|
1049 | 1049 | } |
1050 | - foreach($this->get_details($data,$receiver) as $name => $detail) |
|
1050 | + foreach ($this->get_details($data, $receiver) as $name => $detail) |
|
1051 | 1051 | { |
1052 | 1052 | // if there's no old entry, the entry is not modified by definition |
1053 | 1053 | // if both values are '', 0 or null, we count them as equal too |
1054 | 1054 | $modified = $old && $data[$name] != $old[$name] && !(!$data[$name] && !$old[$name]); |
1055 | 1055 | //if ($modified) error_log("data[$name]=".print_r($data[$name],true).", old[$name]=".print_r($old[$name],true)." --> modified=".(int)$modified); |
1056 | - if (empty($detail['value']) && !$modified) continue; // skip unchanged, empty values |
|
1056 | + if (empty($detail['value']) && !$modified) continue; // skip unchanged, empty values |
|
1057 | 1057 | |
1058 | - $body .= $this->format_line($html_email,$detail['type'],$modified, |
|
1058 | + $body .= $this->format_line($html_email, $detail['type'], $modified, |
|
1059 | 1059 | $detail['label'] ? $detail['label'] : '', $detail['value']); |
1060 | 1060 | } |
1061 | 1061 | if ($html_email) |
1062 | 1062 | { |
1063 | 1063 | $body .= "</table>\n"; |
1064 | 1064 | } |
1065 | - if(($sig = $this->get_signature($data,$old,$receiver))) |
|
1065 | + if (($sig = $this->get_signature($data, $old, $receiver))) |
|
1066 | 1066 | { |
1067 | - $body .= ($html_email ? '<br />':'') . "\n$sig"; |
|
1067 | + $body .= ($html_email ? '<br />' : '')."\n$sig"; |
|
1068 | 1068 | } |
1069 | 1069 | if (!$html_email && $data['tr_edit_mode'] == 'html') |
1070 | 1070 | { |
@@ -1084,20 +1084,20 @@ discard block |
||
1084 | 1084 | * @param string $data = null data or null to display just $line over 2 columns |
1085 | 1085 | * @return string |
1086 | 1086 | */ |
1087 | - protected function format_line($html_mail,$type,$modified,$line,$data=null) |
|
1087 | + protected function format_line($html_mail, $type, $modified, $line, $data = null) |
|
1088 | 1088 | { |
1089 | 1089 | //error_log(__METHOD__.'('.array2string($html_mail).",'$type',".array2string($modified).",'$line',".array2string($data).')'); |
1090 | 1090 | $content = ''; |
1091 | 1091 | |
1092 | 1092 | if ($html_mail) |
1093 | 1093 | { |
1094 | - if (!$this->html_content_allow) $line = Api\Html::htmlspecialchars($line); // XSS |
|
1094 | + if (!$this->html_content_allow) $line = Api\Html::htmlspecialchars($line); // XSS |
|
1095 | 1095 | |
1096 | 1096 | $color = $modified ? 'red' : false; |
1097 | 1097 | $size = '110%'; |
1098 | 1098 | $bold = false; |
1099 | 1099 | $background = '#FFFFF1'; |
1100 | - switch($type) |
|
1100 | + switch ($type) |
|
1101 | 1101 | { |
1102 | 1102 | case 'message': |
1103 | 1103 | $background = '#D3DCE3;'; |
@@ -1115,7 +1115,7 @@ discard block |
||
1115 | 1115 | if (strpos($data, '<br') === false) |
1116 | 1116 | { |
1117 | 1117 | $data = nl2br($this->html_content_allow ? $data : Api\Html::htmlspecialchars($data)); |
1118 | - $this->html_content_allow = true; // to NOT do htmlspecialchars again |
|
1118 | + $this->html_content_allow = true; // to NOT do htmlspecialchars again |
|
1119 | 1119 | } |
1120 | 1120 | break; |
1121 | 1121 | case 'reply': |
@@ -1124,13 +1124,13 @@ discard block |
||
1124 | 1124 | default: |
1125 | 1125 | $size = false; |
1126 | 1126 | } |
1127 | - $style = ($bold ? 'font-weight:bold;' : '').($size ? 'font-size:'.$size.';' : '').($color?'color:'.$color:''); |
|
1127 | + $style = ($bold ? 'font-weight:bold;' : '').($size ? 'font-size:'.$size.';' : '').($color ? 'color:'.$color : ''); |
|
1128 | 1128 | |
1129 | - $content = '<tr style="background-color: '.$background.';"><td style="'.$style.($line && $data?'" width="20%':'" colspan="2').'">'; |
|
1129 | + $content = '<tr style="background-color: '.$background.';"><td style="'.$style.($line && $data ? '" width="20%' : '" colspan="2').'">'; |
|
1130 | 1130 | } |
1131 | 1131 | else // text-mail |
1132 | 1132 | { |
1133 | - if ($type == 'reply') $content = str_repeat('-',64)."\n"; |
|
1133 | + if ($type == 'reply') $content = str_repeat('-', 64)."\n"; |
|
1134 | 1134 | |
1135 | 1135 | if ($modified) $content .= '> '; |
1136 | 1136 | } |
@@ -1142,7 +1142,7 @@ discard block |
||
1142 | 1142 | if ($type == 'link') |
1143 | 1143 | { |
1144 | 1144 | // the link is often too long for html boxes chunk-split allows to break lines if needed |
1145 | - $content .= Api\Html::a_href(chunk_split(rawurldecode($data),40,'​'),$data,'','target="_blank"'); |
|
1145 | + $content .= Api\Html::a_href(chunk_split(rawurldecode($data), 40, '​'), $data, '', 'target="_blank"'); |
|
1146 | 1146 | } |
1147 | 1147 | elseif ($this->html_content_allow) |
1148 | 1148 | { |
@@ -1155,7 +1155,7 @@ discard block |
||
1155 | 1155 | } |
1156 | 1156 | else |
1157 | 1157 | { |
1158 | - $content .= ($content&&$data?': ':'').$data; |
|
1158 | + $content .= ($content && $data ? ': ' : '').$data; |
|
1159 | 1159 | } |
1160 | 1160 | if ($html_mail) $content .= '</td></tr>'; |
1161 | 1161 | |
@@ -1172,9 +1172,9 @@ discard block |
||
1172 | 1172 | * @param int|string $receiver nummeric account_id or email address |
1173 | 1173 | * @return array or array with values for either 'string' or 'path' and optionally (mime-)'type', 'filename' and 'encoding' |
1174 | 1174 | */ |
1175 | - protected function get_attachments($data,$old,$receiver=null) |
|
1175 | + protected function get_attachments($data, $old, $receiver = null) |
|
1176 | 1176 | { |
1177 | - unset($data, $old, $receiver); // not used, but required by function signature |
|
1177 | + unset($data, $old, $receiver); // not used, but required by function signature |
|
1178 | 1178 | |
1179 | 1179 | return array(); |
1180 | 1180 | } |
@@ -1187,20 +1187,20 @@ discard block |
||
1187 | 1187 | */ |
1188 | 1188 | protected function get_signature($data, $old, $receiver) |
1189 | 1189 | { |
1190 | - unset($old, $receiver); // not used, but required by function signature |
|
1190 | + unset($old, $receiver); // not used, but required by function signature |
|
1191 | 1191 | |
1192 | 1192 | $config = Api\Config::read('notifications'); |
1193 | - if(!isset($data[$this->id_field])) |
|
1193 | + if (!isset($data[$this->id_field])) |
|
1194 | 1194 | { |
1195 | - error_log($this->app . ' did not properly implement bo_tracking->id_field. Merge skipped.'); |
|
1195 | + error_log($this->app.' did not properly implement bo_tracking->id_field. Merge skipped.'); |
|
1196 | 1196 | } |
1197 | - elseif(class_exists($this->app. '_merge')) |
|
1197 | + elseif (class_exists($this->app.'_merge')) |
|
1198 | 1198 | { |
1199 | 1199 | $merge_class = $this->app.'_merge'; |
1200 | 1200 | $merge = new $merge_class(); |
1201 | 1201 | $error = null; |
1202 | 1202 | $sig = $merge->merge_string($config['signature'], array($data[$this->id_field]), $error, 'text/html'); |
1203 | - if($error) |
|
1203 | + if ($error) |
|
1204 | 1204 | { |
1205 | 1205 | error_log($error); |
1206 | 1206 | return $config['signature']; |
@@ -1217,7 +1217,7 @@ discard block |
||
1217 | 1217 | protected function get_custom_message($data, $old, $merge_class = null, $receiver = false) |
1218 | 1218 | { |
1219 | 1219 | $message = $this->get_config(self::CUSTOM_NOTIFICATION, $data, $old); |
1220 | - if(!$message) |
|
1220 | + if (!$message) |
|
1221 | 1221 | { |
1222 | 1222 | return ''; |
1223 | 1223 | } |
@@ -1226,21 +1226,21 @@ discard block |
||
1226 | 1226 | $message = $this->sanitize_custom_message($message, $receiver); |
1227 | 1227 | |
1228 | 1228 | // Automatically set merge class from naming conventions |
1229 | - if($merge_class == null) |
|
1229 | + if ($merge_class == null) |
|
1230 | 1230 | { |
1231 | 1231 | $merge_class = $this->app.'_merge'; |
1232 | 1232 | } |
1233 | - if(!isset($data[$this->id_field])) |
|
1233 | + if (!isset($data[$this->id_field])) |
|
1234 | 1234 | { |
1235 | - error_log($this->app . ' did not properly implement bo_tracking->id_field. Merge skipped.'); |
|
1235 | + error_log($this->app.' did not properly implement bo_tracking->id_field. Merge skipped.'); |
|
1236 | 1236 | return $message; |
1237 | 1237 | } |
1238 | - elseif(class_exists($merge_class)) |
|
1238 | + elseif (class_exists($merge_class)) |
|
1239 | 1239 | { |
1240 | 1240 | $merge = new $merge_class(); |
1241 | 1241 | $error = null; |
1242 | 1242 | $merged_message = $merge->merge_string($message, array($data[$this->id_field]), $error, 'text/html'); |
1243 | - if($error) |
|
1243 | + if ($error) |
|
1244 | 1244 | { |
1245 | 1245 | error_log($error); |
1246 | 1246 | return $message; |
@@ -1262,7 +1262,7 @@ discard block |
||
1262 | 1262 | */ |
1263 | 1263 | protected function sanitize_custom_message($message, $receiver) |
1264 | 1264 | { |
1265 | - if(!is_numeric($receiver)) |
|
1265 | + if (!is_numeric($receiver)) |
|
1266 | 1266 | { |
1267 | 1267 | $receiver = false; |
1268 | 1268 | } |
@@ -1272,14 +1272,14 @@ discard block |
||
1272 | 1272 | |
1273 | 1273 | // If we have a specific user and they're the same then there are |
1274 | 1274 | // no private fields so nothing needs to be done |
1275 | - if($receiver && $all_cfs == $cfs) |
|
1275 | + if ($receiver && $all_cfs == $cfs) |
|
1276 | 1276 | { |
1277 | 1277 | return $message; |
1278 | 1278 | } |
1279 | 1279 | |
1280 | 1280 | // Replace any placeholders that use the private field, or any sub-keys |
1281 | 1281 | // of the field |
1282 | - foreach($all_cfs as $name => $field) |
|
1282 | + foreach ($all_cfs as $name => $field) |
|
1283 | 1283 | { |
1284 | 1284 | if ($receiver === false && $field['private'] || !$cfs[$name]) |
1285 | 1285 | { |
@@ -742,7 +742,7 @@ |
||
742 | 742 | * |
743 | 743 | * @param string $app application name |
744 | 744 | * @param string $lang language code |
745 | - * @return the full path of the filename for the requested app and language |
|
745 | + * @return string full path of the filename for the requested app and language |
|
746 | 746 | */ |
747 | 747 | static function get_lang_file($app,$lang) |
748 | 748 | { |
@@ -738,12 +738,12 @@ discard block |
||
738 | 738 | } |
739 | 739 | |
740 | 740 | /** |
741 | - * provides centralization and compatibility to locate the lang files |
|
742 | - * |
|
743 | - * @param string $app application name |
|
744 | - * @param string $lang language code |
|
745 | - * @return the full path of the filename for the requested app and language |
|
746 | - */ |
|
741 | + * provides centralization and compatibility to locate the lang files |
|
742 | + * |
|
743 | + * @param string $app application name |
|
744 | + * @param string $lang language code |
|
745 | + * @return the full path of the filename for the requested app and language |
|
746 | + */ |
|
747 | 747 | static function get_lang_file($app,$lang) |
748 | 748 | { |
749 | 749 | if ($app == 'common') $app = 'phpgwapi'; |
@@ -1074,13 +1074,13 @@ discard block |
||
1074 | 1074 | } |
1075 | 1075 | |
1076 | 1076 | /** |
1077 | - * detect_encoding - try to detect the encoding |
|
1078 | - * only to be used if the string in question has no structure that determines his encoding |
|
1079 | - * |
|
1080 | - * @param string - to be evaluated |
|
1081 | - * @param string $verify =null encoding to verify, get checked first and have a match for only ascii or no detection available |
|
1082 | - * @return string - encoding |
|
1083 | - */ |
|
1077 | + * detect_encoding - try to detect the encoding |
|
1078 | + * only to be used if the string in question has no structure that determines his encoding |
|
1079 | + * |
|
1080 | + * @param string - to be evaluated |
|
1081 | + * @param string $verify =null encoding to verify, get checked first and have a match for only ascii or no detection available |
|
1082 | + * @return string - encoding |
|
1083 | + */ |
|
1084 | 1084 | static function detect_encoding($string, $verify=null) |
1085 | 1085 | { |
1086 | 1086 | if (function_exists('iconv')) |
@@ -126,17 +126,23 @@ discard block |
||
126 | 126 | } |
127 | 127 | return $charsets[$lang]; |
128 | 128 | } |
129 | - if (self::$system_charset) // do we have a system-charset ==> return it |
|
129 | + if (self::$system_charset) |
|
130 | + { |
|
131 | + // do we have a system-charset ==> return it |
|
130 | 132 | { |
131 | 133 | $charset = self::$system_charset; |
132 | 134 | } |
135 | + } |
|
133 | 136 | else |
134 | 137 | { |
135 | 138 | // if no translations are loaded (system-startup) use a default, else lang('charset') |
136 | 139 | $charset = !self::$lang_arr ? 'utf-8' : strtolower(self::translate('charset')); |
137 | 140 | } |
138 | 141 | // in case no charset is set, default to utf-8 |
139 | - if (empty($charset) || $charset == 'charset') $charset = 'utf-8'; |
|
142 | + if (empty($charset) || $charset == 'charset') |
|
143 | + { |
|
144 | + $charset = 'utf-8'; |
|
145 | + } |
|
140 | 146 | |
141 | 147 | // we need to set our charset as mbstring.internal_encoding if mbstring.func_overlaod > 0 |
142 | 148 | // else we get problems for a charset is different from the default utf-8 |
@@ -195,8 +201,14 @@ discard block |
||
195 | 201 | } |
196 | 202 | $apps = array('common'); |
197 | 203 | // for eTemplate apps, load etemplate before app itself (allowing app to overwrite etemplate translations) |
198 | - if (class_exists('EGroupware\\Api\\Etemplate', false) || class_exists('etemplate', false)) $apps[] = 'etemplate'; |
|
199 | - if ($GLOBALS['egw_info']['flags']['currentapp']) $apps[] = $GLOBALS['egw_info']['flags']['currentapp']; |
|
204 | + if (class_exists('EGroupware\\Api\\Etemplate', false) || class_exists('etemplate', false)) |
|
205 | + { |
|
206 | + $apps[] = 'etemplate'; |
|
207 | + } |
|
208 | + if ($GLOBALS['egw_info']['flags']['currentapp']) |
|
209 | + { |
|
210 | + $apps[] = $GLOBALS['egw_info']['flags']['currentapp']; |
|
211 | + } |
|
200 | 212 | // load instance specific translations last, so they can overwrite everything |
201 | 213 | $apps[] = 'custom'; |
202 | 214 | self::add_app($apps); |
@@ -224,7 +236,10 @@ discard block |
||
224 | 236 | self::init(); |
225 | 237 | } |
226 | 238 | $ret = $key; // save key if we dont find a translation |
227 | - if ($not_found) $ret .= $not_found; |
|
239 | + if ($not_found) |
|
240 | + { |
|
241 | + $ret .= $not_found; |
|
242 | + } |
|
228 | 243 | |
229 | 244 | if (isset(self::$lang_arr[$key])) |
230 | 245 | { |
@@ -271,9 +286,15 @@ discard block |
||
271 | 286 | { |
272 | 287 | //error_log(__METHOD__."(".array2string($apps).", $lang) count(self::\$lang_arr)=".count(self::$lang_arr)); |
273 | 288 | //$start = microtime(true); |
274 | - if (!$lang) $lang = self::$userlang; |
|
289 | + if (!$lang) |
|
290 | + { |
|
291 | + $lang = self::$userlang; |
|
292 | + } |
|
275 | 293 | $tree_level = $instance_level = array(); |
276 | - if (!is_array($apps)) $apps = (array)$apps; |
|
294 | + if (!is_array($apps)) |
|
295 | + { |
|
296 | + $apps = (array)$apps; |
|
297 | + } |
|
277 | 298 | foreach($apps as $key => $app) |
278 | 299 | { |
279 | 300 | if (!isset(self::$loaded_apps[$app]) || self::$loaded_apps[$app] != $lang && $app != 'common') |
@@ -293,8 +314,14 @@ discard block |
||
293 | 314 | } |
294 | 315 | } |
295 | 316 | // load all translations from cache at once |
296 | - if ($tree_level) $tree_level = Cache::getTree(__CLASS__, $tree_level); |
|
297 | - if ($instance_level) $instance_level = Cache::getInstance(__CLASS__, $instance_level); |
|
317 | + if ($tree_level) |
|
318 | + { |
|
319 | + $tree_level = Cache::getTree(__CLASS__, $tree_level); |
|
320 | + } |
|
321 | + if ($instance_level) |
|
322 | + { |
|
323 | + $instance_level = Cache::getInstance(__CLASS__, $instance_level); |
|
324 | + } |
|
298 | 325 | |
299 | 326 | // merging loaded translations together |
300 | 327 | $updated_load_via = false; |
@@ -361,7 +388,10 @@ discard block |
||
361 | 388 | static function &load_app($app,$lang) |
362 | 389 | { |
363 | 390 | //$start = microtime(true); |
364 | - if (is_null(self::$db)) self::init(false); |
|
391 | + if (is_null(self::$db)) |
|
392 | + { |
|
393 | + self::init(false); |
|
394 | + } |
|
365 | 395 | $loaded = array(); |
366 | 396 | foreach(self::$db->select(self::LANG_TABLE,'message_id,content',array( |
367 | 397 | 'lang' => $lang, |
@@ -467,7 +497,10 @@ discard block |
||
467 | 497 | $cache['']['en'] = count($en_phrases); |
468 | 498 | foreach(array_keys(self::get_available_langs()) as $lang) |
469 | 499 | { |
470 | - if ($lang == 'en') continue; |
|
500 | + if ($lang == 'en') |
|
501 | + { |
|
502 | + continue; |
|
503 | + } |
|
471 | 504 | $lang_phrases = array_keys(self::load_app_files(null, $lang, 'all-apps')); |
472 | 505 | $valid_phrases = array_intersect($lang_phrases, $en_phrases); |
473 | 506 | $cache[''][$lang] = count($valid_phrases); |
@@ -484,7 +517,10 @@ discard block |
||
484 | 517 | continue; |
485 | 518 | } |
486 | 519 | $en_phrases = array_keys(self::load_app_files(null, 'en', $app)); |
487 | - if (count($en_phrases) <= 2) continue; |
|
520 | + if (count($en_phrases) <= 2) |
|
521 | + { |
|
522 | + continue; |
|
523 | + } |
|
488 | 524 | $cache['en'][$app] = count($en_phrases); |
489 | 525 | $lang_phrases = array_keys(self::load_app_files(null, $_lang, $app)); |
490 | 526 | $valid_phrases = array_intersect($lang_phrases, $en_phrases); |
@@ -516,7 +552,10 @@ discard block |
||
516 | 552 | // check if cache is NOT invalided by checking if we have a modification time for concerned lang-file |
517 | 553 | $time = Cache::getTree(__CLASS__, $file=self::get_lang_file($_app, $_lang)); |
518 | 554 | // if we dont have one, cache has been invalidated and we need to load translations |
519 | - if (!isset($time)) self::add_app($_app, $_lang); |
|
555 | + if (!isset($time)) |
|
556 | + { |
|
557 | + self::add_app($_app, $_lang); |
|
558 | + } |
|
520 | 559 | |
521 | 560 | $etag = self::max_lang_time(); |
522 | 561 | } |
@@ -568,7 +607,11 @@ discard block |
||
568 | 607 | $loaded = array(); |
569 | 608 | foreach($load_app == 'all-apps' ? scandir(EGW_SERVER_ROOT) : (array)$load_app as $app_dir) |
570 | 609 | { |
571 | - if ($load_app == 'all-apps' && $app_dir=='..') continue; // do not try to break out of egw server root |
|
610 | + if ($load_app == 'all-apps' && $app_dir=='..') |
|
611 | + { |
|
612 | + continue; |
|
613 | + } |
|
614 | + // do not try to break out of egw server root |
|
572 | 615 | if ($app_dir[0] == '.' || !is_dir(EGW_SERVER_ROOT.'/'.$app_dir) || |
573 | 616 | !@file_exists($file=self::get_lang_file($app_dir, $lang)) || |
574 | 617 | !($f = fopen($file, 'r'))) |
@@ -587,9 +630,15 @@ discard block |
||
587 | 630 | { |
588 | 631 | $line = explode("\t", trim($read)); |
589 | 632 | ++$line_nr; |
590 | - if (count($line) != 4) continue; |
|
633 | + if (count($line) != 4) |
|
634 | + { |
|
635 | + continue; |
|
636 | + } |
|
591 | 637 | list($l_id,$l_app,$l_lang,$l_translation) = $line; |
592 | - if ($l_lang != $lang) continue; |
|
638 | + if ($l_lang != $lang) |
|
639 | + { |
|
640 | + continue; |
|
641 | + } |
|
593 | 642 | if (!isset($just_app_file) && $l_app != $app) |
594 | 643 | { |
595 | 644 | // check if $l_app contained in file in $app_dir is mentioned in $load_via |
@@ -603,8 +652,14 @@ discard block |
||
603 | 652 | } |
604 | 653 | // if not update load_via accordingly and store it as config |
605 | 654 | //error_log(__METHOD__."() load_via does not contain $l_app => $app_dir"); |
606 | - if (!isset(self::$load_via[$l_app])) self::$load_via[$l_app] = array($l_app); |
|
607 | - if (!is_array(self::$load_via[$l_app])) self::$load_via[$l_app] = array(self::$load_via[$l_app]); |
|
655 | + if (!isset(self::$load_via[$l_app])) |
|
656 | + { |
|
657 | + self::$load_via[$l_app] = array($l_app); |
|
658 | + } |
|
659 | + if (!is_array(self::$load_via[$l_app])) |
|
660 | + { |
|
661 | + self::$load_via[$l_app] = array(self::$load_via[$l_app]); |
|
662 | + } |
|
608 | 663 | self::$load_via[$l_app][] = $app_dir; |
609 | 664 | $updated_load_via = true; |
610 | 665 | } |
@@ -671,7 +726,10 @@ discard block |
||
671 | 726 | |
672 | 727 | if ($translate) |
673 | 728 | { |
674 | - if (is_null(self::$db)) self::init(false); |
|
729 | + if (is_null(self::$db)) |
|
730 | + { |
|
731 | + self::init(false); |
|
732 | + } |
|
675 | 733 | |
676 | 734 | foreach(self::$langs as $lang => $name) |
677 | 735 | { |
@@ -704,10 +762,13 @@ discard block |
||
704 | 762 | */ |
705 | 763 | static function lang2language($lang) |
706 | 764 | { |
707 | - if (isset(self::$langs[$lang])) // no need to query the DB |
|
765 | + if (isset(self::$langs[$lang])) |
|
766 | + { |
|
767 | + // no need to query the DB |
|
708 | 768 | { |
709 | 769 | return self::$langs[$lang]; |
710 | 770 | } |
771 | + } |
|
711 | 772 | return self::$db->select(self::LANGUAGES_TABLE,'lang_name',array('lang_id' => $lang),__LINE__,__FILE__)->fetchColumn(); |
712 | 773 | } |
713 | 774 | |
@@ -746,7 +807,10 @@ discard block |
||
746 | 807 | */ |
747 | 808 | static function get_lang_file($app,$lang) |
748 | 809 | { |
749 | - if ($app == 'common') $app = 'phpgwapi'; |
|
810 | + if ($app == 'common') |
|
811 | + { |
|
812 | + $app = 'phpgwapi'; |
|
813 | + } |
|
750 | 814 | return EGW_SERVER_ROOT.'/'.$app.'/'.self::LANG_DIR.'/'.self::LANGFILE_PREFIX.$lang.self::LANGFILE_EXTENSION; |
751 | 815 | } |
752 | 816 | |
@@ -809,9 +873,15 @@ discard block |
||
809 | 873 | { |
810 | 874 | if ($check_to_from) |
811 | 875 | { |
812 | - if ($from) $from = strtolower($from); |
|
876 | + if ($from) |
|
877 | + { |
|
878 | + $from = strtolower($from); |
|
879 | + } |
|
813 | 880 | |
814 | - if ($to) $to = strtolower($to); |
|
881 | + if ($to) |
|
882 | + { |
|
883 | + $to = strtolower($to); |
|
884 | + } |
|
815 | 885 | |
816 | 886 | if (!$from) |
817 | 887 | { |
@@ -936,7 +1006,10 @@ discard block |
||
936 | 1006 | */ |
937 | 1007 | static function convert_jsonsafe($_data,$from=False) |
938 | 1008 | { |
939 | - if ($from===false) $from = self::detect_encoding($_data); |
|
1009 | + if ($from===false) |
|
1010 | + { |
|
1011 | + $from = self::detect_encoding($_data); |
|
1012 | + } |
|
940 | 1013 | |
941 | 1014 | $data = self::convert($_data, strtolower($from)); |
942 | 1015 | |
@@ -1035,15 +1108,22 @@ discard block |
||
1035 | 1108 | static function get_message_id($translation,$app=null,$lang=null) |
1036 | 1109 | { |
1037 | 1110 | $where = array('content '.self::$db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.self::$db->quote($translation)); |
1038 | - if ($app) $where['app_name'] = $app; |
|
1039 | - if ($lang) $where['lang'] = $lang; |
|
1111 | + if ($app) |
|
1112 | + { |
|
1113 | + $where['app_name'] = $app; |
|
1114 | + } |
|
1115 | + if ($lang) |
|
1116 | + { |
|
1117 | + $where['lang'] = $lang; |
|
1118 | + } |
|
1040 | 1119 | |
1041 | 1120 | $id = self::$db->select(self::LANG_TABLE,'message_id',$where,__LINE__,__FILE__)->fetchColumn(); |
1042 | 1121 | |
1043 | 1122 | // Check cache, since most things aren't in the DB anymore |
1044 | 1123 | if(!$id) |
1045 | 1124 | { |
1046 | - $ids = array_filter(array_keys(self::$lang_arr), function($haystack) use($translation) { |
|
1125 | + $ids = array_filter(array_keys(self::$lang_arr), function($haystack) use($translation) |
|
1126 | + { |
|
1047 | 1127 | return stripos(self::$lang_arr[$haystack],$translation) !== false; |
1048 | 1128 | }); |
1049 | 1129 | $id = array_shift($ids); |
@@ -1060,10 +1140,17 @@ discard block |
||
1060 | 1140 | } |
1061 | 1141 | |
1062 | 1142 | // load all translations from cache at once |
1063 | - if ($tree_level) $lang_arr = Cache::getTree(__CLASS__, $tree_level); |
|
1064 | - if ($instance_level) $lang_arr = Cache::getInstance(__CLASS__, $instance_level); |
|
1143 | + if ($tree_level) |
|
1144 | + { |
|
1145 | + $lang_arr = Cache::getTree(__CLASS__, $tree_level); |
|
1146 | + } |
|
1147 | + if ($instance_level) |
|
1148 | + { |
|
1149 | + $lang_arr = Cache::getInstance(__CLASS__, $instance_level); |
|
1150 | + } |
|
1065 | 1151 | $lang_arr = $lang_arr[$app.':en']; |
1066 | - $ids = array_filter(array_keys($lang_arr), function($haystack) use($translation, $lang_arr) { |
|
1152 | + $ids = array_filter(array_keys($lang_arr), function($haystack) use($translation, $lang_arr) |
|
1153 | + { |
|
1067 | 1154 | return stripos($lang_arr[$haystack],$translation) !== false; |
1068 | 1155 | }); |
1069 | 1156 | $id = array_shift($ids); |
@@ -1087,7 +1174,10 @@ discard block |
||
1087 | 1174 | { |
1088 | 1175 | $list = array('utf-8', 'iso-8859-1', 'windows-1251'); // list may be extended |
1089 | 1176 | |
1090 | - if ($verify) array_unshift($list, $verify); |
|
1177 | + if ($verify) |
|
1178 | + { |
|
1179 | + array_unshift($list, $verify); |
|
1180 | + } |
|
1091 | 1181 | |
1092 | 1182 | foreach ($list as $item) |
1093 | 1183 | { |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * |
100 | 100 | * @var array |
101 | 101 | */ |
102 | - static $instance_specific_translations = array('loginscreen','mainscreen','custom'); |
|
102 | + static $instance_specific_translations = array('loginscreen', 'mainscreen', 'custom'); |
|
103 | 103 | |
104 | 104 | /** |
105 | 105 | * returns the charset to use (!$lang) or the charset of the lang-files or $lang |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | * @param string|boolean $lang =False return charset of the active user-lang, or $lang if specified |
108 | 108 | * @return string charset |
109 | 109 | */ |
110 | - static function charset($lang=False) |
|
110 | + static function charset($lang = False) |
|
111 | 111 | { |
112 | 112 | static $charsets = array(); |
113 | 113 | |
@@ -115,11 +115,11 @@ discard block |
||
115 | 115 | { |
116 | 116 | if (!isset($charsets[$lang])) |
117 | 117 | { |
118 | - if (!($charsets[$lang] = self::$db->select(self::LANG_TABLE,'content',array( |
|
118 | + if (!($charsets[$lang] = self::$db->select(self::LANG_TABLE, 'content', array( |
|
119 | 119 | 'lang' => $lang, |
120 | 120 | 'message_id'=> 'charset', |
121 | 121 | 'app_name' => 'common', |
122 | - ),__LINE__,__FILE__)->fetchColumn())) |
|
122 | + ), __LINE__, __FILE__)->fetchColumn())) |
|
123 | 123 | { |
124 | 124 | $charsets[$lang] = 'utf-8'; |
125 | 125 | } |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * |
154 | 154 | * @param boolean $load_translations =true should we also load translations for common and currentapp |
155 | 155 | */ |
156 | - static function init($load_translations=true) |
|
156 | + static function init($load_translations = true) |
|
157 | 157 | { |
158 | 158 | if (!isset(self::$db)) |
159 | 159 | { |
@@ -165,11 +165,11 @@ discard block |
||
165 | 165 | } |
166 | 166 | else |
167 | 167 | { |
168 | - self::$system_charset =& $GLOBALS['egw_setup']->system_charset; |
|
168 | + self::$system_charset = & $GLOBALS['egw_setup']->system_charset; |
|
169 | 169 | } |
170 | 170 | if ((self::$mbstring = check_load_extension('mbstring'))) |
171 | 171 | { |
172 | - if(!empty(self::$system_charset)) |
|
172 | + if (!empty(self::$system_charset)) |
|
173 | 173 | { |
174 | 174 | $ini_default_charset = version_compare(PHP_VERSION, '5.6', '<') ? 'mbstring.internal_encoding' : 'default_charset'; |
175 | 175 | ini_set($ini_default_charset, self::$system_charset); |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | |
179 | 179 | // try loading load_via from tree-wide cache and check if it contains more rules |
180 | 180 | if (($load_via = Cache::getTree(__CLASS__, 'load_via')) && |
181 | - $load_via >= self::$load_via && // > for array --> contains more elements |
|
181 | + $load_via >= self::$load_via && // > for array --> contains more elements |
|
182 | 182 | // little sanity check: cached array contains all stock keys, otherwise ignore it |
183 | 183 | !array_diff_key(self::$load_via, $load_via)) |
184 | 184 | { |
@@ -217,13 +217,13 @@ discard block |
||
217 | 217 | * @param string $not_found ='*' what to add to not found phrases, default '*' |
218 | 218 | * @return string with translation |
219 | 219 | */ |
220 | - static function translate($key, $vars=null, $not_found='' ) |
|
220 | + static function translate($key, $vars = null, $not_found = '') |
|
221 | 221 | { |
222 | 222 | if (!self::$lang_arr) |
223 | 223 | { |
224 | 224 | self::init(); |
225 | 225 | } |
226 | - $ret = $key; // save key if we dont find a translation |
|
226 | + $ret = $key; // save key if we dont find a translation |
|
227 | 227 | if ($not_found) $ret .= $not_found; |
228 | 228 | |
229 | 229 | if (isset(self::$lang_arr[$key])) |
@@ -243,16 +243,16 @@ discard block |
||
243 | 243 | { |
244 | 244 | if (count($vars) > 1) |
245 | 245 | { |
246 | - static $placeholders = array('%3','%2','%1','|%2|','|%3|','%4','%5','%6','%7','%8','%9','%10'); |
|
246 | + static $placeholders = array('%3', '%2', '%1', '|%2|', '|%3|', '%4', '%5', '%6', '%7', '%8', '%9', '%10'); |
|
247 | 247 | // to cope with $vars[0] containing '%2' (eg. an urlencoded path like a referer), |
248 | 248 | // we first replace '%2' in $ret with '|%2|' and then use that as 2. placeholder |
249 | 249 | // we do that for %3 as well, ... |
250 | - $vars = array_merge(array('|%3|','|%2|'),$vars); // push '|%2|' (and such) as first replacement on $vars |
|
251 | - $ret = str_replace($placeholders,$vars,$ret); |
|
250 | + $vars = array_merge(array('|%3|', '|%2|'), $vars); // push '|%2|' (and such) as first replacement on $vars |
|
251 | + $ret = str_replace($placeholders, $vars, $ret); |
|
252 | 252 | } |
253 | 253 | else |
254 | 254 | { |
255 | - $ret = str_replace('%1',$vars[0],$ret); |
|
255 | + $ret = str_replace('%1', $vars[0], $ret); |
|
256 | 256 | } |
257 | 257 | } |
258 | 258 | return $ret; |
@@ -267,14 +267,14 @@ discard block |
||
267 | 267 | * if multiple names given, they are requested in one request from cache and loaded in given order |
268 | 268 | * @param string $lang =false 2 or 5 char lang-code or false for the users language |
269 | 269 | */ |
270 | - static function add_app($apps, $lang=null) |
|
270 | + static function add_app($apps, $lang = null) |
|
271 | 271 | { |
272 | 272 | //error_log(__METHOD__."(".array2string($apps).", $lang) count(self::\$lang_arr)=".count(self::$lang_arr)); |
273 | 273 | //$start = microtime(true); |
274 | 274 | if (!$lang) $lang = self::$userlang; |
275 | 275 | $tree_level = $instance_level = array(); |
276 | 276 | if (!is_array($apps)) $apps = (array)$apps; |
277 | - foreach($apps as $key => $app) |
|
277 | + foreach ($apps as $key => $app) |
|
278 | 278 | { |
279 | 279 | if (!isset(self::$loaded_apps[$app]) || self::$loaded_apps[$app] != $lang && $app != 'common') |
280 | 280 | { |
@@ -298,26 +298,26 @@ discard block |
||
298 | 298 | |
299 | 299 | // merging loaded translations together |
300 | 300 | $updated_load_via = false; |
301 | - foreach((array)$apps as $app) |
|
301 | + foreach ((array)$apps as $app) |
|
302 | 302 | { |
303 | 303 | $l = $app == 'custom' ? 'en' : $lang; |
304 | 304 | if (isset($tree_level[$app.':'.$l])) |
305 | 305 | { |
306 | - $loaded =& $tree_level[$app.':'.$l]; |
|
306 | + $loaded = & $tree_level[$app.':'.$l]; |
|
307 | 307 | } |
308 | 308 | elseif (isset($instance_level[$app.':'.$l])) |
309 | 309 | { |
310 | - $loaded =& $instance_level[$app.':'.$l]; |
|
310 | + $loaded = & $instance_level[$app.':'.$l]; |
|
311 | 311 | } |
312 | 312 | else |
313 | 313 | { |
314 | 314 | if (($instance_specific = in_array($app, self::$instance_specific_translations))) |
315 | 315 | { |
316 | - $loaded =& self::load_app($app, $l); |
|
316 | + $loaded = & self::load_app($app, $l); |
|
317 | 317 | } |
318 | 318 | else |
319 | 319 | { |
320 | - $loaded =& self::load_app_files($app, $l, null, $updated_load_via); |
|
320 | + $loaded = & self::load_app_files($app, $l, null, $updated_load_via); |
|
321 | 321 | } |
322 | 322 | //error_log(__METHOD__."('$app', '$lang') instance_specific=$instance_specific, load_app(_files)() returned ".(is_array($loaded)?'Array('.count($loaded).')':array2string($loaded))); |
323 | 323 | if ($loaded || $instance_specific) |
@@ -330,14 +330,14 @@ discard block |
||
330 | 330 | if ($loaded) |
331 | 331 | { |
332 | 332 | self::$lang_arr = array_merge(self::$lang_arr, $loaded); |
333 | - self::$loaded_apps[$app] = $l; // dont set something not existing to $loaded_apps, no need to load client-side |
|
333 | + self::$loaded_apps[$app] = $l; // dont set something not existing to $loaded_apps, no need to load client-side |
|
334 | 334 | } |
335 | 335 | } |
336 | 336 | // Re-merge custom over instance level, they have higher precidence |
337 | - if($tree_level && !$instance_level && self::$instance_specific_translations) |
|
337 | + if ($tree_level && !$instance_level && self::$instance_specific_translations) |
|
338 | 338 | { |
339 | 339 | $custom = Cache::getInstance(__CLASS__, 'custom:en'); |
340 | - if($custom) |
|
340 | + if ($custom) |
|
341 | 341 | { |
342 | 342 | self::$lang_arr = array_merge(self::$lang_arr, $custom); |
343 | 343 | } |
@@ -358,15 +358,15 @@ discard block |
||
358 | 358 | * @param string $lang =false 2 or 5 char lang-code or false for the users language |
359 | 359 | * @return array the loaded strings |
360 | 360 | */ |
361 | - static function &load_app($app,$lang) |
|
361 | + static function &load_app($app, $lang) |
|
362 | 362 | { |
363 | 363 | //$start = microtime(true); |
364 | 364 | if (is_null(self::$db)) self::init(false); |
365 | 365 | $loaded = array(); |
366 | - foreach(self::$db->select(self::LANG_TABLE,'message_id,content',array( |
|
366 | + foreach (self::$db->select(self::LANG_TABLE, 'message_id,content', array( |
|
367 | 367 | 'lang' => $lang, |
368 | 368 | 'app_name' => $app, |
369 | - ),__LINE__,__FILE__) as $row) |
|
369 | + ), __LINE__, __FILE__) as $row) |
|
370 | 370 | { |
371 | 371 | $loaded[strtolower($row['message_id'])] = $row['content']; |
372 | 372 | } |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | 'sitemgr-link' => array('sitemgr'), |
391 | 391 | 'groupdav' => array('api'), |
392 | 392 | 'developer_tools' => array('etemplate'), |
393 | - 'login' => array('api','registration'), |
|
393 | + 'login' => array('api', 'registration'), |
|
394 | 394 | ); |
395 | 395 | |
396 | 396 | /** |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | { |
403 | 403 | $lang = $GLOBALS['egw_info']['user']['preferences']['common']['lang']; |
404 | 404 | $apps = array_keys($GLOBALS['egw_info']['apps']); |
405 | - foreach($apps as $app) |
|
405 | + foreach ($apps as $app) |
|
406 | 406 | { |
407 | 407 | $file = self::get_lang_file($app, $lang); |
408 | 408 | // check if file has changed compared to what's cached |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | Cache::unsetTree(__CLASS__, $app.':'.$lang); |
433 | 433 | Cache::unsetTree(__CLASS__, self::get_lang_file($app, $lang)); |
434 | 434 | |
435 | - foreach(self::$load_via as $load => $via) |
|
435 | + foreach (self::$load_via as $load => $via) |
|
436 | 436 | { |
437 | 437 | //error_log("load_via[load='$load'] = via = ".array2string($via)); |
438 | 438 | if ($via === 'all-apps' || in_array($app, (array)$via)) |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | * @param string $_lang =null |
455 | 455 | * @return array $lang or $app => number pairs |
456 | 456 | */ |
457 | - static function statistics($_lang=null) |
|
457 | + static function statistics($_lang = null) |
|
458 | 458 | { |
459 | 459 | $cache = Cache::getTree(__CLASS__, 'statistics'); |
460 | 460 | |
@@ -465,7 +465,7 @@ discard block |
||
465 | 465 | { |
466 | 466 | $en_phrases = array_keys(self::load_app_files(null, 'en', 'all-apps')); |
467 | 467 | $cache['']['en'] = count($en_phrases); |
468 | - foreach(array_keys(self::get_available_langs()) as $lang) |
|
468 | + foreach (array_keys(self::get_available_langs()) as $lang) |
|
469 | 469 | { |
470 | 470 | if ($lang == 'en') continue; |
471 | 471 | $lang_phrases = array_keys(self::load_app_files(null, $lang, 'all-apps')); |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | else |
477 | 477 | { |
478 | 478 | $cache['en'] = array(); |
479 | - foreach(scandir(EGW_SERVER_ROOT) as $app) |
|
479 | + foreach (scandir(EGW_SERVER_ROOT) as $app) |
|
480 | 480 | { |
481 | 481 | if ($app[0] == '.' || !is_dir(EGW_SERVER_ROOT.'/'.$app) || |
482 | 482 | !file_exists(self::get_lang_file($app, 'en'))) |
@@ -514,7 +514,7 @@ discard block |
||
514 | 514 | if (!in_array($_app, self::$instance_specific_translations)) |
515 | 515 | { |
516 | 516 | // check if cache is NOT invalided by checking if we have a modification time for concerned lang-file |
517 | - $time = Cache::getTree(__CLASS__, $file=self::get_lang_file($_app, $_lang)); |
|
517 | + $time = Cache::getTree(__CLASS__, $file = self::get_lang_file($_app, $_lang)); |
|
518 | 518 | // if we dont have one, cache has been invalidated and we need to load translations |
519 | 519 | if (!isset($time)) self::add_app($_app, $_lang); |
520 | 520 | |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | * @param type $time |
535 | 535 | * @return type |
536 | 536 | */ |
537 | - static function max_lang_time($time=null) |
|
537 | + static function max_lang_time($time = null) |
|
538 | 538 | { |
539 | 539 | static $max_lang_time = null; |
540 | 540 | |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | if (isset($time) && $time > $max_lang_time) |
546 | 546 | { |
547 | 547 | //error_log(__METHOD__."($time) updating previous max_lang_time=$max_lang_time to $time"); |
548 | - Cache::setTree(__CLASS__, 'max_lang_time', $max_lang_time=$time); |
|
548 | + Cache::setTree(__CLASS__, 'max_lang_time', $max_lang_time = $time); |
|
549 | 549 | } |
550 | 550 | return $max_lang_time; |
551 | 551 | } |
@@ -561,34 +561,34 @@ discard block |
||
561 | 561 | * @param boolean $updated_load_via =false on return true if self::$load_via was updated |
562 | 562 | * @return array the loaded strings |
563 | 563 | */ |
564 | - static function &load_app_files($app, $lang, $just_app_file=null, &$updated_load_via=false) |
|
564 | + static function &load_app_files($app, $lang, $just_app_file = null, &$updated_load_via = false) |
|
565 | 565 | { |
566 | 566 | //$start = microtime(true); |
567 | 567 | $load_app = isset($just_app_file) ? $just_app_file : (isset(self::$load_via[$app]) ? self::$load_via[$app] : $app); |
568 | 568 | $loaded = array(); |
569 | - foreach($load_app == 'all-apps' ? scandir(EGW_SERVER_ROOT) : (array)$load_app as $app_dir) |
|
569 | + foreach ($load_app == 'all-apps' ? scandir(EGW_SERVER_ROOT) : (array)$load_app as $app_dir) |
|
570 | 570 | { |
571 | - if ($load_app == 'all-apps' && $app_dir=='..') continue; // do not try to break out of egw server root |
|
571 | + if ($load_app == 'all-apps' && $app_dir == '..') continue; // do not try to break out of egw server root |
|
572 | 572 | if ($app_dir[0] == '.' || !is_dir(EGW_SERVER_ROOT.'/'.$app_dir) || |
573 | - !@file_exists($file=self::get_lang_file($app_dir, $lang)) || |
|
573 | + !@file_exists($file = self::get_lang_file($app_dir, $lang)) || |
|
574 | 574 | !($f = fopen($file, 'r'))) |
575 | 575 | { |
576 | 576 | continue; |
577 | 577 | } |
578 | 578 | // store ctime of file we parse |
579 | - Cache::setTree(__CLASS__, $file, $time=filemtime($file)); |
|
579 | + Cache::setTree(__CLASS__, $file, $time = filemtime($file)); |
|
580 | 580 | self::max_lang_time($time); |
581 | 581 | |
582 | 582 | $line_nr = 0; |
583 | 583 | //use fgets and split the line, as php5.3.3 with squeeze does not support splitting lines with fgetcsv while reading properly |
584 | 584 | //if the first letter after the delimiter is a german umlaut (UTF8 representation thereoff) |
585 | 585 | //while(($line = fgetcsv($f, 1024, "\t"))) |
586 | - while(($read = fgets($f))) |
|
586 | + while (($read = fgets($f))) |
|
587 | 587 | { |
588 | 588 | $line = explode("\t", trim($read)); |
589 | 589 | ++$line_nr; |
590 | 590 | if (count($line) != 4) continue; |
591 | - list($l_id,$l_app,$l_lang,$l_translation) = $line; |
|
591 | + list($l_id, $l_app, $l_lang, $l_translation) = $line; |
|
592 | 592 | if ($l_lang != $lang) continue; |
593 | 593 | if (!isset($just_app_file) && $l_app != $app) |
594 | 594 | { |
@@ -634,7 +634,7 @@ discard block |
||
634 | 634 | // little sanity check: cached array contains all stock keys, otherwise ignore it |
635 | 635 | !array_diff_key(self::$load_via, $load_via)) |
636 | 636 | { |
637 | - foreach($load_via as $app => $via) |
|
637 | + foreach ($load_via as $app => $via) |
|
638 | 638 | { |
639 | 639 | if (self::$load_via[$app] != $via) |
640 | 640 | { |
@@ -660,15 +660,15 @@ discard block |
||
660 | 660 | * @param boolean $force_read =false force a re-read of the languages |
661 | 661 | * @return array with lang-code => descriptiv lang-name pairs |
662 | 662 | */ |
663 | - static function get_available_langs($translate=true, $force_read=false) |
|
663 | + static function get_available_langs($translate = true, $force_read = false) |
|
664 | 664 | { |
665 | 665 | if (!is_array(self::$langs) || $force_read) |
666 | 666 | { |
667 | - if (!($f = fopen($file=EGW_SERVER_ROOT.'/setup/lang/languages','rb'))) |
|
667 | + if (!($f = fopen($file = EGW_SERVER_ROOT.'/setup/lang/languages', 'rb'))) |
|
668 | 668 | { |
669 | 669 | throw new Exception("List of available languages (%1) missing!", $file); |
670 | 670 | } |
671 | - while(($line = fgetcsv($f, null, "\t"))) |
|
671 | + while (($line = fgetcsv($f, null, "\t"))) |
|
672 | 672 | { |
673 | 673 | self::$langs[$line[0]] = $line[1]; |
674 | 674 | } |
@@ -678,12 +678,12 @@ discard block |
||
678 | 678 | { |
679 | 679 | if (is_null(self::$db)) self::init(false); |
680 | 680 | |
681 | - foreach(self::$langs as $lang => $name) |
|
681 | + foreach (self::$langs as $lang => $name) |
|
682 | 682 | { |
683 | - self::$langs[$lang] = self::translate($name,False,''); |
|
683 | + self::$langs[$lang] = self::translate($name, False, ''); |
|
684 | 684 | } |
685 | 685 | } |
686 | - uasort(self::$langs,'strcasecmp'); |
|
686 | + uasort(self::$langs, 'strcasecmp'); |
|
687 | 687 | } |
688 | 688 | return self::$langs; |
689 | 689 | } |
@@ -696,7 +696,7 @@ discard block |
||
696 | 696 | * @param boolean $force_read =false force a re-read of the languages |
697 | 697 | * @return array with lang-code => descriptiv lang-name pairs |
698 | 698 | */ |
699 | - static function get_installed_langs($force_read=false) |
|
699 | + static function get_installed_langs($force_read = false) |
|
700 | 700 | { |
701 | 701 | return self::get_available_langs($force_read); |
702 | 702 | } |
@@ -713,7 +713,7 @@ discard block |
||
713 | 713 | { |
714 | 714 | return self::$langs[$lang]; |
715 | 715 | } |
716 | - return self::$db->select(self::LANGUAGES_TABLE,'lang_name',array('lang_id' => $lang),__LINE__,__FILE__)->fetchColumn(); |
|
716 | + return self::$db->select(self::LANGUAGES_TABLE, 'lang_name', array('lang_id' => $lang), __LINE__, __FILE__)->fetchColumn(); |
|
717 | 717 | } |
718 | 718 | |
719 | 719 | /** |
@@ -722,20 +722,20 @@ discard block |
||
722 | 722 | * @param boolean $force_read =false |
723 | 723 | * @return array with lang_id => lang_name pairs |
724 | 724 | */ |
725 | - static function list_langs($force_read=false) |
|
725 | + static function list_langs($force_read = false) |
|
726 | 726 | { |
727 | 727 | if (!$force_read) |
728 | 728 | { |
729 | - return Cache::getInstance(__CLASS__,'list_langs',array(__CLASS__,'list_langs'),array(true)); |
|
729 | + return Cache::getInstance(__CLASS__, 'list_langs', array(__CLASS__, 'list_langs'), array(true)); |
|
730 | 730 | } |
731 | - $languages = self::get_installed_langs(); // available languages |
|
732 | - $availible = "('".implode("','",array_keys($languages))."')"; |
|
731 | + $languages = self::get_installed_langs(); // available languages |
|
732 | + $availible = "('".implode("','", array_keys($languages))."')"; |
|
733 | 733 | |
734 | 734 | // this shows first the installed, then the available and then the rest |
735 | - foreach(self::$db->select(self::LANGUAGES_TABLE,array( |
|
736 | - 'lang_id','lang_name', |
|
735 | + foreach (self::$db->select(self::LANGUAGES_TABLE, array( |
|
736 | + 'lang_id', 'lang_name', |
|
737 | 737 | "CASE WHEN lang_id IN $availible THEN 1 ELSE 0 END AS availible", |
738 | - ),"lang_id NOT IN ('".implode("','",array_keys($languages))."')",__LINE__,__FILE__,false,' ORDER BY availible DESC,lang_name') as $row) |
|
738 | + ), "lang_id NOT IN ('".implode("','", array_keys($languages))."')", __LINE__, __FILE__, false, ' ORDER BY availible DESC,lang_name') as $row) |
|
739 | 739 | { |
740 | 740 | $languages[$row['lang_id']] = $row['lang_name']; |
741 | 741 | } |
@@ -749,7 +749,7 @@ discard block |
||
749 | 749 | * @param string $lang language code |
750 | 750 | * @return the full path of the filename for the requested app and language |
751 | 751 | */ |
752 | - static function get_lang_file($app,$lang) |
|
752 | + static function get_lang_file($app, $lang) |
|
753 | 753 | { |
754 | 754 | if ($app == 'common') $app = 'phpgwapi'; |
755 | 755 | return EGW_SERVER_ROOT.'/'.$app.'/'.self::LANG_DIR.'/'.self::LANGFILE_PREFIX.$lang.self::LANGFILE_EXTENSION; |
@@ -762,7 +762,7 @@ discard block |
||
762 | 762 | */ |
763 | 763 | static function get_installed_charsets() |
764 | 764 | { |
765 | - static $charsets=null; |
|
765 | + static $charsets = null; |
|
766 | 766 | |
767 | 767 | if (!isset($charsets)) |
768 | 768 | { |
@@ -791,7 +791,7 @@ discard block |
||
791 | 791 | { |
792 | 792 | static $extra = array( |
793 | 793 | 'ß' => 'ss', |
794 | - '̈' => 'e', // mb_convert_encoding return ̈ for all German umlauts |
|
794 | + '̈' => 'e', // mb_convert_encoding return ̈ for all German umlauts |
|
795 | 795 | ); |
796 | 796 | if (function_exists('mb_convert_encoding')) |
797 | 797 | { |
@@ -802,12 +802,12 @@ discard block |
||
802 | 802 | $entities = htmlentities($_str, ENT_QUOTES, self::charset()); |
803 | 803 | } |
804 | 804 | |
805 | - $estr = str_replace(array_keys($extra),array_values($extra), $entities); |
|
806 | - $ustr = preg_replace('/&([aAuUoO])uml;/','\\1e', $estr); // replace german umlauts with the letter plus one 'e' |
|
807 | - $astr = preg_replace('/&([a-zA-Z])(grave|acute|circ|ring|cedil|tilde|slash|uml);/','\\1', $ustr); // remove all types of accents |
|
805 | + $estr = str_replace(array_keys($extra), array_values($extra), $entities); |
|
806 | + $ustr = preg_replace('/&([aAuUoO])uml;/', '\\1e', $estr); // replace german umlauts with the letter plus one 'e' |
|
807 | + $astr = preg_replace('/&([a-zA-Z])(grave|acute|circ|ring|cedil|tilde|slash|uml);/', '\\1', $ustr); // remove all types of accents |
|
808 | 808 | |
809 | - return preg_replace('/[^\x20-\x7f]/', '', // remove all non-ascii |
|
810 | - preg_replace('/&([a-zA-Z]+|#[0-9]+|);/','', $astr)); // remove all other entities |
|
809 | + return preg_replace('/[^\x20-\x7f]/', '', // remove all non-ascii |
|
810 | + preg_replace('/&([a-zA-Z]+|#[0-9]+|);/', '', $astr)); // remove all other entities |
|
811 | 811 | } |
812 | 812 | |
813 | 813 | /** |
@@ -819,7 +819,7 @@ discard block |
||
819 | 819 | * @param boolean $check_to_from =true internal to bypass all charset replacements |
820 | 820 | * @return string|array converted string(s) from $data |
821 | 821 | */ |
822 | - static function convert($data,$from=False,$to=False,$check_to_from=true) |
|
822 | + static function convert($data, $from = False, $to = False, $check_to_from = true) |
|
823 | 823 | { |
824 | 824 | if ($check_to_from) |
825 | 825 | { |
@@ -830,7 +830,7 @@ discard block |
||
830 | 830 | if (!$from) |
831 | 831 | { |
832 | 832 | $from = self::$mbstring ? strtolower(mb_detect_encoding($data)) : 'iso-8859-1'; |
833 | - if($from == 'ascii') |
|
833 | + if ($from == 'ascii') |
|
834 | 834 | { |
835 | 835 | $from = 'iso-8859-1'; |
836 | 836 | } |
@@ -840,7 +840,7 @@ discard block |
||
840 | 840 | php does not seem to support gb2312 |
841 | 841 | but seems to be able to decode it as EUC-CN |
842 | 842 | */ |
843 | - switch($from) |
|
843 | + switch ($from) |
|
844 | 844 | { |
845 | 845 | case 'ks_c_5601-1987': |
846 | 846 | $from = 'CP949'; |
@@ -886,9 +886,9 @@ discard block |
||
886 | 886 | } |
887 | 887 | if (is_array($data)) |
888 | 888 | { |
889 | - foreach($data as $key => $str) |
|
889 | + foreach ($data as $key => $str) |
|
890 | 890 | { |
891 | - $ret[$key] = self::convert($str,$from,$to,false); // false = bypass the above checks, as they are already done |
|
891 | + $ret[$key] = self::convert($str, $from, $to, false); // false = bypass the above checks, as they are already done |
|
892 | 892 | } |
893 | 893 | return $ret; |
894 | 894 | } |
@@ -900,7 +900,7 @@ discard block |
||
900 | 900 | { |
901 | 901 | return utf8_decode($data); |
902 | 902 | } |
903 | - if (self::$mbstring && !$prefer_iconv && ($data = @mb_convert_encoding($data,$to,$from)) != '') |
|
903 | + if (self::$mbstring && !$prefer_iconv && ($data = @mb_convert_encoding($data, $to, $from)) != '') |
|
904 | 904 | { |
905 | 905 | return $data; |
906 | 906 | } |
@@ -928,12 +928,12 @@ discard block |
||
928 | 928 | // in an email on the first Traditional/Japanese/Korean character, |
929 | 929 | // but in reality when people send mails in GB2312, UMA mostly use |
930 | 930 | // extended GB13000/GB18030 which allow T/Jap/Korean characters. |
931 | - if($from == 'euc-cn') |
|
931 | + if ($from == 'euc-cn') |
|
932 | 932 | { |
933 | 933 | $from = 'gb18030'; |
934 | 934 | } |
935 | 935 | |
936 | - if (($convertedData = iconv($from,$to,$data))) |
|
936 | + if (($convertedData = iconv($from, $to, $data))) |
|
937 | 937 | { |
938 | 938 | return $convertedData; |
939 | 939 | } |
@@ -948,9 +948,9 @@ discard block |
||
948 | 948 | * @param string|boolean $from charset $data is in or False if it should be detected |
949 | 949 | * @return string|array converted string(s) from $data |
950 | 950 | */ |
951 | - static function convert_jsonsafe($_data,$from=False) |
|
951 | + static function convert_jsonsafe($_data, $from = False) |
|
952 | 952 | { |
953 | - if ($from===false) $from = self::detect_encoding($_data); |
|
953 | + if ($from === false) $from = self::detect_encoding($_data); |
|
954 | 954 | |
955 | 955 | $data = self::convert($_data, strtolower($from)); |
956 | 956 | |
@@ -959,12 +959,12 @@ discard block |
||
959 | 959 | { |
960 | 960 | $test = @json_encode($data); |
961 | 961 | //error_log(__METHOD__.__LINE__.' ->'.strlen($data).' Error:'.json_last_error().'<- data:#'.$test.'#'); |
962 | - if (($test=="null" || $test === false || is_null($test)) && strlen($data)>0) |
|
962 | + if (($test == "null" || $test === false || is_null($test)) && strlen($data) > 0) |
|
963 | 963 | { |
964 | 964 | // try to fix broken utf8 |
965 | - $x = (function_exists('mb_convert_encoding')?mb_convert_encoding($data,'UTF-8','UTF-8'):(function_exists('iconv')?@iconv("UTF-8","UTF-8//IGNORE",$data):$data)); |
|
965 | + $x = (function_exists('mb_convert_encoding') ?mb_convert_encoding($data, 'UTF-8', 'UTF-8') : (function_exists('iconv') ? @iconv("UTF-8", "UTF-8//IGNORE", $data) : $data)); |
|
966 | 966 | $test = @json_encode($x); |
967 | - if (($test=="null" || $test === false || is_null($test)) && strlen($data)>0) |
|
967 | + if (($test == "null" || $test === false || is_null($test)) && strlen($data) > 0) |
|
968 | 968 | { |
969 | 969 | // this should not be needed, unless something fails with charset detection/ wrong charset passed |
970 | 970 | error_log(__METHOD__.__LINE__.' Charset Reported:'.$from.' Charset Detected:'.self::detect_encoding($data)); |
@@ -987,36 +987,36 @@ discard block |
||
987 | 987 | * @param string $message_id |
988 | 988 | * @param string $content translation or null to delete translation |
989 | 989 | */ |
990 | - static function write($lang,$app,$message_id,$content) |
|
990 | + static function write($lang, $app, $message_id, $content) |
|
991 | 991 | { |
992 | 992 | if ($content) |
993 | 993 | { |
994 | - self::$db->insert(self::LANG_TABLE,array( |
|
994 | + self::$db->insert(self::LANG_TABLE, array( |
|
995 | 995 | 'content' => $content, |
996 | - ),array( |
|
996 | + ), array( |
|
997 | 997 | 'lang' => $lang, |
998 | 998 | 'app_name' => $app, |
999 | 999 | 'message_id' => $message_id, |
1000 | - ),__LINE__,__FILE__); |
|
1000 | + ), __LINE__, __FILE__); |
|
1001 | 1001 | } |
1002 | 1002 | else |
1003 | 1003 | { |
1004 | - self::$db->delete(self::LANG_TABLE,array( |
|
1004 | + self::$db->delete(self::LANG_TABLE, array( |
|
1005 | 1005 | 'lang' => $lang, |
1006 | 1006 | 'app_name' => $app, |
1007 | 1007 | 'message_id' => $message_id, |
1008 | - ),__LINE__,__FILE__); |
|
1008 | + ), __LINE__, __FILE__); |
|
1009 | 1009 | } |
1010 | 1010 | // invalidate the cache |
1011 | - if(!in_array($app,self::$instance_specific_translations)) |
|
1011 | + if (!in_array($app, self::$instance_specific_translations)) |
|
1012 | 1012 | { |
1013 | - Cache::unsetCache(Cache::TREE,__CLASS__,$app.':'.$lang); |
|
1013 | + Cache::unsetCache(Cache::TREE, __CLASS__, $app.':'.$lang); |
|
1014 | 1014 | } |
1015 | 1015 | else |
1016 | 1016 | { |
1017 | - foreach(array_keys((array)self::get_installed_langs()) as $key) |
|
1017 | + foreach (array_keys((array)self::get_installed_langs()) as $key) |
|
1018 | 1018 | { |
1019 | - Cache::unsetCache(Cache::INSTANCE,__CLASS__,$app.':'.$key); |
|
1019 | + Cache::unsetCache(Cache::INSTANCE, __CLASS__, $app.':'.$key); |
|
1020 | 1020 | } |
1021 | 1021 | } |
1022 | 1022 | } |
@@ -1029,13 +1029,13 @@ discard block |
||
1029 | 1029 | * @param string $message_id |
1030 | 1030 | * @return string|boolean content or false if not found |
1031 | 1031 | */ |
1032 | - static function read($lang,$app_name,$message_id) |
|
1032 | + static function read($lang, $app_name, $message_id) |
|
1033 | 1033 | { |
1034 | - return self::$db->select(self::LANG_TABLE,'content',array( |
|
1034 | + return self::$db->select(self::LANG_TABLE, 'content', array( |
|
1035 | 1035 | 'lang' => $lang, |
1036 | 1036 | 'app_name' => $app_name, |
1037 | 1037 | 'message_id' => $message_id, |
1038 | - ),__LINE__,__FILE__)->fetchColumn(); |
|
1038 | + ), __LINE__, __FILE__)->fetchColumn(); |
|
1039 | 1039 | } |
1040 | 1040 | |
1041 | 1041 | /** |
@@ -1046,22 +1046,22 @@ discard block |
||
1046 | 1046 | * @param string $lang ='' default check all langs |
1047 | 1047 | * @return string |
1048 | 1048 | */ |
1049 | - static function get_message_id($translation,$app=null,$lang=null) |
|
1049 | + static function get_message_id($translation, $app = null, $lang = null) |
|
1050 | 1050 | { |
1051 | 1051 | $where = array('content '.self::$db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.self::$db->quote($translation)); |
1052 | 1052 | if ($app) $where['app_name'] = $app; |
1053 | 1053 | if ($lang) $where['lang'] = $lang; |
1054 | 1054 | |
1055 | - $id = self::$db->select(self::LANG_TABLE,'message_id',$where,__LINE__,__FILE__)->fetchColumn(); |
|
1055 | + $id = self::$db->select(self::LANG_TABLE, 'message_id', $where, __LINE__, __FILE__)->fetchColumn(); |
|
1056 | 1056 | |
1057 | 1057 | // Check cache, since most things aren't in the DB anymore |
1058 | - if(!$id) |
|
1058 | + if (!$id) |
|
1059 | 1059 | { |
1060 | 1060 | $ids = array_filter(array_keys(self::$lang_arr), function($haystack) use($translation) { |
1061 | - return stripos(self::$lang_arr[$haystack],$translation) !== false; |
|
1061 | + return stripos(self::$lang_arr[$haystack], $translation) !== false; |
|
1062 | 1062 | }); |
1063 | 1063 | $id = array_shift($ids); |
1064 | - if(!$id && ($lang && $lang !== 'en' || self::$userlang != 'en')) |
|
1064 | + if (!$id && ($lang && $lang !== 'en' || self::$userlang != 'en')) |
|
1065 | 1065 | { |
1066 | 1066 | // Try english |
1067 | 1067 | if (in_array($app, self::$instance_specific_translations)) |
@@ -1078,7 +1078,7 @@ discard block |
||
1078 | 1078 | if ($instance_level) $lang_arr = Cache::getInstance(__CLASS__, $instance_level); |
1079 | 1079 | $lang_arr = $lang_arr[$app.':en']; |
1080 | 1080 | $ids = array_filter(array_keys($lang_arr), function($haystack) use($translation, $lang_arr) { |
1081 | - return stripos($lang_arr[$haystack],$translation) !== false; |
|
1081 | + return stripos($lang_arr[$haystack], $translation) !== false; |
|
1082 | 1082 | }); |
1083 | 1083 | $id = array_shift($ids); |
1084 | 1084 | } |
@@ -1095,7 +1095,7 @@ discard block |
||
1095 | 1095 | * @param string $verify =null encoding to verify, get checked first and have a match for only ascii or no detection available |
1096 | 1096 | * @return string - encoding |
1097 | 1097 | */ |
1098 | - static function detect_encoding($string, $verify=null) |
|
1098 | + static function detect_encoding($string, $verify = null) |
|
1099 | 1099 | { |
1100 | 1100 | if (function_exists('iconv')) |
1101 | 1101 | { |
@@ -1118,7 +1118,7 @@ discard block |
||
1118 | 1118 | } |
1119 | 1119 | if ($verify && (!isset($detected) || $detected === 'ascii')) |
1120 | 1120 | { |
1121 | - return $verify; // ascii matches all charsets |
|
1121 | + return $verify; // ascii matches all charsets |
|
1122 | 1122 | } |
1123 | 1123 | return isset($detected) ? $detected : 'iso-8859-1'; // we choose to return iso-8859-1 as default |
1124 | 1124 | } |
@@ -84,7 +84,7 @@ |
||
84 | 84 | /** |
85 | 85 | * Returns available diskspace information |
86 | 86 | * |
87 | - * @return array [ available-space, free-space ] |
|
87 | + * @return false[] [ available-space, free-space ] |
|
88 | 88 | */ |
89 | 89 | function getQuotaInfo() |
90 | 90 | { |
@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | function getChild($name) |
67 | 67 | { |
68 | 68 | //error_log(__METHOD__."('$name') this->path=$this->path, this->vfs_path=$this->vfs_path"); |
69 | - $path = $this->vfs_path . '/' . $name; |
|
70 | - $vfs_path = $this->vfs_path . '/' . Vfs::encodePathComponent($name); |
|
69 | + $path = $this->vfs_path.'/'.$name; |
|
70 | + $vfs_path = $this->vfs_path.'/'.Vfs::encodePathComponent($name); |
|
71 | 71 | |
72 | - if (!Vfs::file_exists($vfs_path)) throw new DAV\Exception\NotFound('File with name ' . $path . ' could not be located'); |
|
72 | + if (!Vfs::file_exists($vfs_path)) throw new DAV\Exception\NotFound('File with name '.$path.' could not be located'); |
|
73 | 73 | |
74 | 74 | if (Vfs::is_dir($vfs_path)) |
75 | 75 | { |
@@ -88,6 +88,6 @@ discard block |
||
88 | 88 | */ |
89 | 89 | function getQuotaInfo() |
90 | 90 | { |
91 | - return [ false, false ]; |
|
91 | + return [false, false]; |
|
92 | 92 | } |
93 | 93 | } |
@@ -69,7 +69,10 @@ |
||
69 | 69 | $path = $this->vfs_path . '/' . $name; |
70 | 70 | $vfs_path = $this->vfs_path . '/' . Vfs::encodePathComponent($name); |
71 | 71 | |
72 | - if (!Vfs::file_exists($vfs_path)) throw new DAV\Exception\NotFound('File with name ' . $path . ' could not be located'); |
|
72 | + if (!Vfs::file_exists($vfs_path)) |
|
73 | + { |
|
74 | + throw new DAV\Exception\NotFound('File with name ' . $path . ' could not be located'); |
|
75 | + } |
|
73 | 76 | |
74 | 77 | if (Vfs::is_dir($vfs_path)) |
75 | 78 | { |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * |
63 | 63 | * Return null if the ETag can not effectively be determined |
64 | 64 | * |
65 | - * @return mixed |
|
65 | + * @return string|null |
|
66 | 66 | */ |
67 | 67 | function getETag() |
68 | 68 | { |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * |
79 | 79 | * If null is returned, we'll assume application/octet-stream |
80 | 80 | * |
81 | - * @return mixed |
|
81 | + * @return string |
|
82 | 82 | */ |
83 | 83 | function getContentType() |
84 | 84 | { |