@@ -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 | } |