@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -34,14 +34,14 @@ discard block |
||
| 34 | 34 | * @return void |
| 35 | 35 | */ |
| 36 | 36 | function action_ajouter_lien_dist($arg = null) { |
| 37 | - if (is_null($arg)) { |
|
| 38 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 39 | - $arg = $securiser_action(); |
|
| 40 | - } |
|
| 37 | + if (is_null($arg)) { |
|
| 38 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 39 | + $arg = $securiser_action(); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - $arg = explode('-', $arg); |
|
| 43 | - [$objet_source, $ids, $objet_lie, $idl] = $arg; |
|
| 42 | + $arg = explode('-', $arg); |
|
| 43 | + [$objet_source, $ids, $objet_lie, $idl] = $arg; |
|
| 44 | 44 | |
| 45 | - include_spip('action/editer_liens'); |
|
| 46 | - objet_associer([$objet_source => $ids], [$objet_lie => $idl]); |
|
| 45 | + include_spip('action/editer_liens'); |
|
| 46 | + objet_associer([$objet_source => $ids], [$objet_lie => $idl]); |
|
| 47 | 47 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -31,17 +31,17 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | function action_debloquer_edition_dist() { |
| 33 | 33 | |
| 34 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 35 | - $arg = $securiser_action(); |
|
| 34 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 35 | + $arg = $securiser_action(); |
|
| 36 | 36 | |
| 37 | - if ($arg) { |
|
| 38 | - include_spip('inc/drapeau_edition'); |
|
| 39 | - if ($arg == 'tous') { |
|
| 40 | - debloquer_tous($GLOBALS['visiteur_session']['id_auteur']); |
|
| 41 | - } else { |
|
| 42 | - $arg = explode('-', $arg); |
|
| 43 | - [$objet, $id_objet] = $arg; |
|
| 44 | - debloquer_edition($GLOBALS['visiteur_session']['id_auteur'], $id_objet, $objet); |
|
| 45 | - } |
|
| 46 | - } |
|
| 37 | + if ($arg) { |
|
| 38 | + include_spip('inc/drapeau_edition'); |
|
| 39 | + if ($arg == 'tous') { |
|
| 40 | + debloquer_tous($GLOBALS['visiteur_session']['id_auteur']); |
|
| 41 | + } else { |
|
| 42 | + $arg = explode('-', $arg); |
|
| 43 | + [$objet, $id_objet] = $arg; |
|
| 44 | + debloquer_edition($GLOBALS['visiteur_session']['id_auteur'], $id_objet, $objet); |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/actions'); |
@@ -33,93 +33,93 @@ discard block |
||
| 33 | 33 | * @return void |
| 34 | 34 | */ |
| 35 | 35 | function action_cookie_dist($set_cookie_admin = null, $change_session = null) { |
| 36 | - $redirect_echec = $redirect = null; |
|
| 37 | - $test_echec_cookie = null; |
|
| 38 | - $url = ''; |
|
| 39 | - if (is_null($set_cookie_admin)) { |
|
| 40 | - $set_cookie_admin = _request('cookie_admin'); |
|
| 41 | - $change_session = _request('change_session'); |
|
| 42 | - $test_echec_cookie = _request('test_echec_cookie'); |
|
| 36 | + $redirect_echec = $redirect = null; |
|
| 37 | + $test_echec_cookie = null; |
|
| 38 | + $url = ''; |
|
| 39 | + if (is_null($set_cookie_admin)) { |
|
| 40 | + $set_cookie_admin = _request('cookie_admin'); |
|
| 41 | + $change_session = _request('change_session'); |
|
| 42 | + $test_echec_cookie = _request('test_echec_cookie'); |
|
| 43 | 43 | |
| 44 | - // La cible de notre operation de connexion |
|
| 45 | - $url = securiser_redirect_action(_request('url')); |
|
| 46 | - $redirect = $url ?: generer_url_ecrire('accueil'); |
|
| 47 | - $redirect_echec = _request('url_echec'); |
|
| 48 | - if (!isset($redirect_echec)) { |
|
| 49 | - if (strpos($redirect, (string) _DIR_RESTREINT_ABS) !== false) { |
|
| 50 | - $redirect_echec = generer_url_public('login', '', true); |
|
| 51 | - } else { |
|
| 52 | - $redirect_echec = $redirect; |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - } |
|
| 44 | + // La cible de notre operation de connexion |
|
| 45 | + $url = securiser_redirect_action(_request('url')); |
|
| 46 | + $redirect = $url ?: generer_url_ecrire('accueil'); |
|
| 47 | + $redirect_echec = _request('url_echec'); |
|
| 48 | + if (!isset($redirect_echec)) { |
|
| 49 | + if (strpos($redirect, (string) _DIR_RESTREINT_ABS) !== false) { |
|
| 50 | + $redirect_echec = generer_url_public('login', '', true); |
|
| 51 | + } else { |
|
| 52 | + $redirect_echec = $redirect; |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | 57 | |
| 58 | - // rejoue le cookie pour renouveler spip_session |
|
| 59 | - if ($change_session == 'oui') { |
|
| 60 | - $session = charger_fonction('session', 'inc'); |
|
| 61 | - $session(true); |
|
| 62 | - spip_log('statut 204 pour ' . $_SERVER['REQUEST_URI']); |
|
| 63 | - http_response_code(204); // No Content |
|
| 64 | - return; |
|
| 65 | - } |
|
| 58 | + // rejoue le cookie pour renouveler spip_session |
|
| 59 | + if ($change_session == 'oui') { |
|
| 60 | + $session = charger_fonction('session', 'inc'); |
|
| 61 | + $session(true); |
|
| 62 | + spip_log('statut 204 pour ' . $_SERVER['REQUEST_URI']); |
|
| 63 | + http_response_code(204); // No Content |
|
| 64 | + return; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - // tentative de connexion en auth_http |
|
| 68 | - if (_request('essai_auth_http') and !$GLOBALS['ignore_auth_http']) { |
|
| 69 | - include_spip('inc/auth'); |
|
| 70 | - if ( |
|
| 71 | - @$_SERVER['PHP_AUTH_USER'] |
|
| 72 | - and @$_SERVER['PHP_AUTH_PW'] |
|
| 73 | - and $auteur = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) |
|
| 74 | - ) { |
|
| 75 | - auth_loger($auteur); |
|
| 76 | - redirige_par_entete(parametre_url($redirect, 't', time(), '&')); |
|
| 77 | - } else { |
|
| 78 | - ask_php_auth( |
|
| 79 | - _T('info_connexion_refusee'), |
|
| 80 | - _T('login_login_pass_incorrect'), |
|
| 81 | - _T('login_retour_site'), |
|
| 82 | - 'url=' . rawurlencode($redirect), |
|
| 83 | - _T('login_nouvelle_tentative'), |
|
| 84 | - (strpos($url, (string) _DIR_RESTREINT_ABS) !== false) |
|
| 85 | - ); |
|
| 86 | - } |
|
| 87 | - } else { |
|
| 88 | - // en cas de login sur bonjour=oui, on tente de poser un cookie |
|
| 89 | - // puis de passer au login qui diagnostiquera l'echec de cookie |
|
| 90 | - // le cas echeant. |
|
| 91 | - if ($test_echec_cookie == 'oui') { |
|
| 92 | - spip_setcookie('spip_session', 'test_echec_cookie'); |
|
| 93 | - if ($redirect) { |
|
| 94 | - $redirect = parametre_url( |
|
| 95 | - parametre_url($redirect_echec, 'var_echec_cookie', 'oui', '&'), |
|
| 96 | - 'url', |
|
| 97 | - rawurlencode($redirect), |
|
| 98 | - '&' |
|
| 99 | - ); |
|
| 100 | - } |
|
| 101 | - } else { |
|
| 102 | - $cook = $_COOKIE['spip_admin'] ?? ''; |
|
| 103 | - // Suppression cookie d'admin ? |
|
| 104 | - if ($set_cookie_admin == 'non') { |
|
| 105 | - if ($cook) { |
|
| 106 | - spip_setcookie('spip_admin', $cook, [ |
|
| 107 | - 'expires' => time() - 3600 * 24 |
|
| 108 | - ]); |
|
| 109 | - } |
|
| 110 | - } // Ajout de cookie d'admin |
|
| 111 | - else { |
|
| 112 | - if ($set_cookie_admin and _DUREE_COOKIE_ADMIN) { |
|
| 113 | - spip_setcookie('spip_admin', $set_cookie_admin, [ |
|
| 114 | - 'expires' => time() + max(_DUREE_COOKIE_ADMIN, 2 * _RENOUVELLE_ALEA) |
|
| 115 | - ]); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - } |
|
| 67 | + // tentative de connexion en auth_http |
|
| 68 | + if (_request('essai_auth_http') and !$GLOBALS['ignore_auth_http']) { |
|
| 69 | + include_spip('inc/auth'); |
|
| 70 | + if ( |
|
| 71 | + @$_SERVER['PHP_AUTH_USER'] |
|
| 72 | + and @$_SERVER['PHP_AUTH_PW'] |
|
| 73 | + and $auteur = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) |
|
| 74 | + ) { |
|
| 75 | + auth_loger($auteur); |
|
| 76 | + redirige_par_entete(parametre_url($redirect, 't', time(), '&')); |
|
| 77 | + } else { |
|
| 78 | + ask_php_auth( |
|
| 79 | + _T('info_connexion_refusee'), |
|
| 80 | + _T('login_login_pass_incorrect'), |
|
| 81 | + _T('login_retour_site'), |
|
| 82 | + 'url=' . rawurlencode($redirect), |
|
| 83 | + _T('login_nouvelle_tentative'), |
|
| 84 | + (strpos($url, (string) _DIR_RESTREINT_ABS) !== false) |
|
| 85 | + ); |
|
| 86 | + } |
|
| 87 | + } else { |
|
| 88 | + // en cas de login sur bonjour=oui, on tente de poser un cookie |
|
| 89 | + // puis de passer au login qui diagnostiquera l'echec de cookie |
|
| 90 | + // le cas echeant. |
|
| 91 | + if ($test_echec_cookie == 'oui') { |
|
| 92 | + spip_setcookie('spip_session', 'test_echec_cookie'); |
|
| 93 | + if ($redirect) { |
|
| 94 | + $redirect = parametre_url( |
|
| 95 | + parametre_url($redirect_echec, 'var_echec_cookie', 'oui', '&'), |
|
| 96 | + 'url', |
|
| 97 | + rawurlencode($redirect), |
|
| 98 | + '&' |
|
| 99 | + ); |
|
| 100 | + } |
|
| 101 | + } else { |
|
| 102 | + $cook = $_COOKIE['spip_admin'] ?? ''; |
|
| 103 | + // Suppression cookie d'admin ? |
|
| 104 | + if ($set_cookie_admin == 'non') { |
|
| 105 | + if ($cook) { |
|
| 106 | + spip_setcookie('spip_admin', $cook, [ |
|
| 107 | + 'expires' => time() - 3600 * 24 |
|
| 108 | + ]); |
|
| 109 | + } |
|
| 110 | + } // Ajout de cookie d'admin |
|
| 111 | + else { |
|
| 112 | + if ($set_cookie_admin and _DUREE_COOKIE_ADMIN) { |
|
| 113 | + spip_setcookie('spip_admin', $set_cookie_admin, [ |
|
| 114 | + 'expires' => time() + max(_DUREE_COOKIE_ADMIN, 2 * _RENOUVELLE_ALEA) |
|
| 115 | + ]); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - // Redirection finale |
|
| 122 | - if ($redirect) { |
|
| 123 | - redirige_par_entete($redirect, true); |
|
| 124 | - } |
|
| 121 | + // Redirection finale |
|
| 122 | + if ($redirect) { |
|
| 123 | + redirige_par_entete($redirect, true); |
|
| 124 | + } |
|
| 125 | 125 | } |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | if ($change_session == 'oui') { |
| 60 | 60 | $session = charger_fonction('session', 'inc'); |
| 61 | 61 | $session(true); |
| 62 | - spip_log('statut 204 pour ' . $_SERVER['REQUEST_URI']); |
|
| 62 | + spip_log('statut 204 pour '.$_SERVER['REQUEST_URI']); |
|
| 63 | 63 | http_response_code(204); // No Content |
| 64 | 64 | return; |
| 65 | 65 | } |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | _T('info_connexion_refusee'), |
| 80 | 80 | _T('login_login_pass_incorrect'), |
| 81 | 81 | _T('login_retour_site'), |
| 82 | - 'url=' . rawurlencode($redirect), |
|
| 82 | + 'url='.rawurlencode($redirect), |
|
| 83 | 83 | _T('login_nouvelle_tentative'), |
| 84 | 84 | (strpos($url, (string) _DIR_RESTREINT_ABS) !== false) |
| 85 | 85 | ); |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -32,28 +32,28 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | function action_desinstaller_plugin_dist() { |
| 34 | 34 | |
| 35 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 36 | - $arg = $securiser_action(); |
|
| 37 | - [$dir_plugins, $plugin] = explode('::', $arg); |
|
| 38 | - $dir_type = '_DIR_PLUGINS'; |
|
| 39 | - if (defined('_DIR_PLUGINS_SUPPL') and $dir_plugins == _DIR_PLUGINS_SUPPL) { |
|
| 40 | - $dir_type = '_DIR_PLUGINS_SUPPL'; |
|
| 41 | - } |
|
| 42 | - $installer_plugins = charger_fonction('installer', 'plugins'); |
|
| 43 | - $infos = $installer_plugins($plugin, 'uninstall', $dir_type); |
|
| 44 | - if ($infos and !$infos['install_test'][0]) { |
|
| 45 | - include_spip('inc/plugin'); |
|
| 46 | - ecrire_plugin_actifs([$plugin], false, 'enleve'); |
|
| 47 | - $erreur = ''; |
|
| 48 | - } else { |
|
| 49 | - $erreur = 'erreur_plugin_desinstalation_echouee'; |
|
| 50 | - } |
|
| 51 | - if ($redirect = _request('redirect')) { |
|
| 52 | - include_spip('inc/headers'); |
|
| 53 | - if ($erreur) { |
|
| 54 | - $redirect = parametre_url($redirect, 'erreur', $erreur); |
|
| 55 | - } |
|
| 56 | - $redirect = str_replace('&', '&', $redirect); |
|
| 57 | - redirige_par_entete($redirect); |
|
| 58 | - } |
|
| 35 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 36 | + $arg = $securiser_action(); |
|
| 37 | + [$dir_plugins, $plugin] = explode('::', $arg); |
|
| 38 | + $dir_type = '_DIR_PLUGINS'; |
|
| 39 | + if (defined('_DIR_PLUGINS_SUPPL') and $dir_plugins == _DIR_PLUGINS_SUPPL) { |
|
| 40 | + $dir_type = '_DIR_PLUGINS_SUPPL'; |
|
| 41 | + } |
|
| 42 | + $installer_plugins = charger_fonction('installer', 'plugins'); |
|
| 43 | + $infos = $installer_plugins($plugin, 'uninstall', $dir_type); |
|
| 44 | + if ($infos and !$infos['install_test'][0]) { |
|
| 45 | + include_spip('inc/plugin'); |
|
| 46 | + ecrire_plugin_actifs([$plugin], false, 'enleve'); |
|
| 47 | + $erreur = ''; |
|
| 48 | + } else { |
|
| 49 | + $erreur = 'erreur_plugin_desinstalation_echouee'; |
|
| 50 | + } |
|
| 51 | + if ($redirect = _request('redirect')) { |
|
| 52 | + include_spip('inc/headers'); |
|
| 53 | + if ($erreur) { |
|
| 54 | + $redirect = parametre_url($redirect, 'erreur', $erreur); |
|
| 55 | + } |
|
| 56 | + $redirect = str_replace('&', '&', $redirect); |
|
| 57 | + redirige_par_entete($redirect); |
|
| 58 | + } |
|
| 59 | 59 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -54,84 +54,84 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | function balise_LOGO__dist($p) { |
| 56 | 56 | |
| 57 | - preg_match(',^LOGO_([A-Z_]+?)(|_NORMAL|_SURVOL|_RUBRIQUE)$,i', $p->nom_champ, $regs); |
|
| 58 | - $type = strtolower($regs[1]); |
|
| 59 | - $suite_logo = $regs[2]; |
|
| 60 | - |
|
| 61 | - // cas de #LOGO_SITE_SPIP |
|
| 62 | - if ($type == 'site_spip') { |
|
| 63 | - $type = 'site'; |
|
| 64 | - $_id_objet = "\"'0'\""; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - $id_objet = id_table_objet($type); |
|
| 68 | - if (!isset($_id_objet)) { |
|
| 69 | - $_id_objet = champ_sql($id_objet, $p); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - $fichier = ($p->etoile === '**') ? -1 : 0; |
|
| 73 | - $coord = []; |
|
| 74 | - $align = $lien = ''; |
|
| 75 | - $mode_logo = ''; |
|
| 76 | - |
|
| 77 | - if ($p->param and !$p->param[0][0]) { |
|
| 78 | - $params = $p->param[0]; |
|
| 79 | - array_shift($params); |
|
| 80 | - foreach ($params as $a) { |
|
| 81 | - if ($a[0]->type === 'texte') { |
|
| 82 | - $n = $a[0]->texte; |
|
| 83 | - if (is_numeric($n)) { |
|
| 84 | - $coord[] = $n; |
|
| 85 | - } elseif (in_array($n, ['top', 'left', 'right', 'center', 'bottom'])) { |
|
| 86 | - $align = $n; |
|
| 87 | - } elseif (in_array($n, ['auto', 'icone', 'apercu', 'vignette'])) { |
|
| 88 | - $mode_logo = $n; |
|
| 89 | - } |
|
| 90 | - } else { |
|
| 91 | - $lien = calculer_liste($a, $p->descr, $p->boucles, $p->id_boucle); |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - $coord_x = !$coord ? 0 : intval(array_shift($coord)); |
|
| 97 | - $coord_y = !$coord ? 0 : intval(array_shift($coord)); |
|
| 98 | - |
|
| 99 | - if ($p->etoile === '*') { |
|
| 100 | - include_spip('balise/url_'); |
|
| 101 | - $lien = generer_generer_url_arg($type, $p, $_id_objet); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $connect = $p->id_boucle ? $p->boucles[$p->id_boucle]->sql_serveur : ''; |
|
| 105 | - if ($type == 'document') { |
|
| 106 | - $qconnect = _q($connect); |
|
| 107 | - $doc = "quete_document($_id_objet, $qconnect)"; |
|
| 108 | - if ($fichier) { |
|
| 109 | - $code = "quete_logo_file($doc, $qconnect)"; |
|
| 110 | - } else { |
|
| 111 | - $code = "quete_logo_document($doc, " . ($lien ?: "''") . ", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)"; |
|
| 112 | - } |
|
| 113 | - // (x=non-faux ? y : '') pour affecter x en retournant y |
|
| 114 | - if ($p->descr['documents']) { |
|
| 115 | - $code = '(($doublons["documents"] .= ",". ' |
|
| 116 | - . $_id_objet |
|
| 117 | - . ") ? $code : '')"; |
|
| 118 | - } |
|
| 119 | - } elseif ($connect) { |
|
| 120 | - $code = "''"; |
|
| 121 | - spip_log('Les logos distants ne sont pas prevus'); |
|
| 122 | - } else { |
|
| 123 | - $code = logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $lien, $p, $suite_logo); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - // demande de reduction sur logo avec ecriture spip 2.1 : #LOGO_xxx{200, 0} |
|
| 127 | - if ($coord_x or $coord_y) { |
|
| 128 | - $code = "filtrer('image_graver',filtrer('image_reduire'," . $code . ", '$coord_x', '$coord_y'))"; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - $p->code = $code; |
|
| 132 | - $p->interdire_scripts = false; |
|
| 133 | - |
|
| 134 | - return $p; |
|
| 57 | + preg_match(',^LOGO_([A-Z_]+?)(|_NORMAL|_SURVOL|_RUBRIQUE)$,i', $p->nom_champ, $regs); |
|
| 58 | + $type = strtolower($regs[1]); |
|
| 59 | + $suite_logo = $regs[2]; |
|
| 60 | + |
|
| 61 | + // cas de #LOGO_SITE_SPIP |
|
| 62 | + if ($type == 'site_spip') { |
|
| 63 | + $type = 'site'; |
|
| 64 | + $_id_objet = "\"'0'\""; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + $id_objet = id_table_objet($type); |
|
| 68 | + if (!isset($_id_objet)) { |
|
| 69 | + $_id_objet = champ_sql($id_objet, $p); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + $fichier = ($p->etoile === '**') ? -1 : 0; |
|
| 73 | + $coord = []; |
|
| 74 | + $align = $lien = ''; |
|
| 75 | + $mode_logo = ''; |
|
| 76 | + |
|
| 77 | + if ($p->param and !$p->param[0][0]) { |
|
| 78 | + $params = $p->param[0]; |
|
| 79 | + array_shift($params); |
|
| 80 | + foreach ($params as $a) { |
|
| 81 | + if ($a[0]->type === 'texte') { |
|
| 82 | + $n = $a[0]->texte; |
|
| 83 | + if (is_numeric($n)) { |
|
| 84 | + $coord[] = $n; |
|
| 85 | + } elseif (in_array($n, ['top', 'left', 'right', 'center', 'bottom'])) { |
|
| 86 | + $align = $n; |
|
| 87 | + } elseif (in_array($n, ['auto', 'icone', 'apercu', 'vignette'])) { |
|
| 88 | + $mode_logo = $n; |
|
| 89 | + } |
|
| 90 | + } else { |
|
| 91 | + $lien = calculer_liste($a, $p->descr, $p->boucles, $p->id_boucle); |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + $coord_x = !$coord ? 0 : intval(array_shift($coord)); |
|
| 97 | + $coord_y = !$coord ? 0 : intval(array_shift($coord)); |
|
| 98 | + |
|
| 99 | + if ($p->etoile === '*') { |
|
| 100 | + include_spip('balise/url_'); |
|
| 101 | + $lien = generer_generer_url_arg($type, $p, $_id_objet); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $connect = $p->id_boucle ? $p->boucles[$p->id_boucle]->sql_serveur : ''; |
|
| 105 | + if ($type == 'document') { |
|
| 106 | + $qconnect = _q($connect); |
|
| 107 | + $doc = "quete_document($_id_objet, $qconnect)"; |
|
| 108 | + if ($fichier) { |
|
| 109 | + $code = "quete_logo_file($doc, $qconnect)"; |
|
| 110 | + } else { |
|
| 111 | + $code = "quete_logo_document($doc, " . ($lien ?: "''") . ", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)"; |
|
| 112 | + } |
|
| 113 | + // (x=non-faux ? y : '') pour affecter x en retournant y |
|
| 114 | + if ($p->descr['documents']) { |
|
| 115 | + $code = '(($doublons["documents"] .= ",". ' |
|
| 116 | + . $_id_objet |
|
| 117 | + . ") ? $code : '')"; |
|
| 118 | + } |
|
| 119 | + } elseif ($connect) { |
|
| 120 | + $code = "''"; |
|
| 121 | + spip_log('Les logos distants ne sont pas prevus'); |
|
| 122 | + } else { |
|
| 123 | + $code = logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $lien, $p, $suite_logo); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + // demande de reduction sur logo avec ecriture spip 2.1 : #LOGO_xxx{200, 0} |
|
| 127 | + if ($coord_x or $coord_y) { |
|
| 128 | + $code = "filtrer('image_graver',filtrer('image_reduire'," . $code . ", '$coord_x', '$coord_y'))"; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + $p->code = $code; |
|
| 132 | + $p->interdire_scripts = false; |
|
| 133 | + |
|
| 134 | + return $p; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -158,20 +158,20 @@ discard block |
||
| 158 | 158 | * Code compilé retournant le chemin du logo ou le code HTML du logo. |
| 159 | 159 | **/ |
| 160 | 160 | function logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $_lien, $p, $suite) { |
| 161 | - $code = "quete_logo('$id_objet', '" . |
|
| 162 | - (($suite == '_SURVOL') ? 'off' : |
|
| 163 | - (($suite == '_NORMAL') ? 'on' : 'ON')) . |
|
| 164 | - "', $_id_objet," . |
|
| 165 | - (($suite == '_RUBRIQUE') ? |
|
| 166 | - champ_sql('id_rubrique', $p) : |
|
| 167 | - (($type == 'rubrique') ? "quete_parent($_id_objet)" : "''")) . |
|
| 168 | - ', ' . intval($fichier) . ')'; |
|
| 169 | - |
|
| 170 | - if ($fichier) { |
|
| 171 | - return $code; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - $align = preg_replace(',\W,', '', $align); |
|
| 175 | - |
|
| 176 | - return "quete_html_logo($code, '$align', " . ($_lien ?: "''") . ')'; |
|
| 161 | + $code = "quete_logo('$id_objet', '" . |
|
| 162 | + (($suite == '_SURVOL') ? 'off' : |
|
| 163 | + (($suite == '_NORMAL') ? 'on' : 'ON')) . |
|
| 164 | + "', $_id_objet," . |
|
| 165 | + (($suite == '_RUBRIQUE') ? |
|
| 166 | + champ_sql('id_rubrique', $p) : |
|
| 167 | + (($type == 'rubrique') ? "quete_parent($_id_objet)" : "''")) . |
|
| 168 | + ', ' . intval($fichier) . ')'; |
|
| 169 | + |
|
| 170 | + if ($fichier) { |
|
| 171 | + return $code; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + $align = preg_replace(',\W,', '', $align); |
|
| 175 | + |
|
| 176 | + return "quete_html_logo($code, '$align', " . ($_lien ?: "''") . ')'; |
|
| 177 | 177 | } |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | if ($fichier) { |
| 109 | 109 | $code = "quete_logo_file($doc, $qconnect)"; |
| 110 | 110 | } else { |
| 111 | - $code = "quete_logo_document($doc, " . ($lien ?: "''") . ", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)"; |
|
| 111 | + $code = "quete_logo_document($doc, ".($lien ?: "''").", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)"; |
|
| 112 | 112 | } |
| 113 | 113 | // (x=non-faux ? y : '') pour affecter x en retournant y |
| 114 | 114 | if ($p->descr['documents']) { |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | // demande de reduction sur logo avec ecriture spip 2.1 : #LOGO_xxx{200, 0} |
| 127 | 127 | if ($coord_x or $coord_y) { |
| 128 | - $code = "filtrer('image_graver',filtrer('image_reduire'," . $code . ", '$coord_x', '$coord_y'))"; |
|
| 128 | + $code = "filtrer('image_graver',filtrer('image_reduire',".$code.", '$coord_x', '$coord_y'))"; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | $p->code = $code; |
@@ -158,14 +158,12 @@ discard block |
||
| 158 | 158 | * Code compilé retournant le chemin du logo ou le code HTML du logo. |
| 159 | 159 | **/ |
| 160 | 160 | function logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $_lien, $p, $suite) { |
| 161 | - $code = "quete_logo('$id_objet', '" . |
|
| 162 | - (($suite == '_SURVOL') ? 'off' : |
|
| 163 | - (($suite == '_NORMAL') ? 'on' : 'ON')) . |
|
| 164 | - "', $_id_objet," . |
|
| 161 | + $code = "quete_logo('$id_objet', '". |
|
| 162 | + (($suite == '_SURVOL') ? 'off' : (($suite == '_NORMAL') ? 'on' : 'ON')). |
|
| 163 | + "', $_id_objet,". |
|
| 165 | 164 | (($suite == '_RUBRIQUE') ? |
| 166 | - champ_sql('id_rubrique', $p) : |
|
| 167 | - (($type == 'rubrique') ? "quete_parent($_id_objet)" : "''")) . |
|
| 168 | - ', ' . intval($fichier) . ')'; |
|
| 165 | + champ_sql('id_rubrique', $p) : (($type == 'rubrique') ? "quete_parent($_id_objet)" : "''")). |
|
| 166 | + ', '.intval($fichier).')'; |
|
| 169 | 167 | |
| 170 | 168 | if ($fichier) { |
| 171 | 169 | return $code; |
@@ -173,5 +171,5 @@ discard block |
||
| 173 | 171 | |
| 174 | 172 | $align = preg_replace(',\W,', '', $align); |
| 175 | 173 | |
| 176 | - return "quete_html_logo($code, '$align', " . ($_lien ?: "''") . ')'; |
|
| 174 | + return "quete_html_logo($code, '$align', ".($_lien ?: "''").')'; |
|
| 177 | 175 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * Pile complétée du code compilé |
| 37 | 37 | **/ |
| 38 | 38 | function balise_URL_LOGOUT($p) { |
| 39 | - return calculer_balise_dynamique($p, 'URL_LOGOUT', []); |
|
| 39 | + return calculer_balise_dynamique($p, 'URL_LOGOUT', []); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | |
@@ -52,9 +52,9 @@ discard block |
||
| 52 | 52 | * Liste (url) des arguments collectés. |
| 53 | 53 | */ |
| 54 | 54 | function balise_URL_LOGOUT_stat($args, $context_compil) { |
| 55 | - $url = $args[0] ?? ''; |
|
| 55 | + $url = $args[0] ?? ''; |
|
| 56 | 56 | |
| 57 | - return [$url]; |
|
| 57 | + return [$url]; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | **/ |
| 70 | 70 | function balise_URL_LOGOUT_dyn($cible) { |
| 71 | 71 | |
| 72 | - if (empty($GLOBALS['visiteur_session']['login']) and empty($GLOBALS['visiteur_session']['statut'])) { |
|
| 73 | - return ''; |
|
| 74 | - } |
|
| 72 | + if (empty($GLOBALS['visiteur_session']['login']) and empty($GLOBALS['visiteur_session']['statut'])) { |
|
| 73 | + return ''; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - return generer_url_action('logout', 'logout=public&url=' . rawurlencode($cible ?: self('&'))); |
|
| 76 | + return generer_url_action('logout', 'logout=public&url=' . rawurlencode($cible ?: self('&'))); |
|
| 77 | 77 | } |
@@ -73,5 +73,5 @@ |
||
| 73 | 73 | return ''; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - return generer_url_action('logout', 'logout=public&url=' . rawurlencode($cible ?: self('&'))); |
|
| 76 | + return generer_url_action('logout', 'logout=public&url='.rawurlencode($cible ?: self('&'))); |
|
| 77 | 77 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('base/abstract_sql'); |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * Pile complétée du code compilé |
| 44 | 44 | **/ |
| 45 | 45 | function balise_FORMULAIRE_INSCRIPTION($p) { |
| 46 | - return calculer_balise_dynamique($p, 'FORMULAIRE_INSCRIPTION', []); |
|
| 46 | + return calculer_balise_dynamique($p, 'FORMULAIRE_INSCRIPTION', []); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -72,9 +72,9 @@ discard block |
||
| 72 | 72 | * - chaîne vide sinon. |
| 73 | 73 | */ |
| 74 | 74 | function balise_FORMULAIRE_INSCRIPTION_stat($args, $context_compil) { |
| 75 | - [$mode, $id, $retour] = array_pad($args, 3, null); |
|
| 76 | - include_spip('action/inscrire_auteur'); |
|
| 77 | - $mode = tester_statut_inscription($mode, $id ?? 0); |
|
| 75 | + [$mode, $id, $retour] = array_pad($args, 3, null); |
|
| 76 | + include_spip('action/inscrire_auteur'); |
|
| 77 | + $mode = tester_statut_inscription($mode, $id ?? 0); |
|
| 78 | 78 | |
| 79 | - return $mode ? [$mode, $id, $retour] : ''; |
|
| 79 | + return $mode ? [$mode, $id, $retour] : ''; |
|
| 80 | 80 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | **/ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | // Ce fichier doit imperativement definir la fonction ci-dessous: |
@@ -39,59 +39,59 @@ discard block |
||
| 39 | 39 | * @return array |
| 40 | 40 | */ |
| 41 | 41 | function public_styliser_dist($fond, $contexte, $lang = '', string $connect = '') { |
| 42 | - static $styliser_par_z; |
|
| 43 | - |
|
| 44 | - // s'assurer que le fond est licite |
|
| 45 | - // car il peut etre construit a partir d'une variable d'environnement |
|
| 46 | - if (strpos($fond, '../') !== false or strncmp($fond, '/', 1) == 0) { |
|
| 47 | - $fond = '404'; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - if (strncmp($fond, 'modeles/', 8) == 0) { |
|
| 51 | - $modele = substr($fond, 8); |
|
| 52 | - $modele = styliser_modele($modele, null, $contexte); |
|
| 53 | - $fond = "modeles/$modele"; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - // Choisir entre $fond-dist.html, $fond=7.html, etc? |
|
| 57 | - $id_rubrique = 0; |
|
| 58 | - // Chercher le fond qui va servir de squelette |
|
| 59 | - if ($r = quete_rubrique_fond($contexte)) { |
|
| 60 | - [$id_rubrique, $lang] = $r; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // trouver un squelette du nom demande |
|
| 64 | - // ne rien dire si on ne trouve pas, |
|
| 65 | - // c'est l'appelant qui sait comment gerer la situation |
|
| 66 | - // ou les plugins qui feront mieux dans le pipeline |
|
| 67 | - $squelette = trouver_fond($fond, '', true); |
|
| 68 | - $ext = $squelette['extension']; |
|
| 69 | - |
|
| 70 | - $flux = [ |
|
| 71 | - 'args' => [ |
|
| 72 | - 'id_rubrique' => $id_rubrique, |
|
| 73 | - 'ext' => $ext, |
|
| 74 | - 'fond' => $fond, |
|
| 75 | - 'lang' => $lang, |
|
| 76 | - 'contexte' => $contexte, // le style d'un objet peut dependre de lui meme |
|
| 77 | - 'connect' => $connect |
|
| 78 | - ], |
|
| 79 | - 'data' => $squelette['fond'], |
|
| 80 | - ]; |
|
| 81 | - |
|
| 82 | - if (test_espace_prive() or defined('_ZPIP')) { |
|
| 83 | - if (!$styliser_par_z) { |
|
| 84 | - $styliser_par_z = charger_fonction('styliser_par_z', 'public'); |
|
| 85 | - } |
|
| 86 | - $flux = $styliser_par_z($flux); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $flux = styliser_par_objets($flux); |
|
| 90 | - |
|
| 91 | - // pipeline styliser |
|
| 92 | - $squelette = pipeline('styliser', $flux); |
|
| 93 | - |
|
| 94 | - return [$squelette, $ext, $ext, "$squelette.$ext"]; |
|
| 42 | + static $styliser_par_z; |
|
| 43 | + |
|
| 44 | + // s'assurer que le fond est licite |
|
| 45 | + // car il peut etre construit a partir d'une variable d'environnement |
|
| 46 | + if (strpos($fond, '../') !== false or strncmp($fond, '/', 1) == 0) { |
|
| 47 | + $fond = '404'; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + if (strncmp($fond, 'modeles/', 8) == 0) { |
|
| 51 | + $modele = substr($fond, 8); |
|
| 52 | + $modele = styliser_modele($modele, null, $contexte); |
|
| 53 | + $fond = "modeles/$modele"; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + // Choisir entre $fond-dist.html, $fond=7.html, etc? |
|
| 57 | + $id_rubrique = 0; |
|
| 58 | + // Chercher le fond qui va servir de squelette |
|
| 59 | + if ($r = quete_rubrique_fond($contexte)) { |
|
| 60 | + [$id_rubrique, $lang] = $r; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // trouver un squelette du nom demande |
|
| 64 | + // ne rien dire si on ne trouve pas, |
|
| 65 | + // c'est l'appelant qui sait comment gerer la situation |
|
| 66 | + // ou les plugins qui feront mieux dans le pipeline |
|
| 67 | + $squelette = trouver_fond($fond, '', true); |
|
| 68 | + $ext = $squelette['extension']; |
|
| 69 | + |
|
| 70 | + $flux = [ |
|
| 71 | + 'args' => [ |
|
| 72 | + 'id_rubrique' => $id_rubrique, |
|
| 73 | + 'ext' => $ext, |
|
| 74 | + 'fond' => $fond, |
|
| 75 | + 'lang' => $lang, |
|
| 76 | + 'contexte' => $contexte, // le style d'un objet peut dependre de lui meme |
|
| 77 | + 'connect' => $connect |
|
| 78 | + ], |
|
| 79 | + 'data' => $squelette['fond'], |
|
| 80 | + ]; |
|
| 81 | + |
|
| 82 | + if (test_espace_prive() or defined('_ZPIP')) { |
|
| 83 | + if (!$styliser_par_z) { |
|
| 84 | + $styliser_par_z = charger_fonction('styliser_par_z', 'public'); |
|
| 85 | + } |
|
| 86 | + $flux = $styliser_par_z($flux); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $flux = styliser_par_objets($flux); |
|
| 90 | + |
|
| 91 | + // pipeline styliser |
|
| 92 | + $squelette = pipeline('styliser', $flux); |
|
| 93 | + |
|
| 94 | + return [$squelette, $ext, $ext, "$squelette.$ext"]; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -110,32 +110,32 @@ discard block |
||
| 110 | 110 | * Données du pipeline styliser |
| 111 | 111 | **/ |
| 112 | 112 | function styliser_par_objets($flux) { |
| 113 | - if ( |
|
| 114 | - test_espace_prive() |
|
| 115 | - and !$squelette = $flux['data'] |
|
| 116 | - and strncmp($flux['args']['fond'], 'prive/objets/', 13) == 0 |
|
| 117 | - and $echafauder = charger_fonction('echafauder', 'prive', true) |
|
| 118 | - ) { |
|
| 119 | - if (strncmp($flux['args']['fond'], 'prive/objets/liste/', 19) == 0) { |
|
| 120 | - $table = table_objet(substr($flux['args']['fond'], 19)); |
|
| 121 | - $table_sql = table_objet_sql($table); |
|
| 122 | - $objets = lister_tables_objets_sql(); |
|
| 123 | - if (isset($objets[$table_sql])) { |
|
| 124 | - $flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - if (strncmp($flux['args']['fond'], 'prive/objets/contenu/', 21) == 0) { |
|
| 128 | - $type = substr($flux['args']['fond'], 21); |
|
| 129 | - $table = table_objet($type); |
|
| 130 | - $table_sql = table_objet_sql($table); |
|
| 131 | - $objets = lister_tables_objets_sql(); |
|
| 132 | - if (isset($objets[$table_sql])) { |
|
| 133 | - $flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $flux; |
|
| 113 | + if ( |
|
| 114 | + test_espace_prive() |
|
| 115 | + and !$squelette = $flux['data'] |
|
| 116 | + and strncmp($flux['args']['fond'], 'prive/objets/', 13) == 0 |
|
| 117 | + and $echafauder = charger_fonction('echafauder', 'prive', true) |
|
| 118 | + ) { |
|
| 119 | + if (strncmp($flux['args']['fond'], 'prive/objets/liste/', 19) == 0) { |
|
| 120 | + $table = table_objet(substr($flux['args']['fond'], 19)); |
|
| 121 | + $table_sql = table_objet_sql($table); |
|
| 122 | + $objets = lister_tables_objets_sql(); |
|
| 123 | + if (isset($objets[$table_sql])) { |
|
| 124 | + $flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + if (strncmp($flux['args']['fond'], 'prive/objets/contenu/', 21) == 0) { |
|
| 128 | + $type = substr($flux['args']['fond'], 21); |
|
| 129 | + $table = table_objet($type); |
|
| 130 | + $table_sql = table_objet_sql($table); |
|
| 131 | + $objets = lister_tables_objets_sql(); |
|
| 132 | + if (isset($objets[$table_sql])) { |
|
| 133 | + $flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return $flux; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -151,50 +151,50 @@ discard block |
||
| 151 | 151 | * @return array |
| 152 | 152 | */ |
| 153 | 153 | function quete_rubrique_fond($contexte) { |
| 154 | - static $liste_objets = null; |
|
| 155 | - static $quete = []; |
|
| 156 | - if (is_null($liste_objets)) { |
|
| 157 | - $liste_objets = []; |
|
| 158 | - include_spip('inc/urls'); |
|
| 159 | - include_spip('public/quete'); |
|
| 160 | - $l = urls_liste_objets(false); |
|
| 161 | - // placer la rubrique en tete des objets |
|
| 162 | - $l = array_diff($l, ['rubrique']); |
|
| 163 | - array_unshift($l, 'rubrique'); |
|
| 164 | - foreach ($l as $objet) { |
|
| 165 | - $id = id_table_objet($objet); |
|
| 166 | - if (!isset($liste_objets[$id])) { |
|
| 167 | - $liste_objets[$id] = objet_type($objet, false); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - $c = array_intersect_key($contexte, $liste_objets); |
|
| 172 | - if (!count($c)) { |
|
| 173 | - return false; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - $c = array_map('intval', $c); |
|
| 177 | - $s = serialize($c); |
|
| 178 | - if (isset($quete[$s])) { |
|
| 179 | - return $quete[$s]; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - if (isset($c['id_rubrique']) and $r = $c['id_rubrique']) { |
|
| 183 | - unset($c['id_rubrique']); |
|
| 184 | - $c = ['id_rubrique' => $r] + $c; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - foreach ($c as $_id => $id) { |
|
| 188 | - if ( |
|
| 189 | - $id |
|
| 190 | - and $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id) |
|
| 191 | - ) { |
|
| 192 | - $lang = $row['lang'] ?? ''; |
|
| 193 | - if ($_id == 'id_rubrique' or (isset($row['id_rubrique']) and $id = $row['id_rubrique'])) { |
|
| 194 | - return $quete[$s] = [$id, $lang]; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - return $quete[$s] = false; |
|
| 154 | + static $liste_objets = null; |
|
| 155 | + static $quete = []; |
|
| 156 | + if (is_null($liste_objets)) { |
|
| 157 | + $liste_objets = []; |
|
| 158 | + include_spip('inc/urls'); |
|
| 159 | + include_spip('public/quete'); |
|
| 160 | + $l = urls_liste_objets(false); |
|
| 161 | + // placer la rubrique en tete des objets |
|
| 162 | + $l = array_diff($l, ['rubrique']); |
|
| 163 | + array_unshift($l, 'rubrique'); |
|
| 164 | + foreach ($l as $objet) { |
|
| 165 | + $id = id_table_objet($objet); |
|
| 166 | + if (!isset($liste_objets[$id])) { |
|
| 167 | + $liste_objets[$id] = objet_type($objet, false); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + $c = array_intersect_key($contexte, $liste_objets); |
|
| 172 | + if (!count($c)) { |
|
| 173 | + return false; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + $c = array_map('intval', $c); |
|
| 177 | + $s = serialize($c); |
|
| 178 | + if (isset($quete[$s])) { |
|
| 179 | + return $quete[$s]; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + if (isset($c['id_rubrique']) and $r = $c['id_rubrique']) { |
|
| 183 | + unset($c['id_rubrique']); |
|
| 184 | + $c = ['id_rubrique' => $r] + $c; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + foreach ($c as $_id => $id) { |
|
| 188 | + if ( |
|
| 189 | + $id |
|
| 190 | + and $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id) |
|
| 191 | + ) { |
|
| 192 | + $lang = $row['lang'] ?? ''; |
|
| 193 | + if ($_id == 'id_rubrique' or (isset($row['id_rubrique']) and $id = $row['id_rubrique'])) { |
|
| 194 | + return $quete[$s] = [$id, $lang]; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + return $quete[$s] = false; |
|
| 200 | 200 | } |
@@ -53,8 +53,7 @@ discard block |
||
| 53 | 53 | // (pas glop) |
| 54 | 54 | try { |
| 55 | 55 | switch (is_countable($a) ? count($a) : 0) { |
| 56 | - case 0: |
|
| 57 | - $iter = new $iterateur(); |
|
| 56 | + case 0 : $iter = new $iterateur(); |
|
| 58 | 57 | break; |
| 59 | 58 | case 1: |
| 60 | 59 | $iter = new $iterateur($a[0]); |
@@ -79,10 +78,10 @@ discard block |
||
| 79 | 78 | // chercher la classe d'iterateur |
| 80 | 79 | // IterateurXXX |
| 81 | 80 | // definie dans le fichier iterateurs/xxx.php |
| 82 | - $class = 'Iterateur' . $iterateur; |
|
| 81 | + $class = 'Iterateur'.$iterateur; |
|
| 83 | 82 | if (!class_exists($class)) { |
| 84 | 83 | if ( |
| 85 | - !include_spip('iterateur/' . strtolower($iterateur)) |
|
| 84 | + !include_spip('iterateur/'.strtolower($iterateur)) |
|
| 86 | 85 | or !class_exists($class) |
| 87 | 86 | ) { |
| 88 | 87 | die("Iterateur $iterateur non trouvé"); |
@@ -210,7 +209,7 @@ discard block |
||
| 210 | 209 | return $this->iter->$nom(); |
| 211 | 210 | } catch (Exception $e) { |
| 212 | 211 | // #GETCHILDREN sur un fichier de DirectoryIterator ... |
| 213 | - spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 212 | + spip_log("Methode $nom en echec sur ".get_class($this->iter)); |
|
| 214 | 213 | spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
| 215 | 214 | |
| 216 | 215 | return ''; |
@@ -259,7 +258,7 @@ discard block |
||
| 259 | 258 | // Creer la fonction de filtrage sur $this |
| 260 | 259 | if ($this->filtre) { |
| 261 | 260 | if ($filtres = $this->assembler_filtres($this->filtre)) { |
| 262 | - $filtres = 'return ' . $filtres . ';'; |
|
| 261 | + $filtres = 'return '.$filtres.';'; |
|
| 263 | 262 | $this->func_filtre = fn() => eval($filtres); |
| 264 | 263 | } |
| 265 | 264 | else { |
@@ -294,7 +293,7 @@ discard block |
||
| 294 | 293 | return null; |
| 295 | 294 | } |
| 296 | 295 | |
| 297 | - return '(' . implode(") $operateur (", $filtres_string) . ')'; |
|
| 296 | + return '('.implode(") $operateur (", $filtres_string).')'; |
|
| 298 | 297 | } |
| 299 | 298 | |
| 300 | 299 | /** |
@@ -375,7 +374,7 @@ discard block |
||
| 375 | 374 | return $this->composer_filtre($v[1], $v[0], $v[2]); |
| 376 | 375 | } |
| 377 | 376 | |
| 378 | - return null; // sera ignore |
|
| 377 | + return null; // sera ignore |
|
| 379 | 378 | } |
| 380 | 379 | |
| 381 | 380 | /** |
@@ -401,28 +400,28 @@ discard block |
||
| 401 | 400 | # if (!in_array($cle, array('cle', 'valeur'))) |
| 402 | 401 | # return; |
| 403 | 402 | |
| 404 | - $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 403 | + $a = '$this->get_select(\''.$cle.'\')'; |
|
| 405 | 404 | |
| 406 | 405 | $filtre = ''; |
| 407 | 406 | |
| 408 | 407 | if ($op == 'REGEXP') { |
| 409 | - $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 408 | + $filtre = 'filtrer("match", '.$a.', '.str_replace('\"', '"', $valeur).')'; |
|
| 410 | 409 | $op = ''; |
| 411 | 410 | } else { |
| 412 | 411 | if ($op == 'LIKE') { |
| 413 | 412 | $valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote($valeur)); |
| 414 | - $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 413 | + $filtre = 'filtrer("match", '.$a.', '.$valeur.')'; |
|
| 415 | 414 | $op = ''; |
| 416 | 415 | } else { |
| 417 | 416 | if ($op == '=') { |
| 418 | 417 | $op = '=='; |
| 419 | 418 | } else { |
| 420 | 419 | if ($op == 'IN') { |
| 421 | - $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 420 | + $filtre = 'in_array('.$a.', array'.$valeur.')'; |
|
| 422 | 421 | $op = ''; |
| 423 | 422 | } else { |
| 424 | 423 | if (!in_array($op, ['<', '<=', '>', '>='])) { |
| 425 | - spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 424 | + spip_log('operateur non reconnu '.$op); // [todo] mettre une erreur de squelette |
|
| 426 | 425 | $op = ''; |
| 427 | 426 | } |
| 428 | 427 | } |
@@ -431,7 +430,7 @@ discard block |
||
| 431 | 430 | } |
| 432 | 431 | |
| 433 | 432 | if ($op) { |
| 434 | - $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 433 | + $filtre = $a.$op.str_replace('\"', '"', $valeur); |
|
| 435 | 434 | } |
| 436 | 435 | |
| 437 | 436 | if ($not) { |
@@ -261,8 +261,7 @@ discard block |
||
| 261 | 261 | if ($filtres = $this->assembler_filtres($this->filtre)) { |
| 262 | 262 | $filtres = 'return ' . $filtres . ';'; |
| 263 | 263 | $this->func_filtre = fn() => eval($filtres); |
| 264 | - } |
|
| 265 | - else { |
|
| 264 | + } else { |
|
| 266 | 265 | $this->func_filtre = null; |
| 267 | 266 | } |
| 268 | 267 | } |
@@ -345,16 +344,14 @@ discard block |
||
| 345 | 344 | $v[$k] = $this->traduire_condition_sql_en_filtre($v[$k]); |
| 346 | 345 | if ($v[$k] === null) { |
| 347 | 346 | unset($v[$k]); |
| 348 | - } |
|
| 349 | - elseif ($v[$k] === 'true') { |
|
| 347 | + } elseif ($v[$k] === 'true') { |
|
| 350 | 348 | if ($op === 'OR') { |
| 351 | 349 | return 'true'; |
| 352 | 350 | } |
| 353 | 351 | if ($op === 'AND') { |
| 354 | 352 | unset($v[$k]); |
| 355 | 353 | } |
| 356 | - } |
|
| 357 | - elseif ($v[$k] === 'false') { |
|
| 354 | + } elseif ($v[$k] === 'false') { |
|
| 358 | 355 | if ($op === 'OR') { |
| 359 | 356 | unset($v[$k]); |
| 360 | 357 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -21,667 +21,667 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | */ |
| 23 | 23 | class IterFactory { |
| 24 | - public static function create($iterateur, $command, $info = null) { |
|
| 25 | - |
|
| 26 | - $iter = null; |
|
| 27 | - // cas des SI {si expression} analises tres tot |
|
| 28 | - // pour eviter le chargement de tout iterateur |
|
| 29 | - if (isset($command['si'])) { |
|
| 30 | - foreach ($command['si'] as $si) { |
|
| 31 | - if (!$si) { |
|
| 32 | - // $command pour boucle SQL peut generer des erreurs de compilation |
|
| 33 | - // s'il est transmis alors qu'on est dans un iterateur vide |
|
| 34 | - return new IterDecorator(new EmptyIterator(), [], $info); |
|
| 35 | - } |
|
| 36 | - } |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - // chercher un iterateur PHP existant (par exemple dans SPL) |
|
| 40 | - // (il faudrait passer l'argument ->sql_serveur |
|
| 41 | - // pour etre certain qu'on est sur un "php:") |
|
| 42 | - if (class_exists($iterateur)) { |
|
| 43 | - $a = $command['args'] ?? []; |
|
| 44 | - |
|
| 45 | - // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 46 | - // si on recoit deja un iterateur en argument, on l'utilise |
|
| 47 | - if ((is_countable($a) ? count($a) : 0) == 1 and is_object($a[0]) and is_subclass_of($a[0], \Iterator::class)) { |
|
| 48 | - $iter = $a[0]; |
|
| 49 | - |
|
| 50 | - // sinon, on cree un iterateur du type donne |
|
| 51 | - } else { |
|
| 52 | - // arguments de creation de l'iterateur... |
|
| 53 | - // (pas glop) |
|
| 54 | - try { |
|
| 55 | - switch (is_countable($a) ? count($a) : 0) { |
|
| 56 | - case 0: |
|
| 57 | - $iter = new $iterateur(); |
|
| 58 | - break; |
|
| 59 | - case 1: |
|
| 60 | - $iter = new $iterateur($a[0]); |
|
| 61 | - break; |
|
| 62 | - case 2: |
|
| 63 | - $iter = new $iterateur($a[0], $a[1]); |
|
| 64 | - break; |
|
| 65 | - case 3: |
|
| 66 | - $iter = new $iterateur($a[0], $a[1], $a[2]); |
|
| 67 | - break; |
|
| 68 | - case 4: |
|
| 69 | - $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]); |
|
| 70 | - break; |
|
| 71 | - } |
|
| 72 | - } catch (Exception $e) { |
|
| 73 | - spip_log("Erreur de chargement de l'iterateur $iterateur"); |
|
| 74 | - spip_log($e->getMessage()); |
|
| 75 | - $iter = new EmptyIterator(); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - } else { |
|
| 79 | - // chercher la classe d'iterateur |
|
| 80 | - // IterateurXXX |
|
| 81 | - // definie dans le fichier iterateurs/xxx.php |
|
| 82 | - $class = 'Iterateur' . $iterateur; |
|
| 83 | - if (!class_exists($class)) { |
|
| 84 | - if ( |
|
| 85 | - !include_spip('iterateur/' . strtolower($iterateur)) |
|
| 86 | - or !class_exists($class) |
|
| 87 | - ) { |
|
| 88 | - die("Iterateur $iterateur non trouvé"); |
|
| 89 | - // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 90 | - # $iter = new EmptyIterator(); |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - $iter = new $class($command, $info); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - return new IterDecorator($iter, $command, $info); |
|
| 97 | - } |
|
| 24 | + public static function create($iterateur, $command, $info = null) { |
|
| 25 | + |
|
| 26 | + $iter = null; |
|
| 27 | + // cas des SI {si expression} analises tres tot |
|
| 28 | + // pour eviter le chargement de tout iterateur |
|
| 29 | + if (isset($command['si'])) { |
|
| 30 | + foreach ($command['si'] as $si) { |
|
| 31 | + if (!$si) { |
|
| 32 | + // $command pour boucle SQL peut generer des erreurs de compilation |
|
| 33 | + // s'il est transmis alors qu'on est dans un iterateur vide |
|
| 34 | + return new IterDecorator(new EmptyIterator(), [], $info); |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + // chercher un iterateur PHP existant (par exemple dans SPL) |
|
| 40 | + // (il faudrait passer l'argument ->sql_serveur |
|
| 41 | + // pour etre certain qu'on est sur un "php:") |
|
| 42 | + if (class_exists($iterateur)) { |
|
| 43 | + $a = $command['args'] ?? []; |
|
| 44 | + |
|
| 45 | + // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 46 | + // si on recoit deja un iterateur en argument, on l'utilise |
|
| 47 | + if ((is_countable($a) ? count($a) : 0) == 1 and is_object($a[0]) and is_subclass_of($a[0], \Iterator::class)) { |
|
| 48 | + $iter = $a[0]; |
|
| 49 | + |
|
| 50 | + // sinon, on cree un iterateur du type donne |
|
| 51 | + } else { |
|
| 52 | + // arguments de creation de l'iterateur... |
|
| 53 | + // (pas glop) |
|
| 54 | + try { |
|
| 55 | + switch (is_countable($a) ? count($a) : 0) { |
|
| 56 | + case 0: |
|
| 57 | + $iter = new $iterateur(); |
|
| 58 | + break; |
|
| 59 | + case 1: |
|
| 60 | + $iter = new $iterateur($a[0]); |
|
| 61 | + break; |
|
| 62 | + case 2: |
|
| 63 | + $iter = new $iterateur($a[0], $a[1]); |
|
| 64 | + break; |
|
| 65 | + case 3: |
|
| 66 | + $iter = new $iterateur($a[0], $a[1], $a[2]); |
|
| 67 | + break; |
|
| 68 | + case 4: |
|
| 69 | + $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]); |
|
| 70 | + break; |
|
| 71 | + } |
|
| 72 | + } catch (Exception $e) { |
|
| 73 | + spip_log("Erreur de chargement de l'iterateur $iterateur"); |
|
| 74 | + spip_log($e->getMessage()); |
|
| 75 | + $iter = new EmptyIterator(); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + } else { |
|
| 79 | + // chercher la classe d'iterateur |
|
| 80 | + // IterateurXXX |
|
| 81 | + // definie dans le fichier iterateurs/xxx.php |
|
| 82 | + $class = 'Iterateur' . $iterateur; |
|
| 83 | + if (!class_exists($class)) { |
|
| 84 | + if ( |
|
| 85 | + !include_spip('iterateur/' . strtolower($iterateur)) |
|
| 86 | + or !class_exists($class) |
|
| 87 | + ) { |
|
| 88 | + die("Iterateur $iterateur non trouvé"); |
|
| 89 | + // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 90 | + # $iter = new EmptyIterator(); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + $iter = new $class($command, $info); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + return new IterDecorator($iter, $command, $info); |
|
| 97 | + } |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | |
| 101 | 101 | class IterDecorator extends FilterIterator { |
| 102 | - private $iter; |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Conditions de filtrage |
|
| 106 | - * ie criteres de selection |
|
| 107 | - * |
|
| 108 | - * @var array |
|
| 109 | - */ |
|
| 110 | - protected $filtre = []; |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Fonction de filtrage compilee a partir des criteres de filtre |
|
| 114 | - * |
|
| 115 | - * @var string |
|
| 116 | - */ |
|
| 117 | - protected $func_filtre = null; |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Critere {offset, limit} |
|
| 121 | - * |
|
| 122 | - * @var int |
|
| 123 | - * @var int |
|
| 124 | - */ |
|
| 125 | - protected $offset = null; |
|
| 126 | - protected $limit = null; |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * nombre d'elements recuperes depuis la position 0, |
|
| 130 | - * en tenant compte des filtres |
|
| 131 | - * |
|
| 132 | - * @var int |
|
| 133 | - */ |
|
| 134 | - protected $fetched = 0; |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Y a t'il une erreur ? |
|
| 138 | - * |
|
| 139 | - * @var bool |
|
| 140 | - **/ |
|
| 141 | - protected $err = false; |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Drapeau a activer en cas d'echec |
|
| 145 | - * (select SQL errone, non chargement des DATA, etc) |
|
| 146 | - */ |
|
| 147 | - public function err() { |
|
| 148 | - if (method_exists($this->iter, 'err')) { |
|
| 149 | - return $this->iter->err(); |
|
| 150 | - } |
|
| 151 | - if (property_exists($this->iter, 'err')) { |
|
| 152 | - return $this->iter->err; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - return false; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - public function __construct(Iterator $iter, $command, $info) { |
|
| 159 | - parent::__construct($iter); |
|
| 160 | - parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 161 | - |
|
| 162 | - // recuperer l'iterateur transmis |
|
| 163 | - $this->iter = $this->getInnerIterator(); |
|
| 164 | - $this->command = $command; |
|
| 165 | - $this->info = $info; |
|
| 166 | - $this->pos = 0; |
|
| 167 | - $this->fetched = 0; |
|
| 168 | - |
|
| 169 | - // chercher la liste des champs a retourner par |
|
| 170 | - // fetch si l'objet ne les calcule pas tout seul |
|
| 171 | - if (!method_exists($this->iter, 'fetch')) { |
|
| 172 | - $this->calculer_select(); |
|
| 173 | - $this->calculer_filtres(); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 177 | - if (isset($this->iter->err)) { |
|
| 178 | - $this->err = $this->iter->err; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 182 | - //$this->total = $this->count(); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - // calcule les elements a retournes par fetch() |
|
| 187 | - // enleve les elements inutiles du select() |
|
| 188 | - // |
|
| 189 | - private function calculer_select() { |
|
| 190 | - if ($select = &$this->command['select']) { |
|
| 191 | - foreach ($select as $s) { |
|
| 192 | - // /!\ $s = '.nom' |
|
| 193 | - if ($s[0] == '.') { |
|
| 194 | - $s = substr($s, 1); |
|
| 195 | - } |
|
| 196 | - $this->select[] = $s; |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // recuperer la valeur d'une balise #X |
|
| 202 | - // en fonction des methodes |
|
| 203 | - // et proprietes disponibles |
|
| 204 | - public function get_select($nom) { |
|
| 205 | - if ( |
|
| 206 | - is_object($this->iter) |
|
| 207 | - and method_exists($this->iter, $nom) |
|
| 208 | - ) { |
|
| 209 | - try { |
|
| 210 | - return $this->iter->$nom(); |
|
| 211 | - } catch (Exception $e) { |
|
| 212 | - // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 213 | - spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 214 | - spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 215 | - |
|
| 216 | - return ''; |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - /* |
|
| 102 | + private $iter; |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Conditions de filtrage |
|
| 106 | + * ie criteres de selection |
|
| 107 | + * |
|
| 108 | + * @var array |
|
| 109 | + */ |
|
| 110 | + protected $filtre = []; |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Fonction de filtrage compilee a partir des criteres de filtre |
|
| 114 | + * |
|
| 115 | + * @var string |
|
| 116 | + */ |
|
| 117 | + protected $func_filtre = null; |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Critere {offset, limit} |
|
| 121 | + * |
|
| 122 | + * @var int |
|
| 123 | + * @var int |
|
| 124 | + */ |
|
| 125 | + protected $offset = null; |
|
| 126 | + protected $limit = null; |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * nombre d'elements recuperes depuis la position 0, |
|
| 130 | + * en tenant compte des filtres |
|
| 131 | + * |
|
| 132 | + * @var int |
|
| 133 | + */ |
|
| 134 | + protected $fetched = 0; |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Y a t'il une erreur ? |
|
| 138 | + * |
|
| 139 | + * @var bool |
|
| 140 | + **/ |
|
| 141 | + protected $err = false; |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Drapeau a activer en cas d'echec |
|
| 145 | + * (select SQL errone, non chargement des DATA, etc) |
|
| 146 | + */ |
|
| 147 | + public function err() { |
|
| 148 | + if (method_exists($this->iter, 'err')) { |
|
| 149 | + return $this->iter->err(); |
|
| 150 | + } |
|
| 151 | + if (property_exists($this->iter, 'err')) { |
|
| 152 | + return $this->iter->err; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + return false; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + public function __construct(Iterator $iter, $command, $info) { |
|
| 159 | + parent::__construct($iter); |
|
| 160 | + parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 161 | + |
|
| 162 | + // recuperer l'iterateur transmis |
|
| 163 | + $this->iter = $this->getInnerIterator(); |
|
| 164 | + $this->command = $command; |
|
| 165 | + $this->info = $info; |
|
| 166 | + $this->pos = 0; |
|
| 167 | + $this->fetched = 0; |
|
| 168 | + |
|
| 169 | + // chercher la liste des champs a retourner par |
|
| 170 | + // fetch si l'objet ne les calcule pas tout seul |
|
| 171 | + if (!method_exists($this->iter, 'fetch')) { |
|
| 172 | + $this->calculer_select(); |
|
| 173 | + $this->calculer_filtres(); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 177 | + if (isset($this->iter->err)) { |
|
| 178 | + $this->err = $this->iter->err; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 182 | + //$this->total = $this->count(); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + // calcule les elements a retournes par fetch() |
|
| 187 | + // enleve les elements inutiles du select() |
|
| 188 | + // |
|
| 189 | + private function calculer_select() { |
|
| 190 | + if ($select = &$this->command['select']) { |
|
| 191 | + foreach ($select as $s) { |
|
| 192 | + // /!\ $s = '.nom' |
|
| 193 | + if ($s[0] == '.') { |
|
| 194 | + $s = substr($s, 1); |
|
| 195 | + } |
|
| 196 | + $this->select[] = $s; |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // recuperer la valeur d'une balise #X |
|
| 202 | + // en fonction des methodes |
|
| 203 | + // et proprietes disponibles |
|
| 204 | + public function get_select($nom) { |
|
| 205 | + if ( |
|
| 206 | + is_object($this->iter) |
|
| 207 | + and method_exists($this->iter, $nom) |
|
| 208 | + ) { |
|
| 209 | + try { |
|
| 210 | + return $this->iter->$nom(); |
|
| 211 | + } catch (Exception $e) { |
|
| 212 | + // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 213 | + spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 214 | + spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 215 | + |
|
| 216 | + return ''; |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + /* |
|
| 220 | 220 | if (property_exists($this->iter, $nom)) { |
| 221 | 221 | return $this->iter->$nom; |
| 222 | 222 | }*/ |
| 223 | - // cle et valeur par defaut |
|
| 224 | - // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 225 | - if ( |
|
| 226 | - in_array($nom, ['cle', 'valeur']) |
|
| 227 | - and method_exists($this, $nom) |
|
| 228 | - ) { |
|
| 229 | - return $this->$nom(); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - // Par defaut chercher en xpath dans la valeur() |
|
| 233 | - return table_valeur($this->valeur(), $nom, null); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - |
|
| 237 | - private function calculer_filtres() { |
|
| 238 | - |
|
| 239 | - // Issu de calculer_select() de public/composer L.519 |
|
| 240 | - // TODO: externaliser... |
|
| 241 | - // |
|
| 242 | - // retirer les criteres vides: |
|
| 243 | - // {X ?} avec X absent de l'URL |
|
| 244 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 245 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 246 | - if ($where = &$this->command['where']) { |
|
| 247 | - foreach ($where as $k => $v) { |
|
| 248 | - $this->filtre[] = $this->traduire_condition_sql_en_filtre($v); |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - // critere {2,7} |
|
| 253 | - if (isset($this->command['limit']) and $this->command['limit']) { |
|
| 254 | - $limit = explode(',', $this->command['limit']); |
|
| 255 | - $this->offset = $limit[0]; |
|
| 256 | - $this->limit = $limit[1]; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - // Creer la fonction de filtrage sur $this |
|
| 260 | - if ($this->filtre) { |
|
| 261 | - if ($filtres = $this->assembler_filtres($this->filtre)) { |
|
| 262 | - $filtres = 'return ' . $filtres . ';'; |
|
| 263 | - $this->func_filtre = fn() => eval($filtres); |
|
| 264 | - } |
|
| 265 | - else { |
|
| 266 | - $this->func_filtre = null; |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * Assembler le tableau de filtres traduits depuis les conditions SQL |
|
| 273 | - * les filtres vides ou null sont ignores |
|
| 274 | - * @param $filtres |
|
| 275 | - * @param string $operateur |
|
| 276 | - * @return string|null |
|
| 277 | - */ |
|
| 278 | - protected function assembler_filtres($filtres, $operateur = 'AND') { |
|
| 279 | - |
|
| 280 | - $filtres_string = []; |
|
| 281 | - foreach ($filtres as $k => $v) { |
|
| 282 | - // si c'est un tableau de OR/AND + 2 sous-filtres, on recurse pour transformer en chaine |
|
| 283 | - if (is_array($v) and in_array(reset($v), ['OR', 'AND'])) { |
|
| 284 | - $op = array_shift($v); |
|
| 285 | - $v = $this->assembler_filtres($v, $op); |
|
| 286 | - } |
|
| 287 | - if (is_null($v) or !is_string($v) or empty($v)) { |
|
| 288 | - continue; |
|
| 289 | - } |
|
| 290 | - $filtres_string[] = $v; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - if (!count($filtres_string)) { |
|
| 294 | - return null; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - return '(' . implode(") $operateur (", $filtres_string) . ')'; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * Traduire un element du tableau where SQL en un filtre |
|
| 302 | - * @param $v |
|
| 303 | - * @return string|array|null |
|
| 304 | - */ |
|
| 305 | - protected function traduire_condition_sql_en_filtre($v) { |
|
| 306 | - if (is_array($v)) { |
|
| 307 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 308 | - return 'true'; |
|
| 309 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 310 | - return 'true'; |
|
| 311 | - } else { |
|
| 312 | - $op = $v[0] ?: $v; |
|
| 313 | - } |
|
| 314 | - } else { |
|
| 315 | - $op = $v; |
|
| 316 | - } |
|
| 317 | - if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 318 | - return 'true'; |
|
| 319 | - } |
|
| 320 | - if ($op === '0=1') { |
|
| 321 | - return 'false'; |
|
| 322 | - } |
|
| 323 | - // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 324 | - if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', $op, $regs)) { |
|
| 325 | - return $this->composer_filtre($regs[1], 'IN', $regs[3], $regs[2]); |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - // 3 possibilites : count($v) = |
|
| 329 | - // * 1 : {x y} ; on recoit $v[0] = y |
|
| 330 | - // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 331 | - // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 332 | - |
|
| 333 | - // 1 : forcement traite par un critere, on passe |
|
| 334 | - if (!$v or !is_array($v) or count($v) == 1) { |
|
| 335 | - return null; // sera ignore |
|
| 336 | - } |
|
| 337 | - if (count($v) == 2 and is_array($v[1])) { |
|
| 338 | - return $this->composer_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 339 | - } |
|
| 340 | - if (count($v) == 3) { |
|
| 341 | - // traiter le OR/AND suivi de 2 valeurs |
|
| 342 | - if (in_array($op, ['OR', 'AND'])) { |
|
| 343 | - array_shift($v); |
|
| 344 | - foreach (array_keys($v) as $k) { |
|
| 345 | - $v[$k] = $this->traduire_condition_sql_en_filtre($v[$k]); |
|
| 346 | - if ($v[$k] === null) { |
|
| 347 | - unset($v[$k]); |
|
| 348 | - } |
|
| 349 | - elseif ($v[$k] === 'true') { |
|
| 350 | - if ($op === 'OR') { |
|
| 351 | - return 'true'; |
|
| 352 | - } |
|
| 353 | - if ($op === 'AND') { |
|
| 354 | - unset($v[$k]); |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - elseif ($v[$k] === 'false') { |
|
| 358 | - if ($op === 'OR') { |
|
| 359 | - unset($v[$k]); |
|
| 360 | - } |
|
| 361 | - if ($op === 'AND') { |
|
| 362 | - return 'false'; |
|
| 363 | - } |
|
| 364 | - } |
|
| 365 | - } |
|
| 366 | - if (!count($v)) { |
|
| 367 | - return null; |
|
| 368 | - } |
|
| 369 | - if (count($v) === 1) { |
|
| 370 | - return reset($v); |
|
| 371 | - } |
|
| 372 | - array_unshift($v, $op); |
|
| 373 | - return $v; |
|
| 374 | - } |
|
| 375 | - return $this->composer_filtre($v[1], $v[0], $v[2]); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - return null; // sera ignore |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * Calculer un filtre sur un champ du tableau |
|
| 383 | - * @param $cle |
|
| 384 | - * @param $op |
|
| 385 | - * @param $valeur |
|
| 386 | - * @param false $not |
|
| 387 | - * @return string|null |
|
| 388 | - */ |
|
| 389 | - protected function composer_filtre($cle, $op, $valeur, $not = false) { |
|
| 390 | - if (method_exists($this->iter, 'exception_des_criteres')) { |
|
| 391 | - if (in_array($cle, $this->iter->exception_des_criteres())) { |
|
| 392 | - return null; |
|
| 393 | - } |
|
| 394 | - } |
|
| 395 | - // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 396 | - # mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 397 | - # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 398 | - # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 399 | - # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 400 | - |
|
| 401 | - # if (!in_array($cle, array('cle', 'valeur'))) |
|
| 402 | - # return; |
|
| 403 | - |
|
| 404 | - $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 405 | - |
|
| 406 | - $filtre = ''; |
|
| 407 | - |
|
| 408 | - if ($op == 'REGEXP') { |
|
| 409 | - $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 410 | - $op = ''; |
|
| 411 | - } else { |
|
| 412 | - if ($op == 'LIKE') { |
|
| 413 | - $valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote($valeur)); |
|
| 414 | - $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 415 | - $op = ''; |
|
| 416 | - } else { |
|
| 417 | - if ($op == '=') { |
|
| 418 | - $op = '=='; |
|
| 419 | - } else { |
|
| 420 | - if ($op == 'IN') { |
|
| 421 | - $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 422 | - $op = ''; |
|
| 423 | - } else { |
|
| 424 | - if (!in_array($op, ['<', '<=', '>', '>='])) { |
|
| 425 | - spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 426 | - $op = ''; |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - if ($op) { |
|
| 434 | - $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - if ($not) { |
|
| 438 | - $filtre = "!($filtre)"; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - return $filtre; |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - |
|
| 445 | - public function next(): void { |
|
| 446 | - $this->pos++; |
|
| 447 | - parent::next(); |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * revient au depart |
|
| 452 | - * |
|
| 453 | - * @return void |
|
| 454 | - */ |
|
| 455 | - public function rewind(): void { |
|
| 456 | - $this->pos = 0; |
|
| 457 | - $this->fetched = 0; |
|
| 458 | - parent::rewind(); |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - |
|
| 462 | - # Extension SPIP des iterateurs PHP |
|
| 463 | - /** |
|
| 464 | - * type de l'iterateur |
|
| 465 | - * |
|
| 466 | - * @var string |
|
| 467 | - */ |
|
| 468 | - protected $type; |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * parametres de l'iterateur |
|
| 472 | - * |
|
| 473 | - * @var array |
|
| 474 | - */ |
|
| 475 | - protected $command; |
|
| 476 | - |
|
| 477 | - /** |
|
| 478 | - * infos de compilateur |
|
| 479 | - * |
|
| 480 | - * @var array |
|
| 481 | - */ |
|
| 482 | - protected $info; |
|
| 483 | - |
|
| 484 | - /** |
|
| 485 | - * position courante de l'iterateur |
|
| 486 | - * |
|
| 487 | - * @var int |
|
| 488 | - */ |
|
| 489 | - protected $pos = null; |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * nombre total resultats dans l'iterateur |
|
| 493 | - * |
|
| 494 | - * @var int |
|
| 495 | - */ |
|
| 496 | - protected $total = null; |
|
| 497 | - |
|
| 498 | - /** |
|
| 499 | - * nombre maximal de recherche pour $total |
|
| 500 | - * si l'iterateur n'implemente pas de fonction specifique |
|
| 501 | - */ |
|
| 502 | - protected $max = 100000; |
|
| 503 | - |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * Liste des champs a inserer dans les $row |
|
| 507 | - * retournes par ->fetch() |
|
| 508 | - */ |
|
| 509 | - protected $select = []; |
|
| 510 | - |
|
| 511 | - |
|
| 512 | - /** |
|
| 513 | - * aller a la position absolue n, |
|
| 514 | - * comptee depuis le debut |
|
| 515 | - * |
|
| 516 | - * @param int $n |
|
| 517 | - * absolute pos |
|
| 518 | - * @param string $continue |
|
| 519 | - * param for sql_ api |
|
| 520 | - * @return bool |
|
| 521 | - * success or fail if not implemented |
|
| 522 | - */ |
|
| 523 | - public function seek($n = 0, $continue = null) { |
|
| 524 | - if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) { |
|
| 525 | - $this->seek_loop($n); |
|
| 526 | - } |
|
| 527 | - $this->pos = $n; |
|
| 528 | - $this->fetched = $n; |
|
| 529 | - |
|
| 530 | - return true; |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - /* |
|
| 223 | + // cle et valeur par defaut |
|
| 224 | + // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 225 | + if ( |
|
| 226 | + in_array($nom, ['cle', 'valeur']) |
|
| 227 | + and method_exists($this, $nom) |
|
| 228 | + ) { |
|
| 229 | + return $this->$nom(); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + // Par defaut chercher en xpath dans la valeur() |
|
| 233 | + return table_valeur($this->valeur(), $nom, null); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + |
|
| 237 | + private function calculer_filtres() { |
|
| 238 | + |
|
| 239 | + // Issu de calculer_select() de public/composer L.519 |
|
| 240 | + // TODO: externaliser... |
|
| 241 | + // |
|
| 242 | + // retirer les criteres vides: |
|
| 243 | + // {X ?} avec X absent de l'URL |
|
| 244 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 245 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 246 | + if ($where = &$this->command['where']) { |
|
| 247 | + foreach ($where as $k => $v) { |
|
| 248 | + $this->filtre[] = $this->traduire_condition_sql_en_filtre($v); |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + // critere {2,7} |
|
| 253 | + if (isset($this->command['limit']) and $this->command['limit']) { |
|
| 254 | + $limit = explode(',', $this->command['limit']); |
|
| 255 | + $this->offset = $limit[0]; |
|
| 256 | + $this->limit = $limit[1]; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + // Creer la fonction de filtrage sur $this |
|
| 260 | + if ($this->filtre) { |
|
| 261 | + if ($filtres = $this->assembler_filtres($this->filtre)) { |
|
| 262 | + $filtres = 'return ' . $filtres . ';'; |
|
| 263 | + $this->func_filtre = fn() => eval($filtres); |
|
| 264 | + } |
|
| 265 | + else { |
|
| 266 | + $this->func_filtre = null; |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * Assembler le tableau de filtres traduits depuis les conditions SQL |
|
| 273 | + * les filtres vides ou null sont ignores |
|
| 274 | + * @param $filtres |
|
| 275 | + * @param string $operateur |
|
| 276 | + * @return string|null |
|
| 277 | + */ |
|
| 278 | + protected function assembler_filtres($filtres, $operateur = 'AND') { |
|
| 279 | + |
|
| 280 | + $filtres_string = []; |
|
| 281 | + foreach ($filtres as $k => $v) { |
|
| 282 | + // si c'est un tableau de OR/AND + 2 sous-filtres, on recurse pour transformer en chaine |
|
| 283 | + if (is_array($v) and in_array(reset($v), ['OR', 'AND'])) { |
|
| 284 | + $op = array_shift($v); |
|
| 285 | + $v = $this->assembler_filtres($v, $op); |
|
| 286 | + } |
|
| 287 | + if (is_null($v) or !is_string($v) or empty($v)) { |
|
| 288 | + continue; |
|
| 289 | + } |
|
| 290 | + $filtres_string[] = $v; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + if (!count($filtres_string)) { |
|
| 294 | + return null; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + return '(' . implode(") $operateur (", $filtres_string) . ')'; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * Traduire un element du tableau where SQL en un filtre |
|
| 302 | + * @param $v |
|
| 303 | + * @return string|array|null |
|
| 304 | + */ |
|
| 305 | + protected function traduire_condition_sql_en_filtre($v) { |
|
| 306 | + if (is_array($v)) { |
|
| 307 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 308 | + return 'true'; |
|
| 309 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 310 | + return 'true'; |
|
| 311 | + } else { |
|
| 312 | + $op = $v[0] ?: $v; |
|
| 313 | + } |
|
| 314 | + } else { |
|
| 315 | + $op = $v; |
|
| 316 | + } |
|
| 317 | + if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 318 | + return 'true'; |
|
| 319 | + } |
|
| 320 | + if ($op === '0=1') { |
|
| 321 | + return 'false'; |
|
| 322 | + } |
|
| 323 | + // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 324 | + if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', $op, $regs)) { |
|
| 325 | + return $this->composer_filtre($regs[1], 'IN', $regs[3], $regs[2]); |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + // 3 possibilites : count($v) = |
|
| 329 | + // * 1 : {x y} ; on recoit $v[0] = y |
|
| 330 | + // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 331 | + // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 332 | + |
|
| 333 | + // 1 : forcement traite par un critere, on passe |
|
| 334 | + if (!$v or !is_array($v) or count($v) == 1) { |
|
| 335 | + return null; // sera ignore |
|
| 336 | + } |
|
| 337 | + if (count($v) == 2 and is_array($v[1])) { |
|
| 338 | + return $this->composer_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 339 | + } |
|
| 340 | + if (count($v) == 3) { |
|
| 341 | + // traiter le OR/AND suivi de 2 valeurs |
|
| 342 | + if (in_array($op, ['OR', 'AND'])) { |
|
| 343 | + array_shift($v); |
|
| 344 | + foreach (array_keys($v) as $k) { |
|
| 345 | + $v[$k] = $this->traduire_condition_sql_en_filtre($v[$k]); |
|
| 346 | + if ($v[$k] === null) { |
|
| 347 | + unset($v[$k]); |
|
| 348 | + } |
|
| 349 | + elseif ($v[$k] === 'true') { |
|
| 350 | + if ($op === 'OR') { |
|
| 351 | + return 'true'; |
|
| 352 | + } |
|
| 353 | + if ($op === 'AND') { |
|
| 354 | + unset($v[$k]); |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + elseif ($v[$k] === 'false') { |
|
| 358 | + if ($op === 'OR') { |
|
| 359 | + unset($v[$k]); |
|
| 360 | + } |
|
| 361 | + if ($op === 'AND') { |
|
| 362 | + return 'false'; |
|
| 363 | + } |
|
| 364 | + } |
|
| 365 | + } |
|
| 366 | + if (!count($v)) { |
|
| 367 | + return null; |
|
| 368 | + } |
|
| 369 | + if (count($v) === 1) { |
|
| 370 | + return reset($v); |
|
| 371 | + } |
|
| 372 | + array_unshift($v, $op); |
|
| 373 | + return $v; |
|
| 374 | + } |
|
| 375 | + return $this->composer_filtre($v[1], $v[0], $v[2]); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + return null; // sera ignore |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * Calculer un filtre sur un champ du tableau |
|
| 383 | + * @param $cle |
|
| 384 | + * @param $op |
|
| 385 | + * @param $valeur |
|
| 386 | + * @param false $not |
|
| 387 | + * @return string|null |
|
| 388 | + */ |
|
| 389 | + protected function composer_filtre($cle, $op, $valeur, $not = false) { |
|
| 390 | + if (method_exists($this->iter, 'exception_des_criteres')) { |
|
| 391 | + if (in_array($cle, $this->iter->exception_des_criteres())) { |
|
| 392 | + return null; |
|
| 393 | + } |
|
| 394 | + } |
|
| 395 | + // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 396 | + # mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 397 | + # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 398 | + # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 399 | + # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 400 | + |
|
| 401 | + # if (!in_array($cle, array('cle', 'valeur'))) |
|
| 402 | + # return; |
|
| 403 | + |
|
| 404 | + $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 405 | + |
|
| 406 | + $filtre = ''; |
|
| 407 | + |
|
| 408 | + if ($op == 'REGEXP') { |
|
| 409 | + $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 410 | + $op = ''; |
|
| 411 | + } else { |
|
| 412 | + if ($op == 'LIKE') { |
|
| 413 | + $valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote($valeur)); |
|
| 414 | + $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 415 | + $op = ''; |
|
| 416 | + } else { |
|
| 417 | + if ($op == '=') { |
|
| 418 | + $op = '=='; |
|
| 419 | + } else { |
|
| 420 | + if ($op == 'IN') { |
|
| 421 | + $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 422 | + $op = ''; |
|
| 423 | + } else { |
|
| 424 | + if (!in_array($op, ['<', '<=', '>', '>='])) { |
|
| 425 | + spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 426 | + $op = ''; |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + if ($op) { |
|
| 434 | + $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + if ($not) { |
|
| 438 | + $filtre = "!($filtre)"; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + return $filtre; |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + |
|
| 445 | + public function next(): void { |
|
| 446 | + $this->pos++; |
|
| 447 | + parent::next(); |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * revient au depart |
|
| 452 | + * |
|
| 453 | + * @return void |
|
| 454 | + */ |
|
| 455 | + public function rewind(): void { |
|
| 456 | + $this->pos = 0; |
|
| 457 | + $this->fetched = 0; |
|
| 458 | + parent::rewind(); |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + |
|
| 462 | + # Extension SPIP des iterateurs PHP |
|
| 463 | + /** |
|
| 464 | + * type de l'iterateur |
|
| 465 | + * |
|
| 466 | + * @var string |
|
| 467 | + */ |
|
| 468 | + protected $type; |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * parametres de l'iterateur |
|
| 472 | + * |
|
| 473 | + * @var array |
|
| 474 | + */ |
|
| 475 | + protected $command; |
|
| 476 | + |
|
| 477 | + /** |
|
| 478 | + * infos de compilateur |
|
| 479 | + * |
|
| 480 | + * @var array |
|
| 481 | + */ |
|
| 482 | + protected $info; |
|
| 483 | + |
|
| 484 | + /** |
|
| 485 | + * position courante de l'iterateur |
|
| 486 | + * |
|
| 487 | + * @var int |
|
| 488 | + */ |
|
| 489 | + protected $pos = null; |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * nombre total resultats dans l'iterateur |
|
| 493 | + * |
|
| 494 | + * @var int |
|
| 495 | + */ |
|
| 496 | + protected $total = null; |
|
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * nombre maximal de recherche pour $total |
|
| 500 | + * si l'iterateur n'implemente pas de fonction specifique |
|
| 501 | + */ |
|
| 502 | + protected $max = 100000; |
|
| 503 | + |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * Liste des champs a inserer dans les $row |
|
| 507 | + * retournes par ->fetch() |
|
| 508 | + */ |
|
| 509 | + protected $select = []; |
|
| 510 | + |
|
| 511 | + |
|
| 512 | + /** |
|
| 513 | + * aller a la position absolue n, |
|
| 514 | + * comptee depuis le debut |
|
| 515 | + * |
|
| 516 | + * @param int $n |
|
| 517 | + * absolute pos |
|
| 518 | + * @param string $continue |
|
| 519 | + * param for sql_ api |
|
| 520 | + * @return bool |
|
| 521 | + * success or fail if not implemented |
|
| 522 | + */ |
|
| 523 | + public function seek($n = 0, $continue = null) { |
|
| 524 | + if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) { |
|
| 525 | + $this->seek_loop($n); |
|
| 526 | + } |
|
| 527 | + $this->pos = $n; |
|
| 528 | + $this->fetched = $n; |
|
| 529 | + |
|
| 530 | + return true; |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + /* |
|
| 534 | 534 | * aller a la position $n en parcourant |
| 535 | 535 | * un par un tous les elements |
| 536 | 536 | */ |
| 537 | - private function seek_loop($n) { |
|
| 538 | - if ($this->pos > $n) { |
|
| 539 | - $this->rewind(); |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - while ($this->pos < $n and $this->valid()) { |
|
| 543 | - $this->next(); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - return true; |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * Avancer de $saut pas |
|
| 551 | - * |
|
| 552 | - * @param $saut |
|
| 553 | - * @param $max |
|
| 554 | - * @return int |
|
| 555 | - */ |
|
| 556 | - public function skip($saut, $max = null) { |
|
| 557 | - // pas de saut en arriere autorise pour cette fonction |
|
| 558 | - if (($saut = intval($saut)) <= 0) { |
|
| 559 | - return $this->pos; |
|
| 560 | - } |
|
| 561 | - $seek = $this->pos + $saut; |
|
| 562 | - // si le saut fait depasser le maxi, on libere la resource |
|
| 563 | - // et on sort |
|
| 564 | - if (is_null($max)) { |
|
| 565 | - $max = $this->count(); |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - if ($seek >= $max or $seek >= $this->count()) { |
|
| 569 | - // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 570 | - $this->free(); |
|
| 571 | - |
|
| 572 | - return $max; |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - $this->seek($seek); |
|
| 576 | - |
|
| 577 | - return $this->pos; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * Renvoyer un tableau des donnees correspondantes |
|
| 582 | - * a la position courante de l'iterateur |
|
| 583 | - * en controlant si on respecte le filtre |
|
| 584 | - * Appliquer aussi le critere {offset,limit} |
|
| 585 | - * |
|
| 586 | - * @return array|bool |
|
| 587 | - */ |
|
| 588 | - public function fetch() { |
|
| 589 | - if (method_exists($this->iter, 'fetch')) { |
|
| 590 | - return $this->iter->fetch(); |
|
| 591 | - } else { |
|
| 592 | - while ( |
|
| 593 | - $this->valid() |
|
| 594 | - and ( |
|
| 595 | - !$this->accept() |
|
| 596 | - or (isset($this->offset) and $this->fetched++ < $this->offset) |
|
| 597 | - ) |
|
| 598 | - ) { |
|
| 599 | - $this->next(); |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - if (!$this->valid()) { |
|
| 603 | - return false; |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - if ( |
|
| 607 | - isset($this->limit) |
|
| 608 | - and $this->fetched > $this->offset + $this->limit |
|
| 609 | - ) { |
|
| 610 | - return false; |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - $r = []; |
|
| 614 | - foreach ($this->select as $nom) { |
|
| 615 | - $r[$nom] = $this->get_select($nom); |
|
| 616 | - } |
|
| 617 | - $this->next(); |
|
| 618 | - |
|
| 619 | - return $r; |
|
| 620 | - } |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - // retourner la cle pour #CLE |
|
| 624 | - public function cle() { |
|
| 625 | - return $this->key(); |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - // retourner la valeur pour #VALEUR |
|
| 629 | - public function valeur() { |
|
| 630 | - return $this->current(); |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - /** |
|
| 634 | - * Accepte-t-on l'entree courante lue ? |
|
| 635 | - * On execute les filtres pour le savoir. |
|
| 636 | - **/ |
|
| 637 | - public function accept(): bool { |
|
| 638 | - if ($f = $this->func_filtre) { |
|
| 639 | - return $f(); |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - return true; |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - /** |
|
| 646 | - * liberer la ressource |
|
| 647 | - * |
|
| 648 | - * @return bool |
|
| 649 | - */ |
|
| 650 | - public function free() { |
|
| 651 | - if (method_exists($this->iter, 'free')) { |
|
| 652 | - $this->iter->free(); |
|
| 653 | - } |
|
| 654 | - $this->pos = $this->total = 0; |
|
| 655 | - |
|
| 656 | - return true; |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - /** |
|
| 660 | - * Compter le nombre total de resultats |
|
| 661 | - * pour #TOTAL_BOUCLE |
|
| 662 | - * |
|
| 663 | - * @return int |
|
| 664 | - */ |
|
| 665 | - public function count() { |
|
| 666 | - if (is_null($this->total)) { |
|
| 667 | - if ( |
|
| 668 | - method_exists($this->iter, 'count') |
|
| 669 | - and !$this->func_filtre |
|
| 670 | - ) { |
|
| 671 | - return $this->total = $this->iter->count(); |
|
| 672 | - } else { |
|
| 673 | - // compter les lignes et rembobiner |
|
| 674 | - $total = 0; |
|
| 675 | - $pos = $this->pos; // sauver la position |
|
| 676 | - $this->rewind(); |
|
| 677 | - while ($this->fetch() and $total < $this->max) { |
|
| 678 | - $total++; |
|
| 679 | - } |
|
| 680 | - $this->seek($pos); |
|
| 681 | - $this->total = $total; |
|
| 682 | - } |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - return $this->total; |
|
| 686 | - } |
|
| 537 | + private function seek_loop($n) { |
|
| 538 | + if ($this->pos > $n) { |
|
| 539 | + $this->rewind(); |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + while ($this->pos < $n and $this->valid()) { |
|
| 543 | + $this->next(); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + return true; |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * Avancer de $saut pas |
|
| 551 | + * |
|
| 552 | + * @param $saut |
|
| 553 | + * @param $max |
|
| 554 | + * @return int |
|
| 555 | + */ |
|
| 556 | + public function skip($saut, $max = null) { |
|
| 557 | + // pas de saut en arriere autorise pour cette fonction |
|
| 558 | + if (($saut = intval($saut)) <= 0) { |
|
| 559 | + return $this->pos; |
|
| 560 | + } |
|
| 561 | + $seek = $this->pos + $saut; |
|
| 562 | + // si le saut fait depasser le maxi, on libere la resource |
|
| 563 | + // et on sort |
|
| 564 | + if (is_null($max)) { |
|
| 565 | + $max = $this->count(); |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + if ($seek >= $max or $seek >= $this->count()) { |
|
| 569 | + // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 570 | + $this->free(); |
|
| 571 | + |
|
| 572 | + return $max; |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + $this->seek($seek); |
|
| 576 | + |
|
| 577 | + return $this->pos; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * Renvoyer un tableau des donnees correspondantes |
|
| 582 | + * a la position courante de l'iterateur |
|
| 583 | + * en controlant si on respecte le filtre |
|
| 584 | + * Appliquer aussi le critere {offset,limit} |
|
| 585 | + * |
|
| 586 | + * @return array|bool |
|
| 587 | + */ |
|
| 588 | + public function fetch() { |
|
| 589 | + if (method_exists($this->iter, 'fetch')) { |
|
| 590 | + return $this->iter->fetch(); |
|
| 591 | + } else { |
|
| 592 | + while ( |
|
| 593 | + $this->valid() |
|
| 594 | + and ( |
|
| 595 | + !$this->accept() |
|
| 596 | + or (isset($this->offset) and $this->fetched++ < $this->offset) |
|
| 597 | + ) |
|
| 598 | + ) { |
|
| 599 | + $this->next(); |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + if (!$this->valid()) { |
|
| 603 | + return false; |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + if ( |
|
| 607 | + isset($this->limit) |
|
| 608 | + and $this->fetched > $this->offset + $this->limit |
|
| 609 | + ) { |
|
| 610 | + return false; |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + $r = []; |
|
| 614 | + foreach ($this->select as $nom) { |
|
| 615 | + $r[$nom] = $this->get_select($nom); |
|
| 616 | + } |
|
| 617 | + $this->next(); |
|
| 618 | + |
|
| 619 | + return $r; |
|
| 620 | + } |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + // retourner la cle pour #CLE |
|
| 624 | + public function cle() { |
|
| 625 | + return $this->key(); |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + // retourner la valeur pour #VALEUR |
|
| 629 | + public function valeur() { |
|
| 630 | + return $this->current(); |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + /** |
|
| 634 | + * Accepte-t-on l'entree courante lue ? |
|
| 635 | + * On execute les filtres pour le savoir. |
|
| 636 | + **/ |
|
| 637 | + public function accept(): bool { |
|
| 638 | + if ($f = $this->func_filtre) { |
|
| 639 | + return $f(); |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + return true; |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + /** |
|
| 646 | + * liberer la ressource |
|
| 647 | + * |
|
| 648 | + * @return bool |
|
| 649 | + */ |
|
| 650 | + public function free() { |
|
| 651 | + if (method_exists($this->iter, 'free')) { |
|
| 652 | + $this->iter->free(); |
|
| 653 | + } |
|
| 654 | + $this->pos = $this->total = 0; |
|
| 655 | + |
|
| 656 | + return true; |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + /** |
|
| 660 | + * Compter le nombre total de resultats |
|
| 661 | + * pour #TOTAL_BOUCLE |
|
| 662 | + * |
|
| 663 | + * @return int |
|
| 664 | + */ |
|
| 665 | + public function count() { |
|
| 666 | + if (is_null($this->total)) { |
|
| 667 | + if ( |
|
| 668 | + method_exists($this->iter, 'count') |
|
| 669 | + and !$this->func_filtre |
|
| 670 | + ) { |
|
| 671 | + return $this->total = $this->iter->count(); |
|
| 672 | + } else { |
|
| 673 | + // compter les lignes et rembobiner |
|
| 674 | + $total = 0; |
|
| 675 | + $pos = $this->pos; // sauver la position |
|
| 676 | + $this->rewind(); |
|
| 677 | + while ($this->fetch() and $total < $this->max) { |
|
| 678 | + $total++; |
|
| 679 | + } |
|
| 680 | + $this->seek($pos); |
|
| 681 | + $this->total = $total; |
|
| 682 | + } |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + return $this->total; |
|
| 686 | + } |
|
| 687 | 687 | } |