@@ -10,9 +10,13 @@ discard block |
||
| 10 | 10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 13 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 14 | + return; |
|
| 15 | +} |
|
| 14 | 16 | |
| 15 | -if (!defined('_DATA_SOURCE_MAX_SIZE')) define('_DATA_SOURCE_MAX_SIZE',2*1048576); |
|
| 17 | +if (!defined('_DATA_SOURCE_MAX_SIZE')) { |
|
| 18 | + define('_DATA_SOURCE_MAX_SIZE',2*1048576); |
|
| 19 | +} |
|
| 16 | 20 | |
| 17 | 21 | |
| 18 | 22 | /** |
@@ -117,10 +121,14 @@ discard block |
||
| 117 | 121 | * @return |
| 118 | 122 | */ |
| 119 | 123 | protected function cache_get($cle) { |
| 120 | - if (!$cle) return; |
|
| 124 | + if (!$cle) { |
|
| 125 | + return; |
|
| 126 | + } |
|
| 121 | 127 | # utiliser memoization si dispo |
| 122 | 128 | include_spip('inc/memoization'); |
| 123 | - if (!function_exists('cache_get')) return; |
|
| 129 | + if (!function_exists('cache_get')) { |
|
| 130 | + return; |
|
| 131 | + } |
|
| 124 | 132 | return cache_get($cle); |
| 125 | 133 | } |
| 126 | 134 | |
@@ -131,13 +139,17 @@ discard block |
||
| 131 | 139 | * @return |
| 132 | 140 | */ |
| 133 | 141 | protected function cache_set($cle, $ttl, $valeur = null) { |
| 134 | - if (!$cle) return; |
|
| 142 | + if (!$cle) { |
|
| 143 | + return; |
|
| 144 | + } |
|
| 135 | 145 | if (is_null($valeur)) { |
| 136 | 146 | $valeur = $this->tableau; |
| 137 | 147 | } |
| 138 | 148 | # utiliser memoization si dispo |
| 139 | 149 | include_spip('inc/memoization'); |
| 140 | - if (!function_exists('cache_set')) return; |
|
| 150 | + if (!function_exists('cache_set')) { |
|
| 151 | + return; |
|
| 152 | + } |
|
| 141 | 153 | return cache_set($cle, |
| 142 | 154 | array( |
| 143 | 155 | 'data' => $valeur, |
@@ -226,20 +238,23 @@ discard block |
||
| 226 | 238 | # l'objet en cache ; cf plugins/icalendar |
| 227 | 239 | # perf : pas de fonction table_to_array ! (table est deja un array) |
| 228 | 240 | 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); |
|
| 241 | + AND !in_array($this->command['sourcemode'],array('table', 'array', 'tableau'))) { |
|
| 242 | + charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 243 | + } |
|
| 231 | 244 | |
| 232 | 245 | # le premier argument peut etre un array, une URL etc. |
| 233 | 246 | $src = $this->command['source'][0]; |
| 234 | 247 | |
| 235 | 248 | # avons-nous un cache dispo ? |
| 236 | 249 | $cle = null; |
| 237 | - if (is_string($src)) |
|
| 238 | - $cle = 'datasource_'.md5($this->command['sourcemode'].':'.var_export($this->command['source'],true)); |
|
| 250 | + if (is_string($src)) { |
|
| 251 | + $cle = 'datasource_'.md5($this->command['sourcemode'].':'.var_export($this->command['source'],true)); |
|
| 252 | + } |
|
| 239 | 253 | |
| 240 | 254 | $cache = $this->cache_get($cle); |
| 241 | - if (isset($this->command['datacache'])) |
|
| 242 | - $ttl = intval($this->command['datacache']); |
|
| 255 | + if (isset($this->command['datacache'])) { |
|
| 256 | + $ttl = intval($this->command['datacache']); |
|
| 257 | + } |
|
| 243 | 258 | if ($cache |
| 244 | 259 | AND ($cache['time'] + (isset($ttl) ? $ttl : $cache['ttl']) |
| 245 | 260 | > time()) |
@@ -248,11 +263,12 @@ discard block |
||
| 248 | 263 | AND autoriser('recalcul') |
| 249 | 264 | )) { |
| 250 | 265 | $this->tableau = $cache['data']; |
| 251 | - } |
|
| 252 | - else try { |
|
| 266 | + } else { |
|
| 267 | + try { |
|
| 253 | 268 | # dommage que ca ne soit pas une option de yql_to_array... |
| 254 | 269 | if ($this->command['sourcemode'] == 'yql') |
| 255 | 270 | if (!isset($ttl)) $ttl = 3600; |
| 271 | + } |
|
| 256 | 272 | |
| 257 | 273 | if (isset($this->command['sourcemode']) |
| 258 | 274 | AND in_array($this->command['sourcemode'], |
@@ -262,25 +278,34 @@ discard block |
||
| 262 | 278 | OR (is_string($a) |
| 263 | 279 | AND $a = str_replace('"', '"', $a) # fragile! |
| 264 | 280 | AND is_array($a = @unserialize($a))) |
| 265 | - ) |
|
| 266 | - $this->tableau = $a; |
|
| 267 | - } |
|
| 268 | - else { |
|
| 281 | + ) { |
|
| 282 | + $this->tableau = $a; |
|
| 283 | + } |
|
| 284 | + } else { |
|
| 269 | 285 | if (preg_match(',^https?://,', $src)) { |
| 270 | 286 | include_spip('inc/distant'); |
| 271 | 287 | $u = recuperer_page($src, false, false, _DATA_SOURCE_MAX_SIZE); |
| 272 | - if (!$u) |
|
| 273 | - throw new Exception("404"); |
|
| 274 | - if (!isset($ttl)) $ttl = 24*3600; |
|
| 288 | + if (!$u) { |
|
| 289 | + throw new Exception("404"); |
|
| 290 | + } |
|
| 291 | + if (!isset($ttl)) { |
|
| 292 | + $ttl = 24*3600; |
|
| 293 | + } |
|
| 275 | 294 | } else if (@is_dir($src)) { |
| 276 | 295 | $u = $src; |
| 277 | - if (!isset($ttl)) $ttl = 10; |
|
| 296 | + if (!isset($ttl)) { |
|
| 297 | + $ttl = 10; |
|
| 298 | + } |
|
| 278 | 299 | } else if (@is_readable($src) && @is_file($src)) { |
| 279 | 300 | $u = spip_file_get_contents($src); |
| 280 | - if (!isset($ttl)) $ttl = 10; |
|
| 301 | + if (!isset($ttl)) { |
|
| 302 | + $ttl = 10; |
|
| 303 | + } |
|
| 281 | 304 | } else { |
| 282 | 305 | $u = $src; |
| 283 | - if (!isset($ttl)) $ttl = 10; |
|
| 306 | + if (!isset($ttl)) { |
|
| 307 | + $ttl = 10; |
|
| 308 | + } |
|
| 284 | 309 | } |
| 285 | 310 | if (!$this->err |
| 286 | 311 | AND $g = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true)) { |
@@ -292,14 +317,15 @@ discard block |
||
| 292 | 317 | } |
| 293 | 318 | } |
| 294 | 319 | |
| 295 | - if (!is_array($this->tableau)) |
|
| 296 | - $this->err = true; |
|
| 320 | + if (!is_array($this->tableau)) { |
|
| 321 | + $this->err = true; |
|
| 322 | + } |
|
| 297 | 323 | |
| 298 | - if (!$this->err AND isset($ttl) and $ttl>0) |
|
| 299 | - $this->cache_set($cle, $ttl); |
|
| 324 | + if (!$this->err AND isset($ttl) and $ttl>0) { |
|
| 325 | + $this->cache_set($cle, $ttl); |
|
| 326 | + } |
|
| 300 | 327 | |
| 301 | - } |
|
| 302 | - catch (Exception $e) { |
|
| 328 | + } catch (Exception $e) { |
|
| 303 | 329 | $e = $e->getMessage(); |
| 304 | 330 | $err = sprintf("[%s, %s] $e", |
| 305 | 331 | $src, |
@@ -348,10 +374,11 @@ discard block |
||
| 348 | 374 | $this->command['enum'] = $this->command['enum'][0]; |
| 349 | 375 | } |
| 350 | 376 | } |
| 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 | - else |
|
| 354 | - $enum = range(array_shift($this->command['enum']),array_shift($this->command['enum'])); |
|
| 377 | + if (count($this->command['enum'])>=3) { |
|
| 378 | + $enum = range(array_shift($this->command['enum']),array_shift($this->command['enum']),array_shift($this->command['enum'])); |
|
| 379 | + } else { |
|
| 380 | + $enum = range(array_shift($this->command['enum']),array_shift($this->command['enum'])); |
|
| 381 | + } |
|
| 355 | 382 | $this->tableau = $enum; |
| 356 | 383 | } |
| 357 | 384 | |
@@ -386,27 +413,30 @@ discard block |
||
| 386 | 413 | if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
| 387 | 414 | // tri par cle |
| 388 | 415 | if ($r[1] == 'cle'){ |
| 389 | - if (isset($r[2]) and $r[2]) |
|
| 390 | - krsort($this->tableau); |
|
| 391 | - else |
|
| 392 | - ksort($this->tableau); |
|
| 416 | + if (isset($r[2]) and $r[2]) { |
|
| 417 | + krsort($this->tableau); |
|
| 418 | + } else { |
|
| 419 | + ksort($this->tableau); |
|
| 420 | + } |
|
| 393 | 421 | } |
| 394 | 422 | # {par hasard} |
| 395 | 423 | else if ($r[1] == 'alea') { |
| 396 | 424 | $k = array_keys($this->tableau); |
| 397 | 425 | shuffle($k); |
| 398 | 426 | $v = array(); |
| 399 | - foreach($k as $cle) |
|
| 400 | - $v[$cle] = $this->tableau[$cle]; |
|
| 427 | + foreach($k as $cle) { |
|
| 428 | + $v[$cle] = $this->tableau[$cle]; |
|
| 429 | + } |
|
| 401 | 430 | $this->tableau = $v; |
| 402 | - } |
|
| 403 | - else { |
|
| 431 | + } else { |
|
| 404 | 432 | # {par valeur} |
| 405 | - if ($r[1] == 'valeur') |
|
| 406 | - $tv = '%s'; |
|
| 433 | + if ($r[1] == 'valeur') { |
|
| 434 | + $tv = '%s'; |
|
| 435 | + } |
|
| 407 | 436 | # {par valeur/xx/yy} ?? |
| 408 | - else |
|
| 409 | - $tv = 'table_valeur(%s, '.var_export($r[1],true).')'; |
|
| 437 | + else { |
|
| 438 | + $tv = 'table_valeur(%s, '.var_export($r[1],true).')'; |
|
| 439 | + } |
|
| 410 | 440 | $sortfunc .= ' |
| 411 | 441 | $a = '.sprintf($tv,'$aa').'; |
| 412 | 442 | $b = '.sprintf($tv,'$bb').'; |
@@ -436,10 +466,11 @@ discard block |
||
| 436 | 466 | $vu = array(); |
| 437 | 467 | foreach($this->tableau as $k => $v) { |
| 438 | 468 | $val = table_valeur($v, $fusion); |
| 439 | - if (isset($vu[$val])) |
|
| 440 | - unset($this->tableau[$k]); |
|
| 441 | - else |
|
| 442 | - $vu[$val] = true; |
|
| 469 | + if (isset($vu[$val])) { |
|
| 470 | + unset($this->tableau[$k]); |
|
| 471 | + } else { |
|
| 472 | + $vu[$val] = true; |
|
| 473 | + } |
|
| 443 | 474 | } |
| 444 | 475 | } |
| 445 | 476 | } |
@@ -474,8 +505,9 @@ discard block |
||
| 474 | 505 | * @return void |
| 475 | 506 | */ |
| 476 | 507 | public function next(){ |
| 477 | - if ($this->valid()) |
|
| 478 | - list($this->cle, $this->valeur) = each($this->tableau); |
|
| 508 | + if ($this->valid()) { |
|
| 509 | + list($this->cle, $this->valeur) = each($this->tableau); |
|
| 510 | + } |
|
| 479 | 511 | } |
| 480 | 512 | |
| 481 | 513 | /** |
@@ -483,8 +515,9 @@ discard block |
||
| 483 | 515 | * @return int |
| 484 | 516 | */ |
| 485 | 517 | public function count() { |
| 486 | - if (is_null($this->total)) |
|
| 487 | - $this->total = count($this->tableau); |
|
| 518 | + if (is_null($this->total)) { |
|
| 519 | + $this->total = count($this->tableau); |
|
| 520 | + } |
|
| 488 | 521 | return $this->total; |
| 489 | 522 | } |
| 490 | 523 | } |
@@ -568,8 +601,9 @@ discard block |
||
| 568 | 601 | $req = trim($v[2]); |
| 569 | 602 | if ($s = sql_query($req, $serveur)) { |
| 570 | 603 | $r = array(); |
| 571 | - while ($t = sql_fetch($s)) |
|
| 572 | - $r[] = $t; |
|
| 604 | + while ($t = sql_fetch($s)) { |
|
| 605 | + $r[] = $t; |
|
| 606 | + } |
|
| 573 | 607 | return $r; |
| 574 | 608 | } |
| 575 | 609 | return false; |
@@ -582,9 +616,10 @@ discard block |
||
| 582 | 616 | */ |
| 583 | 617 | function inc_json_to_array_dist($u) { |
| 584 | 618 | if (is_array($json = json_decode($u)) |
| 585 | - OR is_object($json)) |
|
| 586 | - return (array) $json; |
|
| 587 | -} |
|
| 619 | + OR is_object($json)) { |
|
| 620 | + return (array) $json; |
|
| 621 | + } |
|
| 622 | + } |
|
| 588 | 623 | |
| 589 | 624 | /** |
| 590 | 625 | * csv -> tableau |
@@ -599,8 +634,9 @@ discard block |
||
| 599 | 634 | include_spip('inc/charsets'); |
| 600 | 635 | foreach ($entete as $k => $v) { |
| 601 | 636 | $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
| 602 | - foreach ($csv as &$item) |
|
| 603 | - $item[$v] = &$item[$k]; |
|
| 637 | + foreach ($csv as &$item) { |
|
| 638 | + $item[$v] = &$item[$k]; |
|
| 639 | + } |
|
| 604 | 640 | } |
| 605 | 641 | return $csv; |
| 606 | 642 | } |
@@ -612,8 +648,9 @@ discard block |
||
| 612 | 648 | */ |
| 613 | 649 | function inc_rss_to_array_dist($u) { |
| 614 | 650 | include_spip('inc/syndic'); |
| 615 | - if (is_array($rss = analyser_backend($u))) |
|
| 616 | - $tableau = $rss; |
|
| 651 | + if (is_array($rss = analyser_backend($u))) { |
|
| 652 | + $tableau = $rss; |
|
| 653 | + } |
|
| 617 | 654 | return $tableau; |
| 618 | 655 | } |
| 619 | 656 | |
@@ -681,8 +718,9 @@ discard block |
||
| 681 | 718 | $a = $glob($u); |
| 682 | 719 | foreach ($a as &$v) { |
| 683 | 720 | $b = (array) @stat($v); |
| 684 | - foreach ($b as $k => $ignore) |
|
| 685 | - if (is_numeric($k)) unset($b[$k]); |
|
| 721 | + foreach ($b as $k => $ignore) { |
|
| 722 | + if (is_numeric($k)) unset($b[$k]); |
|
| 723 | + } |
|
| 686 | 724 | $b['file'] = preg_replace('`/$`','',$v) ; |
| 687 | 725 | $v = array_merge( |
| 688 | 726 | pathinfo($v), |
@@ -704,14 +742,14 @@ discard block |
||
| 704 | 742 | $key .= '-'.uniqid(); |
| 705 | 743 | } |
| 706 | 744 | $vars = get_object_vars($object->current()); |
| 707 | - if (isset($vars['@attributes'])) |
|
| 708 | - foreach($vars['@attributes'] as $k => $v) |
|
| 745 | + if (isset($vars['@attributes'])) { |
|
| 746 | + foreach($vars['@attributes'] as $k => $v) |
|
| 709 | 747 | $xml_array[$key][$k] = $v; |
| 748 | + } |
|
| 710 | 749 | if($object->hasChildren()){ |
| 711 | 750 | $xml_array[$key][] = XMLObjectToArray( |
| 712 | 751 | $object->current()); |
| 713 | - } |
|
| 714 | - else{ |
|
| 752 | + } else{ |
|
| 715 | 753 | $xml_array[$key][] = strval($object->current()); |
| 716 | 754 | } |
| 717 | 755 | } |