@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | { |
47 | 47 | if (!function_exists('apcu_fetch')) // apc >= 3.0 |
48 | 48 | { |
49 | - throw new Exception (__METHOD__.'('.array2string($params).") No function apcu_fetch()!"); |
|
49 | + throw new Exception(__METHOD__.'('.array2string($params).") No function apcu_fetch()!"); |
|
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | { |
66 | 66 | $size = ini_get('apc.shm_size'); |
67 | 67 | |
68 | - switch(strtoupper(substr($size, -1))) |
|
68 | + switch (strtoupper(substr($size, -1))) |
|
69 | 69 | { |
70 | 70 | case 'G': |
71 | 71 | $size *= 1024; |
@@ -91,9 +91,9 @@ discard block |
||
91 | 91 | * @param int $expiration =0 |
92 | 92 | * @return boolean true on success, false on error, incl. key already exists in cache |
93 | 93 | */ |
94 | - function add(array $keys,$data,$expiration=0) |
|
94 | + function add(array $keys, $data, $expiration = 0) |
|
95 | 95 | { |
96 | - return apcu_add(self::key($keys),$data,$expiration); |
|
96 | + return apcu_add(self::key($keys), $data, $expiration); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -104,9 +104,9 @@ discard block |
||
104 | 104 | * @param int $expiration =0 |
105 | 105 | * @return boolean true on success, false on error |
106 | 106 | */ |
107 | - function set(array $keys,$data,$expiration=0) |
|
107 | + function set(array $keys, $data, $expiration = 0) |
|
108 | 108 | { |
109 | - return apcu_store(self::key($keys),$data,$expiration); |
|
109 | + return apcu_store(self::key($keys), $data, $expiration); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | function get(array $keys) |
119 | 119 | { |
120 | 120 | $success = null; |
121 | - $data = apcu_fetch($key=self::key($keys),$success); |
|
121 | + $data = apcu_fetch($key = self::key($keys), $success); |
|
122 | 122 | |
123 | 123 | if (!$success) |
124 | 124 | { |
@@ -160,12 +160,12 @@ discard block |
||
160 | 160 | // APCu > 5 has APCUIterator |
161 | 161 | if (class_exists('APCUIterator')) |
162 | 162 | { |
163 | - $iterator = new \APCUIterator($preg='/^'.preg_quote(self::key($keys).'/')); |
|
163 | + $iterator = new \APCUIterator($preg = '/^'.preg_quote(self::key($keys).'/')); |
|
164 | 164 | } |
165 | 165 | // APC >= 3.1.1, but also seems to be missing if apc is disabled eg. for cli |
166 | - elseif(class_exists('APCIterator')) |
|
166 | + elseif (class_exists('APCIterator')) |
|
167 | 167 | { |
168 | - $iterator = new \APCIterator('user', $preg='/^'.preg_quote(self::key($keys).'/')); |
|
168 | + $iterator = new \APCIterator('user', $preg = '/^'.preg_quote(self::key($keys).'/')); |
|
169 | 169 | } |
170 | 170 | else |
171 | 171 | { |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | |
174 | 174 | return false; |
175 | 175 | } |
176 | - foreach($iterator as $item) |
|
176 | + foreach ($iterator as $item) |
|
177 | 177 | { |
178 | 178 | //error_log(__METHOD__."(".array2string($keys).") preg='$preg': calling apcu_delete('$item[key]')"); |
179 | 179 | apcu_delete($item['key']); |
@@ -189,6 +189,6 @@ discard block |
||
189 | 189 | */ |
190 | 190 | private static function key(array $keys) |
191 | 191 | { |
192 | - return implode('::',$keys); |
|
192 | + return implode('::', $keys); |
|
193 | 193 | } |
194 | 194 | } |
@@ -44,10 +44,13 @@ discard block |
||
44 | 44 | */ |
45 | 45 | function __construct(array $params) |
46 | 46 | { |
47 | - if (!function_exists('apcu_fetch')) // apc >= 3.0 |
|
47 | + if (!function_exists('apcu_fetch')) |
|
48 | + { |
|
49 | + // apc >= 3.0 |
|
48 | 50 | { |
49 | 51 | throw new Exception (__METHOD__.'('.array2string($params).") No function apcu_fetch()!"); |
50 | 52 | } |
53 | + } |
|
51 | 54 | } |
52 | 55 | |
53 | 56 | /** |
@@ -169,7 +172,10 @@ discard block |
||
169 | 172 | } |
170 | 173 | else |
171 | 174 | { |
172 | - if (function_exists('apcu_clear_cache')) apcu_clear_cache(); |
|
175 | + if (function_exists('apcu_clear_cache')) |
|
176 | + { |
|
177 | + apcu_clear_cache(); |
|
178 | + } |
|
173 | 179 | |
174 | 180 | return false; |
175 | 181 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | { |
47 | 47 | if (!function_exists('apc_fetch')) // apc >= 3.0 |
48 | 48 | { |
49 | - throw new Exception (__METHOD__.'('.array2string($params).") No function apc_fetch()!"); |
|
49 | + throw new Exception(__METHOD__.'('.array2string($params).") No function apc_fetch()!"); |
|
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | // ancent APC (3.1.3) in Debian 6/Squezze has size in MB without a unit |
67 | 67 | if (is_numeric($size) && $size <= 1048576) $size .= 'M'; |
68 | 68 | |
69 | - switch(strtoupper(substr($size, -1))) |
|
69 | + switch (strtoupper(substr($size, -1))) |
|
70 | 70 | { |
71 | 71 | case 'G': |
72 | 72 | $size *= 1024; |
@@ -92,9 +92,9 @@ discard block |
||
92 | 92 | * @param int $expiration =0 |
93 | 93 | * @return boolean true on success, false on error, incl. key already exists in cache |
94 | 94 | */ |
95 | - function add(array $keys,$data,$expiration=0) |
|
95 | + function add(array $keys, $data, $expiration = 0) |
|
96 | 96 | { |
97 | - return apc_add(self::key($keys),$data,$expiration); |
|
97 | + return apc_add(self::key($keys), $data, $expiration); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | * @param int $expiration =0 |
106 | 106 | * @return boolean true on success, false on error |
107 | 107 | */ |
108 | - function set(array $keys,$data,$expiration=0) |
|
108 | + function set(array $keys, $data, $expiration = 0) |
|
109 | 109 | { |
110 | - return apc_store(self::key($keys),$data,$expiration); |
|
110 | + return apc_store(self::key($keys), $data, $expiration); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | function get(array $keys) |
120 | 120 | { |
121 | 121 | $success = null; |
122 | - $data = apc_fetch($key=self::key($keys),$success); |
|
122 | + $data = apc_fetch($key = self::key($keys), $success); |
|
123 | 123 | |
124 | 124 | if (!$success) |
125 | 125 | { |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | return false; |
161 | 161 | } |
162 | 162 | //error_log(__METHOD__."(".array2string($keys).")"); |
163 | - foreach(new \APCIterator('user', $preg='/^'.preg_quote(self::key($keys).'/')) as $item) |
|
163 | + foreach (new \APCIterator('user', $preg = '/^'.preg_quote(self::key($keys).'/')) as $item) |
|
164 | 164 | { |
165 | 165 | //error_log(__METHOD__."(".array2string($keys).") preg='$preg': calling apc_delete('$item[key]')"); |
166 | 166 | apc_delete($item['key']); |
@@ -176,6 +176,6 @@ discard block |
||
176 | 176 | */ |
177 | 177 | private static function key(array $keys) |
178 | 178 | { |
179 | - return implode('::',$keys); |
|
179 | + return implode('::', $keys); |
|
180 | 180 | } |
181 | 181 | } |
@@ -44,10 +44,13 @@ discard block |
||
44 | 44 | */ |
45 | 45 | function __construct(array $params) |
46 | 46 | { |
47 | - if (!function_exists('apc_fetch')) // apc >= 3.0 |
|
47 | + if (!function_exists('apc_fetch')) |
|
48 | + { |
|
49 | + // apc >= 3.0 |
|
48 | 50 | { |
49 | 51 | throw new Exception (__METHOD__.'('.array2string($params).") No function apc_fetch()!"); |
50 | 52 | } |
53 | + } |
|
51 | 54 | } |
52 | 55 | |
53 | 56 | /** |
@@ -64,7 +67,10 @@ discard block |
||
64 | 67 | { |
65 | 68 | $size = ini_get('apc.shm_size'); |
66 | 69 | // ancent APC (3.1.3) in Debian 6/Squezze has size in MB without a unit |
67 | - if (is_numeric($size) && $size <= 1048576) $size .= 'M'; |
|
70 | + if (is_numeric($size) && $size <= 1048576) |
|
71 | + { |
|
72 | + $size .= 'M'; |
|
73 | + } |
|
68 | 74 | |
69 | 75 | switch(strtoupper(substr($size, -1))) |
70 | 76 | { |
@@ -155,7 +161,10 @@ discard block |
||
155 | 161 | // APC >= 3.1.1, but also seems to be missing if apc is disabled eg. for cli |
156 | 162 | if (!class_exists('APCIterator') || !$keys) |
157 | 163 | { |
158 | - if (function_exists('apc_clear_cache')) apc_clear_cache('user'); |
|
164 | + if (function_exists('apc_clear_cache')) |
|
165 | + { |
|
166 | + apc_clear_cache('user'); |
|
167 | + } |
|
159 | 168 | |
160 | 169 | return false; |
161 | 170 | } |
@@ -43,9 +43,9 @@ |
||
43 | 43 | 'ppt' => 'application/vnd.ms-powerpoint', |
44 | 44 | 'qt' => 'video/quicktime', |
45 | 45 | ); |
46 | -$src_dir=__DIR__.'/MimeTypes-Link-Icons/images'; |
|
47 | -$dst_dir=__DIR__; |
|
48 | -foreach(scandir($src_dir) as $file) |
|
46 | +$src_dir = __DIR__.'/MimeTypes-Link-Icons/images'; |
|
47 | +$dst_dir = __DIR__; |
|
48 | +foreach (scandir($src_dir) as $file) |
|
49 | 49 | { |
50 | 50 | if (preg_match('/^([^-]+)-icon-128x128.png$/', $file, $matches)) |
51 | 51 | { |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | * |
364 | 364 | * @param string $password cleartext password |
365 | 365 | * @param int $account_id user-account password is for |
366 | - * @param int& $pw_enc on return encryption used |
|
366 | + * @param integer $pw_enc on return encryption used |
|
367 | 367 | * @return string encrypted password |
368 | 368 | */ |
369 | 369 | protected static function encrypt($password, $account_id, &$pw_enc) |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | * With a 12 byte binary (16 byte base64) salt we can store 39 byte password in our varchar(80) column. |
437 | 437 | * |
438 | 438 | * @param string $password |
439 | - * @param string& $salt binary salt to use or null to generate one, on return used salt |
|
439 | + * @param string|null $salt binary salt to use or null to generate one, on return used salt |
|
440 | 440 | * @param int $iterations =2048 iterations of passsword |
441 | 441 | * @param int $length =16 length of binary aes key |
442 | 442 | * @param string $hash ='sha256' |
@@ -614,7 +614,6 @@ discard block |
||
614 | 614 | * |
615 | 615 | * @param array $row database row |
616 | 616 | * @param string $key =null password to use |
617 | - * @param string $salt_len =16 len of base64 encoded salt (binary is 3/4) |
|
618 | 617 | * @return string cleartext password |
619 | 618 | * @throws Api\Exception\WrongParameter |
620 | 619 | * @throws Api\Exception\AssertionFailed if OpenSSL extension not available |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * to run on successful login to trigger password migration |
154 | 154 | * @return array with values for (imap|smtp|admin)_(username|password|cred_id) |
155 | 155 | */ |
156 | - public static function read($acc_id, $type=null, $account_id=null, &$on_login=null) |
|
156 | + public static function read($acc_id, $type = null, $account_id = null, &$on_login = null) |
|
157 | 157 | { |
158 | 158 | if (is_null($type)) $type = self::ALL; |
159 | 159 | if (is_null($account_id)) |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | $rows = self::$db->select(self::TABLE, '*', array( |
170 | 170 | 'acc_id' => $acc_id, |
171 | 171 | 'account_id' => $account_id, |
172 | - '(cred_type & '.(int)$type.') > 0', // postgreSQL require > 0, or gives error as it expects boolean |
|
172 | + '(cred_type & '.(int)$type.') > 0', // postgreSQL require > 0, or gives error as it expects boolean |
|
173 | 173 | ), __LINE__, __FILE__, false, |
174 | 174 | // account_id DESC ensures 0=all allways overwrite (old user-specific credentials) |
175 | 175 | 'ORDER BY account_id ASC', self::APP); |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | } |
178 | 178 | else |
179 | 179 | { |
180 | - ksort($rows); // ORDER BY account_id ASC |
|
180 | + ksort($rows); // ORDER BY account_id ASC |
|
181 | 181 | |
182 | 182 | // flatten account_id => cred_type => row array again, to have format like from database |
183 | 183 | $rows = call_user_func_array('array_merge', $rows); |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | } |
186 | 186 | $on_login = null; |
187 | 187 | $results = array(); |
188 | - foreach($rows as $row) |
|
188 | + foreach ($rows as $row) |
|
189 | 189 | { |
190 | 190 | // update cache (only if we have database-iterator and all credentials asked!) |
191 | 191 | if (!is_array($rows) && $type == self::ALL) |
@@ -203,9 +203,9 @@ discard block |
||
203 | 203 | // Remove special x char added to the end for \0 trimming escape. |
204 | 204 | if ($type == self::SMIME && substr($password, -1) === 'x') $password = substr($password, 0, -1); |
205 | 205 | |
206 | - foreach(self::$type2prefix as $pattern => $prefix) |
|
206 | + foreach (self::$type2prefix as $pattern => $prefix) |
|
207 | 207 | { |
208 | - if ($row['cred_type'] & $pattern) |
|
208 | + if ($row['cred_type']&$pattern) |
|
209 | 209 | { |
210 | 210 | $results[$prefix.'username'] = $row['cred_username']; |
211 | 211 | $results[$prefix.'password'] = $password; |
@@ -225,9 +225,9 @@ discard block |
||
225 | 225 | * @param boolean $set_identity =true true: also set identity values realname&email, if not yet set |
226 | 226 | * @return array with values for keys 'acc_(imap|smtp)_(username|password|cred_id)' |
227 | 227 | */ |
228 | - public static function from_session(array $data, $set_identity=true) |
|
228 | + public static function from_session(array $data, $set_identity = true) |
|
229 | 229 | { |
230 | - switch($data['acc_imap_logintype']) |
|
230 | + switch ($data['acc_imap_logintype']) |
|
231 | 231 | { |
232 | 232 | case 'standard': |
233 | 233 | $username = $GLOBALS['egw_info']['user']['account_lid']; |
@@ -253,23 +253,21 @@ discard block |
||
253 | 253 | throw new Api\Exception\WrongParameter("Unknown data[acc_imap_logintype]=".array2string($data['acc_imap_logintype']).'!'); |
254 | 254 | } |
255 | 255 | $password = base64_decode(Api\Cache::getSession('phpgwapi', 'password')); |
256 | - $realname = !$set_identity || $data['ident_realname'] ? $data['ident_realname'] : |
|
257 | - $GLOBALS['egw_info']['user']['account_fullname']; |
|
258 | - $email = !$set_identity || $data['ident_email'] ? $data['ident_email'] : |
|
259 | - $GLOBALS['egw_info']['user']['account_email']; |
|
256 | + $realname = !$set_identity || $data['ident_realname'] ? $data['ident_realname'] : $GLOBALS['egw_info']['user']['account_fullname']; |
|
257 | + $email = !$set_identity || $data['ident_email'] ? $data['ident_email'] : $GLOBALS['egw_info']['user']['account_email']; |
|
260 | 258 | |
261 | 259 | return array( |
262 | 260 | 'ident_realname' => $realname, |
263 | 261 | 'ident_email' => $email, |
264 | 262 | 'acc_imap_username' => $username, |
265 | 263 | 'acc_imap_password' => $password, |
266 | - 'acc_imap_cred_id' => $data['acc_imap_logintype'], // to NOT store it |
|
264 | + 'acc_imap_cred_id' => $data['acc_imap_logintype'], // to NOT store it |
|
267 | 265 | 'acc_imap_account_id' => 'c', |
268 | 266 | ) + ($data['acc_smtp_auth_session'] ? array( |
269 | 267 | // only set smtp |
270 | 268 | 'acc_smtp_username' => $username, |
271 | 269 | 'acc_smtp_password' => $password, |
272 | - 'acc_smtp_cred_id' => $data['acc_imap_logintype'], // to NOT store it |
|
270 | + 'acc_smtp_cred_id' => $data['acc_imap_logintype'], // to NOT store it |
|
273 | 271 | 'acc_smtp_account_id' => 'c', |
274 | 272 | ) : array()); |
275 | 273 | } |
@@ -285,13 +283,13 @@ discard block |
||
285 | 283 | * @param int $cred_id =null id of existing credentials to update |
286 | 284 | * @return int cred_id |
287 | 285 | */ |
288 | - public static function write($acc_id, $username, $password, $type, $account_id=0, $cred_id=null) |
|
286 | + public static function write($acc_id, $username, $password, $type, $account_id = 0, $cred_id = null) |
|
289 | 287 | { |
290 | 288 | //error_log(__METHOD__."(acc_id=$acc_id, '$username', \$password, type=$type, account_id=$account_id, cred_id=$cred_id)"); |
291 | 289 | if (!empty($cred_id) && !is_numeric($cred_id) || !is_numeric($account_id)) |
292 | 290 | { |
293 | 291 | //error_log(__METHOD__."($acc_id, '$username', \$password, $type, $account_id, ".array2string($cred_id).") not storing session credentials!"); |
294 | - return; // do NOT store credentials from session of current user! |
|
292 | + return; // do NOT store credentials from session of current user! |
|
295 | 293 | } |
296 | 294 | |
297 | 295 | // Add arbitary char to the ending to make sure the Smime binary content |
@@ -302,15 +300,14 @@ discard block |
||
302 | 300 | if ((string)$username === '') |
303 | 301 | { |
304 | 302 | if ($cred_id) self::$db->delete(self::TABLE, array('cred_id' => $cred_id), __LINE__, __FILE__, self::APP); |
305 | - return; // nothing to save |
|
303 | + return; // nothing to save |
|
306 | 304 | } |
307 | 305 | $pw_enc = self::CLEARTEXT; |
308 | 306 | $data = array( |
309 | 307 | 'acc_id' => $acc_id, |
310 | 308 | 'account_id' => $account_id, |
311 | 309 | 'cred_username' => $username, |
312 | - 'cred_password' => (string)$password === '' ? '' : |
|
313 | - self::encrypt($password, $account_id, $pw_enc), |
|
310 | + 'cred_password' => (string)$password === '' ? '' : self::encrypt($password, $account_id, $pw_enc), |
|
314 | 311 | 'cred_type' => $type, |
315 | 312 | 'cred_pw_enc' => $pw_enc, |
316 | 313 | ); |
@@ -350,7 +347,7 @@ discard block |
||
350 | 347 | * @param boolean $exact_type =false true: delete only cred_type=$type, false: delete cred_type&$type |
351 | 348 | * @return int number of rows deleted |
352 | 349 | */ |
353 | - public static function delete($acc_id, $account_id=null, $type=self::ALL, $exact_type=false) |
|
350 | + public static function delete($acc_id, $account_id = null, $type = self::ALL, $exact_type = false) |
|
354 | 351 | { |
355 | 352 | if (!($acc_id > 0) && !isset($account_id)) |
356 | 353 | { |
@@ -365,12 +362,12 @@ discard block |
||
365 | 362 | } |
366 | 363 | elseif ($type != self::ALL) |
367 | 364 | { |
368 | - $where[] = '(cred_type & '.(int)$type.') > 0'; // postgreSQL require > 0, or gives error as it expects boolean |
|
365 | + $where[] = '(cred_type & '.(int)$type.') > 0'; // postgreSQL require > 0, or gives error as it expects boolean |
|
369 | 366 | } |
370 | 367 | self::$db->delete(self::TABLE, $where, __LINE__, __FILE__, self::APP); |
371 | 368 | |
372 | 369 | // invalidate cache: we allways unset everything about an account to simplify cache handling |
373 | - foreach($acc_id > 0 ? (array)$acc_id : array_keys(self::$cache) as $acc_id) |
|
370 | + foreach ($acc_id > 0 ? (array)$acc_id : array_keys(self::$cache) as $acc_id) |
|
374 | 371 | { |
375 | 372 | unset(self::$cache[$acc_id]); |
376 | 373 | } |
@@ -428,7 +425,7 @@ discard block |
||
428 | 425 | * @param string $salt =null (binary) salt to use, default generate new random salt |
429 | 426 | * @return string encrypted password |
430 | 427 | */ |
431 | - protected static function encrypt_openssl_aes($password, $account_id, &$pw_enc, $key=null, $salt=null) |
|
428 | + protected static function encrypt_openssl_aes($password, $account_id, &$pw_enc, $key = null, $salt = null) |
|
432 | 429 | { |
433 | 430 | if (empty($key)) |
434 | 431 | { |
@@ -463,7 +460,7 @@ discard block |
||
463 | 460 | * @param string $hash ='sha256' |
464 | 461 | * @return string |
465 | 462 | */ |
466 | - protected static function aes_key($password, &$salt, $iterations=2048, $length=16, $hash='sha256') |
|
463 | + protected static function aes_key($password, &$salt, $iterations = 2048, $length = 16, $hash = 'sha256') |
|
467 | 464 | { |
468 | 465 | if (empty($salt)) |
469 | 466 | { |
@@ -518,7 +515,7 @@ discard block |
||
518 | 515 | * @throws Api\Exception\WrongParameter |
519 | 516 | * @throws Api\Exception\AssertionFailed if neither OpenSSL nor MCrypt extension available |
520 | 517 | */ |
521 | - protected static function decrypt(array $row, $key=null) |
|
518 | + protected static function decrypt(array $row, $key = null) |
|
522 | 519 | { |
523 | 520 | // empty/unset passwords only give warnings ... |
524 | 521 | if (empty($row['cred_password'])) return ''; |
@@ -528,7 +525,7 @@ discard block |
||
528 | 525 | return self::UNAVAILABLE; |
529 | 526 | } |
530 | 527 | |
531 | - switch($row['cred_pw_enc']) |
|
528 | + switch ($row['cred_pw_enc']) |
|
532 | 529 | { |
533 | 530 | case self::CLEARTEXT: |
534 | 531 | return base64_decode($row['cred_password']); |
@@ -544,7 +541,7 @@ discard block |
||
544 | 541 | // ToDo store as AES |
545 | 542 | return $password; |
546 | 543 | } |
547 | - catch(Api\Exception\AssertionFailed $e) { |
|
544 | + catch (Api\Exception\AssertionFailed $e) { |
|
548 | 545 | unset($e); |
549 | 546 | // try Mcrypt |
550 | 547 | return self::decrypt_mcrypt_3des($row); |
@@ -562,7 +559,7 @@ discard block |
||
562 | 559 | * @throws Api\Exception\WrongParameter |
563 | 560 | * @throws Api\Exception\AssertionFailed if MCrypt extension not available |
564 | 561 | */ |
565 | - protected static function decrypt_mcrypt_3des(array $row, $key=null) |
|
562 | + protected static function decrypt_mcrypt_3des(array $row, $key = null) |
|
566 | 563 | { |
567 | 564 | check_load_extension('mcrypt', true); |
568 | 565 | |
@@ -616,7 +613,7 @@ discard block |
||
616 | 613 | * @throws Api\Exception\WrongParameter |
617 | 614 | * @throws Api\Exception\AssertionFailed if OpenSSL extension not available |
618 | 615 | */ |
619 | - protected static function decrypt_openssl_3des(array $row, $key=null) |
|
616 | + protected static function decrypt_openssl_3des(array $row, $key = null) |
|
620 | 617 | { |
621 | 618 | check_load_extension('openssl', true); |
622 | 619 | |
@@ -626,7 +623,7 @@ discard block |
||
626 | 623 | } |
627 | 624 | // seems iv is NOT used for mcrypt "tripledes/ecb" = openssl "des-ede3", only key-size 24 |
628 | 625 | $keySize = 24; |
629 | - if (bytes($key) > $keySize) $key = cut_bytes($key,0,$keySize-1); // $keySize-1 is wrong, but that's what's used! |
|
626 | + if (bytes($key) > $keySize) $key = cut_bytes($key, 0, $keySize - 1); // $keySize-1 is wrong, but that's what's used! |
|
630 | 627 | return trim(openssl_decrypt($row['cred_password'], self::TRIPLEDES_ECB_METHOD, $key, OPENSSL_ZERO_PADDING, ''), "\0"); |
631 | 628 | } |
632 | 629 | |
@@ -640,7 +637,7 @@ discard block |
||
640 | 637 | * @throws Api\Exception\WrongParameter |
641 | 638 | * @throws Api\Exception\AssertionFailed if OpenSSL extension not available |
642 | 639 | */ |
643 | - protected static function decrypt_openssl_aes(array $row, $key=null) |
|
640 | + protected static function decrypt_openssl_aes(array $row, $key = null) |
|
644 | 641 | { |
645 | 642 | check_load_extension('openssl', true); |
646 | 643 | |
@@ -676,9 +673,9 @@ discard block |
||
676 | 673 | try { |
677 | 674 | if (isset(self::$cache[$acc_id])) |
678 | 675 | { |
679 | - foreach(self::$cache[$acc_id] as $account_id => &$rows) |
|
676 | + foreach (self::$cache[$acc_id] as $account_id => &$rows) |
|
680 | 677 | { |
681 | - foreach($rows as $cred_type => &$row) |
|
678 | + foreach ($rows as $cred_type => &$row) |
|
682 | 679 | { |
683 | 680 | if (self::needMigration($row['cred_pw_enc']) && ($row['cred_pw_enc'] != self::USER || |
684 | 681 | $row['cred_pw_enc'] == self::USER && $account_id == $GLOBALS['egw_info']['user']['account_id'])) |
@@ -689,7 +686,7 @@ discard block |
||
689 | 686 | } |
690 | 687 | } |
691 | 688 | } |
692 | - catch(\Exception $e) { |
|
689 | + catch (\Exception $e) { |
|
693 | 690 | // do not stall regular use, if password migration fails |
694 | 691 | _egw_log_exception($e); |
695 | 692 | } |
@@ -715,9 +712,9 @@ discard block |
||
715 | 712 | throw new Api\Exception\AssertionFailed('Password in session !== password given in $data[new_password]!'); |
716 | 713 | } |
717 | 714 | |
718 | - foreach(self::$db->select(self::TABLE, self::TABLE.'.*', array( |
|
715 | + foreach (self::$db->select(self::TABLE, self::TABLE.'.*', array( |
|
719 | 716 | 'account_id' => $data['account_id'] |
720 | - ),__LINE__, __FILE__, false, '', self::APP, 0, self::USER_EDITABLE_JOIN.self::$db->quote(true, 'bool')) as $row) |
|
717 | + ), __LINE__, __FILE__, false, '', self::APP, 0, self::USER_EDITABLE_JOIN.self::$db->quote(true, 'bool')) as $row) |
|
721 | 718 | { |
722 | 719 | $password = self::decrypt($row, self::isUser($row['cred_pw_enc']) ? $data['old_passwd'] : null); |
723 | 720 | |
@@ -735,7 +732,7 @@ discard block |
||
735 | 732 | * @param string $mode ='ecb' |
736 | 733 | * @return ressource|boolean mcrypt ressource to use or false if not available |
737 | 734 | */ |
738 | - static public function init_crypt($user=false, $algo='tripledes',$mode='ecb') |
|
735 | + static public function init_crypt($user = false, $algo = 'tripledes', $mode = 'ecb') |
|
739 | 736 | { |
740 | 737 | if (is_string($user)) |
741 | 738 | { |
@@ -743,11 +740,11 @@ discard block |
||
743 | 740 | } |
744 | 741 | elseif ($user) |
745 | 742 | { |
746 | - $mcrypt =& self::$user_mcrypt; |
|
743 | + $mcrypt = & self::$user_mcrypt; |
|
747 | 744 | } |
748 | 745 | else |
749 | 746 | { |
750 | - $mcrypt =& self::$system_mcrypt; |
|
747 | + $mcrypt = & self::$system_mcrypt; |
|
751 | 748 | } |
752 | 749 | if (!isset($mcrypt)) |
753 | 750 | { |
@@ -785,10 +782,10 @@ discard block |
||
785 | 782 | { |
786 | 783 | $iv_size = mcrypt_enc_get_iv_size($mcrypt); |
787 | 784 | $iv = !isset($GLOBALS['egw_info']['server']['mcrypt_iv']) || strlen($GLOBALS['egw_info']['server']['mcrypt_iv']) < $iv_size ? |
788 | - mcrypt_create_iv ($iv_size, MCRYPT_RAND) : substr($GLOBALS['egw_info']['server']['mcrypt_iv'],0,$iv_size); |
|
785 | + mcrypt_create_iv ($iv_size, MCRYPT_RAND) : substr($GLOBALS['egw_info']['server']['mcrypt_iv'], 0, $iv_size); |
|
789 | 786 | |
790 | 787 | $key_size = mcrypt_enc_get_key_size($mcrypt); |
791 | - if (bytes($key) > $key_size) $key = cut_bytes($key,0,$key_size-1); |
|
788 | + if (bytes($key) > $key_size) $key = cut_bytes($key, 0, $key_size - 1); |
|
792 | 789 | |
793 | 790 | if (mcrypt_generic_init($mcrypt, $key, $iv) < 0) |
794 | 791 | { |
@@ -155,7 +155,10 @@ discard block |
||
155 | 155 | */ |
156 | 156 | public static function read($acc_id, $type=null, $account_id=null, &$on_login=null) |
157 | 157 | { |
158 | - if (is_null($type)) $type = self::ALL; |
|
158 | + if (is_null($type)) |
|
159 | + { |
|
160 | + $type = self::ALL; |
|
161 | + } |
|
159 | 162 | if (is_null($account_id)) |
160 | 163 | { |
161 | 164 | $account_id = array(0, $GLOBALS['egw_info']['user']['account_id']); |
@@ -201,7 +204,10 @@ discard block |
||
201 | 204 | $password = self::decrypt($row); |
202 | 205 | |
203 | 206 | // Remove special x char added to the end for \0 trimming escape. |
204 | - if ($type == self::SMIME && substr($password, -1) === 'x') $password = substr($password, 0, -1); |
|
207 | + if ($type == self::SMIME && substr($password, -1) === 'x') |
|
208 | + { |
|
209 | + $password = substr($password, 0, -1); |
|
210 | + } |
|
205 | 211 | |
206 | 212 | foreach(self::$type2prefix as $pattern => $prefix) |
207 | 213 | { |
@@ -296,12 +302,18 @@ discard block |
||
296 | 302 | |
297 | 303 | // Add arbitary char to the ending to make sure the Smime binary content |
298 | 304 | // with \0 at the end not getting trimmed of while trying to decrypt. |
299 | - if ($type == self::SMIME) $password .= 'x'; |
|
305 | + if ($type == self::SMIME) |
|
306 | + { |
|
307 | + $password .= 'x'; |
|
308 | + } |
|
300 | 309 | |
301 | 310 | // no need to write empty usernames, but delete existing row |
302 | 311 | if ((string)$username === '') |
303 | 312 | { |
304 | - if ($cred_id) self::$db->delete(self::TABLE, array('cred_id' => $cred_id), __LINE__, __FILE__, self::APP); |
|
313 | + if ($cred_id) |
|
314 | + { |
|
315 | + self::$db->delete(self::TABLE, array('cred_id' => $cred_id), __LINE__, __FILE__, self::APP); |
|
316 | + } |
|
305 | 317 | return; // nothing to save |
306 | 318 | } |
307 | 319 | $pw_enc = self::CLEARTEXT; |
@@ -357,8 +369,14 @@ discard block |
||
357 | 369 | throw new Api\Exception\WrongParameter(__METHOD__."() no acc_id AND no account_id parameter!"); |
358 | 370 | } |
359 | 371 | $where = array(); |
360 | - if ($acc_id > 0) $where['acc_id'] = $acc_id; |
|
361 | - if (isset($account_id)) $where['account_id'] = $account_id; |
|
372 | + if ($acc_id > 0) |
|
373 | + { |
|
374 | + $where['acc_id'] = $acc_id; |
|
375 | + } |
|
376 | + if (isset($account_id)) |
|
377 | + { |
|
378 | + $where['account_id'] = $account_id; |
|
379 | + } |
|
362 | 380 | if ($exact_type) |
363 | 381 | { |
364 | 382 | $where['cred_type'] = $type; |
@@ -521,7 +539,10 @@ discard block |
||
521 | 539 | protected static function decrypt(array $row, $key=null) |
522 | 540 | { |
523 | 541 | // empty/unset passwords only give warnings ... |
524 | - if (empty($row['cred_password'])) return ''; |
|
542 | + if (empty($row['cred_password'])) |
|
543 | + { |
|
544 | + return ''; |
|
545 | + } |
|
525 | 546 | |
526 | 547 | if (self::isUser($row['cred_pw_enc']) && $row['account_id'] != $GLOBALS['egw_info']['user']['account_id']) |
527 | 548 | { |
@@ -626,7 +647,11 @@ discard block |
||
626 | 647 | } |
627 | 648 | // seems iv is NOT used for mcrypt "tripledes/ecb" = openssl "des-ede3", only key-size 24 |
628 | 649 | $keySize = 24; |
629 | - if (bytes($key) > $keySize) $key = cut_bytes($key,0,$keySize-1); // $keySize-1 is wrong, but that's what's used! |
|
650 | + if (bytes($key) > $keySize) |
|
651 | + { |
|
652 | + $key = cut_bytes($key,0,$keySize-1); |
|
653 | + } |
|
654 | + // $keySize-1 is wrong, but that's what's used! |
|
630 | 655 | return trim(openssl_decrypt($row['cred_password'], self::TRIPLEDES_ECB_METHOD, $key, OPENSSL_ZERO_PADDING, ''), "\0"); |
631 | 656 | } |
632 | 657 | |
@@ -707,7 +732,10 @@ discard block |
||
707 | 732 | */ |
708 | 733 | static public function changepassword(array $data) |
709 | 734 | { |
710 | - if (empty($data['old_passwd'])) return; |
|
735 | + if (empty($data['old_passwd'])) |
|
736 | + { |
|
737 | + return; |
|
738 | + } |
|
711 | 739 | |
712 | 740 | // as self::encrypt will use password in session, check it is identical to given new password |
713 | 741 | if ($data['new_passwd'] !== base64_decode(Api\Cache::getSession('phpgwapi', 'password'))) |
@@ -788,7 +816,10 @@ discard block |
||
788 | 816 | mcrypt_create_iv ($iv_size, MCRYPT_RAND) : substr($GLOBALS['egw_info']['server']['mcrypt_iv'],0,$iv_size); |
789 | 817 | |
790 | 818 | $key_size = mcrypt_enc_get_key_size($mcrypt); |
791 | - if (bytes($key) > $key_size) $key = cut_bytes($key,0,$key_size-1); |
|
819 | + if (bytes($key) > $key_size) |
|
820 | + { |
|
821 | + $key = cut_bytes($key,0,$key_size-1); |
|
822 | + } |
|
792 | 823 | |
793 | 824 | if (mcrypt_generic_init($mcrypt, $key, $iv) < 0) |
794 | 825 | { |
@@ -548,7 +548,7 @@ |
||
548 | 548 | * Validate and create a new content type |
549 | 549 | * |
550 | 550 | * @param array $content |
551 | - * @return string|boolean New type ID, or false for error |
|
551 | + * @return false|string New type ID, or false for error |
|
552 | 552 | */ |
553 | 553 | function create_content_type(&$content) |
554 | 554 | { |
@@ -32,10 +32,10 @@ discard block |
||
32 | 32 | { |
33 | 33 | |
34 | 34 | /** |
35 | - * appname of app which want to add / edit its customfields |
|
36 | - * |
|
37 | - * @var string |
|
38 | - */ |
|
35 | + * appname of app which want to add / edit its customfields |
|
36 | + * |
|
37 | + * @var string |
|
38 | + */ |
|
39 | 39 | var $appname; |
40 | 40 | |
41 | 41 | /** |
@@ -44,10 +44,10 @@ discard block |
||
44 | 44 | protected $use_private = false; |
45 | 45 | |
46 | 46 | /** |
47 | - * userdefiened types e.g. type of infolog |
|
48 | - * |
|
49 | - * @var array |
|
50 | - */ |
|
47 | + * userdefiened types e.g. type of infolog |
|
48 | + * |
|
49 | + * @var array |
|
50 | + */ |
|
51 | 51 | var $types2 = array(); |
52 | 52 | var $content_types,$fields; |
53 | 53 | |
@@ -507,8 +507,8 @@ discard block |
||
507 | 507 | } |
508 | 508 | |
509 | 509 | /** |
510 | - * deletes custom field from customfield definitions |
|
511 | - */ |
|
510 | + * deletes custom field from customfield definitions |
|
511 | + */ |
|
512 | 512 | function delete_field(&$content) |
513 | 513 | { |
514 | 514 | unset($this->fields[key($content['fields']['delete'])]); |
@@ -525,8 +525,8 @@ discard block |
||
525 | 525 | } |
526 | 526 | |
527 | 527 | /** |
528 | - * create a new custom field |
|
529 | - */ |
|
528 | + * create a new custom field |
|
529 | + */ |
|
530 | 530 | function create_field(&$content) |
531 | 531 | { |
532 | 532 | $new_name = trim($content['fields'][count($content['fields'])-1]['name']); |
@@ -587,8 +587,8 @@ discard block |
||
587 | 587 | } |
588 | 588 | |
589 | 589 | /** |
590 | - * save changes to repository |
|
591 | - */ |
|
590 | + * save changes to repository |
|
591 | + */ |
|
592 | 592 | function save_repository() |
593 | 593 | { |
594 | 594 | //echo '<p>uicustomfields::save_repository() \$this->fields=<pre style="text-aling: left;">'; print_r($this->fields); echo "</pre>\n"; |
@@ -601,25 +601,25 @@ discard block |
||
601 | 601 | } |
602 | 602 | |
603 | 603 | /** |
604 | - * get customfields of using application |
|
605 | - * |
|
606 | - * @deprecated use Api\Storage\Customfields::get() direct, no need to instanciate this UI class |
|
607 | - * @author Cornelius Weiss |
|
608 | - * @param boolean $all_private_too =false should all the private fields be returned too |
|
609 | - * @return array with customfields |
|
610 | - */ |
|
604 | + * get customfields of using application |
|
605 | + * |
|
606 | + * @deprecated use Api\Storage\Customfields::get() direct, no need to instanciate this UI class |
|
607 | + * @author Cornelius Weiss |
|
608 | + * @param boolean $all_private_too =false should all the private fields be returned too |
|
609 | + * @return array with customfields |
|
610 | + */ |
|
611 | 611 | function get_customfields($all_private_too=false) |
612 | 612 | { |
613 | 613 | return Api\Storage\Customfields::get($this->appname,$all_private_too); |
614 | 614 | } |
615 | 615 | |
616 | 616 | /** |
617 | - * get_content_types of using application |
|
618 | - * |
|
619 | - * @deprecated use Api\Config::get_content_types() direct, no need to instanciate this UI class |
|
620 | - * @author Cornelius Weiss |
|
621 | - * @return array with content-types |
|
622 | - */ |
|
617 | + * get_content_types of using application |
|
618 | + * |
|
619 | + * @deprecated use Api\Config::get_content_types() direct, no need to instanciate this UI class |
|
620 | + * @author Cornelius Weiss |
|
621 | + * @return array with content-types |
|
622 | + */ |
|
623 | 623 | function get_content_types() |
624 | 624 | { |
625 | 625 | return Api\Config::get_content_types($this->appname); |
@@ -127,7 +127,10 @@ discard block |
||
127 | 127 | { |
128 | 128 | // determine appname |
129 | 129 | $this->appname = $this->appname ? $this->appname : ($_GET['appname'] ? $_GET['appname'] : ($content['appname'] ? $content['appname'] : false)); |
130 | - if(!$this->appname) die(lang('Error! No appname found')); |
|
130 | + if(!$this->appname) |
|
131 | + { |
|
132 | + die(lang('Error! No appname found')); |
|
133 | + } |
|
131 | 134 | |
132 | 135 | $this->use_private = !isset($_GET['use_private']) || (boolean)$_GET['use_private'] || $content['use_private']; |
133 | 136 | |
@@ -139,7 +142,10 @@ discard block |
||
139 | 142 | |
140 | 143 | // do we manage content-types? |
141 | 144 | $test = new Etemplate(); |
142 | - if($test->read($this->appname.'.admin.types')) $this->manage_content_types = true; |
|
145 | + if($test->read($this->appname.'.admin.types')) |
|
146 | + { |
|
147 | + $this->manage_content_types = true; |
|
148 | + } |
|
143 | 149 | |
144 | 150 | // Handle incoming - types, options, etc. |
145 | 151 | if($this->manage_content_types) |
@@ -359,7 +365,11 @@ discard block |
||
359 | 365 | lang('Invalide value "%1", use only:', $var)."\n". |
360 | 366 | preg_replace('/^.*\[([^]]+)\].*$/', '$1', self::CHECK_MULTISELCT_VALUE)); |
361 | 367 | $action = 'apply'; // do not close the window to show validation error |
362 | - if (!$cf_id) break 2; // only stop storing of new CFs |
|
368 | + if (!$cf_id) |
|
369 | + { |
|
370 | + break 2; |
|
371 | + } |
|
372 | + // only stop storing of new CFs |
|
363 | 373 | } |
364 | 374 | $values[$var] = trim($value)==='' ? $var : $value; |
365 | 375 | } |
@@ -399,7 +409,10 @@ discard block |
||
399 | 409 | |
400 | 410 | // do we manage content-types? |
401 | 411 | $test = new Etemplate(); |
402 | - if($test->read($this->appname.'.admin.types')) $this->manage_content_types = true; |
|
412 | + if($test->read($this->appname.'.admin.types')) |
|
413 | + { |
|
414 | + $this->manage_content_types = true; |
|
415 | + } |
|
403 | 416 | |
404 | 417 | $this->tmpl = new Etemplate(); |
405 | 418 | $this->tmpl->read('admin.customfield_edit'); |
@@ -567,7 +580,10 @@ discard block |
||
567 | 580 | else |
568 | 581 | { |
569 | 582 | $this->fields[$new_name] = $content['fields'][count($content['fields'])-1]; |
570 | - if(!$this->fields[$new_name]['label']) $this->fields[$new_name]['label'] = $this->fields[$new_name]['name']; |
|
583 | + if(!$this->fields[$new_name]['label']) |
|
584 | + { |
|
585 | + $this->fields[$new_name]['label'] = $this->fields[$new_name]['name']; |
|
586 | + } |
|
571 | 587 | $this->save_repository(); |
572 | 588 | } |
573 | 589 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @var array |
50 | 50 | */ |
51 | 51 | var $types2 = array(); |
52 | - var $content_types,$fields; |
|
52 | + var $content_types, $fields; |
|
53 | 53 | |
54 | 54 | /** |
55 | 55 | * Does App uses content-types |
@@ -110,14 +110,14 @@ discard block |
||
110 | 110 | * |
111 | 111 | * @param string $appname |
112 | 112 | */ |
113 | - function __construct($appname='') |
|
113 | + function __construct($appname = '') |
|
114 | 114 | { |
115 | 115 | if (($this->appname = $appname)) |
116 | 116 | { |
117 | - $this->fields = Api\Storage\Customfields::get($this->appname,true); |
|
117 | + $this->fields = Api\Storage\Customfields::get($this->appname, true); |
|
118 | 118 | $this->content_types = Api\Config::get_content_types($this->appname); |
119 | 119 | } |
120 | - $this->so = new Api\Storage\Base('phpgwapi','egw_customfields',null,'',true); |
|
120 | + $this->so = new Api\Storage\Base('phpgwapi', 'egw_customfields', null, '', true); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -127,43 +127,43 @@ discard block |
||
127 | 127 | { |
128 | 128 | // determine appname |
129 | 129 | $this->appname = $this->appname ? $this->appname : ($_GET['appname'] ? $_GET['appname'] : ($content['appname'] ? $content['appname'] : false)); |
130 | - if(!$this->appname) die(lang('Error! No appname found')); |
|
130 | + if (!$this->appname) die(lang('Error! No appname found')); |
|
131 | 131 | |
132 | 132 | $this->use_private = !isset($_GET['use_private']) || (boolean)$_GET['use_private'] || $content['use_private']; |
133 | 133 | |
134 | 134 | // Read fields, constructor doesn't always know appname |
135 | - $this->fields = Api\Storage\Customfields::get($this->appname,true); |
|
135 | + $this->fields = Api\Storage\Customfields::get($this->appname, true); |
|
136 | 136 | |
137 | 137 | $this->tmpl = new Etemplate(); |
138 | 138 | $this->tmpl->read('admin.customfields'); |
139 | 139 | |
140 | 140 | // do we manage content-types? |
141 | 141 | $test = new Etemplate(); |
142 | - if($test->read($this->appname.'.admin.types')) $this->manage_content_types = true; |
|
142 | + if ($test->read($this->appname.'.admin.types')) $this->manage_content_types = true; |
|
143 | 143 | |
144 | 144 | // Handle incoming - types, options, etc. |
145 | - if($this->manage_content_types) |
|
145 | + if ($this->manage_content_types) |
|
146 | 146 | { |
147 | - if(count($this->content_types) == 0) |
|
147 | + if (count($this->content_types) == 0) |
|
148 | 148 | { |
149 | 149 | $this->content_types = Api\Config::get_content_types($this->appname); |
150 | 150 | } |
151 | - if (count($this->content_types)==0) |
|
151 | + if (count($this->content_types) == 0) |
|
152 | 152 | { |
153 | 153 | // if you define your default types of your app with the search_link hook, they are available here, if no types were found |
154 | - $this->content_types = (array)Api\Link::get_registry($this->appname,'default_types'); |
|
154 | + $this->content_types = (array)Api\Link::get_registry($this->appname, 'default_types'); |
|
155 | 155 | } |
156 | 156 | // Set this now, we need to know it for updates |
157 | - $this->content_type = $content['content_types']['types'] ? $content['content_types']['types'] : (array_key_exists(0,$this->content_types) ? $this->content_types[0] : key($this->content_types)); |
|
157 | + $this->content_type = $content['content_types']['types'] ? $content['content_types']['types'] : (array_key_exists(0, $this->content_types) ? $this->content_types[0] : key($this->content_types)); |
|
158 | 158 | |
159 | 159 | // Common type changes - add, delete |
160 | - if($content['content_types']['delete']) |
|
160 | + if ($content['content_types']['delete']) |
|
161 | 161 | { |
162 | 162 | $this->delete_content_type($content); |
163 | 163 | } |
164 | - elseif($content['content_types']['create']) |
|
164 | + elseif ($content['content_types']['create']) |
|
165 | 165 | { |
166 | - if(($new_type = $this->create_content_type($content))) |
|
166 | + if (($new_type = $this->create_content_type($content))) |
|
167 | 167 | { |
168 | 168 | $content['content_types']['types'] = $this->content_type = $new_type; |
169 | 169 | } |
@@ -171,18 +171,18 @@ discard block |
||
171 | 171 | unset($content['content_types']['name']); |
172 | 172 | } |
173 | 173 | // No common type change and type didn't change, try an update |
174 | - elseif($this->content_type && is_array($content) && $this->content_type == $content['old_content_type']) |
|
174 | + elseif ($this->content_type && is_array($content) && $this->content_type == $content['old_content_type']) |
|
175 | 175 | { |
176 | 176 | $this->update($content); |
177 | 177 | } |
178 | 178 | } |
179 | 179 | |
180 | 180 | // Custom field deleted from nextmatch |
181 | - if($content['nm']['action'] == 'delete') |
|
181 | + if ($content['nm']['action'] == 'delete') |
|
182 | 182 | { |
183 | - foreach($this->fields as $name => $data) |
|
183 | + foreach ($this->fields as $name => $data) |
|
184 | 184 | { |
185 | - if(in_array($data['id'],$content['nm']['selected'])) |
|
185 | + if (in_array($data['id'], $content['nm']['selected'])) |
|
186 | 186 | { |
187 | 187 | unset($this->fields[$name]); |
188 | 188 | } |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | $this->save_repository(); |
192 | 192 | } |
193 | 193 | |
194 | - $content['nm']= Api\Cache::getSession('admin', 'customfield-index'); |
|
194 | + $content['nm'] = Api\Cache::getSession('admin', 'customfield-index'); |
|
195 | 195 | if (!is_array($content['nm'])) |
196 | 196 | { |
197 | 197 | // Initialize nextmatch |
@@ -201,8 +201,8 @@ discard block |
||
201 | 201 | 'no_filter' => 'true', |
202 | 202 | 'no_filter2' => 'true', |
203 | 203 | 'row_id' => 'cf_id', |
204 | - 'order' => 'cf_order',// IO name of the column to sort |
|
205 | - 'sort' => 'ASC',// IO direction of the sort: 'ASC' or 'DESC' |
|
204 | + 'order' => 'cf_order', // IO name of the column to sort |
|
205 | + 'sort' => 'ASC', // IO direction of the sort: 'ASC' or 'DESC' |
|
206 | 206 | 'actions' => $this->get_actions() |
207 | 207 | ); |
208 | 208 | } |
@@ -210,11 +210,11 @@ discard block |
||
210 | 210 | $content['nm']['use_private'] = $this->use_private; |
211 | 211 | |
212 | 212 | // Set up sub-types |
213 | - if($this->manage_content_types) |
|
213 | + if ($this->manage_content_types) |
|
214 | 214 | { |
215 | - foreach($this->content_types as $type => $entry) |
|
215 | + foreach ($this->content_types as $type => $entry) |
|
216 | 216 | { |
217 | - if(!is_array($entry)) |
|
217 | + if (!is_array($entry)) |
|
218 | 218 | { |
219 | 219 | $this->content_types[$type] = array('name' => $entry); |
220 | 220 | $entry = $this->content_types[$type]; |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | } |
224 | 224 | $sel_options['types'] = $sel_options['cf_type2'] = $this->types2; |
225 | 225 | |
226 | - $content['type_template'] = $this->appname . '.admin.types'; |
|
226 | + $content['type_template'] = $this->appname.'.admin.types'; |
|
227 | 227 | $content['content_types']['appname'] = $this->appname; |
228 | 228 | |
229 | 229 | $content['content_type_options'] = $this->content_types[$this->content_type]['options']; |
@@ -265,16 +265,16 @@ discard block |
||
265 | 265 | static::app_index($content, $sel_options, $readonlys, $preserve); |
266 | 266 | |
267 | 267 | // Make sure app css gets loaded, extending app might cause et2 to miss it |
268 | - Framework::includeCSS('admin','app'); |
|
268 | + Framework::includeCSS('admin', 'app'); |
|
269 | 269 | |
270 | 270 | $GLOBALS['egw_info']['flags']['app_header'] = $GLOBALS['egw_info']['apps'][$this->appname]['title'].' - '.lang('Custom fields'); |
271 | 271 | |
272 | 272 | // Some logic to make sure extending class (if there is one) gets called |
273 | 273 | // when etemplate2 comes back instead of parent class |
274 | 274 | $exec = get_class() == get_called_class() || get_called_class() == 'customfields' ? |
275 | - 'admin.admin_customfields.index' : $this->appname . '.' . get_called_class() . '.index'; |
|
275 | + 'admin.admin_customfields.index' : $this->appname.'.'.get_called_class().'.index'; |
|
276 | 276 | |
277 | - $this->tmpl->exec($exec,$content,$sel_options,$readonlys,$preserve); |
|
277 | + $this->tmpl->exec($exec, $content, $sel_options, $readonlys, $preserve); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | /** |
@@ -296,28 +296,28 @@ discard block |
||
296 | 296 | |
297 | 297 | // determine appname |
298 | 298 | $this->appname = $this->appname ? $this->appname : ($_GET['appname'] ? $_GET['appname'] : ($content['cf_app'] ? $content['cf_app'] : false)); |
299 | - if(!$this->appname) |
|
299 | + if (!$this->appname) |
|
300 | 300 | { |
301 | - if($cf_id && $this->so) |
|
301 | + if ($cf_id && $this->so) |
|
302 | 302 | { |
303 | 303 | $content = $this->so->read($cf_id); |
304 | 304 | $this->appname = $content['cf_app']; |
305 | 305 | } |
306 | 306 | } |
307 | - if(!$this->appname) |
|
307 | + if (!$this->appname) |
|
308 | 308 | { |
309 | 309 | die(lang('Error! No appname found')); |
310 | 310 | } |
311 | 311 | $this->use_private = !isset($_GET['use_private']) || (boolean)$_GET['use_private'] || $content['use_private']; |
312 | 312 | |
313 | 313 | // Read fields, constructor doesn't always know appname |
314 | - $this->fields = Api\Storage\Customfields::get($this->appname,true); |
|
314 | + $this->fields = Api\Storage\Customfields::get($this->appname, true); |
|
315 | 315 | |
316 | 316 | // Update based on info returned from template |
317 | 317 | if (is_array($content)) |
318 | 318 | { |
319 | 319 | list($action) = @each($content['button']); |
320 | - switch($action) |
|
320 | + switch ($action) |
|
321 | 321 | { |
322 | 322 | case 'delete': |
323 | 323 | $this->so->delete($cf_id); |
@@ -326,54 +326,54 @@ discard block |
||
326 | 326 | break; |
327 | 327 | case 'save': |
328 | 328 | case 'apply': |
329 | - if(!$cf_id && $this->fields[$content['cf_name']]) |
|
329 | + if (!$cf_id && $this->fields[$content['cf_name']]) |
|
330 | 330 | { |
331 | - Framework::message(lang("Field '%1' already exists !!!",$content['cf_name']),'error'); |
|
331 | + Framework::message(lang("Field '%1' already exists !!!", $content['cf_name']), 'error'); |
|
332 | 332 | $content['cf_name'] = ''; |
333 | 333 | break; |
334 | 334 | } |
335 | - if(empty($content['cf_label'])) |
|
335 | + if (empty($content['cf_label'])) |
|
336 | 336 | { |
337 | 337 | $content['cf_label'] = $content['cf_name']; |
338 | 338 | } |
339 | 339 | if (!empty($content['cf_values'])) |
340 | 340 | { |
341 | 341 | $values = array(); |
342 | - if($content['cf_values'][0] === '@') |
|
342 | + if ($content['cf_values'][0] === '@') |
|
343 | 343 | { |
344 | - $values['@'] = substr($content['cf_values'], $content['cf_values'][1] === '=' ? 2:1); |
|
344 | + $values['@'] = substr($content['cf_values'], $content['cf_values'][1] === '=' ? 2 : 1); |
|
345 | 345 | } |
346 | 346 | else |
347 | 347 | { |
348 | - foreach(explode("\n",trim($content['cf_values'])) as $line) |
|
348 | + foreach (explode("\n", trim($content['cf_values'])) as $line) |
|
349 | 349 | { |
350 | - list($var_raw,$value) = explode('=',trim($line),2); |
|
350 | + list($var_raw, $value) = explode('=', trim($line), 2); |
|
351 | 351 | $var = trim($var_raw); |
352 | 352 | if (!preg_match(self::CHECK_MULTISELCT_VALUE, $var)) |
353 | 353 | { |
354 | 354 | Api\Etemplate::set_validation_error('cf_values', |
355 | 355 | lang('Invalide value "%1", use only:', $var)."\n". |
356 | 356 | preg_replace('/^.*\[([^]]+)\].*$/', '$1', self::CHECK_MULTISELCT_VALUE)); |
357 | - $action = 'apply'; // do not close the window to show validation error |
|
358 | - if (!$cf_id) break 2; // only stop storing of new CFs |
|
357 | + $action = 'apply'; // do not close the window to show validation error |
|
358 | + if (!$cf_id) break 2; // only stop storing of new CFs |
|
359 | 359 | } |
360 | - $values[$var] = trim($value)==='' ? $var : $value; |
|
360 | + $values[$var] = trim($value) === '' ? $var : $value; |
|
361 | 361 | } |
362 | 362 | } |
363 | 363 | $content['cf_values'] = $values; |
364 | 364 | } |
365 | 365 | $update_content = array(); |
366 | - foreach($content as $key => $value) |
|
366 | + foreach ($content as $key => $value) |
|
367 | 367 | { |
368 | - if(substr($key,0,3) == 'cf_') |
|
368 | + if (substr($key, 0, 3) == 'cf_') |
|
369 | 369 | { |
370 | - $update_content[substr($key,3)] = $value; |
|
370 | + $update_content[substr($key, 3)] = $value; |
|
371 | 371 | } |
372 | 372 | } |
373 | 373 | Api\Storage\Customfields::update($update_content); |
374 | - if(!$cf_id) |
|
374 | + if (!$cf_id) |
|
375 | 375 | { |
376 | - $this->fields = Api\Storage\Customfields::get($this->appname,true); |
|
376 | + $this->fields = Api\Storage\Customfields::get($this->appname, true); |
|
377 | 377 | $cf_id = (int)$this->fields[$content['cf_name']]['id']; |
378 | 378 | } |
379 | 379 | Framework::refresh_opener('Saved', 'admin', $cf_id, 'edit'); |
@@ -394,30 +394,30 @@ discard block |
||
394 | 394 | |
395 | 395 | // do we manage content-types? |
396 | 396 | $test = new Etemplate(); |
397 | - if($test->read($this->appname.'.admin.types')) $this->manage_content_types = true; |
|
397 | + if ($test->read($this->appname.'.admin.types')) $this->manage_content_types = true; |
|
398 | 398 | |
399 | 399 | $this->tmpl = new Etemplate(); |
400 | 400 | $this->tmpl->read('admin.customfield_edit'); |
401 | 401 | |
402 | - Api\Translation::add_app('infolog'); // til we move the translations |
|
402 | + Api\Translation::add_app('infolog'); // til we move the translations |
|
403 | 403 | |
404 | 404 | $GLOBALS['egw_info']['flags']['app_header'] = $GLOBALS['egw_info']['apps'][$this->appname]['title'].' - '.lang('Custom fields'); |
405 | 405 | $sel_options = array(); |
406 | 406 | $readonlys = array(); |
407 | 407 | |
408 | 408 | //echo 'customfields=<pre style="text-align: left;">'; print_r($this->fields); echo "</pre>\n"; |
409 | - $content['cf_order'] = (count($this->fields)+1) * 10; |
|
409 | + $content['cf_order'] = (count($this->fields) + 1) * 10; |
|
410 | 410 | $content['use_private'] = $this->use_private; |
411 | 411 | |
412 | - if($cf_id) |
|
412 | + if ($cf_id) |
|
413 | 413 | { |
414 | 414 | $content = array_merge($content, $this->so->read($cf_id)); |
415 | 415 | $this->appname = $content['cf_app']; |
416 | - if($content['cf_private']) |
|
416 | + if ($content['cf_private']) |
|
417 | 417 | { |
418 | - $content['cf_private'] = explode(',',$content['cf_private']); |
|
418 | + $content['cf_private'] = explode(',', $content['cf_private']); |
|
419 | 419 | } |
420 | - if($content['cf_name']) |
|
420 | + if ($content['cf_name']) |
|
421 | 421 | { |
422 | 422 | $readonlys['cf_name'] = true; |
423 | 423 | } |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | if (is_array($content['cf_values'])) |
431 | 431 | { |
432 | 432 | $values = ''; |
433 | - foreach($content['cf_values'] as $var => $value) |
|
433 | + foreach ($content['cf_values'] as $var => $value) |
|
434 | 434 | { |
435 | 435 | $values .= (!empty($values) ? "\n" : '').$var.'='.$value; |
436 | 436 | } |
@@ -438,18 +438,18 @@ discard block |
||
438 | 438 | } |
439 | 439 | |
440 | 440 | // Show sub-type row, and get types |
441 | - if($this->manage_content_types) |
|
441 | + if ($this->manage_content_types) |
|
442 | 442 | { |
443 | - if(count($this->content_types) == 0) |
|
443 | + if (count($this->content_types) == 0) |
|
444 | 444 | { |
445 | 445 | $this->content_types = Api\Config::get_content_types($this->appname); |
446 | 446 | } |
447 | - if (count($this->content_types)==0) |
|
447 | + if (count($this->content_types) == 0) |
|
448 | 448 | { |
449 | 449 | // if you define your default types of your app with the search_link hook, they are available here, if no types were found |
450 | 450 | $this->content_types = (array)Api\Link::get_registry($this->appname, 'default_types'); |
451 | 451 | } |
452 | - foreach($this->content_types as $type => $entry) |
|
452 | + foreach ($this->content_types as $type => $entry) |
|
453 | 453 | { |
454 | 454 | $this->types2[$type] = is_array($entry) ? $entry['name'] : $entry; |
455 | 455 | } |
@@ -461,19 +461,19 @@ discard block |
||
461 | 461 | } |
462 | 462 | |
463 | 463 | // Include type-specific value help |
464 | - foreach(self::$type_option_help as $key => $value) |
|
464 | + foreach (self::$type_option_help as $key => $value) |
|
465 | 465 | { |
466 | 466 | $content['options'][$key] = lang($value); |
467 | 467 | } |
468 | 468 | $content['statustext'] = $content['options'][$content['cf_type']]; |
469 | 469 | $content['attributes'] = self::$type_attribute_flags; |
470 | 470 | |
471 | - $this->tmpl->exec('admin.admin_customfields.edit',$content,$sel_options,$readonlys,array( |
|
471 | + $this->tmpl->exec('admin.admin_customfields.edit', $content, $sel_options, $readonlys, array( |
|
472 | 472 | 'cf_id' => $cf_id, |
473 | 473 | 'cf_app' => $this->appname, |
474 | 474 | 'cf_name' => $content['cf_name'], |
475 | 475 | 'use_private' => $this->use_private, |
476 | - ),2); |
|
476 | + ), 2); |
|
477 | 477 | } |
478 | 478 | |
479 | 479 | /** |
@@ -482,7 +482,7 @@ discard block |
||
482 | 482 | */ |
483 | 483 | protected function app_index(&$content, &$sel_options, &$readonlys, &$preserve) |
484 | 484 | { |
485 | - unset($content, $sel_options, $readonlys, $preserve); // not used, as this is a stub |
|
485 | + unset($content, $sel_options, $readonlys, $preserve); // not used, as this is a stub |
|
486 | 486 | // This is just a stub. |
487 | 487 | } |
488 | 488 | |
@@ -502,7 +502,7 @@ discard block |
||
502 | 502 | 'allowOnMultiple' => false, |
503 | 503 | 'url' => 'menuaction=admin.admin_customfields.edit&cf_id=$id&use_private='.$this->use_private, |
504 | 504 | 'popup' => '500x380', |
505 | - 'group' => $group=1, |
|
505 | + 'group' => $group = 1, |
|
506 | 506 | 'disableClass' => 'th', |
507 | 507 | ), |
508 | 508 | 'add' => array( |
@@ -552,17 +552,16 @@ discard block |
||
552 | 552 | */ |
553 | 553 | function create_field(&$content) |
554 | 554 | { |
555 | - $new_name = trim($content['fields'][count($content['fields'])-1]['name']); |
|
555 | + $new_name = trim($content['fields'][count($content['fields']) - 1]['name']); |
|
556 | 556 | if (empty($new_name) || isset($this->fields[$new_name])) |
557 | 557 | { |
558 | 558 | $content['error_msg'] .= empty($new_name) ? |
559 | - lang('You have to enter a name, to create a new field!!!') : |
|
560 | - lang("Field '%1' already exists !!!",$new_name); |
|
559 | + lang('You have to enter a name, to create a new field!!!') : lang("Field '%1' already exists !!!", $new_name); |
|
561 | 560 | } |
562 | 561 | else |
563 | 562 | { |
564 | - $this->fields[$new_name] = $content['fields'][count($content['fields'])-1]; |
|
565 | - if(!$this->fields[$new_name]['label']) $this->fields[$new_name]['label'] = $this->fields[$new_name]['name']; |
|
563 | + $this->fields[$new_name] = $content['fields'][count($content['fields']) - 1]; |
|
564 | + if (!$this->fields[$new_name]['label']) $this->fields[$new_name]['label'] = $this->fields[$new_name]['name']; |
|
566 | 565 | $this->save_repository(); |
567 | 566 | } |
568 | 567 | } |
@@ -579,20 +578,20 @@ discard block |
||
579 | 578 | $new_type = false; |
580 | 579 | if (empty($new_name)) |
581 | 580 | { |
582 | - $this->tmpl->set_validation_error('content_types[name]','You have to enter a name, to create a new type!!!'); |
|
581 | + $this->tmpl->set_validation_error('content_types[name]', 'You have to enter a name, to create a new type!!!'); |
|
583 | 582 | } |
584 | 583 | else |
585 | 584 | { |
586 | - foreach($this->content_types as $type) |
|
585 | + foreach ($this->content_types as $type) |
|
587 | 586 | { |
588 | - if($type['name'] == $new_name) |
|
587 | + if ($type['name'] == $new_name) |
|
589 | 588 | { |
590 | - $this->tmpl->set_validation_error('content_types[name]',lang("type '%1' already exists !!!",$new_name)); |
|
589 | + $this->tmpl->set_validation_error('content_types[name]', lang("type '%1' already exists !!!", $new_name)); |
|
591 | 590 | return false; |
592 | 591 | } |
593 | 592 | } |
594 | 593 | // search free type character |
595 | - for($i=97;$i<=122;$i++) |
|
594 | + for ($i = 97; $i <= 122; $i++) |
|
596 | 595 | { |
597 | 596 | if (!$this->content_types[chr($i)] && |
598 | 597 | // skip letter of deleted type for addressbook content-types, as it gives SQL error |
@@ -617,7 +616,7 @@ discard block |
||
617 | 616 | //echo '<p>uicustomfields::save_repository() \$this->fields=<pre style="text-aling: left;">'; print_r($this->fields); echo "</pre>\n"; |
618 | 617 | $config = new Api\Config($this->appname); |
619 | 618 | $config->read_repository(); |
620 | - $config->value('types',$this->content_types); |
|
619 | + $config->value('types', $this->content_types); |
|
621 | 620 | $config->save_repository(); |
622 | 621 | |
623 | 622 | Api\Storage\Customfields::save($this->appname, $this->fields); |
@@ -631,9 +630,9 @@ discard block |
||
631 | 630 | * @param boolean $all_private_too =false should all the private fields be returned too |
632 | 631 | * @return array with customfields |
633 | 632 | */ |
634 | - function get_customfields($all_private_too=false) |
|
633 | + function get_customfields($all_private_too = false) |
|
635 | 634 | { |
636 | - return Api\Storage\Customfields::get($this->appname,$all_private_too); |
|
635 | + return Api\Storage\Customfields::get($this->appname, $all_private_too); |
|
637 | 636 | } |
638 | 637 | |
639 | 638 | /** |
@@ -659,13 +658,13 @@ discard block |
||
659 | 658 | $total = $this->so->get_rows($query, $rows, $readonlys); |
660 | 659 | unset($query['col_filter']['cf_app']); |
661 | 660 | |
662 | - foreach($rows as &$row) |
|
661 | + foreach ($rows as &$row) |
|
663 | 662 | { |
664 | 663 | $row['cf_values'] = json_decode($row['cf_values'], true); |
665 | 664 | if (is_array($row['cf_values'])) |
666 | 665 | { |
667 | 666 | $values = ''; |
668 | - foreach($row['cf_values'] as $var => $value) |
|
667 | + foreach ($row['cf_values'] as $var => $value) |
|
669 | 668 | { |
670 | 669 | $values .= (!empty($values) ? "\n" : '').$var.'='.$value; |
671 | 670 | } |
@@ -15,4 +15,6 @@ |
||
15 | 15 | * |
16 | 16 | * Wrapper allowing apps to use old name |
17 | 17 | */ |
18 | -class customfields extends admin_customfields {} |
|
18 | +class customfields extends admin_customfields |
|
19 | +{ |
|
20 | +} |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | * @param boolean $cloned =true true: object does NOT need to be cloned, false: to set attribute, set them in cloned object |
121 | 121 | * @return Etempalte\Widget current object or clone, if any attribute was set |
122 | 122 | */ |
123 | - public function set_attrs($xml, $cloned=true) |
|
123 | + public function set_attrs($xml, $cloned = true) |
|
124 | 124 | { |
125 | 125 | $this->attrs['type'] = $xml->localName; |
126 | 126 | parent::set_attrs($xml, $cloned); |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | |
165 | 165 | if (isset($item['item']) && is_array($item['item'])) |
166 | 166 | { |
167 | - foreach($item['item'] as &$child) |
|
167 | + foreach ($item['item'] as &$child) |
|
168 | 168 | { |
169 | 169 | $child = self::htmlencode_node($child); |
170 | 170 | } |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | { |
186 | 186 | return true; |
187 | 187 | } |
188 | - foreach((array)$item['item'] as $child) |
|
188 | + foreach ((array)$item['item'] as $child) |
|
189 | 189 | { |
190 | 190 | if (self::in_tree($id, $child)) return true; |
191 | 191 | } |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * @param array $content |
218 | 218 | * @param array &$validated=array() validated content |
219 | 219 | */ |
220 | - public function validate($cname, array $expand, array $content, &$validated=array()) |
|
220 | + public function validate($cname, array $expand, array $content, &$validated = array()) |
|
221 | 221 | { |
222 | 222 | $form_name = self::form_name($cname, $this->id, $expand); |
223 | 223 | |
@@ -231,13 +231,13 @@ discard block |
||
231 | 231 | { |
232 | 232 | $allowed = $this->attrs['multiple'] ? array() : array('' => $this->attrs['options']); |
233 | 233 | $allowed += self::selOptions($form_name); |
234 | - foreach((array) $value as $val) |
|
234 | + foreach ((array)$value as $val) |
|
235 | 235 | { |
236 | 236 | if ($this->type == 'tree-cat' && !($this->attrs['multiple'] && !$val) && !self::in_cats($val, $allowed) || |
237 | 237 | $this->type == 'tree' && !self::in_tree($val, $allowed)) |
238 | 238 | { |
239 | - self::set_validation_error($form_name,lang("'%1' is NOT allowed%2)!", $val, |
|
240 | - $this->type == 'tree-cat' ? " ('".implode("','",array_keys($allowed)).')' : ''), ''); |
|
239 | + self::set_validation_error($form_name, lang("'%1' is NOT allowed%2)!", $val, |
|
240 | + $this->type == 'tree-cat' ? " ('".implode("','", array_keys($allowed)).')' : ''), ''); |
|
241 | 241 | $value = ''; |
242 | 242 | break; |
243 | 243 | } |
@@ -254,18 +254,18 @@ discard block |
||
254 | 254 | { |
255 | 255 | $value = array_merge($value, (array)self::$request->preserv[$unavailable_name]); |
256 | 256 | } |
257 | - elseif(!$value) // for single cat, we only restore unavailable one, if no other was selected |
|
257 | + elseif (!$value) // for single cat, we only restore unavailable one, if no other was selected |
|
258 | 258 | { |
259 | 259 | $value = self::$request->preserv[$unavailable_name]; |
260 | 260 | } |
261 | 261 | } |
262 | - $value = implode(',',$value); |
|
262 | + $value = implode(',', $value); |
|
263 | 263 | } |
264 | 264 | if ($ok && $value === '' && $this->attrs['needed']) |
265 | 265 | { |
266 | - self::set_validation_error($form_name,lang('Field must not be empty !!!',$value),''); |
|
266 | + self::set_validation_error($form_name, lang('Field must not be empty !!!', $value), ''); |
|
267 | 267 | } |
268 | - $valid =& self::get_array($validated, $form_name, true); |
|
268 | + $valid = & self::get_array($validated, $form_name, true); |
|
269 | 269 | if (true) $valid = $value; |
270 | 270 | //error_log(__METHOD__."() $form_name: ".array2string($value_in).' --> '.array2string($value).', allowed='.array2string($allowed)); |
271 | 271 | } |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | { |
292 | 292 | // += to keep further options set by app code |
293 | 293 | self::$request->sel_options[$form_name] += self::typeOptions($this->attrs['type'], $this->attrs['options'], |
294 | - $no_lang=null, $this->attrs['readonly'], self::get_array(self::$request->content, $form_name), $form_name); |
|
294 | + $no_lang = null, $this->attrs['readonly'], self::get_array(self::$request->content, $form_name), $form_name); |
|
295 | 295 | |
296 | 296 | // if no_lang was modified, forward modification to the client |
297 | 297 | if ($no_lang != $this->attr['no_lang']) |
@@ -301,15 +301,15 @@ discard block |
||
301 | 301 | } |
302 | 302 | |
303 | 303 | // Make sure s, etc. are properly encoded when sent, and not double-encoded |
304 | - foreach(self::$request->sel_options[$form_name] as &$label) |
|
304 | + foreach (self::$request->sel_options[$form_name] as &$label) |
|
305 | 305 | { |
306 | - if(!is_array($label)) |
|
306 | + if (!is_array($label)) |
|
307 | 307 | { |
308 | - $label = html_entity_decode($label, ENT_NOQUOTES,'utf-8'); |
|
308 | + $label = html_entity_decode($label, ENT_NOQUOTES, 'utf-8'); |
|
309 | 309 | } |
310 | - elseif($label['label']) |
|
310 | + elseif ($label['label']) |
|
311 | 311 | { |
312 | - $label['label'] = html_entity_decode($label['label'], ENT_NOQUOTES,'utf-8'); |
|
312 | + $label['label'] = html_entity_decode($label['label'], ENT_NOQUOTES, 'utf-8'); |
|
313 | 313 | } |
314 | 314 | } |
315 | 315 | |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | * @param string $image_path =null default path to use, or empty to use default of /api/templates/default/images/dhtmlxtree |
322 | 322 | * @return string templated url if available, otherwise default path |
323 | 323 | */ |
324 | - public static function templateImagePath($image_path=null) |
|
324 | + public static function templateImagePath($image_path = null) |
|
325 | 325 | { |
326 | 326 | $webserver_url = $GLOBALS['egw_info']['server']['webserver_url']; |
327 | 327 | if (empty($image_path)) |
@@ -353,20 +353,20 @@ discard block |
||
353 | 353 | */ |
354 | 354 | public static function imagePath($image) |
355 | 355 | { |
356 | - static $image_path=null; |
|
357 | - if (!isset($image_path)) $image_path = self::templateImagePath (); |
|
356 | + static $image_path = null; |
|
357 | + if (!isset($image_path)) $image_path = self::templateImagePath(); |
|
358 | 358 | |
359 | 359 | $parts = explode('/', $image_path); |
360 | - $image_parts = explode('/', $image); |
|
360 | + $image_parts = explode('/', $image); |
|
361 | 361 | |
362 | 362 | // remove common parts |
363 | - while(isset($parts[0]) && $parts[0] === $image_parts[0]) |
|
363 | + while (isset($parts[0]) && $parts[0] === $image_parts[0]) |
|
364 | 364 | { |
365 | 365 | array_shift($parts); |
366 | 366 | array_shift($image_parts); |
367 | 367 | } |
368 | 368 | // add .. for different parts, except last image part |
369 | - $url = implode('/', array_merge(array_fill(0, count($parts)-1, '..'), $image_parts)); |
|
369 | + $url = implode('/', array_merge(array_fill(0, count($parts) - 1, '..'), $image_parts)); |
|
370 | 370 | |
371 | 371 | //error_log(__METHOD__."('$image') image_path=$image_path returning $url"); |
372 | 372 | return $url; |
@@ -388,10 +388,10 @@ discard block |
||
388 | 388 | } |
389 | 389 | else |
390 | 390 | { |
391 | - $name_parts = explode('[',str_replace(']','',$name)); |
|
391 | + $name_parts = explode('[', str_replace(']', '', $name)); |
|
392 | 392 | if (count($name_parts)) |
393 | 393 | { |
394 | - $org_name = $name_parts[count($name_parts)-1]; |
|
394 | + $org_name = $name_parts[count($name_parts) - 1]; |
|
395 | 395 | if (isset(self::$request->sel_options[$org_name]) && is_array(self::$request->sel_options[$org_name])) |
396 | 396 | { |
397 | 397 | $options += self::$request->sel_options[$org_name]; |
@@ -421,9 +421,9 @@ discard block |
||
421 | 421 | * @param string $form_name form-name of widget, used to store unavailable cats |
422 | 422 | * @return array with value => label pairs |
423 | 423 | */ |
424 | - public static function typeOptions($widget_type, $legacy_options, &$no_lang=false, $readonly=false, $value=null, $form_name=null) |
|
424 | + public static function typeOptions($widget_type, $legacy_options, &$no_lang = false, $readonly = false, $value = null, $form_name = null) |
|
425 | 425 | { |
426 | - list($rows,$type,$type2,$type3) = explode(',',$legacy_options); |
|
426 | + list($rows, $type, $type2, $type3) = explode(',', $legacy_options); |
|
427 | 427 | |
428 | 428 | $no_lang = false; |
429 | 429 | $options = array(); |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | if ($readonly) // for readonly we dont need to fetch all cat's, nor do we need to indent them by level |
434 | 434 | { |
435 | 435 | $cell['no_lang'] = True; |
436 | - foreach(is_array($value) ? $value : (strpos($value,',') !== false ? explode(',',$value) : array($value)) as $id) |
|
436 | + foreach (is_array($value) ? $value : (strpos($value, ',') !== false ? explode(',', $value) : array($value)) as $id) |
|
437 | 437 | { |
438 | 438 | if ($id) $cell['sel_options'][$id] = stripslashes($GLOBALS['egw']->categories->id2name($id)); |
439 | 439 | } |
@@ -441,14 +441,14 @@ discard block |
||
441 | 441 | } |
442 | 442 | if (!$type3 || $type3 === $GLOBALS['egw']->categories->app_name) |
443 | 443 | { |
444 | - $categories =& $GLOBALS['egw']->categories; |
|
444 | + $categories = & $GLOBALS['egw']->categories; |
|
445 | 445 | } |
446 | 446 | else // we need to instanciate a new cat object for the correct application |
447 | 447 | { |
448 | - $categories = new Api\Categories('',$type3); |
|
448 | + $categories = new Api\Categories('', $type3); |
|
449 | 449 | } |
450 | - $cat2path=array(); |
|
451 | - foreach((array)$categories->return_sorted_array(0,False,'','','',!$type,0,true) as $cat) |
|
450 | + $cat2path = array(); |
|
451 | + foreach ((array)$categories->return_sorted_array(0, False, '', '', '', !$type, 0, true) as $cat) |
|
452 | 452 | { |
453 | 453 | $s = stripslashes($cat['name']); |
454 | 454 | |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | if ($value) |
480 | 480 | { |
481 | 481 | $pathes = $unavailable = array(); |
482 | - foreach(is_array($value) ? $value : explode(',',$value) as $cat) |
|
482 | + foreach (is_array($value) ? $value : explode(',', $value) as $cat) |
|
483 | 483 | { |
484 | 484 | if (isset($cat2path[$cat])) |
485 | 485 | { |
@@ -187,7 +187,10 @@ discard block |
||
187 | 187 | } |
188 | 188 | foreach((array)$item['item'] as $child) |
189 | 189 | { |
190 | - if (self::in_tree($id, $child)) return true; |
|
190 | + if (self::in_tree($id, $child)) |
|
191 | + { |
|
192 | + return true; |
|
193 | + } |
|
191 | 194 | } |
192 | 195 | return false; |
193 | 196 | } |
@@ -254,10 +257,13 @@ discard block |
||
254 | 257 | { |
255 | 258 | $value = array_merge($value, (array)self::$request->preserv[$unavailable_name]); |
256 | 259 | } |
257 | - elseif(!$value) // for single cat, we only restore unavailable one, if no other was selected |
|
260 | + elseif(!$value) |
|
261 | + { |
|
262 | + // for single cat, we only restore unavailable one, if no other was selected |
|
258 | 263 | { |
259 | 264 | $value = self::$request->preserv[$unavailable_name]; |
260 | 265 | } |
266 | + } |
|
261 | 267 | } |
262 | 268 | $value = implode(',',$value); |
263 | 269 | } |
@@ -266,7 +272,10 @@ discard block |
||
266 | 272 | self::set_validation_error($form_name,lang('Field must not be empty !!!',$value),''); |
267 | 273 | } |
268 | 274 | $valid =& self::get_array($validated, $form_name, true); |
269 | - if (true) $valid = $value; |
|
275 | + if (true) |
|
276 | + { |
|
277 | + $valid = $value; |
|
278 | + } |
|
270 | 279 | //error_log(__METHOD__."() $form_name: ".array2string($value_in).' --> '.array2string($value).', allowed='.array2string($allowed)); |
271 | 280 | } |
272 | 281 | } |
@@ -286,7 +295,10 @@ discard block |
||
286 | 295 | //error_log(__METHOD__."() setting templated image-path for $form_name: $templated_path"); |
287 | 296 | } |
288 | 297 | |
289 | - if (!is_array(self::$request->sel_options[$form_name])) self::$request->sel_options[$form_name] = array(); |
|
298 | + if (!is_array(self::$request->sel_options[$form_name])) |
|
299 | + { |
|
300 | + self::$request->sel_options[$form_name] = array(); |
|
301 | + } |
|
290 | 302 | if ($this->attrs['type']) |
291 | 303 | { |
292 | 304 | // += to keep further options set by app code |
@@ -354,7 +366,10 @@ discard block |
||
354 | 366 | public static function imagePath($image) |
355 | 367 | { |
356 | 368 | static $image_path=null; |
357 | - if (!isset($image_path)) $image_path = self::templateImagePath (); |
|
369 | + if (!isset($image_path)) |
|
370 | + { |
|
371 | + $image_path = self::templateImagePath (); |
|
372 | + } |
|
358 | 373 | |
359 | 374 | $parts = explode('/', $image_path); |
360 | 375 | $image_parts = explode('/', $image); |
@@ -430,12 +445,18 @@ discard block |
||
430 | 445 | switch ($widget_type) |
431 | 446 | { |
432 | 447 | case 'tree-cat': // !$type == globals cats too, $type2: extraStyleMultiselect, $type3: application, if not current-app, $type4: parent-id, $type5=owner (-1=global),$type6=show missing |
433 | - if ($readonly) // for readonly we dont need to fetch all cat's, nor do we need to indent them by level |
|
448 | + if ($readonly) |
|
449 | + { |
|
450 | + // for readonly we dont need to fetch all cat's, nor do we need to indent them by level |
|
434 | 451 | { |
435 | 452 | $cell['no_lang'] = True; |
453 | + } |
|
436 | 454 | foreach(is_array($value) ? $value : (strpos($value,',') !== false ? explode(',',$value) : array($value)) as $id) |
437 | 455 | { |
438 | - if ($id) $cell['sel_options'][$id] = stripslashes($GLOBALS['egw']->categories->id2name($id)); |
|
456 | + if ($id) |
|
457 | + { |
|
458 | + $cell['sel_options'][$id] = stripslashes($GLOBALS['egw']->categories->id2name($id)); |
|
459 | + } |
|
439 | 460 | } |
440 | 461 | break; |
441 | 462 | } |
@@ -376,7 +376,6 @@ discard block |
||
376 | 376 | * Get options from $sel_options array for a given selectbox name |
377 | 377 | * |
378 | 378 | * @param string $name |
379 | - * @param boolean $no_lang=false value of no_lang attribute |
|
380 | 379 | * @return array |
381 | 380 | */ |
382 | 381 | public static function selOptions($name) |
@@ -415,7 +414,7 @@ discard block |
||
415 | 414 | * |
416 | 415 | * @param string $widget_type |
417 | 416 | * @param string $legacy_options options string of widget |
418 | - * @param boolean $no_lang=false initial value of no_lang attribute (some types set it to true) |
|
417 | + * @param boolean $no_lang initial value of no_lang attribute (some types set it to true) |
|
419 | 418 | * @param boolean $readonly =false |
420 | 419 | * @param mixed $value =null value for readonly |
421 | 420 | * @param string $form_name form-name of widget, used to store unavailable cats |
@@ -373,9 +373,9 @@ discard block |
||
373 | 373 | * |
374 | 374 | * Calls get_links() repeatedly to get all the combinations for the content. |
375 | 375 | * |
376 | - * @param $app String appname |
|
377 | - * @param $id String ID of record |
|
378 | - * @param $prefix |
|
376 | + * @param string $app String appname |
|
377 | + * @param integer $id String ID of record |
|
378 | + * @param string $prefix |
|
379 | 379 | * @param $content String document content |
380 | 380 | */ |
381 | 381 | protected function get_all_links($app, $id, $prefix, &$content) |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | * @param mixed $app_limit app_limit, if not set checks the global limit |
536 | 536 | * @param string $checkas [AND|ISALLOWED], AND default; if set to ISALLOWED it is checked if Export is allowed |
537 | 537 | * |
538 | - * @return bool - true if no export is allowed or a limit is set, false if there is no restriction |
|
538 | + * @return boolean|null - true if no export is allowed or a limit is set, false if there is no restriction |
|
539 | 539 | */ |
540 | 540 | public static function hasExportLimit($app_limit,$checkas='AND') |
541 | 541 | { |
@@ -585,6 +585,9 @@ discard block |
||
585 | 585 | return $content; |
586 | 586 | } |
587 | 587 | |
588 | + /** |
|
589 | + * @param string $mimetype |
|
590 | + */ |
|
588 | 591 | protected function apply_styles (&$content, $mimetype, $mso_application_progid=null) |
589 | 592 | { |
590 | 593 | if (!isset($mso_application_progid)) |
@@ -1178,6 +1181,8 @@ discard block |
||
1178 | 1181 | |
1179 | 1182 | /** |
1180 | 1183 | * Convert numeric values in spreadsheets into actual numeric values |
1184 | + * @param string $content |
|
1185 | + * @param string $mimetype |
|
1181 | 1186 | */ |
1182 | 1187 | protected function format_spreadsheet_numbers(&$content, $names, $mimetype) |
1183 | 1188 | { |
@@ -1247,6 +1252,7 @@ discard block |
||
1247 | 1252 | |
1248 | 1253 | /** |
1249 | 1254 | * Convert date / timestamp values in spreadsheets into actual date / timestamp values |
1255 | + * @param string $mimetype |
|
1250 | 1256 | */ |
1251 | 1257 | protected function format_spreadsheet_dates(&$content, $names, &$values, $mimetype) |
1252 | 1258 | { |
@@ -1351,6 +1357,7 @@ discard block |
||
1351 | 1357 | /** |
1352 | 1358 | * Expand link_to custom fields with the merge replacements from the app |
1353 | 1359 | * but only if the template uses them. |
1360 | + * @param string $app |
|
1354 | 1361 | */ |
1355 | 1362 | public function cf_link_to_expand($values, $content, &$replacements, $app = null) |
1356 | 1363 | { |
@@ -1416,7 +1423,7 @@ discard block |
||
1416 | 1423 | /** |
1417 | 1424 | * Process special flags, such as IF or NELF |
1418 | 1425 | * |
1419 | - * @param content Text to be examined and changed |
|
1426 | + * @param content string to be examined and changed |
|
1420 | 1427 | * @param replacements array of markers => replacement |
1421 | 1428 | * |
1422 | 1429 | * @return changed content |
@@ -1729,8 +1736,7 @@ discard block |
||
1729 | 1736 | * Get a list of document actions / files from the given directory |
1730 | 1737 | * |
1731 | 1738 | * @param string $dirs Directory(s comma or space separated) to search |
1732 | - * @param string $prefix='document_' prefix for array keys |
|
1733 | - * @param array|string $mime_filter=null allowed mime type(s), default all, negative filter if $mime_filter[0] === '!' |
|
1739 | + * @param array|string $mime_filter allowed mime type(s), default all, negative filter if $mime_filter[0] === '!' |
|
1734 | 1740 | * @return array List of documents, suitable for a selectbox. The key is document_<filename>. |
1735 | 1741 | */ |
1736 | 1742 | public static function get_documents($dirs, $prefix='document_', $mime_filter=null, $app='') |
@@ -1997,7 +2003,8 @@ discard block |
||
1997 | 2003 | * |
1998 | 2004 | * @param string &$document maybe relative path of document, on return true absolute path to existing document |
1999 | 2005 | * @param string $dirs comma or whitespace separated directories |
2000 | - * @return string|boolean false if document exists, otherwise string with error-message |
|
2006 | + * @param string $document |
|
2007 | + * @return false|string false if document exists, otherwise string with error-message |
|
2001 | 2008 | */ |
2002 | 2009 | public static function check_document(&$document, $dirs) |
2003 | 2010 | { |
@@ -1456,19 +1456,19 @@ discard block |
||
1456 | 1456 | if (strpos($content,'$$IF') !== false) |
1457 | 1457 | { //Example use to use: $$IF n_prefix~Herr~Sehr geehrter~Sehr geehrte$$ |
1458 | 1458 | $this->replacements =& $replacements; |
1459 | - $content = preg_replace_callback('/\$\$IF ([#0-9a-z_\/-]+)~(.*)~(.*)~(.*)\$\$/imU',Array($this,'replace_callback'),$content); |
|
1459 | + $content = preg_replace_callback('/\$\$IF ([#0-9a-z_\/-]+)~(.*)~(.*)~(.*)\$\$/imU',array($this,'replace_callback'),$content); |
|
1460 | 1460 | unset($this->replacements); |
1461 | 1461 | } |
1462 | 1462 | if (strpos($content,'$$NELF') !== false) |
1463 | 1463 | { //Example: $$NEPBR org_unit$$ sets a LF and value of org_unit, only if there is a value |
1464 | 1464 | $this->replacements =& $replacements; |
1465 | - $content = preg_replace_callback('/\$\$NELF ([#0-9a-z_\/-]+)\$\$/imU',Array($this,'replace_callback'),$content); |
|
1465 | + $content = preg_replace_callback('/\$\$NELF ([#0-9a-z_\/-]+)\$\$/imU',array($this,'replace_callback'),$content); |
|
1466 | 1466 | unset($this->replacements); |
1467 | 1467 | } |
1468 | 1468 | if (strpos($content,'$$NENVLF') !== false) |
1469 | 1469 | { //Example: $$NEPBRNV org_unit$$ sets only a LF if there is a value for org_units, but did not add any value |
1470 | 1470 | $this->replacements =& $replacements; |
1471 | - $content = preg_replace_callback('/\$\$NENVLF ([#0-9a-z_\/-]+)\$\$/imU',Array($this,'replace_callback'),$content); |
|
1471 | + $content = preg_replace_callback('/\$\$NENVLF ([#0-9a-z_\/-]+)\$\$/imU',array($this,'replace_callback'),$content); |
|
1472 | 1472 | unset($this->replacements); |
1473 | 1473 | } |
1474 | 1474 | if (strpos($content,'$$LETTERPREFIX$$') !== false) |
@@ -1479,7 +1479,7 @@ discard block |
||
1479 | 1479 | if (strpos($content,'$$LETTERPREFIXCUSTOM') !== false) |
1480 | 1480 | { //Example use to use for a custom Letter Prefix: $$LETTERPREFIX n_prefix title n_family$$ |
1481 | 1481 | $this->replacements =& $replacements; |
1482 | - $content = preg_replace_callback('/\$\$LETTERPREFIXCUSTOM ([#0-9a-z_-]+)(.*)\$\$/imU',Array($this,'replace_callback'),$content); |
|
1482 | + $content = preg_replace_callback('/\$\$LETTERPREFIXCUSTOM ([#0-9a-z_-]+)(.*)\$\$/imU',array($this,'replace_callback'),$content); |
|
1483 | 1483 | unset($this->replacements); |
1484 | 1484 | } |
1485 | 1485 | return $content; |
@@ -2055,7 +2055,7 @@ discard block |
||
2055 | 2055 | * @param Array $file Array of information about the document from Api\Vfs::find |
2056 | 2056 | * @return void |
2057 | 2057 | */ |
2058 | - private static function document_mail_action(Array &$action, $file) |
|
2058 | + private static function document_mail_action(array &$action, $file) |
|
2059 | 2059 | { |
2060 | 2060 | unset($action['postSubmit']); |
2061 | 2061 | |
@@ -2088,7 +2088,7 @@ discard block |
||
2088 | 2088 | * @param Array $file Array of information about the document from Api\Vfs::find |
2089 | 2089 | * @return void |
2090 | 2090 | */ |
2091 | - private static function document_editable_action(Array &$action, $file) |
|
2091 | + private static function document_editable_action(array &$action, $file) |
|
2092 | 2092 | { |
2093 | 2093 | unset($action['postSubmit']); |
2094 | 2094 | $action['nm_action'] = 'location'; |
@@ -168,7 +168,10 @@ discard block |
||
168 | 168 | switch ($mimetype) |
169 | 169 | { |
170 | 170 | case 'application/msword': |
171 | - if (strtolower($extension) != '.rtf') break; |
|
171 | + if (strtolower($extension) != '.rtf') |
|
172 | + { |
|
173 | + break; |
|
174 | + } |
|
172 | 175 | case 'application/rtf': |
173 | 176 | case 'text/rtf': |
174 | 177 | return true; // rtf files |
@@ -178,7 +181,10 @@ discard block |
||
178 | 181 | case 'application/vnd.oasis.opendocument.text-template': |
179 | 182 | case 'application/vnd.oasis.opendocument.spreadsheet-template': |
180 | 183 | case 'application/vnd.oasis.opendocument.presentation-template': |
181 | - if (!$zip_available) break; |
|
184 | + if (!$zip_available) |
|
185 | + { |
|
186 | + break; |
|
187 | + } |
|
182 | 188 | return true; // open office write xml files |
183 | 189 | case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms word 2007 xml format |
184 | 190 | case 'application/vnd.openxmlformats-officedocument.wordprocessingml.d': // mimetypes in vfs are limited to 64 chars |
@@ -186,7 +192,10 @@ discard block |
||
186 | 192 | case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': // ms excel 2007 xml format |
187 | 193 | case 'application/vnd.openxmlformats-officedocument.spreadsheetml.shee': |
188 | 194 | case 'application/vnd.ms-excel.sheet.macroenabled.12': |
189 | - if (!$zip_available) break; |
|
195 | + if (!$zip_available) |
|
196 | + { |
|
197 | + break; |
|
198 | + } |
|
190 | 199 | return true; // ms word xml format |
191 | 200 | case 'application/xml': |
192 | 201 | return true; // alias for text/xml, eg. ms office 2003 word format |
@@ -221,7 +230,10 @@ discard block |
||
221 | 230 | { |
222 | 231 | $contact = $this->contacts->read($contact, $ignore_acl); |
223 | 232 | } |
224 | - if (!is_array($contact)) return array(); |
|
233 | + if (!is_array($contact)) |
|
234 | + { |
|
235 | + return array(); |
|
236 | + } |
|
225 | 237 | |
226 | 238 | $replacements = array(); |
227 | 239 | foreach(array_keys($this->contacts->contact_fields) as $name) |
@@ -230,7 +242,10 @@ discard block |
||
230 | 242 | switch($name) |
231 | 243 | { |
232 | 244 | case 'created': case 'modified': |
233 | - if($value) $value = Api\DateTime::to($value); |
|
245 | + if($value) |
|
246 | + { |
|
247 | + $value = Api\DateTime::to($value); |
|
248 | + } |
|
234 | 249 | break; |
235 | 250 | case 'bday': |
236 | 251 | if ($value) |
@@ -278,7 +293,10 @@ discard block |
||
278 | 293 | } |
279 | 294 | break; |
280 | 295 | } |
281 | - if ($name != 'photo') $replacements['$$'.($prefix ? $prefix.'/':'').$name.'$$'] = $value; |
|
296 | + if ($name != 'photo') |
|
297 | + { |
|
298 | + $replacements['$$'.($prefix ? $prefix.'/':'').$name.'$$'] = $value; |
|
299 | + } |
|
282 | 300 | } |
283 | 301 | // set custom fields, should probably go to a general method all apps can use |
284 | 302 | // need to load all cfs for $ignore_acl=true |
@@ -300,17 +318,23 @@ discard block |
||
300 | 318 | $cats = array(); |
301 | 319 | foreach(is_array($contact['cat_id']) ? $contact['cat_id'] : explode(',',$contact['cat_id']) as $cat_id) |
302 | 320 | { |
303 | - if(!$cat_id) continue; |
|
321 | + if(!$cat_id) |
|
322 | + { |
|
323 | + continue; |
|
324 | + } |
|
304 | 325 | if($GLOBALS['egw']->categories->id2name($cat_id,'main') != $cat_id) |
305 | 326 | { |
306 | 327 | $path = explode(' / ', $GLOBALS['egw']->categories->id2name($cat_id, 'path')); |
307 | 328 | unset($path[0]); // Drop main |
308 | 329 | $cats[$GLOBALS['egw']->categories->id2name($cat_id,'main')][] = implode(' / ', $path); |
309 | - } elseif($cat_id) { |
|
330 | + } |
|
331 | + elseif($cat_id) |
|
332 | + { |
|
310 | 333 | $cats[$cat_id] = array(); |
311 | 334 | } |
312 | 335 | } |
313 | - foreach($cats as $main => $cat) { |
|
336 | + foreach($cats as $main => $cat) |
|
337 | + { |
|
314 | 338 | $replacements['$$'.($prefix ? $prefix.'/':'').'categories$$'] .= $GLOBALS['egw']->categories->id2name($main,'name') |
315 | 339 | . (count($cat) > 0 ? ': ' : '') . implode(', ', $cats[$main]) . "\n"; |
316 | 340 | } |
@@ -345,7 +369,10 @@ discard block |
||
345 | 369 | 'id' => $link_info |
346 | 370 | ); |
347 | 371 | } |
348 | - if($exclude && in_array($link_info['id'], $exclude)) continue; |
|
372 | + if($exclude && in_array($link_info['id'], $exclude)) |
|
373 | + { |
|
374 | + continue; |
|
375 | + } |
|
349 | 376 | |
350 | 377 | $title = Api\Link::title($link_info['app'], $link_info['id']); |
351 | 378 | if(class_exists('EGroupware\Stylite\Vfs\Links\StreamWrapper') && $link_info['app'] != Api\Link::VFS_APPNAME) |
@@ -365,7 +392,10 @@ discard block |
||
365 | 392 | $link = Api\Framework::link($link, array()); |
366 | 393 | } |
367 | 394 | // Prepend site |
368 | - if ($link[0] == '/') $link = Api\Framework::getUrl($link); |
|
395 | + if ($link[0] == '/') |
|
396 | + { |
|
397 | + $link = Api\Framework::getUrl($link); |
|
398 | + } |
|
369 | 399 | |
370 | 400 | $title = $style == 'href' ? Api\Html::a_href(Api\Html::htmlspecialchars($title), $link) : $link; |
371 | 401 | } |
@@ -421,7 +451,10 @@ discard block |
||
421 | 451 | $link = Api\Framework::link($link, array()); |
422 | 452 | } |
423 | 453 | // Prepend site |
424 | - if ($link[0] == '/') $link = Api\Framework::getUrl($link); |
|
454 | + if ($link[0] == '/') |
|
455 | + { |
|
456 | + $link = Api\Framework::getUrl($link); |
|
457 | + } |
|
425 | 458 | |
426 | 459 | $array['$$'.($prefix?$prefix.'/':'').$placeholder.'$$'] = Api\Html::a_href(Api\Html::htmlspecialchars($title), $link); |
427 | 460 | break; |
@@ -453,7 +486,10 @@ discard block |
||
453 | 486 | protected function format_datetime($time,$format=null) |
454 | 487 | { |
455 | 488 | trigger_error(__METHOD__ . ' is deprecated, use Api\DateTime::to($time, $format)', E_USER_DEPRECATED); |
456 | - if (is_null($format)) $format = $this->datetime_format; |
|
489 | + if (is_null($format)) |
|
490 | + { |
|
491 | + $format = $this->datetime_format; |
|
492 | + } |
|
457 | 493 | |
458 | 494 | return Api\DateTime::to($time,$format); |
459 | 495 | } |
@@ -495,7 +531,10 @@ discard block |
||
495 | 531 | public static function getExportLimit($app='common') |
496 | 532 | { |
497 | 533 | static $exportLimitStore=array(); |
498 | - if (empty($app)) $app='common'; |
|
534 | + if (empty($app)) |
|
535 | + { |
|
536 | + $app='common'; |
|
537 | + } |
|
499 | 538 | //error_log(__METHOD__.__LINE__.' called with app:'.$app); |
500 | 539 | if (!array_key_exists($app,$exportLimitStore)) |
501 | 540 | { |
@@ -504,7 +543,10 @@ discard block |
||
504 | 543 | if ($app !='common') |
505 | 544 | { |
506 | 545 | $app_limit = Api\Hooks::single('export_limit',$app); |
507 | - if ($app_limit) $exportLimitStore[$app] = $app_limit; |
|
546 | + if ($app_limit) |
|
547 | + { |
|
548 | + $exportLimitStore[$app] = $app_limit; |
|
549 | + } |
|
508 | 550 | } |
509 | 551 | //error_log(__METHOD__.__LINE__.' building cache for app:'.$app.' -> '.$exportLimitStore[$app]); |
510 | 552 | if (empty($exportLimitStore[$app])) |
@@ -537,10 +579,22 @@ discard block |
||
537 | 579 | */ |
538 | 580 | public static function hasExportLimit($app_limit,$checkas='AND') |
539 | 581 | { |
540 | - if (strtoupper($checkas) == 'ISALLOWED') return (empty($app_limit) || ($app_limit !='no' && $app_limit > 0) ); |
|
541 | - if (empty($app_limit)) return false; |
|
542 | - if ($app_limit == 'no') return true; |
|
543 | - if ($app_limit > 0) return true; |
|
582 | + if (strtoupper($checkas) == 'ISALLOWED') |
|
583 | + { |
|
584 | + return (empty($app_limit) || ($app_limit !='no' && $app_limit > 0) ); |
|
585 | + } |
|
586 | + if (empty($app_limit)) |
|
587 | + { |
|
588 | + return false; |
|
589 | + } |
|
590 | + if ($app_limit == 'no') |
|
591 | + { |
|
592 | + return true; |
|
593 | + } |
|
594 | + if ($app_limit > 0) |
|
595 | + { |
|
596 | + return true; |
|
597 | + } |
|
544 | 598 | } |
545 | 599 | |
546 | 600 | /** |
@@ -575,7 +629,8 @@ discard block |
||
575 | 629 | |
576 | 630 | try { |
577 | 631 | $content = $this->merge_string($content,$ids,$err,$mimetype,$fix); |
578 | - } catch (\Exception $e) { |
|
632 | + } |
|
633 | + catch (\Exception $e) { |
|
579 | 634 | _egw_log_exception($e); |
580 | 635 | $err = $e->getMessage(); |
581 | 636 | return false; |
@@ -663,7 +718,8 @@ discard block |
||
663 | 718 | $content = $xslt->transformToXml($element); |
664 | 719 | //echo $content;die(); |
665 | 720 | // Word 2003 needs two declarations, add extra declaration back in |
666 | - if($mimetype == 'application/xml' && $mso_application_progid == 'Word.Document' && strpos($content, '<?xml') !== 0) { |
|
721 | + if($mimetype == 'application/xml' && $mso_application_progid == 'Word.Document' && strpos($content, '<?xml') !== 0) |
|
722 | + { |
|
667 | 723 | $content = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'.$content; |
668 | 724 | } |
669 | 725 | // Validate |
@@ -725,7 +781,10 @@ discard block |
||
725 | 781 | // textdocuments are simple, they do not hold start and end, but they may have content before and after the $$pagerepeat$$ tag |
726 | 782 | // header and footer should not hold any $$ tags; if we find $$ tags with the header, we assume it is the pagerepeatcontent |
727 | 783 | $nohead = false; |
728 | - if (stripos($contentstart,'$$') !== false) $nohead = true; |
|
784 | + if (stripos($contentstart,'$$') !== false) |
|
785 | + { |
|
786 | + $nohead = true; |
|
787 | + } |
|
729 | 788 | if ($nohead) |
730 | 789 | { |
731 | 790 | $contentend = $contentrepeat; |
@@ -767,13 +826,19 @@ discard block |
||
767 | 826 | preg_match_all('/\$\$labelplacement\$\$/',$contentrepeat,$countlables, PREG_SPLIT_NO_EMPTY); |
768 | 827 | $countlables = count($countlables[0]); |
769 | 828 | preg_replace('/\$\$labelplacement\$\$/','',$Labelrepeat,1); |
770 | - if ($countlables > 1) $lableprint = true; |
|
829 | + if ($countlables > 1) |
|
830 | + { |
|
831 | + $lableprint = true; |
|
832 | + } |
|
771 | 833 | if (count($ids) > 1 && !$contentrepeat) |
772 | 834 | { |
773 | 835 | $err = lang('for more than one contact in a document use the tag pagerepeat!'); |
774 | 836 | return false; |
775 | 837 | } |
776 | - if ($this->report_memory_usage) error_log(__METHOD__."(count(ids)=".count($ids).") strlen(contentrepeat)=".strlen($contentrepeat).', strlen(labelrepeat)='.strlen($Labelrepeat)); |
|
838 | + if ($this->report_memory_usage) |
|
839 | + { |
|
840 | + error_log(__METHOD__."(count(ids)=".count($ids).") strlen(contentrepeat)=".strlen($contentrepeat).', strlen(labelrepeat)='.strlen($Labelrepeat)); |
|
841 | + } |
|
777 | 842 | |
778 | 843 | if ($contentrepeat) |
779 | 844 | { |
@@ -813,8 +878,15 @@ discard block |
||
813 | 878 | } |
814 | 879 | foreach ((array)$ids as $n => $id) |
815 | 880 | { |
816 | - if ($contentrepeat) $content = $contentrepeat; //content to repeat |
|
817 | - if ($lableprint) $content = $Labelrepeat; |
|
881 | + if ($contentrepeat) |
|
882 | + { |
|
883 | + $content = $contentrepeat; |
|
884 | + } |
|
885 | + //content to repeat |
|
886 | + if ($lableprint) |
|
887 | + { |
|
888 | + $content = $Labelrepeat; |
|
889 | + } |
|
818 | 890 | |
819 | 891 | // generate replacements; if exeption is thrown, catch it set error message and return false |
820 | 892 | try |
@@ -831,7 +903,10 @@ discard block |
||
831 | 903 | $err = $e->getMessage(); |
832 | 904 | return false; |
833 | 905 | } |
834 | - if ($this->report_memory_usage) error_log(__METHOD__."() $n: $id ".Api\Vfs::hsize(memory_get_usage(true))); |
|
906 | + if ($this->report_memory_usage) |
|
907 | + { |
|
908 | + error_log(__METHOD__."() $n: $id ".Api\Vfs::hsize(memory_get_usage(true))); |
|
909 | + } |
|
835 | 910 | // some general replacements: current user, date and time |
836 | 911 | if (strpos($content,'$$user/') !== null && ($user = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id'))) |
837 | 912 | { |
@@ -889,9 +964,12 @@ discard block |
||
889 | 964 | { |
890 | 965 | $contentrepeatpages[$countpage] = preg_replace('/\$\$labelplacement\$\$/',$Label,$contentrepeatpages[$countpage],1); |
891 | 966 | $count=$count+1; |
892 | - if (($count % $countlables) == 0 && count($contentrep)>$count) //new page |
|
967 | + if (($count % $countlables) == 0 && count($contentrep)>$count) |
|
968 | + { |
|
969 | + //new page |
|
893 | 970 | { |
894 | 971 | $countpage = $countpage+1; |
972 | + } |
|
895 | 973 | $contentrepeatpages[$countpage] = $Labelstart.$Labeltend; |
896 | 974 | } |
897 | 975 | } |
@@ -928,7 +1006,10 @@ discard block |
||
928 | 1006 | rewind($content_stream); |
929 | 1007 | return stream_get_contents($content_stream); |
930 | 1008 | } |
931 | - if ($this->report_memory_usage) error_log(__METHOD__."() returning ".Api\Vfs::hsize(memory_get_peak_usage(true))); |
|
1009 | + if ($this->report_memory_usage) |
|
1010 | + { |
|
1011 | + error_log(__METHOD__."() returning ".Api\Vfs::hsize(memory_get_peak_usage(true))); |
|
1012 | + } |
|
932 | 1013 | |
933 | 1014 | return $content; |
934 | 1015 | } |
@@ -977,7 +1058,10 @@ discard block |
||
977 | 1058 | break; |
978 | 1059 | |
979 | 1060 | default: // div. text files --> use our export-charset, defined in addressbook prefs |
980 | - if (empty($charset)) $charset = $this->contacts->prefs['csv_charset']; |
|
1061 | + if (empty($charset)) |
|
1062 | + { |
|
1063 | + $charset = $this->contacts->prefs['csv_charset']; |
|
1064 | + } |
|
981 | 1065 | break; |
982 | 1066 | } |
983 | 1067 | //error_log(__METHOD__."('$document', ... ,$mimetype) --> $charset (egw=".Api\Translation::charset().', export='.$this->contacts->prefs['csv_charset'].')'); |
@@ -1000,10 +1084,13 @@ discard block |
||
1000 | 1084 | } |
1001 | 1085 | } |
1002 | 1086 | } |
1003 | - if ($is_xml) // zip'ed xml document (eg. OO) |
|
1087 | + if ($is_xml) |
|
1088 | + { |
|
1089 | + // zip'ed xml document (eg. OO) |
|
1004 | 1090 | { |
1005 | 1091 | // Numeric fields |
1006 | 1092 | $names = array(); |
1093 | + } |
|
1007 | 1094 | |
1008 | 1095 | // Tags we can replace with the target document's version |
1009 | 1096 | $replace_tags = array(); |
@@ -1073,7 +1160,8 @@ discard block |
||
1073 | 1160 | else if (is_string($value) && (strpos($value,'<') !== false)) |
1074 | 1161 | { |
1075 | 1162 | // Clean HTML, if it's being kept |
1076 | - if($replace_tags && extension_loaded('tidy')) { |
|
1163 | + if($replace_tags && extension_loaded('tidy')) |
|
1164 | + { |
|
1077 | 1165 | $tidy = new tidy(); |
1078 | 1166 | $cleaned = $tidy->repairString($value, self::$tidy_config); |
1079 | 1167 | // Found errors. Strip it all so there's some output |
@@ -1107,16 +1195,20 @@ discard block |
||
1107 | 1195 | // replace all control chars (C0+C1) but CR (\015), LF (\012) and TAB (\011) (eg. vertical tabulators) with space |
1108 | 1196 | // as they are not allowed in xml |
1109 | 1197 | $value = preg_replace('/[\000-\010\013\014\016-\037\177-\237]/u',' ',$value); |
1110 | - if(is_numeric($value) && $name != '$$user/account_id$$') // account_id causes problems with the preg_replace below |
|
1198 | + if(is_numeric($value) && $name != '$$user/account_id$$') |
|
1199 | + { |
|
1200 | + // account_id causes problems with the preg_replace below |
|
1111 | 1201 | { |
1112 | 1202 | $names[] = preg_quote($name,'/'); |
1113 | 1203 | } |
1204 | + } |
|
1114 | 1205 | } |
1115 | 1206 | |
1116 | 1207 | // Look for numbers, set their value if needed |
1117 | 1208 | if($this->numeric_fields || count($names)) |
1118 | 1209 | { |
1119 | - foreach((array)$this->numeric_fields as $fieldname) { |
|
1210 | + foreach((array)$this->numeric_fields as $fieldname) |
|
1211 | + { |
|
1120 | 1212 | $names[] = preg_quote($fieldname,'/'); |
1121 | 1213 | } |
1122 | 1214 | $this->format_spreadsheet_numbers($content, $names, $mimetype.$mso_application_progid); |
@@ -1126,7 +1218,8 @@ discard block |
||
1126 | 1218 | if($this->date_fields || count($names)) |
1127 | 1219 | { |
1128 | 1220 | $names = array(); |
1129 | - foreach((array)$this->date_fields as $fieldname) { |
|
1221 | + foreach((array)$this->date_fields as $fieldname) |
|
1222 | + { |
|
1130 | 1223 | $names[] = $fieldname; |
1131 | 1224 | } |
1132 | 1225 | $this->format_spreadsheet_dates($content, $names, $replacements, $mimetype.$mso_application_progid); |
@@ -1209,7 +1302,8 @@ discard block |
||
1209 | 1302 | */ |
1210 | 1303 | protected function format_spreadsheet_numbers(&$content, $names, $mimetype) |
1211 | 1304 | { |
1212 | - foreach((array)$this->numeric_fields as $fieldname) { |
|
1305 | + foreach((array)$this->numeric_fields as $fieldname) |
|
1306 | + { |
|
1213 | 1307 | $names[] = preg_quote($fieldname,'/'); |
1214 | 1308 | } |
1215 | 1309 | switch($mimetype) |
@@ -1242,7 +1336,11 @@ discard block |
||
1242 | 1336 | // try to increase/double pcre.backtrack_limit failure |
1243 | 1337 | while(preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit()); |
1244 | 1338 | |
1245 | - if ($result) $content = $result; // On failure $result would be NULL |
|
1339 | + if ($result) |
|
1340 | + { |
|
1341 | + $content = $result; |
|
1342 | + } |
|
1343 | + // On failure $result would be NULL |
|
1246 | 1344 | } |
1247 | 1345 | } |
1248 | 1346 | |
@@ -1286,7 +1384,10 @@ discard block |
||
1286 | 1384 | 'application/vnd.oasis.opendocument.spreadsheet', // open office calc |
1287 | 1385 | 'application/xmlExcel.Sheet', // Excel 2003 |
1288 | 1386 | //'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'//Excel WTF |
1289 | - ))) return; |
|
1387 | + ))) |
|
1388 | + { |
|
1389 | + return; |
|
1390 | + } |
|
1290 | 1391 | |
1291 | 1392 | // Some different formats dates could be in, depending what they've been through |
1292 | 1393 | $formats = array( |
@@ -1307,9 +1408,12 @@ discard block |
||
1307 | 1408 | { |
1308 | 1409 | $date = Api\DateTime::createFromUserFormat($values[$key]); |
1309 | 1410 | if($mimetype == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' || |
1310 | - $mimetype == 'application/vnd.ms-excel.sheet.macroenabled.12')//Excel WTF |
|
1411 | + $mimetype == 'application/vnd.ms-excel.sheet.macroenabled.12') |
|
1412 | + { |
|
1413 | + //Excel WTF |
|
1311 | 1414 | { |
1312 | 1415 | $interval = $date->diff(new Api\DateTime('1900-01-00 0:00')); |
1416 | + } |
|
1313 | 1417 | $values[$key] = $interval->format('%a')+1;// 1900-02-29 did not exist |
1314 | 1418 | // 1440 minutes in a day - fractional part |
1315 | 1419 | $values[$key] += ($date->format('H') * 60 + $date->format('i'))/1440; |
@@ -1352,7 +1456,11 @@ discard block |
||
1352 | 1456 | // try to increase/double pcre.backtrack_limit failure |
1353 | 1457 | while(preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit()); |
1354 | 1458 | |
1355 | - if ($result) $content = $result; // On failure $result would be NULL |
|
1459 | + if ($result) |
|
1460 | + { |
|
1461 | + $content = $result; |
|
1462 | + } |
|
1463 | + // On failure $result would be NULL |
|
1356 | 1464 | } |
1357 | 1465 | } |
1358 | 1466 | |
@@ -1425,7 +1533,10 @@ discard block |
||
1425 | 1533 | } |
1426 | 1534 | else |
1427 | 1535 | { |
1428 | - if ($cfs[$field]['type'] == 'date' || $cfs[$field]['type'] == 'date-time') $this->date_fields[] = '#'.$field; |
|
1536 | + if ($cfs[$field]['type'] == 'date' || $cfs[$field]['type'] == 'date-time') |
|
1537 | + { |
|
1538 | + $this->date_fields[] = '#'.$field; |
|
1539 | + } |
|
1429 | 1540 | } |
1430 | 1541 | } |
1431 | 1542 | } |
@@ -1479,30 +1590,35 @@ discard block |
||
1479 | 1590 | private function process_commands($content, $replacements) |
1480 | 1591 | { |
1481 | 1592 | if (strpos($content,'$$IF') !== false) |
1482 | - { //Example use to use: $$IF n_prefix~Herr~Sehr geehrter~Sehr geehrte$$ |
|
1593 | + { |
|
1594 | +//Example use to use: $$IF n_prefix~Herr~Sehr geehrter~Sehr geehrte$$ |
|
1483 | 1595 | $this->replacements =& $replacements; |
1484 | 1596 | $content = preg_replace_callback('/\$\$IF ([#0-9a-z_\/-]+)~(.*)~(.*)~(.*)\$\$/imU',Array($this,'replace_callback'),$content); |
1485 | 1597 | unset($this->replacements); |
1486 | 1598 | } |
1487 | 1599 | if (strpos($content,'$$NELF') !== false) |
1488 | - { //Example: $$NEPBR org_unit$$ sets a LF and value of org_unit, only if there is a value |
|
1600 | + { |
|
1601 | +//Example: $$NEPBR org_unit$$ sets a LF and value of org_unit, only if there is a value |
|
1489 | 1602 | $this->replacements =& $replacements; |
1490 | 1603 | $content = preg_replace_callback('/\$\$NELF ([#0-9a-z_\/-]+)\$\$/imU',Array($this,'replace_callback'),$content); |
1491 | 1604 | unset($this->replacements); |
1492 | 1605 | } |
1493 | 1606 | if (strpos($content,'$$NENVLF') !== false) |
1494 | - { //Example: $$NEPBRNV org_unit$$ sets only a LF if there is a value for org_units, but did not add any value |
|
1607 | + { |
|
1608 | +//Example: $$NEPBRNV org_unit$$ sets only a LF if there is a value for org_units, but did not add any value |
|
1495 | 1609 | $this->replacements =& $replacements; |
1496 | 1610 | $content = preg_replace_callback('/\$\$NENVLF ([#0-9a-z_\/-]+)\$\$/imU',Array($this,'replace_callback'),$content); |
1497 | 1611 | unset($this->replacements); |
1498 | 1612 | } |
1499 | 1613 | if (strpos($content,'$$LETTERPREFIX$$') !== false) |
1500 | - { //Example use to use: $$LETTERPREFIX$$ |
|
1614 | + { |
|
1615 | +//Example use to use: $$LETTERPREFIX$$ |
|
1501 | 1616 | $LETTERPREFIXCUSTOM = '$$LETTERPREFIXCUSTOM n_prefix title n_family$$'; |
1502 | 1617 | $content = str_replace('$$LETTERPREFIX$$',$LETTERPREFIXCUSTOM,$content); |
1503 | 1618 | } |
1504 | 1619 | if (strpos($content,'$$LETTERPREFIXCUSTOM') !== false) |
1505 | - { //Example use to use for a custom Letter Prefix: $$LETTERPREFIX n_prefix title n_family$$ |
|
1620 | + { |
|
1621 | +//Example use to use for a custom Letter Prefix: $$LETTERPREFIX n_prefix title n_family$$ |
|
1506 | 1622 | $this->replacements =& $replacements; |
1507 | 1623 | $content = preg_replace_callback('/\$\$LETTERPREFIXCUSTOM ([#0-9a-z_-]+)(.*)\$\$/imU',Array($this,'replace_callback'),$content); |
1508 | 1624 | unset($this->replacements); |
@@ -1518,8 +1634,14 @@ discard block |
||
1518 | 1634 | */ |
1519 | 1635 | private function replace_callback($param) |
1520 | 1636 | { |
1521 | - if (array_key_exists('$$'.$param[4].'$$',$this->replacements)) $param[4] = $this->replacements['$$'.$param[4].'$$']; |
|
1522 | - if (array_key_exists('$$'.$param[3].'$$',$this->replacements)) $param[3] = $this->replacements['$$'.$param[3].'$$']; |
|
1637 | + if (array_key_exists('$$'.$param[4].'$$',$this->replacements)) |
|
1638 | + { |
|
1639 | + $param[4] = $this->replacements['$$'.$param[4].'$$']; |
|
1640 | + } |
|
1641 | + if (array_key_exists('$$'.$param[3].'$$',$this->replacements)) |
|
1642 | + { |
|
1643 | + $param[3] = $this->replacements['$$'.$param[3].'$$']; |
|
1644 | + } |
|
1523 | 1645 | |
1524 | 1646 | $pattern = '/'.preg_quote($param[2], '/').'/'; |
1525 | 1647 | if (strpos($param[0],'$$IF') === 0 && (trim($param[2]) == "EMPTY" || $param[2] === '')) |
@@ -1547,7 +1669,7 @@ discard block |
||
1547 | 1669 | } |
1548 | 1670 | |
1549 | 1671 | switch($this->mimetype) |
1550 | - { |
|
1672 | + { |
|
1551 | 1673 | case 'application/rtf': |
1552 | 1674 | case 'text/rtf': |
1553 | 1675 | $LF = '}\par \pard\plain{'; |
@@ -1580,25 +1702,38 @@ discard block |
||
1580 | 1702 | default: |
1581 | 1703 | $LF = "\n"; |
1582 | 1704 | } |
1583 | - if($is_xml) { |
|
1705 | + if($is_xml) |
|
1706 | + { |
|
1584 | 1707 | $this->replacements = str_replace(array('&','&amp;','<','>',"\r","\n"),array('&','&','<','>','',$LF),$this->replacements); |
1585 | 1708 | } |
1586 | 1709 | if (strpos($param[0],'$$NELF') === 0) |
1587 | - { //sets a Pagebreak and value, only if the field has a value |
|
1588 | - if ($this->replacements['$$'.$param[1].'$$'] !='') $replace = $LF.$this->replacements['$$'.$param[1].'$$']; |
|
1710 | + { |
|
1711 | +//sets a Pagebreak and value, only if the field has a value |
|
1712 | + if ($this->replacements['$$'.$param[1].'$$'] !='') |
|
1713 | + { |
|
1714 | + $replace = $LF.$this->replacements['$$'.$param[1].'$$']; |
|
1715 | + } |
|
1589 | 1716 | } |
1590 | 1717 | if (strpos($param[0],'$$NENVLF') === 0) |
1591 | - { //sets a Pagebreak without any value, only if the field has a value |
|
1592 | - if ($this->replacements['$$'.$param[1].'$$'] !='') $replace = $LF; |
|
1718 | + { |
|
1719 | +//sets a Pagebreak without any value, only if the field has a value |
|
1720 | + if ($this->replacements['$$'.$param[1].'$$'] !='') |
|
1721 | + { |
|
1722 | + $replace = $LF; |
|
1723 | + } |
|
1593 | 1724 | } |
1594 | 1725 | if (strpos($param[0],'$$LETTERPREFIXCUSTOM') === 0) |
1595 | - { //sets a Letterprefix |
|
1726 | + { |
|
1727 | +//sets a Letterprefix |
|
1596 | 1728 | $replaceprefixsort = array(); |
1597 | 1729 | // ToDo Stefan: $contentstart is NOT defined here!!! |
1598 | 1730 | $replaceprefix = explode(' ',substr($param[0],21,-2)); |
1599 | 1731 | foreach ($replaceprefix as $nameprefix) |
1600 | 1732 | { |
1601 | - if ($this->replacements['$$'.$nameprefix.'$$'] !='') $replaceprefixsort[] = $this->replacements['$$'.$nameprefix.'$$']; |
|
1733 | + if ($this->replacements['$$'.$nameprefix.'$$'] !='') |
|
1734 | + { |
|
1735 | + $replaceprefixsort[] = $this->replacements['$$'.$nameprefix.'$$']; |
|
1736 | + } |
|
1602 | 1737 | } |
1603 | 1738 | $replace = implode($replaceprefixsort,' '); |
1604 | 1739 | } |
@@ -1665,13 +1800,20 @@ discard block |
||
1665 | 1800 | } |
1666 | 1801 | //error_log(__METHOD__.__LINE__.' Message after importMessageToMergeAndSend:'.array2string($msgs)); |
1667 | 1802 | $retString = ''; |
1668 | - if (count($msgs['success'])>0) $retString .= count($msgs['success']).' '.(count($msgs['success'])+count($msgs['failed'])==1?lang('Message prepared for sending.'):lang('Message(s) send ok.'));//implode('<br />',$msgs['success']); |
|
1803 | + if (count($msgs['success'])>0) |
|
1804 | + { |
|
1805 | + $retString .= count($msgs['success']).' '.(count($msgs['success'])+count($msgs['failed'])==1?lang('Message prepared for sending.'):lang('Message(s) send ok.')); |
|
1806 | + } |
|
1807 | + //implode('<br />',$msgs['success']); |
|
1669 | 1808 | //if (strlen($retString)>0) $retString .= '<br />'; |
1670 | 1809 | foreach($msgs['failed'] as $c =>$e) |
1671 | 1810 | { |
1672 | 1811 | $errorString .= lang('contact').' '.lang('id').':'.$c.'->'.$e.'.'; |
1673 | 1812 | } |
1674 | - if (count($msgs['failed'])>0) $retString .= count($msgs['failed']).' '.lang('Message(s) send failed!').'=>'.$errorString; |
|
1813 | + if (count($msgs['failed'])>0) |
|
1814 | + { |
|
1815 | + $retString .= count($msgs['failed']).' '.lang('Message(s) send failed!').'=>'.$errorString; |
|
1816 | + } |
|
1675 | 1817 | return $retString; |
1676 | 1818 | case 'application/vnd.oasis.opendocument.text': |
1677 | 1819 | case 'application/vnd.oasis.opendocument.spreadsheet': |
@@ -1757,7 +1899,10 @@ discard block |
||
1757 | 1899 | return $err; |
1758 | 1900 | } |
1759 | 1901 | } |
1760 | - if ($this->report_memory_usage) error_log(__METHOD__."() after HTML processing ".Api\Vfs::hsize(memory_get_peak_usage(true))); |
|
1902 | + if ($this->report_memory_usage) |
|
1903 | + { |
|
1904 | + error_log(__METHOD__."() after HTML processing ".Api\Vfs::hsize(memory_get_peak_usage(true))); |
|
1905 | + } |
|
1761 | 1906 | } |
1762 | 1907 | if(!empty($name)) |
1763 | 1908 | { |
@@ -1778,13 +1923,25 @@ discard block |
||
1778 | 1923 | if ($zip->open($archive, ZipArchive::CHECKCONS) !== true) |
1779 | 1924 | { |
1780 | 1925 | error_log(__METHOD__.__LINE__." !ZipArchive::open('$archive',ZIPARCHIVE"."::CHECKCONS) failed. Trying open without validating"); |
1781 | - if ($zip->open($archive) !== true) throw new Api\Exception("!ZipArchive::open('$archive',|ZIPARCHIVE::CHECKCONS)"); |
|
1926 | + if ($zip->open($archive) !== true) |
|
1927 | + { |
|
1928 | + throw new Api\Exception("!ZipArchive::open('$archive',|ZIPARCHIVE::CHECKCONS)"); |
|
1929 | + } |
|
1930 | + } |
|
1931 | + if ($zip->addFromString($content_file,$merged) !== true) |
|
1932 | + { |
|
1933 | + throw new Api\Exception("!ZipArchive::addFromString('$content_file',\$merged)"); |
|
1934 | + } |
|
1935 | + if ($zip->close() !== true) |
|
1936 | + { |
|
1937 | + throw new Api\Exception("!ZipArchive::close()"); |
|
1782 | 1938 | } |
1783 | - if ($zip->addFromString($content_file,$merged) !== true) throw new Api\Exception("!ZipArchive::addFromString('$content_file',\$merged)"); |
|
1784 | - if ($zip->close() !== true) throw new Api\Exception("!ZipArchive::close()"); |
|
1785 | 1939 | unset($zip); |
1786 | 1940 | unset($merged); |
1787 | - if ($this->report_memory_usage) error_log(__METHOD__."() after ZIP processing ".Api\Vfs::hsize(memory_get_peak_usage(true))); |
|
1941 | + if ($this->report_memory_usage) |
|
1942 | + { |
|
1943 | + error_log(__METHOD__."() after ZIP processing ".Api\Vfs::hsize(memory_get_peak_usage(true))); |
|
1944 | + } |
|
1788 | 1945 | $header['filesize'] = filesize($archive); |
1789 | 1946 | } |
1790 | 1947 | else |
@@ -1820,9 +1977,18 @@ discard block |
||
1820 | 1977 | */ |
1821 | 1978 | public function download_by_request() |
1822 | 1979 | { |
1823 | - if(empty($_POST['data_document_name'])) return false; |
|
1824 | - if(empty($_POST['data_document_dir'])) return false; |
|
1825 | - if(empty($_POST['data_checked'])) return false; |
|
1980 | + if(empty($_POST['data_document_name'])) |
|
1981 | + { |
|
1982 | + return false; |
|
1983 | + } |
|
1984 | + if(empty($_POST['data_document_dir'])) |
|
1985 | + { |
|
1986 | + return false; |
|
1987 | + } |
|
1988 | + if(empty($_POST['data_checked'])) |
|
1989 | + { |
|
1990 | + return false; |
|
1991 | + } |
|
1826 | 1992 | |
1827 | 1993 | return $this->download( |
1828 | 1994 | $_POST['data_document_name'], |
@@ -1843,7 +2009,10 @@ discard block |
||
1843 | 2009 | public static function get_documents($dirs, $prefix='document_', $mime_filter=null, $app='') |
1844 | 2010 | { |
1845 | 2011 | $export_limit=self::getExportLimit($app); |
1846 | - if (!$dirs || (!self::hasExportLimit($export_limit,'ISALLOWED') && !self::is_export_limit_excepted())) return array(); |
|
2012 | + if (!$dirs || (!self::hasExportLimit($export_limit,'ISALLOWED') && !self::is_export_limit_excepted())) |
|
2013 | + { |
|
2014 | + return array(); |
|
2015 | + } |
|
1847 | 2016 | |
1848 | 2017 | // split multiple comma or whitespace separated directories |
1849 | 2018 | // to still allow space or comma in dirnames, we also use the trailing slash of all pathes to split |
@@ -1851,7 +2020,11 @@ discard block |
||
1851 | 2020 | { |
1852 | 2021 | foreach($dirs as $n => &$d) |
1853 | 2022 | { |
1854 | - if ($n) $d = '/'.$d; // re-adding trailing slash removed by split |
|
2023 | + if ($n) |
|
2024 | + { |
|
2025 | + $d = '/'.$d; |
|
2026 | + } |
|
2027 | + // re-adding trailing slash removed by split |
|
1855 | 2028 | } |
1856 | 2029 | } |
1857 | 2030 | if ($mime_filter && ($negativ_filter = $mime_filter[0] === '!')) |
@@ -1874,8 +2047,14 @@ discard block |
||
1874 | 2047 | { |
1875 | 2048 | // return only the mime-types we support |
1876 | 2049 | $parts = explode('.',$file['name']); |
1877 | - if (!self::is_implemented($file['mime'],'.'.array_pop($parts))) continue; |
|
1878 | - if ($mime_filter && $negativ_filter === in_array($file['mime'], (array)$mime_filter)) continue; |
|
2050 | + if (!self::is_implemented($file['mime'],'.'.array_pop($parts))) |
|
2051 | + { |
|
2052 | + continue; |
|
2053 | + } |
|
2054 | + if ($mime_filter && $negativ_filter === in_array($file['mime'], (array)$mime_filter)) |
|
2055 | + { |
|
2056 | + continue; |
|
2057 | + } |
|
1879 | 2058 | $list[$prefix.$file['name']] = Api\Vfs::decodePath($file['name']); |
1880 | 2059 | } |
1881 | 2060 | } |
@@ -1906,15 +2085,18 @@ discard block |
||
1906 | 2085 | { |
1907 | 2086 | $documents = array(); |
1908 | 2087 | $editable_mimes = array(); |
1909 | - if ($export_limit == null) $export_limit = self::getExportLimit(); // check if there is a globalsetting |
|
2088 | + if ($export_limit == null) |
|
2089 | + { |
|
2090 | + $export_limit = self::getExportLimit(); |
|
2091 | + } |
|
2092 | + // check if there is a globalsetting |
|
1910 | 2093 | |
1911 | 2094 | try { |
1912 | 2095 | if (class_exists('EGroupware\\collabora\\Bo') && |
1913 | 2096 | $GLOBALS['egw_info']['user']['apps']['collabora'] && |
1914 | 2097 | ($discovery = \EGroupware\collabora\Bo::discover()) && |
1915 | 2098 | $GLOBALS['egw_info']['user']['preferences']['filemanager']['merge_open_handler'] != 'download' |
1916 | - ) |
|
1917 | - { |
|
2099 | + ) { |
|
1918 | 2100 | $editable_mimes = $discovery; |
1919 | 2101 | } |
1920 | 2102 | } |
@@ -1923,11 +2105,14 @@ discard block |
||
1923 | 2105 | // ignore failed discovery |
1924 | 2106 | unset($e); |
1925 | 2107 | } |
1926 | - if ($default_doc && ($file = Api\Vfs::stat($default_doc))) // put default document on top |
|
2108 | + if ($default_doc && ($file = Api\Vfs::stat($default_doc))) |
|
2109 | + { |
|
2110 | + // put default document on top |
|
1927 | 2111 | { |
1928 | 2112 | if(!$file['mime']) |
1929 | 2113 | { |
1930 | 2114 | $file['mime'] = Api\Vfs::mime_content_type($default_doc); |
2115 | + } |
|
1931 | 2116 | $file['path'] = $default_doc; |
1932 | 2117 | } |
1933 | 2118 | $documents['document'] = array( |
@@ -1955,7 +2140,11 @@ discard block |
||
1955 | 2140 | { |
1956 | 2141 | foreach($dirs as $n => &$d) |
1957 | 2142 | { |
1958 | - if ($n) $d = '/'.$d; // re-adding trailing slash removed by split |
|
2143 | + if ($n) |
|
2144 | + { |
|
2145 | + $d = '/'.$d; |
|
2146 | + } |
|
2147 | + // re-adding trailing slash removed by split |
|
1959 | 2148 | } |
1960 | 2149 | } |
1961 | 2150 | foreach($dirs as $dir) |
@@ -1975,10 +2164,13 @@ discard block |
||
1975 | 2164 | $parts = explode('.',$file['name']); |
1976 | 2165 | if (!self::is_implemented($file['mime'],'.'.array_pop($parts)) || |
1977 | 2166 | !Api\Vfs::check_access($file['path'], Api\Vfs::READABLE, $file) || // remove files not readable by user |
1978 | - $file['path'] === $default_doc) // default doc already added |
|
2167 | + $file['path'] === $default_doc) |
|
2168 | + { |
|
2169 | + // default doc already added |
|
1979 | 2170 | { |
1980 | 2171 | unset($files[$key]); |
1981 | 2172 | } |
2173 | + } |
|
1982 | 2174 | else |
1983 | 2175 | { |
1984 | 2176 | $dirname = Api\Vfs::dirname($file['path']); |
@@ -2171,7 +2363,11 @@ discard block |
||
2171 | 2363 | { |
2172 | 2364 | foreach($dirs as $n => $dir) |
2173 | 2365 | { |
2174 | - if ($n) $dir = '/'.$dir; // re-adding trailing slash removed by split |
|
2366 | + if ($n) |
|
2367 | + { |
|
2368 | + $dir = '/'.$dir; |
|
2369 | + } |
|
2370 | + // re-adding trailing slash removed by split |
|
2175 | 2371 | if (Api\Vfs::stat($dir.'/'.$document) && Api\Vfs::is_readable($dir.'/'.$document)) |
2176 | 2372 | { |
2177 | 2373 | $document = $dir.'/'.$document; |
@@ -2208,7 +2404,10 @@ discard block |
||
2208 | 2404 | */ |
2209 | 2405 | static public function number_format($number,$num_decimal_places=2,$_mimetype='') |
2210 | 2406 | { |
2211 | - if ((string)$number === '') return ''; |
|
2407 | + if ((string)$number === '') |
|
2408 | + { |
|
2409 | + return ''; |
|
2410 | + } |
|
2212 | 2411 | //error_log(__METHOD__.$_mimetype); |
2213 | 2412 | switch($_mimetype) |
2214 | 2413 | { |
@@ -82,14 +82,14 @@ discard block |
||
82 | 82 | * Configuration for HTML Tidy to clean up any HTML content that is kept |
83 | 83 | */ |
84 | 84 | public static $tidy_config = array( |
85 | - 'output-xml' => true, // Entity encoding |
|
85 | + 'output-xml' => true, // Entity encoding |
|
86 | 86 | 'show-body-only' => true, |
87 | 87 | 'output-encoding' => 'utf-8', |
88 | 88 | 'input-encoding' => 'utf-8', |
89 | - 'quote-ampersand' => false, // Prevent double encoding |
|
90 | - 'quote-nbsp' => true, // XSLT can handle spaces easier |
|
89 | + 'quote-ampersand' => false, // Prevent double encoding |
|
90 | + 'quote-nbsp' => true, // XSLT can handle spaces easier |
|
91 | 91 | 'preserve-entities' => true, |
92 | - 'wrap' => 0, // Wrapping can break output |
|
92 | + 'wrap' => 0, // Wrapping can break output |
|
93 | 93 | ); |
94 | 94 | |
95 | 95 | /** |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | $this->contacts = new Api\Contacts(); |
121 | 121 | |
122 | 122 | $this->datetime_format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'].' '. |
123 | - ($GLOBALS['egw_info']['user']['preferences']['common']['timeformat']==12 ? 'h:i a' : 'H:i'); |
|
123 | + ($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == 12 ? 'h:i a' : 'H:i'); |
|
124 | 124 | |
125 | 125 | $this->export_limit = self::getExportLimit(); |
126 | 126 | } |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | $accountsel = new uiaccountsel(); |
136 | 136 | |
137 | 137 | return '<input type="hidden" value="" name="newsettings[export_limit_excepted]" />'. |
138 | - $accountsel->selection('newsettings[export_limit_excepted]','export_limit_excepted',$config['export_limit_excepted'],'both',4); |
|
138 | + $accountsel->selection('newsettings[export_limit_excepted]', 'export_limit_excepted', $config['export_limit_excepted'], 'both', 4); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @param string &$content=null content to create some replacements only if they are use |
150 | 150 | * @return array|boolean array with replacements or false if entry not found |
151 | 151 | */ |
152 | - abstract protected function get_replacements($id,&$content=null); |
|
152 | + abstract protected function get_replacements($id, &$content = null); |
|
153 | 153 | |
154 | 154 | /** |
155 | 155 | * Return if merge-print is implemented for given mime-type (and/or extension) |
@@ -157,13 +157,13 @@ discard block |
||
157 | 157 | * @param string $mimetype eg. text/plain |
158 | 158 | * @param string $extension only checked for applications/msword and .rtf |
159 | 159 | */ |
160 | - static public function is_implemented($mimetype,$extension=null) |
|
160 | + static public function is_implemented($mimetype, $extension = null) |
|
161 | 161 | { |
162 | - static $zip_available=null; |
|
162 | + static $zip_available = null; |
|
163 | 163 | if (is_null($zip_available)) |
164 | 164 | { |
165 | 165 | $zip_available = check_load_extension('zip') && |
166 | - class_exists('ZipArchive'); // some PHP has zip extension, but no ZipArchive (eg. RHEL5!) |
|
166 | + class_exists('ZipArchive'); // some PHP has zip extension, but no ZipArchive (eg. RHEL5!) |
|
167 | 167 | } |
168 | 168 | switch ($mimetype) |
169 | 169 | { |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | if (strtolower($extension) != '.rtf') break; |
172 | 172 | case 'application/rtf': |
173 | 173 | case 'text/rtf': |
174 | - return true; // rtf files |
|
174 | + return true; // rtf files |
|
175 | 175 | case 'application/vnd.oasis.opendocument.text': // oo text |
176 | 176 | case 'application/vnd.oasis.opendocument.spreadsheet': // oo spreadsheet |
177 | 177 | case 'application/vnd.oasis.opendocument.presentation': |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | case 'application/vnd.oasis.opendocument.spreadsheet-template': |
180 | 180 | case 'application/vnd.oasis.opendocument.presentation-template': |
181 | 181 | if (!$zip_available) break; |
182 | - return true; // open office write xml files |
|
182 | + return true; // open office write xml files |
|
183 | 183 | case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms word 2007 xml format |
184 | 184 | case 'application/vnd.openxmlformats-officedocument.wordprocessingml.d': // mimetypes in vfs are limited to 64 chars |
185 | 185 | case 'application/vnd.ms-word.document.macroenabled.12': |
@@ -187,17 +187,17 @@ discard block |
||
187 | 187 | case 'application/vnd.openxmlformats-officedocument.spreadsheetml.shee': |
188 | 188 | case 'application/vnd.ms-excel.sheet.macroenabled.12': |
189 | 189 | if (!$zip_available) break; |
190 | - return true; // ms word xml format |
|
190 | + return true; // ms word xml format |
|
191 | 191 | case 'application/xml': |
192 | - return true; // alias for text/xml, eg. ms office 2003 word format |
|
192 | + return true; // alias for text/xml, eg. ms office 2003 word format |
|
193 | 193 | case 'message/rfc822': |
194 | 194 | return true; // ToDo: check if you are theoretical able to send mail |
195 | 195 | case 'application/x-yaml': |
196 | - return true; // yaml file, plain text with marginal syntax support for multiline replacements |
|
196 | + return true; // yaml file, plain text with marginal syntax support for multiline replacements |
|
197 | 197 | default: |
198 | - if (substr($mimetype,0,5) == 'text/') |
|
198 | + if (substr($mimetype, 0, 5) == 'text/') |
|
199 | 199 | { |
200 | - return true; // text files |
|
200 | + return true; // text files |
|
201 | 201 | } |
202 | 202 | break; |
203 | 203 | } |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * @param boolean $ignore_acl =false true: no acl check |
216 | 216 | * @return array |
217 | 217 | */ |
218 | - public function contact_replacements($contact,$prefix='',$ignore_acl=false, &$content = '') |
|
218 | + public function contact_replacements($contact, $prefix = '', $ignore_acl = false, &$content = '') |
|
219 | 219 | { |
220 | 220 | if (!is_array($contact)) |
221 | 221 | { |
@@ -224,13 +224,13 @@ discard block |
||
224 | 224 | if (!is_array($contact)) return array(); |
225 | 225 | |
226 | 226 | $replacements = array(); |
227 | - foreach(array_keys($this->contacts->contact_fields) as $name) |
|
227 | + foreach (array_keys($this->contacts->contact_fields) as $name) |
|
228 | 228 | { |
229 | 229 | $value = $contact[$name]; |
230 | - switch($name) |
|
230 | + switch ($name) |
|
231 | 231 | { |
232 | 232 | case 'created': case 'modified': |
233 | - if($value) $value = Api\DateTime::to($value); |
|
233 | + if ($value) $value = Api\DateTime::to($value); |
|
234 | 234 | break; |
235 | 235 | case 'bday': |
236 | 236 | if ($value) |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | $value = Api\DateTime::to($value, true); |
240 | 240 | } |
241 | 241 | catch (\Exception $e) { |
242 | - unset($e); // ignore exception caused by wrongly formatted date |
|
242 | + unset($e); // ignore exception caused by wrongly formatted date |
|
243 | 243 | } |
244 | 244 | } |
245 | 245 | break; |
@@ -252,17 +252,17 @@ discard block |
||
252 | 252 | // if cat-tree is displayed, we return a full category path not just the name of the cat |
253 | 253 | $use = $GLOBALS['egw_info']['server']['cat_tab'] == 'Tree' ? 'path' : 'name'; |
254 | 254 | $cats = array(); |
255 | - foreach(is_array($value) ? $value : explode(',',$value) as $cat_id) |
|
255 | + foreach (is_array($value) ? $value : explode(',', $value) as $cat_id) |
|
256 | 256 | { |
257 | - $cats[] = $GLOBALS['egw']->categories->id2name($cat_id,$use); |
|
257 | + $cats[] = $GLOBALS['egw']->categories->id2name($cat_id, $use); |
|
258 | 258 | } |
259 | - $value = implode(', ',$cats); |
|
259 | + $value = implode(', ', $cats); |
|
260 | 260 | } |
261 | 261 | break; |
262 | 262 | case 'jpegphoto': // returning a link might make more sense then the binary photo |
263 | 263 | if ($contact['photo']) |
264 | 264 | { |
265 | - $value = Api\Framework::getUrl(Api\Framework::link('/index.php',$contact['photo'])); |
|
265 | + $value = Api\Framework::getUrl(Api\Framework::link('/index.php', $contact['photo'])); |
|
266 | 266 | } |
267 | 267 | break; |
268 | 268 | case 'tel_prefer': |
@@ -274,57 +274,56 @@ discard block |
||
274 | 274 | case 'account_id': |
275 | 275 | if ($value) |
276 | 276 | { |
277 | - $replacements['$$'.($prefix ? $prefix.'/':'').'account_lid$$'] = $GLOBALS['egw']->accounts->id2name($value); |
|
277 | + $replacements['$$'.($prefix ? $prefix.'/' : '').'account_lid$$'] = $GLOBALS['egw']->accounts->id2name($value); |
|
278 | 278 | } |
279 | 279 | break; |
280 | 280 | } |
281 | - if ($name != 'photo') $replacements['$$'.($prefix ? $prefix.'/':'').$name.'$$'] = $value; |
|
281 | + if ($name != 'photo') $replacements['$$'.($prefix ? $prefix.'/' : '').$name.'$$'] = $value; |
|
282 | 282 | } |
283 | 283 | // set custom fields, should probably go to a general method all apps can use |
284 | 284 | // need to load all cfs for $ignore_acl=true |
285 | - foreach($ignore_acl ? Customfields::get('addressbook', true) : $this->contacts->customfields as $name => $field) |
|
285 | + foreach ($ignore_acl ? Customfields::get('addressbook', true) : $this->contacts->customfields as $name => $field) |
|
286 | 286 | { |
287 | 287 | $name = '#'.$name; |
288 | - if(!$contact[$name]) |
|
288 | + if (!$contact[$name]) |
|
289 | 289 | { |
290 | - $replacements['$$'.($prefix ? $prefix.'/':'').$name.'$$'] = ''; |
|
290 | + $replacements['$$'.($prefix ? $prefix.'/' : '').$name.'$$'] = ''; |
|
291 | 291 | continue; |
292 | 292 | } |
293 | 293 | // Format date cfs per user Api\Preferences |
294 | - if($this->mimetype !== 'application/x-yaml' && $contact[$name] && |
|
294 | + if ($this->mimetype !== 'application/x-yaml' && $contact[$name] && |
|
295 | 295 | ($field['type'] == 'date' || $field['type'] == 'date-time')) |
296 | 296 | { |
297 | 297 | $this->date_fields[] = '#'.$name; |
298 | - $replacements['$$'.($prefix ? $prefix.'/':'').$name.'$$'] = Api\DateTime::to($contact[$name], $field['type'] == 'date' ? true : ''); |
|
298 | + $replacements['$$'.($prefix ? $prefix.'/' : '').$name.'$$'] = Api\DateTime::to($contact[$name], $field['type'] == 'date' ? true : ''); |
|
299 | 299 | } |
300 | - $replacements['$$'.($prefix ? $prefix.'/':'').$name.'$$'] = |
|
300 | + $replacements['$$'.($prefix ? $prefix.'/' : '').$name.'$$'] = |
|
301 | 301 | // use raw data for yaml, no user-preference specific formatting |
302 | - $this->mimetype == 'application/x-yaml' || $field['type'] == 'htmlarea' ? (string)$contact[$name] : |
|
303 | - Customfields::format($field, (string)$contact[$name]); |
|
302 | + $this->mimetype == 'application/x-yaml' || $field['type'] == 'htmlarea' ? (string)$contact[$name] : Customfields::format($field, (string)$contact[$name]); |
|
304 | 303 | } |
305 | 304 | |
306 | - if($content && strpos($content, '$$#') !== FALSE) |
|
305 | + if ($content && strpos($content, '$$#') !== FALSE) |
|
307 | 306 | { |
308 | 307 | $this->cf_link_to_expand($contact, $content, $replacements, 'addressbook'); |
309 | 308 | } |
310 | 309 | |
311 | 310 | // Add in extra cat field |
312 | 311 | $cats = array(); |
313 | - foreach(is_array($contact['cat_id']) ? $contact['cat_id'] : explode(',',$contact['cat_id']) as $cat_id) |
|
312 | + foreach (is_array($contact['cat_id']) ? $contact['cat_id'] : explode(',', $contact['cat_id']) as $cat_id) |
|
314 | 313 | { |
315 | - if(!$cat_id) continue; |
|
316 | - if($GLOBALS['egw']->categories->id2name($cat_id,'main') != $cat_id) |
|
314 | + if (!$cat_id) continue; |
|
315 | + if ($GLOBALS['egw']->categories->id2name($cat_id, 'main') != $cat_id) |
|
317 | 316 | { |
318 | 317 | $path = explode(' / ', $GLOBALS['egw']->categories->id2name($cat_id, 'path')); |
319 | 318 | unset($path[0]); // Drop main |
320 | - $cats[$GLOBALS['egw']->categories->id2name($cat_id,'main')][] = implode(' / ', $path); |
|
321 | - } elseif($cat_id) { |
|
319 | + $cats[$GLOBALS['egw']->categories->id2name($cat_id, 'main')][] = implode(' / ', $path); |
|
320 | + } elseif ($cat_id) { |
|
322 | 321 | $cats[$cat_id] = array(); |
323 | 322 | } |
324 | 323 | } |
325 | - foreach($cats as $main => $cat) { |
|
326 | - $replacements['$$'.($prefix ? $prefix.'/':'').'categories$$'] .= $GLOBALS['egw']->categories->id2name($main,'name') |
|
327 | - . (count($cat) > 0 ? ': ' : '') . implode(', ', $cats[$main]) . "\n"; |
|
324 | + foreach ($cats as $main => $cat) { |
|
325 | + $replacements['$$'.($prefix ? $prefix.'/' : '').'categories$$'] .= $GLOBALS['egw']->categories->id2name($main, 'name') |
|
326 | + . (count($cat) > 0 ? ': ' : '').implode(', ', $cats[$main])."\n"; |
|
328 | 327 | } |
329 | 328 | return $replacements; |
330 | 329 | } |
@@ -343,34 +342,34 @@ discard block |
||
343 | 342 | * 'link' - URL to the entry |
344 | 343 | * 'href' - HREF tag wrapped around the title |
345 | 344 | */ |
346 | - protected function get_links($app, $id, $only_app='', $exclude = array(), $style = 'title') |
|
345 | + protected function get_links($app, $id, $only_app = '', $exclude = array(), $style = 'title') |
|
347 | 346 | { |
348 | 347 | $links = Api\Link::get_links($app, $id, $only_app); |
349 | 348 | $link_titles = array(); |
350 | - foreach($links as $link_info) |
|
349 | + foreach ($links as $link_info) |
|
351 | 350 | { |
352 | 351 | // Using only_app only returns the ID |
353 | - if(!is_array($link_info) && $only_app && $only_app[0] !== '!') |
|
352 | + if (!is_array($link_info) && $only_app && $only_app[0] !== '!') |
|
354 | 353 | { |
355 | 354 | $link_info = array( |
356 | 355 | 'app' => $only_app, |
357 | 356 | 'id' => $link_info |
358 | 357 | ); |
359 | 358 | } |
360 | - if($exclude && in_array($link_info['id'], $exclude)) continue; |
|
359 | + if ($exclude && in_array($link_info['id'], $exclude)) continue; |
|
361 | 360 | |
362 | 361 | $title = Api\Link::title($link_info['app'], $link_info['id']); |
363 | - if(class_exists('EGroupware\Stylite\Vfs\Links\StreamWrapper') && $link_info['app'] != Api\Link::VFS_APPNAME) |
|
362 | + if (class_exists('EGroupware\Stylite\Vfs\Links\StreamWrapper') && $link_info['app'] != Api\Link::VFS_APPNAME) |
|
364 | 363 | { |
365 | 364 | $title = Stylite\Vfs\Links\StreamWrapper::entry2name($link_info['app'], $link_info['id'], $title); |
366 | 365 | } |
367 | - if($style == 'href' || $style == 'link') |
|
366 | + if ($style == 'href' || $style == 'link') |
|
368 | 367 | { |
369 | 368 | $link = Api\Link::view($link_info['app'], $link_info['id'], $link_info); |
370 | - if($link_info['app'] != Api\Link::VFS_APPNAME) |
|
369 | + if ($link_info['app'] != Api\Link::VFS_APPNAME) |
|
371 | 370 | { |
372 | 371 | // Set app to false so we always get an external link |
373 | - $link = str_replace(',', '%2C', $GLOBALS['egw']->framework->link('/index.php',$link, false)); |
|
372 | + $link = str_replace(',', '%2C', $GLOBALS['egw']->framework->link('/index.php', $link, false)); |
|
374 | 373 | } |
375 | 374 | else |
376 | 375 | { |
@@ -383,7 +382,7 @@ discard block |
||
383 | 382 | } |
384 | 383 | $link_titles[] = $title; |
385 | 384 | } |
386 | - return implode("\n",$link_titles); |
|
385 | + return implode("\n", $link_titles); |
|
387 | 386 | } |
388 | 387 | |
389 | 388 | /** |
@@ -400,33 +399,33 @@ discard block |
||
400 | 399 | { |
401 | 400 | $array = array(); |
402 | 401 | $pattern = '@\$\$(links_attachments|links|attachments|link)\/?(title|href|link)?\/?([a-z]*)\$\$@'; |
403 | - static $link_cache=null; |
|
402 | + static $link_cache = null; |
|
404 | 403 | $matches = null; |
405 | - if(preg_match_all($pattern, $content, $matches)) |
|
404 | + if (preg_match_all($pattern, $content, $matches)) |
|
406 | 405 | { |
407 | - foreach($matches[0] as $i => $placeholder) |
|
406 | + foreach ($matches[0] as $i => $placeholder) |
|
408 | 407 | { |
409 | 408 | $placeholder = substr($placeholder, 2, -2); |
410 | - if($link_cache[$id][$placeholder]) |
|
409 | + if ($link_cache[$id][$placeholder]) |
|
411 | 410 | { |
412 | 411 | $array[$placeholder] = $link_cache[$id][$placeholder]; |
413 | 412 | continue; |
414 | 413 | } |
415 | - switch($matches[1][$i]) |
|
414 | + switch ($matches[1][$i]) |
|
416 | 415 | { |
417 | 416 | case 'link': |
418 | 417 | // Link to current record |
419 | 418 | $title = Api\Link::title($app, $id); |
420 | - if(class_exists('EGroupware\Stylite\Vfs\Links\StreamWrapper') && $app != Api\Link::VFS_APPNAME) |
|
419 | + if (class_exists('EGroupware\Stylite\Vfs\Links\StreamWrapper') && $app != Api\Link::VFS_APPNAME) |
|
421 | 420 | { |
422 | 421 | $title = Stylite\Vfs\Links\StreamWrapper::entry2name($app, $id, $title); |
423 | 422 | } |
424 | 423 | |
425 | 424 | $link = Api\Link::view($app, $id); |
426 | - if($app != Api\Link::VFS_APPNAME) |
|
425 | + if ($app != Api\Link::VFS_APPNAME) |
|
427 | 426 | { |
428 | 427 | // Set app to false so we always get an external link |
429 | - $link = str_replace(',', '%2C', $GLOBALS['egw']->framework->link('/index.php',$link, false)); |
|
428 | + $link = str_replace(',', '%2C', $GLOBALS['egw']->framework->link('/index.php', $link, false)); |
|
430 | 429 | } |
431 | 430 | else |
432 | 431 | { |
@@ -435,17 +434,17 @@ discard block |
||
435 | 434 | // Prepend site |
436 | 435 | if ($link[0] == '/') $link = Api\Framework::getUrl($link); |
437 | 436 | |
438 | - $array['$$'.($prefix?$prefix.'/':'').$placeholder.'$$'] = Api\Html::a_href(Api\Html::htmlspecialchars($title), $link); |
|
437 | + $array['$$'.($prefix ? $prefix.'/' : '').$placeholder.'$$'] = Api\Html::a_href(Api\Html::htmlspecialchars($title), $link); |
|
439 | 438 | break; |
440 | 439 | case 'links': |
441 | - $link_app = $matches[3][$i] ? $matches[3][$i] : '!'.Api\Link::VFS_APPNAME; |
|
442 | - $array['$$'.($prefix?$prefix.'/':'').$placeholder.'$$'] = $this->get_links($app, $id, $link_app, array(),$matches[2][$i]); |
|
440 | + $link_app = $matches[3][$i] ? $matches[3][$i] : '!'.Api\Link::VFS_APPNAME; |
|
441 | + $array['$$'.($prefix ? $prefix.'/' : '').$placeholder.'$$'] = $this->get_links($app, $id, $link_app, array(), $matches[2][$i]); |
|
443 | 442 | break; |
444 | 443 | case 'attachments': |
445 | - $array['$$'.($prefix?$prefix.'/':'').$placeholder.'$$'] = $this->get_links($app, $id, Api\Link::VFS_APPNAME,array(),$matches[2][$i]); |
|
444 | + $array['$$'.($prefix ? $prefix.'/' : '').$placeholder.'$$'] = $this->get_links($app, $id, Api\Link::VFS_APPNAME, array(), $matches[2][$i]); |
|
446 | 445 | break; |
447 | 446 | default: |
448 | - $array['$$'.($prefix?$prefix.'/':'').$placeholder.'$$'] = $this->get_links($app, $id, $matches[3][$i], array(), $matches[2][$i]); |
|
447 | + $array['$$'.($prefix ? $prefix.'/' : '').$placeholder.'$$'] = $this->get_links($app, $id, $matches[3][$i], array(), $matches[2][$i]); |
|
449 | 448 | break; |
450 | 449 | } |
451 | 450 | $link_cache[$id][$placeholder] = $array[$placeholder]; |
@@ -462,12 +461,12 @@ discard block |
||
462 | 461 | * @deprecated use Api\DateTime::to($time='now',$format='') |
463 | 462 | * @return string |
464 | 463 | */ |
465 | - protected function format_datetime($time,$format=null) |
|
464 | + protected function format_datetime($time, $format = null) |
|
466 | 465 | { |
467 | - trigger_error(__METHOD__ . ' is deprecated, use Api\DateTime::to($time, $format)', E_USER_DEPRECATED); |
|
466 | + trigger_error(__METHOD__.' is deprecated, use Api\DateTime::to($time, $format)', E_USER_DEPRECATED); |
|
468 | 467 | if (is_null($format)) $format = $this->datetime_format; |
469 | 468 | |
470 | - return Api\DateTime::to($time,$format); |
|
469 | + return Api\DateTime::to($time, $format); |
|
471 | 470 | } |
472 | 471 | |
473 | 472 | /** |
@@ -479,7 +478,7 @@ discard block |
||
479 | 478 | */ |
480 | 479 | public static function is_export_limit_excepted() |
481 | 480 | { |
482 | - static $is_excepted=null; |
|
481 | + static $is_excepted = null; |
|
483 | 482 | |
484 | 483 | if (is_null($is_excepted)) |
485 | 484 | { |
@@ -489,9 +488,9 @@ discard block |
||
489 | 488 | if (!$is_excepted && (is_array($export_limit_excepted = $GLOBALS['egw_info']['server']['export_limit_excepted']) || |
490 | 489 | is_array($export_limit_excepted = unserialize($export_limit_excepted)))) |
491 | 490 | { |
492 | - $id_and_memberships = $GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'],true); |
|
491 | + $id_and_memberships = $GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true); |
|
493 | 492 | $id_and_memberships[] = $GLOBALS['egw_info']['user']['account_id']; |
494 | - $is_excepted = (bool) array_intersect($id_and_memberships, $export_limit_excepted); |
|
493 | + $is_excepted = (bool)array_intersect($id_and_memberships, $export_limit_excepted); |
|
495 | 494 | } |
496 | 495 | } |
497 | 496 | return $is_excepted; |
@@ -504,18 +503,18 @@ discard block |
||
504 | 503 | * @return mixed - no if no export is allowed, false if there is no restriction and int as there is a valid restriction |
505 | 504 | * you may have to cast the returned value to int, if you want to use it as number |
506 | 505 | */ |
507 | - public static function getExportLimit($app='common') |
|
506 | + public static function getExportLimit($app = 'common') |
|
508 | 507 | { |
509 | - static $exportLimitStore=array(); |
|
510 | - if (empty($app)) $app='common'; |
|
508 | + static $exportLimitStore = array(); |
|
509 | + if (empty($app)) $app = 'common'; |
|
511 | 510 | //error_log(__METHOD__.__LINE__.' called with app:'.$app); |
512 | - if (!array_key_exists($app,$exportLimitStore)) |
|
511 | + if (!array_key_exists($app, $exportLimitStore)) |
|
513 | 512 | { |
514 | 513 | //error_log(__METHOD__.__LINE__.' -> '.$app_limit.' '.function_backtrace()); |
515 | 514 | $exportLimitStore[$app] = $GLOBALS['egw_info']['server']['export_limit']; |
516 | - if ($app !='common') |
|
515 | + if ($app != 'common') |
|
517 | 516 | { |
518 | - $app_limit = Api\Hooks::single('export_limit',$app); |
|
517 | + $app_limit = Api\Hooks::single('export_limit', $app); |
|
519 | 518 | if ($app_limit) $exportLimitStore[$app] = $app_limit; |
520 | 519 | } |
521 | 520 | //error_log(__METHOD__.__LINE__.' building cache for app:'.$app.' -> '.$exportLimitStore[$app]); |
@@ -547,9 +546,9 @@ discard block |
||
547 | 546 | * |
548 | 547 | * @return bool - true if no export is allowed or a limit is set, false if there is no restriction |
549 | 548 | */ |
550 | - public static function hasExportLimit($app_limit,$checkas='AND') |
|
549 | + public static function hasExportLimit($app_limit, $checkas = 'AND') |
|
551 | 550 | { |
552 | - if (strtoupper($checkas) == 'ISALLOWED') return (empty($app_limit) || ($app_limit !='no' && $app_limit > 0) ); |
|
551 | + if (strtoupper($checkas) == 'ISALLOWED') return (empty($app_limit) || ($app_limit != 'no' && $app_limit > 0)); |
|
553 | 552 | if (empty($app_limit)) return false; |
554 | 553 | if ($app_limit == 'no') return true; |
555 | 554 | if ($app_limit > 0) return true; |
@@ -565,28 +564,28 @@ discard block |
||
565 | 564 | * @param array $fix =null regular expression => replacement pairs eg. to fix garbled placeholders |
566 | 565 | * @return string|boolean merged document or false on error |
567 | 566 | */ |
568 | - public function &merge($document,$ids,&$err,$mimetype,array $fix=null) |
|
567 | + public function &merge($document, $ids, &$err, $mimetype, array $fix = null) |
|
569 | 568 | { |
570 | 569 | if (!($content = file_get_contents($document))) |
571 | 570 | { |
572 | - $err = lang("Document '%1' does not exist or is not readable for you!",$document); |
|
571 | + $err = lang("Document '%1' does not exist or is not readable for you!", $document); |
|
573 | 572 | return false; |
574 | 573 | } |
575 | 574 | |
576 | 575 | if (self::hasExportLimit($this->export_limit) && !self::is_export_limit_excepted() && count($ids) > (int)$this->export_limit) |
577 | 576 | { |
578 | - $err = lang('No rights to export more than %1 entries!',(int)$this->export_limit); |
|
577 | + $err = lang('No rights to export more than %1 entries!', (int)$this->export_limit); |
|
579 | 578 | return false; |
580 | 579 | } |
581 | 580 | |
582 | 581 | // fix application/msword mimetype for rtf files |
583 | - if ($mimetype == 'application/msword' && strtolower(substr($document,-4)) == '.rtf') |
|
582 | + if ($mimetype == 'application/msword' && strtolower(substr($document, -4)) == '.rtf') |
|
584 | 583 | { |
585 | 584 | $mimetype = 'application/rtf'; |
586 | 585 | } |
587 | 586 | |
588 | 587 | try { |
589 | - $content = $this->merge_string($content,$ids,$err,$mimetype,$fix); |
|
588 | + $content = $this->merge_string($content, $ids, $err, $mimetype, $fix); |
|
590 | 589 | } catch (\Exception $e) { |
591 | 590 | _egw_log_exception($e); |
592 | 591 | $err = $e->getMessage(); |
@@ -595,18 +594,18 @@ discard block |
||
595 | 594 | return $content; |
596 | 595 | } |
597 | 596 | |
598 | - protected function apply_styles (&$content, $mimetype, $mso_application_progid=null) |
|
597 | + protected function apply_styles(&$content, $mimetype, $mso_application_progid = null) |
|
599 | 598 | { |
600 | 599 | if (!isset($mso_application_progid)) |
601 | 600 | { |
602 | 601 | $matches = null; |
603 | 602 | $mso_application_progid = $mimetype == 'application/xml' && |
604 | - preg_match('/'.preg_quote('<?mso-application progid="').'([^"]+)'.preg_quote('"?>').'/',substr($content,0,200),$matches) ? |
|
603 | + preg_match('/'.preg_quote('<?mso-application progid="').'([^"]+)'.preg_quote('"?>').'/', substr($content, 0, 200), $matches) ? |
|
605 | 604 | $matches[1] : ''; |
606 | 605 | } |
607 | 606 | // Tags we can replace with the target document's version |
608 | 607 | $replace_tags = array(); |
609 | - switch($mimetype.$mso_application_progid) |
|
608 | + switch ($mimetype.$mso_application_progid) |
|
610 | 609 | { |
611 | 610 | case 'application/vnd.oasis.opendocument.text': // oo text |
612 | 611 | case 'application/vnd.oasis.opendocument.spreadsheet': // oo spreadsheet |
@@ -639,7 +638,7 @@ discard block |
||
639 | 638 | // Remove spans with no attributes, linebreaks inside them cause problems |
640 | 639 | '/<span>(.*?)<\/span>/' => '$1' |
641 | 640 | ); |
642 | - $content = preg_replace(array_keys($replace_tags),array_values($replace_tags),$content); |
|
641 | + $content = preg_replace(array_keys($replace_tags), array_values($replace_tags), $content); |
|
643 | 642 | |
644 | 643 | /* |
645 | 644 | In the case where you have something like <span><span></w:t><w:br/><w:t></span></span> (invalid - mismatched tags), |
@@ -649,9 +648,9 @@ discard block |
||
649 | 648 | $count = $i = 0; |
650 | 649 | do |
651 | 650 | { |
652 | - $content = preg_replace('/<span>(.*?)<\/span>/','$1',$content, -1, $count); |
|
651 | + $content = preg_replace('/<span>(.*?)<\/span>/', '$1', $content, -1, $count); |
|
653 | 652 | $i++; |
654 | - } while($count > 0 && $i < 10); |
|
653 | + } while ($count > 0 && $i < 10); |
|
655 | 654 | |
656 | 655 | $doc = new DOMDocument(); |
657 | 656 | $xslt = new XSLTProcessor(); |
@@ -662,20 +661,20 @@ discard block |
||
662 | 661 | } |
663 | 662 | |
664 | 663 | // XSLT transform known tags |
665 | - if($xslt) |
|
664 | + if ($xslt) |
|
666 | 665 | { |
667 | 666 | // does NOT work with php 5.2.6: Catchable fatal error: argument 1 to transformToXml() must be of type DOMDocument |
668 | 667 | //$element = new SimpleXMLelement($content); |
669 | 668 | $element = new DOMDocument('1.0', 'utf-8'); |
670 | 669 | $result = $element->loadXML($content); |
671 | - if(!$result) |
|
670 | + if (!$result) |
|
672 | 671 | { |
673 | 672 | throw new Api\Exception('Unable to parse merged document for styles. Check warnings in log for details.'); |
674 | 673 | } |
675 | 674 | $content = $xslt->transformToXml($element); |
676 | 675 | //echo $content;die(); |
677 | 676 | // Word 2003 needs two declarations, add extra declaration back in |
678 | - if($mimetype == 'application/xml' && $mso_application_progid == 'Word.Document' && strpos($content, '<?xml') !== 0) { |
|
677 | + if ($mimetype == 'application/xml' && $mso_application_progid == 'Word.Document' && strpos($content, '<?xml') !== 0) { |
|
679 | 678 | $content = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'.$content; |
680 | 679 | } |
681 | 680 | // Validate |
@@ -698,11 +697,11 @@ discard block |
||
698 | 697 | * @param string $charset =null charset to override default set by mimetype or export charset |
699 | 698 | * @return string|boolean merged document or false on error |
700 | 699 | */ |
701 | - public function &merge_string($_content,$ids,&$err,$mimetype,array $fix=null,$charset=null) |
|
700 | + public function &merge_string($_content, $ids, &$err, $mimetype, array $fix = null, $charset = null) |
|
702 | 701 | { |
703 | 702 | $matches = null; |
704 | 703 | if ($mimetype == 'application/xml' && |
705 | - preg_match('/'.preg_quote('<?mso-application progid="').'([^"]+)'.preg_quote('"?>').'/',substr($_content,0,200),$matches)) |
|
704 | + preg_match('/'.preg_quote('<?mso-application progid="').'([^"]+)'.preg_quote('"?>').'/', substr($_content, 0, 200), $matches)) |
|
706 | 705 | { |
707 | 706 | $mso_application_progid = $matches[1]; |
708 | 707 | } |
@@ -717,9 +716,9 @@ discard block |
||
717 | 716 | return '$$'.strip_tags(substr($matches[0], 2, -2)).'$$'; |
718 | 717 | }, $_content); |
719 | 718 | // Handle escaped placeholder markers in RTF, they won't match when escaped |
720 | - if($mimetype == 'application/rtf') |
|
719 | + if ($mimetype == 'application/rtf') |
|
721 | 720 | { |
722 | - $content = preg_replace('/\\\{\\\{([^\\}]+)\\\}\\\}/i','$$\1$$',$content); |
|
721 | + $content = preg_replace('/\\\{\\\{([^\\}]+)\\\}\\\}/i', '$$\1$$', $content); |
|
723 | 722 | } |
724 | 723 | |
725 | 724 | // make currently processed mimetype available to class methods; |
@@ -728,16 +727,16 @@ discard block |
||
728 | 727 | // fix garbled placeholders |
729 | 728 | if ($fix && is_array($fix)) |
730 | 729 | { |
731 | - $content = preg_replace(array_keys($fix),array_values($fix),$content); |
|
730 | + $content = preg_replace(array_keys($fix), array_values($fix), $content); |
|
732 | 731 | //die("<pre>".htmlspecialchars($content)."</pre>\n"); |
733 | 732 | } |
734 | - list($contentstart,$contentrepeat,$contentend) = preg_split('/\$\$pagerepeat\$\$/',$content,-1, PREG_SPLIT_NO_EMPTY); //get differt parts of document, seperatet by Pagerepeat |
|
733 | + list($contentstart, $contentrepeat, $contentend) = preg_split('/\$\$pagerepeat\$\$/', $content, -1, PREG_SPLIT_NO_EMPTY); //get differt parts of document, seperatet by Pagerepeat |
|
735 | 734 | if ($mimetype == 'text/plain' && count($ids) > 1) |
736 | 735 | { |
737 | 736 | // textdocuments are simple, they do not hold start and end, but they may have content before and after the $$pagerepeat$$ tag |
738 | 737 | // header and footer should not hold any $$ tags; if we find $$ tags with the header, we assume it is the pagerepeatcontent |
739 | 738 | $nohead = false; |
740 | - if (stripos($contentstart,'$$') !== false) $nohead = true; |
|
739 | + if (stripos($contentstart, '$$') !== false) $nohead = true; |
|
741 | 740 | if ($nohead) |
742 | 741 | { |
743 | 742 | $contentend = $contentrepeat; |
@@ -746,16 +745,16 @@ discard block |
||
746 | 745 | } |
747 | 746 | |
748 | 747 | } |
749 | - if (in_array($mimetype, array('application/vnd.oasis.opendocument.text','application/vnd.oasis.opendocument.text-template')) && count($ids) > 1) |
|
748 | + if (in_array($mimetype, array('application/vnd.oasis.opendocument.text', 'application/vnd.oasis.opendocument.text-template')) && count($ids) > 1) |
|
750 | 749 | { |
751 | - if(strpos($content, '$$pagerepeat') === false) |
|
750 | + if (strpos($content, '$$pagerepeat') === false) |
|
752 | 751 | { |
753 | 752 | //for odt files we have to split the content and add a style for page break to the style area |
754 | - list($contentstart,$contentrepeat,$contentend) = preg_split('/office:body>/',$content,-1, PREG_SPLIT_NO_EMPTY); //get differt parts of document, seperatet by Pagerepeat |
|
755 | - $contentstart = substr($contentstart,0,strlen($contentstart)-1); //remove "<" |
|
756 | - $contentrepeat = substr($contentrepeat,0,strlen($contentrepeat)-2); //remove "</"; |
|
753 | + list($contentstart, $contentrepeat, $contentend) = preg_split('/office:body>/', $content, -1, PREG_SPLIT_NO_EMPTY); //get differt parts of document, seperatet by Pagerepeat |
|
754 | + $contentstart = substr($contentstart, 0, strlen($contentstart) - 1); //remove "<" |
|
755 | + $contentrepeat = substr($contentrepeat, 0, strlen($contentrepeat) - 2); //remove "</"; |
|
757 | 756 | // need to add page-break style to the style list |
758 | - list($stylestart,$stylerepeat,$styleend) = preg_split('/<\/office:automatic-styles>/',$content,-1, PREG_SPLIT_NO_EMPTY); //get differt parts of document style sheets |
|
757 | + list($stylestart, $stylerepeat, $styleend) = preg_split('/<\/office:automatic-styles>/', $content, -1, PREG_SPLIT_NO_EMPTY); //get differt parts of document style sheets |
|
759 | 758 | $contentstart = $stylestart.'<style:style style:name="P200" style:family="paragraph" style:parent-style-name="Standard"><style:paragraph-properties fo:break-before="page"/></style:style></office:automatic-styles>'; |
760 | 759 | $contentstart .= '<office:body>'; |
761 | 760 | $contentend = '</office:body></office:document-content>'; |
@@ -763,22 +762,22 @@ discard block |
||
763 | 762 | else |
764 | 763 | { |
765 | 764 | // Template specifies where to repeat |
766 | - list($contentstart,$contentrepeat,$contentend) = preg_split('/\$\$pagerepeat\$\$/',$content,-1, PREG_SPLIT_NO_EMPTY); //get different parts of document, seperated by pagerepeat |
|
765 | + list($contentstart, $contentrepeat, $contentend) = preg_split('/\$\$pagerepeat\$\$/', $content, -1, PREG_SPLIT_NO_EMPTY); //get different parts of document, seperated by pagerepeat |
|
767 | 766 | } |
768 | 767 | } |
769 | 768 | if (in_array($mimetype, array('application/vnd.ms-word.document.macroenabled.12', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')) && count($ids) > 1) |
770 | 769 | { |
771 | 770 | //for Word 2007 XML files we have to split the content and add a style for page break to the style area |
772 | - list($contentstart,$contentrepeat,$contentend) = preg_split('/w:body>/',$content,-1, PREG_SPLIT_NO_EMPTY); //get differt parts of document, seperatet by Pagerepeat |
|
773 | - $contentstart = substr($contentstart,0,strlen($contentstart)-1); //remove "</" |
|
774 | - $contentrepeat = substr($contentrepeat,0,strlen($contentrepeat)-2); //remove "</"; |
|
771 | + list($contentstart, $contentrepeat, $contentend) = preg_split('/w:body>/', $content, -1, PREG_SPLIT_NO_EMPTY); //get differt parts of document, seperatet by Pagerepeat |
|
772 | + $contentstart = substr($contentstart, 0, strlen($contentstart) - 1); //remove "</" |
|
773 | + $contentrepeat = substr($contentrepeat, 0, strlen($contentrepeat) - 2); //remove "</"; |
|
775 | 774 | $contentstart .= '<w:body>'; |
776 | 775 | $contentend = '</w:body></w:document>'; |
777 | 776 | } |
778 | - list($Labelstart,$Labelrepeat,$Labeltend) = preg_split('/\$\$label\$\$/',$contentrepeat,-1, PREG_SPLIT_NO_EMPTY); //get the Lable content |
|
779 | - preg_match_all('/\$\$labelplacement\$\$/',$contentrepeat,$countlables, PREG_SPLIT_NO_EMPTY); |
|
777 | + list($Labelstart, $Labelrepeat, $Labeltend) = preg_split('/\$\$label\$\$/', $contentrepeat, -1, PREG_SPLIT_NO_EMPTY); //get the Lable content |
|
778 | + preg_match_all('/\$\$labelplacement\$\$/', $contentrepeat, $countlables, PREG_SPLIT_NO_EMPTY); |
|
780 | 779 | $countlables = count($countlables[0]); |
781 | - preg_replace('/\$\$labelplacement\$\$/','',$Labelrepeat,1); |
|
780 | + preg_replace('/\$\$labelplacement\$\$/', '', $Labelrepeat, 1); |
|
782 | 781 | if ($countlables > 1) $lableprint = true; |
783 | 782 | if (count($ids) > 1 && !$contentrepeat) |
784 | 783 | { |
@@ -789,10 +788,10 @@ discard block |
||
789 | 788 | |
790 | 789 | if ($contentrepeat) |
791 | 790 | { |
792 | - $content_stream = fopen('php://temp','r+'); |
|
791 | + $content_stream = fopen('php://temp', 'r+'); |
|
793 | 792 | fwrite($content_stream, $contentstart); |
794 | 793 | $joiner = ''; |
795 | - switch($mimetype) |
|
794 | + switch ($mimetype) |
|
796 | 795 | { |
797 | 796 | case 'application/rtf': |
798 | 797 | case 'text/rtf': |
@@ -818,19 +817,19 @@ discard block |
||
818 | 817 | $joiner = "\r\n"; |
819 | 818 | break; |
820 | 819 | default: |
821 | - $err = lang('%1 not implemented for %2!','$$pagerepeat$$',$mimetype); |
|
820 | + $err = lang('%1 not implemented for %2!', '$$pagerepeat$$', $mimetype); |
|
822 | 821 | return false; |
823 | 822 | } |
824 | 823 | } |
825 | 824 | foreach ((array)$ids as $n => $id) |
826 | 825 | { |
827 | - if ($contentrepeat) $content = $contentrepeat; //content to repeat |
|
826 | + if ($contentrepeat) $content = $contentrepeat; //content to repeat |
|
828 | 827 | if ($lableprint) $content = $Labelrepeat; |
829 | 828 | |
830 | 829 | // generate replacements; if exeption is thrown, catch it set error message and return false |
831 | 830 | try |
832 | 831 | { |
833 | - if(!($replacements = $this->get_replacements($id,$content))) |
|
832 | + if (!($replacements = $this->get_replacements($id, $content))) |
|
834 | 833 | { |
835 | 834 | $err = lang('Entry not found!'); |
836 | 835 | return false; |
@@ -844,92 +843,92 @@ discard block |
||
844 | 843 | } |
845 | 844 | if ($this->report_memory_usage) error_log(__METHOD__."() $n: $id ".Api\Vfs::hsize(memory_get_usage(true))); |
846 | 845 | // some general replacements: current user, date and time |
847 | - if (strpos($content,'$$user/') !== null && ($user = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id'))) |
|
846 | + if (strpos($content, '$$user/') !== null && ($user = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'], 'person_id'))) |
|
848 | 847 | { |
849 | - $replacements += $this->contact_replacements($user,'user', false, $content); |
|
850 | - $replacements['$$user/primary_group$$'] = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'account_primary_group')); |
|
848 | + $replacements += $this->contact_replacements($user, 'user', false, $content); |
|
849 | + $replacements['$$user/primary_group$$'] = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'], 'account_primary_group')); |
|
851 | 850 | } |
852 | - $replacements['$$date$$'] = Api\DateTime::to('now',true); |
|
851 | + $replacements['$$date$$'] = Api\DateTime::to('now', true); |
|
853 | 852 | $replacements['$$datetime$$'] = Api\DateTime::to('now'); |
854 | - $replacements['$$time$$'] = Api\DateTime::to('now',false); |
|
853 | + $replacements['$$time$$'] = Api\DateTime::to('now', false); |
|
855 | 854 | |
856 | 855 | // does our extending class registered table-plugins AND document contains table tags |
857 | - if ($this->table_plugins && preg_match_all('/\\$\\$table\\/([A-Za-z0-9_]+)\\$\\$(.*?)\\$\\$endtable\\$\\$/s',$content,$matches,PREG_SET_ORDER)) |
|
856 | + if ($this->table_plugins && preg_match_all('/\\$\\$table\\/([A-Za-z0-9_]+)\\$\\$(.*?)\\$\\$endtable\\$\\$/s', $content, $matches, PREG_SET_ORDER)) |
|
858 | 857 | { |
859 | 858 | // process each table |
860 | - foreach($matches as $match) |
|
859 | + foreach ($matches as $match) |
|
861 | 860 | { |
862 | - $plugin = $match[1]; // plugin name |
|
861 | + $plugin = $match[1]; // plugin name |
|
863 | 862 | $callback = $this->table_plugins[$plugin]; |
864 | - $repeat = $match[2]; // line to repeat |
|
863 | + $repeat = $match[2]; // line to repeat |
|
865 | 864 | $repeats = ''; |
866 | 865 | if (isset($callback)) |
867 | 866 | { |
868 | - for($n = 0; ($row_replacements = $this->$callback($plugin,$id,$n,$repeat)); ++$n) |
|
867 | + for ($n = 0; ($row_replacements = $this->$callback($plugin, $id, $n, $repeat)); ++$n) |
|
869 | 868 | { |
870 | 869 | $_repeat = $this->process_commands($repeat, $row_replacements); |
871 | - $repeats .= $this->replace($_repeat,$row_replacements,$mimetype,$mso_application_progid); |
|
870 | + $repeats .= $this->replace($_repeat, $row_replacements, $mimetype, $mso_application_progid); |
|
872 | 871 | } |
873 | 872 | } |
874 | - $content = str_replace($match[0],$repeats,$content); |
|
873 | + $content = str_replace($match[0], $repeats, $content); |
|
875 | 874 | } |
876 | 875 | } |
877 | - $content = $this->process_commands($this->replace($content,$replacements,$mimetype,$mso_application_progid,$charset), $replacements); |
|
876 | + $content = $this->process_commands($this->replace($content, $replacements, $mimetype, $mso_application_progid, $charset), $replacements); |
|
878 | 877 | |
879 | 878 | // remove not existing replacements (eg. from calendar array) |
880 | - if (strpos($content,'$$') !== null) |
|
879 | + if (strpos($content, '$$') !== null) |
|
881 | 880 | { |
882 | - $content = preg_replace('/\$\$[a-z0-9_\/]+\$\$/i','',$content); |
|
881 | + $content = preg_replace('/\$\$[a-z0-9_\/]+\$\$/i', '', $content); |
|
883 | 882 | } |
884 | 883 | if ($contentrepeat) |
885 | 884 | { |
886 | - fwrite($content_stream, ($n == 0 ? '' : $joiner) . $content); |
|
885 | + fwrite($content_stream, ($n == 0 ? '' : $joiner).$content); |
|
887 | 886 | } |
888 | - if($lableprint) |
|
887 | + if ($lableprint) |
|
889 | 888 | { |
890 | - $contentrep[is_array($id) ? implode(':',$id) : $id] = $content; |
|
889 | + $contentrep[is_array($id) ? implode(':', $id) : $id] = $content; |
|
891 | 890 | } |
892 | 891 | } |
893 | 892 | if ($Labelrepeat) |
894 | 893 | { |
895 | - $countpage=0; |
|
896 | - $count=0; |
|
894 | + $countpage = 0; |
|
895 | + $count = 0; |
|
897 | 896 | $contentrepeatpages[$countpage] = $Labelstart.$Labeltend; |
898 | 897 | |
899 | 898 | foreach ($contentrep as $Label) |
900 | 899 | { |
901 | - $contentrepeatpages[$countpage] = preg_replace('/\$\$labelplacement\$\$/',$Label,$contentrepeatpages[$countpage],1); |
|
902 | - $count=$count+1; |
|
903 | - if (($count % $countlables) == 0 && count($contentrep)>$count) //new page |
|
900 | + $contentrepeatpages[$countpage] = preg_replace('/\$\$labelplacement\$\$/', $Label, $contentrepeatpages[$countpage], 1); |
|
901 | + $count = $count + 1; |
|
902 | + if (($count % $countlables) == 0 && count($contentrep) > $count) //new page |
|
904 | 903 | { |
905 | - $countpage = $countpage+1; |
|
904 | + $countpage = $countpage + 1; |
|
906 | 905 | $contentrepeatpages[$countpage] = $Labelstart.$Labeltend; |
907 | 906 | } |
908 | 907 | } |
909 | - $contentrepeatpages[$countpage] = preg_replace('/\$\$labelplacement\$\$/','',$contentrepeatpages[$countpage],-1); //clean empty fields |
|
908 | + $contentrepeatpages[$countpage] = preg_replace('/\$\$labelplacement\$\$/', '', $contentrepeatpages[$countpage], -1); //clean empty fields |
|
910 | 909 | |
911 | - switch($mimetype) |
|
910 | + switch ($mimetype) |
|
912 | 911 | { |
913 | 912 | case 'application/rtf': |
914 | 913 | case 'text/rtf': |
915 | - return $contentstart.implode('\\par \\page\\pard\\plain',$contentrepeatpages).$contentend; |
|
914 | + return $contentstart.implode('\\par \\page\\pard\\plain', $contentrepeatpages).$contentend; |
|
916 | 915 | case 'application/vnd.oasis.opendocument.text': |
917 | 916 | case 'application/vnd.oasis.opendocument.presentation': |
918 | 917 | case 'application/vnd.oasis.opendocument.text-template': |
919 | 918 | case 'application/vnd.oasis.opendocument.presentation-template': |
920 | - return $contentstart.implode('<text:line-break />',$contentrepeatpages).$contentend; |
|
919 | + return $contentstart.implode('<text:line-break />', $contentrepeatpages).$contentend; |
|
921 | 920 | case 'application/vnd.oasis.opendocument.spreadsheet': |
922 | 921 | case 'application/vnd.oasis.opendocument.spreadsheet-template': |
923 | - return $contentstart.implode('</text:p><text:p>',$contentrepeatpages).$contentend; |
|
922 | + return $contentstart.implode('</text:p><text:p>', $contentrepeatpages).$contentend; |
|
924 | 923 | case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': |
925 | 924 | case 'application/vnd.ms-word.document.macroenabled.12': |
926 | 925 | case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': |
927 | 926 | case 'application/vnd.ms-excel.sheet.macroenabled.12': |
928 | - return $contentstart.implode('<w:br w:type="page" />',$contentrepeatpages).$contentend; |
|
927 | + return $contentstart.implode('<w:br w:type="page" />', $contentrepeatpages).$contentend; |
|
929 | 928 | case 'text/plain': |
930 | - return $contentstart.implode("\r\n",$contentrep).$contentend; |
|
929 | + return $contentstart.implode("\r\n", $contentrep).$contentend; |
|
931 | 930 | } |
932 | - $err = lang('%1 not implemented for %2!','$$labelplacement$$',$mimetype); |
|
931 | + $err = lang('%1 not implemented for %2!', '$$labelplacement$$', $mimetype); |
|
933 | 932 | return false; |
934 | 933 | } |
935 | 934 | |
@@ -954,9 +953,9 @@ discard block |
||
954 | 953 | * @param string $charset =null charset to override default set by mimetype or export charset |
955 | 954 | * @return string |
956 | 955 | */ |
957 | - protected function replace($content,array $replacements,$mimetype,$mso_application_progid='',$charset=null) |
|
956 | + protected function replace($content, array $replacements, $mimetype, $mso_application_progid = '', $charset = null) |
|
958 | 957 | { |
959 | - switch($mimetype) |
|
958 | + switch ($mimetype) |
|
960 | 959 | { |
961 | 960 | case 'application/vnd.oasis.opendocument.text': // open office |
962 | 961 | case 'application/vnd.oasis.opendocument.spreadsheet': |
@@ -971,13 +970,13 @@ discard block |
||
971 | 970 | case 'application/xml': |
972 | 971 | case 'text/xml': |
973 | 972 | $is_xml = true; |
974 | - $charset = 'utf-8'; // xml files --> always use utf-8 |
|
973 | + $charset = 'utf-8'; // xml files --> always use utf-8 |
|
975 | 974 | break; |
976 | 975 | |
977 | 976 | case 'text/html': |
978 | 977 | $is_xml = true; |
979 | 978 | $matches = null; |
980 | - if (preg_match('/<meta http-equiv="content-type".*charset=([^;"]+)/i',$content,$matches)) |
|
979 | + if (preg_match('/<meta http-equiv="content-type".*charset=([^;"]+)/i', $content, $matches)) |
|
981 | 980 | { |
982 | 981 | $charset = $matches[1]; |
983 | 982 | } |
@@ -996,18 +995,18 @@ discard block |
||
996 | 995 | // do we need to convert charset |
997 | 996 | if ($charset && $charset != Api\Translation::charset()) |
998 | 997 | { |
999 | - $replacements = Api\Translation::convert($replacements,Api\Translation::charset(),$charset); |
|
998 | + $replacements = Api\Translation::convert($replacements, Api\Translation::charset(), $charset); |
|
1000 | 999 | } |
1001 | 1000 | |
1002 | 1001 | // Date only placeholders for timestamps |
1003 | - if(is_array($this->date_fields)) |
|
1002 | + if (is_array($this->date_fields)) |
|
1004 | 1003 | { |
1005 | - foreach($this->date_fields as $field) |
|
1004 | + foreach ($this->date_fields as $field) |
|
1006 | 1005 | { |
1007 | - if(($value = $replacements['$$'.$field.'$$'])) |
|
1006 | + if (($value = $replacements['$$'.$field.'$$'])) |
|
1008 | 1007 | { |
1009 | 1008 | $time = Api\DateTime::createFromFormat('+'.Api\DateTime::$user_dateformat.' '.Api\DateTime::$user_timeformat.'*', $value); |
1010 | - $replacements['$$'.$field.'/date$$'] = $time ? $time->format(Api\DateTime::$user_dateformat) : ''; |
|
1009 | + $replacements['$$'.$field.'/date$$'] = $time ? $time->format(Api\DateTime::$user_dateformat) : ''; |
|
1011 | 1010 | } |
1012 | 1011 | } |
1013 | 1012 | } |
@@ -1021,12 +1020,12 @@ discard block |
||
1021 | 1020 | // only keep tags, if we have xsl extension available |
1022 | 1021 | if (class_exists('XSLTProcessor') && class_exists('DOMDocument') && $this->parse_html_styles) |
1023 | 1022 | { |
1024 | - switch($mimetype.$mso_application_progid) |
|
1023 | + switch ($mimetype.$mso_application_progid) |
|
1025 | 1024 | { |
1026 | 1025 | case 'text/html': |
1027 | 1026 | $replace_tags = array( |
1028 | - '<b>','<strong>','<i>','<em>','<u>','<span>','<ol>','<ul>','<li>', |
|
1029 | - '<table>','<tr>','<td>','<a>','<style>','<img>', |
|
1027 | + '<b>', '<strong>', '<i>', '<em>', '<u>', '<span>', '<ol>', '<ul>', '<li>', |
|
1028 | + '<table>', '<tr>', '<td>', '<a>', '<style>', '<img>', |
|
1030 | 1029 | ); |
1031 | 1030 | break; |
1032 | 1031 | case 'application/vnd.oasis.opendocument.text': // open office |
@@ -1036,8 +1035,8 @@ discard block |
||
1036 | 1035 | case 'application/vnd.oasis.opendocument.spreadsheet-template': |
1037 | 1036 | case 'application/vnd.oasis.opendocument.presentation-template': |
1038 | 1037 | $replace_tags = array( |
1039 | - '<b>','<strong>','<i>','<em>','<u>','<span>','<ol>','<ul>','<li>', |
|
1040 | - '<table>','<tr>','<td>','<a>', |
|
1038 | + '<b>', '<strong>', '<i>', '<em>', '<u>', '<span>', '<ol>', '<ul>', '<li>', |
|
1039 | + '<table>', '<tr>', '<td>', '<a>', |
|
1041 | 1040 | ); |
1042 | 1041 | break; |
1043 | 1042 | case 'application/xmlWord.Document': // Word 2003*/ |
@@ -1046,49 +1045,49 @@ discard block |
||
1046 | 1045 | case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': |
1047 | 1046 | case 'application/vnd.ms-excel.sheet.macroenabled.12': |
1048 | 1047 | $replace_tags = array( |
1049 | - '<b>','<strong>','<i>','<em>','<u>','<span>','<ol>','<ul>','<li>', |
|
1050 | - '<table>','<tr>','<td>', |
|
1048 | + '<b>', '<strong>', '<i>', '<em>', '<u>', '<span>', '<ol>', '<ul>', '<li>', |
|
1049 | + '<table>', '<tr>', '<td>', |
|
1051 | 1050 | ); |
1052 | 1051 | break; |
1053 | 1052 | } |
1054 | 1053 | } |
1055 | 1054 | // clean replacements from array values and html or html-entities, which mess up xml |
1056 | - foreach($replacements as $name => &$value) |
|
1055 | + foreach ($replacements as $name => &$value) |
|
1057 | 1056 | { |
1058 | 1057 | // set unresolved array values to empty string |
1059 | - if(is_array($value)) |
|
1058 | + if (is_array($value)) |
|
1060 | 1059 | { |
1061 | 1060 | $value = ''; |
1062 | 1061 | continue; |
1063 | 1062 | } |
1064 | 1063 | // decode html entities back to utf-8 |
1065 | 1064 | |
1066 | - if (is_string($value) && (strpos($value,'&') !== false) && $this->parse_html_styles) |
|
1065 | + if (is_string($value) && (strpos($value, '&') !== false) && $this->parse_html_styles) |
|
1067 | 1066 | { |
1068 | - $value = html_entity_decode($value,ENT_QUOTES,$charset); |
|
1067 | + $value = html_entity_decode($value, ENT_QUOTES, $charset); |
|
1069 | 1068 | |
1070 | 1069 | // remove all non-decodable entities |
1071 | - if (strpos($value,'&') !== false) |
|
1070 | + if (strpos($value, '&') !== false) |
|
1072 | 1071 | { |
1073 | - $value = preg_replace('/&[^; ]+;/','',$value); |
|
1072 | + $value = preg_replace('/&[^; ]+;/', '', $value); |
|
1074 | 1073 | } |
1075 | 1074 | } |
1076 | - if(!$this->parse_html_styles || ( |
|
1075 | + if (!$this->parse_html_styles || ( |
|
1077 | 1076 | strpos($value, "\n") !== FALSE && |
1078 | - strpos($value,'<br') === FALSE && strpos($value, '<span') === FALSE && strpos($value, '<p') === FALSE && strpos($value, '<div') === FALSE |
|
1077 | + strpos($value, '<br') === FALSE && strpos($value, '<span') === FALSE && strpos($value, '<p') === FALSE && strpos($value, '<div') === FALSE |
|
1079 | 1078 | )) |
1080 | 1079 | { |
1081 | 1080 | // Encode special chars so they don't break the file |
1082 | - $value = htmlspecialchars($value,ENT_NOQUOTES); |
|
1081 | + $value = htmlspecialchars($value, ENT_NOQUOTES); |
|
1083 | 1082 | } |
1084 | - else if (is_string($value) && (strpos($value,'<') !== false)) |
|
1083 | + else if (is_string($value) && (strpos($value, '<') !== false)) |
|
1085 | 1084 | { |
1086 | 1085 | // Clean HTML, if it's being kept |
1087 | - if($replace_tags && extension_loaded('tidy')) { |
|
1086 | + if ($replace_tags && extension_loaded('tidy')) { |
|
1088 | 1087 | $tidy = new tidy(); |
1089 | 1088 | $cleaned = $tidy->repairString($value, self::$tidy_config); |
1090 | 1089 | // Found errors. Strip it all so there's some output |
1091 | - if($tidy->getStatus() == 2) |
|
1090 | + if ($tidy->getStatus() == 2) |
|
1092 | 1091 | { |
1093 | 1092 | error_log($tidy->errorBuffer); |
1094 | 1093 | $value = strip_tags($value); |
@@ -1099,52 +1098,52 @@ discard block |
||
1099 | 1098 | } |
1100 | 1099 | } |
1101 | 1100 | // replace </p> and <br /> with CRLF (remove <p> and CRLF) |
1102 | - $value = strip_tags(str_replace(array("\r","\n",'<p>','</p>','<div>','</div>','<br />'), |
|
1103 | - array('','','',"\r\n",'',"\r\n","\r\n"), $value), |
|
1101 | + $value = strip_tags(str_replace(array("\r", "\n", '<p>', '</p>', '<div>', '</div>', '<br />'), |
|
1102 | + array('', '', '', "\r\n", '', "\r\n", "\r\n"), $value), |
|
1104 | 1103 | implode('', $replace_tags)); |
1105 | 1104 | |
1106 | 1105 | // Change <tag>...\r\n</tag> to <tag>...</tag>\r\n or simplistic line break below will mangle it |
1107 | 1106 | // Loop to catch things like <b><span>Break:\r\n</span></b> |
1108 | - if($mso_application_progid) |
|
1107 | + if ($mso_application_progid) |
|
1109 | 1108 | { |
1110 | 1109 | $count = $i = 0; |
1111 | 1110 | do |
1112 | 1111 | { |
1113 | - $value = preg_replace('/<(b|strong|i|em|u|span)\b([^>]*?)>(.*?)'."\r\n".'<\/\1>/u', '<$1$2>$3</$1>'."\r\n",$value,-1,$count); |
|
1112 | + $value = preg_replace('/<(b|strong|i|em|u|span)\b([^>]*?)>(.*?)'."\r\n".'<\/\1>/u', '<$1$2>$3</$1>'."\r\n", $value, -1, $count); |
|
1114 | 1113 | $i++; |
1115 | - } while($count > 0 && $i < 10); // Limit of 10 chosen arbitrarily just in case |
|
1114 | + } while ($count > 0 && $i < 10); // Limit of 10 chosen arbitrarily just in case |
|
1116 | 1115 | } |
1117 | 1116 | } |
1118 | 1117 | // replace all control chars (C0+C1) but CR (\015), LF (\012) and TAB (\011) (eg. vertical tabulators) with space |
1119 | 1118 | // as they are not allowed in xml |
1120 | - $value = preg_replace('/[\000-\010\013\014\016-\037\177-\237]/u',' ',$value); |
|
1121 | - if(is_numeric($value) && $name != '$$user/account_id$$') // account_id causes problems with the preg_replace below |
|
1119 | + $value = preg_replace('/[\000-\010\013\014\016-\037\177-\237]/u', ' ', $value); |
|
1120 | + if (is_numeric($value) && $name != '$$user/account_id$$') // account_id causes problems with the preg_replace below |
|
1122 | 1121 | { |
1123 | - $names[] = preg_quote($name,'/'); |
|
1122 | + $names[] = preg_quote($name, '/'); |
|
1124 | 1123 | } |
1125 | 1124 | } |
1126 | 1125 | |
1127 | 1126 | // Look for numbers, set their value if needed |
1128 | - if($this->numeric_fields || count($names)) |
|
1127 | + if ($this->numeric_fields || count($names)) |
|
1129 | 1128 | { |
1130 | - foreach((array)$this->numeric_fields as $fieldname) { |
|
1131 | - $names[] = preg_quote($fieldname,'/'); |
|
1129 | + foreach ((array)$this->numeric_fields as $fieldname) { |
|
1130 | + $names[] = preg_quote($fieldname, '/'); |
|
1132 | 1131 | } |
1133 | 1132 | $this->format_spreadsheet_numbers($content, $names, $mimetype.$mso_application_progid); |
1134 | 1133 | } |
1135 | 1134 | |
1136 | 1135 | // Look for dates, set their value if needed |
1137 | - if($this->date_fields || count($names)) |
|
1136 | + if ($this->date_fields || count($names)) |
|
1138 | 1137 | { |
1139 | 1138 | $names = array(); |
1140 | - foreach((array)$this->date_fields as $fieldname) { |
|
1139 | + foreach ((array)$this->date_fields as $fieldname) { |
|
1141 | 1140 | $names[] = $fieldname; |
1142 | 1141 | } |
1143 | 1142 | $this->format_spreadsheet_dates($content, $names, $replacements, $mimetype.$mso_application_progid); |
1144 | 1143 | } |
1145 | 1144 | |
1146 | 1145 | // replace CRLF with linebreak tag of given type |
1147 | - switch($mimetype.$mso_application_progid) |
|
1146 | + switch ($mimetype.$mso_application_progid) |
|
1148 | 1147 | { |
1149 | 1148 | case 'application/vnd.oasis.opendocument.text': // open office writer |
1150 | 1149 | case 'application/vnd.oasis.opendocument.text-template': |
@@ -1177,14 +1176,14 @@ discard block |
||
1177 | 1176 | } |
1178 | 1177 | // now decode &, < and >, which need to be encoded as entities in xml |
1179 | 1178 | // Check for encoded >< getting double-encoded |
1180 | - if($this->parse_html_styles) |
|
1179 | + if ($this->parse_html_styles) |
|
1181 | 1180 | { |
1182 | - $replacements = str_replace(array('&',"\r","\n",'&lt;','&gt;'),array('&','',$break,'<','>'),$replacements); |
|
1181 | + $replacements = str_replace(array('&', "\r", "\n", '&lt;', '&gt;'), array('&', '', $break, '<', '>'), $replacements); |
|
1183 | 1182 | } |
1184 | 1183 | else |
1185 | 1184 | { |
1186 | 1185 | // Need to at least handle new lines, or it'll be run together on one line |
1187 | - $replacements = str_replace(array("\r","\n"),array('',$break),$replacements); |
|
1186 | + $replacements = str_replace(array("\r", "\n"), array('', $break), $replacements); |
|
1188 | 1187 | } |
1189 | 1188 | } |
1190 | 1189 | if ($mimetype == 'application/x-yaml') |
@@ -1195,24 +1194,24 @@ discard block |
||
1195 | 1194 | $parts = null; |
1196 | 1195 | if (preg_match('|^\$\$([^/]+)/([^/]+)/([^$]*)\$\$$|', $matches[3], $parts) && isset($replacements['$$'.$parts[1].'$$'])) |
1197 | 1196 | { |
1198 | - $replacement =& $replacements['$$'.$parts[1].'$$']; |
|
1197 | + $replacement = & $replacements['$$'.$parts[1].'$$']; |
|
1199 | 1198 | $replacement = preg_replace('/'.$parts[2].'/', strtr($parts[3], array( |
1200 | 1199 | '\\n' => "\n", '\\r' => "\r", '\\t' => "\t", '\\v' => "\v", '\\\\' => '\\', '\\f' => "\f", |
1201 | 1200 | )), $replacement); |
1202 | 1201 | } |
1203 | 1202 | else |
1204 | 1203 | { |
1205 | - $replacement =& $replacements[$matches[3]]; |
|
1204 | + $replacement = & $replacements[$matches[3]]; |
|
1206 | 1205 | } |
1207 | 1206 | // replacement with multiple lines --> add same number of space as before placeholder |
1208 | 1207 | if (isset($replacement)) |
1209 | 1208 | { |
1210 | 1209 | return $matches[1].$matches[2].implode("\n".$matches[1], preg_split("/\r?\n/", $replacement)); |
1211 | 1210 | } |
1212 | - return $matches[0]; // regular replacement below |
|
1211 | + return $matches[0]; // regular replacement below |
|
1213 | 1212 | }, $content); |
1214 | 1213 | } |
1215 | - return str_replace(array_keys($replacements),array_values($replacements),$content); |
|
1214 | + return str_replace(array_keys($replacements), array_values($replacements), $content); |
|
1216 | 1215 | } |
1217 | 1216 | |
1218 | 1217 | /** |
@@ -1220,40 +1219,40 @@ discard block |
||
1220 | 1219 | */ |
1221 | 1220 | protected function format_spreadsheet_numbers(&$content, $names, $mimetype) |
1222 | 1221 | { |
1223 | - foreach((array)$this->numeric_fields as $fieldname) { |
|
1224 | - $names[] = preg_quote($fieldname,'/'); |
|
1222 | + foreach ((array)$this->numeric_fields as $fieldname) { |
|
1223 | + $names[] = preg_quote($fieldname, '/'); |
|
1225 | 1224 | } |
1226 | - switch($mimetype) |
|
1225 | + switch ($mimetype) |
|
1227 | 1226 | { |
1228 | 1227 | case 'application/vnd.oasis.opendocument.spreadsheet': // open office calc |
1229 | 1228 | case 'application/vnd.oasis.opendocument.spreadsheet-template': |
1230 | - $format = '/<table:table-cell([^>]+?)office:value-type="[^"]+"([^>]*?)(?:calcext:value-type="[^"]+")?>.?<([a-z].*?)[^>]*>('.implode('|',$names).')<\/\3>.?<\/table:table-cell>/s'; |
|
1229 | + $format = '/<table:table-cell([^>]+?)office:value-type="[^"]+"([^>]*?)(?:calcext:value-type="[^"]+")?>.?<([a-z].*?)[^>]*>('.implode('|', $names).')<\/\3>.?<\/table:table-cell>/s'; |
|
1231 | 1230 | $replacement = '<table:table-cell$1office:value-type="float" office:value="$4"$2><$3>$4</$3></table:table-cell>'; |
1232 | 1231 | break; |
1233 | 1232 | case 'application/vnd.oasis.opendocument.text': // tables in open office writer |
1234 | 1233 | case 'application/vnd.oasis.opendocument.presentation': |
1235 | 1234 | case 'application/vnd.oasis.opendocument.text-template': |
1236 | 1235 | case 'application/vnd.oasis.opendocument.presentation-template': |
1237 | - $format = '/<table:table-cell([^>]+?)office:value-type="[^"]+"([^>]*?)>.?<([a-z].*?)[^>]*>('.implode('|',$names).')<\/\3>.?<\/table:table-cell>/s'; |
|
1236 | + $format = '/<table:table-cell([^>]+?)office:value-type="[^"]+"([^>]*?)>.?<([a-z].*?)[^>]*>('.implode('|', $names).')<\/\3>.?<\/table:table-cell>/s'; |
|
1238 | 1237 | $replacement = '<table:table-cell$1office:value-type="float" office:value="$4"$2><text:p text:style-name="Standard">$4</text:p></table:table-cell>'; |
1239 | 1238 | break; |
1240 | 1239 | case 'application/vnd.oasis.opendocument.text': // open office writer |
1241 | 1240 | case 'application/xmlExcel.Sheet': // Excel 2003 |
1242 | - $format = '/'.preg_quote('<Data ss:Type="String">','/').'('.implode('|',$names).')'.preg_quote('</Data>','/').'/'; |
|
1241 | + $format = '/'.preg_quote('<Data ss:Type="String">', '/').'('.implode('|', $names).')'.preg_quote('</Data>', '/').'/'; |
|
1243 | 1242 | $replacement = '<Data ss:Type="Number">$1</Data>'; |
1244 | 1243 | |
1245 | 1244 | break; |
1246 | 1245 | } |
1247 | - if($format && $names) |
|
1246 | + if ($format && $names) |
|
1248 | 1247 | { |
1249 | 1248 | // Dealing with backtrack limit per AmigoJack 10-Jul-2010 comment on php.net preg-replace docs |
1250 | 1249 | do { |
1251 | 1250 | $result = preg_replace($format, $replacement, $content, -1); |
1252 | 1251 | } |
1253 | 1252 | // try to increase/double pcre.backtrack_limit failure |
1254 | - while(preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit()); |
|
1253 | + while (preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit()); |
|
1255 | 1254 | |
1256 | - if ($result) $content = $result; // On failure $result would be NULL |
|
1255 | + if ($result) $content = $result; // On failure $result would be NULL |
|
1257 | 1256 | } |
1258 | 1257 | } |
1259 | 1258 | |
@@ -1264,7 +1263,7 @@ discard block |
||
1264 | 1263 | */ |
1265 | 1264 | protected static function increase_backtrack_limit() |
1266 | 1265 | { |
1267 | - static $backtrack_limit=null,$memory_limit=null; |
|
1266 | + static $backtrack_limit = null, $memory_limit = null; |
|
1268 | 1267 | if (!isset($backtrack_limit)) |
1269 | 1268 | { |
1270 | 1269 | $backtrack_limit = ini_get('pcre.backtrack_limit'); |
@@ -1272,16 +1271,16 @@ discard block |
||
1272 | 1271 | if (!isset($memory_limit)) |
1273 | 1272 | { |
1274 | 1273 | $memory_limit = ini_get('memory_limit'); |
1275 | - switch(strtoupper(substr($memory_limit, -1))) |
|
1274 | + switch (strtoupper(substr($memory_limit, -1))) |
|
1276 | 1275 | { |
1277 | 1276 | case 'G': $memory_limit *= 1024; |
1278 | 1277 | case 'M': $memory_limit *= 1024; |
1279 | 1278 | case 'K': $memory_limit *= 1024; |
1280 | 1279 | } |
1281 | 1280 | } |
1282 | - if ($backtrack_limit < $memory_limit/8) |
|
1281 | + if ($backtrack_limit < $memory_limit / 8) |
|
1283 | 1282 | { |
1284 | - ini_set( 'pcre.backtrack_limit', $backtrack_limit*=2); |
|
1283 | + ini_set('pcre.backtrack_limit', $backtrack_limit *= 2); |
|
1285 | 1284 | return true; |
1286 | 1285 | } |
1287 | 1286 | error_log("pcre.backtrack_limit exceeded @ $backtrack_limit, some cells left as text."); |
@@ -1293,41 +1292,41 @@ discard block |
||
1293 | 1292 | */ |
1294 | 1293 | protected function format_spreadsheet_dates(&$content, $names, &$values, $mimetype) |
1295 | 1294 | { |
1296 | - if(!in_array($mimetype, array( |
|
1297 | - 'application/vnd.oasis.opendocument.spreadsheet', // open office calc |
|
1298 | - 'application/xmlExcel.Sheet', // Excel 2003 |
|
1295 | + if (!in_array($mimetype, array( |
|
1296 | + 'application/vnd.oasis.opendocument.spreadsheet', // open office calc |
|
1297 | + 'application/xmlExcel.Sheet', // Excel 2003 |
|
1299 | 1298 | //'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'//Excel WTF |
1300 | 1299 | ))) return; |
1301 | 1300 | |
1302 | 1301 | // Some different formats dates could be in, depending what they've been through |
1303 | 1302 | $formats = array( |
1304 | - '!'.Api\DateTime::$user_dateformat . ' ' .Api\DateTime::$user_timeformat.':s', |
|
1305 | - '!'.Api\DateTime::$user_dateformat . '*' .Api\DateTime::$user_timeformat.':s', |
|
1306 | - '!'.Api\DateTime::$user_dateformat . '* ' .Api\DateTime::$user_timeformat, |
|
1307 | - '!'.Api\DateTime::$user_dateformat . '*', |
|
1303 | + '!'.Api\DateTime::$user_dateformat.' '.Api\DateTime::$user_timeformat.':s', |
|
1304 | + '!'.Api\DateTime::$user_dateformat.'*'.Api\DateTime::$user_timeformat.':s', |
|
1305 | + '!'.Api\DateTime::$user_dateformat.'* '.Api\DateTime::$user_timeformat, |
|
1306 | + '!'.Api\DateTime::$user_dateformat.'*', |
|
1308 | 1307 | '!'.Api\DateTime::$user_dateformat, |
1309 | 1308 | '!Y-m-d\TH:i:s' |
1310 | 1309 | ); |
1311 | 1310 | |
1312 | 1311 | // Properly format values for spreadsheet |
1313 | - foreach($names as $idx => &$field) |
|
1312 | + foreach ($names as $idx => &$field) |
|
1314 | 1313 | { |
1315 | 1314 | $key = '$$'.$field.'$$'; |
1316 | 1315 | $field = preg_quote($field, '/'); |
1317 | - if($values[$key]) |
|
1316 | + if ($values[$key]) |
|
1318 | 1317 | { |
1319 | 1318 | $date = Api\DateTime::createFromUserFormat($values[$key]); |
1320 | - if($mimetype == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' || |
|
1319 | + if ($mimetype == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' || |
|
1321 | 1320 | $mimetype == 'application/vnd.ms-excel.sheet.macroenabled.12')//Excel WTF |
1322 | 1321 | { |
1323 | 1322 | $interval = $date->diff(new Api\DateTime('1900-01-00 0:00')); |
1324 | - $values[$key] = $interval->format('%a')+1;// 1900-02-29 did not exist |
|
1323 | + $values[$key] = $interval->format('%a') + 1; // 1900-02-29 did not exist |
|
1325 | 1324 | // 1440 minutes in a day - fractional part |
1326 | - $values[$key] += ($date->format('H') * 60 + $date->format('i'))/1440; |
|
1325 | + $values[$key] += ($date->format('H') * 60 + $date->format('i')) / 1440; |
|
1327 | 1326 | } |
1328 | 1327 | else |
1329 | 1328 | { |
1330 | - $values[$key] = date('Y-m-d\TH:i:s',Api\DateTime::to($date,'ts')); |
|
1329 | + $values[$key] = date('Y-m-d\TH:i:s', Api\DateTime::to($date, 'ts')); |
|
1331 | 1330 | } |
1332 | 1331 | } |
1333 | 1332 | else |
@@ -1336,17 +1335,17 @@ discard block |
||
1336 | 1335 | } |
1337 | 1336 | } |
1338 | 1337 | |
1339 | - switch($mimetype) |
|
1338 | + switch ($mimetype) |
|
1340 | 1339 | { |
1341 | 1340 | case 'application/vnd.oasis.opendocument.spreadsheet': // open office calc |
1342 | 1341 | // Removing these forces calc to respect our set value-type |
1343 | - $content = str_ireplace('calcext:value-type="string"','',$content); |
|
1342 | + $content = str_ireplace('calcext:value-type="string"', '', $content); |
|
1344 | 1343 | |
1345 | - $format = '/<table:table-cell([^>]+?)office:value-type="[^"]+"([^>]*?)>.?<([a-z].*?)[^>]*>\$\$('.implode('|',$names).')\$\$<\/\3>.?<\/table:table-cell>/s'; |
|
1344 | + $format = '/<table:table-cell([^>]+?)office:value-type="[^"]+"([^>]*?)>.?<([a-z].*?)[^>]*>\$\$('.implode('|', $names).')\$\$<\/\3>.?<\/table:table-cell>/s'; |
|
1346 | 1345 | $replacement = '<table:table-cell$1office:value-type="date" office:date-value="\$\$$4\$\$"$2><$3>\$\$$4\$\$</$3></table:table-cell>'; |
1347 | 1346 | break; |
1348 | 1347 | case 'application/xmlExcel.Sheet': // Excel 2003 |
1349 | - $format = '/'.preg_quote('<Data ss:Type="String">','/').'..('.implode('|',$names).')..'.preg_quote('</Data>','/').'/'; |
|
1348 | + $format = '/'.preg_quote('<Data ss:Type="String">', '/').'..('.implode('|', $names).')..'.preg_quote('</Data>', '/').'/'; |
|
1350 | 1349 | $replacement = '<Data ss:Type="DateTime">\$\$$1\$\$</Data>'; |
1351 | 1350 | |
1352 | 1351 | break; |
@@ -1354,16 +1353,16 @@ discard block |
||
1354 | 1353 | case 'application/vnd.ms-excel.sheet.macroenabled.12': |
1355 | 1354 | break; |
1356 | 1355 | } |
1357 | - if($format && $names) |
|
1356 | + if ($format && $names) |
|
1358 | 1357 | { |
1359 | 1358 | // Dealing with backtrack limit per AmigoJack 10-Jul-2010 comment on php.net preg-replace docs |
1360 | 1359 | do { |
1361 | 1360 | $result = preg_replace($format, $replacement, $content, -1); |
1362 | 1361 | } |
1363 | 1362 | // try to increase/double pcre.backtrack_limit failure |
1364 | - while(preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit()); |
|
1363 | + while (preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit()); |
|
1365 | 1364 | |
1366 | - if ($result) $content = $result; // On failure $result would be NULL |
|
1365 | + if ($result) $content = $result; // On failure $result would be NULL |
|
1367 | 1366 | } |
1368 | 1367 | } |
1369 | 1368 | |
@@ -1373,9 +1372,9 @@ discard block |
||
1373 | 1372 | */ |
1374 | 1373 | public function cf_link_to_expand($values, $content, &$replacements, $app = null) |
1375 | 1374 | { |
1376 | - if($app == null) |
|
1375 | + if ($app == null) |
|
1377 | 1376 | { |
1378 | - $app = str_replace('_merge','',get_class($this)); |
|
1377 | + $app = str_replace('_merge', '', get_class($this)); |
|
1379 | 1378 | } |
1380 | 1379 | $cfs = Api\Storage\Customfields::get($app); |
1381 | 1380 | |
@@ -1386,24 +1385,24 @@ discard block |
||
1386 | 1385 | // Placeholders that need expanded will look like {{#name/placeholder}} |
1387 | 1386 | $matches = null; |
1388 | 1387 | preg_match_all('/\${2}(([^\/#]*?\/)?)#([^$\/]+)\/(.*?)[$}]{2}/', $content, $matches); |
1389 | - list($placeholders, , , $cf, $sub) = $matches; |
|
1388 | + list($placeholders,,, $cf, $sub) = $matches; |
|
1390 | 1389 | |
1391 | 1390 | // Collect any used custom fields from entries so you can do |
1392 | 1391 | // {{#other_app/#other_app_cf/n_fn}} |
1393 | 1392 | $expand_sub_cfs = []; |
1394 | - foreach($sub as $index => $cf_sub) |
|
1393 | + foreach ($sub as $index => $cf_sub) |
|
1395 | 1394 | { |
1396 | - if(strpos($cf_sub, '#') === 0) |
|
1395 | + if (strpos($cf_sub, '#') === 0) |
|
1397 | 1396 | { |
1398 | - $expand_sub_cfs[$cf[$index]] .= '$$'.$cf_sub . '$$ '; |
|
1397 | + $expand_sub_cfs[$cf[$index]] .= '$$'.$cf_sub.'$$ '; |
|
1399 | 1398 | } |
1400 | 1399 | } |
1401 | 1400 | |
1402 | - foreach($cf as $index => $field) |
|
1401 | + foreach ($cf as $index => $field) |
|
1403 | 1402 | { |
1404 | - if($cfs[$field]) |
|
1403 | + if ($cfs[$field]) |
|
1405 | 1404 | { |
1406 | - if(in_array($cfs[$field]['type'],array_keys($GLOBALS['egw_info']['apps']))) |
|
1405 | + if (in_array($cfs[$field]['type'], array_keys($GLOBALS['egw_info']['apps']))) |
|
1407 | 1406 | { |
1408 | 1407 | $field_app = $cfs[$field]['type']; |
1409 | 1408 | } |
@@ -1414,7 +1413,7 @@ discard block |
||
1414 | 1413 | $account = $GLOBALS['egw']->accounts->read($values['#'.$field]); |
1415 | 1414 | $app_replacements[$field] = $this->contact_replacements($account['person_id']); |
1416 | 1415 | } |
1417 | - else if (($list = explode('-',$cfs[$field]['type']) && in_array($list[0], array_keys($GLOBALS['egw_info']['apps'])))) |
|
1416 | + else if (($list = explode('-', $cfs[$field]['type']) && in_array($list[0], array_keys($GLOBALS['egw_info']['apps'])))) |
|
1418 | 1417 | { |
1419 | 1418 | // Sub-type - use app |
1420 | 1419 | $field_app = $list[0]; |
@@ -1425,7 +1424,7 @@ discard block |
||
1425 | 1424 | } |
1426 | 1425 | |
1427 | 1426 | // Get replacements for that application |
1428 | - if(!$app_replacements[$field]) |
|
1427 | + if (!$app_replacements[$field]) |
|
1429 | 1428 | { |
1430 | 1429 | // If we send the real content it can result in infinite loop of lookups |
1431 | 1430 | // so we send only the used fields |
@@ -1449,10 +1448,10 @@ discard block |
||
1449 | 1448 | * @param string $content |
1450 | 1449 | * @return array |
1451 | 1450 | */ |
1452 | - public function get_app_replacements($app, $id, $content, $prefix='') |
|
1451 | + public function get_app_replacements($app, $id, $content, $prefix = '') |
|
1453 | 1452 | { |
1454 | 1453 | $replacements = array(); |
1455 | - if($app == 'addressbook') |
|
1454 | + if ($app == 'addressbook') |
|
1456 | 1455 | { |
1457 | 1456 | return $this->contact_replacements($id, $prefix, false, $content); |
1458 | 1457 | } |
@@ -1462,7 +1461,7 @@ discard block |
||
1462 | 1461 | $classname = "{$app}_merge"; |
1463 | 1462 | $class = new $classname(); |
1464 | 1463 | $method = $app.'_replacements'; |
1465 | - if(method_exists($class,$method)) |
|
1464 | + if (method_exists($class, $method)) |
|
1466 | 1465 | { |
1467 | 1466 | $replacements = $class->$method($id, $prefix, $content); |
1468 | 1467 | } |
@@ -1489,33 +1488,33 @@ discard block |
||
1489 | 1488 | */ |
1490 | 1489 | private function process_commands($content, $replacements) |
1491 | 1490 | { |
1492 | - if (strpos($content,'$$IF') !== false) |
|
1491 | + if (strpos($content, '$$IF') !== false) |
|
1493 | 1492 | { //Example use to use: $$IF n_prefix~Herr~Sehr geehrter~Sehr geehrte$$ |
1494 | - $this->replacements =& $replacements; |
|
1495 | - $content = preg_replace_callback('/\$\$IF ([#0-9a-z_\/-]+)~(.*)~(.*)~(.*)\$\$/imU',Array($this,'replace_callback'),$content); |
|
1493 | + $this->replacements = & $replacements; |
|
1494 | + $content = preg_replace_callback('/\$\$IF ([#0-9a-z_\/-]+)~(.*)~(.*)~(.*)\$\$/imU', Array($this, 'replace_callback'), $content); |
|
1496 | 1495 | unset($this->replacements); |
1497 | 1496 | } |
1498 | - if (strpos($content,'$$NELF') !== false) |
|
1497 | + if (strpos($content, '$$NELF') !== false) |
|
1499 | 1498 | { //Example: $$NEPBR org_unit$$ sets a LF and value of org_unit, only if there is a value |
1500 | - $this->replacements =& $replacements; |
|
1501 | - $content = preg_replace_callback('/\$\$NELF ([#0-9a-z_\/-]+)\$\$/imU',Array($this,'replace_callback'),$content); |
|
1499 | + $this->replacements = & $replacements; |
|
1500 | + $content = preg_replace_callback('/\$\$NELF ([#0-9a-z_\/-]+)\$\$/imU', Array($this, 'replace_callback'), $content); |
|
1502 | 1501 | unset($this->replacements); |
1503 | 1502 | } |
1504 | - if (strpos($content,'$$NENVLF') !== false) |
|
1503 | + if (strpos($content, '$$NENVLF') !== false) |
|
1505 | 1504 | { //Example: $$NEPBRNV org_unit$$ sets only a LF if there is a value for org_units, but did not add any value |
1506 | - $this->replacements =& $replacements; |
|
1507 | - $content = preg_replace_callback('/\$\$NENVLF ([#0-9a-z_\/-]+)\$\$/imU',Array($this,'replace_callback'),$content); |
|
1505 | + $this->replacements = & $replacements; |
|
1506 | + $content = preg_replace_callback('/\$\$NENVLF ([#0-9a-z_\/-]+)\$\$/imU', Array($this, 'replace_callback'), $content); |
|
1508 | 1507 | unset($this->replacements); |
1509 | 1508 | } |
1510 | - if (strpos($content,'$$LETTERPREFIX$$') !== false) |
|
1509 | + if (strpos($content, '$$LETTERPREFIX$$') !== false) |
|
1511 | 1510 | { //Example use to use: $$LETTERPREFIX$$ |
1512 | 1511 | $LETTERPREFIXCUSTOM = '$$LETTERPREFIXCUSTOM n_prefix title n_family$$'; |
1513 | - $content = str_replace('$$LETTERPREFIX$$',$LETTERPREFIXCUSTOM,$content); |
|
1512 | + $content = str_replace('$$LETTERPREFIX$$', $LETTERPREFIXCUSTOM, $content); |
|
1514 | 1513 | } |
1515 | - if (strpos($content,'$$LETTERPREFIXCUSTOM') !== false) |
|
1514 | + if (strpos($content, '$$LETTERPREFIXCUSTOM') !== false) |
|
1516 | 1515 | { //Example use to use for a custom Letter Prefix: $$LETTERPREFIX n_prefix title n_family$$ |
1517 | - $this->replacements =& $replacements; |
|
1518 | - $content = preg_replace_callback('/\$\$LETTERPREFIXCUSTOM ([#0-9a-z_-]+)(.*)\$\$/imU',Array($this,'replace_callback'),$content); |
|
1516 | + $this->replacements = & $replacements; |
|
1517 | + $content = preg_replace_callback('/\$\$LETTERPREFIXCUSTOM ([#0-9a-z_-]+)(.*)\$\$/imU', Array($this, 'replace_callback'), $content); |
|
1519 | 1518 | unset($this->replacements); |
1520 | 1519 | } |
1521 | 1520 | return $content; |
@@ -1529,16 +1528,16 @@ discard block |
||
1529 | 1528 | */ |
1530 | 1529 | private function replace_callback($param) |
1531 | 1530 | { |
1532 | - if (array_key_exists('$$'.$param[4].'$$',$this->replacements)) $param[4] = $this->replacements['$$'.$param[4].'$$']; |
|
1533 | - if (array_key_exists('$$'.$param[3].'$$',$this->replacements)) $param[3] = $this->replacements['$$'.$param[3].'$$']; |
|
1531 | + if (array_key_exists('$$'.$param[4].'$$', $this->replacements)) $param[4] = $this->replacements['$$'.$param[4].'$$']; |
|
1532 | + if (array_key_exists('$$'.$param[3].'$$', $this->replacements)) $param[3] = $this->replacements['$$'.$param[3].'$$']; |
|
1534 | 1533 | |
1535 | 1534 | $pattern = '/'.preg_quote($param[2], '/').'/'; |
1536 | - if (strpos($param[0],'$$IF') === 0 && (trim($param[2]) == "EMPTY" || $param[2] === '')) |
|
1535 | + if (strpos($param[0], '$$IF') === 0 && (trim($param[2]) == "EMPTY" || $param[2] === '')) |
|
1537 | 1536 | { |
1538 | 1537 | $pattern = '/^$/'; |
1539 | 1538 | } |
1540 | - $replace = preg_match($pattern,$this->replacements['$$'.$param[1].'$$']) ? $param[3] : $param[4]; |
|
1541 | - switch($this->mimetype) |
|
1539 | + $replace = preg_match($pattern, $this->replacements['$$'.$param[1].'$$']) ? $param[3] : $param[4]; |
|
1540 | + switch ($this->mimetype) |
|
1542 | 1541 | { |
1543 | 1542 | case 'application/vnd.oasis.opendocument.text': // open office |
1544 | 1543 | case 'application/vnd.oasis.opendocument.spreadsheet': |
@@ -1557,7 +1556,7 @@ discard block |
||
1557 | 1556 | break; |
1558 | 1557 | } |
1559 | 1558 | |
1560 | - switch($this->mimetype) |
|
1559 | + switch ($this->mimetype) |
|
1561 | 1560 | { |
1562 | 1561 | case 'application/rtf': |
1563 | 1562 | case 'text/rtf': |
@@ -1567,7 +1566,7 @@ discard block |
||
1567 | 1566 | case 'application/vnd.oasis.opendocument.presentation': |
1568 | 1567 | case 'application/vnd.oasis.opendocument.text-template': |
1569 | 1568 | case 'application/vnd.oasis.opendocument.presentation-template': |
1570 | - $LF ='<text:line-break/>'; |
|
1569 | + $LF = '<text:line-break/>'; |
|
1571 | 1570 | break; |
1572 | 1571 | case 'application/vnd.oasis.opendocument.spreadsheet': // open office calc |
1573 | 1572 | case 'application/vnd.oasis.opendocument.spreadsheet-template': |
@@ -1580,10 +1579,10 @@ discard block |
||
1580 | 1579 | case 'application/vnd.ms-word.document.macroenabled.12': |
1581 | 1580 | case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': |
1582 | 1581 | case 'application/vnd.ms-excel.sheet.macroenabled.12': |
1583 | - $LF ='</w:t></w:r></w:p><w:p><w:r><w:t>'; |
|
1582 | + $LF = '</w:t></w:r></w:p><w:p><w:r><w:t>'; |
|
1584 | 1583 | break; |
1585 | 1584 | case 'application/xml'; |
1586 | - $LF ='</w:t></w:r><w:r><w:br w:type="text-wrapping" w:clear="all"/></w:r><w:r><w:t>'; |
|
1585 | + $LF = '</w:t></w:r><w:r><w:br w:type="text-wrapping" w:clear="all"/></w:r><w:r><w:t>'; |
|
1587 | 1586 | break; |
1588 | 1587 | case 'text/html': |
1589 | 1588 | $LF = "<br/>"; |
@@ -1591,27 +1590,27 @@ discard block |
||
1591 | 1590 | default: |
1592 | 1591 | $LF = "\n"; |
1593 | 1592 | } |
1594 | - if($is_xml) { |
|
1595 | - $this->replacements = str_replace(array('&','&amp;','<','>',"\r","\n"),array('&','&','<','>','',$LF),$this->replacements); |
|
1593 | + if ($is_xml) { |
|
1594 | + $this->replacements = str_replace(array('&', '&amp;', '<', '>', "\r", "\n"), array('&', '&', '<', '>', '', $LF), $this->replacements); |
|
1596 | 1595 | } |
1597 | - if (strpos($param[0],'$$NELF') === 0) |
|
1596 | + if (strpos($param[0], '$$NELF') === 0) |
|
1598 | 1597 | { //sets a Pagebreak and value, only if the field has a value |
1599 | - if ($this->replacements['$$'.$param[1].'$$'] !='') $replace = $LF.$this->replacements['$$'.$param[1].'$$']; |
|
1598 | + if ($this->replacements['$$'.$param[1].'$$'] != '') $replace = $LF.$this->replacements['$$'.$param[1].'$$']; |
|
1600 | 1599 | } |
1601 | - if (strpos($param[0],'$$NENVLF') === 0) |
|
1600 | + if (strpos($param[0], '$$NENVLF') === 0) |
|
1602 | 1601 | { //sets a Pagebreak without any value, only if the field has a value |
1603 | - if ($this->replacements['$$'.$param[1].'$$'] !='') $replace = $LF; |
|
1602 | + if ($this->replacements['$$'.$param[1].'$$'] != '') $replace = $LF; |
|
1604 | 1603 | } |
1605 | - if (strpos($param[0],'$$LETTERPREFIXCUSTOM') === 0) |
|
1604 | + if (strpos($param[0], '$$LETTERPREFIXCUSTOM') === 0) |
|
1606 | 1605 | { //sets a Letterprefix |
1607 | 1606 | $replaceprefixsort = array(); |
1608 | 1607 | // ToDo Stefan: $contentstart is NOT defined here!!! |
1609 | - $replaceprefix = explode(' ',substr($param[0],21,-2)); |
|
1608 | + $replaceprefix = explode(' ', substr($param[0], 21, -2)); |
|
1610 | 1609 | foreach ($replaceprefix as $nameprefix) |
1611 | 1610 | { |
1612 | - if ($this->replacements['$$'.$nameprefix.'$$'] !='') $replaceprefixsort[] = $this->replacements['$$'.$nameprefix.'$$']; |
|
1611 | + if ($this->replacements['$$'.$nameprefix.'$$'] != '') $replaceprefixsort[] = $this->replacements['$$'.$nameprefix.'$$']; |
|
1613 | 1612 | } |
1614 | - $replace = implode($replaceprefixsort,' '); |
|
1613 | + $replace = implode($replaceprefixsort, ' '); |
|
1615 | 1614 | } |
1616 | 1615 | return $replace; |
1617 | 1616 | } |
@@ -1625,14 +1624,14 @@ discard block |
||
1625 | 1624 | * @param string $dirs comma or whitespace separated directories, used if $document is a relative path |
1626 | 1625 | * @return string with error-message on error, otherwise it does NOT return |
1627 | 1626 | */ |
1628 | - public function download($document, $ids, $name='', $dirs='') |
|
1627 | + public function download($document, $ids, $name = '', $dirs = '') |
|
1629 | 1628 | { |
1630 | 1629 | $result = $this->merge_file($document, $ids, $name, $dirs, $header); |
1631 | 1630 | |
1632 | - if(is_file($result) && is_readable($result)) |
|
1631 | + if (is_file($result) && is_readable($result)) |
|
1633 | 1632 | { |
1634 | - Api\Header\Content::type($header['name'],$header['mime'],$header['filesize']); |
|
1635 | - readfile($result,'r'); |
|
1633 | + Api\Header\Content::type($header['name'], $header['mime'], $header['filesize']); |
|
1634 | + readfile($result, 'r'); |
|
1636 | 1635 | exit; |
1637 | 1636 | } |
1638 | 1637 | |
@@ -1651,7 +1650,7 @@ discard block |
||
1651 | 1650 | * @return string with error-message on error |
1652 | 1651 | * @throws Api\Exception |
1653 | 1652 | */ |
1654 | - public function merge_file($document, $ids, &$name='', $dirs='', &$header) |
|
1653 | + public function merge_file($document, $ids, &$name = '', $dirs = '', &$header) |
|
1655 | 1654 | { |
1656 | 1655 | //error_log(__METHOD__."('$document', ".array2string($ids).", '$name', dirs='$dirs') ->".function_backtrace()); |
1657 | 1656 | if (($error = $this->check_document($document, $dirs))) |
@@ -1667,7 +1666,7 @@ discard block |
||
1667 | 1666 | $mail_bo->openConnection(); |
1668 | 1667 | try |
1669 | 1668 | { |
1670 | - $msgs = $mail_bo->importMessageToMergeAndSend($this, $content_url, $ids, $_folder=''); |
|
1669 | + $msgs = $mail_bo->importMessageToMergeAndSend($this, $content_url, $ids, $_folder = ''); |
|
1671 | 1670 | } |
1672 | 1671 | catch (Api\Exception\WrongUserinput $e) |
1673 | 1672 | { |
@@ -1676,13 +1675,13 @@ discard block |
||
1676 | 1675 | } |
1677 | 1676 | //error_log(__METHOD__.__LINE__.' Message after importMessageToMergeAndSend:'.array2string($msgs)); |
1678 | 1677 | $retString = ''; |
1679 | - if (count($msgs['success'])>0) $retString .= count($msgs['success']).' '.(count($msgs['success'])+count($msgs['failed'])==1?lang('Message prepared for sending.'):lang('Message(s) send ok.'));//implode('<br />',$msgs['success']); |
|
1678 | + if (count($msgs['success']) > 0) $retString .= count($msgs['success']).' '.(count($msgs['success']) + count($msgs['failed']) == 1 ?lang('Message prepared for sending.') : lang('Message(s) send ok.')); //implode('<br />',$msgs['success']); |
|
1680 | 1679 | //if (strlen($retString)>0) $retString .= '<br />'; |
1681 | - foreach($msgs['failed'] as $c =>$e) |
|
1680 | + foreach ($msgs['failed'] as $c =>$e) |
|
1682 | 1681 | { |
1683 | 1682 | $errorString .= lang('contact').' '.lang('id').':'.$c.'->'.$e.'.'; |
1684 | 1683 | } |
1685 | - if (count($msgs['failed'])>0) $retString .= count($msgs['failed']).' '.lang('Message(s) send failed!').'=>'.$errorString; |
|
1684 | + if (count($msgs['failed']) > 0) $retString .= count($msgs['failed']).' '.lang('Message(s) send failed!').'=>'.$errorString; |
|
1686 | 1685 | return $retString; |
1687 | 1686 | case 'application/vnd.oasis.opendocument.text': |
1688 | 1687 | case 'application/vnd.oasis.opendocument.spreadsheet': |
@@ -1690,7 +1689,7 @@ discard block |
||
1690 | 1689 | case 'application/vnd.oasis.opendocument.text-template': |
1691 | 1690 | case 'application/vnd.oasis.opendocument.spreadsheet-template': |
1692 | 1691 | case 'application/vnd.oasis.opendocument.presentation-template': |
1693 | - switch($mimetype) |
|
1692 | + switch ($mimetype) |
|
1694 | 1693 | { |
1695 | 1694 | case 'application/vnd.oasis.opendocument.text': $ext = '.odt'; break; |
1696 | 1695 | case 'application/vnd.oasis.opendocument.spreadsheet': $ext = '.ods'; break; |
@@ -1699,8 +1698,8 @@ discard block |
||
1699 | 1698 | case 'application/vnd.oasis.opendocument.spreadsheet-template': $ext = '.ots'; break; |
1700 | 1699 | case 'application/vnd.oasis.opendocument.presentation-template': $ext = '.otp'; break; |
1701 | 1700 | } |
1702 | - $archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document,$ext).'-').$ext; |
|
1703 | - copy($content_url,$archive); |
|
1701 | + $archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document, $ext).'-').$ext; |
|
1702 | + copy($content_url, $archive); |
|
1704 | 1703 | $content_url = 'zip://'.$archive.'#'.($content_file = 'content.xml'); |
1705 | 1704 | $this->parse_html_styles = true; |
1706 | 1705 | break; |
@@ -1708,20 +1707,20 @@ discard block |
||
1708 | 1707 | $mimetype = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; |
1709 | 1708 | case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': |
1710 | 1709 | case 'application/vnd.ms-word.document.macroenabled.12': |
1711 | - $archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document,'.docx').'-').'.docx'; |
|
1712 | - copy($content_url,$archive); |
|
1710 | + $archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document, '.docx').'-').'.docx'; |
|
1711 | + copy($content_url, $archive); |
|
1713 | 1712 | $content_url = 'zip://'.$archive.'#'.($content_file = 'word/document.xml'); |
1714 | 1713 | $fix = array( // regular expression to fix garbled placeholders |
1715 | - '/'.preg_quote('$$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>','/').'([a-z0-9_]+)'. |
|
1716 | - preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>','/').'/i' => '$$\\1$$', |
|
1717 | - '/'.preg_quote('$$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:rPr><w:lang w:val="','/'). |
|
1718 | - '([a-z]{2}-[A-Z]{2})'.preg_quote('"/></w:rPr><w:t>','/').'([a-z0-9_]+)'. |
|
1719 | - preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:rPr><w:lang w:val="','/'). |
|
1720 | - '([a-z]{2}-[A-Z]{2})'.preg_quote('"/></w:rPr><w:t>$$','/').'/i' => '$$\\2$$', |
|
1721 | - '/'.preg_quote('$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>','/').'([a-z0-9_]+)'. |
|
1722 | - preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>','/').'/i' => '$\\1$', |
|
1723 | - '/'.preg_quote('$ $</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>','/').'([a-z0-9_]+)'. |
|
1724 | - preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>','/').'/i' => '$ $\\1$ $', |
|
1714 | + '/'.preg_quote('$$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>', '/').'([a-z0-9_]+)'. |
|
1715 | + preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>', '/').'/i' => '$$\\1$$', |
|
1716 | + '/'.preg_quote('$$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:rPr><w:lang w:val="', '/'). |
|
1717 | + '([a-z]{2}-[A-Z]{2})'.preg_quote('"/></w:rPr><w:t>', '/').'([a-z0-9_]+)'. |
|
1718 | + preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:rPr><w:lang w:val="', '/'). |
|
1719 | + '([a-z]{2}-[A-Z]{2})'.preg_quote('"/></w:rPr><w:t>$$', '/').'/i' => '$$\\2$$', |
|
1720 | + '/'.preg_quote('$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>', '/').'([a-z0-9_]+)'. |
|
1721 | + preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>', '/').'/i' => '$\\1$', |
|
1722 | + '/'.preg_quote('$ $</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>', '/').'([a-z0-9_]+)'. |
|
1723 | + preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>', '/').'/i' => '$ $\\1$ $', |
|
1725 | 1724 | ); |
1726 | 1725 | break; |
1727 | 1726 | case 'application/xml': |
@@ -1736,13 +1735,13 @@ discard block |
||
1736 | 1735 | $fix = array( // hack to get Excel 2007 to display additional rows in tables |
1737 | 1736 | '/ss:ExpandedRowCount="\d+"/' => 'ss:ExpandedRowCount="9999"', |
1738 | 1737 | ); |
1739 | - $archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document,'.xlsx').'-').'.xlsx'; |
|
1740 | - copy($content_url,$archive); |
|
1738 | + $archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document, '.xlsx').'-').'.xlsx'; |
|
1739 | + copy($content_url, $archive); |
|
1741 | 1740 | $content_url = 'zip://'.$archive.'#'.($content_file = 'xl/sharedStrings.xml'); |
1742 | 1741 | break; |
1743 | 1742 | } |
1744 | 1743 | $err = null; |
1745 | - if (!($merged =& $this->merge($content_url,$ids,$err,$mimetype,$fix))) |
|
1744 | + if (!($merged = & $this->merge($content_url, $ids, $err, $mimetype, $fix))) |
|
1746 | 1745 | { |
1747 | 1746 | //error_log(__METHOD__."() !this->merge() err=$err"); |
1748 | 1747 | return $err; |
@@ -1759,22 +1758,22 @@ discard block |
||
1759 | 1758 | { |
1760 | 1759 | // Error converting HTML styles over |
1761 | 1760 | error_log($e->getMessage()); |
1762 | - error_log("Target document: $content_url, IDs: ". array2string($ids)); |
|
1761 | + error_log("Target document: $content_url, IDs: ".array2string($ids)); |
|
1763 | 1762 | |
1764 | 1763 | // Try again, but strip HTML so user gets something |
1765 | 1764 | $this->parse_html_styles = false; |
1766 | - if (!($merged =& $this->merge($content_url,$ids,$err,$mimetype,$fix))) |
|
1765 | + if (!($merged = & $this->merge($content_url, $ids, $err, $mimetype, $fix))) |
|
1767 | 1766 | { |
1768 | 1767 | return $err; |
1769 | 1768 | } |
1770 | 1769 | } |
1771 | 1770 | if ($this->report_memory_usage) error_log(__METHOD__."() after HTML processing ".Api\Vfs::hsize(memory_get_peak_usage(true))); |
1772 | 1771 | } |
1773 | - if(!empty($name)) |
|
1772 | + if (!empty($name)) |
|
1774 | 1773 | { |
1775 | - if(empty($ext)) |
|
1774 | + if (empty($ext)) |
|
1776 | 1775 | { |
1777 | - $ext = '.'.pathinfo($document,PATHINFO_EXTENSION); |
|
1776 | + $ext = '.'.pathinfo($document, PATHINFO_EXTENSION); |
|
1778 | 1777 | } |
1779 | 1778 | $name .= $ext; |
1780 | 1779 | } |
@@ -1791,7 +1790,7 @@ discard block |
||
1791 | 1790 | error_log(__METHOD__.__LINE__." !ZipArchive::open('$archive',ZIPARCHIVE"."::CHECKCONS) failed. Trying open without validating"); |
1792 | 1791 | if ($zip->open($archive) !== true) throw new Api\Exception("!ZipArchive::open('$archive',|ZIPARCHIVE::CHECKCONS)"); |
1793 | 1792 | } |
1794 | - if ($zip->addFromString($content_file,$merged) !== true) throw new Api\Exception("!ZipArchive::addFromString('$content_file',\$merged)"); |
|
1793 | + if ($zip->addFromString($content_file, $merged) !== true) throw new Api\Exception("!ZipArchive::addFromString('$content_file',\$merged)"); |
|
1795 | 1794 | if ($zip->close() !== true) throw new Api\Exception("!ZipArchive::close()"); |
1796 | 1795 | unset($zip); |
1797 | 1796 | unset($merged); |
@@ -1800,16 +1799,16 @@ discard block |
||
1800 | 1799 | } |
1801 | 1800 | else |
1802 | 1801 | { |
1803 | - $archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document,'.'.$ext).'-').'.'.$ext; |
|
1802 | + $archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document, '.'.$ext).'-').'.'.$ext; |
|
1804 | 1803 | if ($mimetype == 'application/xml') |
1805 | 1804 | { |
1806 | - if (strpos($merged,'<?mso-application progid="Word.Document"?>') !== false) |
|
1805 | + if (strpos($merged, '<?mso-application progid="Word.Document"?>') !== false) |
|
1807 | 1806 | { |
1808 | - $header['mimetype'] = 'application/msword'; // to open it automatically in word or oowriter |
|
1807 | + $header['mimetype'] = 'application/msword'; // to open it automatically in word or oowriter |
|
1809 | 1808 | } |
1810 | - elseif (strpos($merged,'<?mso-application progid="Excel.Sheet"?>') !== false) |
|
1809 | + elseif (strpos($merged, '<?mso-application progid="Excel.Sheet"?>') !== false) |
|
1811 | 1810 | { |
1812 | - $header['mimetype'] = 'application/vnd.ms-excel'; // to open it automatically in excel or oocalc |
|
1811 | + $header['mimetype'] = 'application/vnd.ms-excel'; // to open it automatically in excel or oocalc |
|
1813 | 1812 | } |
1814 | 1813 | } |
1815 | 1814 | $handle = fopen($archive, 'w'); |
@@ -1831,13 +1830,13 @@ discard block |
||
1831 | 1830 | */ |
1832 | 1831 | public function download_by_request() |
1833 | 1832 | { |
1834 | - if(empty($_POST['data_document_name'])) return false; |
|
1835 | - if(empty($_POST['data_document_dir'])) return false; |
|
1836 | - if(empty($_POST['data_checked'])) return false; |
|
1833 | + if (empty($_POST['data_document_name'])) return false; |
|
1834 | + if (empty($_POST['data_document_dir'])) return false; |
|
1835 | + if (empty($_POST['data_checked'])) return false; |
|
1837 | 1836 | |
1838 | 1837 | return $this->download( |
1839 | 1838 | $_POST['data_document_name'], |
1840 | - explode(',',$_POST['data_checked']), |
|
1839 | + explode(',', $_POST['data_checked']), |
|
1841 | 1840 | '', |
1842 | 1841 | $_POST['data_document_dir'] |
1843 | 1842 | ); |
@@ -1851,18 +1850,18 @@ discard block |
||
1851 | 1850 | * @param array|string $mime_filter=null allowed mime type(s), default all, negative filter if $mime_filter[0] === '!' |
1852 | 1851 | * @return array List of documents, suitable for a selectbox. The key is document_<filename>. |
1853 | 1852 | */ |
1854 | - public static function get_documents($dirs, $prefix='document_', $mime_filter=null, $app='') |
|
1853 | + public static function get_documents($dirs, $prefix = 'document_', $mime_filter = null, $app = '') |
|
1855 | 1854 | { |
1856 | - $export_limit=self::getExportLimit($app); |
|
1857 | - if (!$dirs || (!self::hasExportLimit($export_limit,'ISALLOWED') && !self::is_export_limit_excepted())) return array(); |
|
1855 | + $export_limit = self::getExportLimit($app); |
|
1856 | + if (!$dirs || (!self::hasExportLimit($export_limit, 'ISALLOWED') && !self::is_export_limit_excepted())) return array(); |
|
1858 | 1857 | |
1859 | 1858 | // split multiple comma or whitespace separated directories |
1860 | 1859 | // to still allow space or comma in dirnames, we also use the trailing slash of all pathes to split |
1861 | 1860 | if (count($dirs = preg_split('/[,\s]+\//', $dirs)) > 1) |
1862 | 1861 | { |
1863 | - foreach($dirs as $n => &$d) |
|
1862 | + foreach ($dirs as $n => &$d) |
|
1864 | 1863 | { |
1865 | - if ($n) $d = '/'.$d; // re-adding trailing slash removed by split |
|
1864 | + if ($n) $d = '/'.$d; // re-adding trailing slash removed by split |
|
1866 | 1865 | } |
1867 | 1866 | } |
1868 | 1867 | if ($mime_filter && ($negativ_filter = $mime_filter[0] === '!')) |
@@ -1877,15 +1876,15 @@ discard block |
||
1877 | 1876 | } |
1878 | 1877 | } |
1879 | 1878 | $list = array(); |
1880 | - foreach($dirs as $dir) |
|
1879 | + foreach ($dirs as $dir) |
|
1881 | 1880 | { |
1882 | - if (($files = Api\Vfs::find($dir,array('need_mime'=>true),true))) |
|
1881 | + if (($files = Api\Vfs::find($dir, array('need_mime'=>true), true))) |
|
1883 | 1882 | { |
1884 | - foreach($files as $file) |
|
1883 | + foreach ($files as $file) |
|
1885 | 1884 | { |
1886 | 1885 | // return only the mime-types we support |
1887 | - $parts = explode('.',$file['name']); |
|
1888 | - if (!self::is_implemented($file['mime'],'.'.array_pop($parts))) continue; |
|
1886 | + $parts = explode('.', $file['name']); |
|
1887 | + if (!self::is_implemented($file['mime'], '.'.array_pop($parts))) continue; |
|
1889 | 1888 | if ($mime_filter && $negativ_filter === in_array($file['mime'], (array)$mime_filter)) continue; |
1890 | 1889 | $list[$prefix.$file['name']] = Api\Vfs::decodePath($file['name']); |
1891 | 1890 | } |
@@ -1912,8 +1911,8 @@ discard block |
||
1912 | 1911 | * @param int|string $export_limit =null export-limit, default $GLOBALS['egw_info']['server']['export_limit'] |
1913 | 1912 | * @return array see nextmatch_widget::egw_actions |
1914 | 1913 | */ |
1915 | - public static function document_action($dirs, $group=0, $caption='Insert in document', $prefix='document_', $default_doc='', |
|
1916 | - $export_limit=null) |
|
1914 | + public static function document_action($dirs, $group = 0, $caption = 'Insert in document', $prefix = 'document_', $default_doc = '', |
|
1915 | + $export_limit = null) |
|
1917 | 1916 | { |
1918 | 1917 | $documents = array(); |
1919 | 1918 | $editable_mimes = array(); |
@@ -1936,7 +1935,7 @@ discard block |
||
1936 | 1935 | } |
1937 | 1936 | if ($default_doc && ($file = Api\Vfs::stat($default_doc))) // put default document on top |
1938 | 1937 | { |
1939 | - if(!$file['mime']) |
|
1938 | + if (!$file['mime']) |
|
1940 | 1939 | { |
1941 | 1940 | $file['mime'] = Api\Vfs::mime_content_type($default_doc); |
1942 | 1941 | $file['path'] = $default_doc; |
@@ -1945,7 +1944,7 @@ discard block |
||
1945 | 1944 | 'icon' => Api\Vfs::mime_icon($file['mime']), |
1946 | 1945 | 'caption' => Api\Vfs::decodePath(Api\Vfs::basename($default_doc)), |
1947 | 1946 | 'group' => 1, |
1948 | - 'postSubmit' => true, // download needs post submit (not Ajax) to work |
|
1947 | + 'postSubmit' => true, // download needs post submit (not Ajax) to work |
|
1949 | 1948 | ); |
1950 | 1949 | if ($file['mime'] == 'message/rfc822') |
1951 | 1950 | { |
@@ -1964,28 +1963,28 @@ discard block |
||
1964 | 1963 | // to still allow space or comma in dirnames, we also use the trailing slash of all pathes to split |
1965 | 1964 | if (count($dirs = preg_split('/[,\s]+\//', $dirs)) > 1) |
1966 | 1965 | { |
1967 | - foreach($dirs as $n => &$d) |
|
1966 | + foreach ($dirs as $n => &$d) |
|
1968 | 1967 | { |
1969 | - if ($n) $d = '/'.$d; // re-adding trailing slash removed by split |
|
1968 | + if ($n) $d = '/'.$d; // re-adding trailing slash removed by split |
|
1970 | 1969 | } |
1971 | 1970 | } |
1972 | - foreach($dirs as $dir) |
|
1971 | + foreach ($dirs as $dir) |
|
1973 | 1972 | { |
1974 | - $files += Api\Vfs::find($dir,array( |
|
1973 | + $files += Api\Vfs::find($dir, array( |
|
1975 | 1974 | 'need_mime' => true, |
1976 | 1975 | 'order' => 'fs_name', |
1977 | 1976 | 'sort' => 'ASC', |
1978 | - ),true); |
|
1977 | + ), true); |
|
1979 | 1978 | } |
1980 | 1979 | } |
1981 | 1980 | |
1982 | 1981 | $dircount = array(); |
1983 | - foreach($files as $key => $file) |
|
1982 | + foreach ($files as $key => $file) |
|
1984 | 1983 | { |
1985 | 1984 | // use only the mime-types we support |
1986 | - $parts = explode('.',$file['name']); |
|
1987 | - if (!self::is_implemented($file['mime'],'.'.array_pop($parts)) || |
|
1988 | - !Api\Vfs::check_access($file['path'], Api\Vfs::READABLE, $file) || // remove files not readable by user |
|
1985 | + $parts = explode('.', $file['name']); |
|
1986 | + if (!self::is_implemented($file['mime'], '.'.array_pop($parts)) || |
|
1987 | + !Api\Vfs::check_access($file['path'], Api\Vfs::READABLE, $file) || // remove files not readable by user |
|
1989 | 1988 | $file['path'] === $default_doc) // default doc already added |
1990 | 1989 | { |
1991 | 1990 | unset($files[$key]); |
@@ -1993,40 +1992,40 @@ discard block |
||
1993 | 1992 | else |
1994 | 1993 | { |
1995 | 1994 | $dirname = Api\Vfs::dirname($file['path']); |
1996 | - if(!isset($dircount[$dirname])) |
|
1995 | + if (!isset($dircount[$dirname])) |
|
1997 | 1996 | { |
1998 | 1997 | $dircount[$dirname] = 1; |
1999 | 1998 | } |
2000 | 1999 | else |
2001 | 2000 | { |
2002 | - $dircount[$dirname] ++; |
|
2001 | + $dircount[$dirname]++; |
|
2003 | 2002 | } |
2004 | 2003 | } |
2005 | 2004 | } |
2006 | - foreach($files as $file) |
|
2005 | + foreach ($files as $file) |
|
2007 | 2006 | { |
2008 | 2007 | if (count($dircount) > 1) |
2009 | 2008 | { |
2010 | 2009 | $name_arr = explode('/', $file['name']); |
2011 | 2010 | $current_level = &$documents; |
2012 | - for($count = 0; $count < count($name_arr); $count++) |
|
2011 | + for ($count = 0; $count < count($name_arr); $count++) |
|
2013 | 2012 | { |
2014 | - if($count == 0) |
|
2013 | + if ($count == 0) |
|
2015 | 2014 | { |
2016 | 2015 | $current_level = &$documents; |
2017 | 2016 | } |
2018 | 2017 | else |
2019 | 2018 | { |
2020 | - $current_level = &$current_level[$prefix.$name_arr[($count-1)]]['children']; |
|
2019 | + $current_level = &$current_level[$prefix.$name_arr[($count - 1)]]['children']; |
|
2021 | 2020 | } |
2022 | - switch($count) |
|
2021 | + switch ($count) |
|
2023 | 2022 | { |
2024 | - case (count($name_arr)-1): |
|
2023 | + case (count($name_arr) - 1): |
|
2025 | 2024 | $current_level[$prefix.$file['name']] = array( |
2026 | 2025 | 'icon' => Api\Vfs::mime_icon($file['mime']), |
2027 | 2026 | 'caption' => Api\Vfs::decodePath($name_arr[$count]), |
2028 | 2027 | 'group' => 2, |
2029 | - 'postSubmit' => true, // download needs post submit (not Ajax) to work |
|
2028 | + 'postSubmit' => true, // download needs post submit (not Ajax) to work |
|
2030 | 2029 | ); |
2031 | 2030 | if ($file['mime'] == 'message/rfc822') |
2032 | 2031 | { |
@@ -2039,7 +2038,7 @@ discard block |
||
2039 | 2038 | break; |
2040 | 2039 | |
2041 | 2040 | default: |
2042 | - if(!is_array($current_level[$prefix.$name_arr[$count]])) |
|
2041 | + if (!is_array($current_level[$prefix.$name_arr[$count]])) |
|
2043 | 2042 | { |
2044 | 2043 | // create parent folder |
2045 | 2044 | $current_level[$prefix.$name_arr[$count]] = array( |
@@ -2066,7 +2065,7 @@ discard block |
||
2066 | 2065 | } |
2067 | 2066 | $documents[$file['mime']]['children'][$prefix.$file['name']] = array( |
2068 | 2067 | 'caption' => Api\Vfs::decodePath($file['name']), |
2069 | - 'postSubmit' => true, // download needs post submit (not Ajax) to work |
|
2068 | + 'postSubmit' => true, // download needs post submit (not Ajax) to work |
|
2070 | 2069 | ); |
2071 | 2070 | if ($file['mime'] == 'message/rfc822') |
2072 | 2071 | { |
@@ -2083,7 +2082,7 @@ discard block |
||
2083 | 2082 | 'icon' => Api\Vfs::mime_icon($file['mime']), |
2084 | 2083 | 'caption' => Api\Vfs::decodePath($file['name']), |
2085 | 2084 | 'group' => 2, |
2086 | - 'postSubmit' => true, // download needs post submit (not Ajax) to work |
|
2085 | + 'postSubmit' => true, // download needs post submit (not Ajax) to work |
|
2087 | 2086 | ); |
2088 | 2087 | if ($file['mime'] == 'message/rfc822') |
2089 | 2088 | { |
@@ -2101,8 +2100,8 @@ discard block |
||
2101 | 2100 | 'caption' => $caption, |
2102 | 2101 | 'children' => $documents, |
2103 | 2102 | // disable action if no document or export completly forbidden for non-admins |
2104 | - 'enabled' => (boolean)$documents && (self::hasExportLimit($export_limit,'ISALLOWED') || self::is_export_limit_excepted()), |
|
2105 | - 'hideOnDisabled' => true, // do not show 'Insert in document', if no documents defined or no export allowed |
|
2103 | + 'enabled' => (boolean)$documents && (self::hasExportLimit($export_limit, 'ISALLOWED') || self::is_export_limit_excepted()), |
|
2104 | + 'hideOnDisabled' => true, // do not show 'Insert in document', if no documents defined or no export allowed |
|
2106 | 2105 | 'group' => $group, |
2107 | 2106 | ); |
2108 | 2107 | } |
@@ -2133,14 +2132,14 @@ discard block |
||
2133 | 2132 | ); |
2134 | 2133 | |
2135 | 2134 | // egw.open() used if only 1 row selected |
2136 | - $action['egw_open'] = 'edit-mail--'.implode('&',$extra); |
|
2137 | - $action['target'] = 'compose_' .$file['path']; |
|
2135 | + $action['egw_open'] = 'edit-mail--'.implode('&', $extra); |
|
2136 | + $action['target'] = 'compose_'.$file['path']; |
|
2138 | 2137 | |
2139 | 2138 | // long_task runs menuaction once for each selected row |
2140 | 2139 | $action['nm_action'] = 'long_task'; |
2141 | 2140 | $action['popup'] = Api\Link::get_registry('mail', 'edit_popup'); |
2142 | - $action['message'] = lang('insert in %1',Api\Vfs::decodePath($file['name'])); |
|
2143 | - $action['menuaction'] = 'mail.mail_compose.ajax_merge&document='.$file['path'].'&merge='. get_called_class(); |
|
2141 | + $action['message'] = lang('insert in %1', Api\Vfs::decodePath($file['name'])); |
|
2142 | + $action['menuaction'] = 'mail.mail_compose.ajax_merge&document='.$file['path'].'&merge='.get_called_class(); |
|
2144 | 2143 | } |
2145 | 2144 | |
2146 | 2145 | /** |
@@ -2174,15 +2173,15 @@ discard block |
||
2174 | 2173 | */ |
2175 | 2174 | public static function check_document(&$document, $dirs) |
2176 | 2175 | { |
2177 | - if($document[0] !== '/') |
|
2176 | + if ($document[0] !== '/') |
|
2178 | 2177 | { |
2179 | 2178 | // split multiple comma or whitespace separated directories |
2180 | 2179 | // to still allow space or comma in dirnames, we also use the trailing slash of all pathes to split |
2181 | 2180 | if ($dirs && ($dirs = preg_split('/[,\s]+\//', $dirs))) |
2182 | 2181 | { |
2183 | - foreach($dirs as $n => $dir) |
|
2182 | + foreach ($dirs as $n => $dir) |
|
2184 | 2183 | { |
2185 | - if ($n) $dir = '/'.$dir; // re-adding trailing slash removed by split |
|
2184 | + if ($n) $dir = '/'.$dir; // re-adding trailing slash removed by split |
|
2186 | 2185 | if (Api\Vfs::stat($dir.'/'.$document) && Api\Vfs::is_readable($dir.'/'.$document)) |
2187 | 2186 | { |
2188 | 2187 | $document = $dir.'/'.$document; |
@@ -2196,7 +2195,7 @@ discard block |
||
2196 | 2195 | return false; |
2197 | 2196 | } |
2198 | 2197 | //error_log(__METHOD__."('$document', dirs='$dirs') returning 'Document '$document' does not exist or is not readable for you!'"); |
2199 | - return lang("Document '%1' does not exist or is not readable for you!",$document); |
|
2198 | + return lang("Document '%1' does not exist or is not readable for you!", $document); |
|
2200 | 2199 | } |
2201 | 2200 | |
2202 | 2201 | /** |
@@ -2217,16 +2216,16 @@ discard block |
||
2217 | 2216 | * @param string $_mimetype ='' |
2218 | 2217 | * @return string |
2219 | 2218 | */ |
2220 | - static public function number_format($number,$num_decimal_places=2,$_mimetype='') |
|
2219 | + static public function number_format($number, $num_decimal_places = 2, $_mimetype = '') |
|
2221 | 2220 | { |
2222 | 2221 | if ((string)$number === '') return ''; |
2223 | 2222 | //error_log(__METHOD__.$_mimetype); |
2224 | - switch($_mimetype) |
|
2223 | + switch ($_mimetype) |
|
2225 | 2224 | { |
2226 | 2225 | case 'application/xml': // Excel 2003 |
2227 | 2226 | case 'application/vnd.oasis.opendocument.spreadsheet': // OO.o spreadsheet |
2228 | - return number_format(str_replace(' ','',$number),$num_decimal_places,'.',''); |
|
2227 | + return number_format(str_replace(' ', '', $number), $num_decimal_places, '.', ''); |
|
2229 | 2228 | } |
2230 | - return Api\Etemplate::number_format($number,$num_decimal_places); |
|
2229 | + return Api\Etemplate::number_format($number, $num_decimal_places); |
|
2231 | 2230 | } |
2232 | 2231 | } |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | * generate temporary link_id used as array-key |
434 | 434 | * |
435 | 435 | * @param string $app app-name |
436 | - * @param mixed $id |
|
436 | + * @param string $id |
|
437 | 437 | * @return string |
438 | 438 | */ |
439 | 439 | static function temp_link_id($app,$id) |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | * @param string|array $id ='' id if $app_link_id is an appname or array with links, if 1. entry not yet created |
580 | 580 | * @param string $app2 ='' second app |
581 | 581 | * @param string $id2 ='' id in $app2 |
582 | - * @return array with link-data or False |
|
582 | + * @return string with link-data or False |
|
583 | 583 | */ |
584 | 584 | static function get_link($app_link_id,$id='',$app2='',$id2='') |
585 | 585 | { |
@@ -1197,7 +1197,7 @@ discard block |
||
1197 | 1197 | * @param string $app appname to link the file to |
1198 | 1198 | * @param string $id id in $app |
1199 | 1199 | * @param string $file VFS path to link to |
1200 | - * @return boolean true on success, false on failure |
|
1200 | + * @return null|boolean true on success, false on failure |
|
1201 | 1201 | */ |
1202 | 1202 | static function link_file($app,$id,$file) |
1203 | 1203 | { |
@@ -309,13 +309,16 @@ discard block |
||
309 | 309 | */ |
310 | 310 | static function save_session_cache() |
311 | 311 | { |
312 | - if (isset($GLOBALS['egw']->session)) // eg. cron-jobs use it too, without any session |
|
312 | + if (isset($GLOBALS['egw']->session)) |
|
313 | + { |
|
314 | + // eg. cron-jobs use it too, without any session |
|
313 | 315 | { |
314 | 316 | //error_log(__METHOD__.'() items in title-cache: '.count(self::$title_cache).' file-access-cache: '.count(self::$file_access_cache)); |
315 | 317 | |
316 | 318 | if (count(self::$title_cache) > self::TITLE_CACHE_SIZE) |
317 | 319 | { |
318 | 320 | self::$title_cache = array_slice(self::$title_cache, -self::TITLE_CACHE_SIZE); |
321 | + } |
|
319 | 322 | } |
320 | 323 | Cache::setSession(__CLASS__, 'link_title_cache', self::$title_cache); |
321 | 324 | |
@@ -366,14 +369,20 @@ discard block |
||
366 | 369 | $link_id = True; |
367 | 370 | while ($link_id && list(,$link) = each($app2)) |
368 | 371 | { |
369 | - if (!is_array($link)) // check for unlink-marker |
|
372 | + if (!is_array($link)) |
|
373 | + { |
|
374 | + // check for unlink-marker |
|
370 | 375 | { |
371 | 376 | //echo "<b>link='$link' is no array</b><br>\n"; |
372 | 377 | continue; |
373 | 378 | } |
374 | - if (is_array($id1) || !$id1) // create link only in $id1 array |
|
379 | + } |
|
380 | + if (is_array($id1) || !$id1) |
|
381 | + { |
|
382 | + // create link only in $id1 array |
|
375 | 383 | { |
376 | 384 | self::link($app1, $id1, $link['app'], $link['id'], $link['remark'],$link['owner'],$link['lastmod']); |
385 | + } |
|
377 | 386 | continue; |
378 | 387 | } |
379 | 388 | switch ($link['app']) |
@@ -397,18 +406,27 @@ discard block |
||
397 | 406 | $link_id = Link\Storage::link($app1,$id1,$link['app'],$link['id'], |
398 | 407 | $link['remark'],$link['owner'],$link['lastmod']); |
399 | 408 | // notify both sides |
400 | - if (!($no_notify&2)) self::notify('link',$link['app'],$link['id'],$app1,$id1,$link_id); |
|
401 | - if (!($no_notify&1)) self::notify('link',$app1,$id1,$link['app'],$link['id'],$link_id); |
|
409 | + if (!($no_notify&2)) |
|
410 | + { |
|
411 | + self::notify('link',$link['app'],$link['id'],$app1,$id1,$link_id); |
|
412 | + } |
|
413 | + if (!($no_notify&1)) |
|
414 | + { |
|
415 | + self::notify('link',$app1,$id1,$link['app'],$link['id'],$link_id); |
|
416 | + } |
|
402 | 417 | break; |
403 | 418 | } |
404 | 419 | } |
405 | 420 | return $link_id; |
406 | 421 | } |
407 | - if (is_array($id1) || !$id1) // create link only in $id1 array |
|
422 | + if (is_array($id1) || !$id1) |
|
423 | + { |
|
424 | + // create link only in $id1 array |
|
408 | 425 | { |
409 | 426 | if (!is_array($id1)) |
410 | 427 | { |
411 | 428 | $id1 = array( ); |
429 | + } |
|
412 | 430 | } |
413 | 431 | $link_id = self::temp_link_id($app2,$id2); |
414 | 432 | |
@@ -444,8 +462,14 @@ discard block |
||
444 | 462 | } |
445 | 463 | $link_id = Link\Storage::link($app1,$id1,$app2,$id2,$remark,$owner); |
446 | 464 | |
447 | - if (!($no_notify&2)) self::notify('link',$app2,$id2,$app1,$id1,$link_id); |
|
448 | - if (!($no_notify&1)) self::notify('link',$app1,$id1,$app2,$id2,$link_id); |
|
465 | + if (!($no_notify&2)) |
|
466 | + { |
|
467 | + self::notify('link',$app2,$id2,$app1,$id1,$link_id); |
|
468 | + } |
|
469 | + if (!($no_notify&1)) |
|
470 | + { |
|
471 | + self::notify('link',$app1,$id1,$app2,$id2,$link_id); |
|
472 | + } |
|
449 | 473 | |
450 | 474 | return $link_id; |
451 | 475 | } |
@@ -477,7 +501,10 @@ discard block |
||
477 | 501 | */ |
478 | 502 | static function get_links($app, $id, $only_app='', $order='link_lastmod DESC',$cache_titles=false, $deleted=false, $limit=null) |
479 | 503 | { |
480 | - if (self::DEBUG) echo "<p>Link::get_links(app='$app',id='$id',only_app='$only_app',order='$order',deleted='$deleted')</p>\n"; |
|
504 | + if (self::DEBUG) |
|
505 | + { |
|
506 | + echo "<p>Link::get_links(app='$app',id='$id',only_app='$only_app',order='$order',deleted='$deleted')</p>\n"; |
|
507 | + } |
|
481 | 508 | |
482 | 509 | if (is_array($id) || !$id) |
483 | 510 | { |
@@ -548,7 +575,10 @@ discard block |
||
548 | 575 | */ |
549 | 576 | static function get_links_multiple($app,array $ids,$cache_titles=true,$only_app='',$order='link_lastmod DESC', $deleted=false ) |
550 | 577 | { |
551 | - if (self::DEBUG) echo "<p>".__METHOD__."('$app',".print_r($ids,true).",$cache_titles,'$only_app','$order')</p>\n"; |
|
578 | + if (self::DEBUG) |
|
579 | + { |
|
580 | + echo "<p>".__METHOD__."('$app',".print_r($ids,true).",$cache_titles,'$only_app','$order')</p>\n"; |
|
581 | + } |
|
552 | 582 | |
553 | 583 | if (!$ids) |
554 | 584 | { |
@@ -580,7 +610,10 @@ discard block |
||
580 | 610 | { |
581 | 611 | foreach($targets as $link) |
582 | 612 | { |
583 | - if (is_array($link)) $app_ids[$link['app']][] = $link['id']; |
|
613 | + if (is_array($link)) |
|
614 | + { |
|
615 | + $app_ids[$link['app']][] = $link['id']; |
|
616 | + } |
|
584 | 617 | } |
585 | 618 | } |
586 | 619 | foreach($app_ids as $app => $a_ids) |
@@ -610,20 +643,30 @@ discard block |
||
610 | 643 | } |
611 | 644 | if (is_array($id)) |
612 | 645 | { |
613 | - if (strpos($app_link_id,':') === false) $app_link_id = self::temp_link_id($app2,$id2); // create link_id of temporary link, if not given |
|
646 | + if (strpos($app_link_id,':') === false) |
|
647 | + { |
|
648 | + $app_link_id = self::temp_link_id($app2,$id2); |
|
649 | + } |
|
650 | + // create link_id of temporary link, if not given |
|
614 | 651 | |
615 | - if (isset($id[$app_link_id]) && is_array($id[$app_link_id])) // check for unlinked-marker |
|
652 | + if (isset($id[$app_link_id]) && is_array($id[$app_link_id])) |
|
653 | + { |
|
654 | + // check for unlinked-marker |
|
616 | 655 | { |
617 | 656 | return $id[$app_link_id]; |
618 | 657 | } |
658 | + } |
|
619 | 659 | return False; |
620 | 660 | } |
621 | 661 | if ((int)$app_link_id < 0 || $app_link_id == self::VFS_APPNAME || $app2 == self::VFS_APPNAME) |
622 | 662 | { |
623 | - if ((int)$app_link_id < 0) // vfs link_id ? |
|
663 | + if ((int)$app_link_id < 0) |
|
664 | + { |
|
665 | + // vfs link_id ? |
|
624 | 666 | { |
625 | 667 | return self::fileinfo2link(-$app_link_id); |
626 | 668 | } |
669 | + } |
|
627 | 670 | if ($app_link_id == self::VFS_APPNAME) |
628 | 671 | { |
629 | 672 | return self::info_attached($app2,$id2,$id); |
@@ -671,10 +714,13 @@ discard block |
||
671 | 714 | { |
672 | 715 | echo "<p>Link::unlink('$link_id','$app',".array2string($id).",'$owner','$app2','$id2', $hold_for_purge)</p>\n"; |
673 | 716 | } |
674 | - if ($link_id < 0) // vfs-link? |
|
717 | + if ($link_id < 0) |
|
718 | + { |
|
719 | + // vfs-link? |
|
675 | 720 | { |
676 | 721 | return self::delete_attached(-$link_id); |
677 | 722 | } |
723 | + } |
|
678 | 724 | elseif ($app == self::VFS_APPNAME) |
679 | 725 | { |
680 | 726 | return self::delete_attached($app2,$id2,$id); |
@@ -713,7 +759,11 @@ discard block |
||
713 | 759 | |
714 | 760 | return count($deleted); |
715 | 761 | } |
716 | - if (!$link_id) $link_id = self::temp_link_id($app2,$id2); // create link_id of temporary link, if not given |
|
762 | + if (!$link_id) |
|
763 | + { |
|
764 | + $link_id = self::temp_link_id($app2,$id2); |
|
765 | + } |
|
766 | + // create link_id of temporary link, if not given |
|
717 | 767 | |
718 | 768 | if (isset($id[$link_id])) |
719 | 769 | { |
@@ -739,7 +789,10 @@ discard block |
||
739 | 789 | $apps = array(); |
740 | 790 | foreach(self::$app_register as $type => $reg) |
741 | 791 | { |
742 | - if ($must_support && !isset($reg[$must_support])) continue; |
|
792 | + if ($must_support && !isset($reg[$must_support])) |
|
793 | + { |
|
794 | + continue; |
|
795 | + } |
|
743 | 796 | |
744 | 797 | list($app) = explode('-', $type); |
745 | 798 | if ($GLOBALS['egw_info']['user']['apps'][$app]) |
@@ -796,12 +849,18 @@ discard block |
||
796 | 849 | */ |
797 | 850 | static function title($app,$id,$link=null) |
798 | 851 | { |
799 | - if (!$id) return ''; |
|
852 | + if (!$id) |
|
853 | + { |
|
854 | + return ''; |
|
855 | + } |
|
800 | 856 | |
801 | 857 | $title =& self::get_cache($app,$id); |
802 | 858 | if (isset($title) && !empty($title) && !is_array($id)) |
803 | 859 | { |
804 | - if (self::DEBUG) echo '<p>'.__METHOD__."('$app','$id')='$title' (from cache)</p>\n"; |
|
860 | + if (self::DEBUG) |
|
861 | + { |
|
862 | + echo '<p>'.__METHOD__."('$app','$id')='$title' (from cache)</p>\n"; |
|
863 | + } |
|
805 | 864 | return $title; |
806 | 865 | } |
807 | 866 | if ($app == self::VFS_APPNAME) |
@@ -821,21 +880,33 @@ discard block |
||
821 | 880 | { |
822 | 881 | $title .= ': '.$link['type'] . ' '.Vfs::hsize($link['size']); |
823 | 882 | }*/ |
824 | - if (self::DEBUG) echo '<p>'.__METHOD__."('$app','$id')='$title' (file)</p>\n"; |
|
883 | + if (self::DEBUG) |
|
884 | + { |
|
885 | + echo '<p>'.__METHOD__."('$app','$id')='$title' (file)</p>\n"; |
|
886 | + } |
|
825 | 887 | return $title; |
826 | 888 | } |
827 | 889 | if ($app == '' || !is_array($reg = self::$app_register[$app]) || !isset($reg['title'])) |
828 | 890 | { |
829 | - if (self::DEBUG) echo "<p>".__METHOD__."('$app','$id') something is wrong!!!</p>\n"; |
|
891 | + if (self::DEBUG) |
|
892 | + { |
|
893 | + echo "<p>".__METHOD__."('$app','$id') something is wrong!!!</p>\n"; |
|
894 | + } |
|
830 | 895 | return false; //array(); // not sure why it should return an array on failure, as the description states boolean/string |
831 | 896 | } |
832 | 897 | $method = $reg['title']; |
833 | 898 | |
834 | - if (true) $title = self::exec($method, array($id)); |
|
899 | + if (true) |
|
900 | + { |
|
901 | + $title = self::exec($method, array($id)); |
|
902 | + } |
|
835 | 903 | |
836 | - if ($id && is_null($title)) // $app,$id has been deleted ==> unlink all links to it |
|
904 | + if ($id && is_null($title)) |
|
905 | + { |
|
906 | + // $app,$id has been deleted ==> unlink all links to it |
|
837 | 907 | { |
838 | 908 | static $unlinking = array(); |
909 | + } |
|
839 | 910 | // check if we are already trying to unlink the entry, to avoid an infinit recursion |
840 | 911 | if (!isset($unlinking[$app]) || !isset($unlinking[$app][$id])) |
841 | 912 | { |
@@ -843,10 +914,16 @@ discard block |
||
843 | 914 | self::unlink(0,$app,$id); |
844 | 915 | unset($unlinking[$app][$id]); |
845 | 916 | } |
846 | - if (self::DEBUG) echo '<p>'.__METHOD__."('$app','$id') unlinked, as $method returned null</p>\n"; |
|
917 | + if (self::DEBUG) |
|
918 | + { |
|
919 | + echo '<p>'.__METHOD__."('$app','$id') unlinked, as $method returned null</p>\n"; |
|
920 | + } |
|
847 | 921 | return False; |
848 | 922 | } |
849 | - if (self::DEBUG) echo '<p>'.__METHOD__."('$app','$id')='$title' (from $method)</p>\n"; |
|
923 | + if (self::DEBUG) |
|
924 | + { |
|
925 | + echo '<p>'.__METHOD__."('$app','$id')='$title' (from $method)</p>\n"; |
|
926 | + } |
|
850 | 927 | |
851 | 928 | return $title; |
852 | 929 | } |
@@ -1012,7 +1089,10 @@ discard block |
||
1012 | 1089 | { |
1013 | 1090 | foreach($registry['mime'] as $mime => $data) |
1014 | 1091 | { |
1015 | - if ($mime == $type) return $data; |
|
1092 | + if ($mime == $type) |
|
1093 | + { |
|
1094 | + return $data; |
|
1095 | + } |
|
1016 | 1096 | if ($mime[0] == '/' && preg_match($mime.'i', $type)) |
1017 | 1097 | { |
1018 | 1098 | $wildcard_mime = $data; |
@@ -1033,7 +1113,10 @@ discard block |
||
1033 | 1113 | */ |
1034 | 1114 | static function mime_open($path, $type=null, &$popup=null) |
1035 | 1115 | { |
1036 | - if (is_null($type)) $type = Vfs::mime_content_type($path); |
|
1116 | + if (is_null($type)) |
|
1117 | + { |
|
1118 | + $type = Vfs::mime_content_type($path); |
|
1119 | + } |
|
1037 | 1120 | |
1038 | 1121 | if (($data = self::get_mime_info($type))) |
1039 | 1122 | { |
@@ -1101,14 +1184,20 @@ discard block |
||
1101 | 1184 | { |
1102 | 1185 | $reg = self::$app_register[$app]; |
1103 | 1186 | |
1104 | - if (!isset($reg)) return false; |
|
1187 | + if (!isset($reg)) |
|
1188 | + { |
|
1189 | + return false; |
|
1190 | + } |
|
1105 | 1191 | |
1106 | - if (!isset($reg[$name])) // some defaults |
|
1192 | + if (!isset($reg[$name])) |
|
1193 | + { |
|
1194 | + // some defaults |
|
1107 | 1195 | { |
1108 | 1196 | switch($name) |
1109 | 1197 | { |
1110 | 1198 | case 'name': |
1111 | 1199 | $reg[$name] = $app; |
1200 | + } |
|
1112 | 1201 | break; |
1113 | 1202 | case 'entry': |
1114 | 1203 | $reg[$name] = $app; |
@@ -1147,10 +1236,12 @@ discard block |
||
1147 | 1236 | |
1148 | 1237 | if ($app) |
1149 | 1238 | { |
1150 | - if( isset(self::$app_register[$app]) ) { |
|
1239 | + if( isset(self::$app_register[$app]) ) |
|
1240 | + { |
|
1151 | 1241 | $reg = self::$app_register[$app]; |
1152 | 1242 | |
1153 | - if( isset($reg['file_dir']) ) { |
|
1243 | + if( isset($reg['file_dir']) ) |
|
1244 | + { |
|
1154 | 1245 | $app = $reg['file_dir']; |
1155 | 1246 | } |
1156 | 1247 | } |
@@ -1212,7 +1303,10 @@ discard block |
||
1212 | 1303 | if (file_exists($entry_dir) || ($Ok = mkdir($entry_dir,0,true))) |
1213 | 1304 | { |
1214 | 1305 | $Ok = Vfs::copy_uploaded($file, $p=Vfs::parse_url($entry_dir, PHP_URL_PATH), $comment, false); // no is_uploaded_file() check! |
1215 | - if (!$Ok) error_log(__METHOD__."('$app', '$id', ".array2string($file).", '$comment') called Vfs::copy_uploaded('$file[tmp_name]', '$p', '$comment', false)=".array2string($Ok)); |
|
1306 | + if (!$Ok) |
|
1307 | + { |
|
1308 | + error_log(__METHOD__."('$app', '$id', ".array2string($file).", '$comment') called Vfs::copy_uploaded('$file[tmp_name]', '$p', '$comment', false)=".array2string($Ok)); |
|
1309 | + } |
|
1216 | 1310 | } |
1217 | 1311 | else |
1218 | 1312 | { |
@@ -1232,7 +1326,10 @@ discard block |
||
1232 | 1326 | static function link_file($app,$id,$file) |
1233 | 1327 | { |
1234 | 1328 | // Don't try to link into app dir if there is no id |
1235 | - if(!$id) return; |
|
1329 | + if(!$id) |
|
1330 | + { |
|
1331 | + return; |
|
1332 | + } |
|
1236 | 1333 | |
1237 | 1334 | if (!Vfs::stat($file)) |
1238 | 1335 | { |
@@ -1259,10 +1356,13 @@ discard block |
||
1259 | 1356 | */ |
1260 | 1357 | static function delete_attached($app,$id='',$fname='') |
1261 | 1358 | { |
1262 | - if ((int)$app > 0) // is file_id |
|
1359 | + if ((int)$app > 0) |
|
1360 | + { |
|
1361 | + // is file_id |
|
1263 | 1362 | { |
1264 | 1363 | $url = Vfs::resolve_url(Vfs\Sqlfs\StreamWrapper::id2path($app)); |
1265 | 1364 | } |
1365 | + } |
|
1266 | 1366 | else |
1267 | 1367 | { |
1268 | 1368 | if (empty($app) || empty($id)) |
@@ -1271,9 +1371,12 @@ discard block |
||
1271 | 1371 | } |
1272 | 1372 | $url = self::vfs_path($app,$id,$fname); |
1273 | 1373 | |
1274 | - if (!$fname || !$id) // we delete the whole entry (or all entries), which probably not exist anymore |
|
1374 | + if (!$fname || !$id) |
|
1375 | + { |
|
1376 | + // we delete the whole entry (or all entries), which probably not exist anymore |
|
1275 | 1377 | { |
1276 | 1378 | $current_is_root = Vfs::$is_root; |
1379 | + } |
|
1277 | 1380 | Vfs::$is_root = true; |
1278 | 1381 | } |
1279 | 1382 | } |
@@ -1293,7 +1396,10 @@ discard block |
||
1293 | 1396 | if (($Ok = !file_exists($url) || Vfs::remove($url,true)) && ((int)$app > 0 || $fname)) |
1294 | 1397 | { |
1295 | 1398 | // try removing the dir, in case it's empty |
1296 | - if (($dir = Vfs::dirname($url))) @Vfs::rmdir($dir); |
|
1399 | + if (($dir = Vfs::dirname($url))) |
|
1400 | + { |
|
1401 | + @Vfs::rmdir($dir); |
|
1402 | + } |
|
1297 | 1403 | } |
1298 | 1404 | if (!is_null($current_is_root)) |
1299 | 1405 | { |
@@ -1340,8 +1446,10 @@ discard block |
||
1340 | 1446 | $up = explode('/',$url[0] == '/' ? $url : parse_url($url,PHP_URL_PATH)); // /apps/$app/$id |
1341 | 1447 | $app = null; |
1342 | 1448 | |
1343 | - foreach( self::$app_register as $tapp => $reg ) { |
|
1344 | - if( isset($reg['file_dir']) ) { |
|
1449 | + foreach( self::$app_register as $tapp => $reg ) |
|
1450 | + { |
|
1451 | + if( isset($reg['file_dir']) ) |
|
1452 | + { |
|
1345 | 1453 | $lup = $up; |
1346 | 1454 | |
1347 | 1455 | unset($lup[0]); |
@@ -1353,20 +1461,25 @@ discard block |
||
1353 | 1461 | |
1354 | 1462 | $found = true; |
1355 | 1463 | |
1356 | - foreach( $fdp as $part ) { |
|
1357 | - if( current($lup) == $part ) { |
|
1358 | - if( next($lup) === false ) { |
|
1464 | + foreach( $fdp as $part ) |
|
1465 | + { |
|
1466 | + if( current($lup) == $part ) |
|
1467 | + { |
|
1468 | + if( next($lup) === false ) |
|
1469 | + { |
|
1359 | 1470 | $found = false; |
1360 | 1471 | break; |
1361 | 1472 | } |
1362 | 1473 | } |
1363 | - else { |
|
1474 | + else |
|
1475 | + { |
|
1364 | 1476 | $found = false; |
1365 | 1477 | break; |
1366 | 1478 | } |
1367 | 1479 | } |
1368 | 1480 | |
1369 | - if( $found ) { |
|
1481 | + if( $found ) |
|
1482 | + { |
|
1370 | 1483 | $id = current($lup); |
1371 | 1484 | $app = $tapp; |
1372 | 1485 | break; |
@@ -1374,7 +1487,8 @@ discard block |
||
1374 | 1487 | } |
1375 | 1488 | } |
1376 | 1489 | |
1377 | - if( $app === null ) { |
|
1490 | + if( $app === null ) |
|
1491 | + { |
|
1378 | 1492 | list(,,$app,$id) = $up; |
1379 | 1493 | } |
1380 | 1494 | |
@@ -1404,10 +1518,16 @@ discard block |
||
1404 | 1518 | $path = self::vfs_path($app,$id); |
1405 | 1519 | //error_log(__METHOD__."($app,$id) url=$url"); |
1406 | 1520 | |
1407 | - if (!($extra = self::get_registry($app,'find_extra'))) $extra = array(); |
|
1521 | + if (!($extra = self::get_registry($app,'find_extra'))) |
|
1522 | + { |
|
1523 | + $extra = array(); |
|
1524 | + } |
|
1408 | 1525 | |
1409 | 1526 | // always use regular links stream wrapper here: extended one is unnecessary (slow) for just listing attachments |
1410 | - if (substr($path,0,13) == 'stylite.links') $path = substr($path,8); |
|
1527 | + if (substr($path,0,13) == 'stylite.links') |
|
1528 | + { |
|
1529 | + $path = substr($path,8); |
|
1530 | + } |
|
1411 | 1531 | |
1412 | 1532 | $attached = array(); |
1413 | 1533 | if (($url2stats = Vfs::find($path,array('need_mime'=>true,'type'=>'F','url'=>true)+$extra,true))) |
@@ -1650,7 +1770,10 @@ discard block |
||
1650 | 1770 | $method = array_shift($data); |
1651 | 1771 | $ret = self::exec($method, $data); |
1652 | 1772 | |
1653 | - if (is_resource($ret)) fseek($ret, 0); |
|
1773 | + if (is_resource($ret)) |
|
1774 | + { |
|
1775 | + fseek($ret, 0); |
|
1776 | + } |
|
1654 | 1777 | |
1655 | 1778 | if ($return_resource != is_resource($ret)) |
1656 | 1779 | { |
@@ -1748,7 +1871,10 @@ discard block |
||
1748 | 1871 | } |
1749 | 1872 | |
1750 | 1873 | list($app, $class, $m) = $parts = explode('.', $method); |
1751 | - if (count($parts) != 3) throw Api\Exception\WrongParameter("Wrong dot-delimited method string '$method'!"); |
|
1874 | + if (count($parts) != 3) |
|
1875 | + { |
|
1876 | + throw Api\Exception\WrongParameter("Wrong dot-delimited method string '$method'!"); |
|
1877 | + } |
|
1752 | 1878 | |
1753 | 1879 | if (!isset($objs[$class])) |
1754 | 1880 | { |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | /** |
114 | 114 | * appname used for returned attached files (!= 'filemanager'!) |
115 | 115 | */ |
116 | - const VFS_APPNAME = 'file'; // pseudo-appname for own file-attachments in vfs, this is NOT the vfs-app |
|
116 | + const VFS_APPNAME = 'file'; // pseudo-appname for own file-attachments in vfs, this is NOT the vfs-app |
|
117 | 117 | |
118 | 118 | /** |
119 | 119 | * Appname used of files stored via Link::set_data() |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | 'icon' => 'addressbook/accounts', |
147 | 147 | 'query' => 'EGroupware\\Api\\Accounts::link_query', |
148 | 148 | 'title' => 'EGroupware\\Api\\Accounts::username', |
149 | - 'view' => array('menuaction'=>'addressbook.addressbook_ui.view','ajax'=>'true'), |
|
149 | + 'view' => array('menuaction'=>'addressbook.addressbook_ui.view', 'ajax'=>'true'), |
|
150 | 150 | 'view_id' => 'account_id' |
151 | 151 | ), |
152 | 152 | 'api' => array( |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | * |
205 | 205 | * @param boolean $clear_all do not use session AND not permission check for app-registry |
206 | 206 | */ |
207 | - static function init_static($clear_all=false) |
|
207 | + static function init_static($clear_all = false) |
|
208 | 208 | { |
209 | 209 | // FireFox 36 can not display pdf with it's internal viewer in an iframe used by mobile theme/template for popups |
210 | 210 | // same is true for all mobile devices |
@@ -218,19 +218,19 @@ discard block |
||
218 | 218 | // for performance reasons, we do it only once / cache it in the session |
219 | 219 | if ($clear_all || !($search_link_hooks = Cache::getSession(__CLASS__, 'search_link_hooks'))) |
220 | 220 | { |
221 | - $search_link_hooks = Hooks::process('search_link',array(), $clear_all || (bool)$GLOBALS['egw_info']['flags']['async-service']); |
|
221 | + $search_link_hooks = Hooks::process('search_link', array(), $clear_all || (bool)$GLOBALS['egw_info']['flags']['async-service']); |
|
222 | 222 | Cache::setSession(__CLASS__, 'search_link_hooks', $search_link_hooks); |
223 | 223 | } |
224 | 224 | if (is_array($search_link_hooks)) |
225 | 225 | { |
226 | - foreach($search_link_hooks as $app => $data) |
|
226 | + foreach ($search_link_hooks as $app => $data) |
|
227 | 227 | { |
228 | 228 | // allow apps to register additional types |
229 | 229 | if (isset($data['additional'])) |
230 | 230 | { |
231 | - foreach($data['additional'] as $name => $values) |
|
231 | + foreach ($data['additional'] as $name => $values) |
|
232 | 232 | { |
233 | - $values['app'] = $app; // store name of registring app, to be able to check access |
|
233 | + $values['app'] = $app; // store name of registring app, to be able to check access |
|
234 | 234 | self::$app_register[$name] = $values; |
235 | 235 | } |
236 | 236 | unset($data['additional']); |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | { |
241 | 241 | $data['list'] = array('menuaction' => $data['view_list']); |
242 | 242 | } |
243 | - elseif(isset($data['list']) && !isset($data['view_list'])) |
|
243 | + elseif (isset($data['list']) && !isset($data['view_list'])) |
|
244 | 244 | { |
245 | 245 | $data['view_list'] = $data['list']['menuaction']; |
246 | 246 | } |
@@ -284,18 +284,18 @@ discard block |
||
284 | 284 | public static function json_registry() |
285 | 285 | { |
286 | 286 | $to_json = array(); |
287 | - foreach(self::$app_register as $app => $data) |
|
287 | + foreach (self::$app_register as $app => $data) |
|
288 | 288 | { |
289 | 289 | if (isset($GLOBALS['egw_info']['user']['apps'][$app]) || |
290 | 290 | isset($data['app']) && isset($GLOBALS['egw_info']['user']['apps'][$data['app']])) |
291 | 291 | { |
292 | 292 | $to_json[$app] = array_intersect_key($data, array_flip(array( |
293 | - 'view','view_id','view_popup', |
|
294 | - 'add','add_app','add_id','add_popup', |
|
295 | - 'edit','edit_id','edit_popup', |
|
296 | - 'list','list_popup', |
|
297 | - 'name','icon','query', |
|
298 | - 'mime','entry','entries', |
|
293 | + 'view', 'view_id', 'view_popup', |
|
294 | + 'add', 'add_app', 'add_id', 'add_popup', |
|
295 | + 'edit', 'edit_id', 'edit_popup', |
|
296 | + 'list', 'list_popup', |
|
297 | + 'name', 'icon', 'query', |
|
298 | + 'mime', 'entry', 'entries', |
|
299 | 299 | ))); |
300 | 300 | } |
301 | 301 | } |
@@ -350,11 +350,11 @@ discard block |
||
350 | 350 | * @param int $no_notify =0 &1 dont notify $app1, &2 dont notify $app2 |
351 | 351 | * @return int/boolean False (for db or param-error) or on success link_id (Please not the return-value of $id1) |
352 | 352 | */ |
353 | - static function link( $app1,&$id1,$app2,$id2='',$remark='',$owner=0,$lastmod=0,$no_notify=0 ) |
|
353 | + static function link($app1, &$id1, $app2, $id2 = '', $remark = '', $owner = 0, $lastmod = 0, $no_notify = 0) |
|
354 | 354 | { |
355 | 355 | if (self::DEBUG) |
356 | 356 | { |
357 | - echo "<p>Link::link('$app1',$id1,'".print_r($app2,true)."',".print_r($id2,true).",'$remark',$owner,$lastmod)</p>\n"; |
|
357 | + echo "<p>Link::link('$app1',$id1,'".print_r($app2, true)."',".print_r($id2, true).",'$remark',$owner,$lastmod)</p>\n"; |
|
358 | 358 | } |
359 | 359 | if (!$app1 || !$app2 || $app1 == $app2 && $id1 == $id2) |
360 | 360 | { |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | } |
374 | 374 | if (is_array($id1) || !$id1) // create link only in $id1 array |
375 | 375 | { |
376 | - self::link($app1, $id1, $link['app'], $link['id'], $link['remark'],$link['owner'],$link['lastmod']); |
|
376 | + self::link($app1, $id1, $link['app'], $link['id'], $link['remark'], $link['owner'], $link['lastmod']); |
|
377 | 377 | continue; |
378 | 378 | } |
379 | 379 | switch ($link['app']) |
@@ -386,19 +386,19 @@ discard block |
||
386 | 386 | } |
387 | 387 | // fall through |
388 | 388 | case self::VFS_APPNAME: |
389 | - $link_id = self::attach_file($app1,$id1,$link['id'],$link['remark']); |
|
389 | + $link_id = self::attach_file($app1, $id1, $link['id'], $link['remark']); |
|
390 | 390 | break; |
391 | 391 | |
392 | 392 | case self::VFS_LINK: |
393 | - $link_id = self::link_file($app1,$id1, $link['id'],$link['remark']); |
|
393 | + $link_id = self::link_file($app1, $id1, $link['id'], $link['remark']); |
|
394 | 394 | break; |
395 | 395 | |
396 | 396 | default: |
397 | - $link_id = Link\Storage::link($app1,$id1,$link['app'],$link['id'], |
|
398 | - $link['remark'],$link['owner'],$link['lastmod']); |
|
397 | + $link_id = Link\Storage::link($app1, $id1, $link['app'], $link['id'], |
|
398 | + $link['remark'], $link['owner'], $link['lastmod']); |
|
399 | 399 | // notify both sides |
400 | - if (!($no_notify&2)) self::notify('link',$link['app'],$link['id'],$app1,$id1,$link_id); |
|
401 | - if (!($no_notify&1)) self::notify('link',$app1,$id1,$link['app'],$link['id'],$link_id); |
|
400 | + if (!($no_notify&2)) self::notify('link', $link['app'], $link['id'], $app1, $id1, $link_id); |
|
401 | + if (!($no_notify&1)) self::notify('link', $app1, $id1, $link['app'], $link['id'], $link_id); |
|
402 | 402 | break; |
403 | 403 | } |
404 | 404 | } |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | { |
411 | 411 | $id1 = array( ); |
412 | 412 | } |
413 | - $link_id = self::temp_link_id($app2,$id2); |
|
413 | + $link_id = self::temp_link_id($app2, $id2); |
|
414 | 414 | |
415 | 415 | $id1[$link_id] = array( |
416 | 416 | 'app' => $app2, |
@@ -428,24 +428,24 @@ discard block |
||
428 | 428 | } |
429 | 429 | if ($app1 == self::VFS_LINK) |
430 | 430 | { |
431 | - return self::link_file($app2,$id2,$id1,$remark); |
|
431 | + return self::link_file($app2, $id2, $id1, $remark); |
|
432 | 432 | } |
433 | 433 | elseif ($app2 == self::VFS_LINK) |
434 | 434 | { |
435 | - return self::link_file($app1,$id1,$id2,$remark); |
|
435 | + return self::link_file($app1, $id1, $id2, $remark); |
|
436 | 436 | } |
437 | 437 | if ($app1 == self::VFS_APPNAME) |
438 | 438 | { |
439 | - return self::attach_file($app2,$id2,$id1,$remark); |
|
439 | + return self::attach_file($app2, $id2, $id1, $remark); |
|
440 | 440 | } |
441 | 441 | elseif ($app2 == self::VFS_APPNAME) |
442 | 442 | { |
443 | - return self::attach_file($app1,$id1,$id2,$remark); |
|
443 | + return self::attach_file($app1, $id1, $id2, $remark); |
|
444 | 444 | } |
445 | - $link_id = Link\Storage::link($app1,$id1,$app2,$id2,$remark,$owner); |
|
445 | + $link_id = Link\Storage::link($app1, $id1, $app2, $id2, $remark, $owner); |
|
446 | 446 | |
447 | - if (!($no_notify&2)) self::notify('link',$app2,$id2,$app1,$id1,$link_id); |
|
448 | - if (!($no_notify&1)) self::notify('link',$app1,$id1,$app2,$id2,$link_id); |
|
447 | + if (!($no_notify&2)) self::notify('link', $app2, $id2, $app1, $id1, $link_id); |
|
448 | + if (!($no_notify&1)) self::notify('link', $app1, $id1, $app2, $id2, $link_id); |
|
449 | 449 | |
450 | 450 | return $link_id; |
451 | 451 | } |
@@ -457,9 +457,9 @@ discard block |
||
457 | 457 | * @param mixed $id |
458 | 458 | * @return string |
459 | 459 | */ |
460 | - static function temp_link_id($app,$id) |
|
460 | + static function temp_link_id($app, $id) |
|
461 | 461 | { |
462 | - return $app.':'.(!in_array($app, array(self::VFS_APPNAME,self::VFS_LINK, self::DATA_APPNAME)) ? $id : $id['name']); |
|
462 | + return $app.':'.(!in_array($app, array(self::VFS_APPNAME, self::VFS_LINK, self::DATA_APPNAME)) ? $id : $id['name']); |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | /** |
@@ -475,7 +475,7 @@ discard block |
||
475 | 475 | * @param int $limit =null number of entries to return, only affects links, attachments are allways reported! |
476 | 476 | * @return array id => links pairs if $id is an array or just the links (only_app: ids) or empty array if no matching links found |
477 | 477 | */ |
478 | - static function get_links($app, $id, $only_app='', $order='link_lastmod DESC',$cache_titles=false, $deleted=false, $limit=null) |
|
478 | + static function get_links($app, $id, $only_app = '', $order = 'link_lastmod DESC', $cache_titles = false, $deleted = false, $limit = null) |
|
479 | 479 | { |
480 | 480 | if (self::DEBUG) echo "<p>Link::get_links(app='$app',id='$id',only_app='$only_app',order='$order',deleted='$deleted')</p>\n"; |
481 | 481 | |
@@ -486,7 +486,7 @@ discard block |
||
486 | 486 | { |
487 | 487 | if (($not_only = $only_app[0] == '!')) |
488 | 488 | { |
489 | - $only_app = substr(1,$only_app); |
|
489 | + $only_app = substr(1, $only_app); |
|
490 | 490 | } |
491 | 491 | foreach (array_reverse($id) as $link) |
492 | 492 | { |
@@ -503,7 +503,7 @@ discard block |
||
503 | 503 | if (empty($only_app) || $only_app == self::VFS_APPNAME || |
504 | 504 | ($only_app[0] == '!' && $only_app != '!'.self::VFS_APPNAME)) |
505 | 505 | { |
506 | - if (($vfs_ids = self::list_attached($app,$id))) |
|
506 | + if (($vfs_ids = self::list_attached($app, $id))) |
|
507 | 507 | { |
508 | 508 | $ids += $vfs_ids; |
509 | 509 | } |
@@ -513,18 +513,18 @@ discard block |
||
513 | 513 | { |
514 | 514 | // agregate links by app |
515 | 515 | $app_ids = array(); |
516 | - foreach($ids as $link) |
|
516 | + foreach ($ids as $link) |
|
517 | 517 | { |
518 | 518 | $app_ids[$link['app']][] = $link['id']; |
519 | 519 | } |
520 | - foreach($app_ids as $appname => $a_ids) |
|
520 | + foreach ($app_ids as $appname => $a_ids) |
|
521 | 521 | { |
522 | - self::titles($appname,array_unique($a_ids)); |
|
522 | + self::titles($appname, array_unique($a_ids)); |
|
523 | 523 | } |
524 | 524 | // remove links, current user has no access, from result |
525 | - foreach($ids as $key => $link) |
|
525 | + foreach ($ids as $key => $link) |
|
526 | 526 | { |
527 | - if (!self::title($link['app'],$link['id'])) |
|
527 | + if (!self::title($link['app'], $link['id'])) |
|
528 | 528 | { |
529 | 529 | unset($ids[$key]); |
530 | 530 | } |
@@ -546,27 +546,27 @@ discard block |
||
546 | 546 | * @param boolean $deleted =false Include links that have been flagged as deleted, waiting for purge of linked record. |
547 | 547 | * @return array of $id => array($links) pairs |
548 | 548 | */ |
549 | - static function get_links_multiple($app,array $ids,$cache_titles=true,$only_app='',$order='link_lastmod DESC', $deleted=false ) |
|
549 | + static function get_links_multiple($app, array $ids, $cache_titles = true, $only_app = '', $order = 'link_lastmod DESC', $deleted = false) |
|
550 | 550 | { |
551 | - if (self::DEBUG) echo "<p>".__METHOD__."('$app',".print_r($ids,true).",$cache_titles,'$only_app','$order')</p>\n"; |
|
551 | + if (self::DEBUG) echo "<p>".__METHOD__."('$app',".print_r($ids, true).",$cache_titles,'$only_app','$order')</p>\n"; |
|
552 | 552 | |
553 | 553 | if (!$ids) |
554 | 554 | { |
555 | - return array(); // no ids are linked to nothing |
|
555 | + return array(); // no ids are linked to nothing |
|
556 | 556 | } |
557 | - $links = Link\Storage::get_links($app,$ids,$only_app,$order,$deleted); |
|
557 | + $links = Link\Storage::get_links($app, $ids, $only_app, $order, $deleted); |
|
558 | 558 | |
559 | 559 | if (empty($only_app) || $only_app == self::VFS_APPNAME || |
560 | 560 | ($only_app[0] == '!' && $only_app != '!'.self::VFS_APPNAME)) |
561 | 561 | { |
562 | 562 | // todo do that in a single query, eg. directory listing, too |
563 | - foreach($ids as $id) |
|
563 | + foreach ($ids as $id) |
|
564 | 564 | { |
565 | 565 | if (!isset($links[$id])) |
566 | 566 | { |
567 | 567 | $links[$id] = array(); |
568 | 568 | } |
569 | - if (($vfs_ids = self::list_attached($app,$id))) |
|
569 | + if (($vfs_ids = self::list_attached($app, $id))) |
|
570 | 570 | { |
571 | 571 | $links[$id] += $vfs_ids; |
572 | 572 | } |
@@ -576,16 +576,16 @@ discard block |
||
576 | 576 | { |
577 | 577 | // agregate links by app |
578 | 578 | $app_ids = array(); |
579 | - foreach($links as &$targets) |
|
579 | + foreach ($links as &$targets) |
|
580 | 580 | { |
581 | - foreach($targets as $link) |
|
581 | + foreach ($targets as $link) |
|
582 | 582 | { |
583 | 583 | if (is_array($link)) $app_ids[$link['app']][] = $link['id']; |
584 | 584 | } |
585 | 585 | } |
586 | - foreach($app_ids as $app => $a_ids) |
|
586 | + foreach ($app_ids as $app => $a_ids) |
|
587 | 587 | { |
588 | - self::titles($app,array_unique($a_ids)); |
|
588 | + self::titles($app, array_unique($a_ids)); |
|
589 | 589 | } |
590 | 590 | } |
591 | 591 | return $links; |
@@ -602,7 +602,7 @@ discard block |
||
602 | 602 | * @param string $id2 ='' id in $app2 |
603 | 603 | * @return array with link-data or False |
604 | 604 | */ |
605 | - static function get_link($app_link_id,$id='',$app2='',$id2='') |
|
605 | + static function get_link($app_link_id, $id = '', $app2 = '', $id2 = '') |
|
606 | 606 | { |
607 | 607 | if (self::DEBUG) |
608 | 608 | { |
@@ -610,7 +610,7 @@ discard block |
||
610 | 610 | } |
611 | 611 | if (is_array($id)) |
612 | 612 | { |
613 | - if (strpos($app_link_id,':') === false) $app_link_id = self::temp_link_id($app2,$id2); // create link_id of temporary link, if not given |
|
613 | + if (strpos($app_link_id, ':') === false) $app_link_id = self::temp_link_id($app2, $id2); // create link_id of temporary link, if not given |
|
614 | 614 | |
615 | 615 | if (isset($id[$app_link_id]) && is_array($id[$app_link_id])) // check for unlinked-marker |
616 | 616 | { |
@@ -626,11 +626,11 @@ discard block |
||
626 | 626 | } |
627 | 627 | if ($app_link_id == self::VFS_APPNAME) |
628 | 628 | { |
629 | - return self::info_attached($app2,$id2,$id); |
|
629 | + return self::info_attached($app2, $id2, $id); |
|
630 | 630 | } |
631 | - return self::info_attached($app_link_id,$id,$id2); |
|
631 | + return self::info_attached($app_link_id, $id, $id2); |
|
632 | 632 | } |
633 | - return Link\Storage::get_link($app_link_id,$id,$app2,$id2); |
|
633 | + return Link\Storage::get_link($app_link_id, $id, $app2, $id2); |
|
634 | 634 | } |
635 | 635 | |
636 | 636 | /** |
@@ -648,9 +648,9 @@ discard block |
||
648 | 648 | * @param boolean $hold_for_purge Don't really delete the link, just mark it as deleted and wait for final delete |
649 | 649 | * @return the number of links deleted |
650 | 650 | */ |
651 | - static function unlink($link_id,$app='',$id='',$owner=0,$app2='',$id2='',$hold_for_purge=false) |
|
651 | + static function unlink($link_id, $app = '', $id = '', $owner = 0, $app2 = '', $id2 = '', $hold_for_purge = false) |
|
652 | 652 | { |
653 | - return self::unlink2($link_id,$app,$id,$owner,$app2,$id2,$hold_for_purge); |
|
653 | + return self::unlink2($link_id, $app, $id, $owner, $app2, $id2, $hold_for_purge); |
|
654 | 654 | } |
655 | 655 | |
656 | 656 | /** |
@@ -665,7 +665,7 @@ discard block |
||
665 | 665 | * @param boolean $hold_for_purge Don't really delete the link, just mark it as deleted and wait for final delete |
666 | 666 | * @return the number of links deleted |
667 | 667 | */ |
668 | - static function unlink2($link_id,$app,&$id,$owner=0,$app2='',$id2='',$hold_for_purge=false) |
|
668 | + static function unlink2($link_id, $app, &$id, $owner = 0, $app2 = '', $id2 = '', $hold_for_purge = false) |
|
669 | 669 | { |
670 | 670 | if (self::DEBUG) |
671 | 671 | { |
@@ -677,22 +677,22 @@ discard block |
||
677 | 677 | } |
678 | 678 | elseif ($app == self::VFS_APPNAME) |
679 | 679 | { |
680 | - return self::delete_attached($app2,$id2,$id); |
|
680 | + return self::delete_attached($app2, $id2, $id); |
|
681 | 681 | } |
682 | 682 | elseif ($app2 == self::VFS_APPNAME) |
683 | 683 | { |
684 | - return self::delete_attached($app,$id,$id2); |
|
684 | + return self::delete_attached($app, $id, $id2); |
|
685 | 685 | } |
686 | 686 | if (!is_array($id)) |
687 | 687 | { |
688 | 688 | if (!$link_id && !$app2 && !$id2 && $app2 != '!'.self::VFS_APPNAME) |
689 | 689 | { |
690 | - self::delete_attached($app,$id); // deleting all attachments |
|
691 | - self::delete_cache($app,$id); |
|
690 | + self::delete_attached($app, $id); // deleting all attachments |
|
691 | + self::delete_cache($app, $id); |
|
692 | 692 | } |
693 | 693 | |
694 | 694 | // Log in history |
695 | - if($link_id && (!$app || !$app2)) |
|
695 | + if ($link_id && (!$app || !$app2)) |
|
696 | 696 | { |
697 | 697 | // Need to load it first |
698 | 698 | $link = self::get_link($link_id); |
@@ -703,21 +703,21 @@ discard block |
||
703 | 703 | } |
704 | 704 | if ($app && $app2) |
705 | 705 | { |
706 | - Storage\History::static_add($app,$id,$GLOBALS['egw_info']['user']['account_id'],'~link~','',$app2.':'.$id2); |
|
707 | - Storage\History::static_add($app2,$id2,$GLOBALS['egw_info']['user']['account_id'],'~link~','',$app.':'.$id); |
|
706 | + Storage\History::static_add($app, $id, $GLOBALS['egw_info']['user']['account_id'], '~link~', '', $app2.':'.$id2); |
|
707 | + Storage\History::static_add($app2, $id2, $GLOBALS['egw_info']['user']['account_id'], '~link~', '', $app.':'.$id); |
|
708 | 708 | } |
709 | - $deleted = Link\Storage::unlink($link_id,$app,$id,$owner,$app2 != '!'.self::VFS_APPNAME ? $app2 : '',$id2,$hold_for_purge); |
|
709 | + $deleted = Link\Storage::unlink($link_id, $app, $id, $owner, $app2 != '!'.self::VFS_APPNAME ? $app2 : '', $id2, $hold_for_purge); |
|
710 | 710 | |
711 | 711 | // only notify on real links, not the one cached for writing or fileattachments |
712 | 712 | self::notify_unlink($deleted); |
713 | 713 | |
714 | 714 | return count($deleted); |
715 | 715 | } |
716 | - if (!$link_id) $link_id = self::temp_link_id($app2,$id2); // create link_id of temporary link, if not given |
|
716 | + if (!$link_id) $link_id = self::temp_link_id($app2, $id2); // create link_id of temporary link, if not given |
|
717 | 717 | |
718 | 718 | if (isset($id[$link_id])) |
719 | 719 | { |
720 | - $id[$link_id] = False; // set the unlink marker |
|
720 | + $id[$link_id] = False; // set the unlink marker |
|
721 | 721 | |
722 | 722 | if (self::DEBUG) |
723 | 723 | { |
@@ -734,10 +734,10 @@ discard block |
||
734 | 734 | * @param string $must_support capability the apps need to support, eg. 'add', default ''=list all apps |
735 | 735 | * @return array with app => title pairs |
736 | 736 | */ |
737 | - static function app_list($must_support='') |
|
737 | + static function app_list($must_support = '') |
|
738 | 738 | { |
739 | 739 | $apps = array(); |
740 | - foreach(self::$app_register as $type => $reg) |
|
740 | + foreach (self::$app_register as $type => $reg) |
|
741 | 741 | { |
742 | 742 | if ($must_support && !isset($reg[$must_support])) continue; |
743 | 743 | |
@@ -794,11 +794,11 @@ discard block |
||
794 | 794 | * @param array $link =null link-data for file-attachments |
795 | 795 | * @return string/boolean string with title, null if $id does not exist in $app or false if no perms to view it |
796 | 796 | */ |
797 | - static function title($app,$id,$link=null) |
|
797 | + static function title($app, $id, $link = null) |
|
798 | 798 | { |
799 | 799 | if (!$id) return ''; |
800 | 800 | |
801 | - $title =& self::get_cache($app,$id); |
|
801 | + $title = & self::get_cache($app, $id); |
|
802 | 802 | if (isset($title) && !empty($title) && !is_array($id)) |
803 | 803 | { |
804 | 804 | if (self::DEBUG) echo '<p>'.__METHOD__."('$app','$id')='$title' (from cache)</p>\n"; |
@@ -840,7 +840,7 @@ discard block |
||
840 | 840 | if (!isset($unlinking[$app]) || !isset($unlinking[$app][$id])) |
841 | 841 | { |
842 | 842 | $unlinking[$app][$id] = true; |
843 | - self::unlink(0,$app,$id); |
|
843 | + self::unlink(0, $app, $id); |
|
844 | 844 | unset($unlinking[$app][$id]); |
845 | 845 | } |
846 | 846 | if (self::DEBUG) echo '<p>'.__METHOD__."('$app','$id') unlinked, as $method returned null</p>\n"; |
@@ -865,36 +865,36 @@ discard block |
||
865 | 865 | * @param string $app |
866 | 866 | * @param array $ids |
867 | 867 | */ |
868 | - static function titles($app,array $ids) |
|
868 | + static function titles($app, array $ids) |
|
869 | 869 | { |
870 | 870 | if (self::DEBUG) |
871 | 871 | { |
872 | - echo "<p>".__METHOD__."($app,".implode(',',$ids).")</p>\n"; |
|
872 | + echo "<p>".__METHOD__."($app,".implode(',', $ids).")</p>\n"; |
|
873 | 873 | } |
874 | 874 | $titles = $ids_to_query = array(); |
875 | - foreach($ids as $id) |
|
875 | + foreach ($ids as $id) |
|
876 | 876 | { |
877 | - $title =& self::get_cache($app,$id); |
|
877 | + $title = & self::get_cache($app, $id); |
|
878 | 878 | if (!isset($title)) |
879 | 879 | { |
880 | 880 | if (isset(self::$app_register[$app]['titles'])) |
881 | 881 | { |
882 | - $ids_to_query[] = $id; // titles method --> collect links to query at once |
|
882 | + $ids_to_query[] = $id; // titles method --> collect links to query at once |
|
883 | 883 | } |
884 | 884 | else |
885 | 885 | { |
886 | - $title = self::title($app,$id); // no titles method --> fallback to query each link separate |
|
886 | + $title = self::title($app, $id); // no titles method --> fallback to query each link separate |
|
887 | 887 | } |
888 | 888 | } |
889 | 889 | $titles[$id] = $title; |
890 | 890 | } |
891 | 891 | if ($ids_to_query) |
892 | 892 | { |
893 | - for ($n = 0; ($ids = array_slice($ids_to_query,$n*self::MAX_TITLES_QUERY,self::MAX_TITLES_QUERY)); ++$n) |
|
893 | + for ($n = 0; ($ids = array_slice($ids_to_query, $n * self::MAX_TITLES_QUERY, self::MAX_TITLES_QUERY)); ++$n) |
|
894 | 894 | { |
895 | - foreach(self::exec(self::$app_register[$app]['titles'], array($ids)) as $id => $t) |
|
895 | + foreach (self::exec(self::$app_register[$app]['titles'], array($ids)) as $id => $t) |
|
896 | 896 | { |
897 | - $title =& self::get_cache($app,$id); |
|
897 | + $title = & self::get_cache($app, $id); |
|
898 | 898 | $titles[$id] = $title = $t; |
899 | 899 | } |
900 | 900 | } |
@@ -910,7 +910,7 @@ discard block |
||
910 | 910 | * @param string $to_id =''id in $to_app |
911 | 911 | * @return array/boolean with name-value pairs for link to add-methode of $app or false if add not supported |
912 | 912 | */ |
913 | - static function add($app,$to_app='',$to_id='') |
|
913 | + static function add($app, $to_app = '', $to_id = '') |
|
914 | 914 | { |
915 | 915 | //echo "<p>Link::add('$app','$to_app','$to_id') app_register[$app] ="; _debug_array($app_register[$app]); |
916 | 916 | if ($app == '' || !is_array($reg = self::$app_register[$app]) || !isset($reg['add'])) |
@@ -935,7 +935,7 @@ discard block |
||
935 | 935 | * @param string &$popup=null on return popup size eg. '600x400' or null |
936 | 936 | * @return array|boolean with name-value pairs for link to edit-methode of $app or false if edit not supported |
937 | 937 | */ |
938 | - static function edit($app,$id,&$popup=null) |
|
938 | + static function edit($app, $id, &$popup = null) |
|
939 | 939 | { |
940 | 940 | //echo "<p>Link::add('$app','$to_app','$to_id') app_register[$app] ="; _debug_array($app_register[$app]); |
941 | 941 | if (empty($app) || empty($id) || !is_array($reg = self::$app_register[$app]) || !isset($reg['edit'])) |
@@ -943,7 +943,7 @@ discard block |
||
943 | 943 | if ($reg && isset($reg['view'])) |
944 | 944 | { |
945 | 945 | $popup = $reg['view_popup']; |
946 | - return self::view($app,$id); // fallback to view |
|
946 | + return self::view($app, $id); // fallback to view |
|
947 | 947 | } |
948 | 948 | return false; |
949 | 949 | } |
@@ -963,12 +963,12 @@ discard block |
||
963 | 963 | * @param array $link =null link-data for file-attachments |
964 | 964 | * @return array with name-value pairs for link to view-methode of $app to view $id |
965 | 965 | */ |
966 | - static function view($app,$id,$link=null) |
|
966 | + static function view($app, $id, $link = null) |
|
967 | 967 | { |
968 | 968 | if ($app == self::VFS_APPNAME && !empty($id) && is_array($link)) |
969 | 969 | { |
970 | 970 | //return Vfs::download_url(self::vfs_path($link['app2'],$link['id2'],$link['id'],true)); |
971 | - return self::mime_open(self::vfs_path($link['app2'],$link['id2'],$link['id'],true), $link['type']); |
|
971 | + return self::mime_open(self::vfs_path($link['app2'], $link['id2'], $link['id'], true), $link['type']); |
|
972 | 972 | } |
973 | 973 | if ($app == '' || !is_array($reg = self::$app_register[$app]) || !isset($reg['view']) || !isset($reg['view_id'])) |
974 | 974 | { |
@@ -976,11 +976,11 @@ discard block |
||
976 | 976 | } |
977 | 977 | $view = $reg['view']; |
978 | 978 | |
979 | - $names = explode(':',$reg['view_id']); |
|
979 | + $names = explode(':', $reg['view_id']); |
|
980 | 980 | if (count($names) > 1) |
981 | 981 | { |
982 | - $id = explode(':',$id); |
|
983 | - while (list($n,$name) = each($names)) |
|
982 | + $id = explode(':', $id); |
|
983 | + while (list($n, $name) = each($names)) |
|
984 | 984 | { |
985 | 985 | $view[$name] = $id[$n]; |
986 | 986 | } |
@@ -1004,13 +1004,13 @@ discard block |
||
1004 | 1004 | */ |
1005 | 1005 | static function get_mime_info($type) |
1006 | 1006 | { |
1007 | - foreach(self::$app_register as $app => $registry) |
|
1007 | + foreach (self::$app_register as $app => $registry) |
|
1008 | 1008 | { |
1009 | 1009 | if (isset($registry['mime']) && |
1010 | 1010 | (isset($GLOBALS['egw_info']['user']['apps'][$app]) || |
1011 | 1011 | isset($registry['app']) && isset($GLOBALS['egw_info']['user']['apps'][$registry['app']]))) |
1012 | 1012 | { |
1013 | - foreach($registry['mime'] as $mime => $data) |
|
1013 | + foreach ($registry['mime'] as $mime => $data) |
|
1014 | 1014 | { |
1015 | 1015 | if ($mime == $type) return $data; |
1016 | 1016 | if ($mime[0] == '/' && preg_match($mime.'i', $type)) |
@@ -1031,7 +1031,7 @@ discard block |
||
1031 | 1031 | * @param string &$popup=null on return popup size or null |
1032 | 1032 | * @return string|array string with EGw relative link, array with get-parameters for '/index.php' or null (directory and not filemanager access) |
1033 | 1033 | */ |
1034 | - static function mime_open($path, $type=null, &$popup=null) |
|
1034 | + static function mime_open($path, $type = null, &$popup = null) |
|
1035 | 1035 | { |
1036 | 1036 | if (is_null($type)) $type = Vfs::mime_content_type($path); |
1037 | 1037 | |
@@ -1047,7 +1047,7 @@ discard block |
||
1047 | 1047 | $data[$data['mime_id']] = $path; |
1048 | 1048 | unset($data['mime_id']); |
1049 | 1049 | } |
1050 | - elseif(isset($data['mime_popup'])) |
|
1050 | + elseif (isset($data['mime_popup'])) |
|
1051 | 1051 | { |
1052 | 1052 | $popup = $data['mime_popup']; |
1053 | 1053 | } |
@@ -1072,9 +1072,9 @@ discard block |
||
1072 | 1072 | * @param array $link =null link-data for file-attachments |
1073 | 1073 | * @return boolean|string false if no popup is used or $app is not registered, otherwise string with the prefered popup size (eg. '640x400) |
1074 | 1074 | */ |
1075 | - static function is_popup($app, $action='view', $link=null) |
|
1075 | + static function is_popup($app, $action = 'view', $link = null) |
|
1076 | 1076 | { |
1077 | - $popup = self::get_registry($app,$action.'_popup'); |
|
1077 | + $popup = self::get_registry($app, $action.'_popup'); |
|
1078 | 1078 | |
1079 | 1079 | // for files/attachments check mime-registry |
1080 | 1080 | if ($app == self::VFS_APPNAME && is_array($link) && !empty($link['type'])) |
@@ -1097,7 +1097,7 @@ discard block |
||
1097 | 1097 | * @param string $name name / key in the registry, eg. 'view' |
1098 | 1098 | * @return boolean|string false if $app is not registered, otherwise string with the value for $name |
1099 | 1099 | */ |
1100 | - static function get_registry($app,$name) |
|
1100 | + static function get_registry($app, $name) |
|
1101 | 1101 | { |
1102 | 1102 | $reg = self::$app_register[$app]; |
1103 | 1103 | |
@@ -1105,7 +1105,7 @@ discard block |
||
1105 | 1105 | |
1106 | 1106 | if (!isset($reg[$name])) // some defaults |
1107 | 1107 | { |
1108 | - switch($name) |
|
1108 | + switch ($name) |
|
1109 | 1109 | { |
1110 | 1110 | case 'name': |
1111 | 1111 | $reg[$name] = $app; |
@@ -1141,16 +1141,16 @@ discard block |
||
1141 | 1141 | * @param boolean $just_the_path =false return url or just the vfs path |
1142 | 1142 | * @return string/array path or array with path and relatives, depending on $relatives |
1143 | 1143 | */ |
1144 | - static function vfs_path($app,$id='',$file='',$just_the_path=false) |
|
1144 | + static function vfs_path($app, $id = '', $file = '', $just_the_path = false) |
|
1145 | 1145 | { |
1146 | 1146 | $path = self::VFS_BASEURL; |
1147 | 1147 | |
1148 | 1148 | if ($app) |
1149 | 1149 | { |
1150 | - if( isset(self::$app_register[$app]) ) { |
|
1150 | + if (isset(self::$app_register[$app])) { |
|
1151 | 1151 | $reg = self::$app_register[$app]; |
1152 | 1152 | |
1153 | - if( isset($reg['file_dir']) ) { |
|
1153 | + if (isset($reg['file_dir'])) { |
|
1154 | 1154 | $app = $reg['file_dir']; |
1155 | 1155 | } |
1156 | 1156 | } |
@@ -1169,7 +1169,7 @@ discard block |
||
1169 | 1169 | } |
1170 | 1170 | if ($just_the_path) |
1171 | 1171 | { |
1172 | - $path = parse_url($path,PHP_URL_PATH); |
|
1172 | + $path = parse_url($path, PHP_URL_PATH); |
|
1173 | 1173 | } |
1174 | 1174 | else |
1175 | 1175 | { |
@@ -1193,7 +1193,7 @@ discard block |
||
1193 | 1193 | * @param string $comment ='' comment to add to the link |
1194 | 1194 | * @return int negative id of egw_sqlfs table as negative link-id's are for vfs attachments |
1195 | 1195 | */ |
1196 | - static function attach_file($app,$id,$file,$comment='') |
|
1196 | + static function attach_file($app, $id, $file, $comment = '') |
|
1197 | 1197 | { |
1198 | 1198 | // check if $file['name'] specifies a subdirectory, in which case use and, if necessary, create it |
1199 | 1199 | if (is_array($file) && strpos($file['name'], '/') && strpos($file['name'], '..') === false) |
@@ -1203,15 +1203,15 @@ discard block |
||
1203 | 1203 | } |
1204 | 1204 | else |
1205 | 1205 | { |
1206 | - $entry_dir = self::vfs_path($app,$id); |
|
1206 | + $entry_dir = self::vfs_path($app, $id); |
|
1207 | 1207 | } |
1208 | 1208 | if (self::DEBUG) |
1209 | 1209 | { |
1210 | 1210 | echo "<p>attach_file: app='$app', id='$id', tmp_name='$file[tmp_name]', name='$file[name]', size='$file[size]', type='$file[type]', path='$file[path]', ip='$file[ip]', comment='$comment', entry_dir='$entry_dir'</p>\n"; |
1211 | 1211 | } |
1212 | - if (file_exists($entry_dir) || ($Ok = mkdir($entry_dir,0,true))) |
|
1212 | + if (file_exists($entry_dir) || ($Ok = mkdir($entry_dir, 0, true))) |
|
1213 | 1213 | { |
1214 | - $Ok = Vfs::copy_uploaded($file, $p=Vfs::parse_url($entry_dir, PHP_URL_PATH), $comment, false); // no is_uploaded_file() check! |
|
1214 | + $Ok = Vfs::copy_uploaded($file, $p = Vfs::parse_url($entry_dir, PHP_URL_PATH), $comment, false); // no is_uploaded_file() check! |
|
1215 | 1215 | if (!$Ok) error_log(__METHOD__."('$app', '$id', ".array2string($file).", '$comment') called Vfs::copy_uploaded('$file[tmp_name]', '$p', '$comment', false)=".array2string($Ok)); |
1216 | 1216 | } |
1217 | 1217 | else |
@@ -1229,14 +1229,14 @@ discard block |
||
1229 | 1229 | * @param string $file VFS path to link to |
1230 | 1230 | * @return boolean true on success, false on failure |
1231 | 1231 | */ |
1232 | - static function link_file($app,$id,$file) |
|
1232 | + static function link_file($app, $id, $file) |
|
1233 | 1233 | { |
1234 | 1234 | // Don't try to link into app dir if there is no id |
1235 | - if(!$id) return; |
|
1235 | + if (!$id) return; |
|
1236 | 1236 | |
1237 | 1237 | if (!Vfs::stat($file)) |
1238 | 1238 | { |
1239 | - error_log(__METHOD__. ' (Link target ' . Vfs::decodePath($file) . ' not found!'); |
|
1239 | + error_log(__METHOD__.' (Link target '.Vfs::decodePath($file).' not found!'); |
|
1240 | 1240 | return false; |
1241 | 1241 | } |
1242 | 1242 | |
@@ -1257,7 +1257,7 @@ discard block |
||
1257 | 1257 | * @param string $fname ='' filename |
1258 | 1258 | * @return boolean|array false on error ($app or $id not found), array with path as key and boolean result of delete |
1259 | 1259 | */ |
1260 | - static function delete_attached($app,$id='',$fname='') |
|
1260 | + static function delete_attached($app, $id = '', $fname = '') |
|
1261 | 1261 | { |
1262 | 1262 | if ((int)$app > 0) // is file_id |
1263 | 1263 | { |
@@ -1267,9 +1267,9 @@ discard block |
||
1267 | 1267 | { |
1268 | 1268 | if (empty($app) || empty($id)) |
1269 | 1269 | { |
1270 | - return False; // dont delete more than all attachments of an entry |
|
1270 | + return False; // dont delete more than all attachments of an entry |
|
1271 | 1271 | } |
1272 | - $url = self::vfs_path($app,$id,$fname); |
|
1272 | + $url = self::vfs_path($app, $id, $fname); |
|
1273 | 1273 | |
1274 | 1274 | if (!$fname || !$id) // we delete the whole entry (or all entries), which probably not exist anymore |
1275 | 1275 | { |
@@ -1282,15 +1282,15 @@ discard block |
||
1282 | 1282 | echo '<p>'.__METHOD__."('$app','$id','$fname') url=$url</p>\n"; |
1283 | 1283 | } |
1284 | 1284 | // Log in history - Need to load it first |
1285 | - if((int)$app > 0) |
|
1285 | + if ((int)$app > 0) |
|
1286 | 1286 | { |
1287 | 1287 | $link = self::get_link(-$app); |
1288 | - if($link['app2'] && $link['id2']) |
|
1288 | + if ($link['app2'] && $link['id2']) |
|
1289 | 1289 | { |
1290 | - Storage\History::static_add($link['app2'],$link['id2'],$GLOBALS['egw_info']['user']['account_id'],'~file~','', Vfs::basename($url)); |
|
1290 | + Storage\History::static_add($link['app2'], $link['id2'], $GLOBALS['egw_info']['user']['account_id'], '~file~', '', Vfs::basename($url)); |
|
1291 | 1291 | } |
1292 | 1292 | } |
1293 | - if (($Ok = !file_exists($url) || Vfs::remove($url,true)) && ((int)$app > 0 || $fname)) |
|
1293 | + if (($Ok = !file_exists($url) || Vfs::remove($url, true)) && ((int)$app > 0 || $fname)) |
|
1294 | 1294 | { |
1295 | 1295 | // try removing the dir, in case it's empty |
1296 | 1296 | if (($dir = Vfs::dirname($url))) @Vfs::rmdir($dir); |
@@ -1310,14 +1310,14 @@ discard block |
||
1310 | 1310 | * @param string $filename filename |
1311 | 1311 | * @return array 'kind' of link-array |
1312 | 1312 | */ |
1313 | - static function info_attached($app,$id,$filename) |
|
1313 | + static function info_attached($app, $id, $filename) |
|
1314 | 1314 | { |
1315 | - $path = self::vfs_path($app,$id,$filename,true); |
|
1316 | - if (!($stat = Vfs::stat($path,STREAM_URL_STAT_QUIET))) |
|
1315 | + $path = self::vfs_path($app, $id, $filename, true); |
|
1316 | + if (!($stat = Vfs::stat($path, STREAM_URL_STAT_QUIET))) |
|
1317 | 1317 | { |
1318 | 1318 | return false; |
1319 | 1319 | } |
1320 | - return self::fileinfo2link($stat,$path); |
|
1320 | + return self::fileinfo2link($stat, $path); |
|
1321 | 1321 | } |
1322 | 1322 | |
1323 | 1323 | /** |
@@ -1326,36 +1326,36 @@ discard block |
||
1326 | 1326 | * @param array|int $fileinfo a row from the vfs-db-table (eg. returned by the vfs ls static function) or a file_id of that table |
1327 | 1327 | * @return array a 'kind' of link-array |
1328 | 1328 | */ |
1329 | - static function fileinfo2link($fileinfo,$url=null) |
|
1329 | + static function fileinfo2link($fileinfo, $url = null) |
|
1330 | 1330 | { |
1331 | 1331 | if (!is_array($fileinfo)) |
1332 | 1332 | { |
1333 | 1333 | $url = Vfs\Sqlfs\StreamWrapper::id2path($fileinfo); |
1334 | - if (!($fileinfo = Vfs::stat($url,STREAM_URL_STAT_QUIET))) |
|
1334 | + if (!($fileinfo = Vfs::stat($url, STREAM_URL_STAT_QUIET))) |
|
1335 | 1335 | { |
1336 | 1336 | return false; |
1337 | 1337 | } |
1338 | 1338 | } |
1339 | 1339 | |
1340 | - $up = explode('/',$url[0] == '/' ? $url : parse_url($url,PHP_URL_PATH)); // /apps/$app/$id |
|
1340 | + $up = explode('/', $url[0] == '/' ? $url : parse_url($url, PHP_URL_PATH)); // /apps/$app/$id |
|
1341 | 1341 | $app = null; |
1342 | 1342 | |
1343 | - foreach( self::$app_register as $tapp => $reg ) { |
|
1344 | - if( isset($reg['file_dir']) ) { |
|
1343 | + foreach (self::$app_register as $tapp => $reg) { |
|
1344 | + if (isset($reg['file_dir'])) { |
|
1345 | 1345 | $lup = $up; |
1346 | 1346 | |
1347 | 1347 | unset($lup[0]); |
1348 | 1348 | unset($lup[1]); |
1349 | 1349 | reset($lup); |
1350 | 1350 | |
1351 | - $fdp = explode('/',$reg['file_dir'][0] == '/' ? |
|
1352 | - $reg['file_dir'] : parse_url($reg['file_dir'],PHP_URL_PATH)); |
|
1351 | + $fdp = explode('/', $reg['file_dir'][0] == '/' ? |
|
1352 | + $reg['file_dir'] : parse_url($reg['file_dir'], PHP_URL_PATH)); |
|
1353 | 1353 | |
1354 | 1354 | $found = true; |
1355 | 1355 | |
1356 | - foreach( $fdp as $part ) { |
|
1357 | - if( current($lup) == $part ) { |
|
1358 | - if( next($lup) === false ) { |
|
1356 | + foreach ($fdp as $part) { |
|
1357 | + if (current($lup) == $part) { |
|
1358 | + if (next($lup) === false) { |
|
1359 | 1359 | $found = false; |
1360 | 1360 | break; |
1361 | 1361 | } |
@@ -1366,16 +1366,16 @@ discard block |
||
1366 | 1366 | } |
1367 | 1367 | } |
1368 | 1368 | |
1369 | - if( $found ) { |
|
1370 | - $id = current($lup); |
|
1369 | + if ($found) { |
|
1370 | + $id = current($lup); |
|
1371 | 1371 | $app = $tapp; |
1372 | 1372 | break; |
1373 | 1373 | } |
1374 | 1374 | } |
1375 | 1375 | } |
1376 | 1376 | |
1377 | - if( $app === null ) { |
|
1378 | - list(,,$app,$id) = $up; |
|
1377 | + if ($app === null) { |
|
1378 | + list(,, $app, $id) = $up; |
|
1379 | 1379 | } |
1380 | 1380 | |
1381 | 1381 | return array( |
@@ -1383,7 +1383,7 @@ discard block |
||
1383 | 1383 | 'id' => $fileinfo['name'], |
1384 | 1384 | 'app2' => $app, |
1385 | 1385 | 'id2' => $id, |
1386 | - 'remark' => '', // only list_attached currently sets the remark |
|
1386 | + 'remark' => '', // only list_attached currently sets the remark |
|
1387 | 1387 | 'owner' => $fileinfo['uid'], |
1388 | 1388 | 'link_id' => -$fileinfo['ino'], |
1389 | 1389 | 'lastmod' => $fileinfo['mtime'], |
@@ -1399,26 +1399,26 @@ discard block |
||
1399 | 1399 | * @param string $id id in app |
1400 | 1400 | * @return array with link_id => 'kind' of link-array pairs |
1401 | 1401 | */ |
1402 | - static function list_attached($app,$id) |
|
1402 | + static function list_attached($app, $id) |
|
1403 | 1403 | { |
1404 | - $path = self::vfs_path($app,$id); |
|
1404 | + $path = self::vfs_path($app, $id); |
|
1405 | 1405 | //error_log(__METHOD__."($app,$id) url=$url"); |
1406 | 1406 | |
1407 | - if (!($extra = self::get_registry($app,'find_extra'))) $extra = array(); |
|
1407 | + if (!($extra = self::get_registry($app, 'find_extra'))) $extra = array(); |
|
1408 | 1408 | |
1409 | 1409 | // always use regular links stream wrapper here: extended one is unnecessary (slow) for just listing attachments |
1410 | - if (substr($path,0,13) == 'stylite.links') $path = substr($path,8); |
|
1410 | + if (substr($path, 0, 13) == 'stylite.links') $path = substr($path, 8); |
|
1411 | 1411 | |
1412 | 1412 | $attached = array(); |
1413 | - if (($url2stats = Vfs::find($path,array('need_mime'=>true,'type'=>'F','url'=>true)+$extra,true))) |
|
1413 | + if (($url2stats = Vfs::find($path, array('need_mime'=>true, 'type'=>'F', 'url'=>true) + $extra, true))) |
|
1414 | 1414 | { |
1415 | - $props = Vfs::propfind(array_keys($url2stats)); // get the comments |
|
1416 | - foreach($url2stats as $url => &$fileinfo) |
|
1415 | + $props = Vfs::propfind(array_keys($url2stats)); // get the comments |
|
1416 | + foreach ($url2stats as $url => &$fileinfo) |
|
1417 | 1417 | { |
1418 | - $link = self::fileinfo2link($fileinfo,$url); |
|
1418 | + $link = self::fileinfo2link($fileinfo, $url); |
|
1419 | 1419 | if ($props && isset($props[$url])) |
1420 | 1420 | { |
1421 | - foreach($props[$url] as $prop) |
|
1421 | + foreach ($props[$url] as $prop) |
|
1422 | 1422 | { |
1423 | 1423 | if ($prop['ns'] == Vfs::DEFAULT_PROP_NAMESPACE && $prop['name'] == 'comment') |
1424 | 1424 | { |
@@ -1440,7 +1440,7 @@ discard block |
||
1440 | 1440 | */ |
1441 | 1441 | static private function decode_htmlspecialchars($str) |
1442 | 1442 | { |
1443 | - return str_replace(array('&','"','<','>'),array('&','"','<','>'),$str); |
|
1443 | + return str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), $str); |
|
1444 | 1444 | } |
1445 | 1445 | |
1446 | 1446 | /** |
@@ -1458,18 +1458,18 @@ discard block |
||
1458 | 1458 | * @param string $id id in $app of the updated entry |
1459 | 1459 | * @param array $data =null updated data of changed entry, as the read-method of the BO-layer would supply it |
1460 | 1460 | */ |
1461 | - static function notify_update($app,$id,$data=null) |
|
1461 | + static function notify_update($app, $id, $data = null) |
|
1462 | 1462 | { |
1463 | - self::delete_cache($app,$id); |
|
1463 | + self::delete_cache($app, $id); |
|
1464 | 1464 | //error_log(__METHOD__."('$app', $id, $data)"); |
1465 | - foreach(self::get_links($app,$id,'!'.self::VFS_APPNAME) as $link_id => $link) |
|
1465 | + foreach (self::get_links($app, $id, '!'.self::VFS_APPNAME) as $link_id => $link) |
|
1466 | 1466 | { |
1467 | - self::notify('update',$link['app'],$link['id'],$app,$id,$link_id,$data); |
|
1467 | + self::notify('update', $link['app'], $link['id'], $app, $id, $link_id, $data); |
|
1468 | 1468 | } |
1469 | - if($data[Link::OLD_LINK_TITLE] && Json\Response::isJSONResponse()) |
|
1469 | + if ($data[Link::OLD_LINK_TITLE] && Json\Response::isJSONResponse()) |
|
1470 | 1470 | { |
1471 | 1471 | // Update client side with new title |
1472 | - Json\Response::get()->apply('egw.link_title_callback',array(array($app => array($id => self::title($app, $id))))); |
|
1472 | + Json\Response::get()->apply('egw.link_title_callback', array(array($app => array($id => self::title($app, $id))))); |
|
1473 | 1473 | } |
1474 | 1474 | } |
1475 | 1475 | |
@@ -1493,7 +1493,7 @@ discard block |
||
1493 | 1493 | * @param string $target_id id in $target_app |
1494 | 1494 | * @param array $data =null data of entry in app2 (optional) |
1495 | 1495 | */ |
1496 | - static private function notify($type,$notify_app,$notify_id,$target_app,$target_id,$link_id,$data=null) |
|
1496 | + static private function notify($type, $notify_app, $notify_id, $target_app, $target_id, $link_id, $data = null) |
|
1497 | 1497 | { |
1498 | 1498 | //error_log(__METHOD__."('$type', '$notify_app', $notify_id, '$target_app', $target_id, $link_id, $data)"); |
1499 | 1499 | if ($link_id && isset(self::$app_register[$notify_app]) && isset(self::$app_register[$notify_app]['notify'])) |
@@ -1520,7 +1520,7 @@ discard block |
||
1520 | 1520 | static public function run_notifies() |
1521 | 1521 | { |
1522 | 1522 | //error_log(__METHOD__."() count(self::\$notifies)=".count(self::$notifies)); |
1523 | - while(self::$notifies) |
|
1523 | + while (self::$notifies) |
|
1524 | 1524 | { |
1525 | 1525 | $args = array_shift(self::$notifies); |
1526 | 1526 | $method = $args['method']; |
@@ -1538,11 +1538,11 @@ discard block |
||
1538 | 1538 | */ |
1539 | 1539 | static private function notify_unlink(&$links) |
1540 | 1540 | { |
1541 | - foreach($links as $link) |
|
1541 | + foreach ($links as $link) |
|
1542 | 1542 | { |
1543 | 1543 | // we notify both sides of the link, as the unlink command NOT clearly knows which side initiated the unlink |
1544 | - self::notify('unlink',$link['link_app1'],$link['link_id1'],$link['link_app2'],$link['link_id2'],$link['link_id']); |
|
1545 | - self::notify('unlink',$link['link_app2'],$link['link_id2'],$link['link_app1'],$link['link_id1'],$link['link_id']); |
|
1544 | + self::notify('unlink', $link['link_app1'], $link['link_id1'], $link['link_app2'], $link['link_id2'], $link['link_id']); |
|
1545 | + self::notify('unlink', $link['link_app2'], $link['link_id2'], $link['link_app1'], $link['link_id1'], $link['link_id']); |
|
1546 | 1546 | } |
1547 | 1547 | } |
1548 | 1548 | |
@@ -1554,14 +1554,14 @@ discard block |
||
1554 | 1554 | * @param string $type ='title' 'title' or 'file_access' |
1555 | 1555 | * @return int|string can be null, if cache not yet set |
1556 | 1556 | */ |
1557 | - private static function &get_cache($app,$id,$type = 'title') |
|
1557 | + private static function &get_cache($app, $id, $type = 'title') |
|
1558 | 1558 | { |
1559 | - switch($type) |
|
1559 | + switch ($type) |
|
1560 | 1560 | { |
1561 | 1561 | case 'title': |
1562 | 1562 | if ($app == self::VFS_APPNAME) |
1563 | 1563 | { |
1564 | - return null; // do not cache file titles, they are just the names |
|
1564 | + return null; // do not cache file titles, they are just the names |
|
1565 | 1565 | } |
1566 | 1566 | return self::$title_cache[$app.':'.$id]; |
1567 | 1567 | case 'file_access': |
@@ -1583,7 +1583,7 @@ discard block |
||
1583 | 1583 | * @param string $title title string or null |
1584 | 1584 | * @param int $file_access =null Acl::READ, Acl::EDIT or both or'ed together |
1585 | 1585 | */ |
1586 | - public static function set_cache($app,$id,$title,$file_access=null) |
|
1586 | + public static function set_cache($app, $id, $title, $file_access = null) |
|
1587 | 1587 | { |
1588 | 1588 | //error_log(__METHOD__."($app,$id,$title,$file_access)"); |
1589 | 1589 | // do not cache file titles, they are just the names |
@@ -1603,7 +1603,7 @@ discard block |
||
1603 | 1603 | * @param string $app app-name or null to delete the whole cache |
1604 | 1604 | * @param int|string $id id or null to delete only file_access cache of given app (keeps title cache, if app implements file_access!) |
1605 | 1605 | */ |
1606 | - private static function delete_cache($app,$id) |
|
1606 | + private static function delete_cache($app, $id) |
|
1607 | 1607 | { |
1608 | 1608 | unset(self::$title_cache[$app.':'.$id]); |
1609 | 1609 | unset(self::$file_access_cache[$app.':'.$id]); |
@@ -1618,7 +1618,7 @@ discard block |
||
1618 | 1618 | * @param boolean $ignore_mime =false true: return id, even if nothing registered for given mime-type |
1619 | 1619 | * @return string|null md5 hash of stored data of server-side supported mime-type or null otherwise |
1620 | 1620 | */ |
1621 | - public static function set_data($mime_type, $method, array $params, $ignore_mime=false) |
|
1621 | + public static function set_data($mime_type, $method, array $params, $ignore_mime = false) |
|
1622 | 1622 | { |
1623 | 1623 | if (!$ignore_mime && (!($info = self::get_mime_info($mime_type)) || empty($info['mime_data']))) |
1624 | 1624 | { |
@@ -1639,7 +1639,7 @@ discard block |
||
1639 | 1639 | * @return mixed null if id is not found or invalid |
1640 | 1640 | * @throws Exception\WrongParameter |
1641 | 1641 | */ |
1642 | - public static function get_data($id, $return_resource=false) |
|
1642 | + public static function get_data($id, $return_resource = false) |
|
1643 | 1643 | { |
1644 | 1644 | $data = Cache::getSession(__CLASS__, $id); |
1645 | 1645 | |
@@ -1664,7 +1664,7 @@ discard block |
||
1664 | 1664 | { |
1665 | 1665 | $fp = $ret; |
1666 | 1666 | $ret = ''; |
1667 | - while(!feof($fp)) |
|
1667 | + while (!feof($fp)) |
|
1668 | 1668 | { |
1669 | 1669 | $ret .= fread($fp, 8192); |
1670 | 1670 | } |
@@ -1689,13 +1689,13 @@ discard block |
||
1689 | 1689 | * @param int $user =null default null = current user |
1690 | 1690 | * @return boolean true if access granted, false otherwise |
1691 | 1691 | */ |
1692 | - static function file_access($app,$id,$required=Acl::READ,$rel_path=null,$user=null) |
|
1692 | + static function file_access($app, $id, $required = Acl::READ, $rel_path = null, $user = null) |
|
1693 | 1693 | { |
1694 | 1694 | // are we called for an other user |
1695 | 1695 | if ($user && $user != $GLOBALS['egw_info']['user']['account_id']) |
1696 | 1696 | { |
1697 | 1697 | // check if app supports file_access WITH 4th $user parameter --> return false if not |
1698 | - if (!self::get_registry($app,'file_access_user') || !($method = self::get_registry($app,'file_access'))) |
|
1698 | + if (!self::get_registry($app, 'file_access_user') || !($method = self::get_registry($app, 'file_access'))) |
|
1699 | 1699 | { |
1700 | 1700 | $ret = false; |
1701 | 1701 | $err = "(no file_access_user)"; |
@@ -1709,22 +1709,22 @@ discard block |
||
1709 | 1709 | return $ret; |
1710 | 1710 | } |
1711 | 1711 | |
1712 | - $cache =& self::get_cache($app,$id,'file_access'); |
|
1712 | + $cache = & self::get_cache($app, $id, 'file_access'); |
|
1713 | 1713 | |
1714 | - if (!isset($cache) || $required == Acl::EDIT && !($cache & $required)) |
|
1714 | + if (!isset($cache) || $required == Acl::EDIT && !($cache&$required)) |
|
1715 | 1715 | { |
1716 | - if(($method = self::get_registry($app,'file_access'))) |
|
1716 | + if (($method = self::get_registry($app, 'file_access'))) |
|
1717 | 1717 | { |
1718 | 1718 | $cache |= self::exec($method, array($id, $required, $rel_path)) ? $required|Acl::READ : 0; |
1719 | 1719 | } |
1720 | 1720 | else |
1721 | 1721 | { |
1722 | - $cache |= self::title($app,$id) ? Acl::READ|Acl::EDIT : 0; |
|
1722 | + $cache |= self::title($app, $id) ? Acl::READ|Acl::EDIT : 0; |
|
1723 | 1723 | } |
1724 | 1724 | //error_log(__METHOD__."($app,$id,$required,$rel_path) got $cache --> ".($cache & $required ? 'true' : 'false')); |
1725 | 1725 | } |
1726 | 1726 | //else error_log(__METHOD__."($app,$id,$required,$rel_path) using cached value $cache --> ".($cache & $required ? 'true' : 'false')); |
1727 | - return !!($cache & $required); |
|
1727 | + return !!($cache&$required); |
|
1728 | 1728 | } |
1729 | 1729 | |
1730 | 1730 | /** |
@@ -1737,7 +1737,7 @@ discard block |
||
1737 | 1737 | * @param array $params array with arguments incl. references |
1738 | 1738 | * @return mixed |
1739 | 1739 | */ |
1740 | - protected static function exec($method, array $params=array()) |
|
1740 | + protected static function exec($method, array $params = array()) |
|
1741 | 1741 | { |
1742 | 1742 | static $objs = array(); |
1743 | 1743 |
@@ -501,7 +501,7 @@ discard block |
||
501 | 501 | } |
502 | 502 | $ids = Link\Storage::get_links($app, $id, $only_app, $order, $deleted, $limit); |
503 | 503 | if (empty($only_app) || $only_app == self::VFS_APPNAME || |
504 | - ($only_app[0] == '!' && $only_app != '!'.self::VFS_APPNAME)) |
|
504 | + ($only_app[0] == '!' && $only_app != '!'.self::VFS_APPNAME)) |
|
505 | 505 | { |
506 | 506 | if (($vfs_ids = self::list_attached($app,$id))) |
507 | 507 | { |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | $links = Link\Storage::get_links($app,$ids,$only_app,$order,$deleted); |
558 | 558 | |
559 | 559 | if (empty($only_app) || $only_app == self::VFS_APPNAME || |
560 | - ($only_app[0] == '!' && $only_app != '!'.self::VFS_APPNAME)) |
|
560 | + ($only_app[0] == '!' && $only_app != '!'.self::VFS_APPNAME)) |
|
561 | 561 | { |
562 | 562 | // todo do that in a single query, eg. directory listing, too |
563 | 563 | foreach($ids as $id) |
@@ -776,7 +776,7 @@ discard block |
||
776 | 776 | |
777 | 777 | if (!isset($options['total'])) |
778 | 778 | { |
779 | - $options['total'] = count($result); |
|
779 | + $options['total'] = count($result); |
|
780 | 780 | } |
781 | 781 | if (isset($options['exclude'])) |
782 | 782 | { |