@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) return; |
| 14 | 14 | |
| 15 | -if (!defined('_DATA_SOURCE_MAX_SIZE')) define('_DATA_SOURCE_MAX_SIZE',2*1048576); |
|
| 15 | +if (!defined('_DATA_SOURCE_MAX_SIZE')) define('_DATA_SOURCE_MAX_SIZE', 2 * 1048576); |
|
| 16 | 16 | |
| 17 | 17 | |
| 18 | 18 | /** |
@@ -86,8 +86,8 @@ discard block |
||
| 86 | 86 | * @param $command |
| 87 | 87 | * @param array $info |
| 88 | 88 | */ |
| 89 | - public function __construct($command, $info=array()) { |
|
| 90 | - $this->type='DATA'; |
|
| 89 | + public function __construct($command, $info = array()) { |
|
| 90 | + $this->type = 'DATA'; |
|
| 91 | 91 | $this->command = $command; |
| 92 | 92 | $this->info = $info; |
| 93 | 93 | |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | // Si a ce stade on n'a pas de table, il y a un bug |
| 190 | 190 | if (!is_array($this->tableau)) { |
| 191 | 191 | $this->err = true; |
| 192 | - spip_log("erreur datasource ".var_export($command,true)); |
|
| 192 | + spip_log("erreur datasource ".var_export($command, true)); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | // {datapath query.results} |
@@ -226,8 +226,8 @@ discard block |
||
| 226 | 226 | # l'objet en cache ; cf plugins/icalendar |
| 227 | 227 | # perf : pas de fonction table_to_array ! (table est deja un array) |
| 228 | 228 | if (isset($this->command['sourcemode']) |
| 229 | - AND !in_array($this->command['sourcemode'],array('table', 'array', 'tableau'))) |
|
| 230 | - charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 229 | + AND !in_array($this->command['sourcemode'], array('table', 'array', 'tableau'))) |
|
| 230 | + charger_fonction($this->command['sourcemode'].'_to_array', 'inc', true); |
|
| 231 | 231 | |
| 232 | 232 | # le premier argument peut etre un array, une URL etc. |
| 233 | 233 | $src = $this->command['source'][0]; |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | # avons-nous un cache dispo ? |
| 236 | 236 | $cle = null; |
| 237 | 237 | if (is_string($src)) |
| 238 | - $cle = 'datasource_'.md5($this->command['sourcemode'].':'.var_export($this->command['source'],true)); |
|
| 238 | + $cle = 'datasource_'.md5($this->command['sourcemode'].':'.var_export($this->command['source'], true)); |
|
| 239 | 239 | |
| 240 | 240 | $cache = $this->cache_get($cle); |
| 241 | 241 | if (isset($this->command['datacache'])) |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | $u = recuperer_page($src, false, false, _DATA_SOURCE_MAX_SIZE); |
| 272 | 272 | if (!$u) |
| 273 | 273 | throw new Exception("404"); |
| 274 | - if (!isset($ttl)) $ttl = 24*3600; |
|
| 274 | + if (!isset($ttl)) $ttl = 24 * 3600; |
|
| 275 | 275 | } else if (@is_dir($src)) { |
| 276 | 276 | $u = $src; |
| 277 | 277 | if (!isset($ttl)) $ttl = 10; |
@@ -283,10 +283,10 @@ discard block |
||
| 283 | 283 | if (!isset($ttl)) $ttl = 10; |
| 284 | 284 | } |
| 285 | 285 | if (!$this->err |
| 286 | - AND $g = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true)) { |
|
| 286 | + AND $g = charger_fonction($this->command['sourcemode'].'_to_array', 'inc', true)) { |
|
| 287 | 287 | $args = $this->command['source']; |
| 288 | 288 | $args[0] = $u; |
| 289 | - if (is_array($a = call_user_func_array($g,$args))) { |
|
| 289 | + if (is_array($a = call_user_func_array($g, $args))) { |
|
| 290 | 290 | $this->tableau = $a; |
| 291 | 291 | } |
| 292 | 292 | } |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | if (!is_array($this->tableau)) |
| 296 | 296 | $this->err = true; |
| 297 | 297 | |
| 298 | - if (!$this->err AND isset($ttl) and $ttl>0) |
|
| 298 | + if (!$this->err AND isset($ttl) and $ttl > 0) |
|
| 299 | 299 | $this->cache_set($cle, $ttl); |
| 300 | 300 | |
| 301 | 301 | } |
@@ -348,10 +348,10 @@ discard block |
||
| 348 | 348 | $this->command['enum'] = $this->command['enum'][0]; |
| 349 | 349 | } |
| 350 | 350 | } |
| 351 | - if (count($this->command['enum'])>=3) |
|
| 352 | - $enum = range(array_shift($this->command['enum']),array_shift($this->command['enum']),array_shift($this->command['enum'])); |
|
| 351 | + if (count($this->command['enum']) >= 3) |
|
| 352 | + $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 353 | 353 | else |
| 354 | - $enum = range(array_shift($this->command['enum']),array_shift($this->command['enum'])); |
|
| 354 | + $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 355 | 355 | $this->tableau = $enum; |
| 356 | 356 | } |
| 357 | 357 | |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | **/ |
| 364 | 364 | protected function select_datapath() { |
| 365 | 365 | list(,$base) = each($this->command['datapath']); |
| 366 | - if (strlen($base = ltrim(trim($base),"/"))) { |
|
| 366 | + if (strlen($base = ltrim(trim($base), "/"))) { |
|
| 367 | 367 | $this->tableau = table_valeur($this->tableau, $base); |
| 368 | 368 | if (!is_array($this->tableau)) { |
| 369 | 369 | $this->tableau = array(); |
@@ -381,11 +381,11 @@ discard block |
||
| 381 | 381 | protected function select_orderby() { |
| 382 | 382 | $sortfunc = ''; |
| 383 | 383 | $aleas = 0; |
| 384 | - foreach($this->command['orderby'] as $tri) { |
|
| 384 | + foreach ($this->command['orderby'] as $tri) { |
|
| 385 | 385 | // virer le / initial pour les criteres de la forme {par /xx} |
| 386 | 386 | if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
| 387 | 387 | // tri par cle |
| 388 | - if ($r[1] == 'cle'){ |
|
| 388 | + if ($r[1] == 'cle') { |
|
| 389 | 389 | if (isset($r[2]) and $r[2]) |
| 390 | 390 | krsort($this->tableau); |
| 391 | 391 | else |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | $k = array_keys($this->tableau); |
| 397 | 397 | shuffle($k); |
| 398 | 398 | $v = array(); |
| 399 | - foreach($k as $cle) |
|
| 399 | + foreach ($k as $cle) |
|
| 400 | 400 | $v[$cle] = $this->tableau[$cle]; |
| 401 | 401 | $this->tableau = $v; |
| 402 | 402 | } |
@@ -406,10 +406,10 @@ discard block |
||
| 406 | 406 | $tv = '%s'; |
| 407 | 407 | # {par valeur/xx/yy} ?? |
| 408 | 408 | else |
| 409 | - $tv = 'table_valeur(%s, '.var_export($r[1],true).')'; |
|
| 409 | + $tv = 'table_valeur(%s, '.var_export($r[1], true).')'; |
|
| 410 | 410 | $sortfunc .= ' |
| 411 | - $a = '.sprintf($tv,'$aa').'; |
|
| 412 | - $b = '.sprintf($tv,'$bb').'; |
|
| 411 | + $a = '.sprintf($tv, '$aa').'; |
|
| 412 | + $b = '.sprintf($tv, '$bb').'; |
|
| 413 | 413 | if ($a <> $b) |
| 414 | 414 | return ($a ' . ((isset($r[2]) and $r[2]) ? '>' : '<').' $b) ? -1 : 1;'; |
| 415 | 415 | } |
@@ -434,7 +434,7 @@ discard block |
||
| 434 | 434 | // virer le / initial pour les criteres de la forme {fusion /xx} |
| 435 | 435 | if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
| 436 | 436 | $vu = array(); |
| 437 | - foreach($this->tableau as $k => $v) { |
|
| 437 | + foreach ($this->tableau as $k => $v) { |
|
| 438 | 438 | $val = table_valeur($v, $fusion); |
| 439 | 439 | if (isset($vu[$val])) |
| 440 | 440 | unset($this->tableau[$k]); |
@@ -449,7 +449,7 @@ discard block |
||
| 449 | 449 | * L'iterateur est-il encore valide ? |
| 450 | 450 | * @return bool |
| 451 | 451 | */ |
| 452 | - public function valid(){ |
|
| 452 | + public function valid() { |
|
| 453 | 453 | return !is_null($this->cle); |
| 454 | 454 | } |
| 455 | 455 | |
@@ -473,7 +473,7 @@ discard block |
||
| 473 | 473 | * Passer a la valeur suivante |
| 474 | 474 | * @return void |
| 475 | 475 | */ |
| 476 | - public function next(){ |
|
| 476 | + public function next() { |
|
| 477 | 477 | if ($this->valid()) |
| 478 | 478 | list($this->cle, $this->valeur) = each($this->tableau); |
| 479 | 479 | } |
@@ -529,14 +529,14 @@ discard block |
||
| 529 | 529 | * @return array |
| 530 | 530 | * |
| 531 | 531 | */ |
| 532 | -function inc_object_to_array( $object ) { |
|
| 533 | - if( !is_object( $object ) && !is_array( $object ) ) { |
|
| 532 | +function inc_object_to_array($object) { |
|
| 533 | + if (!is_object($object) && !is_array($object)) { |
|
| 534 | 534 | return $object; |
| 535 | 535 | } |
| 536 | - if( is_object( $object ) ) { |
|
| 537 | - $object = get_object_vars( $object ); |
|
| 536 | + if (is_object($object)) { |
|
| 537 | + $object = get_object_vars($object); |
|
| 538 | 538 | } |
| 539 | - return array_map( 'inc_object_to_array', $object ); |
|
| 539 | + return array_map('inc_object_to_array', $object); |
|
| 540 | 540 | } |
| 541 | 541 | |
| 542 | 542 | /** |
@@ -593,8 +593,8 @@ discard block |
||
| 593 | 593 | */ |
| 594 | 594 | function inc_csv_to_array_dist($u) { |
| 595 | 595 | include_spip('inc/csv'); |
| 596 | - list($entete,$csv) = analyse_csv($u); |
|
| 597 | - array_unshift($csv,$entete); |
|
| 596 | + list($entete, $csv) = analyse_csv($u); |
|
| 597 | + array_unshift($csv, $entete); |
|
| 598 | 598 | |
| 599 | 599 | include_spip('inc/charsets'); |
| 600 | 600 | foreach ($entete as $k => $v) { |
@@ -645,9 +645,9 @@ discard block |
||
| 645 | 645 | * @return bool|array |
| 646 | 646 | * @throws Exception |
| 647 | 647 | */ |
| 648 | -function inc_yaml_to_array_dist($u){ |
|
| 648 | +function inc_yaml_to_array_dist($u) { |
|
| 649 | 649 | include_spip('inc/yaml-mini'); |
| 650 | - if (!function_exists("yaml_decode")){ |
|
| 650 | + if (!function_exists("yaml_decode")) { |
|
| 651 | 651 | throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
| 652 | 652 | return false; |
| 653 | 653 | } |
@@ -665,7 +665,7 @@ discard block |
||
| 665 | 665 | * @param int $limit |
| 666 | 666 | * @return array|bool |
| 667 | 667 | */ |
| 668 | -function inc_pregfiles_to_array_dist($dir, $regexp=-1, $limit=10000) { |
|
| 668 | +function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
|
| 669 | 669 | return (array) preg_files($dir, $regexp, $limit); |
| 670 | 670 | } |
| 671 | 671 | |
@@ -683,7 +683,7 @@ discard block |
||
| 683 | 683 | $b = (array) @stat($v); |
| 684 | 684 | foreach ($b as $k => $ignore) |
| 685 | 685 | if (is_numeric($k)) unset($b[$k]); |
| 686 | - $b['file'] = preg_replace('`/$`','',$v) ; |
|
| 686 | + $b['file'] = preg_replace('`/$`', '', $v); |
|
| 687 | 687 | $v = array_merge( |
| 688 | 688 | pathinfo($v), |
| 689 | 689 | $b |
@@ -697,21 +697,21 @@ discard block |
||
| 697 | 697 | * @param Object $object |
| 698 | 698 | * @return array|bool |
| 699 | 699 | */ |
| 700 | -function XMLObjectToArray($object){ |
|
| 700 | +function XMLObjectToArray($object) { |
|
| 701 | 701 | $xml_array = array(); |
| 702 | - for( $object->rewind(); $object->valid(); $object->next() ) { |
|
| 703 | - if(array_key_exists($key = $object->key(), $xml_array)){ |
|
| 702 | + for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 703 | + if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 704 | 704 | $key .= '-'.uniqid(); |
| 705 | 705 | } |
| 706 | 706 | $vars = get_object_vars($object->current()); |
| 707 | 707 | if (isset($vars['@attributes'])) |
| 708 | - foreach($vars['@attributes'] as $k => $v) |
|
| 708 | + foreach ($vars['@attributes'] as $k => $v) |
|
| 709 | 709 | $xml_array[$key][$k] = $v; |
| 710 | - if($object->hasChildren()){ |
|
| 710 | + if ($object->hasChildren()) { |
|
| 711 | 711 | $xml_array[$key][] = XMLObjectToArray( |
| 712 | 712 | $object->current()); |
| 713 | 713 | } |
| 714 | - else{ |
|
| 714 | + else { |
|
| 715 | 715 | $xml_array[$key][] = strval($object->current()); |
| 716 | 716 | } |
| 717 | 717 | } |