@@ -116,8 +116,6 @@ |
||
| 116 | 116 | * - 'nom' (= id) |
| 117 | 117 | * - 'compatibilite' (= version) |
| 118 | 118 | * |
| 119 | - * @param array $utilise |
|
| 120 | - * Liste des necessite trouvés pour le plugin |
|
| 121 | 119 | * @return array |
| 122 | 120 | * Liste des necessite modifiés. |
| 123 | 121 | */ |
@@ -15,90 +15,90 @@ discard block |
||
| 15 | 15 | // lecture d'un texte ecrit en pseudo-xml issu d'un fichier plugin.xml |
| 16 | 16 | // et conversion approximative en tableau PHP. |
| 17 | 17 | function plugins_infos_plugin($desc, $plug='', $dir_plugins=_DIR_PLUGINS) { |
| 18 | - include_spip('inc/xml'); |
|
| 19 | - $arbre = spip_xml_parse($desc); |
|
| 20 | - |
|
| 21 | - $verifie_conformite = charger_fonction('verifie_conformite','plugins'); |
|
| 22 | - $verifie_conformite($plug, $arbre, $dir_plugins); |
|
| 23 | - |
|
| 24 | - include_spip('inc/charsets'); |
|
| 25 | - |
|
| 26 | - // On renvoie la DTD utilisee |
|
| 27 | - $ret['dtd'] = "plugin"; |
|
| 28 | - |
|
| 29 | - if (isset($arbre['categorie'])) |
|
| 30 | - $ret['categorie'] = trim(spip_xml_aplatit($arbre['categorie'])); |
|
| 31 | - if (isset($arbre['nom'])) |
|
| 32 | - $ret['nom'] = charset2unicode(spip_xml_aplatit($arbre['nom'])); |
|
| 33 | - if (isset($arbre['icon'])) |
|
| 34 | - $ret['logo'] = trim(spip_xml_aplatit($arbre['icon'])); |
|
| 35 | - if (isset($arbre['auteur'])) |
|
| 36 | - $ret['auteur'][] = trim(spip_xml_aplatit($arbre['auteur'])); // garder le 1er niveau en tableau mais traiter le multi possible |
|
| 37 | - if (isset($arbre['licence'])) |
|
| 38 | - $ret['licence'][] = trim(spip_xml_aplatit($arbre['licence'])); |
|
| 39 | - if (isset($arbre['version'])) |
|
| 40 | - $ret['version'] = trim(spip_xml_aplatit($arbre['version'])); |
|
| 41 | - if (isset($arbre['version_base'])) |
|
| 42 | - $ret['schema'] = trim(spip_xml_aplatit($arbre['version_base'])); |
|
| 43 | - if (isset($arbre['etat'])) |
|
| 44 | - $ret['etat'] = trim(spip_xml_aplatit($arbre['etat'])); |
|
| 45 | - |
|
| 46 | - $ret['description'] = $ret['slogan'] = ""; |
|
| 47 | - if (isset($arbre['slogan'])) |
|
| 48 | - $ret['slogan'] = trim(spip_xml_aplatit($arbre['slogan'])); |
|
| 49 | - if (isset($arbre['description'])){ |
|
| 50 | - $ret['description'] = trim(spip_xml_aplatit($arbre['description'])); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - if (isset($arbre['lien'])){ |
|
| 54 | - $ret['documentation'] = trim(join(' ',$arbre['lien'])); |
|
| 55 | - if ($ret['documentation']) { |
|
| 56 | - // le lien de doc doit etre une url et c'est tout |
|
| 57 | - if (!preg_match(',^https?://,iS', $ret['documentation'])) |
|
| 58 | - $ret['documentation'] = ""; |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - if (isset($arbre['options'])) |
|
| 63 | - $ret['options'] = $arbre['options']; |
|
| 64 | - if (isset($arbre['fonctions'])) |
|
| 65 | - $ret['fonctions'] = $arbre['fonctions']; |
|
| 66 | - if (isset($arbre['prefix'][0])) |
|
| 67 | - $ret['prefix'] = trim(array_pop($arbre['prefix'])); |
|
| 68 | - if (isset($arbre['install'])) |
|
| 69 | - $ret['install'] = $arbre['install']; |
|
| 70 | - if (isset($arbre['meta'])) |
|
| 71 | - $ret['meta'] = trim(spip_xml_aplatit($arbre['meta'])); |
|
| 72 | - |
|
| 73 | - $necessite = info_plugin_normalise_necessite($arbre['necessite']); |
|
| 74 | - $ret['compatibilite'] = isset($necessite['compatible'])?$necessite['compatible']:''; |
|
| 75 | - $ret['necessite'] = $necessite['necessite']; |
|
| 76 | - $ret['lib'] = $necessite['lib']; |
|
| 77 | - $ret['utilise'] = info_plugin_normalise_utilise($arbre['utilise']); |
|
| 78 | - $ret['procure'] = info_plugin_normalise_procure($arbre['procure']); |
|
| 79 | - $ret['chemin'] = info_plugin_normalise_chemin($arbre['path']); |
|
| 80 | - |
|
| 81 | - if (isset($arbre['pipeline'])) |
|
| 82 | - $ret['pipeline'] = $arbre['pipeline']; |
|
| 83 | - |
|
| 84 | - $extraire_boutons = charger_fonction('extraire_boutons','plugins'); |
|
| 85 | - $les_boutons = $extraire_boutons($arbre); |
|
| 86 | - $ret['menu'] = $les_boutons['bouton']; |
|
| 87 | - $ret['onglet'] = $les_boutons['onglet']; |
|
| 88 | - |
|
| 89 | - $ret['traduire'] = $arbre['traduire']; |
|
| 18 | + include_spip('inc/xml'); |
|
| 19 | + $arbre = spip_xml_parse($desc); |
|
| 20 | + |
|
| 21 | + $verifie_conformite = charger_fonction('verifie_conformite','plugins'); |
|
| 22 | + $verifie_conformite($plug, $arbre, $dir_plugins); |
|
| 23 | + |
|
| 24 | + include_spip('inc/charsets'); |
|
| 25 | + |
|
| 26 | + // On renvoie la DTD utilisee |
|
| 27 | + $ret['dtd'] = "plugin"; |
|
| 28 | + |
|
| 29 | + if (isset($arbre['categorie'])) |
|
| 30 | + $ret['categorie'] = trim(spip_xml_aplatit($arbre['categorie'])); |
|
| 31 | + if (isset($arbre['nom'])) |
|
| 32 | + $ret['nom'] = charset2unicode(spip_xml_aplatit($arbre['nom'])); |
|
| 33 | + if (isset($arbre['icon'])) |
|
| 34 | + $ret['logo'] = trim(spip_xml_aplatit($arbre['icon'])); |
|
| 35 | + if (isset($arbre['auteur'])) |
|
| 36 | + $ret['auteur'][] = trim(spip_xml_aplatit($arbre['auteur'])); // garder le 1er niveau en tableau mais traiter le multi possible |
|
| 37 | + if (isset($arbre['licence'])) |
|
| 38 | + $ret['licence'][] = trim(spip_xml_aplatit($arbre['licence'])); |
|
| 39 | + if (isset($arbre['version'])) |
|
| 40 | + $ret['version'] = trim(spip_xml_aplatit($arbre['version'])); |
|
| 41 | + if (isset($arbre['version_base'])) |
|
| 42 | + $ret['schema'] = trim(spip_xml_aplatit($arbre['version_base'])); |
|
| 43 | + if (isset($arbre['etat'])) |
|
| 44 | + $ret['etat'] = trim(spip_xml_aplatit($arbre['etat'])); |
|
| 45 | + |
|
| 46 | + $ret['description'] = $ret['slogan'] = ""; |
|
| 47 | + if (isset($arbre['slogan'])) |
|
| 48 | + $ret['slogan'] = trim(spip_xml_aplatit($arbre['slogan'])); |
|
| 49 | + if (isset($arbre['description'])){ |
|
| 50 | + $ret['description'] = trim(spip_xml_aplatit($arbre['description'])); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + if (isset($arbre['lien'])){ |
|
| 54 | + $ret['documentation'] = trim(join(' ',$arbre['lien'])); |
|
| 55 | + if ($ret['documentation']) { |
|
| 56 | + // le lien de doc doit etre une url et c'est tout |
|
| 57 | + if (!preg_match(',^https?://,iS', $ret['documentation'])) |
|
| 58 | + $ret['documentation'] = ""; |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + if (isset($arbre['options'])) |
|
| 63 | + $ret['options'] = $arbre['options']; |
|
| 64 | + if (isset($arbre['fonctions'])) |
|
| 65 | + $ret['fonctions'] = $arbre['fonctions']; |
|
| 66 | + if (isset($arbre['prefix'][0])) |
|
| 67 | + $ret['prefix'] = trim(array_pop($arbre['prefix'])); |
|
| 68 | + if (isset($arbre['install'])) |
|
| 69 | + $ret['install'] = $arbre['install']; |
|
| 70 | + if (isset($arbre['meta'])) |
|
| 71 | + $ret['meta'] = trim(spip_xml_aplatit($arbre['meta'])); |
|
| 72 | + |
|
| 73 | + $necessite = info_plugin_normalise_necessite($arbre['necessite']); |
|
| 74 | + $ret['compatibilite'] = isset($necessite['compatible'])?$necessite['compatible']:''; |
|
| 75 | + $ret['necessite'] = $necessite['necessite']; |
|
| 76 | + $ret['lib'] = $necessite['lib']; |
|
| 77 | + $ret['utilise'] = info_plugin_normalise_utilise($arbre['utilise']); |
|
| 78 | + $ret['procure'] = info_plugin_normalise_procure($arbre['procure']); |
|
| 79 | + $ret['chemin'] = info_plugin_normalise_chemin($arbre['path']); |
|
| 80 | + |
|
| 81 | + if (isset($arbre['pipeline'])) |
|
| 82 | + $ret['pipeline'] = $arbre['pipeline']; |
|
| 83 | + |
|
| 84 | + $extraire_boutons = charger_fonction('extraire_boutons','plugins'); |
|
| 85 | + $les_boutons = $extraire_boutons($arbre); |
|
| 86 | + $ret['menu'] = $les_boutons['bouton']; |
|
| 87 | + $ret['onglet'] = $les_boutons['onglet']; |
|
| 88 | + |
|
| 89 | + $ret['traduire'] = $arbre['traduire']; |
|
| 90 | 90 | |
| 91 | - if (isset($arbre['config'])) |
|
| 92 | - $ret['config'] = spip_xml_aplatit($arbre['config']); |
|
| 93 | - if (isset($arbre['noisette'])) |
|
| 94 | - $ret['noisette'] = $arbre['noisette']; |
|
| 91 | + if (isset($arbre['config'])) |
|
| 92 | + $ret['config'] = spip_xml_aplatit($arbre['config']); |
|
| 93 | + if (isset($arbre['noisette'])) |
|
| 94 | + $ret['noisette'] = $arbre['noisette']; |
|
| 95 | 95 | |
| 96 | - if (isset($arbre['erreur'])) { |
|
| 97 | - $ret['erreur'] = $arbre['erreur']; |
|
| 98 | - if ($plug) spip_log("infos_plugin $plug " . @join(' ', $arbre['erreur'])); |
|
| 99 | - } |
|
| 96 | + if (isset($arbre['erreur'])) { |
|
| 97 | + $ret['erreur'] = $arbre['erreur']; |
|
| 98 | + if ($plug) spip_log("infos_plugin $plug " . @join(' ', $arbre['erreur'])); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - return $ret; |
|
| 101 | + return $ret; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | // Un attribut de nom "id" a une signification particuliere en XML |
@@ -122,23 +122,23 @@ discard block |
||
| 122 | 122 | * Liste des necessite modifiés. |
| 123 | 123 | */ |
| 124 | 124 | function info_plugin_normalise_necessite($necessite) { |
| 125 | - $res = array('necessite' => array(), 'lib' => array()); |
|
| 125 | + $res = array('necessite' => array(), 'lib' => array()); |
|
| 126 | 126 | |
| 127 | - if (is_array($necessite)) { |
|
| 128 | - foreach($necessite as $need) { |
|
| 129 | - $id = $need['id']; |
|
| 130 | - $v = isset($need['version']) ? $need['version'] : ''; |
|
| 127 | + if (is_array($necessite)) { |
|
| 128 | + foreach($necessite as $need) { |
|
| 129 | + $id = $need['id']; |
|
| 130 | + $v = isset($need['version']) ? $need['version'] : ''; |
|
| 131 | 131 | |
| 132 | - // Necessite SPIP version x ? |
|
| 133 | - if (strtoupper($id)=='SPIP') { |
|
| 134 | - $res['compatible'] = $v; |
|
| 135 | - } else if (preg_match(',^lib:\s*([^\s]*),i', $id, $r)) { |
|
| 136 | - $res['lib'][] = array('nom' => $r[1], 'id' => $r[1], 'lien' => $need['src']); |
|
| 137 | - } else $res['necessite'][] = array('id' => $id, 'nom' => $id, 'version' => $v, 'compatibilite' => $v); |
|
| 138 | - } |
|
| 139 | - } |
|
| 132 | + // Necessite SPIP version x ? |
|
| 133 | + if (strtoupper($id)=='SPIP') { |
|
| 134 | + $res['compatible'] = $v; |
|
| 135 | + } else if (preg_match(',^lib:\s*([^\s]*),i', $id, $r)) { |
|
| 136 | + $res['lib'][] = array('nom' => $r[1], 'id' => $r[1], 'lien' => $need['src']); |
|
| 137 | + } else $res['necessite'][] = array('id' => $id, 'nom' => $id, 'version' => $v, 'compatibilite' => $v); |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - return $res; |
|
| 141 | + return $res; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
@@ -154,16 +154,16 @@ discard block |
||
| 154 | 154 | * Liste des utilise modifiés. |
| 155 | 155 | */ |
| 156 | 156 | function info_plugin_normalise_utilise($utilise) { |
| 157 | - $res = array(); |
|
| 158 | - |
|
| 159 | - if (is_array($utilise)) { |
|
| 160 | - foreach($utilise as $need){ |
|
| 161 | - $id = $need['id']; |
|
| 162 | - $v = isset($need['version']) ? $need['version'] : '' ; |
|
| 163 | - $res[]= array('nom' => $id, 'id' => $id, 'version' => $v, 'compatibilite' => $v); |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - return $res; |
|
| 157 | + $res = array(); |
|
| 158 | + |
|
| 159 | + if (is_array($utilise)) { |
|
| 160 | + foreach($utilise as $need){ |
|
| 161 | + $id = $need['id']; |
|
| 162 | + $v = isset($need['version']) ? $need['version'] : '' ; |
|
| 163 | + $res[]= array('nom' => $id, 'id' => $id, 'version' => $v, 'compatibilite' => $v); |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + return $res; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -177,16 +177,16 @@ discard block |
||
| 177 | 177 | * Liste des procure modifiés. |
| 178 | 178 | */ |
| 179 | 179 | function info_plugin_normalise_procure($procure) { |
| 180 | - $res = array(); |
|
| 181 | - |
|
| 182 | - if (is_array($procure)) { |
|
| 183 | - foreach($procure as $need){ |
|
| 184 | - $id = $need['id']; |
|
| 185 | - $v = $need['version']; |
|
| 186 | - $res[]= array('nom' => $id, 'id' => $id, 'version' => $v); |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - return $res; |
|
| 180 | + $res = array(); |
|
| 181 | + |
|
| 182 | + if (is_array($procure)) { |
|
| 183 | + foreach($procure as $need){ |
|
| 184 | + $id = $need['id']; |
|
| 185 | + $v = $need['version']; |
|
| 186 | + $res[]= array('nom' => $id, 'id' => $id, 'version' => $v); |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + return $res; |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | /** |
@@ -200,14 +200,14 @@ discard block |
||
| 200 | 200 | * Liste des chemins modifiés. |
| 201 | 201 | */ |
| 202 | 202 | function info_plugin_normalise_chemin($chemins) { |
| 203 | - $res = array(); |
|
| 204 | - |
|
| 205 | - if (is_array($chemins)) { |
|
| 206 | - foreach ($chemins as $c) { |
|
| 207 | - $c['path'] = $c['dir']; |
|
| 208 | - $res[] = $c; |
|
| 209 | - } |
|
| 210 | - } |
|
| 211 | - return $res; |
|
| 203 | + $res = array(); |
|
| 204 | + |
|
| 205 | + if (is_array($chemins)) { |
|
| 206 | + foreach ($chemins as $c) { |
|
| 207 | + $c['path'] = $c['dir']; |
|
| 208 | + $res[] = $c; |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | + return $res; |
|
| 212 | 212 | } |
| 213 | 213 | ?> |
@@ -14,11 +14,11 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | // lecture d'un texte ecrit en pseudo-xml issu d'un fichier plugin.xml |
| 16 | 16 | // et conversion approximative en tableau PHP. |
| 17 | -function plugins_infos_plugin($desc, $plug='', $dir_plugins=_DIR_PLUGINS) { |
|
| 17 | +function plugins_infos_plugin($desc, $plug = '', $dir_plugins = _DIR_PLUGINS) { |
|
| 18 | 18 | include_spip('inc/xml'); |
| 19 | 19 | $arbre = spip_xml_parse($desc); |
| 20 | 20 | |
| 21 | - $verifie_conformite = charger_fonction('verifie_conformite','plugins'); |
|
| 21 | + $verifie_conformite = charger_fonction('verifie_conformite', 'plugins'); |
|
| 22 | 22 | $verifie_conformite($plug, $arbre, $dir_plugins); |
| 23 | 23 | |
| 24 | 24 | include_spip('inc/charsets'); |
@@ -46,12 +46,12 @@ discard block |
||
| 46 | 46 | $ret['description'] = $ret['slogan'] = ""; |
| 47 | 47 | if (isset($arbre['slogan'])) |
| 48 | 48 | $ret['slogan'] = trim(spip_xml_aplatit($arbre['slogan'])); |
| 49 | - if (isset($arbre['description'])){ |
|
| 49 | + if (isset($arbre['description'])) { |
|
| 50 | 50 | $ret['description'] = trim(spip_xml_aplatit($arbre['description'])); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - if (isset($arbre['lien'])){ |
|
| 54 | - $ret['documentation'] = trim(join(' ',$arbre['lien'])); |
|
| 53 | + if (isset($arbre['lien'])) { |
|
| 54 | + $ret['documentation'] = trim(join(' ', $arbre['lien'])); |
|
| 55 | 55 | if ($ret['documentation']) { |
| 56 | 56 | // le lien de doc doit etre une url et c'est tout |
| 57 | 57 | if (!preg_match(',^https?://,iS', $ret['documentation'])) |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | $ret['meta'] = trim(spip_xml_aplatit($arbre['meta'])); |
| 72 | 72 | |
| 73 | 73 | $necessite = info_plugin_normalise_necessite($arbre['necessite']); |
| 74 | - $ret['compatibilite'] = isset($necessite['compatible'])?$necessite['compatible']:''; |
|
| 74 | + $ret['compatibilite'] = isset($necessite['compatible']) ? $necessite['compatible'] : ''; |
|
| 75 | 75 | $ret['necessite'] = $necessite['necessite']; |
| 76 | 76 | $ret['lib'] = $necessite['lib']; |
| 77 | 77 | $ret['utilise'] = info_plugin_normalise_utilise($arbre['utilise']); |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | if (isset($arbre['pipeline'])) |
| 82 | 82 | $ret['pipeline'] = $arbre['pipeline']; |
| 83 | 83 | |
| 84 | - $extraire_boutons = charger_fonction('extraire_boutons','plugins'); |
|
| 84 | + $extraire_boutons = charger_fonction('extraire_boutons', 'plugins'); |
|
| 85 | 85 | $les_boutons = $extraire_boutons($arbre); |
| 86 | 86 | $ret['menu'] = $les_boutons['bouton']; |
| 87 | 87 | $ret['onglet'] = $les_boutons['onglet']; |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | |
| 96 | 96 | if (isset($arbre['erreur'])) { |
| 97 | 97 | $ret['erreur'] = $arbre['erreur']; |
| 98 | - if ($plug) spip_log("infos_plugin $plug " . @join(' ', $arbre['erreur'])); |
|
| 98 | + if ($plug) spip_log("infos_plugin $plug ".@join(' ', $arbre['erreur'])); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | return $ret; |
@@ -125,12 +125,12 @@ discard block |
||
| 125 | 125 | $res = array('necessite' => array(), 'lib' => array()); |
| 126 | 126 | |
| 127 | 127 | if (is_array($necessite)) { |
| 128 | - foreach($necessite as $need) { |
|
| 128 | + foreach ($necessite as $need) { |
|
| 129 | 129 | $id = $need['id']; |
| 130 | 130 | $v = isset($need['version']) ? $need['version'] : ''; |
| 131 | 131 | |
| 132 | 132 | // Necessite SPIP version x ? |
| 133 | - if (strtoupper($id)=='SPIP') { |
|
| 133 | + if (strtoupper($id) == 'SPIP') { |
|
| 134 | 134 | $res['compatible'] = $v; |
| 135 | 135 | } else if (preg_match(',^lib:\s*([^\s]*),i', $id, $r)) { |
| 136 | 136 | $res['lib'][] = array('nom' => $r[1], 'id' => $r[1], 'lien' => $need['src']); |
@@ -157,10 +157,10 @@ discard block |
||
| 157 | 157 | $res = array(); |
| 158 | 158 | |
| 159 | 159 | if (is_array($utilise)) { |
| 160 | - foreach($utilise as $need){ |
|
| 160 | + foreach ($utilise as $need) { |
|
| 161 | 161 | $id = $need['id']; |
| 162 | - $v = isset($need['version']) ? $need['version'] : '' ; |
|
| 163 | - $res[]= array('nom' => $id, 'id' => $id, 'version' => $v, 'compatibilite' => $v); |
|
| 162 | + $v = isset($need['version']) ? $need['version'] : ''; |
|
| 163 | + $res[] = array('nom' => $id, 'id' => $id, 'version' => $v, 'compatibilite' => $v); |
|
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | 166 | return $res; |
@@ -180,10 +180,10 @@ discard block |
||
| 180 | 180 | $res = array(); |
| 181 | 181 | |
| 182 | 182 | if (is_array($procure)) { |
| 183 | - foreach($procure as $need){ |
|
| 183 | + foreach ($procure as $need) { |
|
| 184 | 184 | $id = $need['id']; |
| 185 | 185 | $v = $need['version']; |
| 186 | - $res[]= array('nom' => $id, 'id' => $id, 'version' => $v); |
|
| 186 | + $res[] = array('nom' => $id, 'id' => $id, 'version' => $v); |
|
| 187 | 187 | } |
| 188 | 188 | } |
| 189 | 189 | return $res; |
@@ -10,7 +10,9 @@ 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 | 17 | // lecture d'un texte ecrit en pseudo-xml issu d'un fichier plugin.xml |
| 16 | 18 | // et conversion approximative en tableau PHP. |
@@ -26,26 +28,36 @@ discard block |
||
| 26 | 28 | // On renvoie la DTD utilisee |
| 27 | 29 | $ret['dtd'] = "plugin"; |
| 28 | 30 | |
| 29 | - if (isset($arbre['categorie'])) |
|
| 30 | - $ret['categorie'] = trim(spip_xml_aplatit($arbre['categorie'])); |
|
| 31 | - if (isset($arbre['nom'])) |
|
| 32 | - $ret['nom'] = charset2unicode(spip_xml_aplatit($arbre['nom'])); |
|
| 33 | - if (isset($arbre['icon'])) |
|
| 34 | - $ret['logo'] = trim(spip_xml_aplatit($arbre['icon'])); |
|
| 35 | - if (isset($arbre['auteur'])) |
|
| 36 | - $ret['auteur'][] = trim(spip_xml_aplatit($arbre['auteur'])); // garder le 1er niveau en tableau mais traiter le multi possible |
|
| 37 | - if (isset($arbre['licence'])) |
|
| 38 | - $ret['licence'][] = trim(spip_xml_aplatit($arbre['licence'])); |
|
| 39 | - if (isset($arbre['version'])) |
|
| 40 | - $ret['version'] = trim(spip_xml_aplatit($arbre['version'])); |
|
| 41 | - if (isset($arbre['version_base'])) |
|
| 42 | - $ret['schema'] = trim(spip_xml_aplatit($arbre['version_base'])); |
|
| 43 | - if (isset($arbre['etat'])) |
|
| 44 | - $ret['etat'] = trim(spip_xml_aplatit($arbre['etat'])); |
|
| 31 | + if (isset($arbre['categorie'])) { |
|
| 32 | + $ret['categorie'] = trim(spip_xml_aplatit($arbre['categorie'])); |
|
| 33 | + } |
|
| 34 | + if (isset($arbre['nom'])) { |
|
| 35 | + $ret['nom'] = charset2unicode(spip_xml_aplatit($arbre['nom'])); |
|
| 36 | + } |
|
| 37 | + if (isset($arbre['icon'])) { |
|
| 38 | + $ret['logo'] = trim(spip_xml_aplatit($arbre['icon'])); |
|
| 39 | + } |
|
| 40 | + if (isset($arbre['auteur'])) { |
|
| 41 | + $ret['auteur'][] = trim(spip_xml_aplatit($arbre['auteur'])); |
|
| 42 | + } |
|
| 43 | + // garder le 1er niveau en tableau mais traiter le multi possible |
|
| 44 | + if (isset($arbre['licence'])) { |
|
| 45 | + $ret['licence'][] = trim(spip_xml_aplatit($arbre['licence'])); |
|
| 46 | + } |
|
| 47 | + if (isset($arbre['version'])) { |
|
| 48 | + $ret['version'] = trim(spip_xml_aplatit($arbre['version'])); |
|
| 49 | + } |
|
| 50 | + if (isset($arbre['version_base'])) { |
|
| 51 | + $ret['schema'] = trim(spip_xml_aplatit($arbre['version_base'])); |
|
| 52 | + } |
|
| 53 | + if (isset($arbre['etat'])) { |
|
| 54 | + $ret['etat'] = trim(spip_xml_aplatit($arbre['etat'])); |
|
| 55 | + } |
|
| 45 | 56 | |
| 46 | 57 | $ret['description'] = $ret['slogan'] = ""; |
| 47 | - if (isset($arbre['slogan'])) |
|
| 48 | - $ret['slogan'] = trim(spip_xml_aplatit($arbre['slogan'])); |
|
| 58 | + if (isset($arbre['slogan'])) { |
|
| 59 | + $ret['slogan'] = trim(spip_xml_aplatit($arbre['slogan'])); |
|
| 60 | + } |
|
| 49 | 61 | if (isset($arbre['description'])){ |
| 50 | 62 | $ret['description'] = trim(spip_xml_aplatit($arbre['description'])); |
| 51 | 63 | } |
@@ -54,21 +66,27 @@ discard block |
||
| 54 | 66 | $ret['documentation'] = trim(join(' ',$arbre['lien'])); |
| 55 | 67 | if ($ret['documentation']) { |
| 56 | 68 | // le lien de doc doit etre une url et c'est tout |
| 57 | - if (!preg_match(',^https?://,iS', $ret['documentation'])) |
|
| 58 | - $ret['documentation'] = ""; |
|
| 69 | + if (!preg_match(',^https?://,iS', $ret['documentation'])) { |
|
| 70 | + $ret['documentation'] = ""; |
|
| 71 | + } |
|
| 59 | 72 | } |
| 60 | 73 | } |
| 61 | 74 | |
| 62 | - if (isset($arbre['options'])) |
|
| 63 | - $ret['options'] = $arbre['options']; |
|
| 64 | - if (isset($arbre['fonctions'])) |
|
| 65 | - $ret['fonctions'] = $arbre['fonctions']; |
|
| 66 | - if (isset($arbre['prefix'][0])) |
|
| 67 | - $ret['prefix'] = trim(array_pop($arbre['prefix'])); |
|
| 68 | - if (isset($arbre['install'])) |
|
| 69 | - $ret['install'] = $arbre['install']; |
|
| 70 | - if (isset($arbre['meta'])) |
|
| 71 | - $ret['meta'] = trim(spip_xml_aplatit($arbre['meta'])); |
|
| 75 | + if (isset($arbre['options'])) { |
|
| 76 | + $ret['options'] = $arbre['options']; |
|
| 77 | + } |
|
| 78 | + if (isset($arbre['fonctions'])) { |
|
| 79 | + $ret['fonctions'] = $arbre['fonctions']; |
|
| 80 | + } |
|
| 81 | + if (isset($arbre['prefix'][0])) { |
|
| 82 | + $ret['prefix'] = trim(array_pop($arbre['prefix'])); |
|
| 83 | + } |
|
| 84 | + if (isset($arbre['install'])) { |
|
| 85 | + $ret['install'] = $arbre['install']; |
|
| 86 | + } |
|
| 87 | + if (isset($arbre['meta'])) { |
|
| 88 | + $ret['meta'] = trim(spip_xml_aplatit($arbre['meta'])); |
|
| 89 | + } |
|
| 72 | 90 | |
| 73 | 91 | $necessite = info_plugin_normalise_necessite($arbre['necessite']); |
| 74 | 92 | $ret['compatibilite'] = isset($necessite['compatible'])?$necessite['compatible']:''; |
@@ -78,8 +96,9 @@ discard block |
||
| 78 | 96 | $ret['procure'] = info_plugin_normalise_procure($arbre['procure']); |
| 79 | 97 | $ret['chemin'] = info_plugin_normalise_chemin($arbre['path']); |
| 80 | 98 | |
| 81 | - if (isset($arbre['pipeline'])) |
|
| 82 | - $ret['pipeline'] = $arbre['pipeline']; |
|
| 99 | + if (isset($arbre['pipeline'])) { |
|
| 100 | + $ret['pipeline'] = $arbre['pipeline']; |
|
| 101 | + } |
|
| 83 | 102 | |
| 84 | 103 | $extraire_boutons = charger_fonction('extraire_boutons','plugins'); |
| 85 | 104 | $les_boutons = $extraire_boutons($arbre); |
@@ -88,14 +107,18 @@ discard block |
||
| 88 | 107 | |
| 89 | 108 | $ret['traduire'] = $arbre['traduire']; |
| 90 | 109 | |
| 91 | - if (isset($arbre['config'])) |
|
| 92 | - $ret['config'] = spip_xml_aplatit($arbre['config']); |
|
| 93 | - if (isset($arbre['noisette'])) |
|
| 94 | - $ret['noisette'] = $arbre['noisette']; |
|
| 110 | + if (isset($arbre['config'])) { |
|
| 111 | + $ret['config'] = spip_xml_aplatit($arbre['config']); |
|
| 112 | + } |
|
| 113 | + if (isset($arbre['noisette'])) { |
|
| 114 | + $ret['noisette'] = $arbre['noisette']; |
|
| 115 | + } |
|
| 95 | 116 | |
| 96 | 117 | if (isset($arbre['erreur'])) { |
| 97 | 118 | $ret['erreur'] = $arbre['erreur']; |
| 98 | - if ($plug) spip_log("infos_plugin $plug " . @join(' ', $arbre['erreur'])); |
|
| 119 | + if ($plug) { |
|
| 120 | + spip_log("infos_plugin $plug " . @join(' ', $arbre['erreur'])); |
|
| 121 | + } |
|
| 99 | 122 | } |
| 100 | 123 | |
| 101 | 124 | return $ret; |
@@ -134,7 +157,9 @@ discard block |
||
| 134 | 157 | $res['compatible'] = $v; |
| 135 | 158 | } else if (preg_match(',^lib:\s*([^\s]*),i', $id, $r)) { |
| 136 | 159 | $res['lib'][] = array('nom' => $r[1], 'id' => $r[1], 'lien' => $need['src']); |
| 137 | - } else $res['necessite'][] = array('id' => $id, 'nom' => $id, 'version' => $v, 'compatibilite' => $v); |
|
| 160 | + } else { |
|
| 161 | + $res['necessite'][] = array('id' => $id, 'nom' => $id, 'version' => $v, 'compatibilite' => $v); |
|
| 162 | + } |
|
| 138 | 163 | } |
| 139 | 164 | } |
| 140 | 165 | |
@@ -57,6 +57,9 @@ discard block |
||
| 57 | 57 | |
| 58 | 58 | |
| 59 | 59 | // http://doc.spip.org/@argumenter_inclure |
| 60 | +/** |
|
| 61 | + * @param boolean $rejet_filtres |
|
| 62 | + */ |
|
| 60 | 63 | function argumenter_inclure($params, $rejet_filtres, $p, &$boucles, $id_boucle, $echap=true, $lang = '', $fond1=false){ |
| 61 | 64 | $l = array(); |
| 62 | 65 | $erreur_p_i_i = ''; |
@@ -665,6 +668,9 @@ discard block |
||
| 665 | 668 | } |
| 666 | 669 | |
| 667 | 670 | // http://doc.spip.org/@calculer_dec |
| 671 | +/** |
|
| 672 | + * @param string $nom |
|
| 673 | + */ |
|
| 668 | 674 | function calculer_dec($nom, $val) |
| 669 | 675 | { |
| 670 | 676 | $static = 'if (!isset($command[\''.$nom.'\'])) '; |
@@ -712,6 +718,9 @@ discard block |
||
| 712 | 718 | } |
| 713 | 719 | |
| 714 | 720 | // http://doc.spip.org/@calculer_from |
| 721 | +/** |
|
| 722 | + * @param Boucle $boucle |
|
| 723 | + */ |
|
| 715 | 724 | function calculer_from(&$boucle) |
| 716 | 725 | { |
| 717 | 726 | $res = ""; |
@@ -783,6 +792,9 @@ discard block |
||
| 783 | 792 | define('_REGEXP_CONCAT_NON_VIDE', "/^(.*)[.]\s*'[^']+'\s*$/"); |
| 784 | 793 | |
| 785 | 794 | // http://doc.spip.org/@compile_cas |
| 795 | +/** |
|
| 796 | + * @param string $id_boucle |
|
| 797 | + */ |
|
| 786 | 798 | function compile_cas($tableau, $descr, &$boucles, $id_boucle) { |
| 787 | 799 | |
| 788 | 800 | $codes = array(); |
@@ -960,6 +972,9 @@ discard block |
||
| 960 | 972 | // de meme si EXP est de la forme (t ? '' : 'C') |
| 961 | 973 | |
| 962 | 974 | // http://doc.spip.org/@compile_retour |
| 975 | +/** |
|
| 976 | + * @param string $tab |
|
| 977 | + */ |
|
| 963 | 978 | function compile_retour($code, $avant, $apres, $altern, $tab, $n) |
| 964 | 979 | { |
| 965 | 980 | if ($avant == "''") $avant = ''; |
@@ -58,62 +58,62 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | // http://doc.spip.org/@argumenter_inclure |
| 60 | 60 | function argumenter_inclure($params, $rejet_filtres, $p, &$boucles, $id_boucle, $echap=true, $lang = '', $fond1=false){ |
| 61 | - $l = array(); |
|
| 62 | - $erreur_p_i_i = ''; |
|
| 63 | - if (!is_array($params)) return $l; |
|
| 64 | - foreach($params as $k => $couple) { |
|
| 65 | - // la liste d'arguments d'inclusion peut se terminer par un filtre |
|
| 66 | - $filtre = array_shift($couple); |
|
| 67 | - if ($filtre) break; |
|
| 68 | - foreach($couple as $n => $val) { |
|
| 69 | - $var = $val[0]; |
|
| 70 | - if ($var->type != 'texte') { |
|
| 71 | - if ($n OR $k OR $fond1) { |
|
| 72 | - $erreur_p_i_i = array('zbug_parametres_inclus_incorrects', |
|
| 73 | - array('param' => $var->nom_champ)); |
|
| 74 | - erreur_squelette($erreur_p_i_i, $p); |
|
| 75 | - break; |
|
| 76 | - } |
|
| 77 | - else $l[1] = calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 78 | - } else { |
|
| 79 | - preg_match(",^([^=]*)(=?)(.*)$,m", $var->texte,$m); |
|
| 80 | - $var = $m[1]; |
|
| 81 | - $auto = false;; |
|
| 82 | - if ($m[2]) { |
|
| 83 | - $v = $m[3]; |
|
| 84 | - if (preg_match(',^[\'"](.*)[\'"]$,', $v, $m)) $v = $m[1]; |
|
| 85 | - $val[0] = new Texte; |
|
| 86 | - $val[0]->texte = $v; |
|
| 87 | - } elseif ($k OR $n OR $fond1) { |
|
| 88 | - $auto = true; |
|
| 89 | - } else $var = 1; |
|
| 90 | - |
|
| 91 | - if ($var == 'lang') { |
|
| 92 | - $lang = !$auto |
|
| 93 | - ? calculer_liste($val, $p->descr, $boucles, $id_boucle) |
|
| 94 | - : '$GLOBALS["spip_lang"]'; |
|
| 95 | - } else { |
|
| 96 | - $val = $auto |
|
| 97 | - ? index_pile($id_boucle, $var, $boucles) |
|
| 98 | - : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 99 | - if ($var !== 1) |
|
| 100 | - $val = ($echap?"\'$var\' => ' . argumenter_squelette(":"'$var' => ") |
|
| 101 | - . $val . ($echap? ") . '":" "); |
|
| 102 | - else $val = $echap ? "'.$val.'" : $val; |
|
| 103 | - $l[$var] = $val; |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - if ($erreur_p_i_i) return false; |
|
| 109 | - // Cas particulier de la langue : si {lang=xx} est definie, on |
|
| 110 | - // la passe, sinon on passe la langue courante au moment du calcul |
|
| 111 | - // sauf si on n'en veut pas |
|
| 112 | - if ($lang === false) return $l; |
|
| 113 | - if (!$lang) $lang = '$GLOBALS["spip_lang"]'; |
|
| 114 | - $l['lang'] = ($echap?"\'lang\' => ' . argumenter_squelette(":"'lang' => ") . $lang . ($echap?") . '":" "); |
|
| 115 | - |
|
| 116 | - return $l; |
|
| 61 | + $l = array(); |
|
| 62 | + $erreur_p_i_i = ''; |
|
| 63 | + if (!is_array($params)) return $l; |
|
| 64 | + foreach($params as $k => $couple) { |
|
| 65 | + // la liste d'arguments d'inclusion peut se terminer par un filtre |
|
| 66 | + $filtre = array_shift($couple); |
|
| 67 | + if ($filtre) break; |
|
| 68 | + foreach($couple as $n => $val) { |
|
| 69 | + $var = $val[0]; |
|
| 70 | + if ($var->type != 'texte') { |
|
| 71 | + if ($n OR $k OR $fond1) { |
|
| 72 | + $erreur_p_i_i = array('zbug_parametres_inclus_incorrects', |
|
| 73 | + array('param' => $var->nom_champ)); |
|
| 74 | + erreur_squelette($erreur_p_i_i, $p); |
|
| 75 | + break; |
|
| 76 | + } |
|
| 77 | + else $l[1] = calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 78 | + } else { |
|
| 79 | + preg_match(",^([^=]*)(=?)(.*)$,m", $var->texte,$m); |
|
| 80 | + $var = $m[1]; |
|
| 81 | + $auto = false;; |
|
| 82 | + if ($m[2]) { |
|
| 83 | + $v = $m[3]; |
|
| 84 | + if (preg_match(',^[\'"](.*)[\'"]$,', $v, $m)) $v = $m[1]; |
|
| 85 | + $val[0] = new Texte; |
|
| 86 | + $val[0]->texte = $v; |
|
| 87 | + } elseif ($k OR $n OR $fond1) { |
|
| 88 | + $auto = true; |
|
| 89 | + } else $var = 1; |
|
| 90 | + |
|
| 91 | + if ($var == 'lang') { |
|
| 92 | + $lang = !$auto |
|
| 93 | + ? calculer_liste($val, $p->descr, $boucles, $id_boucle) |
|
| 94 | + : '$GLOBALS["spip_lang"]'; |
|
| 95 | + } else { |
|
| 96 | + $val = $auto |
|
| 97 | + ? index_pile($id_boucle, $var, $boucles) |
|
| 98 | + : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 99 | + if ($var !== 1) |
|
| 100 | + $val = ($echap?"\'$var\' => ' . argumenter_squelette(":"'$var' => ") |
|
| 101 | + . $val . ($echap? ") . '":" "); |
|
| 102 | + else $val = $echap ? "'.$val.'" : $val; |
|
| 103 | + $l[$var] = $val; |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + if ($erreur_p_i_i) return false; |
|
| 109 | + // Cas particulier de la langue : si {lang=xx} est definie, on |
|
| 110 | + // la passe, sinon on passe la langue courante au moment du calcul |
|
| 111 | + // sauf si on n'en veut pas |
|
| 112 | + if ($lang === false) return $l; |
|
| 113 | + if (!$lang) $lang = '$GLOBALS["spip_lang"]'; |
|
| 114 | + $l['lang'] = ($echap?"\'lang\' => ' . argumenter_squelette(":"'lang' => ") . $lang . ($echap?") . '":" "); |
|
| 115 | + |
|
| 116 | + return $l; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -137,64 +137,64 @@ discard block |
||
| 137 | 137 | **/ |
| 138 | 138 | function calculer_inclure($p, &$boucles, $id_boucle) { |
| 139 | 139 | |
| 140 | - $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); |
|
| 141 | - if (is_string($p->texte)) { |
|
| 142 | - $fichier = $p->texte; |
|
| 143 | - $code = "\"".str_replace('"','\"',$fichier)."\""; |
|
| 144 | - |
|
| 145 | - } else { |
|
| 146 | - $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
|
| 147 | - if ($code AND preg_match("/^'([^']*)'/s", $code, $r)) |
|
| 148 | - $fichier = $r[1]; |
|
| 149 | - else $fichier = ''; |
|
| 150 | - } |
|
| 151 | - if (!$code OR $code === '""') { |
|
| 152 | - $erreur_p_i_i = array('zbug_parametres_inclus_incorrects', |
|
| 153 | - array('param' => $code)); |
|
| 154 | - erreur_squelette($erreur_p_i_i, $p); |
|
| 155 | - return false; |
|
| 156 | - } |
|
| 157 | - $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 158 | - |
|
| 159 | - if (is_array($_contexte)) { |
|
| 160 | - // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 161 | - if ($env = (isset($_contexte['env'])|| isset($_contexte['self']))) { |
|
| 162 | - unset($_contexte['env']); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // noter les doublons dans l'appel a public.php |
|
| 166 | - if (isset($_contexte['doublons'])) { |
|
| 167 | - $_contexte['doublons'] = "\\'doublons\\' => '.var_export(\$doublons,true).'"; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - if ($ajax = isset($_contexte['ajax'])){ |
|
| 171 | - $ajax = preg_replace(",=>(.*)$,ims",'=> ($v=(\\1))?$v:true',$_contexte['ajax']); |
|
| 172 | - unset($_contexte['ajax']); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - $_contexte = join(",\n\t", $_contexte); |
|
| 176 | - } |
|
| 177 | - else |
|
| 178 | - return false; // j'aurais voulu toucher le fond ... |
|
| 140 | + $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); |
|
| 141 | + if (is_string($p->texte)) { |
|
| 142 | + $fichier = $p->texte; |
|
| 143 | + $code = "\"".str_replace('"','\"',$fichier)."\""; |
|
| 144 | + |
|
| 145 | + } else { |
|
| 146 | + $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
|
| 147 | + if ($code AND preg_match("/^'([^']*)'/s", $code, $r)) |
|
| 148 | + $fichier = $r[1]; |
|
| 149 | + else $fichier = ''; |
|
| 150 | + } |
|
| 151 | + if (!$code OR $code === '""') { |
|
| 152 | + $erreur_p_i_i = array('zbug_parametres_inclus_incorrects', |
|
| 153 | + array('param' => $code)); |
|
| 154 | + erreur_squelette($erreur_p_i_i, $p); |
|
| 155 | + return false; |
|
| 156 | + } |
|
| 157 | + $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 158 | + |
|
| 159 | + if (is_array($_contexte)) { |
|
| 160 | + // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 161 | + if ($env = (isset($_contexte['env'])|| isset($_contexte['self']))) { |
|
| 162 | + unset($_contexte['env']); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // noter les doublons dans l'appel a public.php |
|
| 166 | + if (isset($_contexte['doublons'])) { |
|
| 167 | + $_contexte['doublons'] = "\\'doublons\\' => '.var_export(\$doublons,true).'"; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + if ($ajax = isset($_contexte['ajax'])){ |
|
| 171 | + $ajax = preg_replace(",=>(.*)$,ims",'=> ($v=(\\1))?$v:true',$_contexte['ajax']); |
|
| 172 | + unset($_contexte['ajax']); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + $_contexte = join(",\n\t", $_contexte); |
|
| 176 | + } |
|
| 177 | + else |
|
| 178 | + return false; // j'aurais voulu toucher le fond ... |
|
| 179 | 179 | |
| 180 | - $contexte = 'array(' . $_contexte .')'; |
|
| 181 | - |
|
| 182 | - if ($env) { |
|
| 183 | - $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - // s'il y a une extension .php, ce n'est pas un squelette |
|
| 187 | - if ($fichier and preg_match('/^.+[.]php$/s', $fichier)) { |
|
| 188 | - $code = sandbox_composer_inclure_php($fichier, $p, $contexte); |
|
| 189 | - } else { |
|
| 190 | - $_options[] = "\"compil\"=>array($compil)"; |
|
| 191 | - if ($ajax) |
|
| 192 | - $_options[] = $ajax; |
|
| 193 | - $code = " ' . argumenter_squelette($code) . '"; |
|
| 194 | - $code = "echo " . sprintf(CODE_RECUPERER_FOND, $code, $contexte, implode(',',$_options), "_request(\"connect\")") . ';'; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - return "\n'<'.'". "?php ". $code . "\n?'." . "'>'"; |
|
| 180 | + $contexte = 'array(' . $_contexte .')'; |
|
| 181 | + |
|
| 182 | + if ($env) { |
|
| 183 | + $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + // s'il y a une extension .php, ce n'est pas un squelette |
|
| 187 | + if ($fichier and preg_match('/^.+[.]php$/s', $fichier)) { |
|
| 188 | + $code = sandbox_composer_inclure_php($fichier, $p, $contexte); |
|
| 189 | + } else { |
|
| 190 | + $_options[] = "\"compil\"=>array($compil)"; |
|
| 191 | + if ($ajax) |
|
| 192 | + $_options[] = $ajax; |
|
| 193 | + $code = " ' . argumenter_squelette($code) . '"; |
|
| 194 | + $code = "echo " . sprintf(CODE_RECUPERER_FOND, $code, $contexte, implode(',',$_options), "_request(\"connect\")") . ';'; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + return "\n'<'.'". "?php ". $code . "\n?'." . "'>'"; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | * true pour ne tester que le cas publie et ignorer l'eventuel var_mode=preview de la page |
| 213 | 213 | */ |
| 214 | 214 | function instituer_boucle(&$boucle, $echapper=true, $ignore_previsu=false){ |
| 215 | - /* |
|
| 215 | + /* |
|
| 216 | 216 | $show['statut'][] = array( |
| 217 | 217 | 'champ'=>'statut', // champ de la table sur lequel porte le filtrage par le statut |
| 218 | 218 | 'publie'=>'publie', // valeur ou liste de valeurs, qui definissent l'objet comme publie. |
@@ -236,71 +236,71 @@ discard block |
||
| 236 | 236 | champstatut est alors le champ statut sur la tablen |
| 237 | 237 | dans les jointures, clen peut etre un tableau pour une jointure complexe : array('id_objet','id_article','objet','article') |
| 238 | 238 | */ |
| 239 | - $id_table = $boucle->id_table; |
|
| 240 | - $show = $boucle->show; |
|
| 241 | - if (isset($show['statut']) AND $show['statut']){ |
|
| 242 | - foreach($show['statut'] as $k=>$s){ |
|
| 243 | - // Restreindre aux elements publies si pas de {statut} ou autre dans les criteres |
|
| 244 | - $filtrer = true; |
|
| 245 | - if (isset($s['exception'])) { |
|
| 246 | - foreach(is_array($s['exception'])?$s['exception']:array($s['exception']) as $m) { |
|
| 247 | - if (isset($boucle->modificateur[$m]) OR isset($boucle->modificateur['criteres'][$m])) { |
|
| 248 | - $filtrer = false; |
|
| 249 | - break; |
|
| 250 | - } |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - if ($filtrer) { |
|
| 255 | - if (is_array($s['champ'])){ |
|
| 256 | - $statut = preg_replace(',\W,','',array_pop($s['champ'])); // securite |
|
| 257 | - $jointures = array(); |
|
| 258 | - // indiquer la description de chaque table dans le tableau de jointures, |
|
| 259 | - // ce qui permet d'eviter certains GROUP BY inutiles. |
|
| 260 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 261 | - foreach($s['champ'] as $j) { |
|
| 262 | - $id = reset($j); |
|
| 263 | - $def = $trouver_table($id); |
|
| 264 | - $jointures[] = array('',array($id,$def),end($j)); |
|
| 265 | - } |
|
| 266 | - $jointures[0][0] = $id_table; |
|
| 267 | - if (!array_search($id, $boucle->from)){ |
|
| 268 | - include_spip('public/jointures'); |
|
| 269 | - fabrique_jointures($boucle, $jointures, true, $boucle->show, $id_table, '', $echapper); |
|
| 270 | - } |
|
| 271 | - // trouver l'alias de la table d'arrivee qui porte le statut |
|
| 272 | - $id = array_search($id, $boucle->from); |
|
| 273 | - } |
|
| 274 | - else { |
|
| 275 | - $id = $id_table; |
|
| 276 | - $statut = preg_replace(',\W,','',$s['champ']); // securite |
|
| 277 | - } |
|
| 278 | - $mstatut = $id .'.'.$statut; |
|
| 279 | - |
|
| 280 | - $arg_ignore_previsu=($ignore_previsu?",true":''); |
|
| 281 | - include_spip('public/quete'); |
|
| 282 | - if (isset($s['post_date']) AND $s['post_date'] |
|
| 283 | - AND $GLOBALS['meta']["post_dates"] == 'non'){ |
|
| 284 | - $date = $id.'.'.preg_replace(',\W,','',$s['post_date']); // securite |
|
| 285 | - array_unshift($boucle->where, |
|
| 286 | - $echapper ? |
|
| 287 | - "\nquete_condition_postdates('$date',"._q($boucle->sql_serveur)."$arg_ignore_previsu)" |
|
| 288 | - : |
|
| 289 | - quete_condition_postdates($date,$boucle->sql_serveur,$ignore_previsu) |
|
| 290 | - ); |
|
| 291 | - } |
|
| 292 | - array_unshift($boucle->where, |
|
| 293 | - $echapper ? |
|
| 294 | - "\nquete_condition_statut('$mstatut'," |
|
| 295 | - . _q($s['previsu'])."," |
|
| 296 | - ._q($s['publie'])."," |
|
| 297 | - ._q($boucle->sql_serveur)."$arg_ignore_previsu)" |
|
| 298 | - : |
|
| 299 | - quete_condition_statut($mstatut,$s['previsu'],$s['publie'],$boucle->sql_serveur,$ignore_previsu) |
|
| 300 | - ); |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - } |
|
| 239 | + $id_table = $boucle->id_table; |
|
| 240 | + $show = $boucle->show; |
|
| 241 | + if (isset($show['statut']) AND $show['statut']){ |
|
| 242 | + foreach($show['statut'] as $k=>$s){ |
|
| 243 | + // Restreindre aux elements publies si pas de {statut} ou autre dans les criteres |
|
| 244 | + $filtrer = true; |
|
| 245 | + if (isset($s['exception'])) { |
|
| 246 | + foreach(is_array($s['exception'])?$s['exception']:array($s['exception']) as $m) { |
|
| 247 | + if (isset($boucle->modificateur[$m]) OR isset($boucle->modificateur['criteres'][$m])) { |
|
| 248 | + $filtrer = false; |
|
| 249 | + break; |
|
| 250 | + } |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + if ($filtrer) { |
|
| 255 | + if (is_array($s['champ'])){ |
|
| 256 | + $statut = preg_replace(',\W,','',array_pop($s['champ'])); // securite |
|
| 257 | + $jointures = array(); |
|
| 258 | + // indiquer la description de chaque table dans le tableau de jointures, |
|
| 259 | + // ce qui permet d'eviter certains GROUP BY inutiles. |
|
| 260 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 261 | + foreach($s['champ'] as $j) { |
|
| 262 | + $id = reset($j); |
|
| 263 | + $def = $trouver_table($id); |
|
| 264 | + $jointures[] = array('',array($id,$def),end($j)); |
|
| 265 | + } |
|
| 266 | + $jointures[0][0] = $id_table; |
|
| 267 | + if (!array_search($id, $boucle->from)){ |
|
| 268 | + include_spip('public/jointures'); |
|
| 269 | + fabrique_jointures($boucle, $jointures, true, $boucle->show, $id_table, '', $echapper); |
|
| 270 | + } |
|
| 271 | + // trouver l'alias de la table d'arrivee qui porte le statut |
|
| 272 | + $id = array_search($id, $boucle->from); |
|
| 273 | + } |
|
| 274 | + else { |
|
| 275 | + $id = $id_table; |
|
| 276 | + $statut = preg_replace(',\W,','',$s['champ']); // securite |
|
| 277 | + } |
|
| 278 | + $mstatut = $id .'.'.$statut; |
|
| 279 | + |
|
| 280 | + $arg_ignore_previsu=($ignore_previsu?",true":''); |
|
| 281 | + include_spip('public/quete'); |
|
| 282 | + if (isset($s['post_date']) AND $s['post_date'] |
|
| 283 | + AND $GLOBALS['meta']["post_dates"] == 'non'){ |
|
| 284 | + $date = $id.'.'.preg_replace(',\W,','',$s['post_date']); // securite |
|
| 285 | + array_unshift($boucle->where, |
|
| 286 | + $echapper ? |
|
| 287 | + "\nquete_condition_postdates('$date',"._q($boucle->sql_serveur)."$arg_ignore_previsu)" |
|
| 288 | + : |
|
| 289 | + quete_condition_postdates($date,$boucle->sql_serveur,$ignore_previsu) |
|
| 290 | + ); |
|
| 291 | + } |
|
| 292 | + array_unshift($boucle->where, |
|
| 293 | + $echapper ? |
|
| 294 | + "\nquete_condition_statut('$mstatut'," |
|
| 295 | + . _q($s['previsu'])."," |
|
| 296 | + ._q($s['publie'])."," |
|
| 297 | + ._q($boucle->sql_serveur)."$arg_ignore_previsu)" |
|
| 298 | + : |
|
| 299 | + quete_condition_statut($mstatut,$s['previsu'],$s['publie'],$boucle->sql_serveur,$ignore_previsu) |
|
| 300 | + ); |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | /** |
@@ -319,22 +319,22 @@ discard block |
||
| 319 | 319 | */ |
| 320 | 320 | function calculer_boucle($id_boucle, &$boucles) { |
| 321 | 321 | |
| 322 | - $boucle = &$boucles[$id_boucle]; |
|
| 323 | - instituer_boucle($boucle); |
|
| 324 | - $boucles[$id_boucle] = pipeline('post_boucle', $boucles[$id_boucle]); |
|
| 325 | - |
|
| 326 | - // en mode debug memoriser les premiers passages dans la boucle, |
|
| 327 | - // mais pas tous, sinon ca pete. |
|
| 328 | - if (_request('var_mode_affiche') != 'resultat') |
|
| 329 | - $trace = ''; |
|
| 330 | - else { |
|
| 331 | - $trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 332 | - $trace = "if (count(@\$GLOBALS['debug_objets']['resultat']['$trace'])<3) |
|
| 322 | + $boucle = &$boucles[$id_boucle]; |
|
| 323 | + instituer_boucle($boucle); |
|
| 324 | + $boucles[$id_boucle] = pipeline('post_boucle', $boucles[$id_boucle]); |
|
| 325 | + |
|
| 326 | + // en mode debug memoriser les premiers passages dans la boucle, |
|
| 327 | + // mais pas tous, sinon ca pete. |
|
| 328 | + if (_request('var_mode_affiche') != 'resultat') |
|
| 329 | + $trace = ''; |
|
| 330 | + else { |
|
| 331 | + $trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 332 | + $trace = "if (count(@\$GLOBALS['debug_objets']['resultat']['$trace'])<3) |
|
| 333 | 333 | \$GLOBALS['debug_objets']['resultat']['$trace'][] = \$t0;"; |
| 334 | - } |
|
| 335 | - return ($boucles[$id_boucle]->type_requete == TYPE_RECURSIF) |
|
| 336 | - ? calculer_boucle_rec($id_boucle, $boucles, $trace) |
|
| 337 | - : calculer_boucle_nonrec($id_boucle, $boucles, $trace); |
|
| 334 | + } |
|
| 335 | + return ($boucles[$id_boucle]->type_requete == TYPE_RECURSIF) |
|
| 336 | + ? calculer_boucle_rec($id_boucle, $boucles, $trace) |
|
| 337 | + : calculer_boucle_nonrec($id_boucle, $boucles, $trace); |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | |
@@ -357,14 +357,14 @@ discard block |
||
| 357 | 357 | * Code PHP compilé de la boucle récursive |
| 358 | 358 | **/ |
| 359 | 359 | function calculer_boucle_rec($id_boucle, &$boucles, $trace) { |
| 360 | - $nom = $boucles[$id_boucle]->param[0]; |
|
| 361 | - return |
|
| 362 | - // Numrows[$nom] peut ne pas être encore defini |
|
| 363 | - "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
|
| 364 | - . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ";" |
|
| 365 | - . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
|
| 366 | - . $trace |
|
| 367 | - . "\n\treturn \$t0;"; |
|
| 360 | + $nom = $boucles[$id_boucle]->param[0]; |
|
| 361 | + return |
|
| 362 | + // Numrows[$nom] peut ne pas être encore defini |
|
| 363 | + "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
|
| 364 | + . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ";" |
|
| 365 | + . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
|
| 366 | + . $trace |
|
| 367 | + . "\n\treturn \$t0;"; |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | /** |
@@ -417,154 +417,154 @@ discard block |
||
| 417 | 417 | **/ |
| 418 | 418 | function calculer_boucle_nonrec($id_boucle, &$boucles, $trace) { |
| 419 | 419 | |
| 420 | - $boucle = &$boucles[$id_boucle]; |
|
| 421 | - $return = $boucle->return; |
|
| 422 | - $type_boucle = $boucle->type_requete; |
|
| 423 | - $primary = $boucle->primary; |
|
| 424 | - $constant = preg_match(CODE_MONOTONE, str_replace("\\'",'', $return)); |
|
| 425 | - $flag_cpt = $boucle->mode_partie ||$boucle->cptrows; |
|
| 426 | - $corps = ''; |
|
| 427 | - |
|
| 428 | - // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
|
| 429 | - // et puis faire un [] plutot qu'un "','." |
|
| 430 | - if ($boucle->doublons) |
|
| 431 | - $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 432 | - index_pile($id_boucle, $primary, $boucles) |
|
| 433 | - . "; // doublons\n"; |
|
| 434 | - |
|
| 435 | - // La boucle doit-elle selectionner la langue ? |
|
| 436 | - // - par defaut, les boucles suivantes le font |
|
| 437 | - // (sauf si forcer_lang==true ou si le titre contient <multi>). |
|
| 438 | - // - a moins d'une demande explicite via {!lang_select} |
|
| 439 | - if (!$constant && $boucle->lang_select != 'non' && |
|
| 440 | - (($boucle->lang_select == 'oui') || |
|
| 441 | - in_array($type_boucle, array( |
|
| 442 | - 'articles', 'rubriques', 'hierarchie', 'breves' |
|
| 443 | - ))) |
|
| 444 | - ) { |
|
| 445 | - // Memoriser la langue avant la boucle et la restituer apres |
|
| 446 | - // afin que le corps de boucle affecte la globale directement |
|
| 447 | - $init_lang = "lang_select(\$GLOBALS['spip_lang']);\n\t"; |
|
| 448 | - $fin_lang = "lang_select();\n\t"; |
|
| 449 | - $fin_lang_select_public = "\n\t\tlang_select();"; |
|
| 450 | - |
|
| 451 | - $corps .= |
|
| 452 | - "\n\t\tlang_select_public(" |
|
| 453 | - . index_pile($id_boucle, 'lang', $boucles) |
|
| 454 | - . ", '".$boucle->lang_select."'" |
|
| 455 | - . (in_array($type_boucle, array( |
|
| 456 | - 'articles', 'rubriques', 'hierarchie', 'breves' |
|
| 457 | - )) ? ', '.index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 458 | - . ');'; |
|
| 459 | - } |
|
| 460 | - else { |
|
| 461 | - $init_lang = ''; |
|
| 462 | - $fin_lang = ''; |
|
| 463 | - $fin_lang_select_public = ''; |
|
| 464 | - // sortir les appels au traducteur (invariants de boucle) |
|
| 465 | - if (strpos($return, '?php') === false |
|
| 466 | - AND preg_match_all("/\W(_T[(]'[^']*'[)])/", $return, $r)) { |
|
| 467 | - $i = 1; |
|
| 468 | - foreach($r[1] as $t) { |
|
| 469 | - $init_lang .= "\n\t\$l$i = $t;"; |
|
| 470 | - $return = str_replace($t, "\$l$i", $return); |
|
| 471 | - $i++; |
|
| 472 | - } |
|
| 473 | - } |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - // gestion optimale des separateurs et des boucles constantes |
|
| 477 | - if (count($boucle->separateur)) |
|
| 478 | - $code_sep = ("'" . str_replace("'","\'",join('',$boucle->separateur)) . "'"); |
|
| 479 | - |
|
| 480 | - $corps .= |
|
| 481 | - ((!$boucle->separateur) ? |
|
| 482 | - (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 483 | - (($return==="''") ? '' : |
|
| 484 | - ("\n\t\t" . '$t0 .= ' . $return . ";"))) : |
|
| 485 | - ("\n\t\t\$t1 " . |
|
| 486 | - ((strpos($return, '$t1.') === 0) ? |
|
| 487 | - (".=" . substr($return,4)) : |
|
| 488 | - ('= ' . $return)) . |
|
| 489 | - ";\n\t\t" . |
|
| 490 | - '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 420 | + $boucle = &$boucles[$id_boucle]; |
|
| 421 | + $return = $boucle->return; |
|
| 422 | + $type_boucle = $boucle->type_requete; |
|
| 423 | + $primary = $boucle->primary; |
|
| 424 | + $constant = preg_match(CODE_MONOTONE, str_replace("\\'",'', $return)); |
|
| 425 | + $flag_cpt = $boucle->mode_partie ||$boucle->cptrows; |
|
| 426 | + $corps = ''; |
|
| 427 | + |
|
| 428 | + // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
|
| 429 | + // et puis faire un [] plutot qu'un "','." |
|
| 430 | + if ($boucle->doublons) |
|
| 431 | + $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 432 | + index_pile($id_boucle, $primary, $boucles) |
|
| 433 | + . "; // doublons\n"; |
|
| 434 | + |
|
| 435 | + // La boucle doit-elle selectionner la langue ? |
|
| 436 | + // - par defaut, les boucles suivantes le font |
|
| 437 | + // (sauf si forcer_lang==true ou si le titre contient <multi>). |
|
| 438 | + // - a moins d'une demande explicite via {!lang_select} |
|
| 439 | + if (!$constant && $boucle->lang_select != 'non' && |
|
| 440 | + (($boucle->lang_select == 'oui') || |
|
| 441 | + in_array($type_boucle, array( |
|
| 442 | + 'articles', 'rubriques', 'hierarchie', 'breves' |
|
| 443 | + ))) |
|
| 444 | + ) { |
|
| 445 | + // Memoriser la langue avant la boucle et la restituer apres |
|
| 446 | + // afin que le corps de boucle affecte la globale directement |
|
| 447 | + $init_lang = "lang_select(\$GLOBALS['spip_lang']);\n\t"; |
|
| 448 | + $fin_lang = "lang_select();\n\t"; |
|
| 449 | + $fin_lang_select_public = "\n\t\tlang_select();"; |
|
| 450 | + |
|
| 451 | + $corps .= |
|
| 452 | + "\n\t\tlang_select_public(" |
|
| 453 | + . index_pile($id_boucle, 'lang', $boucles) |
|
| 454 | + . ", '".$boucle->lang_select."'" |
|
| 455 | + . (in_array($type_boucle, array( |
|
| 456 | + 'articles', 'rubriques', 'hierarchie', 'breves' |
|
| 457 | + )) ? ', '.index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 458 | + . ');'; |
|
| 459 | + } |
|
| 460 | + else { |
|
| 461 | + $init_lang = ''; |
|
| 462 | + $fin_lang = ''; |
|
| 463 | + $fin_lang_select_public = ''; |
|
| 464 | + // sortir les appels au traducteur (invariants de boucle) |
|
| 465 | + if (strpos($return, '?php') === false |
|
| 466 | + AND preg_match_all("/\W(_T[(]'[^']*'[)])/", $return, $r)) { |
|
| 467 | + $i = 1; |
|
| 468 | + foreach($r[1] as $t) { |
|
| 469 | + $init_lang .= "\n\t\$l$i = $t;"; |
|
| 470 | + $return = str_replace($t, "\$l$i", $return); |
|
| 471 | + $i++; |
|
| 472 | + } |
|
| 473 | + } |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + // gestion optimale des separateurs et des boucles constantes |
|
| 477 | + if (count($boucle->separateur)) |
|
| 478 | + $code_sep = ("'" . str_replace("'","\'",join('',$boucle->separateur)) . "'"); |
|
| 479 | + |
|
| 480 | + $corps .= |
|
| 481 | + ((!$boucle->separateur) ? |
|
| 482 | + (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 483 | + (($return==="''") ? '' : |
|
| 484 | + ("\n\t\t" . '$t0 .= ' . $return . ";"))) : |
|
| 485 | + ("\n\t\t\$t1 " . |
|
| 486 | + ((strpos($return, '$t1.') === 0) ? |
|
| 487 | + (".=" . substr($return,4)) : |
|
| 488 | + ('= ' . $return)) . |
|
| 489 | + ";\n\t\t" . |
|
| 490 | + '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 491 | 491 | |
| 492 | - // Calculer les invalideurs si c'est une boucle non constante et si on |
|
| 493 | - // souhaite invalider ces elements |
|
| 494 | - if (!$constant AND $primary) { |
|
| 495 | - include_spip('inc/invalideur'); |
|
| 496 | - if (function_exists($i = 'calcul_invalideurs')) |
|
| 497 | - $corps = $i($corps, $primary, $boucles, $id_boucle); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - // gerer le compteur de boucle |
|
| 501 | - // avec ou sans son utilisation par les criteres {1/3} {1,4} {n-2,1}... |
|
| 502 | - |
|
| 503 | - if ($boucle->partie OR $boucle->cptrows) |
|
| 504 | - $corps = "\n\t\t\$Numrows['$id_boucle']['compteur_boucle']++;" |
|
| 505 | - . $boucle->partie |
|
| 506 | - . $corps; |
|
| 507 | - |
|
| 508 | - // depiler la lang de la boucle si besoin |
|
| 509 | - $corps .= $fin_lang_select_public; |
|
| 510 | - |
|
| 511 | - // si le corps est une constante, ne pas appeler le serveur N fois! |
|
| 512 | - |
|
| 513 | - if (preg_match(CODE_MONOTONE,str_replace("\\'",'',$corps), $r)) { |
|
| 514 | - if (!isset($r[2]) OR (!$r[2])) { |
|
| 515 | - if (!$boucle->numrows) |
|
| 516 | - return "\n\t\$t0 = '';"; |
|
| 517 | - else |
|
| 518 | - $corps = ""; |
|
| 519 | - } else { |
|
| 520 | - $boucle->numrows = true; |
|
| 521 | - $corps = "\n\t\$t0 = str_repeat($corps, \$Numrows['$id_boucle']['total']);"; |
|
| 522 | - } |
|
| 523 | - } else $corps = "while (\$Pile[\$SP]=\$iter->fetch()) {\n$corps\n }"; |
|
| 524 | - |
|
| 525 | - $count = ''; |
|
| 526 | - if (!$boucle->select) { |
|
| 527 | - if (!$boucle->numrows OR $boucle->limit OR $boucle->mode_partie OR $boucle->group) |
|
| 528 | - $count = '1'; |
|
| 529 | - else $count = 'count(*)'; |
|
| 530 | - $boucles[$id_boucle]->select[]= $count; |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - if ($flag_cpt) |
|
| 534 | - $nums = "\n\t// COMPTEUR\n\t" |
|
| 535 | - . "\$Numrows['$id_boucle']['compteur_boucle'] = 0;\n\t"; |
|
| 536 | - else $nums = ''; |
|
| 537 | - |
|
| 538 | - if ($boucle->numrows OR $boucle->mode_partie) { |
|
| 539 | - $nums .= "\$Numrows['$id_boucle']['total'] = @intval(\$iter->count());" |
|
| 540 | - . $boucle->mode_partie |
|
| 541 | - . "\n\t"; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - // Ne calculer la requete que maintenant |
|
| 545 | - // car ce qui precede appelle index_pile qui influe dessus |
|
| 546 | - |
|
| 547 | - $init = (($init = $boucles[$id_boucle]->doublons) |
|
| 548 | - ? ("\n\t$init = array();") : '') |
|
| 549 | - . calculer_requete_sql($boucles[$id_boucle]); |
|
| 550 | - |
|
| 551 | - $contexte = memoriser_contexte_compil($boucle); |
|
| 552 | - |
|
| 553 | - $a = sprintf(CODE_CORPS_BOUCLE, |
|
| 554 | - $init, |
|
| 555 | - $boucle->iterateur, |
|
| 556 | - "\$command", |
|
| 557 | - $contexte, |
|
| 558 | - $nums, |
|
| 559 | - $init_lang, |
|
| 560 | - $corps, |
|
| 561 | - $fin_lang, |
|
| 562 | - $trace, |
|
| 563 | - 'BOUCLE'.$id_boucle .' @ '.($boucle->descr['sourcefile']) |
|
| 564 | - ); |
|
| 492 | + // Calculer les invalideurs si c'est une boucle non constante et si on |
|
| 493 | + // souhaite invalider ces elements |
|
| 494 | + if (!$constant AND $primary) { |
|
| 495 | + include_spip('inc/invalideur'); |
|
| 496 | + if (function_exists($i = 'calcul_invalideurs')) |
|
| 497 | + $corps = $i($corps, $primary, $boucles, $id_boucle); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + // gerer le compteur de boucle |
|
| 501 | + // avec ou sans son utilisation par les criteres {1/3} {1,4} {n-2,1}... |
|
| 502 | + |
|
| 503 | + if ($boucle->partie OR $boucle->cptrows) |
|
| 504 | + $corps = "\n\t\t\$Numrows['$id_boucle']['compteur_boucle']++;" |
|
| 505 | + . $boucle->partie |
|
| 506 | + . $corps; |
|
| 507 | + |
|
| 508 | + // depiler la lang de la boucle si besoin |
|
| 509 | + $corps .= $fin_lang_select_public; |
|
| 510 | + |
|
| 511 | + // si le corps est une constante, ne pas appeler le serveur N fois! |
|
| 512 | + |
|
| 513 | + if (preg_match(CODE_MONOTONE,str_replace("\\'",'',$corps), $r)) { |
|
| 514 | + if (!isset($r[2]) OR (!$r[2])) { |
|
| 515 | + if (!$boucle->numrows) |
|
| 516 | + return "\n\t\$t0 = '';"; |
|
| 517 | + else |
|
| 518 | + $corps = ""; |
|
| 519 | + } else { |
|
| 520 | + $boucle->numrows = true; |
|
| 521 | + $corps = "\n\t\$t0 = str_repeat($corps, \$Numrows['$id_boucle']['total']);"; |
|
| 522 | + } |
|
| 523 | + } else $corps = "while (\$Pile[\$SP]=\$iter->fetch()) {\n$corps\n }"; |
|
| 524 | + |
|
| 525 | + $count = ''; |
|
| 526 | + if (!$boucle->select) { |
|
| 527 | + if (!$boucle->numrows OR $boucle->limit OR $boucle->mode_partie OR $boucle->group) |
|
| 528 | + $count = '1'; |
|
| 529 | + else $count = 'count(*)'; |
|
| 530 | + $boucles[$id_boucle]->select[]= $count; |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + if ($flag_cpt) |
|
| 534 | + $nums = "\n\t// COMPTEUR\n\t" |
|
| 535 | + . "\$Numrows['$id_boucle']['compteur_boucle'] = 0;\n\t"; |
|
| 536 | + else $nums = ''; |
|
| 537 | + |
|
| 538 | + if ($boucle->numrows OR $boucle->mode_partie) { |
|
| 539 | + $nums .= "\$Numrows['$id_boucle']['total'] = @intval(\$iter->count());" |
|
| 540 | + . $boucle->mode_partie |
|
| 541 | + . "\n\t"; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + // Ne calculer la requete que maintenant |
|
| 545 | + // car ce qui precede appelle index_pile qui influe dessus |
|
| 546 | + |
|
| 547 | + $init = (($init = $boucles[$id_boucle]->doublons) |
|
| 548 | + ? ("\n\t$init = array();") : '') |
|
| 549 | + . calculer_requete_sql($boucles[$id_boucle]); |
|
| 550 | + |
|
| 551 | + $contexte = memoriser_contexte_compil($boucle); |
|
| 552 | + |
|
| 553 | + $a = sprintf(CODE_CORPS_BOUCLE, |
|
| 554 | + $init, |
|
| 555 | + $boucle->iterateur, |
|
| 556 | + "\$command", |
|
| 557 | + $contexte, |
|
| 558 | + $nums, |
|
| 559 | + $init_lang, |
|
| 560 | + $corps, |
|
| 561 | + $fin_lang, |
|
| 562 | + $trace, |
|
| 563 | + 'BOUCLE'.$id_boucle .' @ '.($boucle->descr['sourcefile']) |
|
| 564 | + ); |
|
| 565 | 565 | |
| 566 | 566 | # var_dump($a);exit; |
| 567 | - return $a; |
|
| 567 | + return $a; |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | |
@@ -581,38 +581,38 @@ discard block |
||
| 581 | 581 | **/ |
| 582 | 582 | function calculer_requete_sql($boucle) |
| 583 | 583 | { |
| 584 | - $init = array(); |
|
| 585 | - $init[] = calculer_dec('table', "'" . $boucle->id_table ."'"); |
|
| 586 | - $init[] = calculer_dec('id', "'" . $boucle->id_boucle ."'"); |
|
| 587 | - # En absence de champ c'est un decompte : |
|
| 588 | - $init[] = calculer_dec('from', calculer_from($boucle)); |
|
| 589 | - $init[] = calculer_dec('type', calculer_from_type($boucle)); |
|
| 590 | - $init[] = calculer_dec('groupby', 'array(' . (($g=join("\",\n\t\t\"",$boucle->group))?'"'.$g.'"':'') . ")"); |
|
| 591 | - $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select). "\")"); |
|
| 592 | - $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ")"); |
|
| 593 | - $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
|
| 594 | - $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
|
| 595 | - $init[] = calculer_dec('limit', |
|
| 596 | - (strpos($boucle->limit, 'intval') === false ? |
|
| 597 | - "'".$boucle->limit."'" |
|
| 598 | - : |
|
| 599 | - $boucle->limit)); |
|
| 600 | - $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
|
| 601 | - $s = $d = ""; |
|
| 602 | - foreach ($init as $i){ |
|
| 603 | - if (reset($i)) |
|
| 604 | - $s .= "\n\t\t".end($i); |
|
| 605 | - else |
|
| 606 | - $d .= "\n\t".end($i); |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
|
| 610 | - . $boucle->in |
|
| 611 | - . $boucle->hash |
|
| 612 | - . "\n\t".'if (!isset($command[\'table\'])) {' |
|
| 613 | - . $s |
|
| 614 | - . "\n\t}" |
|
| 615 | - . $d; |
|
| 584 | + $init = array(); |
|
| 585 | + $init[] = calculer_dec('table', "'" . $boucle->id_table ."'"); |
|
| 586 | + $init[] = calculer_dec('id', "'" . $boucle->id_boucle ."'"); |
|
| 587 | + # En absence de champ c'est un decompte : |
|
| 588 | + $init[] = calculer_dec('from', calculer_from($boucle)); |
|
| 589 | + $init[] = calculer_dec('type', calculer_from_type($boucle)); |
|
| 590 | + $init[] = calculer_dec('groupby', 'array(' . (($g=join("\",\n\t\t\"",$boucle->group))?'"'.$g.'"':'') . ")"); |
|
| 591 | + $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select). "\")"); |
|
| 592 | + $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ")"); |
|
| 593 | + $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
|
| 594 | + $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
|
| 595 | + $init[] = calculer_dec('limit', |
|
| 596 | + (strpos($boucle->limit, 'intval') === false ? |
|
| 597 | + "'".$boucle->limit."'" |
|
| 598 | + : |
|
| 599 | + $boucle->limit)); |
|
| 600 | + $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
|
| 601 | + $s = $d = ""; |
|
| 602 | + foreach ($init as $i){ |
|
| 603 | + if (reset($i)) |
|
| 604 | + $s .= "\n\t\t".end($i); |
|
| 605 | + else |
|
| 606 | + $d .= "\n\t".end($i); |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
|
| 610 | + . $boucle->in |
|
| 611 | + . $boucle->hash |
|
| 612 | + . "\n\t".'if (!isset($command[\'table\'])) {' |
|
| 613 | + . $s |
|
| 614 | + . "\n\t}" |
|
| 615 | + . $d; |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | /** |
@@ -630,12 +630,12 @@ discard block |
||
| 630 | 630 | * qui peut être utilisé pour la production d'un tableau array() |
| 631 | 631 | **/ |
| 632 | 632 | function memoriser_contexte_compil($p) { |
| 633 | - return join(',', array( |
|
| 634 | - _q($p->descr['sourcefile']), |
|
| 635 | - _q($p->descr['nom']), |
|
| 636 | - @_q($p->id_boucle), |
|
| 637 | - intval($p->ligne), |
|
| 638 | - '$GLOBALS[\'spip_lang\']')); |
|
| 633 | + return join(',', array( |
|
| 634 | + _q($p->descr['sourcefile']), |
|
| 635 | + _q($p->descr['nom']), |
|
| 636 | + @_q($p->id_boucle), |
|
| 637 | + intval($p->ligne), |
|
| 638 | + '$GLOBALS[\'spip_lang\']')); |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | /** |
@@ -654,25 +654,25 @@ discard block |
||
| 654 | 654 | **/ |
| 655 | 655 | function reconstruire_contexte_compil($context_compil) |
| 656 | 656 | { |
| 657 | - if (!is_array($context_compil)) return $context_compil; |
|
| 658 | - $p = new Contexte; |
|
| 659 | - $p->descr = array('sourcefile' => $context_compil[0], |
|
| 660 | - 'nom' => $context_compil[1]); |
|
| 661 | - $p->id_boucle = $context_compil[2]; |
|
| 662 | - $p->ligne = $context_compil[3]; |
|
| 663 | - $p->lang = $context_compil[4]; |
|
| 664 | - return $p; |
|
| 657 | + if (!is_array($context_compil)) return $context_compil; |
|
| 658 | + $p = new Contexte; |
|
| 659 | + $p->descr = array('sourcefile' => $context_compil[0], |
|
| 660 | + 'nom' => $context_compil[1]); |
|
| 661 | + $p->id_boucle = $context_compil[2]; |
|
| 662 | + $p->ligne = $context_compil[3]; |
|
| 663 | + $p->lang = $context_compil[4]; |
|
| 664 | + return $p; |
|
| 665 | 665 | } |
| 666 | 666 | |
| 667 | 667 | // http://doc.spip.org/@calculer_dec |
| 668 | 668 | function calculer_dec($nom, $val) |
| 669 | 669 | { |
| 670 | - $static = 'if (!isset($command[\''.$nom.'\'])) '; |
|
| 671 | - // si une variable apparait dans le calcul de la clause |
|
| 672 | - // il faut la re-evaluer a chaque passage |
|
| 673 | - if ( |
|
| 674 | - strpos($val, '$') !== false |
|
| 675 | - /* |
|
| 670 | + $static = 'if (!isset($command[\''.$nom.'\'])) '; |
|
| 671 | + // si une variable apparait dans le calcul de la clause |
|
| 672 | + // il faut la re-evaluer a chaque passage |
|
| 673 | + if ( |
|
| 674 | + strpos($val, '$') !== false |
|
| 675 | + /* |
|
| 676 | 676 | OR strpos($val, 'sql_') !== false |
| 677 | 677 | OR ( |
| 678 | 678 | $test = str_replace(array("array(",'\"',"\'"),array("","",""),$val) // supprimer les array( et les echappements de guillemets |
@@ -680,67 +680,67 @@ discard block |
||
| 680 | 680 | AND $test = preg_replace(",'[^']*',UimsS","",$test) // supprimer les chaines qui peuvent contenir des fonctions SQL qui ne genent pas |
| 681 | 681 | AND preg_match(",\w+\s*\(,UimsS",$test,$regs) // tester la presence de fonctions restantes |
| 682 | 682 | )*/ |
| 683 | - ) |
|
| 684 | - $static = ""; |
|
| 683 | + ) |
|
| 684 | + $static = ""; |
|
| 685 | 685 | |
| 686 | - return array($static,'$command[\''.$nom.'\'] = ' . $val . ';'); |
|
| 686 | + return array($static,'$command[\''.$nom.'\'] = ' . $val . ';'); |
|
| 687 | 687 | } |
| 688 | 688 | |
| 689 | 689 | // http://doc.spip.org/@calculer_dump_array |
| 690 | 690 | function calculer_dump_array($a) |
| 691 | 691 | { |
| 692 | - if (!is_array($a)) return $a ; |
|
| 693 | - $res = ""; |
|
| 694 | - if ($a AND $a[0] == "'?'") |
|
| 692 | + if (!is_array($a)) return $a ; |
|
| 693 | + $res = ""; |
|
| 694 | + if ($a AND $a[0] == "'?'") |
|
| 695 | 695 | return ("(" . calculer_dump_array($a[1]) . |
| 696 | - " ? " . calculer_dump_array($a[2]) . |
|
| 697 | - " : " . calculer_dump_array($a[3]) . |
|
| 698 | - ")"); |
|
| 699 | - else { |
|
| 696 | + " ? " . calculer_dump_array($a[2]) . |
|
| 697 | + " : " . calculer_dump_array($a[3]) . |
|
| 698 | + ")"); |
|
| 699 | + else { |
|
| 700 | 700 | foreach($a as $v) $res .= ", " . calculer_dump_array($v); |
| 701 | 701 | return "\n\t\t\tarray(" . substr($res,2) . ')'; |
| 702 | - } |
|
| 702 | + } |
|
| 703 | 703 | } |
| 704 | 704 | |
| 705 | 705 | // http://doc.spip.org/@calculer_dump_join |
| 706 | 706 | function calculer_dump_join($a) |
| 707 | 707 | { |
| 708 | - $res = ""; |
|
| 709 | - foreach($a as $k => $v) |
|
| 710 | - $res .= ", '$k' => array(".implode(',',$v).")"; |
|
| 711 | - return 'array(' . substr($res,2) . ')'; |
|
| 708 | + $res = ""; |
|
| 709 | + foreach($a as $k => $v) |
|
| 710 | + $res .= ", '$k' => array(".implode(',',$v).")"; |
|
| 711 | + return 'array(' . substr($res,2) . ')'; |
|
| 712 | 712 | } |
| 713 | 713 | |
| 714 | 714 | // http://doc.spip.org/@calculer_from |
| 715 | 715 | function calculer_from(&$boucle) |
| 716 | 716 | { |
| 717 | - $res = ""; |
|
| 718 | - foreach($boucle->from as $k => $v) $res .= ",'$k' => '$v'"; |
|
| 719 | - return 'array(' . substr($res,1) . ')'; |
|
| 717 | + $res = ""; |
|
| 718 | + foreach($boucle->from as $k => $v) $res .= ",'$k' => '$v'"; |
|
| 719 | + return 'array(' . substr($res,1) . ')'; |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | // http://doc.spip.org/@calculer_from_type |
| 723 | 723 | function calculer_from_type(&$boucle) |
| 724 | 724 | { |
| 725 | - $res = ""; |
|
| 726 | - foreach($boucle->from_type as $k => $v) $res .= ",'$k' => '$v'"; |
|
| 727 | - return 'array(' . substr($res,1) . ')'; |
|
| 725 | + $res = ""; |
|
| 726 | + foreach($boucle->from_type as $k => $v) $res .= ",'$k' => '$v'"; |
|
| 727 | + return 'array(' . substr($res,1) . ')'; |
|
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | // http://doc.spip.org/@calculer_order |
| 731 | 731 | function calculer_order(&$boucle) |
| 732 | 732 | { |
| 733 | - if (!$order = $boucle->order |
|
| 734 | - AND !$order = $boucle->default_order) |
|
| 735 | - $order = array(); |
|
| 733 | + if (!$order = $boucle->order |
|
| 734 | + AND !$order = $boucle->default_order) |
|
| 735 | + $order = array(); |
|
| 736 | 736 | |
| 737 | - /*if (isset($boucle->modificateur['collate'])){ |
|
| 737 | + /*if (isset($boucle->modificateur['collate'])){ |
|
| 738 | 738 | $col = "." . $boucle->modificateur['collate']; |
| 739 | 739 | foreach($order as $k=>$o) |
| 740 | 740 | if (strpos($order[$k],'COLLATE')===false) |
| 741 | 741 | $order[$k].= $col; |
| 742 | 742 | }*/ |
| 743 | - return join(', ', $order); |
|
| 743 | + return join(', ', $order); |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | // Production du code PHP a partir de la sequence livree par le phraseur |
@@ -750,32 +750,32 @@ discard block |
||
| 750 | 750 | |
| 751 | 751 | // http://doc.spip.org/@calculer_liste |
| 752 | 752 | function calculer_liste($tableau, $descr, &$boucles, $id_boucle='') { |
| 753 | - if (!$tableau) return "''"; |
|
| 754 | - if (!isset($descr['niv'])) $descr['niv'] = 0; |
|
| 755 | - $codes = compile_cas($tableau, $descr, $boucles, $id_boucle); |
|
| 756 | - if ($codes === false) return false; |
|
| 757 | - $n = count($codes); |
|
| 758 | - if (!$n) return "''"; |
|
| 759 | - $tab = str_repeat("\t", $descr['niv']); |
|
| 760 | - if (_request('var_mode_affiche') != 'validation') { |
|
| 761 | - if ($n==1) |
|
| 762 | - return $codes[0]; |
|
| 763 | - else { |
|
| 764 | - $res = ''; |
|
| 765 | - foreach($codes as $code) { |
|
| 766 | - if (!preg_match("/^'[^']*'$/", $code) |
|
| 767 | - OR substr($res,-1,1)!=="'") |
|
| 768 | - $res .= " .\n$tab$code"; |
|
| 769 | - else { |
|
| 770 | - $res = substr($res,0,-1) . substr($code,1); |
|
| 771 | - } |
|
| 772 | - } |
|
| 773 | - return '(' . substr($res,2+$descr['niv']) . ')'; |
|
| 774 | - } |
|
| 775 | - } else { |
|
| 776 | - $nom = $descr['nom'] . $id_boucle . ($descr['niv']?$descr['niv']:''); |
|
| 777 | - return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join(" ,\n$tab", $codes) . ")))"; |
|
| 778 | - } |
|
| 753 | + if (!$tableau) return "''"; |
|
| 754 | + if (!isset($descr['niv'])) $descr['niv'] = 0; |
|
| 755 | + $codes = compile_cas($tableau, $descr, $boucles, $id_boucle); |
|
| 756 | + if ($codes === false) return false; |
|
| 757 | + $n = count($codes); |
|
| 758 | + if (!$n) return "''"; |
|
| 759 | + $tab = str_repeat("\t", $descr['niv']); |
|
| 760 | + if (_request('var_mode_affiche') != 'validation') { |
|
| 761 | + if ($n==1) |
|
| 762 | + return $codes[0]; |
|
| 763 | + else { |
|
| 764 | + $res = ''; |
|
| 765 | + foreach($codes as $code) { |
|
| 766 | + if (!preg_match("/^'[^']*'$/", $code) |
|
| 767 | + OR substr($res,-1,1)!=="'") |
|
| 768 | + $res .= " .\n$tab$code"; |
|
| 769 | + else { |
|
| 770 | + $res = substr($res,0,-1) . substr($code,1); |
|
| 771 | + } |
|
| 772 | + } |
|
| 773 | + return '(' . substr($res,2+$descr['niv']) . ')'; |
|
| 774 | + } |
|
| 775 | + } else { |
|
| 776 | + $nom = $descr['nom'] . $id_boucle . ($descr['niv']?$descr['niv']:''); |
|
| 777 | + return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join(" ,\n$tab", $codes) . ")))"; |
|
| 778 | + } |
|
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | define('_REGEXP_COND_VIDE_NONVIDE',"/^[(](.*)[?]\s*''\s*:\s*('[^']+')\s*[)]$/"); |
@@ -786,173 +786,173 @@ discard block |
||
| 786 | 786 | function compile_cas($tableau, $descr, &$boucles, $id_boucle) { |
| 787 | 787 | |
| 788 | 788 | $codes = array(); |
| 789 | - // cas de la boucle recursive |
|
| 790 | - if (is_array($id_boucle)) |
|
| 791 | - $id_boucle = $id_boucle[0]; |
|
| 792 | - $type = !$id_boucle ? '' : $boucles[$id_boucle]->type_requete; |
|
| 793 | - $tab = str_repeat("\t", ++$descr['niv']); |
|
| 794 | - $mode = _request('var_mode_affiche'); |
|
| 795 | - $err_e_c = ''; |
|
| 796 | - // chaque commentaire introduit dans le code doit commencer |
|
| 797 | - // par un caractere distinguant le cas, pour exploitation par debug. |
|
| 798 | - foreach ($tableau as $p) { |
|
| 799 | - |
|
| 800 | - switch($p->type) { |
|
| 801 | - // texte seul |
|
| 802 | - case 'texte': |
|
| 803 | - $code = sandbox_composer_texte($p->texte, $p); |
|
| 804 | - $commentaire= strlen($p->texte) . " signes"; |
|
| 805 | - $avant=''; |
|
| 806 | - $apres=''; |
|
| 807 | - $altern = "''"; |
|
| 808 | - break; |
|
| 809 | - |
|
| 810 | - case 'polyglotte': |
|
| 811 | - $code = ""; |
|
| 812 | - foreach($p->traductions as $k => $v) { |
|
| 813 | - $code .= ",'" . |
|
| 814 | - str_replace(array("\\","'"),array("\\\\","\\'"), $k) . |
|
| 815 | - "' => '" . |
|
| 816 | - str_replace(array("\\","'"),array("\\\\","\\'"), $v) . |
|
| 817 | - "'"; |
|
| 818 | - } |
|
| 819 | - $code = "choisir_traduction(array(" . |
|
| 820 | - substr($code,1) . |
|
| 821 | - "))"; |
|
| 822 | - $commentaire= '&'; |
|
| 823 | - $avant=''; |
|
| 824 | - $apres=''; |
|
| 825 | - $altern = "''"; |
|
| 826 | - break; |
|
| 827 | - |
|
| 828 | - // inclure |
|
| 829 | - case 'include': |
|
| 830 | - $p->descr = $descr; |
|
| 831 | - $code = calculer_inclure($p, $boucles, $id_boucle); |
|
| 832 | - if ($code === false) { |
|
| 833 | - $err_e_c = true; |
|
| 834 | - $code = "''"; |
|
| 835 | - } else { |
|
| 836 | - $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 837 | - $avant=''; |
|
| 838 | - $apres=''; |
|
| 839 | - $altern = "''"; |
|
| 840 | - } |
|
| 841 | - break; |
|
| 842 | - |
|
| 843 | - // boucle |
|
| 844 | - case TYPE_RECURSIF: |
|
| 845 | - $nom = $p->id_boucle; |
|
| 846 | - $newdescr = $descr; |
|
| 847 | - $newdescr['id_mere'] = $nom; |
|
| 848 | - $newdescr['niv']++; |
|
| 849 | - $avant = calculer_liste($p->avant, |
|
| 850 | - $newdescr, $boucles, $id_boucle); |
|
| 851 | - $apres = calculer_liste($p->apres, |
|
| 852 | - $newdescr, $boucles, $id_boucle); |
|
| 853 | - $newdescr['niv']--; |
|
| 854 | - $altern = calculer_liste($p->altern, |
|
| 855 | - $newdescr, $boucles, $id_boucle); |
|
| 856 | - if (($avant === false) OR ($apres === false) OR ($altern === false)) { |
|
| 857 | - $err_e_c = true; |
|
| 858 | - $code = "''"; |
|
| 859 | - } else { |
|
| 860 | - $code = 'BOUCLE' . |
|
| 861 | - str_replace("-","_", $nom) . $descr['nom'] . |
|
| 862 | - '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
|
| 863 | - $commentaire= "?$nom"; |
|
| 864 | - if (!$boucles[$nom]->milieu |
|
| 865 | - AND $boucles[$nom]->type_requete <> TYPE_RECURSIF) { |
|
| 866 | - if ($altern != "''") $code .= "\n. $altern"; |
|
| 867 | - if ($avant<>"''" OR $apres<>"''") |
|
| 868 | - spip_log("boucle $nom toujours vide, code superflu dans $id"); |
|
| 869 | - $avant = $apres = $altern = "''"; |
|
| 870 | - } else if ($altern != "''") $altern = "($altern)"; |
|
| 871 | - } |
|
| 872 | - break; |
|
| 873 | - |
|
| 874 | - case 'idiome': |
|
| 875 | - $l = array(); |
|
| 876 | - $code = ''; |
|
| 877 | - foreach ($p->arg as $k => $v) { |
|
| 878 | - $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
|
| 879 | - if ($k) { |
|
| 880 | - $l[] = _q($k) . ' => ' . $_v; |
|
| 881 | - } else { |
|
| 882 | - $code = $_v; |
|
| 883 | - } |
|
| 884 | - } |
|
| 885 | - // Si le module n'est pas fourni, l'expliciter sauf si calculé |
|
| 886 | - if ($p->module) { |
|
| 887 | - $m = $p->module .':'.$p->nom_champ; |
|
| 888 | - } elseif ($p->nom_champ) { |
|
| 889 | - $m = MODULES_IDIOMES .':'.$p->nom_champ; |
|
| 890 | - } else { |
|
| 891 | - $m = ''; |
|
| 892 | - } |
|
| 893 | - $code = (!$code ? "'$m'" : |
|
| 894 | - ($m ? "'$m' . $code" : |
|
| 895 | - ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 896 | - . (!$l ? '' : (", array(" . implode(",\n", $l) . ")")); |
|
| 897 | - $code = "_T($code)"; |
|
| 898 | - if ($p->param) { |
|
| 899 | - $p->id_boucle = $id_boucle; |
|
| 900 | - $p->boucles = &$boucles; |
|
| 901 | - $code = compose_filtres($p, $code); |
|
| 902 | - } |
|
| 903 | - $commentaire = ":"; |
|
| 904 | - $avant=''; |
|
| 905 | - $apres=''; |
|
| 906 | - $altern = "''"; |
|
| 907 | - break; |
|
| 908 | - |
|
| 909 | - case 'champ': |
|
| 910 | - |
|
| 911 | - // cette structure pourrait etre completee des le phrase' (a faire) |
|
| 912 | - $p->id_boucle = $id_boucle; |
|
| 913 | - $p->boucles = &$boucles; |
|
| 914 | - $p->descr = $descr; |
|
| 915 | - #$p->interdire_scripts = true; |
|
| 916 | - $p->type_requete = $type; |
|
| 917 | - |
|
| 918 | - $code = calculer_champ($p); |
|
| 919 | - $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 920 | - $avant = calculer_liste($p->avant, |
|
| 921 | - $descr, $boucles, $id_boucle); |
|
| 922 | - $apres = calculer_liste($p->apres, |
|
| 923 | - $descr, $boucles, $id_boucle); |
|
| 924 | - $altern = "''"; |
|
| 925 | - // Si la valeur est destinee a une comparaison a '' |
|
| 926 | - // forcer la conversion en une chaine par strval |
|
| 927 | - // si ca peut etre autre chose qu'une chaine |
|
| 928 | - if (($avant != "''" OR $apres != "''") |
|
| 929 | - AND $code[0]!= "'" |
|
| 789 | + // cas de la boucle recursive |
|
| 790 | + if (is_array($id_boucle)) |
|
| 791 | + $id_boucle = $id_boucle[0]; |
|
| 792 | + $type = !$id_boucle ? '' : $boucles[$id_boucle]->type_requete; |
|
| 793 | + $tab = str_repeat("\t", ++$descr['niv']); |
|
| 794 | + $mode = _request('var_mode_affiche'); |
|
| 795 | + $err_e_c = ''; |
|
| 796 | + // chaque commentaire introduit dans le code doit commencer |
|
| 797 | + // par un caractere distinguant le cas, pour exploitation par debug. |
|
| 798 | + foreach ($tableau as $p) { |
|
| 799 | + |
|
| 800 | + switch($p->type) { |
|
| 801 | + // texte seul |
|
| 802 | + case 'texte': |
|
| 803 | + $code = sandbox_composer_texte($p->texte, $p); |
|
| 804 | + $commentaire= strlen($p->texte) . " signes"; |
|
| 805 | + $avant=''; |
|
| 806 | + $apres=''; |
|
| 807 | + $altern = "''"; |
|
| 808 | + break; |
|
| 809 | + |
|
| 810 | + case 'polyglotte': |
|
| 811 | + $code = ""; |
|
| 812 | + foreach($p->traductions as $k => $v) { |
|
| 813 | + $code .= ",'" . |
|
| 814 | + str_replace(array("\\","'"),array("\\\\","\\'"), $k) . |
|
| 815 | + "' => '" . |
|
| 816 | + str_replace(array("\\","'"),array("\\\\","\\'"), $v) . |
|
| 817 | + "'"; |
|
| 818 | + } |
|
| 819 | + $code = "choisir_traduction(array(" . |
|
| 820 | + substr($code,1) . |
|
| 821 | + "))"; |
|
| 822 | + $commentaire= '&'; |
|
| 823 | + $avant=''; |
|
| 824 | + $apres=''; |
|
| 825 | + $altern = "''"; |
|
| 826 | + break; |
|
| 827 | + |
|
| 828 | + // inclure |
|
| 829 | + case 'include': |
|
| 830 | + $p->descr = $descr; |
|
| 831 | + $code = calculer_inclure($p, $boucles, $id_boucle); |
|
| 832 | + if ($code === false) { |
|
| 833 | + $err_e_c = true; |
|
| 834 | + $code = "''"; |
|
| 835 | + } else { |
|
| 836 | + $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 837 | + $avant=''; |
|
| 838 | + $apres=''; |
|
| 839 | + $altern = "''"; |
|
| 840 | + } |
|
| 841 | + break; |
|
| 842 | + |
|
| 843 | + // boucle |
|
| 844 | + case TYPE_RECURSIF: |
|
| 845 | + $nom = $p->id_boucle; |
|
| 846 | + $newdescr = $descr; |
|
| 847 | + $newdescr['id_mere'] = $nom; |
|
| 848 | + $newdescr['niv']++; |
|
| 849 | + $avant = calculer_liste($p->avant, |
|
| 850 | + $newdescr, $boucles, $id_boucle); |
|
| 851 | + $apres = calculer_liste($p->apres, |
|
| 852 | + $newdescr, $boucles, $id_boucle); |
|
| 853 | + $newdescr['niv']--; |
|
| 854 | + $altern = calculer_liste($p->altern, |
|
| 855 | + $newdescr, $boucles, $id_boucle); |
|
| 856 | + if (($avant === false) OR ($apres === false) OR ($altern === false)) { |
|
| 857 | + $err_e_c = true; |
|
| 858 | + $code = "''"; |
|
| 859 | + } else { |
|
| 860 | + $code = 'BOUCLE' . |
|
| 861 | + str_replace("-","_", $nom) . $descr['nom'] . |
|
| 862 | + '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
|
| 863 | + $commentaire= "?$nom"; |
|
| 864 | + if (!$boucles[$nom]->milieu |
|
| 865 | + AND $boucles[$nom]->type_requete <> TYPE_RECURSIF) { |
|
| 866 | + if ($altern != "''") $code .= "\n. $altern"; |
|
| 867 | + if ($avant<>"''" OR $apres<>"''") |
|
| 868 | + spip_log("boucle $nom toujours vide, code superflu dans $id"); |
|
| 869 | + $avant = $apres = $altern = "''"; |
|
| 870 | + } else if ($altern != "''") $altern = "($altern)"; |
|
| 871 | + } |
|
| 872 | + break; |
|
| 873 | + |
|
| 874 | + case 'idiome': |
|
| 875 | + $l = array(); |
|
| 876 | + $code = ''; |
|
| 877 | + foreach ($p->arg as $k => $v) { |
|
| 878 | + $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
|
| 879 | + if ($k) { |
|
| 880 | + $l[] = _q($k) . ' => ' . $_v; |
|
| 881 | + } else { |
|
| 882 | + $code = $_v; |
|
| 883 | + } |
|
| 884 | + } |
|
| 885 | + // Si le module n'est pas fourni, l'expliciter sauf si calculé |
|
| 886 | + if ($p->module) { |
|
| 887 | + $m = $p->module .':'.$p->nom_champ; |
|
| 888 | + } elseif ($p->nom_champ) { |
|
| 889 | + $m = MODULES_IDIOMES .':'.$p->nom_champ; |
|
| 890 | + } else { |
|
| 891 | + $m = ''; |
|
| 892 | + } |
|
| 893 | + $code = (!$code ? "'$m'" : |
|
| 894 | + ($m ? "'$m' . $code" : |
|
| 895 | + ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 896 | + . (!$l ? '' : (", array(" . implode(",\n", $l) . ")")); |
|
| 897 | + $code = "_T($code)"; |
|
| 898 | + if ($p->param) { |
|
| 899 | + $p->id_boucle = $id_boucle; |
|
| 900 | + $p->boucles = &$boucles; |
|
| 901 | + $code = compose_filtres($p, $code); |
|
| 902 | + } |
|
| 903 | + $commentaire = ":"; |
|
| 904 | + $avant=''; |
|
| 905 | + $apres=''; |
|
| 906 | + $altern = "''"; |
|
| 907 | + break; |
|
| 908 | + |
|
| 909 | + case 'champ': |
|
| 910 | + |
|
| 911 | + // cette structure pourrait etre completee des le phrase' (a faire) |
|
| 912 | + $p->id_boucle = $id_boucle; |
|
| 913 | + $p->boucles = &$boucles; |
|
| 914 | + $p->descr = $descr; |
|
| 915 | + #$p->interdire_scripts = true; |
|
| 916 | + $p->type_requete = $type; |
|
| 917 | + |
|
| 918 | + $code = calculer_champ($p); |
|
| 919 | + $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 920 | + $avant = calculer_liste($p->avant, |
|
| 921 | + $descr, $boucles, $id_boucle); |
|
| 922 | + $apres = calculer_liste($p->apres, |
|
| 923 | + $descr, $boucles, $id_boucle); |
|
| 924 | + $altern = "''"; |
|
| 925 | + // Si la valeur est destinee a une comparaison a '' |
|
| 926 | + // forcer la conversion en une chaine par strval |
|
| 927 | + // si ca peut etre autre chose qu'une chaine |
|
| 928 | + if (($avant != "''" OR $apres != "''") |
|
| 929 | + AND $code[0]!= "'" |
|
| 930 | 930 | # AND (strpos($code,'interdire_scripts') !== 0) |
| 931 | - AND !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
|
| 932 | - AND !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
|
| 933 | - AND !preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) |
|
| 934 | - $code = "strval($code)"; |
|
| 935 | - break; |
|
| 936 | - |
|
| 937 | - default: |
|
| 938 | - // Erreur de construction de l'arbre de syntaxe abstraite |
|
| 939 | - $code = "''"; |
|
| 940 | - $p->descr = $descr; |
|
| 941 | - $err_e_c = _T('zbug_erreur_compilation'); |
|
| 942 | - erreur_squelette($err_e_c, $p); |
|
| 943 | - } // switch |
|
| 944 | - |
|
| 945 | - if ($code != "''") { |
|
| 946 | - $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
|
| 947 | - $codes[]= (($mode == 'validation') ? |
|
| 948 | - "array($code, '$commentaire', " . $p->ligne . ")" |
|
| 949 | - : (($mode == 'code') ? |
|
| 950 | - "\n// $commentaire\n$code" : |
|
| 951 | - $code)); |
|
| 952 | - } |
|
| 953 | - } // foreach |
|
| 954 | - |
|
| 955 | - return $err_e_c ? false : $codes; |
|
| 931 | + AND !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
|
| 932 | + AND !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
|
| 933 | + AND !preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) |
|
| 934 | + $code = "strval($code)"; |
|
| 935 | + break; |
|
| 936 | + |
|
| 937 | + default: |
|
| 938 | + // Erreur de construction de l'arbre de syntaxe abstraite |
|
| 939 | + $code = "''"; |
|
| 940 | + $p->descr = $descr; |
|
| 941 | + $err_e_c = _T('zbug_erreur_compilation'); |
|
| 942 | + erreur_squelette($err_e_c, $p); |
|
| 943 | + } // switch |
|
| 944 | + |
|
| 945 | + if ($code != "''") { |
|
| 946 | + $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
|
| 947 | + $codes[]= (($mode == 'validation') ? |
|
| 948 | + "array($code, '$commentaire', " . $p->ligne . ")" |
|
| 949 | + : (($mode == 'code') ? |
|
| 950 | + "\n// $commentaire\n$code" : |
|
| 951 | + $code)); |
|
| 952 | + } |
|
| 953 | + } // foreach |
|
| 954 | + |
|
| 955 | + return $err_e_c ? false : $codes; |
|
| 956 | 956 | } |
| 957 | 957 | |
| 958 | 958 | // production d'une expression conditionnelle ((v=EXP) ? (p . v .s) : a) |
@@ -962,41 +962,41 @@ discard block |
||
| 962 | 962 | // http://doc.spip.org/@compile_retour |
| 963 | 963 | function compile_retour($code, $avant, $apres, $altern, $tab, $n) |
| 964 | 964 | { |
| 965 | - if ($avant == "''") $avant = ''; |
|
| 966 | - if ($apres == "''") $apres = ''; |
|
| 967 | - if (!$avant AND !$apres AND ($altern==="''")) return $code; |
|
| 968 | - |
|
| 969 | - if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) { |
|
| 970 | - $t = $code; |
|
| 971 | - $cond = ''; |
|
| 972 | - } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE,$code, $r)) { |
|
| 973 | - $t = $r[2]; |
|
| 974 | - $cond = '!' . $r[1]; |
|
| 975 | - } else if (preg_match(_REGEXP_COND_NONVIDE_VIDE,$code, $r)) { |
|
| 976 | - $t = $r[2]; |
|
| 977 | - $cond = $r[1]; |
|
| 978 | - } else { |
|
| 979 | - $t = '$t' . $n; |
|
| 980 | - $cond = "($t = $code)!==''"; |
|
| 981 | - } |
|
| 982 | - |
|
| 983 | - $res = (!$avant ? "" : "$avant . ") . |
|
| 984 | - $t . |
|
| 985 | - (!$apres ? "" : " . $apres"); |
|
| 986 | - |
|
| 987 | - if ($res !== $t) $res = "($res)"; |
|
| 988 | - return !$cond ? $res : "($cond ?\n\t$tab$res :\n\t$tab$altern)"; |
|
| 965 | + if ($avant == "''") $avant = ''; |
|
| 966 | + if ($apres == "''") $apres = ''; |
|
| 967 | + if (!$avant AND !$apres AND ($altern==="''")) return $code; |
|
| 968 | + |
|
| 969 | + if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) { |
|
| 970 | + $t = $code; |
|
| 971 | + $cond = ''; |
|
| 972 | + } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE,$code, $r)) { |
|
| 973 | + $t = $r[2]; |
|
| 974 | + $cond = '!' . $r[1]; |
|
| 975 | + } else if (preg_match(_REGEXP_COND_NONVIDE_VIDE,$code, $r)) { |
|
| 976 | + $t = $r[2]; |
|
| 977 | + $cond = $r[1]; |
|
| 978 | + } else { |
|
| 979 | + $t = '$t' . $n; |
|
| 980 | + $cond = "($t = $code)!==''"; |
|
| 981 | + } |
|
| 982 | + |
|
| 983 | + $res = (!$avant ? "" : "$avant . ") . |
|
| 984 | + $t . |
|
| 985 | + (!$apres ? "" : " . $apres"); |
|
| 986 | + |
|
| 987 | + if ($res !== $t) $res = "($res)"; |
|
| 988 | + return !$cond ? $res : "($cond ?\n\t$tab$res :\n\t$tab$altern)"; |
|
| 989 | 989 | } |
| 990 | 990 | |
| 991 | 991 | |
| 992 | 992 | function compile_inclure_doublons($lexemes) |
| 993 | 993 | { |
| 994 | - foreach($lexemes as $v) |
|
| 995 | - if($v->type === 'include' AND $v->param) |
|
| 996 | - foreach($v->param as $r) |
|
| 997 | - if (trim($r[0]) === 'doublons') |
|
| 998 | - return true; |
|
| 999 | - return false; |
|
| 994 | + foreach($lexemes as $v) |
|
| 995 | + if($v->type === 'include' AND $v->param) |
|
| 996 | + foreach($v->param as $r) |
|
| 997 | + if (trim($r[0]) === 'doublons') |
|
| 998 | + return true; |
|
| 999 | + return false; |
|
| 1000 | 1000 | } |
| 1001 | 1001 | |
| 1002 | 1002 | // Prend en argument le texte d'un squelette, le nom de son fichier d'origine, |
@@ -1016,296 +1016,296 @@ discard block |
||
| 1016 | 1016 | |
| 1017 | 1017 | // http://doc.spip.org/@public_compiler_dist |
| 1018 | 1018 | function public_compiler_dist($squelette, $nom, $gram, $sourcefile, $connect=''){ |
| 1019 | - // Pre-traitement : reperer le charset du squelette, et le convertir |
|
| 1020 | - // Bonus : supprime le BOM |
|
| 1021 | - include_spip('inc/charsets'); |
|
| 1022 | - $squelette = transcoder_page($squelette); |
|
| 1023 | - |
|
| 1024 | - // rendre inertes les echappements de #[](){}<> |
|
| 1025 | - $i = 0; |
|
| 1026 | - while(false !== strpos($squelette, $inerte = '-INERTE'.$i)) $i++; |
|
| 1027 | - $squelette = preg_replace_callback(',\\\\([#[()\]{}<>]),', |
|
| 1028 | - create_function('$a', "return '$inerte-'.ord(\$a[1]).'-';"), $squelette, -1, $esc); |
|
| 1029 | - |
|
| 1030 | - $descr = array('nom' => $nom, |
|
| 1031 | - 'gram' => $gram, |
|
| 1032 | - 'sourcefile' => $sourcefile, |
|
| 1033 | - 'squelette' => $squelette); |
|
| 1034 | - |
|
| 1035 | - // Phraser le squelette, selon sa grammaire |
|
| 1036 | - |
|
| 1037 | - $boucles = array(); |
|
| 1038 | - $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1039 | - |
|
| 1040 | - $squelette = $f($squelette, '', $boucles, $descr); |
|
| 1041 | - $boucles = compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect); |
|
| 1042 | - |
|
| 1043 | - // restituer les echappements |
|
| 1044 | - if ($esc) |
|
| 1045 | - foreach($boucles as $i=>$boucle) { |
|
| 1046 | - $boucles[$i]->return = preg_replace_callback(",$inerte-(\d+)-,", create_function('$a', 'return chr($a[1]);'), |
|
| 1047 | - $boucle->return); |
|
| 1048 | - $boucles[$i]->descr['squelette'] = preg_replace_callback(",$inerte-(\d+)-,", create_function('$a', 'return "\\\\".chr($a[1]);'), |
|
| 1049 | - $boucle->descr['squelette']); |
|
| 1050 | - } |
|
| 1019 | + // Pre-traitement : reperer le charset du squelette, et le convertir |
|
| 1020 | + // Bonus : supprime le BOM |
|
| 1021 | + include_spip('inc/charsets'); |
|
| 1022 | + $squelette = transcoder_page($squelette); |
|
| 1023 | + |
|
| 1024 | + // rendre inertes les echappements de #[](){}<> |
|
| 1025 | + $i = 0; |
|
| 1026 | + while(false !== strpos($squelette, $inerte = '-INERTE'.$i)) $i++; |
|
| 1027 | + $squelette = preg_replace_callback(',\\\\([#[()\]{}<>]),', |
|
| 1028 | + create_function('$a', "return '$inerte-'.ord(\$a[1]).'-';"), $squelette, -1, $esc); |
|
| 1029 | + |
|
| 1030 | + $descr = array('nom' => $nom, |
|
| 1031 | + 'gram' => $gram, |
|
| 1032 | + 'sourcefile' => $sourcefile, |
|
| 1033 | + 'squelette' => $squelette); |
|
| 1034 | + |
|
| 1035 | + // Phraser le squelette, selon sa grammaire |
|
| 1036 | + |
|
| 1037 | + $boucles = array(); |
|
| 1038 | + $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1039 | + |
|
| 1040 | + $squelette = $f($squelette, '', $boucles, $descr); |
|
| 1041 | + $boucles = compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect); |
|
| 1042 | + |
|
| 1043 | + // restituer les echappements |
|
| 1044 | + if ($esc) |
|
| 1045 | + foreach($boucles as $i=>$boucle) { |
|
| 1046 | + $boucles[$i]->return = preg_replace_callback(",$inerte-(\d+)-,", create_function('$a', 'return chr($a[1]);'), |
|
| 1047 | + $boucle->return); |
|
| 1048 | + $boucles[$i]->descr['squelette'] = preg_replace_callback(",$inerte-(\d+)-,", create_function('$a', 'return "\\\\".chr($a[1]);'), |
|
| 1049 | + $boucle->descr['squelette']); |
|
| 1050 | + } |
|
| 1051 | 1051 | |
| 1052 | - $debug = ($boucles AND defined('_VAR_MODE') AND _VAR_MODE == 'debug'); |
|
| 1053 | - if ($debug) { |
|
| 1054 | - include_spip('public/decompiler'); |
|
| 1055 | - foreach($boucles as $id => $boucle) { |
|
| 1056 | - if ($id) |
|
| 1057 | - $decomp = "\n/* BOUCLE " . |
|
| 1058 | - $boucle->type_requete . |
|
| 1059 | - " " . |
|
| 1060 | - str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1061 | - " */\n"; |
|
| 1062 | - else $decomp = ("\n/*\n" . |
|
| 1063 | - str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
|
| 1064 | - . "\n*/"); |
|
| 1065 | - $boucles[$id]->return = $decomp .$boucle->return; |
|
| 1066 | - $GLOBALS['debug_objets']['code'][$nom.$id] = $boucle->return; |
|
| 1067 | - } |
|
| 1068 | - } |
|
| 1069 | - |
|
| 1070 | - return $boucles; |
|
| 1052 | + $debug = ($boucles AND defined('_VAR_MODE') AND _VAR_MODE == 'debug'); |
|
| 1053 | + if ($debug) { |
|
| 1054 | + include_spip('public/decompiler'); |
|
| 1055 | + foreach($boucles as $id => $boucle) { |
|
| 1056 | + if ($id) |
|
| 1057 | + $decomp = "\n/* BOUCLE " . |
|
| 1058 | + $boucle->type_requete . |
|
| 1059 | + " " . |
|
| 1060 | + str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1061 | + " */\n"; |
|
| 1062 | + else $decomp = ("\n/*\n" . |
|
| 1063 | + str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
|
| 1064 | + . "\n*/"); |
|
| 1065 | + $boucles[$id]->return = $decomp .$boucle->return; |
|
| 1066 | + $GLOBALS['debug_objets']['code'][$nom.$id] = $boucle->return; |
|
| 1067 | + } |
|
| 1068 | + } |
|
| 1069 | + |
|
| 1070 | + return $boucles; |
|
| 1071 | 1071 | } |
| 1072 | 1072 | |
| 1073 | 1073 | // Point d'entree pour arbre de syntaxe abstraite fourni en premier argument |
| 1074 | 1074 | // Autres specifications comme ci-dessus |
| 1075 | 1075 | |
| 1076 | 1076 | function compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect=''){ |
| 1077 | - static $trouver_table; |
|
| 1078 | - spip_timer('calcul_skel'); |
|
| 1079 | - |
|
| 1080 | - if (defined('_VAR_MODE') AND _VAR_MODE == 'debug') { |
|
| 1081 | - $GLOBALS['debug_objets']['squelette'][$nom] = $descr['squelette']; |
|
| 1082 | - $GLOBALS['debug_objets']['sourcefile'][$nom] = $sourcefile; |
|
| 1083 | - |
|
| 1084 | - if (!isset($GLOBALS['debug_objets']['principal'])) |
|
| 1085 | - $GLOBALS['debug_objets']['principal'] = $nom; |
|
| 1086 | - } |
|
| 1087 | - foreach ($boucles as $id => $boucle) { |
|
| 1088 | - $GLOBALS['debug_objets']['boucle'][$nom.$id] = $boucle; |
|
| 1089 | - } |
|
| 1090 | - $descr['documents'] = compile_inclure_doublons($squelette); |
|
| 1091 | - |
|
| 1092 | - // Demander la description des tables une fois pour toutes |
|
| 1093 | - // et reperer si les doublons sont demandes |
|
| 1094 | - // pour un inclure ou une boucle document |
|
| 1095 | - // c'est utile a la fonction champs_traitements |
|
| 1096 | - if (!$trouver_table) |
|
| 1097 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1098 | - |
|
| 1099 | - foreach($boucles as $id => $boucle) { |
|
| 1100 | - if (!($type = $boucle->type_requete)) continue; |
|
| 1101 | - if (!$descr['documents'] AND ( |
|
| 1102 | - (($type == 'documents') AND $boucle->doublons) OR |
|
| 1103 | - compile_inclure_doublons($boucle->avant) OR |
|
| 1104 | - compile_inclure_doublons($boucle->apres) OR |
|
| 1105 | - compile_inclure_doublons($boucle->milieu) OR |
|
| 1106 | - compile_inclure_doublons($boucle->altern))) |
|
| 1107 | - $descr['documents'] = true; |
|
| 1108 | - if ($type != TYPE_RECURSIF) { |
|
| 1109 | - if (!$boucles[$id]->sql_serveur AND $connect) |
|
| 1110 | - $boucles[$id]->sql_serveur = $connect; |
|
| 1111 | - |
|
| 1112 | - // chercher dans les iterateurs du repertoire iterateur/ |
|
| 1113 | - if ($g = charger_fonction( |
|
| 1114 | - preg_replace('/\W/', '_', $boucle->type_requete), 'iterateur', true)) { |
|
| 1115 | - $boucles[$id] = $g($boucle); |
|
| 1116 | - |
|
| 1117 | - // sinon, en cas de requeteur d'un type predefini, |
|
| 1118 | - // utiliser les informations donnees par le requeteur |
|
| 1119 | - // cas "php:xx" et "data:xx". |
|
| 1120 | - } else if ($boucle->sql_serveur AND $requeteur = charger_fonction($boucle->sql_serveur, 'requeteur', true)) { |
|
| 1121 | - $requeteur($boucles, $boucle, $id); |
|
| 1122 | - |
|
| 1123 | - // utiliser la description des champs transmis |
|
| 1124 | - } else { |
|
| 1125 | - $show = $trouver_table($type, $boucles[$id]->sql_serveur); |
|
| 1126 | - // si la table n'existe pas avec le connecteur par defaut, |
|
| 1127 | - // c'est peut etre une table qui necessite son connecteur dedie fourni |
|
| 1128 | - // permet une ecriture allegee (GEO) -> (geo:GEO) |
|
| 1129 | - if (!$show |
|
| 1130 | - AND $show=$trouver_table($type, strtolower($type))) { |
|
| 1131 | - $boucles[$id]->sql_serveur = strtolower($type); |
|
| 1132 | - } |
|
| 1133 | - if ($show) { |
|
| 1134 | - $boucles[$id]->show = $show; |
|
| 1135 | - // recopie les infos les plus importantes |
|
| 1136 | - $boucles[$id]->primary = $show['key']["PRIMARY KEY"]; |
|
| 1137 | - $boucles[$id]->id_table = $x = preg_replace(",^spip_,","",$show['id_table']); |
|
| 1138 | - $boucles[$id]->from[$x] = $nom_table = $show['table']; |
|
| 1139 | - $boucles[$id]->iterateur = 'SQL'; |
|
| 1140 | - |
|
| 1141 | - $boucles[$id]->descr = &$descr; |
|
| 1142 | - if ((!$boucles[$id]->jointures) |
|
| 1143 | - AND is_array($show['tables_jointures']) |
|
| 1144 | - AND count($x = $show['tables_jointures'])) |
|
| 1145 | - $boucles[$id]->jointures = $x; |
|
| 1146 | - if ($boucles[$id]->jointures_explicites){ |
|
| 1147 | - $jointures = preg_split("/\s+/",$boucles[$id]->jointures_explicites); |
|
| 1148 | - while ($j=array_pop($jointures)) |
|
| 1149 | - array_unshift($boucles[$id]->jointures,$j); |
|
| 1150 | - } |
|
| 1151 | - } else { |
|
| 1152 | - // Pas une erreur si la table est optionnelle |
|
| 1153 | - if ($boucles[$id]->table_optionnelle) |
|
| 1154 | - $boucles[$id]->type_requete = ''; |
|
| 1155 | - else { |
|
| 1156 | - $boucles[$id]->type_requete = false; |
|
| 1157 | - $boucle = $boucles[$id]; |
|
| 1158 | - $x = (!$boucle->sql_serveur ? '' : |
|
| 1159 | - ($boucle->sql_serveur . ":")) . |
|
| 1160 | - $type; |
|
| 1161 | - $msg = array('zbug_table_inconnue', |
|
| 1162 | - array('table' => $x)); |
|
| 1163 | - erreur_squelette($msg, $boucle); |
|
| 1164 | - } |
|
| 1165 | - } |
|
| 1166 | - } |
|
| 1167 | - } |
|
| 1168 | - } |
|
| 1169 | - |
|
| 1170 | - // Commencer par reperer les boucles appelees explicitement |
|
| 1171 | - // car elles indexent les arguments de maniere derogatoire |
|
| 1172 | - foreach($boucles as $id => $boucle) { |
|
| 1173 | - if ($boucle->type_requete == TYPE_RECURSIF AND $boucle->param) { |
|
| 1174 | - $boucles[$id]->descr = &$descr; |
|
| 1175 | - $rec = &$boucles[$boucle->param[0]]; |
|
| 1176 | - if (!$rec) { |
|
| 1177 | - $msg = array('zbug_boucle_recursive_undef', |
|
| 1178 | - array('nom' => $boucle->param[0])); |
|
| 1179 | - erreur_squelette($msg, $boucle); |
|
| 1180 | - $boucles[$id]->type_requete = false; |
|
| 1181 | - } else { |
|
| 1182 | - $rec->externe = $id; |
|
| 1183 | - $descr['id_mere'] = $id; |
|
| 1184 | - $boucles[$id]->return = |
|
| 1185 | - calculer_liste(array($rec), |
|
| 1186 | - $descr, |
|
| 1187 | - $boucles, |
|
| 1188 | - $boucle->param); |
|
| 1189 | - } |
|
| 1190 | - } |
|
| 1191 | - } |
|
| 1192 | - foreach($boucles as $id => $boucle) { |
|
| 1193 | - $id = strval($id); // attention au type dans index_pile |
|
| 1194 | - $type = $boucle->type_requete; |
|
| 1195 | - if ($type AND $type != TYPE_RECURSIF) { |
|
| 1196 | - $res = ''; |
|
| 1197 | - if ($boucle->param) { |
|
| 1198 | - // retourne un tableau en cas d'erreur |
|
| 1199 | - $res = calculer_criteres($id, $boucles); |
|
| 1200 | - } |
|
| 1201 | - $descr['id_mere'] = $id; |
|
| 1202 | - $boucles[$id]->return = |
|
| 1203 | - calculer_liste($boucle->milieu, |
|
| 1204 | - $descr, |
|
| 1205 | - $boucles, |
|
| 1206 | - $id); |
|
| 1207 | - // Si les criteres se sont mal compiles |
|
| 1208 | - // ne pas tenter d'assembler le code final |
|
| 1209 | - // (mais compiler le corps pour detection d'erreurs) |
|
| 1210 | - if (is_array($res)) { |
|
| 1211 | - $boucles[$id]->type_requete = false; |
|
| 1212 | - } |
|
| 1213 | - } |
|
| 1214 | - } |
|
| 1215 | - |
|
| 1216 | - // idem pour la racine |
|
| 1217 | - $descr['id_mere'] = ''; |
|
| 1218 | - $corps = calculer_liste($squelette, $descr, $boucles); |
|
| 1219 | - |
|
| 1220 | - |
|
| 1221 | - |
|
| 1222 | - // Calcul du corps de toutes les fonctions PHP, |
|
| 1223 | - // en particulier les requetes SQL et TOTAL_BOUCLE |
|
| 1224 | - // de'terminables seulement maintenant |
|
| 1225 | - |
|
| 1226 | - foreach($boucles as $id => $boucle) { |
|
| 1227 | - $boucle = $boucles[$id] = pipeline('pre_boucle', $boucle); |
|
| 1228 | - if ($boucle->return === false) {$corps = false; continue;} |
|
| 1229 | - // appeler la fonction de definition de la boucle |
|
| 1230 | - |
|
| 1231 | - if ($req = $boucle->type_requete) { |
|
| 1232 | - // boucle personnalisée ? |
|
| 1233 | - $table = strtoupper($boucle->type_requete); |
|
| 1234 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1235 | - if ( |
|
| 1236 | - // fonction de boucle avec serveur & table |
|
| 1237 | - (!$serveur OR |
|
| 1238 | - ((!function_exists($f = "boucle_".$serveur."_".$table)) |
|
| 1239 | - AND (!function_exists($f = $f."_dist")) |
|
| 1240 | - ) |
|
| 1241 | - ) |
|
| 1242 | - // fonction de boucle avec table |
|
| 1243 | - AND (!function_exists($f = "boucle_".$table)) |
|
| 1244 | - AND (!function_exists($f = $f."_dist")) |
|
| 1245 | - ){ |
|
| 1246 | - // fonction de boucle standard |
|
| 1247 | - if (!function_exists($f = 'boucle_DEFAUT')) { |
|
| 1248 | - $f = 'boucle_DEFAUT_dist'; |
|
| 1249 | - } |
|
| 1250 | - } |
|
| 1251 | - |
|
| 1252 | - $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1253 | - "static \$connect;\n\t" . |
|
| 1254 | - "\$command['connect'] = \$connect = " . |
|
| 1255 | - _q($boucle->sql_serveur) . |
|
| 1256 | - ";" . |
|
| 1257 | - $f($id, $boucles); |
|
| 1258 | - } else $req = ("\n\treturn '';"); |
|
| 1259 | - |
|
| 1260 | - $boucles[$id]->return = |
|
| 1261 | - "\n\nfunction BOUCLE" . strtr($id,"-","_") . $nom . |
|
| 1262 | - '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1263 | - $req . |
|
| 1264 | - "\n}\n"; |
|
| 1265 | - } |
|
| 1266 | - |
|
| 1267 | - // Au final, si le corps ou un critere au moins s'est mal compile |
|
| 1268 | - // retourner False, sinon inserer leur decompilation |
|
| 1269 | - if (is_bool($corps)) return false; |
|
| 1270 | - |
|
| 1271 | - $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons=array(), $Numrows=array(), $SP=0) { |
|
| 1077 | + static $trouver_table; |
|
| 1078 | + spip_timer('calcul_skel'); |
|
| 1079 | + |
|
| 1080 | + if (defined('_VAR_MODE') AND _VAR_MODE == 'debug') { |
|
| 1081 | + $GLOBALS['debug_objets']['squelette'][$nom] = $descr['squelette']; |
|
| 1082 | + $GLOBALS['debug_objets']['sourcefile'][$nom] = $sourcefile; |
|
| 1083 | + |
|
| 1084 | + if (!isset($GLOBALS['debug_objets']['principal'])) |
|
| 1085 | + $GLOBALS['debug_objets']['principal'] = $nom; |
|
| 1086 | + } |
|
| 1087 | + foreach ($boucles as $id => $boucle) { |
|
| 1088 | + $GLOBALS['debug_objets']['boucle'][$nom.$id] = $boucle; |
|
| 1089 | + } |
|
| 1090 | + $descr['documents'] = compile_inclure_doublons($squelette); |
|
| 1091 | + |
|
| 1092 | + // Demander la description des tables une fois pour toutes |
|
| 1093 | + // et reperer si les doublons sont demandes |
|
| 1094 | + // pour un inclure ou une boucle document |
|
| 1095 | + // c'est utile a la fonction champs_traitements |
|
| 1096 | + if (!$trouver_table) |
|
| 1097 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1098 | + |
|
| 1099 | + foreach($boucles as $id => $boucle) { |
|
| 1100 | + if (!($type = $boucle->type_requete)) continue; |
|
| 1101 | + if (!$descr['documents'] AND ( |
|
| 1102 | + (($type == 'documents') AND $boucle->doublons) OR |
|
| 1103 | + compile_inclure_doublons($boucle->avant) OR |
|
| 1104 | + compile_inclure_doublons($boucle->apres) OR |
|
| 1105 | + compile_inclure_doublons($boucle->milieu) OR |
|
| 1106 | + compile_inclure_doublons($boucle->altern))) |
|
| 1107 | + $descr['documents'] = true; |
|
| 1108 | + if ($type != TYPE_RECURSIF) { |
|
| 1109 | + if (!$boucles[$id]->sql_serveur AND $connect) |
|
| 1110 | + $boucles[$id]->sql_serveur = $connect; |
|
| 1111 | + |
|
| 1112 | + // chercher dans les iterateurs du repertoire iterateur/ |
|
| 1113 | + if ($g = charger_fonction( |
|
| 1114 | + preg_replace('/\W/', '_', $boucle->type_requete), 'iterateur', true)) { |
|
| 1115 | + $boucles[$id] = $g($boucle); |
|
| 1116 | + |
|
| 1117 | + // sinon, en cas de requeteur d'un type predefini, |
|
| 1118 | + // utiliser les informations donnees par le requeteur |
|
| 1119 | + // cas "php:xx" et "data:xx". |
|
| 1120 | + } else if ($boucle->sql_serveur AND $requeteur = charger_fonction($boucle->sql_serveur, 'requeteur', true)) { |
|
| 1121 | + $requeteur($boucles, $boucle, $id); |
|
| 1122 | + |
|
| 1123 | + // utiliser la description des champs transmis |
|
| 1124 | + } else { |
|
| 1125 | + $show = $trouver_table($type, $boucles[$id]->sql_serveur); |
|
| 1126 | + // si la table n'existe pas avec le connecteur par defaut, |
|
| 1127 | + // c'est peut etre une table qui necessite son connecteur dedie fourni |
|
| 1128 | + // permet une ecriture allegee (GEO) -> (geo:GEO) |
|
| 1129 | + if (!$show |
|
| 1130 | + AND $show=$trouver_table($type, strtolower($type))) { |
|
| 1131 | + $boucles[$id]->sql_serveur = strtolower($type); |
|
| 1132 | + } |
|
| 1133 | + if ($show) { |
|
| 1134 | + $boucles[$id]->show = $show; |
|
| 1135 | + // recopie les infos les plus importantes |
|
| 1136 | + $boucles[$id]->primary = $show['key']["PRIMARY KEY"]; |
|
| 1137 | + $boucles[$id]->id_table = $x = preg_replace(",^spip_,","",$show['id_table']); |
|
| 1138 | + $boucles[$id]->from[$x] = $nom_table = $show['table']; |
|
| 1139 | + $boucles[$id]->iterateur = 'SQL'; |
|
| 1140 | + |
|
| 1141 | + $boucles[$id]->descr = &$descr; |
|
| 1142 | + if ((!$boucles[$id]->jointures) |
|
| 1143 | + AND is_array($show['tables_jointures']) |
|
| 1144 | + AND count($x = $show['tables_jointures'])) |
|
| 1145 | + $boucles[$id]->jointures = $x; |
|
| 1146 | + if ($boucles[$id]->jointures_explicites){ |
|
| 1147 | + $jointures = preg_split("/\s+/",$boucles[$id]->jointures_explicites); |
|
| 1148 | + while ($j=array_pop($jointures)) |
|
| 1149 | + array_unshift($boucles[$id]->jointures,$j); |
|
| 1150 | + } |
|
| 1151 | + } else { |
|
| 1152 | + // Pas une erreur si la table est optionnelle |
|
| 1153 | + if ($boucles[$id]->table_optionnelle) |
|
| 1154 | + $boucles[$id]->type_requete = ''; |
|
| 1155 | + else { |
|
| 1156 | + $boucles[$id]->type_requete = false; |
|
| 1157 | + $boucle = $boucles[$id]; |
|
| 1158 | + $x = (!$boucle->sql_serveur ? '' : |
|
| 1159 | + ($boucle->sql_serveur . ":")) . |
|
| 1160 | + $type; |
|
| 1161 | + $msg = array('zbug_table_inconnue', |
|
| 1162 | + array('table' => $x)); |
|
| 1163 | + erreur_squelette($msg, $boucle); |
|
| 1164 | + } |
|
| 1165 | + } |
|
| 1166 | + } |
|
| 1167 | + } |
|
| 1168 | + } |
|
| 1169 | + |
|
| 1170 | + // Commencer par reperer les boucles appelees explicitement |
|
| 1171 | + // car elles indexent les arguments de maniere derogatoire |
|
| 1172 | + foreach($boucles as $id => $boucle) { |
|
| 1173 | + if ($boucle->type_requete == TYPE_RECURSIF AND $boucle->param) { |
|
| 1174 | + $boucles[$id]->descr = &$descr; |
|
| 1175 | + $rec = &$boucles[$boucle->param[0]]; |
|
| 1176 | + if (!$rec) { |
|
| 1177 | + $msg = array('zbug_boucle_recursive_undef', |
|
| 1178 | + array('nom' => $boucle->param[0])); |
|
| 1179 | + erreur_squelette($msg, $boucle); |
|
| 1180 | + $boucles[$id]->type_requete = false; |
|
| 1181 | + } else { |
|
| 1182 | + $rec->externe = $id; |
|
| 1183 | + $descr['id_mere'] = $id; |
|
| 1184 | + $boucles[$id]->return = |
|
| 1185 | + calculer_liste(array($rec), |
|
| 1186 | + $descr, |
|
| 1187 | + $boucles, |
|
| 1188 | + $boucle->param); |
|
| 1189 | + } |
|
| 1190 | + } |
|
| 1191 | + } |
|
| 1192 | + foreach($boucles as $id => $boucle) { |
|
| 1193 | + $id = strval($id); // attention au type dans index_pile |
|
| 1194 | + $type = $boucle->type_requete; |
|
| 1195 | + if ($type AND $type != TYPE_RECURSIF) { |
|
| 1196 | + $res = ''; |
|
| 1197 | + if ($boucle->param) { |
|
| 1198 | + // retourne un tableau en cas d'erreur |
|
| 1199 | + $res = calculer_criteres($id, $boucles); |
|
| 1200 | + } |
|
| 1201 | + $descr['id_mere'] = $id; |
|
| 1202 | + $boucles[$id]->return = |
|
| 1203 | + calculer_liste($boucle->milieu, |
|
| 1204 | + $descr, |
|
| 1205 | + $boucles, |
|
| 1206 | + $id); |
|
| 1207 | + // Si les criteres se sont mal compiles |
|
| 1208 | + // ne pas tenter d'assembler le code final |
|
| 1209 | + // (mais compiler le corps pour detection d'erreurs) |
|
| 1210 | + if (is_array($res)) { |
|
| 1211 | + $boucles[$id]->type_requete = false; |
|
| 1212 | + } |
|
| 1213 | + } |
|
| 1214 | + } |
|
| 1215 | + |
|
| 1216 | + // idem pour la racine |
|
| 1217 | + $descr['id_mere'] = ''; |
|
| 1218 | + $corps = calculer_liste($squelette, $descr, $boucles); |
|
| 1219 | + |
|
| 1220 | + |
|
| 1221 | + |
|
| 1222 | + // Calcul du corps de toutes les fonctions PHP, |
|
| 1223 | + // en particulier les requetes SQL et TOTAL_BOUCLE |
|
| 1224 | + // de'terminables seulement maintenant |
|
| 1225 | + |
|
| 1226 | + foreach($boucles as $id => $boucle) { |
|
| 1227 | + $boucle = $boucles[$id] = pipeline('pre_boucle', $boucle); |
|
| 1228 | + if ($boucle->return === false) {$corps = false; continue;} |
|
| 1229 | + // appeler la fonction de definition de la boucle |
|
| 1230 | + |
|
| 1231 | + if ($req = $boucle->type_requete) { |
|
| 1232 | + // boucle personnalisée ? |
|
| 1233 | + $table = strtoupper($boucle->type_requete); |
|
| 1234 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1235 | + if ( |
|
| 1236 | + // fonction de boucle avec serveur & table |
|
| 1237 | + (!$serveur OR |
|
| 1238 | + ((!function_exists($f = "boucle_".$serveur."_".$table)) |
|
| 1239 | + AND (!function_exists($f = $f."_dist")) |
|
| 1240 | + ) |
|
| 1241 | + ) |
|
| 1242 | + // fonction de boucle avec table |
|
| 1243 | + AND (!function_exists($f = "boucle_".$table)) |
|
| 1244 | + AND (!function_exists($f = $f."_dist")) |
|
| 1245 | + ){ |
|
| 1246 | + // fonction de boucle standard |
|
| 1247 | + if (!function_exists($f = 'boucle_DEFAUT')) { |
|
| 1248 | + $f = 'boucle_DEFAUT_dist'; |
|
| 1249 | + } |
|
| 1250 | + } |
|
| 1251 | + |
|
| 1252 | + $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1253 | + "static \$connect;\n\t" . |
|
| 1254 | + "\$command['connect'] = \$connect = " . |
|
| 1255 | + _q($boucle->sql_serveur) . |
|
| 1256 | + ";" . |
|
| 1257 | + $f($id, $boucles); |
|
| 1258 | + } else $req = ("\n\treturn '';"); |
|
| 1259 | + |
|
| 1260 | + $boucles[$id]->return = |
|
| 1261 | + "\n\nfunction BOUCLE" . strtr($id,"-","_") . $nom . |
|
| 1262 | + '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1263 | + $req . |
|
| 1264 | + "\n}\n"; |
|
| 1265 | + } |
|
| 1266 | + |
|
| 1267 | + // Au final, si le corps ou un critere au moins s'est mal compile |
|
| 1268 | + // retourner False, sinon inserer leur decompilation |
|
| 1269 | + if (is_bool($corps)) return false; |
|
| 1270 | + |
|
| 1271 | + $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons=array(), $Numrows=array(), $SP=0) { |
|
| 1272 | 1272 | ' |
| 1273 | - // reporter de maniere securisee les doublons inclus |
|
| 1273 | + // reporter de maniere securisee les doublons inclus |
|
| 1274 | 1274 | .' |
| 1275 | 1275 | if (isset($Pile[0]["doublons"]) AND is_array($Pile[0]["doublons"])) |
| 1276 | 1276 | $doublons = nettoyer_env_doublons($Pile[0]["doublons"]); |
| 1277 | 1277 | |
| 1278 | 1278 | $connect = ' . |
| 1279 | - _q($connect) . '; |
|
| 1279 | + _q($connect) . '; |
|
| 1280 | 1280 | $page = ' . |
| 1281 | - // ATTENTION, le calcul de l'expression $corps affectera $Cache |
|
| 1282 | - // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
|
| 1283 | - // avant de referencer $Cache |
|
| 1284 | - $corps . "; |
|
| 1281 | + // ATTENTION, le calcul de l'expression $corps affectera $Cache |
|
| 1282 | + // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
|
| 1283 | + // avant de referencer $Cache |
|
| 1284 | + $corps . "; |
|
| 1285 | 1285 | |
| 1286 | 1286 | return analyse_resultat_skel(".var_export($nom,true) |
| 1287 | - .", \$Cache, \$page, ".var_export($sourcefile,true)."); |
|
| 1287 | + .", \$Cache, \$page, ".var_export($sourcefile,true)."); |
|
| 1288 | 1288 | }"; |
| 1289 | 1289 | |
| 1290 | - $secondes = spip_timer('calcul_skel'); |
|
| 1291 | - spip_log("COMPIL ($secondes) [$sourcefile] $nom.php"); |
|
| 1292 | - // $connect n'est pas sûr : on nettoie |
|
| 1293 | - $connect = preg_replace(',[^\w],', '', $connect); |
|
| 1290 | + $secondes = spip_timer('calcul_skel'); |
|
| 1291 | + spip_log("COMPIL ($secondes) [$sourcefile] $nom.php"); |
|
| 1292 | + // $connect n'est pas sûr : on nettoie |
|
| 1293 | + $connect = preg_replace(',[^\w],', '', $connect); |
|
| 1294 | 1294 | |
| 1295 | - // Assimiler la fct principale a une boucle anonyme, pour retourner un resultat simple |
|
| 1296 | - $code = new Boucle; |
|
| 1297 | - $code->descr = $descr; |
|
| 1298 | - $code->return = ' |
|
| 1295 | + // Assimiler la fct principale a une boucle anonyme, pour retourner un resultat simple |
|
| 1296 | + $code = new Boucle; |
|
| 1297 | + $code->descr = $descr; |
|
| 1298 | + $code->return = ' |
|
| 1299 | 1299 | // |
| 1300 | 1300 | // Fonction principale du squelette ' . |
| 1301 | - $sourcefile . |
|
| 1302 | - ($connect ? " pour $connect" : '') . |
|
| 1303 | - (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1304 | - "\n//\n" . |
|
| 1305 | - $principal; |
|
| 1306 | - |
|
| 1307 | - $boucles[''] = $code; |
|
| 1308 | - return $boucles; |
|
| 1301 | + $sourcefile . |
|
| 1302 | + ($connect ? " pour $connect" : '') . |
|
| 1303 | + (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1304 | + "\n//\n" . |
|
| 1305 | + $principal; |
|
| 1306 | + |
|
| 1307 | + $boucles[''] = $code; |
|
| 1308 | + return $boucles; |
|
| 1309 | 1309 | } |
| 1310 | 1310 | |
| 1311 | 1311 | |
@@ -1322,16 +1322,16 @@ discard block |
||
| 1322 | 1322 | * |
| 1323 | 1323 | **/ |
| 1324 | 1324 | function requeteur_php_dist(&$boucles, &$boucle, &$id) { |
| 1325 | - if (class_exists($boucle->type_requete)) { |
|
| 1326 | - $g = charger_fonction('php', 'iterateur'); |
|
| 1327 | - $boucles[$id] = $g($boucle, $boucle->type_requete); |
|
| 1328 | - } else { |
|
| 1329 | - $x = $boucle->type_requete; |
|
| 1330 | - $boucle->type_requete = false; |
|
| 1331 | - $msg = array('zbug_iterateur_inconnu', |
|
| 1332 | - array('iterateur' => $x)); |
|
| 1333 | - erreur_squelette($msg, $boucle); |
|
| 1334 | - } |
|
| 1325 | + if (class_exists($boucle->type_requete)) { |
|
| 1326 | + $g = charger_fonction('php', 'iterateur'); |
|
| 1327 | + $boucles[$id] = $g($boucle, $boucle->type_requete); |
|
| 1328 | + } else { |
|
| 1329 | + $x = $boucle->type_requete; |
|
| 1330 | + $boucle->type_requete = false; |
|
| 1331 | + $msg = array('zbug_iterateur_inconnu', |
|
| 1332 | + array('iterateur' => $x)); |
|
| 1333 | + erreur_squelette($msg, $boucle); |
|
| 1334 | + } |
|
| 1335 | 1335 | } |
| 1336 | 1336 | |
| 1337 | 1337 | |
@@ -1349,23 +1349,23 @@ discard block |
||
| 1349 | 1349 | * |
| 1350 | 1350 | **/ |
| 1351 | 1351 | function requeteur_data_dist(&$boucles, &$boucle, &$id) { |
| 1352 | - include_spip('iterateur/data'); |
|
| 1353 | - if ($h = charger_fonction($boucle->type_requete . '_to_array' , 'inc', true)) { |
|
| 1354 | - $g = charger_fonction('data', 'iterateur'); |
|
| 1355 | - $boucles[$id] = $g($boucle); |
|
| 1356 | - // from[0] stocke le type de data (rss, yql, ...) |
|
| 1357 | - $boucles[$id]->from[] = $boucle->type_requete; |
|
| 1352 | + include_spip('iterateur/data'); |
|
| 1353 | + if ($h = charger_fonction($boucle->type_requete . '_to_array' , 'inc', true)) { |
|
| 1354 | + $g = charger_fonction('data', 'iterateur'); |
|
| 1355 | + $boucles[$id] = $g($boucle); |
|
| 1356 | + // from[0] stocke le type de data (rss, yql, ...) |
|
| 1357 | + $boucles[$id]->from[] = $boucle->type_requete; |
|
| 1358 | 1358 | |
| 1359 | - } else { |
|
| 1360 | - $x = $boucle->type_requete; |
|
| 1361 | - $boucle->type_requete = false; |
|
| 1362 | - $msg = array('zbug_requeteur_inconnu', |
|
| 1363 | - array( |
|
| 1364 | - 'requeteur' => 'data', |
|
| 1365 | - 'type' => $x |
|
| 1366 | - )); |
|
| 1367 | - erreur_squelette($msg, $boucle); |
|
| 1368 | - } |
|
| 1359 | + } else { |
|
| 1360 | + $x = $boucle->type_requete; |
|
| 1361 | + $boucle->type_requete = false; |
|
| 1362 | + $msg = array('zbug_requeteur_inconnu', |
|
| 1363 | + array( |
|
| 1364 | + 'requeteur' => 'data', |
|
| 1365 | + 'type' => $x |
|
| 1366 | + )); |
|
| 1367 | + erreur_squelette($msg, $boucle); |
|
| 1368 | + } |
|
| 1369 | 1369 | } |
| 1370 | 1370 | |
| 1371 | 1371 | ?> |
@@ -799,147 +799,147 @@ |
||
| 799 | 799 | |
| 800 | 800 | switch($p->type) { |
| 801 | 801 | // texte seul |
| 802 | - case 'texte': |
|
| 803 | - $code = sandbox_composer_texte($p->texte, $p); |
|
| 804 | - $commentaire= strlen($p->texte) . " signes"; |
|
| 805 | - $avant=''; |
|
| 806 | - $apres=''; |
|
| 807 | - $altern = "''"; |
|
| 808 | - break; |
|
| 809 | - |
|
| 810 | - case 'polyglotte': |
|
| 811 | - $code = ""; |
|
| 812 | - foreach($p->traductions as $k => $v) { |
|
| 813 | - $code .= ",'" . |
|
| 814 | - str_replace(array("\\","'"),array("\\\\","\\'"), $k) . |
|
| 815 | - "' => '" . |
|
| 816 | - str_replace(array("\\","'"),array("\\\\","\\'"), $v) . |
|
| 817 | - "'"; |
|
| 818 | - } |
|
| 819 | - $code = "choisir_traduction(array(" . |
|
| 820 | - substr($code,1) . |
|
| 821 | - "))"; |
|
| 822 | - $commentaire= '&'; |
|
| 823 | - $avant=''; |
|
| 824 | - $apres=''; |
|
| 825 | - $altern = "''"; |
|
| 826 | - break; |
|
| 827 | - |
|
| 828 | - // inclure |
|
| 829 | - case 'include': |
|
| 830 | - $p->descr = $descr; |
|
| 831 | - $code = calculer_inclure($p, $boucles, $id_boucle); |
|
| 832 | - if ($code === false) { |
|
| 833 | - $err_e_c = true; |
|
| 834 | - $code = "''"; |
|
| 835 | - } else { |
|
| 836 | - $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 837 | - $avant=''; |
|
| 838 | - $apres=''; |
|
| 839 | - $altern = "''"; |
|
| 840 | - } |
|
| 841 | - break; |
|
| 842 | - |
|
| 843 | - // boucle |
|
| 844 | - case TYPE_RECURSIF: |
|
| 845 | - $nom = $p->id_boucle; |
|
| 846 | - $newdescr = $descr; |
|
| 847 | - $newdescr['id_mere'] = $nom; |
|
| 848 | - $newdescr['niv']++; |
|
| 849 | - $avant = calculer_liste($p->avant, |
|
| 850 | - $newdescr, $boucles, $id_boucle); |
|
| 851 | - $apres = calculer_liste($p->apres, |
|
| 852 | - $newdescr, $boucles, $id_boucle); |
|
| 853 | - $newdescr['niv']--; |
|
| 854 | - $altern = calculer_liste($p->altern, |
|
| 855 | - $newdescr, $boucles, $id_boucle); |
|
| 856 | - if (($avant === false) OR ($apres === false) OR ($altern === false)) { |
|
| 857 | - $err_e_c = true; |
|
| 858 | - $code = "''"; |
|
| 859 | - } else { |
|
| 860 | - $code = 'BOUCLE' . |
|
| 861 | - str_replace("-","_", $nom) . $descr['nom'] . |
|
| 862 | - '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
|
| 863 | - $commentaire= "?$nom"; |
|
| 864 | - if (!$boucles[$nom]->milieu |
|
| 865 | - AND $boucles[$nom]->type_requete <> TYPE_RECURSIF) { |
|
| 866 | - if ($altern != "''") $code .= "\n. $altern"; |
|
| 867 | - if ($avant<>"''" OR $apres<>"''") |
|
| 868 | - spip_log("boucle $nom toujours vide, code superflu dans $id"); |
|
| 869 | - $avant = $apres = $altern = "''"; |
|
| 870 | - } else if ($altern != "''") $altern = "($altern)"; |
|
| 871 | - } |
|
| 872 | - break; |
|
| 873 | - |
|
| 874 | - case 'idiome': |
|
| 875 | - $l = array(); |
|
| 876 | - $code = ''; |
|
| 877 | - foreach ($p->arg as $k => $v) { |
|
| 878 | - $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
|
| 879 | - if ($k) { |
|
| 880 | - $l[] = _q($k) . ' => ' . $_v; |
|
| 881 | - } else { |
|
| 882 | - $code = $_v; |
|
| 883 | - } |
|
| 884 | - } |
|
| 885 | - // Si le module n'est pas fourni, l'expliciter sauf si calculé |
|
| 886 | - if ($p->module) { |
|
| 887 | - $m = $p->module .':'.$p->nom_champ; |
|
| 888 | - } elseif ($p->nom_champ) { |
|
| 889 | - $m = MODULES_IDIOMES .':'.$p->nom_champ; |
|
| 890 | - } else { |
|
| 891 | - $m = ''; |
|
| 892 | - } |
|
| 893 | - $code = (!$code ? "'$m'" : |
|
| 894 | - ($m ? "'$m' . $code" : |
|
| 895 | - ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 896 | - . (!$l ? '' : (", array(" . implode(",\n", $l) . ")")); |
|
| 897 | - $code = "_T($code)"; |
|
| 898 | - if ($p->param) { |
|
| 899 | - $p->id_boucle = $id_boucle; |
|
| 900 | - $p->boucles = &$boucles; |
|
| 901 | - $code = compose_filtres($p, $code); |
|
| 902 | - } |
|
| 903 | - $commentaire = ":"; |
|
| 904 | - $avant=''; |
|
| 905 | - $apres=''; |
|
| 906 | - $altern = "''"; |
|
| 907 | - break; |
|
| 908 | - |
|
| 909 | - case 'champ': |
|
| 910 | - |
|
| 911 | - // cette structure pourrait etre completee des le phrase' (a faire) |
|
| 912 | - $p->id_boucle = $id_boucle; |
|
| 913 | - $p->boucles = &$boucles; |
|
| 914 | - $p->descr = $descr; |
|
| 915 | - #$p->interdire_scripts = true; |
|
| 916 | - $p->type_requete = $type; |
|
| 917 | - |
|
| 918 | - $code = calculer_champ($p); |
|
| 919 | - $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 920 | - $avant = calculer_liste($p->avant, |
|
| 921 | - $descr, $boucles, $id_boucle); |
|
| 922 | - $apres = calculer_liste($p->apres, |
|
| 923 | - $descr, $boucles, $id_boucle); |
|
| 924 | - $altern = "''"; |
|
| 925 | - // Si la valeur est destinee a une comparaison a '' |
|
| 926 | - // forcer la conversion en une chaine par strval |
|
| 927 | - // si ca peut etre autre chose qu'une chaine |
|
| 928 | - if (($avant != "''" OR $apres != "''") |
|
| 929 | - AND $code[0]!= "'" |
|
| 930 | -# AND (strpos($code,'interdire_scripts') !== 0) |
|
| 931 | - AND !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
|
| 932 | - AND !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
|
| 933 | - AND !preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) |
|
| 934 | - $code = "strval($code)"; |
|
| 935 | - break; |
|
| 936 | - |
|
| 937 | - default: |
|
| 938 | - // Erreur de construction de l'arbre de syntaxe abstraite |
|
| 939 | - $code = "''"; |
|
| 940 | - $p->descr = $descr; |
|
| 941 | - $err_e_c = _T('zbug_erreur_compilation'); |
|
| 942 | - erreur_squelette($err_e_c, $p); |
|
| 802 | + case 'texte': |
|
| 803 | + $code = sandbox_composer_texte($p->texte, $p); |
|
| 804 | + $commentaire= strlen($p->texte) . " signes"; |
|
| 805 | + $avant=''; |
|
| 806 | + $apres=''; |
|
| 807 | + $altern = "''"; |
|
| 808 | + break; |
|
| 809 | + |
|
| 810 | + case 'polyglotte': |
|
| 811 | + $code = ""; |
|
| 812 | + foreach($p->traductions as $k => $v) { |
|
| 813 | + $code .= ",'" . |
|
| 814 | + str_replace(array("\\","'"),array("\\\\","\\'"), $k) . |
|
| 815 | + "' => '" . |
|
| 816 | + str_replace(array("\\","'"),array("\\\\","\\'"), $v) . |
|
| 817 | + "'"; |
|
| 818 | + } |
|
| 819 | + $code = "choisir_traduction(array(" . |
|
| 820 | + substr($code,1) . |
|
| 821 | + "))"; |
|
| 822 | + $commentaire= '&'; |
|
| 823 | + $avant=''; |
|
| 824 | + $apres=''; |
|
| 825 | + $altern = "''"; |
|
| 826 | + break; |
|
| 827 | + |
|
| 828 | + // inclure |
|
| 829 | + case 'include': |
|
| 830 | + $p->descr = $descr; |
|
| 831 | + $code = calculer_inclure($p, $boucles, $id_boucle); |
|
| 832 | + if ($code === false) { |
|
| 833 | + $err_e_c = true; |
|
| 834 | + $code = "''"; |
|
| 835 | + } else { |
|
| 836 | + $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 837 | + $avant=''; |
|
| 838 | + $apres=''; |
|
| 839 | + $altern = "''"; |
|
| 840 | + } |
|
| 841 | + break; |
|
| 842 | + |
|
| 843 | + // boucle |
|
| 844 | + case TYPE_RECURSIF: |
|
| 845 | + $nom = $p->id_boucle; |
|
| 846 | + $newdescr = $descr; |
|
| 847 | + $newdescr['id_mere'] = $nom; |
|
| 848 | + $newdescr['niv']++; |
|
| 849 | + $avant = calculer_liste($p->avant, |
|
| 850 | + $newdescr, $boucles, $id_boucle); |
|
| 851 | + $apres = calculer_liste($p->apres, |
|
| 852 | + $newdescr, $boucles, $id_boucle); |
|
| 853 | + $newdescr['niv']--; |
|
| 854 | + $altern = calculer_liste($p->altern, |
|
| 855 | + $newdescr, $boucles, $id_boucle); |
|
| 856 | + if (($avant === false) OR ($apres === false) OR ($altern === false)) { |
|
| 857 | + $err_e_c = true; |
|
| 858 | + $code = "''"; |
|
| 859 | + } else { |
|
| 860 | + $code = 'BOUCLE' . |
|
| 861 | + str_replace("-","_", $nom) . $descr['nom'] . |
|
| 862 | + '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
|
| 863 | + $commentaire= "?$nom"; |
|
| 864 | + if (!$boucles[$nom]->milieu |
|
| 865 | + AND $boucles[$nom]->type_requete <> TYPE_RECURSIF) { |
|
| 866 | + if ($altern != "''") $code .= "\n. $altern"; |
|
| 867 | + if ($avant<>"''" OR $apres<>"''") |
|
| 868 | + spip_log("boucle $nom toujours vide, code superflu dans $id"); |
|
| 869 | + $avant = $apres = $altern = "''"; |
|
| 870 | + } else if ($altern != "''") $altern = "($altern)"; |
|
| 871 | + } |
|
| 872 | + break; |
|
| 873 | + |
|
| 874 | + case 'idiome': |
|
| 875 | + $l = array(); |
|
| 876 | + $code = ''; |
|
| 877 | + foreach ($p->arg as $k => $v) { |
|
| 878 | + $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
|
| 879 | + if ($k) { |
|
| 880 | + $l[] = _q($k) . ' => ' . $_v; |
|
| 881 | + } else { |
|
| 882 | + $code = $_v; |
|
| 883 | + } |
|
| 884 | + } |
|
| 885 | + // Si le module n'est pas fourni, l'expliciter sauf si calculé |
|
| 886 | + if ($p->module) { |
|
| 887 | + $m = $p->module .':'.$p->nom_champ; |
|
| 888 | + } elseif ($p->nom_champ) { |
|
| 889 | + $m = MODULES_IDIOMES .':'.$p->nom_champ; |
|
| 890 | + } else { |
|
| 891 | + $m = ''; |
|
| 892 | + } |
|
| 893 | + $code = (!$code ? "'$m'" : |
|
| 894 | + ($m ? "'$m' . $code" : |
|
| 895 | + ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 896 | + . (!$l ? '' : (", array(" . implode(",\n", $l) . ")")); |
|
| 897 | + $code = "_T($code)"; |
|
| 898 | + if ($p->param) { |
|
| 899 | + $p->id_boucle = $id_boucle; |
|
| 900 | + $p->boucles = &$boucles; |
|
| 901 | + $code = compose_filtres($p, $code); |
|
| 902 | + } |
|
| 903 | + $commentaire = ":"; |
|
| 904 | + $avant=''; |
|
| 905 | + $apres=''; |
|
| 906 | + $altern = "''"; |
|
| 907 | + break; |
|
| 908 | + |
|
| 909 | + case 'champ': |
|
| 910 | + |
|
| 911 | + // cette structure pourrait etre completee des le phrase' (a faire) |
|
| 912 | + $p->id_boucle = $id_boucle; |
|
| 913 | + $p->boucles = &$boucles; |
|
| 914 | + $p->descr = $descr; |
|
| 915 | + #$p->interdire_scripts = true; |
|
| 916 | + $p->type_requete = $type; |
|
| 917 | + |
|
| 918 | + $code = calculer_champ($p); |
|
| 919 | + $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 920 | + $avant = calculer_liste($p->avant, |
|
| 921 | + $descr, $boucles, $id_boucle); |
|
| 922 | + $apres = calculer_liste($p->apres, |
|
| 923 | + $descr, $boucles, $id_boucle); |
|
| 924 | + $altern = "''"; |
|
| 925 | + // Si la valeur est destinee a une comparaison a '' |
|
| 926 | + // forcer la conversion en une chaine par strval |
|
| 927 | + // si ca peut etre autre chose qu'une chaine |
|
| 928 | + if (($avant != "''" OR $apres != "''") |
|
| 929 | + AND $code[0]!= "'" |
|
| 930 | + # AND (strpos($code,'interdire_scripts') !== 0) |
|
| 931 | + AND !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
|
| 932 | + AND !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
|
| 933 | + AND !preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) |
|
| 934 | + $code = "strval($code)"; |
|
| 935 | + break; |
|
| 936 | + |
|
| 937 | + default: |
|
| 938 | + // Erreur de construction de l'arbre de syntaxe abstraite |
|
| 939 | + $code = "''"; |
|
| 940 | + $p->descr = $descr; |
|
| 941 | + $err_e_c = _T('zbug_erreur_compilation'); |
|
| 942 | + erreur_squelette($err_e_c, $p); |
|
| 943 | 943 | } // switch |
| 944 | 944 | |
| 945 | 945 | if ($code != "''") { |
@@ -57,15 +57,15 @@ discard block |
||
| 57 | 57 | |
| 58 | 58 | |
| 59 | 59 | // http://doc.spip.org/@argumenter_inclure |
| 60 | -function argumenter_inclure($params, $rejet_filtres, $p, &$boucles, $id_boucle, $echap=true, $lang = '', $fond1=false){ |
|
| 60 | +function argumenter_inclure($params, $rejet_filtres, $p, &$boucles, $id_boucle, $echap = true, $lang = '', $fond1 = false) { |
|
| 61 | 61 | $l = array(); |
| 62 | 62 | $erreur_p_i_i = ''; |
| 63 | 63 | if (!is_array($params)) return $l; |
| 64 | - foreach($params as $k => $couple) { |
|
| 64 | + foreach ($params as $k => $couple) { |
|
| 65 | 65 | // la liste d'arguments d'inclusion peut se terminer par un filtre |
| 66 | 66 | $filtre = array_shift($couple); |
| 67 | 67 | if ($filtre) break; |
| 68 | - foreach($couple as $n => $val) { |
|
| 68 | + foreach ($couple as $n => $val) { |
|
| 69 | 69 | $var = $val[0]; |
| 70 | 70 | if ($var->type != 'texte') { |
| 71 | 71 | if ($n OR $k OR $fond1) { |
@@ -76,9 +76,9 @@ discard block |
||
| 76 | 76 | } |
| 77 | 77 | else $l[1] = calculer_liste($val, $p->descr, $boucles, $id_boucle); |
| 78 | 78 | } else { |
| 79 | - preg_match(",^([^=]*)(=?)(.*)$,m", $var->texte,$m); |
|
| 79 | + preg_match(",^([^=]*)(=?)(.*)$,m", $var->texte, $m); |
|
| 80 | 80 | $var = $m[1]; |
| 81 | - $auto = false;; |
|
| 81 | + $auto = false; ; |
|
| 82 | 82 | if ($m[2]) { |
| 83 | 83 | $v = $m[3]; |
| 84 | 84 | if (preg_match(',^[\'"](.*)[\'"]$,', $v, $m)) $v = $m[1]; |
@@ -97,8 +97,8 @@ discard block |
||
| 97 | 97 | ? index_pile($id_boucle, $var, $boucles) |
| 98 | 98 | : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
| 99 | 99 | if ($var !== 1) |
| 100 | - $val = ($echap?"\'$var\' => ' . argumenter_squelette(":"'$var' => ") |
|
| 101 | - . $val . ($echap? ") . '":" "); |
|
| 100 | + $val = ($echap ? "\'$var\' => ' . argumenter_squelette(" : "'$var' => ") |
|
| 101 | + . $val.($echap ? ") . '" : " "); |
|
| 102 | 102 | else $val = $echap ? "'.$val.'" : $val; |
| 103 | 103 | $l[$var] = $val; |
| 104 | 104 | } |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | // sauf si on n'en veut pas |
| 112 | 112 | if ($lang === false) return $l; |
| 113 | 113 | if (!$lang) $lang = '$GLOBALS["spip_lang"]'; |
| 114 | - $l['lang'] = ($echap?"\'lang\' => ' . argumenter_squelette(":"'lang' => ") . $lang . ($echap?") . '":" "); |
|
| 114 | + $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ").$lang.($echap ? ") . '" : " "); |
|
| 115 | 115 | |
| 116 | 116 | return $l; |
| 117 | 117 | } |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); |
| 141 | 141 | if (is_string($p->texte)) { |
| 142 | 142 | $fichier = $p->texte; |
| 143 | - $code = "\"".str_replace('"','\"',$fichier)."\""; |
|
| 143 | + $code = "\"".str_replace('"', '\"', $fichier)."\""; |
|
| 144 | 144 | |
| 145 | 145 | } else { |
| 146 | 146 | $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | |
| 159 | 159 | if (is_array($_contexte)) { |
| 160 | 160 | // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
| 161 | - if ($env = (isset($_contexte['env'])|| isset($_contexte['self']))) { |
|
| 161 | + if ($env = (isset($_contexte['env']) || isset($_contexte['self']))) { |
|
| 162 | 162 | unset($_contexte['env']); |
| 163 | 163 | } |
| 164 | 164 | |
@@ -167,8 +167,8 @@ discard block |
||
| 167 | 167 | $_contexte['doublons'] = "\\'doublons\\' => '.var_export(\$doublons,true).'"; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - if ($ajax = isset($_contexte['ajax'])){ |
|
| 171 | - $ajax = preg_replace(",=>(.*)$,ims",'=> ($v=(\\1))?$v:true',$_contexte['ajax']); |
|
| 170 | + if ($ajax = isset($_contexte['ajax'])) { |
|
| 171 | + $ajax = preg_replace(",=>(.*)$,ims", '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 172 | 172 | unset($_contexte['ajax']); |
| 173 | 173 | } |
| 174 | 174 | |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | else |
| 178 | 178 | return false; // j'aurais voulu toucher le fond ... |
| 179 | 179 | |
| 180 | - $contexte = 'array(' . $_contexte .')'; |
|
| 180 | + $contexte = 'array('.$_contexte.')'; |
|
| 181 | 181 | |
| 182 | 182 | if ($env) { |
| 183 | 183 | $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
@@ -186,15 +186,15 @@ discard block |
||
| 186 | 186 | // s'il y a une extension .php, ce n'est pas un squelette |
| 187 | 187 | if ($fichier and preg_match('/^.+[.]php$/s', $fichier)) { |
| 188 | 188 | $code = sandbox_composer_inclure_php($fichier, $p, $contexte); |
| 189 | - } else { |
|
| 189 | + } else { |
|
| 190 | 190 | $_options[] = "\"compil\"=>array($compil)"; |
| 191 | 191 | if ($ajax) |
| 192 | 192 | $_options[] = $ajax; |
| 193 | 193 | $code = " ' . argumenter_squelette($code) . '"; |
| 194 | - $code = "echo " . sprintf(CODE_RECUPERER_FOND, $code, $contexte, implode(',',$_options), "_request(\"connect\")") . ';'; |
|
| 194 | + $code = "echo ".sprintf(CODE_RECUPERER_FOND, $code, $contexte, implode(',', $_options), "_request(\"connect\")").';'; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - return "\n'<'.'". "?php ". $code . "\n?'." . "'>'"; |
|
| 197 | + return "\n'<'.'"."?php ".$code."\n?'."."'>'"; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | * @param bool $ignore_previsu |
| 212 | 212 | * true pour ne tester que le cas publie et ignorer l'eventuel var_mode=preview de la page |
| 213 | 213 | */ |
| 214 | -function instituer_boucle(&$boucle, $echapper=true, $ignore_previsu=false){ |
|
| 214 | +function instituer_boucle(&$boucle, $echapper = true, $ignore_previsu = false) { |
|
| 215 | 215 | /* |
| 216 | 216 | $show['statut'][] = array( |
| 217 | 217 | 'champ'=>'statut', // champ de la table sur lequel porte le filtrage par le statut |
@@ -238,12 +238,12 @@ discard block |
||
| 238 | 238 | */ |
| 239 | 239 | $id_table = $boucle->id_table; |
| 240 | 240 | $show = $boucle->show; |
| 241 | - if (isset($show['statut']) AND $show['statut']){ |
|
| 242 | - foreach($show['statut'] as $k=>$s){ |
|
| 241 | + if (isset($show['statut']) AND $show['statut']) { |
|
| 242 | + foreach ($show['statut'] as $k=>$s) { |
|
| 243 | 243 | // Restreindre aux elements publies si pas de {statut} ou autre dans les criteres |
| 244 | 244 | $filtrer = true; |
| 245 | 245 | if (isset($s['exception'])) { |
| 246 | - foreach(is_array($s['exception'])?$s['exception']:array($s['exception']) as $m) { |
|
| 246 | + foreach (is_array($s['exception']) ? $s['exception'] : array($s['exception']) as $m) { |
|
| 247 | 247 | if (isset($boucle->modificateur[$m]) OR isset($boucle->modificateur['criteres'][$m])) { |
| 248 | 248 | $filtrer = false; |
| 249 | 249 | break; |
@@ -252,19 +252,19 @@ discard block |
||
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | if ($filtrer) { |
| 255 | - if (is_array($s['champ'])){ |
|
| 256 | - $statut = preg_replace(',\W,','',array_pop($s['champ'])); // securite |
|
| 255 | + if (is_array($s['champ'])) { |
|
| 256 | + $statut = preg_replace(',\W,', '', array_pop($s['champ'])); // securite |
|
| 257 | 257 | $jointures = array(); |
| 258 | 258 | // indiquer la description de chaque table dans le tableau de jointures, |
| 259 | 259 | // ce qui permet d'eviter certains GROUP BY inutiles. |
| 260 | 260 | $trouver_table = charger_fonction('trouver_table', 'base'); |
| 261 | - foreach($s['champ'] as $j) { |
|
| 261 | + foreach ($s['champ'] as $j) { |
|
| 262 | 262 | $id = reset($j); |
| 263 | 263 | $def = $trouver_table($id); |
| 264 | - $jointures[] = array('',array($id,$def),end($j)); |
|
| 264 | + $jointures[] = array('', array($id, $def), end($j)); |
|
| 265 | 265 | } |
| 266 | 266 | $jointures[0][0] = $id_table; |
| 267 | - if (!array_search($id, $boucle->from)){ |
|
| 267 | + if (!array_search($id, $boucle->from)) { |
|
| 268 | 268 | include_spip('public/jointures'); |
| 269 | 269 | fabrique_jointures($boucle, $jointures, true, $boucle->show, $id_table, '', $echapper); |
| 270 | 270 | } |
@@ -273,20 +273,20 @@ discard block |
||
| 273 | 273 | } |
| 274 | 274 | else { |
| 275 | 275 | $id = $id_table; |
| 276 | - $statut = preg_replace(',\W,','',$s['champ']); // securite |
|
| 276 | + $statut = preg_replace(',\W,', '', $s['champ']); // securite |
|
| 277 | 277 | } |
| 278 | - $mstatut = $id .'.'.$statut; |
|
| 278 | + $mstatut = $id.'.'.$statut; |
|
| 279 | 279 | |
| 280 | - $arg_ignore_previsu=($ignore_previsu?",true":''); |
|
| 280 | + $arg_ignore_previsu = ($ignore_previsu ? ",true" : ''); |
|
| 281 | 281 | include_spip('public/quete'); |
| 282 | 282 | if (isset($s['post_date']) AND $s['post_date'] |
| 283 | - AND $GLOBALS['meta']["post_dates"] == 'non'){ |
|
| 284 | - $date = $id.'.'.preg_replace(',\W,','',$s['post_date']); // securite |
|
| 283 | + AND $GLOBALS['meta']["post_dates"] == 'non') { |
|
| 284 | + $date = $id.'.'.preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 285 | 285 | array_unshift($boucle->where, |
| 286 | 286 | $echapper ? |
| 287 | 287 | "\nquete_condition_postdates('$date',"._q($boucle->sql_serveur)."$arg_ignore_previsu)" |
| 288 | 288 | : |
| 289 | - quete_condition_postdates($date,$boucle->sql_serveur,$ignore_previsu) |
|
| 289 | + quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
|
| 290 | 290 | ); |
| 291 | 291 | } |
| 292 | 292 | array_unshift($boucle->where, |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | ._q($s['publie'])."," |
| 297 | 297 | ._q($boucle->sql_serveur)."$arg_ignore_previsu)" |
| 298 | 298 | : |
| 299 | - quete_condition_statut($mstatut,$s['previsu'],$s['publie'],$boucle->sql_serveur,$ignore_previsu) |
|
| 299 | + quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
|
| 300 | 300 | ); |
| 301 | 301 | } |
| 302 | 302 | } |
@@ -325,10 +325,10 @@ discard block |
||
| 325 | 325 | |
| 326 | 326 | // en mode debug memoriser les premiers passages dans la boucle, |
| 327 | 327 | // mais pas tous, sinon ca pete. |
| 328 | - if (_request('var_mode_affiche') != 'resultat') |
|
| 328 | + if (_request('var_mode_affiche') != 'resultat') |
|
| 329 | 329 | $trace = ''; |
| 330 | 330 | else { |
| 331 | - $trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 331 | + $trace = $boucles[$id_boucle]->descr['nom'].$id_boucle; |
|
| 332 | 332 | $trace = "if (count(@\$GLOBALS['debug_objets']['resultat']['$trace'])<3) |
| 333 | 333 | \$GLOBALS['debug_objets']['resultat']['$trace'][] = \$t0;"; |
| 334 | 334 | } |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | return |
| 362 | 362 | // Numrows[$nom] peut ne pas être encore defini |
| 363 | 363 | "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
| 364 | - . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ";" |
|
| 364 | + . "\n\t\$t0 = ".$boucles[$id_boucle]->return.";" |
|
| 365 | 365 | . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
| 366 | 366 | . $trace |
| 367 | 367 | . "\n\treturn \$t0;"; |
@@ -421,14 +421,14 @@ discard block |
||
| 421 | 421 | $return = $boucle->return; |
| 422 | 422 | $type_boucle = $boucle->type_requete; |
| 423 | 423 | $primary = $boucle->primary; |
| 424 | - $constant = preg_match(CODE_MONOTONE, str_replace("\\'",'', $return)); |
|
| 425 | - $flag_cpt = $boucle->mode_partie ||$boucle->cptrows; |
|
| 424 | + $constant = preg_match(CODE_MONOTONE, str_replace("\\'", '', $return)); |
|
| 425 | + $flag_cpt = $boucle->mode_partie || $boucle->cptrows; |
|
| 426 | 426 | $corps = ''; |
| 427 | 427 | |
| 428 | 428 | // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
| 429 | 429 | // et puis faire un [] plutot qu'un "','." |
| 430 | 430 | if ($boucle->doublons) |
| 431 | - $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 431 | + $corps .= "\n\t\t\tforeach(".$boucle->doublons.' as $k) $doublons[$k] .= "," . '. |
|
| 432 | 432 | index_pile($id_boucle, $primary, $boucles) |
| 433 | 433 | . "; // doublons\n"; |
| 434 | 434 | |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | // (sauf si forcer_lang==true ou si le titre contient <multi>). |
| 438 | 438 | // - a moins d'une demande explicite via {!lang_select} |
| 439 | 439 | if (!$constant && $boucle->lang_select != 'non' && |
| 440 | - (($boucle->lang_select == 'oui') || |
|
| 440 | + (($boucle->lang_select == 'oui') || |
|
| 441 | 441 | in_array($type_boucle, array( |
| 442 | 442 | 'articles', 'rubriques', 'hierarchie', 'breves' |
| 443 | 443 | ))) |
@@ -465,7 +465,7 @@ discard block |
||
| 465 | 465 | if (strpos($return, '?php') === false |
| 466 | 466 | AND preg_match_all("/\W(_T[(]'[^']*'[)])/", $return, $r)) { |
| 467 | 467 | $i = 1; |
| 468 | - foreach($r[1] as $t) { |
|
| 468 | + foreach ($r[1] as $t) { |
|
| 469 | 469 | $init_lang .= "\n\t\$l$i = $t;"; |
| 470 | 470 | $return = str_replace($t, "\$l$i", $return); |
| 471 | 471 | $i++; |
@@ -475,19 +475,15 @@ discard block |
||
| 475 | 475 | |
| 476 | 476 | // gestion optimale des separateurs et des boucles constantes |
| 477 | 477 | if (count($boucle->separateur)) |
| 478 | - $code_sep = ("'" . str_replace("'","\'",join('',$boucle->separateur)) . "'"); |
|
| 478 | + $code_sep = ("'".str_replace("'", "\'", join('', $boucle->separateur))."'"); |
|
| 479 | 479 | |
| 480 | 480 | $corps .= |
| 481 | 481 | ((!$boucle->separateur) ? |
| 482 | - (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 483 | - (($return==="''") ? '' : |
|
| 484 | - ("\n\t\t" . '$t0 .= ' . $return . ";"))) : |
|
| 485 | - ("\n\t\t\$t1 " . |
|
| 482 | + (($constant && !$corps && !$flag_cpt) ? $return : (($return === "''") ? '' : ("\n\t\t".'$t0 .= '.$return.";"))) : ("\n\t\t\$t1 ". |
|
| 486 | 483 | ((strpos($return, '$t1.') === 0) ? |
| 487 | - (".=" . substr($return,4)) : |
|
| 488 | - ('= ' . $return)) . |
|
| 489 | - ";\n\t\t" . |
|
| 490 | - '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 484 | + (".=".substr($return, 4)) : ('= '.$return)). |
|
| 485 | + ";\n\t\t". |
|
| 486 | + '$t0 .= ((strlen($t1) && strlen($t0)) ? '.$code_sep." : '') . \$t1;")); |
|
| 491 | 487 | |
| 492 | 488 | // Calculer les invalideurs si c'est une boucle non constante et si on |
| 493 | 489 | // souhaite invalider ces elements |
@@ -510,7 +506,7 @@ discard block |
||
| 510 | 506 | |
| 511 | 507 | // si le corps est une constante, ne pas appeler le serveur N fois! |
| 512 | 508 | |
| 513 | - if (preg_match(CODE_MONOTONE,str_replace("\\'",'',$corps), $r)) { |
|
| 509 | + if (preg_match(CODE_MONOTONE, str_replace("\\'", '', $corps), $r)) { |
|
| 514 | 510 | if (!isset($r[2]) OR (!$r[2])) { |
| 515 | 511 | if (!$boucle->numrows) |
| 516 | 512 | return "\n\t\$t0 = '';"; |
@@ -527,7 +523,7 @@ discard block |
||
| 527 | 523 | if (!$boucle->numrows OR $boucle->limit OR $boucle->mode_partie OR $boucle->group) |
| 528 | 524 | $count = '1'; |
| 529 | 525 | else $count = 'count(*)'; |
| 530 | - $boucles[$id_boucle]->select[]= $count; |
|
| 526 | + $boucles[$id_boucle]->select[] = $count; |
|
| 531 | 527 | } |
| 532 | 528 | |
| 533 | 529 | if ($flag_cpt) |
@@ -560,7 +556,7 @@ discard block |
||
| 560 | 556 | $corps, |
| 561 | 557 | $fin_lang, |
| 562 | 558 | $trace, |
| 563 | - 'BOUCLE'.$id_boucle .' @ '.($boucle->descr['sourcefile']) |
|
| 559 | + 'BOUCLE'.$id_boucle.' @ '.($boucle->descr['sourcefile']) |
|
| 564 | 560 | ); |
| 565 | 561 | |
| 566 | 562 | # var_dump($a);exit; |
@@ -582,14 +578,14 @@ discard block |
||
| 582 | 578 | function calculer_requete_sql($boucle) |
| 583 | 579 | { |
| 584 | 580 | $init = array(); |
| 585 | - $init[] = calculer_dec('table', "'" . $boucle->id_table ."'"); |
|
| 586 | - $init[] = calculer_dec('id', "'" . $boucle->id_boucle ."'"); |
|
| 581 | + $init[] = calculer_dec('table', "'".$boucle->id_table."'"); |
|
| 582 | + $init[] = calculer_dec('id', "'".$boucle->id_boucle."'"); |
|
| 587 | 583 | # En absence de champ c'est un decompte : |
| 588 | - $init[] = calculer_dec('from', calculer_from($boucle)); |
|
| 584 | + $init[] = calculer_dec('from', calculer_from($boucle)); |
|
| 589 | 585 | $init[] = calculer_dec('type', calculer_from_type($boucle)); |
| 590 | - $init[] = calculer_dec('groupby', 'array(' . (($g=join("\",\n\t\t\"",$boucle->group))?'"'.$g.'"':'') . ")"); |
|
| 591 | - $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select). "\")"); |
|
| 592 | - $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ")"); |
|
| 586 | + $init[] = calculer_dec('groupby', 'array('.(($g = join("\",\n\t\t\"", $boucle->group)) ? '"'.$g.'"' : '').")"); |
|
| 587 | + $init[] = calculer_dec('select', 'array("'.join("\",\n\t\t\"", $boucle->select)."\")"); |
|
| 588 | + $init[] = calculer_dec('orderby', 'array('.calculer_order($boucle).")"); |
|
| 593 | 589 | $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
| 594 | 590 | $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
| 595 | 591 | $init[] = calculer_dec('limit', |
@@ -599,7 +595,7 @@ discard block |
||
| 599 | 595 | $boucle->limit)); |
| 600 | 596 | $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
| 601 | 597 | $s = $d = ""; |
| 602 | - foreach ($init as $i){ |
|
| 598 | + foreach ($init as $i) { |
|
| 603 | 599 | if (reset($i)) |
| 604 | 600 | $s .= "\n\t\t".end($i); |
| 605 | 601 | else |
@@ -683,22 +679,22 @@ discard block |
||
| 683 | 679 | ) |
| 684 | 680 | $static = ""; |
| 685 | 681 | |
| 686 | - return array($static,'$command[\''.$nom.'\'] = ' . $val . ';'); |
|
| 682 | + return array($static, '$command[\''.$nom.'\'] = '.$val.';'); |
|
| 687 | 683 | } |
| 688 | 684 | |
| 689 | 685 | // http://doc.spip.org/@calculer_dump_array |
| 690 | 686 | function calculer_dump_array($a) |
| 691 | 687 | { |
| 692 | - if (!is_array($a)) return $a ; |
|
| 688 | + if (!is_array($a)) return $a; |
|
| 693 | 689 | $res = ""; |
| 694 | 690 | if ($a AND $a[0] == "'?'") |
| 695 | - return ("(" . calculer_dump_array($a[1]) . |
|
| 696 | - " ? " . calculer_dump_array($a[2]) . |
|
| 697 | - " : " . calculer_dump_array($a[3]) . |
|
| 691 | + return ("(".calculer_dump_array($a[1]). |
|
| 692 | + " ? ".calculer_dump_array($a[2]). |
|
| 693 | + " : ".calculer_dump_array($a[3]). |
|
| 698 | 694 | ")"); |
| 699 | 695 | else { |
| 700 | - foreach($a as $v) $res .= ", " . calculer_dump_array($v); |
|
| 701 | - return "\n\t\t\tarray(" . substr($res,2) . ')'; |
|
| 696 | + foreach ($a as $v) $res .= ", ".calculer_dump_array($v); |
|
| 697 | + return "\n\t\t\tarray(".substr($res, 2).')'; |
|
| 702 | 698 | } |
| 703 | 699 | } |
| 704 | 700 | |
@@ -706,25 +702,25 @@ discard block |
||
| 706 | 702 | function calculer_dump_join($a) |
| 707 | 703 | { |
| 708 | 704 | $res = ""; |
| 709 | - foreach($a as $k => $v) |
|
| 710 | - $res .= ", '$k' => array(".implode(',',$v).")"; |
|
| 711 | - return 'array(' . substr($res,2) . ')'; |
|
| 705 | + foreach ($a as $k => $v) |
|
| 706 | + $res .= ", '$k' => array(".implode(',', $v).")"; |
|
| 707 | + return 'array('.substr($res, 2).')'; |
|
| 712 | 708 | } |
| 713 | 709 | |
| 714 | 710 | // http://doc.spip.org/@calculer_from |
| 715 | 711 | function calculer_from(&$boucle) |
| 716 | 712 | { |
| 717 | 713 | $res = ""; |
| 718 | - foreach($boucle->from as $k => $v) $res .= ",'$k' => '$v'"; |
|
| 719 | - return 'array(' . substr($res,1) . ')'; |
|
| 714 | + foreach ($boucle->from as $k => $v) $res .= ",'$k' => '$v'"; |
|
| 715 | + return 'array('.substr($res, 1).')'; |
|
| 720 | 716 | } |
| 721 | 717 | |
| 722 | 718 | // http://doc.spip.org/@calculer_from_type |
| 723 | 719 | function calculer_from_type(&$boucle) |
| 724 | 720 | { |
| 725 | 721 | $res = ""; |
| 726 | - foreach($boucle->from_type as $k => $v) $res .= ",'$k' => '$v'"; |
|
| 727 | - return 'array(' . substr($res,1) . ')'; |
|
| 722 | + foreach ($boucle->from_type as $k => $v) $res .= ",'$k' => '$v'"; |
|
| 723 | + return 'array('.substr($res, 1).')'; |
|
| 728 | 724 | } |
| 729 | 725 | |
| 730 | 726 | // http://doc.spip.org/@calculer_order |
@@ -749,7 +745,7 @@ discard block |
||
| 749 | 745 | // (qui sera argument d'un Return ou la partie droite d'une affectation). |
| 750 | 746 | |
| 751 | 747 | // http://doc.spip.org/@calculer_liste |
| 752 | -function calculer_liste($tableau, $descr, &$boucles, $id_boucle='') { |
|
| 748 | +function calculer_liste($tableau, $descr, &$boucles, $id_boucle = '') { |
|
| 753 | 749 | if (!$tableau) return "''"; |
| 754 | 750 | if (!isset($descr['niv'])) $descr['niv'] = 0; |
| 755 | 751 | $codes = compile_cas($tableau, $descr, $boucles, $id_boucle); |
@@ -758,28 +754,28 @@ discard block |
||
| 758 | 754 | if (!$n) return "''"; |
| 759 | 755 | $tab = str_repeat("\t", $descr['niv']); |
| 760 | 756 | if (_request('var_mode_affiche') != 'validation') { |
| 761 | - if ($n==1) |
|
| 757 | + if ($n == 1) |
|
| 762 | 758 | return $codes[0]; |
| 763 | 759 | else { |
| 764 | 760 | $res = ''; |
| 765 | - foreach($codes as $code) { |
|
| 761 | + foreach ($codes as $code) { |
|
| 766 | 762 | if (!preg_match("/^'[^']*'$/", $code) |
| 767 | - OR substr($res,-1,1)!=="'") |
|
| 768 | - $res .= " .\n$tab$code"; |
|
| 763 | + OR substr($res, -1, 1) !== "'") |
|
| 764 | + $res .= " .\n$tab$code"; |
|
| 769 | 765 | else { |
| 770 | - $res = substr($res,0,-1) . substr($code,1); |
|
| 766 | + $res = substr($res, 0, -1).substr($code, 1); |
|
| 771 | 767 | } |
| 772 | 768 | } |
| 773 | - return '(' . substr($res,2+$descr['niv']) . ')'; |
|
| 769 | + return '('.substr($res, 2 + $descr['niv']).')'; |
|
| 774 | 770 | } |
| 775 | 771 | } else { |
| 776 | - $nom = $descr['nom'] . $id_boucle . ($descr['niv']?$descr['niv']:''); |
|
| 777 | - return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join(" ,\n$tab", $codes) . ")))"; |
|
| 772 | + $nom = $descr['nom'].$id_boucle.($descr['niv'] ? $descr['niv'] : ''); |
|
| 773 | + return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(".join(" ,\n$tab", $codes).")))"; |
|
| 778 | 774 | } |
| 779 | 775 | } |
| 780 | 776 | |
| 781 | -define('_REGEXP_COND_VIDE_NONVIDE',"/^[(](.*)[?]\s*''\s*:\s*('[^']+')\s*[)]$/"); |
|
| 782 | -define('_REGEXP_COND_NONVIDE_VIDE',"/^[(](.*)[?]\s*('[^']+')\s*:\s*''\s*[)]$/"); |
|
| 777 | +define('_REGEXP_COND_VIDE_NONVIDE', "/^[(](.*)[?]\s*''\s*:\s*('[^']+')\s*[)]$/"); |
|
| 778 | +define('_REGEXP_COND_NONVIDE_VIDE', "/^[(](.*)[?]\s*('[^']+')\s*:\s*''\s*[)]$/"); |
|
| 783 | 779 | define('_REGEXP_CONCAT_NON_VIDE', "/^(.*)[.]\s*'[^']+'\s*$/"); |
| 784 | 780 | |
| 785 | 781 | // http://doc.spip.org/@compile_cas |
@@ -797,31 +793,31 @@ discard block |
||
| 797 | 793 | // par un caractere distinguant le cas, pour exploitation par debug. |
| 798 | 794 | foreach ($tableau as $p) { |
| 799 | 795 | |
| 800 | - switch($p->type) { |
|
| 796 | + switch ($p->type) { |
|
| 801 | 797 | // texte seul |
| 802 | 798 | case 'texte': |
| 803 | 799 | $code = sandbox_composer_texte($p->texte, $p); |
| 804 | - $commentaire= strlen($p->texte) . " signes"; |
|
| 805 | - $avant=''; |
|
| 806 | - $apres=''; |
|
| 800 | + $commentaire = strlen($p->texte)." signes"; |
|
| 801 | + $avant = ''; |
|
| 802 | + $apres = ''; |
|
| 807 | 803 | $altern = "''"; |
| 808 | 804 | break; |
| 809 | 805 | |
| 810 | 806 | case 'polyglotte': |
| 811 | 807 | $code = ""; |
| 812 | - foreach($p->traductions as $k => $v) { |
|
| 813 | - $code .= ",'" . |
|
| 814 | - str_replace(array("\\","'"),array("\\\\","\\'"), $k) . |
|
| 815 | - "' => '" . |
|
| 816 | - str_replace(array("\\","'"),array("\\\\","\\'"), $v) . |
|
| 808 | + foreach ($p->traductions as $k => $v) { |
|
| 809 | + $code .= ",'". |
|
| 810 | + str_replace(array("\\", "'"), array("\\\\", "\\'"), $k). |
|
| 811 | + "' => '". |
|
| 812 | + str_replace(array("\\", "'"), array("\\\\", "\\'"), $v). |
|
| 817 | 813 | "'"; |
| 818 | 814 | } |
| 819 | - $code = "choisir_traduction(array(" . |
|
| 820 | - substr($code,1) . |
|
| 815 | + $code = "choisir_traduction(array(". |
|
| 816 | + substr($code, 1). |
|
| 821 | 817 | "))"; |
| 822 | - $commentaire= '&'; |
|
| 823 | - $avant=''; |
|
| 824 | - $apres=''; |
|
| 818 | + $commentaire = '&'; |
|
| 819 | + $avant = ''; |
|
| 820 | + $apres = ''; |
|
| 825 | 821 | $altern = "''"; |
| 826 | 822 | break; |
| 827 | 823 | |
@@ -833,9 +829,9 @@ discard block |
||
| 833 | 829 | $err_e_c = true; |
| 834 | 830 | $code = "''"; |
| 835 | 831 | } else { |
| 836 | - $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 837 | - $avant=''; |
|
| 838 | - $apres=''; |
|
| 832 | + $commentaire = '<INCLURE '.addslashes(str_replace("\n", ' ', $code)).'>'; |
|
| 833 | + $avant = ''; |
|
| 834 | + $apres = ''; |
|
| 839 | 835 | $altern = "''"; |
| 840 | 836 | } |
| 841 | 837 | break; |
@@ -857,14 +853,14 @@ discard block |
||
| 857 | 853 | $err_e_c = true; |
| 858 | 854 | $code = "''"; |
| 859 | 855 | } else { |
| 860 | - $code = 'BOUCLE' . |
|
| 861 | - str_replace("-","_", $nom) . $descr['nom'] . |
|
| 856 | + $code = 'BOUCLE'. |
|
| 857 | + str_replace("-", "_", $nom).$descr['nom']. |
|
| 862 | 858 | '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
| 863 | - $commentaire= "?$nom"; |
|
| 859 | + $commentaire = "?$nom"; |
|
| 864 | 860 | if (!$boucles[$nom]->milieu |
| 865 | 861 | AND $boucles[$nom]->type_requete <> TYPE_RECURSIF) { |
| 866 | 862 | if ($altern != "''") $code .= "\n. $altern"; |
| 867 | - if ($avant<>"''" OR $apres<>"''") |
|
| 863 | + if ($avant <> "''" OR $apres <> "''") |
|
| 868 | 864 | spip_log("boucle $nom toujours vide, code superflu dans $id"); |
| 869 | 865 | $avant = $apres = $altern = "''"; |
| 870 | 866 | } else if ($altern != "''") $altern = "($altern)"; |
@@ -877,23 +873,21 @@ discard block |
||
| 877 | 873 | foreach ($p->arg as $k => $v) { |
| 878 | 874 | $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
| 879 | 875 | if ($k) { |
| 880 | - $l[] = _q($k) . ' => ' . $_v; |
|
| 876 | + $l[] = _q($k).' => '.$_v; |
|
| 881 | 877 | } else { |
| 882 | 878 | $code = $_v; |
| 883 | 879 | } |
| 884 | 880 | } |
| 885 | 881 | // Si le module n'est pas fourni, l'expliciter sauf si calculé |
| 886 | 882 | if ($p->module) { |
| 887 | - $m = $p->module .':'.$p->nom_champ; |
|
| 883 | + $m = $p->module.':'.$p->nom_champ; |
|
| 888 | 884 | } elseif ($p->nom_champ) { |
| 889 | - $m = MODULES_IDIOMES .':'.$p->nom_champ; |
|
| 885 | + $m = MODULES_IDIOMES.':'.$p->nom_champ; |
|
| 890 | 886 | } else { |
| 891 | 887 | $m = ''; |
| 892 | 888 | } |
| 893 | - $code = (!$code ? "'$m'" : |
|
| 894 | - ($m ? "'$m' . $code" : |
|
| 895 | - ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 896 | - . (!$l ? '' : (", array(" . implode(",\n", $l) . ")")); |
|
| 889 | + $code = (!$code ? "'$m'" : ($m ? "'$m' . $code" : ("(strpos(\$x=$code, ':') ? \$x : ('".MODULES_IDIOMES.":' . \$x))"))) |
|
| 890 | + . (!$l ? '' : (", array(".implode(",\n", $l).")")); |
|
| 897 | 891 | $code = "_T($code)"; |
| 898 | 892 | if ($p->param) { |
| 899 | 893 | $p->id_boucle = $id_boucle; |
@@ -901,8 +895,8 @@ discard block |
||
| 901 | 895 | $code = compose_filtres($p, $code); |
| 902 | 896 | } |
| 903 | 897 | $commentaire = ":"; |
| 904 | - $avant=''; |
|
| 905 | - $apres=''; |
|
| 898 | + $avant = ''; |
|
| 899 | + $apres = ''; |
|
| 906 | 900 | $altern = "''"; |
| 907 | 901 | break; |
| 908 | 902 | |
@@ -916,7 +910,7 @@ discard block |
||
| 916 | 910 | $p->type_requete = $type; |
| 917 | 911 | |
| 918 | 912 | $code = calculer_champ($p); |
| 919 | - $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 913 | + $commentaire = '#'.$p->nom_champ.$p->etoile; |
|
| 920 | 914 | $avant = calculer_liste($p->avant, |
| 921 | 915 | $descr, $boucles, $id_boucle); |
| 922 | 916 | $apres = calculer_liste($p->apres, |
@@ -926,7 +920,7 @@ discard block |
||
| 926 | 920 | // forcer la conversion en une chaine par strval |
| 927 | 921 | // si ca peut etre autre chose qu'une chaine |
| 928 | 922 | if (($avant != "''" OR $apres != "''") |
| 929 | - AND $code[0]!= "'" |
|
| 923 | + AND $code[0] != "'" |
|
| 930 | 924 | # AND (strpos($code,'interdire_scripts') !== 0) |
| 931 | 925 | AND !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
| 932 | 926 | AND !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
@@ -944,11 +938,10 @@ discard block |
||
| 944 | 938 | |
| 945 | 939 | if ($code != "''") { |
| 946 | 940 | $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
| 947 | - $codes[]= (($mode == 'validation') ? |
|
| 948 | - "array($code, '$commentaire', " . $p->ligne . ")" |
|
| 941 | + $codes[] = (($mode == 'validation') ? |
|
| 942 | + "array($code, '$commentaire', ".$p->ligne.")" |
|
| 949 | 943 | : (($mode == 'code') ? |
| 950 | - "\n// $commentaire\n$code" : |
|
| 951 | - $code)); |
|
| 944 | + "\n// $commentaire\n$code" : $code)); |
|
| 952 | 945 | } |
| 953 | 946 | } // foreach |
| 954 | 947 | |
@@ -964,24 +957,24 @@ discard block |
||
| 964 | 957 | { |
| 965 | 958 | if ($avant == "''") $avant = ''; |
| 966 | 959 | if ($apres == "''") $apres = ''; |
| 967 | - if (!$avant AND !$apres AND ($altern==="''")) return $code; |
|
| 960 | + if (!$avant AND !$apres AND ($altern === "''")) return $code; |
|
| 968 | 961 | |
| 969 | 962 | if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) { |
| 970 | 963 | $t = $code; |
| 971 | 964 | $cond = ''; |
| 972 | - } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE,$code, $r)) { |
|
| 965 | + } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
|
| 973 | 966 | $t = $r[2]; |
| 974 | - $cond = '!' . $r[1]; |
|
| 975 | - } else if (preg_match(_REGEXP_COND_NONVIDE_VIDE,$code, $r)) { |
|
| 967 | + $cond = '!'.$r[1]; |
|
| 968 | + } else if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)) { |
|
| 976 | 969 | $t = $r[2]; |
| 977 | 970 | $cond = $r[1]; |
| 978 | 971 | } else { |
| 979 | - $t = '$t' . $n; |
|
| 972 | + $t = '$t'.$n; |
|
| 980 | 973 | $cond = "($t = $code)!==''"; |
| 981 | 974 | } |
| 982 | 975 | |
| 983 | - $res = (!$avant ? "" : "$avant . ") . |
|
| 984 | - $t . |
|
| 976 | + $res = (!$avant ? "" : "$avant . "). |
|
| 977 | + $t. |
|
| 985 | 978 | (!$apres ? "" : " . $apres"); |
| 986 | 979 | |
| 987 | 980 | if ($res !== $t) $res = "($res)"; |
@@ -991,9 +984,9 @@ discard block |
||
| 991 | 984 | |
| 992 | 985 | function compile_inclure_doublons($lexemes) |
| 993 | 986 | { |
| 994 | - foreach($lexemes as $v) |
|
| 995 | - if($v->type === 'include' AND $v->param) |
|
| 996 | - foreach($v->param as $r) |
|
| 987 | + foreach ($lexemes as $v) |
|
| 988 | + if ($v->type === 'include' AND $v->param) |
|
| 989 | + foreach ($v->param as $r) |
|
| 997 | 990 | if (trim($r[0]) === 'doublons') |
| 998 | 991 | return true; |
| 999 | 992 | return false; |
@@ -1015,7 +1008,7 @@ discard block |
||
| 1015 | 1008 | // En cas d'erreur, elle retournera un tableau des 2 premiers elements seulement |
| 1016 | 1009 | |
| 1017 | 1010 | // http://doc.spip.org/@public_compiler_dist |
| 1018 | -function public_compiler_dist($squelette, $nom, $gram, $sourcefile, $connect=''){ |
|
| 1011 | +function public_compiler_dist($squelette, $nom, $gram, $sourcefile, $connect = '') { |
|
| 1019 | 1012 | // Pre-traitement : reperer le charset du squelette, et le convertir |
| 1020 | 1013 | // Bonus : supprime le BOM |
| 1021 | 1014 | include_spip('inc/charsets'); |
@@ -1023,7 +1016,7 @@ discard block |
||
| 1023 | 1016 | |
| 1024 | 1017 | // rendre inertes les echappements de #[](){}<> |
| 1025 | 1018 | $i = 0; |
| 1026 | - while(false !== strpos($squelette, $inerte = '-INERTE'.$i)) $i++; |
|
| 1019 | + while (false !== strpos($squelette, $inerte = '-INERTE'.$i)) $i++; |
|
| 1027 | 1020 | $squelette = preg_replace_callback(',\\\\([#[()\]{}<>]),', |
| 1028 | 1021 | create_function('$a', "return '$inerte-'.ord(\$a[1]).'-';"), $squelette, -1, $esc); |
| 1029 | 1022 | |
@@ -1035,14 +1028,14 @@ discard block |
||
| 1035 | 1028 | // Phraser le squelette, selon sa grammaire |
| 1036 | 1029 | |
| 1037 | 1030 | $boucles = array(); |
| 1038 | - $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1031 | + $f = charger_fonction('phraser_'.$gram, 'public'); |
|
| 1039 | 1032 | |
| 1040 | 1033 | $squelette = $f($squelette, '', $boucles, $descr); |
| 1041 | 1034 | $boucles = compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect); |
| 1042 | 1035 | |
| 1043 | 1036 | // restituer les echappements |
| 1044 | 1037 | if ($esc) |
| 1045 | - foreach($boucles as $i=>$boucle) { |
|
| 1038 | + foreach ($boucles as $i=>$boucle) { |
|
| 1046 | 1039 | $boucles[$i]->return = preg_replace_callback(",$inerte-(\d+)-,", create_function('$a', 'return chr($a[1]);'), |
| 1047 | 1040 | $boucle->return); |
| 1048 | 1041 | $boucles[$i]->descr['squelette'] = preg_replace_callback(",$inerte-(\d+)-,", create_function('$a', 'return "\\\\".chr($a[1]);'), |
@@ -1052,17 +1045,17 @@ discard block |
||
| 1052 | 1045 | $debug = ($boucles AND defined('_VAR_MODE') AND _VAR_MODE == 'debug'); |
| 1053 | 1046 | if ($debug) { |
| 1054 | 1047 | include_spip('public/decompiler'); |
| 1055 | - foreach($boucles as $id => $boucle) { |
|
| 1048 | + foreach ($boucles as $id => $boucle) { |
|
| 1056 | 1049 | if ($id) |
| 1057 | - $decomp = "\n/* BOUCLE " . |
|
| 1058 | - $boucle->type_requete . |
|
| 1059 | - " " . |
|
| 1060 | - str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1050 | + $decomp = "\n/* BOUCLE ". |
|
| 1051 | + $boucle->type_requete. |
|
| 1052 | + " ". |
|
| 1053 | + str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')). |
|
| 1061 | 1054 | " */\n"; |
| 1062 | - else $decomp = ("\n/*\n" . |
|
| 1055 | + else $decomp = ("\n/*\n". |
|
| 1063 | 1056 | str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
| 1064 | 1057 | . "\n*/"); |
| 1065 | - $boucles[$id]->return = $decomp .$boucle->return; |
|
| 1058 | + $boucles[$id]->return = $decomp.$boucle->return; |
|
| 1066 | 1059 | $GLOBALS['debug_objets']['code'][$nom.$id] = $boucle->return; |
| 1067 | 1060 | } |
| 1068 | 1061 | } |
@@ -1073,7 +1066,7 @@ discard block |
||
| 1073 | 1066 | // Point d'entree pour arbre de syntaxe abstraite fourni en premier argument |
| 1074 | 1067 | // Autres specifications comme ci-dessus |
| 1075 | 1068 | |
| 1076 | -function compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect=''){ |
|
| 1069 | +function compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect = '') { |
|
| 1077 | 1070 | static $trouver_table; |
| 1078 | 1071 | spip_timer('calcul_skel'); |
| 1079 | 1072 | |
@@ -1096,7 +1089,7 @@ discard block |
||
| 1096 | 1089 | if (!$trouver_table) |
| 1097 | 1090 | $trouver_table = charger_fonction('trouver_table', 'base'); |
| 1098 | 1091 | |
| 1099 | - foreach($boucles as $id => $boucle) { |
|
| 1092 | + foreach ($boucles as $id => $boucle) { |
|
| 1100 | 1093 | if (!($type = $boucle->type_requete)) continue; |
| 1101 | 1094 | if (!$descr['documents'] AND ( |
| 1102 | 1095 | (($type == 'documents') AND $boucle->doublons) OR |
@@ -1127,14 +1120,14 @@ discard block |
||
| 1127 | 1120 | // c'est peut etre une table qui necessite son connecteur dedie fourni |
| 1128 | 1121 | // permet une ecriture allegee (GEO) -> (geo:GEO) |
| 1129 | 1122 | if (!$show |
| 1130 | - AND $show=$trouver_table($type, strtolower($type))) { |
|
| 1123 | + AND $show = $trouver_table($type, strtolower($type))) { |
|
| 1131 | 1124 | $boucles[$id]->sql_serveur = strtolower($type); |
| 1132 | 1125 | } |
| 1133 | 1126 | if ($show) { |
| 1134 | 1127 | $boucles[$id]->show = $show; |
| 1135 | 1128 | // recopie les infos les plus importantes |
| 1136 | 1129 | $boucles[$id]->primary = $show['key']["PRIMARY KEY"]; |
| 1137 | - $boucles[$id]->id_table = $x = preg_replace(",^spip_,","",$show['id_table']); |
|
| 1130 | + $boucles[$id]->id_table = $x = preg_replace(",^spip_,", "", $show['id_table']); |
|
| 1138 | 1131 | $boucles[$id]->from[$x] = $nom_table = $show['table']; |
| 1139 | 1132 | $boucles[$id]->iterateur = 'SQL'; |
| 1140 | 1133 | |
@@ -1143,20 +1136,19 @@ discard block |
||
| 1143 | 1136 | AND is_array($show['tables_jointures']) |
| 1144 | 1137 | AND count($x = $show['tables_jointures'])) |
| 1145 | 1138 | $boucles[$id]->jointures = $x; |
| 1146 | - if ($boucles[$id]->jointures_explicites){ |
|
| 1147 | - $jointures = preg_split("/\s+/",$boucles[$id]->jointures_explicites); |
|
| 1148 | - while ($j=array_pop($jointures)) |
|
| 1149 | - array_unshift($boucles[$id]->jointures,$j); |
|
| 1139 | + if ($boucles[$id]->jointures_explicites) { |
|
| 1140 | + $jointures = preg_split("/\s+/", $boucles[$id]->jointures_explicites); |
|
| 1141 | + while ($j = array_pop($jointures)) |
|
| 1142 | + array_unshift($boucles[$id]->jointures, $j); |
|
| 1150 | 1143 | } |
| 1151 | 1144 | } else { |
| 1152 | 1145 | // Pas une erreur si la table est optionnelle |
| 1153 | 1146 | if ($boucles[$id]->table_optionnelle) |
| 1154 | 1147 | $boucles[$id]->type_requete = ''; |
| 1155 | - else { |
|
| 1148 | + else { |
|
| 1156 | 1149 | $boucles[$id]->type_requete = false; |
| 1157 | 1150 | $boucle = $boucles[$id]; |
| 1158 | - $x = (!$boucle->sql_serveur ? '' : |
|
| 1159 | - ($boucle->sql_serveur . ":")) . |
|
| 1151 | + $x = (!$boucle->sql_serveur ? '' : ($boucle->sql_serveur.":")). |
|
| 1160 | 1152 | $type; |
| 1161 | 1153 | $msg = array('zbug_table_inconnue', |
| 1162 | 1154 | array('table' => $x)); |
@@ -1169,7 +1161,7 @@ discard block |
||
| 1169 | 1161 | |
| 1170 | 1162 | // Commencer par reperer les boucles appelees explicitement |
| 1171 | 1163 | // car elles indexent les arguments de maniere derogatoire |
| 1172 | - foreach($boucles as $id => $boucle) { |
|
| 1164 | + foreach ($boucles as $id => $boucle) { |
|
| 1173 | 1165 | if ($boucle->type_requete == TYPE_RECURSIF AND $boucle->param) { |
| 1174 | 1166 | $boucles[$id]->descr = &$descr; |
| 1175 | 1167 | $rec = &$boucles[$boucle->param[0]]; |
@@ -1189,7 +1181,7 @@ discard block |
||
| 1189 | 1181 | } |
| 1190 | 1182 | } |
| 1191 | 1183 | } |
| 1192 | - foreach($boucles as $id => $boucle) { |
|
| 1184 | + foreach ($boucles as $id => $boucle) { |
|
| 1193 | 1185 | $id = strval($id); // attention au type dans index_pile |
| 1194 | 1186 | $type = $boucle->type_requete; |
| 1195 | 1187 | if ($type AND $type != TYPE_RECURSIF) { |
@@ -1223,9 +1215,9 @@ discard block |
||
| 1223 | 1215 | // en particulier les requetes SQL et TOTAL_BOUCLE |
| 1224 | 1216 | // de'terminables seulement maintenant |
| 1225 | 1217 | |
| 1226 | - foreach($boucles as $id => $boucle) { |
|
| 1218 | + foreach ($boucles as $id => $boucle) { |
|
| 1227 | 1219 | $boucle = $boucles[$id] = pipeline('pre_boucle', $boucle); |
| 1228 | - if ($boucle->return === false) {$corps = false; continue;} |
|
| 1220 | + if ($boucle->return === false) {$corps = false; continue; } |
|
| 1229 | 1221 | // appeler la fonction de definition de la boucle |
| 1230 | 1222 | |
| 1231 | 1223 | if ($req = $boucle->type_requete) { |
@@ -1242,25 +1234,25 @@ discard block |
||
| 1242 | 1234 | // fonction de boucle avec table |
| 1243 | 1235 | AND (!function_exists($f = "boucle_".$table)) |
| 1244 | 1236 | AND (!function_exists($f = $f."_dist")) |
| 1245 | - ){ |
|
| 1237 | + ) { |
|
| 1246 | 1238 | // fonction de boucle standard |
| 1247 | 1239 | if (!function_exists($f = 'boucle_DEFAUT')) { |
| 1248 | 1240 | $f = 'boucle_DEFAUT_dist'; |
| 1249 | 1241 | } |
| 1250 | 1242 | } |
| 1251 | 1243 | |
| 1252 | - $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1253 | - "static \$connect;\n\t" . |
|
| 1254 | - "\$command['connect'] = \$connect = " . |
|
| 1255 | - _q($boucle->sql_serveur) . |
|
| 1256 | - ";" . |
|
| 1244 | + $req = "\n\n\tstatic \$command = array();\n\t". |
|
| 1245 | + "static \$connect;\n\t". |
|
| 1246 | + "\$command['connect'] = \$connect = ". |
|
| 1247 | + _q($boucle->sql_serveur). |
|
| 1248 | + ";". |
|
| 1257 | 1249 | $f($id, $boucles); |
| 1258 | 1250 | } else $req = ("\n\treturn '';"); |
| 1259 | 1251 | |
| 1260 | 1252 | $boucles[$id]->return = |
| 1261 | - "\n\nfunction BOUCLE" . strtr($id,"-","_") . $nom . |
|
| 1262 | - '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1263 | - $req . |
|
| 1253 | + "\n\nfunction BOUCLE".strtr($id, "-", "_").$nom. |
|
| 1254 | + '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {'. |
|
| 1255 | + $req. |
|
| 1264 | 1256 | "\n}\n"; |
| 1265 | 1257 | } |
| 1266 | 1258 | |
@@ -1268,7 +1260,7 @@ discard block |
||
| 1268 | 1260 | // retourner False, sinon inserer leur decompilation |
| 1269 | 1261 | if (is_bool($corps)) return false; |
| 1270 | 1262 | |
| 1271 | - $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons=array(), $Numrows=array(), $SP=0) { |
|
| 1263 | + $principal = "\nfunction ".$nom.'($Cache, $Pile, $doublons=array(), $Numrows=array(), $SP=0) { |
|
| 1272 | 1264 | ' |
| 1273 | 1265 | // reporter de maniere securisee les doublons inclus |
| 1274 | 1266 | .' |
@@ -1276,15 +1268,15 @@ discard block |
||
| 1276 | 1268 | $doublons = nettoyer_env_doublons($Pile[0]["doublons"]); |
| 1277 | 1269 | |
| 1278 | 1270 | $connect = ' . |
| 1279 | - _q($connect) . '; |
|
| 1271 | + _q($connect).'; |
|
| 1280 | 1272 | $page = ' . |
| 1281 | 1273 | // ATTENTION, le calcul de l'expression $corps affectera $Cache |
| 1282 | 1274 | // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
| 1283 | 1275 | // avant de referencer $Cache |
| 1284 | - $corps . "; |
|
| 1276 | + $corps."; |
|
| 1285 | 1277 | |
| 1286 | - return analyse_resultat_skel(".var_export($nom,true) |
|
| 1287 | - .", \$Cache, \$page, ".var_export($sourcefile,true)."); |
|
| 1278 | + return analyse_resultat_skel(".var_export($nom, true) |
|
| 1279 | + .", \$Cache, \$page, ".var_export($sourcefile, true)."); |
|
| 1288 | 1280 | }"; |
| 1289 | 1281 | |
| 1290 | 1282 | $secondes = spip_timer('calcul_skel'); |
@@ -1298,10 +1290,10 @@ discard block |
||
| 1298 | 1290 | $code->return = ' |
| 1299 | 1291 | // |
| 1300 | 1292 | // Fonction principale du squelette ' . |
| 1301 | - $sourcefile . |
|
| 1302 | - ($connect ? " pour $connect" : '') . |
|
| 1303 | - (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1304 | - "\n//\n" . |
|
| 1293 | + $sourcefile. |
|
| 1294 | + ($connect ? " pour $connect" : ''). |
|
| 1295 | + (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes"). |
|
| 1296 | + "\n//\n". |
|
| 1305 | 1297 | $principal; |
| 1306 | 1298 | |
| 1307 | 1299 | $boucles[''] = $code; |
@@ -1350,7 +1342,7 @@ discard block |
||
| 1350 | 1342 | **/ |
| 1351 | 1343 | function requeteur_data_dist(&$boucles, &$boucle, &$id) { |
| 1352 | 1344 | include_spip('iterateur/data'); |
| 1353 | - if ($h = charger_fonction($boucle->type_requete . '_to_array' , 'inc', true)) { |
|
| 1345 | + if ($h = charger_fonction($boucle->type_requete.'_to_array', 'inc', true)) { |
|
| 1354 | 1346 | $g = charger_fonction('data', 'iterateur'); |
| 1355 | 1347 | $boucles[$id] = $g($boucle); |
| 1356 | 1348 | // from[0] stocke le type de data (rss, yql, ...) |
@@ -17,7 +17,9 @@ discard block |
||
| 17 | 17 | * @package SPIP\Compilateur\Compilation |
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 20 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 21 | + return; |
|
| 22 | +} |
|
| 21 | 23 | |
| 22 | 24 | /** Repérer un code ne calculant rien, meme avec commentaire */ |
| 23 | 25 | define('CODE_MONOTONE', ",^(\n//[^\n]*\n)?\(?'([^'])*'\)?$,"); |
@@ -60,11 +62,15 @@ discard block |
||
| 60 | 62 | function argumenter_inclure($params, $rejet_filtres, $p, &$boucles, $id_boucle, $echap=true, $lang = '', $fond1=false){ |
| 61 | 63 | $l = array(); |
| 62 | 64 | $erreur_p_i_i = ''; |
| 63 | - if (!is_array($params)) return $l; |
|
| 65 | + if (!is_array($params)) { |
|
| 66 | + return $l; |
|
| 67 | + } |
|
| 64 | 68 | foreach($params as $k => $couple) { |
| 65 | 69 | // la liste d'arguments d'inclusion peut se terminer par un filtre |
| 66 | 70 | $filtre = array_shift($couple); |
| 67 | - if ($filtre) break; |
|
| 71 | + if ($filtre) { |
|
| 72 | + break; |
|
| 73 | + } |
|
| 68 | 74 | foreach($couple as $n => $val) { |
| 69 | 75 | $var = $val[0]; |
| 70 | 76 | if ($var->type != 'texte') { |
@@ -73,20 +79,25 @@ discard block |
||
| 73 | 79 | array('param' => $var->nom_champ)); |
| 74 | 80 | erreur_squelette($erreur_p_i_i, $p); |
| 75 | 81 | break; |
| 82 | + } else { |
|
| 83 | + $l[1] = calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 76 | 84 | } |
| 77 | - else $l[1] = calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 78 | 85 | } else { |
| 79 | 86 | preg_match(",^([^=]*)(=?)(.*)$,m", $var->texte,$m); |
| 80 | 87 | $var = $m[1]; |
| 81 | 88 | $auto = false;; |
| 82 | 89 | if ($m[2]) { |
| 83 | 90 | $v = $m[3]; |
| 84 | - if (preg_match(',^[\'"](.*)[\'"]$,', $v, $m)) $v = $m[1]; |
|
| 91 | + if (preg_match(',^[\'"](.*)[\'"]$,', $v, $m)) { |
|
| 92 | + $v = $m[1]; |
|
| 93 | + } |
|
| 85 | 94 | $val[0] = new Texte; |
| 86 | 95 | $val[0]->texte = $v; |
| 87 | 96 | } elseif ($k OR $n OR $fond1) { |
| 88 | 97 | $auto = true; |
| 89 | - } else $var = 1; |
|
| 98 | + } else { |
|
| 99 | + $var = 1; |
|
| 100 | + } |
|
| 90 | 101 | |
| 91 | 102 | if ($var == 'lang') { |
| 92 | 103 | $lang = !$auto |
@@ -96,21 +107,29 @@ discard block |
||
| 96 | 107 | $val = $auto |
| 97 | 108 | ? index_pile($id_boucle, $var, $boucles) |
| 98 | 109 | : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
| 99 | - if ($var !== 1) |
|
| 100 | - $val = ($echap?"\'$var\' => ' . argumenter_squelette(":"'$var' => ") |
|
| 110 | + if ($var !== 1) { |
|
| 111 | + $val = ($echap?"\'$var\' => ' . argumenter_squelette(":"'$var' => ") |
|
| 101 | 112 | . $val . ($echap? ") . '":" "); |
| 102 | - else $val = $echap ? "'.$val.'" : $val; |
|
| 113 | + } else { |
|
| 114 | + $val = $echap ? "'.$val.'" : $val; |
|
| 115 | + } |
|
| 103 | 116 | $l[$var] = $val; |
| 104 | 117 | } |
| 105 | 118 | } |
| 106 | 119 | } |
| 107 | 120 | } |
| 108 | - if ($erreur_p_i_i) return false; |
|
| 121 | + if ($erreur_p_i_i) { |
|
| 122 | + return false; |
|
| 123 | + } |
|
| 109 | 124 | // Cas particulier de la langue : si {lang=xx} est definie, on |
| 110 | 125 | // la passe, sinon on passe la langue courante au moment du calcul |
| 111 | 126 | // sauf si on n'en veut pas |
| 112 | - if ($lang === false) return $l; |
|
| 113 | - if (!$lang) $lang = '$GLOBALS["spip_lang"]'; |
|
| 127 | + if ($lang === false) { |
|
| 128 | + return $l; |
|
| 129 | + } |
|
| 130 | + if (!$lang) { |
|
| 131 | + $lang = '$GLOBALS["spip_lang"]'; |
|
| 132 | + } |
|
| 114 | 133 | $l['lang'] = ($echap?"\'lang\' => ' . argumenter_squelette(":"'lang' => ") . $lang . ($echap?") . '":" "); |
| 115 | 134 | |
| 116 | 135 | return $l; |
@@ -144,9 +163,11 @@ discard block |
||
| 144 | 163 | |
| 145 | 164 | } else { |
| 146 | 165 | $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
| 147 | - if ($code AND preg_match("/^'([^']*)'/s", $code, $r)) |
|
| 148 | - $fichier = $r[1]; |
|
| 149 | - else $fichier = ''; |
|
| 166 | + if ($code AND preg_match("/^'([^']*)'/s", $code, $r)) { |
|
| 167 | + $fichier = $r[1]; |
|
| 168 | + } else { |
|
| 169 | + $fichier = ''; |
|
| 170 | + } |
|
| 150 | 171 | } |
| 151 | 172 | if (!$code OR $code === '""') { |
| 152 | 173 | $erreur_p_i_i = array('zbug_parametres_inclus_incorrects', |
@@ -173,9 +194,10 @@ discard block |
||
| 173 | 194 | } |
| 174 | 195 | |
| 175 | 196 | $_contexte = join(",\n\t", $_contexte); |
| 197 | + } else { |
|
| 198 | + return false; |
|
| 176 | 199 | } |
| 177 | - else |
|
| 178 | - return false; // j'aurais voulu toucher le fond ... |
|
| 200 | + // j'aurais voulu toucher le fond ... |
|
| 179 | 201 | |
| 180 | 202 | $contexte = 'array(' . $_contexte .')'; |
| 181 | 203 | |
@@ -188,8 +210,9 @@ discard block |
||
| 188 | 210 | $code = sandbox_composer_inclure_php($fichier, $p, $contexte); |
| 189 | 211 | } else { |
| 190 | 212 | $_options[] = "\"compil\"=>array($compil)"; |
| 191 | - if ($ajax) |
|
| 192 | - $_options[] = $ajax; |
|
| 213 | + if ($ajax) { |
|
| 214 | + $_options[] = $ajax; |
|
| 215 | + } |
|
| 193 | 216 | $code = " ' . argumenter_squelette($code) . '"; |
| 194 | 217 | $code = "echo " . sprintf(CODE_RECUPERER_FOND, $code, $contexte, implode(',',$_options), "_request(\"connect\")") . ';'; |
| 195 | 218 | } |
@@ -270,8 +293,7 @@ discard block |
||
| 270 | 293 | } |
| 271 | 294 | // trouver l'alias de la table d'arrivee qui porte le statut |
| 272 | 295 | $id = array_search($id, $boucle->from); |
| 273 | - } |
|
| 274 | - else { |
|
| 296 | + } else { |
|
| 275 | 297 | $id = $id_table; |
| 276 | 298 | $statut = preg_replace(',\W,','',$s['champ']); // securite |
| 277 | 299 | } |
@@ -325,9 +347,9 @@ discard block |
||
| 325 | 347 | |
| 326 | 348 | // en mode debug memoriser les premiers passages dans la boucle, |
| 327 | 349 | // mais pas tous, sinon ca pete. |
| 328 | - if (_request('var_mode_affiche') != 'resultat') |
|
| 329 | - $trace = ''; |
|
| 330 | - else { |
|
| 350 | + if (_request('var_mode_affiche') != 'resultat') { |
|
| 351 | + $trace = ''; |
|
| 352 | + } else { |
|
| 331 | 353 | $trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
| 332 | 354 | $trace = "if (count(@\$GLOBALS['debug_objets']['resultat']['$trace'])<3) |
| 333 | 355 | \$GLOBALS['debug_objets']['resultat']['$trace'][] = \$t0;"; |
@@ -427,10 +449,11 @@ discard block |
||
| 427 | 449 | |
| 428 | 450 | // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
| 429 | 451 | // et puis faire un [] plutot qu'un "','." |
| 430 | - if ($boucle->doublons) |
|
| 431 | - $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 452 | + if ($boucle->doublons) { |
|
| 453 | + $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 432 | 454 | index_pile($id_boucle, $primary, $boucles) |
| 433 | 455 | . "; // doublons\n"; |
| 456 | + } |
|
| 434 | 457 | |
| 435 | 458 | // La boucle doit-elle selectionner la langue ? |
| 436 | 459 | // - par defaut, les boucles suivantes le font |
@@ -456,8 +479,7 @@ discard block |
||
| 456 | 479 | 'articles', 'rubriques', 'hierarchie', 'breves' |
| 457 | 480 | )) ? ', '.index_pile($id_boucle, 'titre', $boucles) : '') |
| 458 | 481 | . ');'; |
| 459 | - } |
|
| 460 | - else { |
|
| 482 | + } else { |
|
| 461 | 483 | $init_lang = ''; |
| 462 | 484 | $fin_lang = ''; |
| 463 | 485 | $fin_lang_select_public = ''; |
@@ -474,8 +496,9 @@ discard block |
||
| 474 | 496 | } |
| 475 | 497 | |
| 476 | 498 | // gestion optimale des separateurs et des boucles constantes |
| 477 | - if (count($boucle->separateur)) |
|
| 478 | - $code_sep = ("'" . str_replace("'","\'",join('',$boucle->separateur)) . "'"); |
|
| 499 | + if (count($boucle->separateur)) { |
|
| 500 | + $code_sep = ("'" . str_replace("'","\'",join('',$boucle->separateur)) . "'"); |
|
| 501 | + } |
|
| 479 | 502 | |
| 480 | 503 | $corps .= |
| 481 | 504 | ((!$boucle->separateur) ? |
@@ -493,17 +516,19 @@ discard block |
||
| 493 | 516 | // souhaite invalider ces elements |
| 494 | 517 | if (!$constant AND $primary) { |
| 495 | 518 | include_spip('inc/invalideur'); |
| 496 | - if (function_exists($i = 'calcul_invalideurs')) |
|
| 497 | - $corps = $i($corps, $primary, $boucles, $id_boucle); |
|
| 519 | + if (function_exists($i = 'calcul_invalideurs')) { |
|
| 520 | + $corps = $i($corps, $primary, $boucles, $id_boucle); |
|
| 521 | + } |
|
| 498 | 522 | } |
| 499 | 523 | |
| 500 | 524 | // gerer le compteur de boucle |
| 501 | 525 | // avec ou sans son utilisation par les criteres {1/3} {1,4} {n-2,1}... |
| 502 | 526 | |
| 503 | - if ($boucle->partie OR $boucle->cptrows) |
|
| 504 | - $corps = "\n\t\t\$Numrows['$id_boucle']['compteur_boucle']++;" |
|
| 527 | + if ($boucle->partie OR $boucle->cptrows) { |
|
| 528 | + $corps = "\n\t\t\$Numrows['$id_boucle']['compteur_boucle']++;" |
|
| 505 | 529 | . $boucle->partie |
| 506 | 530 | . $corps; |
| 531 | + } |
|
| 507 | 532 | |
| 508 | 533 | // depiler la lang de la boucle si besoin |
| 509 | 534 | $corps .= $fin_lang_select_public; |
@@ -512,28 +537,35 @@ discard block |
||
| 512 | 537 | |
| 513 | 538 | if (preg_match(CODE_MONOTONE,str_replace("\\'",'',$corps), $r)) { |
| 514 | 539 | if (!isset($r[2]) OR (!$r[2])) { |
| 515 | - if (!$boucle->numrows) |
|
| 516 | - return "\n\t\$t0 = '';"; |
|
| 517 | - else |
|
| 518 | - $corps = ""; |
|
| 540 | + if (!$boucle->numrows) { |
|
| 541 | + return "\n\t\$t0 = '';"; |
|
| 542 | + } else { |
|
| 543 | + $corps = ""; |
|
| 544 | + } |
|
| 519 | 545 | } else { |
| 520 | 546 | $boucle->numrows = true; |
| 521 | 547 | $corps = "\n\t\$t0 = str_repeat($corps, \$Numrows['$id_boucle']['total']);"; |
| 522 | 548 | } |
| 523 | - } else $corps = "while (\$Pile[\$SP]=\$iter->fetch()) {\n$corps\n }"; |
|
| 549 | + } else { |
|
| 550 | + $corps = "while (\$Pile[\$SP]=\$iter->fetch()) {\n$corps\n }"; |
|
| 551 | + } |
|
| 524 | 552 | |
| 525 | 553 | $count = ''; |
| 526 | 554 | if (!$boucle->select) { |
| 527 | - if (!$boucle->numrows OR $boucle->limit OR $boucle->mode_partie OR $boucle->group) |
|
| 528 | - $count = '1'; |
|
| 529 | - else $count = 'count(*)'; |
|
| 555 | + if (!$boucle->numrows OR $boucle->limit OR $boucle->mode_partie OR $boucle->group) { |
|
| 556 | + $count = '1'; |
|
| 557 | + } else { |
|
| 558 | + $count = 'count(*)'; |
|
| 559 | + } |
|
| 530 | 560 | $boucles[$id_boucle]->select[]= $count; |
| 531 | 561 | } |
| 532 | 562 | |
| 533 | - if ($flag_cpt) |
|
| 534 | - $nums = "\n\t// COMPTEUR\n\t" |
|
| 563 | + if ($flag_cpt) { |
|
| 564 | + $nums = "\n\t// COMPTEUR\n\t" |
|
| 535 | 565 | . "\$Numrows['$id_boucle']['compteur_boucle'] = 0;\n\t"; |
| 536 | - else $nums = ''; |
|
| 566 | + } else { |
|
| 567 | + $nums = ''; |
|
| 568 | + } |
|
| 537 | 569 | |
| 538 | 570 | if ($boucle->numrows OR $boucle->mode_partie) { |
| 539 | 571 | $nums .= "\$Numrows['$id_boucle']['total'] = @intval(\$iter->count());" |
@@ -600,10 +632,11 @@ discard block |
||
| 600 | 632 | $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
| 601 | 633 | $s = $d = ""; |
| 602 | 634 | foreach ($init as $i){ |
| 603 | - if (reset($i)) |
|
| 604 | - $s .= "\n\t\t".end($i); |
|
| 605 | - else |
|
| 606 | - $d .= "\n\t".end($i); |
|
| 635 | + if (reset($i)) { |
|
| 636 | + $s .= "\n\t\t".end($i); |
|
| 637 | + } else { |
|
| 638 | + $d .= "\n\t".end($i); |
|
| 639 | + } |
|
| 607 | 640 | } |
| 608 | 641 | |
| 609 | 642 | return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
@@ -654,7 +687,9 @@ discard block |
||
| 654 | 687 | **/ |
| 655 | 688 | function reconstruire_contexte_compil($context_compil) |
| 656 | 689 | { |
| 657 | - if (!is_array($context_compil)) return $context_compil; |
|
| 690 | + if (!is_array($context_compil)) { |
|
| 691 | + return $context_compil; |
|
| 692 | + } |
|
| 658 | 693 | $p = new Contexte; |
| 659 | 694 | $p->descr = array('sourcefile' => $context_compil[0], |
| 660 | 695 | 'nom' => $context_compil[1]); |
@@ -680,8 +715,9 @@ discard block |
||
| 680 | 715 | AND $test = preg_replace(",'[^']*',UimsS","",$test) // supprimer les chaines qui peuvent contenir des fonctions SQL qui ne genent pas |
| 681 | 716 | AND preg_match(",\w+\s*\(,UimsS",$test,$regs) // tester la presence de fonctions restantes |
| 682 | 717 | )*/ |
| 683 | - ) |
|
| 684 | - $static = ""; |
|
| 718 | + ) { |
|
| 719 | + $static = ""; |
|
| 720 | + } |
|
| 685 | 721 | |
| 686 | 722 | return array($static,'$command[\''.$nom.'\'] = ' . $val . ';'); |
| 687 | 723 | } |
@@ -689,15 +725,19 @@ discard block |
||
| 689 | 725 | // http://doc.spip.org/@calculer_dump_array |
| 690 | 726 | function calculer_dump_array($a) |
| 691 | 727 | { |
| 692 | - if (!is_array($a)) return $a ; |
|
| 728 | + if (!is_array($a)) { |
|
| 729 | + return $a ; |
|
| 730 | + } |
|
| 693 | 731 | $res = ""; |
| 694 | - if ($a AND $a[0] == "'?'") |
|
| 695 | - return ("(" . calculer_dump_array($a[1]) . |
|
| 732 | + if ($a AND $a[0] == "'?'") { |
|
| 733 | + return ("(" . calculer_dump_array($a[1]) . |
|
| 696 | 734 | " ? " . calculer_dump_array($a[2]) . |
| 697 | 735 | " : " . calculer_dump_array($a[3]) . |
| 698 | 736 | ")"); |
| 699 | - else { |
|
| 700 | - foreach($a as $v) $res .= ", " . calculer_dump_array($v); |
|
| 737 | + } else { |
|
| 738 | + foreach($a as $v) { |
|
| 739 | + $res .= ", " . calculer_dump_array($v); |
|
| 740 | + } |
|
| 701 | 741 | return "\n\t\t\tarray(" . substr($res,2) . ')'; |
| 702 | 742 | } |
| 703 | 743 | } |
@@ -706,8 +746,9 @@ discard block |
||
| 706 | 746 | function calculer_dump_join($a) |
| 707 | 747 | { |
| 708 | 748 | $res = ""; |
| 709 | - foreach($a as $k => $v) |
|
| 710 | - $res .= ", '$k' => array(".implode(',',$v).")"; |
|
| 749 | + foreach($a as $k => $v) { |
|
| 750 | + $res .= ", '$k' => array(".implode(',',$v).")"; |
|
| 751 | + } |
|
| 711 | 752 | return 'array(' . substr($res,2) . ')'; |
| 712 | 753 | } |
| 713 | 754 | |
@@ -715,7 +756,9 @@ discard block |
||
| 715 | 756 | function calculer_from(&$boucle) |
| 716 | 757 | { |
| 717 | 758 | $res = ""; |
| 718 | - foreach($boucle->from as $k => $v) $res .= ",'$k' => '$v'"; |
|
| 759 | + foreach($boucle->from as $k => $v) { |
|
| 760 | + $res .= ",'$k' => '$v'"; |
|
| 761 | + } |
|
| 719 | 762 | return 'array(' . substr($res,1) . ')'; |
| 720 | 763 | } |
| 721 | 764 | |
@@ -723,7 +766,9 @@ discard block |
||
| 723 | 766 | function calculer_from_type(&$boucle) |
| 724 | 767 | { |
| 725 | 768 | $res = ""; |
| 726 | - foreach($boucle->from_type as $k => $v) $res .= ",'$k' => '$v'"; |
|
| 769 | + foreach($boucle->from_type as $k => $v) { |
|
| 770 | + $res .= ",'$k' => '$v'"; |
|
| 771 | + } |
|
| 727 | 772 | return 'array(' . substr($res,1) . ')'; |
| 728 | 773 | } |
| 729 | 774 | |
@@ -731,8 +776,9 @@ discard block |
||
| 731 | 776 | function calculer_order(&$boucle) |
| 732 | 777 | { |
| 733 | 778 | if (!$order = $boucle->order |
| 734 | - AND !$order = $boucle->default_order) |
|
| 735 | - $order = array(); |
|
| 779 | + AND !$order = $boucle->default_order) { |
|
| 780 | + $order = array(); |
|
| 781 | + } |
|
| 736 | 782 | |
| 737 | 783 | /*if (isset($boucle->modificateur['collate'])){ |
| 738 | 784 | $col = "." . $boucle->modificateur['collate']; |
@@ -750,23 +796,31 @@ discard block |
||
| 750 | 796 | |
| 751 | 797 | // http://doc.spip.org/@calculer_liste |
| 752 | 798 | function calculer_liste($tableau, $descr, &$boucles, $id_boucle='') { |
| 753 | - if (!$tableau) return "''"; |
|
| 754 | - if (!isset($descr['niv'])) $descr['niv'] = 0; |
|
| 799 | + if (!$tableau) { |
|
| 800 | + return "''"; |
|
| 801 | + } |
|
| 802 | + if (!isset($descr['niv'])) { |
|
| 803 | + $descr['niv'] = 0; |
|
| 804 | + } |
|
| 755 | 805 | $codes = compile_cas($tableau, $descr, $boucles, $id_boucle); |
| 756 | - if ($codes === false) return false; |
|
| 806 | + if ($codes === false) { |
|
| 807 | + return false; |
|
| 808 | + } |
|
| 757 | 809 | $n = count($codes); |
| 758 | - if (!$n) return "''"; |
|
| 810 | + if (!$n) { |
|
| 811 | + return "''"; |
|
| 812 | + } |
|
| 759 | 813 | $tab = str_repeat("\t", $descr['niv']); |
| 760 | 814 | if (_request('var_mode_affiche') != 'validation') { |
| 761 | - if ($n==1) |
|
| 762 | - return $codes[0]; |
|
| 763 | - else { |
|
| 815 | + if ($n==1) { |
|
| 816 | + return $codes[0]; |
|
| 817 | + } else { |
|
| 764 | 818 | $res = ''; |
| 765 | 819 | foreach($codes as $code) { |
| 766 | 820 | if (!preg_match("/^'[^']*'$/", $code) |
| 767 | - OR substr($res,-1,1)!=="'") |
|
| 768 | - $res .= " .\n$tab$code"; |
|
| 769 | - else { |
|
| 821 | + OR substr($res,-1,1)!=="'") { |
|
| 822 | + $res .= " .\n$tab$code"; |
|
| 823 | + } else { |
|
| 770 | 824 | $res = substr($res,0,-1) . substr($code,1); |
| 771 | 825 | } |
| 772 | 826 | } |
@@ -787,8 +841,9 @@ discard block |
||
| 787 | 841 | |
| 788 | 842 | $codes = array(); |
| 789 | 843 | // cas de la boucle recursive |
| 790 | - if (is_array($id_boucle)) |
|
| 791 | - $id_boucle = $id_boucle[0]; |
|
| 844 | + if (is_array($id_boucle)) { |
|
| 845 | + $id_boucle = $id_boucle[0]; |
|
| 846 | + } |
|
| 792 | 847 | $type = !$id_boucle ? '' : $boucles[$id_boucle]->type_requete; |
| 793 | 848 | $tab = str_repeat("\t", ++$descr['niv']); |
| 794 | 849 | $mode = _request('var_mode_affiche'); |
@@ -863,11 +918,16 @@ discard block |
||
| 863 | 918 | $commentaire= "?$nom"; |
| 864 | 919 | if (!$boucles[$nom]->milieu |
| 865 | 920 | AND $boucles[$nom]->type_requete <> TYPE_RECURSIF) { |
| 866 | - if ($altern != "''") $code .= "\n. $altern"; |
|
| 867 | - if ($avant<>"''" OR $apres<>"''") |
|
| 868 | - spip_log("boucle $nom toujours vide, code superflu dans $id"); |
|
| 921 | + if ($altern != "''") { |
|
| 922 | + $code .= "\n. $altern"; |
|
| 923 | + } |
|
| 924 | + if ($avant<>"''" OR $apres<>"''") { |
|
| 925 | + spip_log("boucle $nom toujours vide, code superflu dans $id"); |
|
| 926 | + } |
|
| 869 | 927 | $avant = $apres = $altern = "''"; |
| 870 | - } else if ($altern != "''") $altern = "($altern)"; |
|
| 928 | + } else if ($altern != "''") { |
|
| 929 | + $altern = "($altern)"; |
|
| 930 | + } |
|
| 871 | 931 | } |
| 872 | 932 | break; |
| 873 | 933 | |
@@ -930,8 +990,9 @@ discard block |
||
| 930 | 990 | # AND (strpos($code,'interdire_scripts') !== 0) |
| 931 | 991 | AND !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
| 932 | 992 | AND !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
| 933 | - AND !preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) |
|
| 934 | - $code = "strval($code)"; |
|
| 993 | + AND !preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) { |
|
| 994 | + $code = "strval($code)"; |
|
| 995 | + } |
|
| 935 | 996 | break; |
| 936 | 997 | |
| 937 | 998 | default: |
@@ -962,9 +1023,15 @@ discard block |
||
| 962 | 1023 | // http://doc.spip.org/@compile_retour |
| 963 | 1024 | function compile_retour($code, $avant, $apres, $altern, $tab, $n) |
| 964 | 1025 | { |
| 965 | - if ($avant == "''") $avant = ''; |
|
| 966 | - if ($apres == "''") $apres = ''; |
|
| 967 | - if (!$avant AND !$apres AND ($altern==="''")) return $code; |
|
| 1026 | + if ($avant == "''") { |
|
| 1027 | + $avant = ''; |
|
| 1028 | + } |
|
| 1029 | + if ($apres == "''") { |
|
| 1030 | + $apres = ''; |
|
| 1031 | + } |
|
| 1032 | + if (!$avant AND !$apres AND ($altern==="''")) { |
|
| 1033 | + return $code; |
|
| 1034 | + } |
|
| 968 | 1035 | |
| 969 | 1036 | if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) { |
| 970 | 1037 | $t = $code; |
@@ -984,18 +1051,21 @@ discard block |
||
| 984 | 1051 | $t . |
| 985 | 1052 | (!$apres ? "" : " . $apres"); |
| 986 | 1053 | |
| 987 | - if ($res !== $t) $res = "($res)"; |
|
| 1054 | + if ($res !== $t) { |
|
| 1055 | + $res = "($res)"; |
|
| 1056 | + } |
|
| 988 | 1057 | return !$cond ? $res : "($cond ?\n\t$tab$res :\n\t$tab$altern)"; |
| 989 | 1058 | } |
| 990 | 1059 | |
| 991 | 1060 | |
| 992 | 1061 | function compile_inclure_doublons($lexemes) |
| 993 | 1062 | { |
| 994 | - foreach($lexemes as $v) |
|
| 995 | - if($v->type === 'include' AND $v->param) |
|
| 1063 | + foreach($lexemes as $v) { |
|
| 1064 | + if($v->type === 'include' AND $v->param) |
|
| 996 | 1065 | foreach($v->param as $r) |
| 997 | 1066 | if (trim($r[0]) === 'doublons') |
| 998 | 1067 | return true; |
| 1068 | + } |
|
| 999 | 1069 | return false; |
| 1000 | 1070 | } |
| 1001 | 1071 | |
@@ -1023,7 +1093,9 @@ discard block |
||
| 1023 | 1093 | |
| 1024 | 1094 | // rendre inertes les echappements de #[](){}<> |
| 1025 | 1095 | $i = 0; |
| 1026 | - while(false !== strpos($squelette, $inerte = '-INERTE'.$i)) $i++; |
|
| 1096 | + while(false !== strpos($squelette, $inerte = '-INERTE'.$i)) { |
|
| 1097 | + $i++; |
|
| 1098 | + } |
|
| 1027 | 1099 | $squelette = preg_replace_callback(',\\\\([#[()\]{}<>]),', |
| 1028 | 1100 | create_function('$a', "return '$inerte-'.ord(\$a[1]).'-';"), $squelette, -1, $esc); |
| 1029 | 1101 | |
@@ -1041,10 +1113,11 @@ discard block |
||
| 1041 | 1113 | $boucles = compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect); |
| 1042 | 1114 | |
| 1043 | 1115 | // restituer les echappements |
| 1044 | - if ($esc) |
|
| 1045 | - foreach($boucles as $i=>$boucle) { |
|
| 1116 | + if ($esc) { |
|
| 1117 | + foreach($boucles as $i=>$boucle) { |
|
| 1046 | 1118 | $boucles[$i]->return = preg_replace_callback(",$inerte-(\d+)-,", create_function('$a', 'return chr($a[1]);'), |
| 1047 | 1119 | $boucle->return); |
| 1120 | + } |
|
| 1048 | 1121 | $boucles[$i]->descr['squelette'] = preg_replace_callback(",$inerte-(\d+)-,", create_function('$a', 'return "\\\\".chr($a[1]);'), |
| 1049 | 1122 | $boucle->descr['squelette']); |
| 1050 | 1123 | } |
@@ -1053,15 +1126,17 @@ discard block |
||
| 1053 | 1126 | if ($debug) { |
| 1054 | 1127 | include_spip('public/decompiler'); |
| 1055 | 1128 | foreach($boucles as $id => $boucle) { |
| 1056 | - if ($id) |
|
| 1057 | - $decomp = "\n/* BOUCLE " . |
|
| 1129 | + if ($id) { |
|
| 1130 | + $decomp = "\n/* BOUCLE " . |
|
| 1058 | 1131 | $boucle->type_requete . |
| 1059 | 1132 | " " . |
| 1060 | 1133 | str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
| 1061 | 1134 | " */\n"; |
| 1062 | - else $decomp = ("\n/*\n" . |
|
| 1135 | + } else { |
|
| 1136 | + $decomp = ("\n/*\n" . |
|
| 1063 | 1137 | str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
| 1064 | 1138 | . "\n*/"); |
| 1139 | + } |
|
| 1065 | 1140 | $boucles[$id]->return = $decomp .$boucle->return; |
| 1066 | 1141 | $GLOBALS['debug_objets']['code'][$nom.$id] = $boucle->return; |
| 1067 | 1142 | } |
@@ -1081,8 +1156,9 @@ discard block |
||
| 1081 | 1156 | $GLOBALS['debug_objets']['squelette'][$nom] = $descr['squelette']; |
| 1082 | 1157 | $GLOBALS['debug_objets']['sourcefile'][$nom] = $sourcefile; |
| 1083 | 1158 | |
| 1084 | - if (!isset($GLOBALS['debug_objets']['principal'])) |
|
| 1085 | - $GLOBALS['debug_objets']['principal'] = $nom; |
|
| 1159 | + if (!isset($GLOBALS['debug_objets']['principal'])) { |
|
| 1160 | + $GLOBALS['debug_objets']['principal'] = $nom; |
|
| 1161 | + } |
|
| 1086 | 1162 | } |
| 1087 | 1163 | foreach ($boucles as $id => $boucle) { |
| 1088 | 1164 | $GLOBALS['debug_objets']['boucle'][$nom.$id] = $boucle; |
@@ -1093,21 +1169,26 @@ discard block |
||
| 1093 | 1169 | // et reperer si les doublons sont demandes |
| 1094 | 1170 | // pour un inclure ou une boucle document |
| 1095 | 1171 | // c'est utile a la fonction champs_traitements |
| 1096 | - if (!$trouver_table) |
|
| 1097 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1172 | + if (!$trouver_table) { |
|
| 1173 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1174 | + } |
|
| 1098 | 1175 | |
| 1099 | 1176 | foreach($boucles as $id => $boucle) { |
| 1100 | - if (!($type = $boucle->type_requete)) continue; |
|
| 1177 | + if (!($type = $boucle->type_requete)) { |
|
| 1178 | + continue; |
|
| 1179 | + } |
|
| 1101 | 1180 | if (!$descr['documents'] AND ( |
| 1102 | 1181 | (($type == 'documents') AND $boucle->doublons) OR |
| 1103 | 1182 | compile_inclure_doublons($boucle->avant) OR |
| 1104 | 1183 | compile_inclure_doublons($boucle->apres) OR |
| 1105 | 1184 | compile_inclure_doublons($boucle->milieu) OR |
| 1106 | - compile_inclure_doublons($boucle->altern))) |
|
| 1107 | - $descr['documents'] = true; |
|
| 1185 | + compile_inclure_doublons($boucle->altern))) { |
|
| 1186 | + $descr['documents'] = true; |
|
| 1187 | + } |
|
| 1108 | 1188 | if ($type != TYPE_RECURSIF) { |
| 1109 | - if (!$boucles[$id]->sql_serveur AND $connect) |
|
| 1110 | - $boucles[$id]->sql_serveur = $connect; |
|
| 1189 | + if (!$boucles[$id]->sql_serveur AND $connect) { |
|
| 1190 | + $boucles[$id]->sql_serveur = $connect; |
|
| 1191 | + } |
|
| 1111 | 1192 | |
| 1112 | 1193 | // chercher dans les iterateurs du repertoire iterateur/ |
| 1113 | 1194 | if ($g = charger_fonction( |
@@ -1141,18 +1222,20 @@ discard block |
||
| 1141 | 1222 | $boucles[$id]->descr = &$descr; |
| 1142 | 1223 | if ((!$boucles[$id]->jointures) |
| 1143 | 1224 | AND is_array($show['tables_jointures']) |
| 1144 | - AND count($x = $show['tables_jointures'])) |
|
| 1145 | - $boucles[$id]->jointures = $x; |
|
| 1225 | + AND count($x = $show['tables_jointures'])) { |
|
| 1226 | + $boucles[$id]->jointures = $x; |
|
| 1227 | + } |
|
| 1146 | 1228 | if ($boucles[$id]->jointures_explicites){ |
| 1147 | 1229 | $jointures = preg_split("/\s+/",$boucles[$id]->jointures_explicites); |
| 1148 | - while ($j=array_pop($jointures)) |
|
| 1149 | - array_unshift($boucles[$id]->jointures,$j); |
|
| 1230 | + while ($j=array_pop($jointures)) { |
|
| 1231 | + array_unshift($boucles[$id]->jointures,$j); |
|
| 1232 | + } |
|
| 1150 | 1233 | } |
| 1151 | 1234 | } else { |
| 1152 | 1235 | // Pas une erreur si la table est optionnelle |
| 1153 | - if ($boucles[$id]->table_optionnelle) |
|
| 1154 | - $boucles[$id]->type_requete = ''; |
|
| 1155 | - else { |
|
| 1236 | + if ($boucles[$id]->table_optionnelle) { |
|
| 1237 | + $boucles[$id]->type_requete = ''; |
|
| 1238 | + } else { |
|
| 1156 | 1239 | $boucles[$id]->type_requete = false; |
| 1157 | 1240 | $boucle = $boucles[$id]; |
| 1158 | 1241 | $x = (!$boucle->sql_serveur ? '' : |
@@ -1255,7 +1338,9 @@ discard block |
||
| 1255 | 1338 | _q($boucle->sql_serveur) . |
| 1256 | 1339 | ";" . |
| 1257 | 1340 | $f($id, $boucles); |
| 1258 | - } else $req = ("\n\treturn '';"); |
|
| 1341 | + } else { |
|
| 1342 | + $req = ("\n\treturn '';"); |
|
| 1343 | + } |
|
| 1259 | 1344 | |
| 1260 | 1345 | $boucles[$id]->return = |
| 1261 | 1346 | "\n\nfunction BOUCLE" . strtr($id,"-","_") . $nom . |
@@ -1266,7 +1351,9 @@ discard block |
||
| 1266 | 1351 | |
| 1267 | 1352 | // Au final, si le corps ou un critere au moins s'est mal compile |
| 1268 | 1353 | // retourner False, sinon inserer leur decompilation |
| 1269 | - if (is_bool($corps)) return false; |
|
| 1354 | + if (is_bool($corps)) { |
|
| 1355 | + return false; |
|
| 1356 | + } |
|
| 1270 | 1357 | |
| 1271 | 1358 | $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons=array(), $Numrows=array(), $SP=0) { |
| 1272 | 1359 | ' |
@@ -788,6 +788,9 @@ discard block |
||
| 788 | 788 | // Code specifique aux criteres {pagination}, {1,n} {n/m} etc |
| 789 | 789 | // |
| 790 | 790 | |
| 791 | +/** |
|
| 792 | + * @param string $mode |
|
| 793 | + */ |
|
| 791 | 794 | function calculer_parties(&$boucles, $id_boucle, $debut, $mode){ |
| 792 | 795 | $total_parties = $boucles[$id_boucle]->total_parties; |
| 793 | 796 | |
@@ -978,6 +981,9 @@ discard block |
||
| 978 | 981 | } |
| 979 | 982 | |
| 980 | 983 | // http://doc.spip.org/@critere_IN_cas |
| 984 | +/** |
|
| 985 | + * @param string $crit2 |
|
| 986 | + */ |
|
| 981 | 987 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col){ |
| 982 | 988 | static $num = array(); |
| 983 | 989 | $descr = $boucles[$idb]->descr; |
@@ -1473,6 +1479,9 @@ discard block |
||
| 1473 | 1479 | |
| 1474 | 1480 | |
| 1475 | 1481 | // http://doc.spip.org/@trouver_champ |
| 1482 | +/** |
|
| 1483 | + * @param string $champ |
|
| 1484 | + */ |
|
| 1476 | 1485 | function trouver_champ($champ, $where){ |
| 1477 | 1486 | if (!is_array($where)) |
| 1478 | 1487 | return preg_match($champ, $where); |
@@ -1680,6 +1689,10 @@ discard block |
||
| 1680 | 1689 | } |
| 1681 | 1690 | |
| 1682 | 1691 | // http://doc.spip.org/@calculer_param_date |
| 1692 | +/** |
|
| 1693 | + * @param string $date_compare |
|
| 1694 | + * @param string $date_orig |
|
| 1695 | + */ |
|
| 1683 | 1696 | function calculer_param_date($date_compare, $date_orig){ |
| 1684 | 1697 | if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)){ |
| 1685 | 1698 | $init = "'\" . (\$x = $r[1]) . \"'"; |
@@ -45,15 +45,15 @@ discard block |
||
| 45 | 45 | * AST complété de la gestion du critère |
| 46 | 46 | **/ |
| 47 | 47 | function critere_racine_dist($idb, &$boucles, $crit){ |
| 48 | - global $exceptions_des_tables; |
|
| 49 | - $not = $crit->not; |
|
| 50 | - $boucle = &$boucles[$idb]; |
|
| 51 | - $id_parent = isset($exceptions_des_tables[$boucle->id_table]['id_parent']) ? |
|
| 52 | - $exceptions_des_tables[$boucle->id_table]['id_parent'] : |
|
| 53 | - 'id_parent'; |
|
| 54 | - |
|
| 55 | - $c = array("'='", "'$boucle->id_table."."$id_parent'", 0); |
|
| 56 | - $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
|
| 48 | + global $exceptions_des_tables; |
|
| 49 | + $not = $crit->not; |
|
| 50 | + $boucle = &$boucles[$idb]; |
|
| 51 | + $id_parent = isset($exceptions_des_tables[$boucle->id_table]['id_parent']) ? |
|
| 52 | + $exceptions_des_tables[$boucle->id_table]['id_parent'] : |
|
| 53 | + 'id_parent'; |
|
| 54 | + |
|
| 55 | + $c = array("'='", "'$boucle->id_table."."$id_parent'", 0); |
|
| 56 | + $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | |
@@ -74,14 +74,14 @@ discard block |
||
| 74 | 74 | * AST complété de la gestion du critère |
| 75 | 75 | **/ |
| 76 | 76 | function critere_exclus_dist($idb, &$boucles, $crit){ |
| 77 | - $not = $crit->not; |
|
| 78 | - $boucle = &$boucles[$idb]; |
|
| 79 | - $id = $boucle->primary; |
|
| 80 | - |
|
| 81 | - if ($not OR !$id) |
|
| 82 | - return (array('zbug_critere_inconnu', array('critere' => $not.$crit->op))); |
|
| 83 | - $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 84 | - $boucle->where[] = array("'!='", "'$boucle->id_table."."$id'", $arg); |
|
| 77 | + $not = $crit->not; |
|
| 78 | + $boucle = &$boucles[$idb]; |
|
| 79 | + $id = $boucle->primary; |
|
| 80 | + |
|
| 81 | + if ($not OR !$id) |
|
| 82 | + return (array('zbug_critere_inconnu', array('critere' => $not.$crit->op))); |
|
| 83 | + $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 84 | + $boucle->where[] = array("'!='", "'$boucle->id_table."."$id'", $arg); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | |
@@ -105,72 +105,72 @@ discard block |
||
| 105 | 105 | * AST complété de la gestion du critère |
| 106 | 106 | **/ |
| 107 | 107 | function critere_doublons_dist($idb, &$boucles, $crit){ |
| 108 | - $boucle = &$boucles[$idb]; |
|
| 109 | - $primary = $boucle->primary; |
|
| 110 | - |
|
| 111 | - // la table nécessite une clé primaire, non composée |
|
| 112 | - if (!$primary OR strpos($primary, ',')){ |
|
| 113 | - return (array('zbug_doublon_sur_table_sans_cle_primaire')); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - $not = ($crit->not ? '' : 'NOT'); |
|
| 117 | - |
|
| 118 | - // le doublon s'applique sur un type de boucle (article) |
|
| 119 | - $nom = "'" . $boucle->type_requete. "'"; |
|
| 120 | - |
|
| 121 | - // compléter le nom avec un nom précisé {doublons nom} |
|
| 122 | - // on obtient $nom = "'article' . 'nom'" |
|
| 123 | - if (isset($crit->param[0])) { |
|
| 124 | - $nom .= "." . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 128 | - $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 129 | - $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 130 | - |
|
| 131 | - // on crée un sql_in avec la clé primaire de la table |
|
| 132 | - // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 133 | - // $doublons et son index, ici $nom |
|
| 134 | - |
|
| 135 | - // debut du code "sql_in('articles.id_article', " |
|
| 136 | - $debut_in = "sql_in('".$boucle->id_table.'.'.$primary."', "; |
|
| 137 | - // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 138 | - // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 139 | - $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons."[]= ")); |
|
| 140 | - |
|
| 141 | - // le debut complet du code des doublons |
|
| 142 | - $debut_doub = $debut_in . $debut_doub; |
|
| 143 | - |
|
| 144 | - // nom du doublon "('article' . 'nom')]" |
|
| 145 | - $fin_doub = "($nom)]"; |
|
| 146 | - |
|
| 147 | - // si on trouve un autre critère doublon, |
|
| 148 | - // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 149 | - foreach ($boucle->where as $k => $w) { |
|
| 150 | - if (strpos($w[0], $debut_doub)===0) { |
|
| 151 | - // fusionner le sql_in (du where) |
|
| 152 | - $boucle->where[$k][0] = $debut_doub . $fin_doub.' . '.substr($w[0], strlen($debut_in)); |
|
| 153 | - // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 154 | - $x = strpos($boucle->hash, $init_comment); |
|
| 155 | - $len = strlen($init_comment); |
|
| 156 | - $boucle->hash = |
|
| 157 | - substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 158 | - return; |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 163 | - $boucle->where[] = array($debut_doub . $fin_doub.", '".$not."')"); |
|
| 164 | - |
|
| 165 | - // déclarer le doublon s'il n'existe pas encore |
|
| 166 | - $boucle->hash .= $init_comment . $init_code; |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 170 | - # mais elle fait planter une boucle a 2 critere doublons: |
|
| 171 | - # {!doublons A}{doublons B} |
|
| 172 | - # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 173 | - # if ($crit->not) $boucle->doublons = ""; |
|
| 108 | + $boucle = &$boucles[$idb]; |
|
| 109 | + $primary = $boucle->primary; |
|
| 110 | + |
|
| 111 | + // la table nécessite une clé primaire, non composée |
|
| 112 | + if (!$primary OR strpos($primary, ',')){ |
|
| 113 | + return (array('zbug_doublon_sur_table_sans_cle_primaire')); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + $not = ($crit->not ? '' : 'NOT'); |
|
| 117 | + |
|
| 118 | + // le doublon s'applique sur un type de boucle (article) |
|
| 119 | + $nom = "'" . $boucle->type_requete. "'"; |
|
| 120 | + |
|
| 121 | + // compléter le nom avec un nom précisé {doublons nom} |
|
| 122 | + // on obtient $nom = "'article' . 'nom'" |
|
| 123 | + if (isset($crit->param[0])) { |
|
| 124 | + $nom .= "." . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 128 | + $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 129 | + $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 130 | + |
|
| 131 | + // on crée un sql_in avec la clé primaire de la table |
|
| 132 | + // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 133 | + // $doublons et son index, ici $nom |
|
| 134 | + |
|
| 135 | + // debut du code "sql_in('articles.id_article', " |
|
| 136 | + $debut_in = "sql_in('".$boucle->id_table.'.'.$primary."', "; |
|
| 137 | + // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 138 | + // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 139 | + $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons."[]= ")); |
|
| 140 | + |
|
| 141 | + // le debut complet du code des doublons |
|
| 142 | + $debut_doub = $debut_in . $debut_doub; |
|
| 143 | + |
|
| 144 | + // nom du doublon "('article' . 'nom')]" |
|
| 145 | + $fin_doub = "($nom)]"; |
|
| 146 | + |
|
| 147 | + // si on trouve un autre critère doublon, |
|
| 148 | + // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 149 | + foreach ($boucle->where as $k => $w) { |
|
| 150 | + if (strpos($w[0], $debut_doub)===0) { |
|
| 151 | + // fusionner le sql_in (du where) |
|
| 152 | + $boucle->where[$k][0] = $debut_doub . $fin_doub.' . '.substr($w[0], strlen($debut_in)); |
|
| 153 | + // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 154 | + $x = strpos($boucle->hash, $init_comment); |
|
| 155 | + $len = strlen($init_comment); |
|
| 156 | + $boucle->hash = |
|
| 157 | + substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 158 | + return; |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 163 | + $boucle->where[] = array($debut_doub . $fin_doub.", '".$not."')"); |
|
| 164 | + |
|
| 165 | + // déclarer le doublon s'il n'existe pas encore |
|
| 166 | + $boucle->hash .= $init_comment . $init_code; |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 170 | + # mais elle fait planter une boucle a 2 critere doublons: |
|
| 171 | + # {!doublons A}{doublons B} |
|
| 172 | + # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 173 | + # if ($crit->not) $boucle->doublons = ""; |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | |
@@ -195,26 +195,26 @@ discard block |
||
| 195 | 195 | * AST complété de la gestion du critère |
| 196 | 196 | **/ |
| 197 | 197 | function critere_lang_select_dist($idb, &$boucles, $crit){ |
| 198 | - if (!isset($crit->param[1][0]) OR !($param = $crit->param[1][0]->texte)) $param = 'oui'; |
|
| 199 | - if ($crit->not) $param = ($param=='oui') ? 'non' : 'oui'; |
|
| 200 | - $boucle = &$boucles[$idb]; |
|
| 201 | - $boucle->lang_select = $param; |
|
| 198 | + if (!isset($crit->param[1][0]) OR !($param = $crit->param[1][0]->texte)) $param = 'oui'; |
|
| 199 | + if ($crit->not) $param = ($param=='oui') ? 'non' : 'oui'; |
|
| 200 | + $boucle = &$boucles[$idb]; |
|
| 201 | + $boucle->lang_select = $param; |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | // {debut_xxx} |
| 205 | 205 | // http://www.spip.net/@debut_ |
| 206 | 206 | // http://doc.spip.org/@critere_debut_dist |
| 207 | 207 | function critere_debut_dist($idb, &$boucles, $crit){ |
| 208 | - list($un, $deux) = $crit->param; |
|
| 209 | - $un = $un[0]->texte; |
|
| 210 | - $deux = $deux[0]->texte; |
|
| 211 | - if ($deux){ |
|
| 212 | - $boucles[$idb]->limit = 'intval($Pile[0]["debut'. |
|
| 213 | - $un. |
|
| 214 | - '"]) . ",'. |
|
| 215 | - $deux. |
|
| 216 | - '"'; |
|
| 217 | - } else calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 208 | + list($un, $deux) = $crit->param; |
|
| 209 | + $un = $un[0]->texte; |
|
| 210 | + $deux = $deux[0]->texte; |
|
| 211 | + if ($deux){ |
|
| 212 | + $boucles[$idb]->limit = 'intval($Pile[0]["debut'. |
|
| 213 | + $un. |
|
| 214 | + '"]) . ",'. |
|
| 215 | + $deux. |
|
| 216 | + '"'; |
|
| 217 | + } else calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | // {pagination} |
@@ -225,46 +225,46 @@ discard block |
||
| 225 | 225 | // http://doc.spip.org/@critere_pagination_dist |
| 226 | 226 | function critere_pagination_dist($idb, &$boucles, $crit){ |
| 227 | 227 | |
| 228 | - $boucle = &$boucles[$idb]; |
|
| 229 | - // definition de la taille de la page |
|
| 230 | - $pas = !isset($crit->param[0][0]) ? "''" |
|
| 231 | - : calculer_liste(array($crit->param[0][0]), array(), $boucles, $boucle->id_parent); |
|
| 232 | - |
|
| 233 | - if (!preg_match(_CODE_QUOTE, $pas, $r)){ |
|
| 234 | - $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 235 | - } else { |
|
| 236 | - $r = intval($r[2]); |
|
| 237 | - $pas = strval($r ? $r : 10); |
|
| 238 | - } |
|
| 239 | - $type = !isset($crit->param[0][1]) ? "'$idb'" |
|
| 240 | - : calculer_liste(array($crit->param[0][1]), array(), $boucles, $boucle->id_parent); |
|
| 241 | - $debut = ($type[0]!=="'") ? "'debut'.$type" |
|
| 242 | - : ("'debut".substr($type, 1)); |
|
| 243 | - |
|
| 244 | - $boucle->modificateur['debut_nom'] = $type; |
|
| 245 | - $partie = |
|
| 246 | - // tester si le numero de page demande est de la forme '@yyy' |
|
| 247 | - 'isset($Pile[0]['.$debut.']) ? $Pile[0]['.$debut.'] : _request('.$debut.");\n" |
|
| 248 | - ."\tif(substr(\$debut_boucle,0,1)=='@'){\n" |
|
| 249 | - ."\t\t".'$debut_boucle = $Pile[0]['.$debut.'] = quete_debut_pagination(\''.$boucle->primary.'\',$Pile[0][\'@'.$boucle->primary.'\'] = substr($debut_boucle,1),'.$pas.',$iter);'."\n" |
|
| 250 | - ."\t\t".'$iter->seek(0);'."\n" |
|
| 251 | - ."\t}\n" |
|
| 252 | - ."\t".'$debut_boucle = intval($debut_boucle)'; |
|
| 253 | - |
|
| 254 | - $boucle->hash .= ' |
|
| 228 | + $boucle = &$boucles[$idb]; |
|
| 229 | + // definition de la taille de la page |
|
| 230 | + $pas = !isset($crit->param[0][0]) ? "''" |
|
| 231 | + : calculer_liste(array($crit->param[0][0]), array(), $boucles, $boucle->id_parent); |
|
| 232 | + |
|
| 233 | + if (!preg_match(_CODE_QUOTE, $pas, $r)){ |
|
| 234 | + $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 235 | + } else { |
|
| 236 | + $r = intval($r[2]); |
|
| 237 | + $pas = strval($r ? $r : 10); |
|
| 238 | + } |
|
| 239 | + $type = !isset($crit->param[0][1]) ? "'$idb'" |
|
| 240 | + : calculer_liste(array($crit->param[0][1]), array(), $boucles, $boucle->id_parent); |
|
| 241 | + $debut = ($type[0]!=="'") ? "'debut'.$type" |
|
| 242 | + : ("'debut".substr($type, 1)); |
|
| 243 | + |
|
| 244 | + $boucle->modificateur['debut_nom'] = $type; |
|
| 245 | + $partie = |
|
| 246 | + // tester si le numero de page demande est de la forme '@yyy' |
|
| 247 | + 'isset($Pile[0]['.$debut.']) ? $Pile[0]['.$debut.'] : _request('.$debut.");\n" |
|
| 248 | + ."\tif(substr(\$debut_boucle,0,1)=='@'){\n" |
|
| 249 | + ."\t\t".'$debut_boucle = $Pile[0]['.$debut.'] = quete_debut_pagination(\''.$boucle->primary.'\',$Pile[0][\'@'.$boucle->primary.'\'] = substr($debut_boucle,1),'.$pas.',$iter);'."\n" |
|
| 250 | + ."\t\t".'$iter->seek(0);'."\n" |
|
| 251 | + ."\t}\n" |
|
| 252 | + ."\t".'$debut_boucle = intval($debut_boucle)'; |
|
| 253 | + |
|
| 254 | + $boucle->hash .= ' |
|
| 255 | 255 | $command[\'pagination\'] = array((isset($Pile[0]['.$debut.']) ? $Pile[0]['.$debut.'] : null), ' . $pas . ');'; |
| 256 | 256 | |
| 257 | - $boucle->total_parties = $pas; |
|
| 258 | - calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 259 | - // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 260 | - // sauf si pas de primaire, ou si primaire composee |
|
| 261 | - // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 262 | - $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 263 | - if ($boucle->primary |
|
| 264 | - AND !preg_match('/[,\s]/', $boucle->primary) |
|
| 265 | - AND !in_array($t, $boucle->select) |
|
| 266 | - ) |
|
| 267 | - $boucle->select[] = $t; |
|
| 257 | + $boucle->total_parties = $pas; |
|
| 258 | + calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 259 | + // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 260 | + // sauf si pas de primaire, ou si primaire composee |
|
| 261 | + // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 262 | + $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 263 | + if ($boucle->primary |
|
| 264 | + AND !preg_match('/[,\s]/', $boucle->primary) |
|
| 265 | + AND !in_array($t, $boucle->select) |
|
| 266 | + ) |
|
| 267 | + $boucle->select[] = $t; |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | |
@@ -273,22 +273,22 @@ discard block |
||
| 273 | 273 | // http://doc.spip.org/@critere_recherche_dist |
| 274 | 274 | function critere_recherche_dist($idb, &$boucles, $crit){ |
| 275 | 275 | |
| 276 | - $boucle = &$boucles[$idb]; |
|
| 276 | + $boucle = &$boucles[$idb]; |
|
| 277 | 277 | |
| 278 | - if (!$boucle->primary OR strpos($boucle->primary, ',')){ |
|
| 279 | - erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire',array('critere'=>'recherche')), $boucle); |
|
| 280 | - return; |
|
| 281 | - } |
|
| 278 | + if (!$boucle->primary OR strpos($boucle->primary, ',')){ |
|
| 279 | + erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire',array('critere'=>'recherche')), $boucle); |
|
| 280 | + return; |
|
| 281 | + } |
|
| 282 | 282 | |
| 283 | - if (isset($crit->param[0])) |
|
| 284 | - $quoi = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 285 | - else |
|
| 286 | - $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 283 | + if (isset($crit->param[0])) |
|
| 284 | + $quoi = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 285 | + else |
|
| 286 | + $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 287 | 287 | |
| 288 | - $_modificateur = var_export($boucle->modificateur, true); |
|
| 289 | - $boucle->hash .= ' |
|
| 288 | + $_modificateur = var_export($boucle->modificateur, true); |
|
| 289 | + $boucle->hash .= ' |
|
| 290 | 290 | // RECHERCHE' |
| 291 | - .($crit->cond ? ' |
|
| 291 | + .($crit->cond ? ' |
|
| 292 | 292 | if (!strlen('.$quoi.')){ |
| 293 | 293 | list($rech_select, $rech_where) = array("0 as points",""); |
| 294 | 294 | } else' : '').' |
@@ -299,20 +299,20 @@ discard block |
||
| 299 | 299 | '; |
| 300 | 300 | |
| 301 | 301 | |
| 302 | - $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 303 | - if (!in_array($t, $boucles[$idb]->select)) |
|
| 304 | - $boucle->select[] = $t; # pour postgres, neuneu ici |
|
| 305 | - // jointure uniquement sur le serveur principal |
|
| 306 | - // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 307 | - if (!$boucle->sql_serveur){ |
|
| 308 | - $boucle->join['resultats'] = array("'".$boucle->id_table."'", "'id'", "'".$boucle->primary."'"); |
|
| 309 | - $boucle->from['resultats'] = 'spip_resultats'; |
|
| 310 | - } |
|
| 311 | - $boucle->select[] = '$rech_select'; |
|
| 312 | - //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 313 | - |
|
| 314 | - // et la recherche trouve |
|
| 315 | - $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 302 | + $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 303 | + if (!in_array($t, $boucles[$idb]->select)) |
|
| 304 | + $boucle->select[] = $t; # pour postgres, neuneu ici |
|
| 305 | + // jointure uniquement sur le serveur principal |
|
| 306 | + // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 307 | + if (!$boucle->sql_serveur){ |
|
| 308 | + $boucle->join['resultats'] = array("'".$boucle->id_table."'", "'id'", "'".$boucle->primary."'"); |
|
| 309 | + $boucle->from['resultats'] = 'spip_resultats'; |
|
| 310 | + } |
|
| 311 | + $boucle->select[] = '$rech_select'; |
|
| 312 | + //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 313 | + |
|
| 314 | + // et la recherche trouve |
|
| 315 | + $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | // {traduction} |
@@ -321,22 +321,22 @@ discard block |
||
| 321 | 321 | // OR id_article=id_article(precedent) |
| 322 | 322 | // http://doc.spip.org/@critere_traduction_dist |
| 323 | 323 | function critere_traduction_dist($idb, &$boucles, $crit){ |
| 324 | - $boucle = &$boucles[$idb]; |
|
| 325 | - $prim = $boucle->primary; |
|
| 326 | - $table = $boucle->id_table; |
|
| 327 | - $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 328 | - $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 329 | - $boucle->where[] = |
|
| 330 | - array("'OR'", |
|
| 331 | - array("'AND'", |
|
| 332 | - array("'='", "'$table.id_trad'", 0), |
|
| 333 | - array("'='", "'$table.$prim'", $dprim) |
|
| 334 | - ), |
|
| 335 | - array("'AND'", |
|
| 336 | - array("'>'", "'$table.id_trad'", 0), |
|
| 337 | - array("'='", "'$table.id_trad'", $arg) |
|
| 338 | - ) |
|
| 339 | - ); |
|
| 324 | + $boucle = &$boucles[$idb]; |
|
| 325 | + $prim = $boucle->primary; |
|
| 326 | + $table = $boucle->id_table; |
|
| 327 | + $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 328 | + $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 329 | + $boucle->where[] = |
|
| 330 | + array("'OR'", |
|
| 331 | + array("'AND'", |
|
| 332 | + array("'='", "'$table.id_trad'", 0), |
|
| 333 | + array("'='", "'$table.$prim'", $dprim) |
|
| 334 | + ), |
|
| 335 | + array("'AND'", |
|
| 336 | + array("'>'", "'$table.id_trad'", 0), |
|
| 337 | + array("'='", "'$table.id_trad'", $arg) |
|
| 338 | + ) |
|
| 339 | + ); |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | // {origine_traduction} |
@@ -344,38 +344,38 @@ discard block |
||
| 344 | 344 | // http://www.spip.net/@origine_traduction |
| 345 | 345 | // http://doc.spip.org/@critere_origine_traduction_dist |
| 346 | 346 | function critere_origine_traduction_dist($idb, &$boucles, $crit){ |
| 347 | - $boucle = &$boucles[$idb]; |
|
| 348 | - $prim = $boucle->primary; |
|
| 349 | - $table = $boucle->id_table; |
|
| 350 | - |
|
| 351 | - $c = |
|
| 352 | - array("'OR'", |
|
| 353 | - array("'='", "'$table."."id_trad'", "'$table.$prim'"), |
|
| 354 | - array("'='", "'$table.id_trad'", "'0'") |
|
| 355 | - ); |
|
| 356 | - $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
|
| 347 | + $boucle = &$boucles[$idb]; |
|
| 348 | + $prim = $boucle->primary; |
|
| 349 | + $table = $boucle->id_table; |
|
| 350 | + |
|
| 351 | + $c = |
|
| 352 | + array("'OR'", |
|
| 353 | + array("'='", "'$table."."id_trad'", "'$table.$prim'"), |
|
| 354 | + array("'='", "'$table.id_trad'", "'0'") |
|
| 355 | + ); |
|
| 356 | + $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | // {meme_parent} |
| 360 | 360 | // http://www.spip.net/@meme_parent |
| 361 | 361 | // http://doc.spip.org/@critere_meme_parent_dist |
| 362 | 362 | function critere_meme_parent_dist($idb, &$boucles, $crit){ |
| 363 | - global $exceptions_des_tables; |
|
| 364 | - $boucle = &$boucles[$idb]; |
|
| 365 | - $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 366 | - $id_parent = isset($exceptions_des_tables[$boucle->id_table]['id_parent']) ? |
|
| 367 | - $exceptions_des_tables[$boucle->id_table]['id_parent'] : |
|
| 368 | - 'id_parent'; |
|
| 369 | - $mparent = $boucle->id_table.'.'.$id_parent; |
|
| 370 | - |
|
| 371 | - if ($boucle->type_requete=='rubriques' OR isset($exceptions_des_tables[$boucle->id_table]['id_parent'])){ |
|
| 372 | - $boucle->where[] = array("'='", "'$mparent'", $arg); |
|
| 373 | - |
|
| 374 | - } |
|
| 375 | - // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 376 | - else { |
|
| 377 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op.' '.$boucle->type_requete))); |
|
| 378 | - } |
|
| 363 | + global $exceptions_des_tables; |
|
| 364 | + $boucle = &$boucles[$idb]; |
|
| 365 | + $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 366 | + $id_parent = isset($exceptions_des_tables[$boucle->id_table]['id_parent']) ? |
|
| 367 | + $exceptions_des_tables[$boucle->id_table]['id_parent'] : |
|
| 368 | + 'id_parent'; |
|
| 369 | + $mparent = $boucle->id_table.'.'.$id_parent; |
|
| 370 | + |
|
| 371 | + if ($boucle->type_requete=='rubriques' OR isset($exceptions_des_tables[$boucle->id_table]['id_parent'])){ |
|
| 372 | + $boucle->where[] = array("'='", "'$mparent'", $arg); |
|
| 373 | + |
|
| 374 | + } |
|
| 375 | + // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 376 | + else { |
|
| 377 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op.' '.$boucle->type_requete))); |
|
| 378 | + } |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | |
@@ -400,249 +400,249 @@ discard block |
||
| 400 | 400 | **/ |
| 401 | 401 | function critere_branche_dist($idb, &$boucles, $crit){ |
| 402 | 402 | |
| 403 | - $not = $crit->not; |
|
| 404 | - $boucle = &$boucles[$idb]; |
|
| 405 | - $arg = calculer_argument_precedent($idb, 'id_rubrique', $boucles); |
|
| 406 | - |
|
| 407 | - //Trouver une jointure |
|
| 408 | - $champ = "id_rubrique"; |
|
| 409 | - $desc = $boucle->show; |
|
| 410 | - //Seulement si necessaire |
|
| 411 | - if (!array_key_exists($champ, $desc['field'])){ |
|
| 412 | - $cle = trouver_jointure_champ($champ, $boucle); |
|
| 413 | - $trouver_table = charger_fonction("trouver_table", "base"); |
|
| 414 | - $desc = $trouver_table($boucle->from[$cle]); |
|
| 415 | - if (count(trouver_champs_decomposes($champ, $desc))>1){ |
|
| 416 | - $decompose = decompose_champ_id_objet($champ); |
|
| 417 | - $champ = array_shift($decompose); |
|
| 418 | - $boucle->where[] = array("'='", _q($cle.".".reset($decompose)), '"'.sql_quote(end($decompose)).'"'); |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - else $cle = $boucle->id_table; |
|
| 422 | - |
|
| 423 | - $c = "sql_in('$cle".".$champ', calcul_branche_in($arg)" |
|
| 424 | - .($not ? ", 'NOT'" : '').")"; |
|
| 425 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 426 | - ("($arg ? $c : ".($not ? "'0=1'" : "'1=1'").')'); |
|
| 403 | + $not = $crit->not; |
|
| 404 | + $boucle = &$boucles[$idb]; |
|
| 405 | + $arg = calculer_argument_precedent($idb, 'id_rubrique', $boucles); |
|
| 406 | + |
|
| 407 | + //Trouver une jointure |
|
| 408 | + $champ = "id_rubrique"; |
|
| 409 | + $desc = $boucle->show; |
|
| 410 | + //Seulement si necessaire |
|
| 411 | + if (!array_key_exists($champ, $desc['field'])){ |
|
| 412 | + $cle = trouver_jointure_champ($champ, $boucle); |
|
| 413 | + $trouver_table = charger_fonction("trouver_table", "base"); |
|
| 414 | + $desc = $trouver_table($boucle->from[$cle]); |
|
| 415 | + if (count(trouver_champs_decomposes($champ, $desc))>1){ |
|
| 416 | + $decompose = decompose_champ_id_objet($champ); |
|
| 417 | + $champ = array_shift($decompose); |
|
| 418 | + $boucle->where[] = array("'='", _q($cle.".".reset($decompose)), '"'.sql_quote(end($decompose)).'"'); |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + else $cle = $boucle->id_table; |
|
| 422 | + |
|
| 423 | + $c = "sql_in('$cle".".$champ', calcul_branche_in($arg)" |
|
| 424 | + .($not ? ", 'NOT'" : '').")"; |
|
| 425 | + $boucle->where[] = !$crit->cond ? $c : |
|
| 426 | + ("($arg ? $c : ".($not ? "'0=1'" : "'1=1'").')'); |
|
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | // {logo} liste les objets qui ont un logo |
| 430 | 430 | // http://doc.spip.org/@critere_logo_dist |
| 431 | 431 | function critere_logo_dist($idb, &$boucles, $crit){ |
| 432 | 432 | |
| 433 | - $not = $crit->not; |
|
| 434 | - $boucle = &$boucles[$idb]; |
|
| 433 | + $not = $crit->not; |
|
| 434 | + $boucle = &$boucles[$idb]; |
|
| 435 | 435 | |
| 436 | - $c = "sql_in('". |
|
| 437 | - $boucle->id_table.'.'.$boucle->primary |
|
| 438 | - ."', lister_objets_avec_logos('".$boucle->primary."'), '')"; |
|
| 436 | + $c = "sql_in('". |
|
| 437 | + $boucle->id_table.'.'.$boucle->primary |
|
| 438 | + ."', lister_objets_avec_logos('".$boucle->primary."'), '')"; |
|
| 439 | 439 | |
| 440 | - if ($crit->cond) $c = "($arg ? $c : 1)"; |
|
| 440 | + if ($crit->cond) $c = "($arg ? $c : 1)"; |
|
| 441 | 441 | |
| 442 | - if ($not) |
|
| 443 | - $boucle->where[] = array("'NOT'", $c); |
|
| 444 | - else |
|
| 445 | - $boucle->where[] = $c; |
|
| 442 | + if ($not) |
|
| 443 | + $boucle->where[] = array("'NOT'", $c); |
|
| 444 | + else |
|
| 445 | + $boucle->where[] = $c; |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | // c'est la commande SQL "GROUP BY" |
| 449 | 449 | // par exemple <boucle(articles){fusion lang}> |
| 450 | 450 | // http://doc.spip.org/@critere_fusion_dist |
| 451 | 451 | function critere_fusion_dist($idb, &$boucles, $crit){ |
| 452 | - if ($t = isset($crit->param[0])){ |
|
| 453 | - $t = $crit->param[0]; |
|
| 454 | - if ($t[0]->type=='texte'){ |
|
| 455 | - $t = $t[0]->texte; |
|
| 456 | - if (preg_match("/^(.*)\.(.*)$/", $t, $r)){ |
|
| 457 | - $t = table_objet_sql($r[1]); |
|
| 458 | - $t = array_search($t, $boucles[$idb]->from); |
|
| 459 | - if ($t) $t .= '.'.$r[2]; |
|
| 460 | - } |
|
| 461 | - } else { |
|
| 462 | - $t = '".' |
|
| 463 | - .calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 464 | - .'."'; |
|
| 465 | - } |
|
| 466 | - } |
|
| 467 | - if ($t){ |
|
| 468 | - $boucles[$idb]->group[] = $t; |
|
| 469 | - if (!in_array($t, $boucles[$idb]->select)) |
|
| 470 | - $boucles[$idb]->select[] = $t; |
|
| 471 | - } else |
|
| 472 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op.' ?'))); |
|
| 452 | + if ($t = isset($crit->param[0])){ |
|
| 453 | + $t = $crit->param[0]; |
|
| 454 | + if ($t[0]->type=='texte'){ |
|
| 455 | + $t = $t[0]->texte; |
|
| 456 | + if (preg_match("/^(.*)\.(.*)$/", $t, $r)){ |
|
| 457 | + $t = table_objet_sql($r[1]); |
|
| 458 | + $t = array_search($t, $boucles[$idb]->from); |
|
| 459 | + if ($t) $t .= '.'.$r[2]; |
|
| 460 | + } |
|
| 461 | + } else { |
|
| 462 | + $t = '".' |
|
| 463 | + .calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 464 | + .'."'; |
|
| 465 | + } |
|
| 466 | + } |
|
| 467 | + if ($t){ |
|
| 468 | + $boucles[$idb]->group[] = $t; |
|
| 469 | + if (!in_array($t, $boucles[$idb]->select)) |
|
| 470 | + $boucles[$idb]->select[] = $t; |
|
| 471 | + } else |
|
| 472 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op.' ?'))); |
|
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | // c'est la commande SQL "COLLATE" |
| 476 | 476 | // qui peut etre appliquee sur les order by, group by, where like ... |
| 477 | 477 | // http://doc.spip.org/@critere_collecte_dist |
| 478 | 478 | function critere_collecte_dist($idb, &$boucles, $crit){ |
| 479 | - if (isset($crit->param[0])){ |
|
| 480 | - $_coll = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 481 | - $boucle = $boucles[$idb]; |
|
| 482 | - $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 483 | - $n = count($boucle->order); |
|
| 484 | - if ($n && (strpos($boucle->order[$n-1], 'COLLATE')===false)) |
|
| 485 | - $boucle->order[$n-1] .= " . ".$boucle->modificateur['collate']; |
|
| 486 | - } else |
|
| 487 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op." ".count($boucles[$idb]->order)))); |
|
| 479 | + if (isset($crit->param[0])){ |
|
| 480 | + $_coll = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 481 | + $boucle = $boucles[$idb]; |
|
| 482 | + $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 483 | + $n = count($boucle->order); |
|
| 484 | + if ($n && (strpos($boucle->order[$n-1], 'COLLATE')===false)) |
|
| 485 | + $boucle->order[$n-1] .= " . ".$boucle->modificateur['collate']; |
|
| 486 | + } else |
|
| 487 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op." ".count($boucles[$idb]->order)))); |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | // http://doc.spip.org/@calculer_critere_arg_dynamique |
| 491 | 491 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = ''){ |
| 492 | - $boucle = $boucles[$idb]; |
|
| 493 | - $alt = "('".$boucle->id_table.'.\' . $x'.$suffix.')'; |
|
| 494 | - $var = '$champs_'.$idb; |
|
| 495 | - $desc = (strpos($boucle->in, "static $var =")!==false); |
|
| 496 | - if (!$desc){ |
|
| 497 | - $desc = $boucle->show['field']; |
|
| 498 | - $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 499 | - $boucles[$idb]->in .= "\n\tstatic $var = array(".$desc.");"; |
|
| 500 | - } |
|
| 501 | - if ($desc) $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 502 | - $arg = calculer_liste($crit, array(), $boucles, $boucle->id_parent); |
|
| 503 | - return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 492 | + $boucle = $boucles[$idb]; |
|
| 493 | + $alt = "('".$boucle->id_table.'.\' . $x'.$suffix.')'; |
|
| 494 | + $var = '$champs_'.$idb; |
|
| 495 | + $desc = (strpos($boucle->in, "static $var =")!==false); |
|
| 496 | + if (!$desc){ |
|
| 497 | + $desc = $boucle->show['field']; |
|
| 498 | + $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 499 | + $boucles[$idb]->in .= "\n\tstatic $var = array(".$desc.");"; |
|
| 500 | + } |
|
| 501 | + if ($desc) $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 502 | + $arg = calculer_liste($crit, array(), $boucles, $boucle->id_parent); |
|
| 503 | + return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | // Tri : {par xxxx} |
| 507 | 507 | // http://www.spip.net/@par |
| 508 | 508 | // http://doc.spip.org/@critere_par_dist |
| 509 | 509 | function critere_par_dist($idb, &$boucles, $crit){ |
| 510 | - return critere_parinverse($idb, $boucles, $crit); |
|
| 510 | + return critere_parinverse($idb, $boucles, $crit); |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | // http://doc.spip.org/@critere_parinverse |
| 514 | 514 | function critere_parinverse($idb, &$boucles, $crit, $sens = ''){ |
| 515 | - global $exceptions_des_jointures; |
|
| 516 | - $boucle = &$boucles[$idb]; |
|
| 517 | - if ($crit->not) $sens = $sens ? "" : " . ' DESC'"; |
|
| 518 | - $collecte = (isset($boucle->modificateur['collecte'])) ? " . ".$boucle->modificateur['collecte'] : ""; |
|
| 519 | - |
|
| 520 | - foreach ($crit->param as $tri){ |
|
| 521 | - |
|
| 522 | - $order = $fct = ""; // en cas de fonction SQL |
|
| 523 | - // tris specifies dynamiquement |
|
| 524 | - if ($tri[0]->type!='texte'){ |
|
| 525 | - // calculer le order dynamique qui verifie les champs |
|
| 526 | - $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 527 | - // et si ce n'est fait, ajouter un champ 'hasard' |
|
| 528 | - // pour supporter 'hasard' comme tri dynamique |
|
| 529 | - $par = "rand()"; |
|
| 530 | - $parha = $par." AS hasard"; |
|
| 531 | - if (!in_array($parha, $boucle->select)) |
|
| 532 | - $boucle->select[] = $parha; |
|
| 533 | - } else { |
|
| 534 | - $par = array_shift($tri); |
|
| 535 | - $par = $par->texte; |
|
| 536 | - // par multi champ |
|
| 537 | - if (preg_match(",^multi[\s]*(.*)$,", $par, $m)){ |
|
| 538 | - $champ = trim($m[1]); |
|
| 539 | - // par multi L1.champ |
|
| 540 | - if (strpos($champ, '.')) { |
|
| 541 | - $cle = ''; |
|
| 542 | - // par multi champ (champ sur une autre table) |
|
| 543 | - } elseif (!array_key_exists($champ, $boucle->show['field'])){ |
|
| 544 | - $cle = trouver_jointure_champ($champ, $boucle); |
|
| 545 | - // par multi champ (champ dans la table en cours) |
|
| 546 | - } else { |
|
| 547 | - $cle = $boucle->id_table; |
|
| 548 | - } |
|
| 549 | - if ($cle) { $cle .= '.'; } |
|
| 550 | - $texte = $cle.$champ; |
|
| 551 | - $boucle->select[] = "\".sql_multi('".$texte."', \$GLOBALS['spip_lang']).\""; |
|
| 552 | - $order = "'multi'"; |
|
| 553 | - // par num champ(, suite) |
|
| 554 | - } else if (preg_match(",^num (.*)$,m", $par, $m)) { |
|
| 555 | - $champ = trim($m[1]); |
|
| 556 | - // par num L1.champ |
|
| 557 | - if (strpos($champ, '.')) { |
|
| 558 | - $cle = ''; |
|
| 559 | - // par num champ (champ sur une autre table) |
|
| 560 | - } elseif (!array_key_exists($champ, $boucle->show['field'])){ |
|
| 561 | - $cle = trouver_jointure_champ($champ, $boucle); |
|
| 562 | - // par num champ (champ dans la table en cours) |
|
| 563 | - } else { |
|
| 564 | - $cle = $boucle->id_table; |
|
| 565 | - } |
|
| 566 | - if ($cle) { $cle .= '.'; } |
|
| 567 | - $texte = '0+'. $cle . $champ; |
|
| 568 | - $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
|
| 569 | - if ($suite!=="''") |
|
| 570 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')"." . \""; |
|
| 571 | - $as = 'num'.($boucle->order ? count($boucle->order) : ""); |
|
| 572 | - $boucle->select[] = $texte." AS $as"; |
|
| 573 | - $order = "'$as'"; |
|
| 574 | - } else { |
|
| 575 | - if (!preg_match(",^".CHAMP_SQL_PLUS_FONC.'$,is', $par, $match)){ |
|
| 576 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op." $par"))); |
|
| 577 | - } else { |
|
| 578 | - if (count($match)>2){ |
|
| 579 | - $par = substr($match[2], 1, -1); |
|
| 580 | - $fct = $match[1]; |
|
| 581 | - } |
|
| 582 | - // par hasard |
|
| 583 | - if ($par=='hasard'){ |
|
| 584 | - $par = "rand()"; |
|
| 585 | - $boucle->select[] = $par." AS alea"; |
|
| 586 | - $order = "'alea'"; |
|
| 587 | - } |
|
| 588 | - // par titre_mot ou type_mot voire d'autres |
|
| 589 | - else if (isset($exceptions_des_jointures[$par])){ |
|
| 590 | - list($table, $champ) = $exceptions_des_jointures[$par]; |
|
| 591 | - $order = critere_par_joint($table, $champ, $boucle, $idb); |
|
| 592 | - if (!$order) |
|
| 593 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op." $par"))); |
|
| 594 | - } |
|
| 595 | - else if ($par=='date' |
|
| 596 | - AND $desc = $boucle->show |
|
| 597 | - AND $desc['date'] |
|
| 598 | - ){ |
|
| 599 | - $m = $desc['date']; |
|
| 600 | - $order = "'".$boucle->id_table.".".$m."'"; |
|
| 601 | - } |
|
| 602 | - // par champ. Verifier qu'ils sont presents. |
|
| 603 | - elseif (preg_match("/^([^,]*)\.(.*)$/", $par, $r)) { |
|
| 604 | - // cas du tri sur champ de jointure explicite |
|
| 605 | - $t = array_search($r[1], $boucle->from); |
|
| 606 | - if (!$t){ |
|
| 607 | - $t = trouver_jointure_champ($r[2], $boucle, array($r[1])); |
|
| 608 | - } |
|
| 609 | - if (!$t){ |
|
| 610 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op." $par"))); |
|
| 611 | - } else $order = "'".$t.'.'.$r[2]."'"; |
|
| 612 | - } else { |
|
| 613 | - $desc = $boucle->show; |
|
| 614 | - if ($desc['field'][$par]) |
|
| 615 | - $par = $boucle->id_table.".".$par; |
|
| 616 | - // sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 617 | - $order = "'$par'"; |
|
| 618 | - } |
|
| 619 | - } |
|
| 620 | - } |
|
| 621 | - } |
|
| 622 | - if (preg_match('/^\'([^"]*)\'$/', $order, $m)){ |
|
| 623 | - $t = $m[1]; |
|
| 624 | - if (strpos($t, '.') AND !in_array($t, $boucle->select)){ |
|
| 625 | - $boucle->select[] = $t; |
|
| 626 | - } |
|
| 627 | - } else $sens = ''; |
|
| 628 | - |
|
| 629 | - if ($fct){ |
|
| 630 | - if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) |
|
| 631 | - $order = "'$fct(".$r[1].")'"; |
|
| 632 | - else $order = "'$fct(' . $order . ')'"; |
|
| 633 | - } |
|
| 634 | - $t = $order.$collecte.$sens; |
|
| 635 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) |
|
| 636 | - $t = $r[1].$r[2]; |
|
| 637 | - $boucle->order[] = $t; |
|
| 638 | - } |
|
| 515 | + global $exceptions_des_jointures; |
|
| 516 | + $boucle = &$boucles[$idb]; |
|
| 517 | + if ($crit->not) $sens = $sens ? "" : " . ' DESC'"; |
|
| 518 | + $collecte = (isset($boucle->modificateur['collecte'])) ? " . ".$boucle->modificateur['collecte'] : ""; |
|
| 519 | + |
|
| 520 | + foreach ($crit->param as $tri){ |
|
| 521 | + |
|
| 522 | + $order = $fct = ""; // en cas de fonction SQL |
|
| 523 | + // tris specifies dynamiquement |
|
| 524 | + if ($tri[0]->type!='texte'){ |
|
| 525 | + // calculer le order dynamique qui verifie les champs |
|
| 526 | + $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 527 | + // et si ce n'est fait, ajouter un champ 'hasard' |
|
| 528 | + // pour supporter 'hasard' comme tri dynamique |
|
| 529 | + $par = "rand()"; |
|
| 530 | + $parha = $par." AS hasard"; |
|
| 531 | + if (!in_array($parha, $boucle->select)) |
|
| 532 | + $boucle->select[] = $parha; |
|
| 533 | + } else { |
|
| 534 | + $par = array_shift($tri); |
|
| 535 | + $par = $par->texte; |
|
| 536 | + // par multi champ |
|
| 537 | + if (preg_match(",^multi[\s]*(.*)$,", $par, $m)){ |
|
| 538 | + $champ = trim($m[1]); |
|
| 539 | + // par multi L1.champ |
|
| 540 | + if (strpos($champ, '.')) { |
|
| 541 | + $cle = ''; |
|
| 542 | + // par multi champ (champ sur une autre table) |
|
| 543 | + } elseif (!array_key_exists($champ, $boucle->show['field'])){ |
|
| 544 | + $cle = trouver_jointure_champ($champ, $boucle); |
|
| 545 | + // par multi champ (champ dans la table en cours) |
|
| 546 | + } else { |
|
| 547 | + $cle = $boucle->id_table; |
|
| 548 | + } |
|
| 549 | + if ($cle) { $cle .= '.'; } |
|
| 550 | + $texte = $cle.$champ; |
|
| 551 | + $boucle->select[] = "\".sql_multi('".$texte."', \$GLOBALS['spip_lang']).\""; |
|
| 552 | + $order = "'multi'"; |
|
| 553 | + // par num champ(, suite) |
|
| 554 | + } else if (preg_match(",^num (.*)$,m", $par, $m)) { |
|
| 555 | + $champ = trim($m[1]); |
|
| 556 | + // par num L1.champ |
|
| 557 | + if (strpos($champ, '.')) { |
|
| 558 | + $cle = ''; |
|
| 559 | + // par num champ (champ sur une autre table) |
|
| 560 | + } elseif (!array_key_exists($champ, $boucle->show['field'])){ |
|
| 561 | + $cle = trouver_jointure_champ($champ, $boucle); |
|
| 562 | + // par num champ (champ dans la table en cours) |
|
| 563 | + } else { |
|
| 564 | + $cle = $boucle->id_table; |
|
| 565 | + } |
|
| 566 | + if ($cle) { $cle .= '.'; } |
|
| 567 | + $texte = '0+'. $cle . $champ; |
|
| 568 | + $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
|
| 569 | + if ($suite!=="''") |
|
| 570 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')"." . \""; |
|
| 571 | + $as = 'num'.($boucle->order ? count($boucle->order) : ""); |
|
| 572 | + $boucle->select[] = $texte." AS $as"; |
|
| 573 | + $order = "'$as'"; |
|
| 574 | + } else { |
|
| 575 | + if (!preg_match(",^".CHAMP_SQL_PLUS_FONC.'$,is', $par, $match)){ |
|
| 576 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op." $par"))); |
|
| 577 | + } else { |
|
| 578 | + if (count($match)>2){ |
|
| 579 | + $par = substr($match[2], 1, -1); |
|
| 580 | + $fct = $match[1]; |
|
| 581 | + } |
|
| 582 | + // par hasard |
|
| 583 | + if ($par=='hasard'){ |
|
| 584 | + $par = "rand()"; |
|
| 585 | + $boucle->select[] = $par." AS alea"; |
|
| 586 | + $order = "'alea'"; |
|
| 587 | + } |
|
| 588 | + // par titre_mot ou type_mot voire d'autres |
|
| 589 | + else if (isset($exceptions_des_jointures[$par])){ |
|
| 590 | + list($table, $champ) = $exceptions_des_jointures[$par]; |
|
| 591 | + $order = critere_par_joint($table, $champ, $boucle, $idb); |
|
| 592 | + if (!$order) |
|
| 593 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op." $par"))); |
|
| 594 | + } |
|
| 595 | + else if ($par=='date' |
|
| 596 | + AND $desc = $boucle->show |
|
| 597 | + AND $desc['date'] |
|
| 598 | + ){ |
|
| 599 | + $m = $desc['date']; |
|
| 600 | + $order = "'".$boucle->id_table.".".$m."'"; |
|
| 601 | + } |
|
| 602 | + // par champ. Verifier qu'ils sont presents. |
|
| 603 | + elseif (preg_match("/^([^,]*)\.(.*)$/", $par, $r)) { |
|
| 604 | + // cas du tri sur champ de jointure explicite |
|
| 605 | + $t = array_search($r[1], $boucle->from); |
|
| 606 | + if (!$t){ |
|
| 607 | + $t = trouver_jointure_champ($r[2], $boucle, array($r[1])); |
|
| 608 | + } |
|
| 609 | + if (!$t){ |
|
| 610 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op." $par"))); |
|
| 611 | + } else $order = "'".$t.'.'.$r[2]."'"; |
|
| 612 | + } else { |
|
| 613 | + $desc = $boucle->show; |
|
| 614 | + if ($desc['field'][$par]) |
|
| 615 | + $par = $boucle->id_table.".".$par; |
|
| 616 | + // sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 617 | + $order = "'$par'"; |
|
| 618 | + } |
|
| 619 | + } |
|
| 620 | + } |
|
| 621 | + } |
|
| 622 | + if (preg_match('/^\'([^"]*)\'$/', $order, $m)){ |
|
| 623 | + $t = $m[1]; |
|
| 624 | + if (strpos($t, '.') AND !in_array($t, $boucle->select)){ |
|
| 625 | + $boucle->select[] = $t; |
|
| 626 | + } |
|
| 627 | + } else $sens = ''; |
|
| 628 | + |
|
| 629 | + if ($fct){ |
|
| 630 | + if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) |
|
| 631 | + $order = "'$fct(".$r[1].")'"; |
|
| 632 | + else $order = "'$fct(' . $order . ')'"; |
|
| 633 | + } |
|
| 634 | + $t = $order.$collecte.$sens; |
|
| 635 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) |
|
| 636 | + $t = $r[1].$r[2]; |
|
| 637 | + $boucle->order[] = $t; |
|
| 638 | + } |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | // http://doc.spip.org/@critere_par_joint |
| 642 | 642 | function critere_par_joint($table, $champ, &$boucle, $idb){ |
| 643 | - $t = array_search($table, $boucle->from); |
|
| 644 | - if (!$t) $t = trouver_jointure_champ($champ, $boucle); |
|
| 645 | - return !$t ? '' : ("'".$t.'.'.$champ."'"); |
|
| 643 | + $t = array_search($table, $boucle->from); |
|
| 644 | + if (!$t) $t = trouver_jointure_champ($champ, $boucle); |
|
| 645 | + return !$t ? '' : ("'".$t.'.'.$champ."'"); |
|
| 646 | 646 | } |
| 647 | 647 | |
| 648 | 648 | // {inverse} |
@@ -651,137 +651,137 @@ discard block |
||
| 651 | 651 | // http://doc.spip.org/@critere_inverse_dist |
| 652 | 652 | function critere_inverse_dist($idb, &$boucles, $crit){ |
| 653 | 653 | |
| 654 | - $boucle = &$boucles[$idb]; |
|
| 655 | - // Classement par ordre inverse |
|
| 656 | - if ($crit->not) |
|
| 657 | - critere_parinverse($idb, $boucles, $crit); |
|
| 658 | - else |
|
| 659 | - { |
|
| 660 | - $order = "' DESC'"; |
|
| 661 | - // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 662 | - if (isset($crit->param[0])){ |
|
| 663 | - $critere = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 664 | - $order = "(($critere)?' DESC':'')"; |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - $n = count($boucle->order); |
|
| 668 | - if (!$n){ |
|
| 669 | - if (isset($boucle->default_order[0])) |
|
| 670 | - $boucle->default_order[0] .= ' . " DESC"'; |
|
| 671 | - else |
|
| 672 | - $boucle->default_order[] = ' DESC'; |
|
| 673 | - } else { |
|
| 674 | - $t = $boucle->order[$n-1]." . $order"; |
|
| 675 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) |
|
| 676 | - $t = $r[1].$r[2]; |
|
| 677 | - $boucle->order[$n-1] = $t; |
|
| 678 | - } |
|
| 679 | - } |
|
| 654 | + $boucle = &$boucles[$idb]; |
|
| 655 | + // Classement par ordre inverse |
|
| 656 | + if ($crit->not) |
|
| 657 | + critere_parinverse($idb, $boucles, $crit); |
|
| 658 | + else |
|
| 659 | + { |
|
| 660 | + $order = "' DESC'"; |
|
| 661 | + // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 662 | + if (isset($crit->param[0])){ |
|
| 663 | + $critere = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 664 | + $order = "(($critere)?' DESC':'')"; |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + $n = count($boucle->order); |
|
| 668 | + if (!$n){ |
|
| 669 | + if (isset($boucle->default_order[0])) |
|
| 670 | + $boucle->default_order[0] .= ' . " DESC"'; |
|
| 671 | + else |
|
| 672 | + $boucle->default_order[] = ' DESC'; |
|
| 673 | + } else { |
|
| 674 | + $t = $boucle->order[$n-1]." . $order"; |
|
| 675 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) |
|
| 676 | + $t = $r[1].$r[2]; |
|
| 677 | + $boucle->order[$n-1] = $t; |
|
| 678 | + } |
|
| 679 | + } |
|
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | // http://doc.spip.org/@critere_agenda_dist |
| 683 | 683 | function critere_agenda_dist($idb, &$boucles, $crit){ |
| 684 | - $params = $crit->param; |
|
| 685 | - |
|
| 686 | - if (count($params)<1) |
|
| 687 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op." ?"))); |
|
| 688 | - |
|
| 689 | - $parent = $boucles[$idb]->id_parent; |
|
| 690 | - |
|
| 691 | - // les valeurs $date et $type doivent etre connus a la compilation |
|
| 692 | - // autrement dit ne pas etre des champs |
|
| 693 | - |
|
| 694 | - $date = array_shift($params); |
|
| 695 | - $date = $date[0]->texte; |
|
| 696 | - |
|
| 697 | - $type = array_shift($params); |
|
| 698 | - $type = $type[0]->texte; |
|
| 699 | - |
|
| 700 | - $annee = $params ? array_shift($params) : ""; |
|
| 701 | - $annee = "\n".'sprintf("%04d", ($x = '. |
|
| 702 | - calculer_liste($annee, array(), $boucles, $parent). |
|
| 703 | - ') ? $x : date("Y"))'; |
|
| 704 | - |
|
| 705 | - $mois = $params ? array_shift($params) : ""; |
|
| 706 | - $mois = "\n".'sprintf("%02d", ($x = '. |
|
| 707 | - calculer_liste($mois, array(), $boucles, $parent). |
|
| 708 | - ') ? $x : date("m"))'; |
|
| 709 | - |
|
| 710 | - $jour = $params ? array_shift($params) : ""; |
|
| 711 | - $jour = "\n".'sprintf("%02d", ($x = '. |
|
| 712 | - calculer_liste($jour, array(), $boucles, $parent). |
|
| 713 | - ') ? $x : date("d"))'; |
|
| 714 | - |
|
| 715 | - $annee2 = $params ? array_shift($params) : ""; |
|
| 716 | - $annee2 = "\n".'sprintf("%04d", ($x = '. |
|
| 717 | - calculer_liste($annee2, array(), $boucles, $parent). |
|
| 718 | - ') ? $x : date("Y"))'; |
|
| 719 | - |
|
| 720 | - $mois2 = $params ? array_shift($params) : ""; |
|
| 721 | - $mois2 = "\n".'sprintf("%02d", ($x = '. |
|
| 722 | - calculer_liste($mois2, array(), $boucles, $parent). |
|
| 723 | - ') ? $x : date("m"))'; |
|
| 724 | - |
|
| 725 | - $jour2 = $params ? array_shift($params) : ""; |
|
| 726 | - $jour2 = "\n".'sprintf("%02d", ($x = '. |
|
| 727 | - calculer_liste($jour2, array(), $boucles, $parent). |
|
| 728 | - ') ? $x : date("d"))'; |
|
| 729 | - |
|
| 730 | - $boucle = &$boucles[$idb]; |
|
| 731 | - $date = $boucle->id_table.".$date"; |
|
| 732 | - |
|
| 733 | - $quote_end = ",'".$boucle->sql_serveur."','text'"; |
|
| 734 | - if ($type=='jour') |
|
| 735 | - $boucle->where[] = array("'='", "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 736 | - ("sql_quote($annee . $mois . $jour$quote_end)")); |
|
| 737 | - elseif ($type=='mois') |
|
| 738 | - $boucle->where[] = array("'='", "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 739 | - ("sql_quote($annee . $mois$quote_end)")); |
|
| 740 | - elseif ($type=='semaine') |
|
| 741 | - $boucle->where[] = array("'AND'", |
|
| 742 | - array("'>='", |
|
| 743 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 744 | - ("date_debut_semaine($annee, $mois, $jour)")), |
|
| 745 | - array("'<='", |
|
| 746 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 747 | - ("date_fin_semaine($annee, $mois, $jour)"))); |
|
| 748 | - elseif (count($crit->param)>2) |
|
| 749 | - $boucle->where[] = array("'AND'", |
|
| 750 | - array("'>='", |
|
| 751 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 752 | - ("sql_quote($annee . $mois . $jour$quote_end)")), |
|
| 753 | - array("'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)"))); |
|
| 754 | - // sinon on prend tout |
|
| 684 | + $params = $crit->param; |
|
| 685 | + |
|
| 686 | + if (count($params)<1) |
|
| 687 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op." ?"))); |
|
| 688 | + |
|
| 689 | + $parent = $boucles[$idb]->id_parent; |
|
| 690 | + |
|
| 691 | + // les valeurs $date et $type doivent etre connus a la compilation |
|
| 692 | + // autrement dit ne pas etre des champs |
|
| 693 | + |
|
| 694 | + $date = array_shift($params); |
|
| 695 | + $date = $date[0]->texte; |
|
| 696 | + |
|
| 697 | + $type = array_shift($params); |
|
| 698 | + $type = $type[0]->texte; |
|
| 699 | + |
|
| 700 | + $annee = $params ? array_shift($params) : ""; |
|
| 701 | + $annee = "\n".'sprintf("%04d", ($x = '. |
|
| 702 | + calculer_liste($annee, array(), $boucles, $parent). |
|
| 703 | + ') ? $x : date("Y"))'; |
|
| 704 | + |
|
| 705 | + $mois = $params ? array_shift($params) : ""; |
|
| 706 | + $mois = "\n".'sprintf("%02d", ($x = '. |
|
| 707 | + calculer_liste($mois, array(), $boucles, $parent). |
|
| 708 | + ') ? $x : date("m"))'; |
|
| 709 | + |
|
| 710 | + $jour = $params ? array_shift($params) : ""; |
|
| 711 | + $jour = "\n".'sprintf("%02d", ($x = '. |
|
| 712 | + calculer_liste($jour, array(), $boucles, $parent). |
|
| 713 | + ') ? $x : date("d"))'; |
|
| 714 | + |
|
| 715 | + $annee2 = $params ? array_shift($params) : ""; |
|
| 716 | + $annee2 = "\n".'sprintf("%04d", ($x = '. |
|
| 717 | + calculer_liste($annee2, array(), $boucles, $parent). |
|
| 718 | + ') ? $x : date("Y"))'; |
|
| 719 | + |
|
| 720 | + $mois2 = $params ? array_shift($params) : ""; |
|
| 721 | + $mois2 = "\n".'sprintf("%02d", ($x = '. |
|
| 722 | + calculer_liste($mois2, array(), $boucles, $parent). |
|
| 723 | + ') ? $x : date("m"))'; |
|
| 724 | + |
|
| 725 | + $jour2 = $params ? array_shift($params) : ""; |
|
| 726 | + $jour2 = "\n".'sprintf("%02d", ($x = '. |
|
| 727 | + calculer_liste($jour2, array(), $boucles, $parent). |
|
| 728 | + ') ? $x : date("d"))'; |
|
| 729 | + |
|
| 730 | + $boucle = &$boucles[$idb]; |
|
| 731 | + $date = $boucle->id_table.".$date"; |
|
| 732 | + |
|
| 733 | + $quote_end = ",'".$boucle->sql_serveur."','text'"; |
|
| 734 | + if ($type=='jour') |
|
| 735 | + $boucle->where[] = array("'='", "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 736 | + ("sql_quote($annee . $mois . $jour$quote_end)")); |
|
| 737 | + elseif ($type=='mois') |
|
| 738 | + $boucle->where[] = array("'='", "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 739 | + ("sql_quote($annee . $mois$quote_end)")); |
|
| 740 | + elseif ($type=='semaine') |
|
| 741 | + $boucle->where[] = array("'AND'", |
|
| 742 | + array("'>='", |
|
| 743 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 744 | + ("date_debut_semaine($annee, $mois, $jour)")), |
|
| 745 | + array("'<='", |
|
| 746 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 747 | + ("date_fin_semaine($annee, $mois, $jour)"))); |
|
| 748 | + elseif (count($crit->param)>2) |
|
| 749 | + $boucle->where[] = array("'AND'", |
|
| 750 | + array("'>='", |
|
| 751 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 752 | + ("sql_quote($annee . $mois . $jour$quote_end)")), |
|
| 753 | + array("'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)"))); |
|
| 754 | + // sinon on prend tout |
|
| 755 | 755 | } |
| 756 | 756 | |
| 757 | 757 | // http://doc.spip.org/@calculer_critere_parties |
| 758 | 758 | function calculer_critere_parties($idb, &$boucles, $crit){ |
| 759 | - $boucle = &$boucles[$idb]; |
|
| 760 | - $a1 = $crit->param[0]; |
|
| 761 | - $a2 = $crit->param[1]; |
|
| 762 | - $op = $crit->op; |
|
| 763 | - |
|
| 764 | - list($a11, $a12) = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 765 | - list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 766 | - |
|
| 767 | - if (($op==',') && (is_numeric($a11) && (is_numeric($a21)))){ |
|
| 768 | - $boucle->limit = $a11.','.$a21; |
|
| 769 | - } |
|
| 770 | - else { |
|
| 771 | - $boucle->total_parties = ($a21!='n') ? $a21 : $a22; |
|
| 772 | - $partie = ($a11!='n') ? $a11 : $a12; |
|
| 773 | - $mode = (($op=='/') ? '/' : |
|
| 774 | - (($a11=='n') ? '-' : '+').(($a21=='n') ? '-' : '+')); |
|
| 775 | - // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 776 | - if ($a11!=='n' AND $a21!=='n' AND $mode=="++" AND $op==','){ |
|
| 777 | - $boucle->limit = |
|
| 778 | - (is_numeric($a11)?"'$a11'":$a11) |
|
| 779 | - .".','." |
|
| 780 | - .(is_numeric($a21)?"'$a21'":$a21); |
|
| 781 | - } |
|
| 782 | - else |
|
| 783 | - calculer_parties($boucles, $idb, $partie, $mode); |
|
| 784 | - } |
|
| 759 | + $boucle = &$boucles[$idb]; |
|
| 760 | + $a1 = $crit->param[0]; |
|
| 761 | + $a2 = $crit->param[1]; |
|
| 762 | + $op = $crit->op; |
|
| 763 | + |
|
| 764 | + list($a11, $a12) = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 765 | + list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 766 | + |
|
| 767 | + if (($op==',') && (is_numeric($a11) && (is_numeric($a21)))){ |
|
| 768 | + $boucle->limit = $a11.','.$a21; |
|
| 769 | + } |
|
| 770 | + else { |
|
| 771 | + $boucle->total_parties = ($a21!='n') ? $a21 : $a22; |
|
| 772 | + $partie = ($a11!='n') ? $a11 : $a12; |
|
| 773 | + $mode = (($op=='/') ? '/' : |
|
| 774 | + (($a11=='n') ? '-' : '+').(($a21=='n') ? '-' : '+')); |
|
| 775 | + // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 776 | + if ($a11!=='n' AND $a21!=='n' AND $mode=="++" AND $op==','){ |
|
| 777 | + $boucle->limit = |
|
| 778 | + (is_numeric($a11)?"'$a11'":$a11) |
|
| 779 | + .".','." |
|
| 780 | + .(is_numeric($a21)?"'$a21'":$a21); |
|
| 781 | + } |
|
| 782 | + else |
|
| 783 | + calculer_parties($boucles, $idb, $partie, $mode); |
|
| 784 | + } |
|
| 785 | 785 | } |
| 786 | 786 | |
| 787 | 787 | // |
@@ -789,77 +789,77 @@ discard block |
||
| 789 | 789 | // |
| 790 | 790 | |
| 791 | 791 | function calculer_parties(&$boucles, $id_boucle, $debut, $mode){ |
| 792 | - $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 793 | - |
|
| 794 | - preg_match(",([+-/p])([+-/])?,", $mode, $regs); |
|
| 795 | - list(, $op1, $op2) = array_pad($regs, 3, null); |
|
| 796 | - $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 797 | - // {1/3} |
|
| 798 | - if ($op1=='/'){ |
|
| 799 | - $pmoins1 = is_numeric($debut) ? ($debut-1) : "($debut-1)"; |
|
| 800 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 801 | - "($total_parties ? $total_parties : 1)"; |
|
| 802 | - $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 803 | - $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 804 | - } else { |
|
| 805 | - // cas {n-1,x} |
|
| 806 | - if ($op1=='-') $debut = "$nombre_boucle - $debut;"; |
|
| 807 | - |
|
| 808 | - // cas {x,n-1} |
|
| 809 | - if ($op2=='-'){ |
|
| 810 | - $fin = '$debut_boucle + '.$nombre_boucle.' - ' |
|
| 811 | - .(is_numeric($total_parties) ? ($total_parties+1) : |
|
| 812 | - ($total_parties.' - 1')); |
|
| 813 | - } else { |
|
| 814 | - // {x,1} ou {pagination} |
|
| 815 | - $fin = '$debut_boucle' |
|
| 816 | - .(is_numeric($total_parties) ? |
|
| 817 | - (($total_parties==1) ? "" : (' + '.($total_parties-1))) : |
|
| 818 | - ('+'.$total_parties.' - 1')); |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 822 | - if ($op1=='p'){ |
|
| 823 | - $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 824 | - $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 825 | - $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 826 | - } |
|
| 827 | - } |
|
| 828 | - |
|
| 829 | - // Notes : |
|
| 830 | - // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 831 | - // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 832 | - // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 833 | - // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 834 | - |
|
| 835 | - $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 836 | - .'$debut_boucle = '.$debut.";\n " |
|
| 837 | - .'$fin_boucle = min('.$fin.", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 838 | - .'$Numrows[\''.$id_boucle."']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 839 | - .'$Numrows[\''.$id_boucle.'\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 840 | - ."\n\tif (\$debut_boucle>0 AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total'] AND \$iter->seek(\$debut_boucle,'continue'))\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 841 | - |
|
| 842 | - $boucles[$id_boucle]->partie = " |
|
| 792 | + $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 793 | + |
|
| 794 | + preg_match(",([+-/p])([+-/])?,", $mode, $regs); |
|
| 795 | + list(, $op1, $op2) = array_pad($regs, 3, null); |
|
| 796 | + $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 797 | + // {1/3} |
|
| 798 | + if ($op1=='/'){ |
|
| 799 | + $pmoins1 = is_numeric($debut) ? ($debut-1) : "($debut-1)"; |
|
| 800 | + $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 801 | + "($total_parties ? $total_parties : 1)"; |
|
| 802 | + $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 803 | + $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 804 | + } else { |
|
| 805 | + // cas {n-1,x} |
|
| 806 | + if ($op1=='-') $debut = "$nombre_boucle - $debut;"; |
|
| 807 | + |
|
| 808 | + // cas {x,n-1} |
|
| 809 | + if ($op2=='-'){ |
|
| 810 | + $fin = '$debut_boucle + '.$nombre_boucle.' - ' |
|
| 811 | + .(is_numeric($total_parties) ? ($total_parties+1) : |
|
| 812 | + ($total_parties.' - 1')); |
|
| 813 | + } else { |
|
| 814 | + // {x,1} ou {pagination} |
|
| 815 | + $fin = '$debut_boucle' |
|
| 816 | + .(is_numeric($total_parties) ? |
|
| 817 | + (($total_parties==1) ? "" : (' + '.($total_parties-1))) : |
|
| 818 | + ('+'.$total_parties.' - 1')); |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 822 | + if ($op1=='p'){ |
|
| 823 | + $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 824 | + $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 825 | + $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 826 | + } |
|
| 827 | + } |
|
| 828 | + |
|
| 829 | + // Notes : |
|
| 830 | + // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 831 | + // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 832 | + // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 833 | + // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 834 | + |
|
| 835 | + $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 836 | + .'$debut_boucle = '.$debut.";\n " |
|
| 837 | + .'$fin_boucle = min('.$fin.", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 838 | + .'$Numrows[\''.$id_boucle."']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 839 | + .'$Numrows[\''.$id_boucle.'\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 840 | + ."\n\tif (\$debut_boucle>0 AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total'] AND \$iter->seek(\$debut_boucle,'continue'))\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 841 | + |
|
| 842 | + $boucles[$id_boucle]->partie = " |
|
| 843 | 843 | if (\$Numrows['$id_boucle']['compteur_boucle'] <= \$debut_boucle) continue; |
| 844 | 844 | if (\$Numrows['$id_boucle']['compteur_boucle']-1 > \$fin_boucle) break;"; |
| 845 | 845 | } |
| 846 | 846 | |
| 847 | 847 | // http://doc.spip.org/@calculer_critere_parties_aux |
| 848 | 848 | function calculer_critere_parties_aux($idb, &$boucles, $param){ |
| 849 | - if ($param[0]->type!='texte'){ |
|
| 850 | - $a1 = calculer_liste(array($param[0]), array('id_mere' => $idb), $boucles, $boucles[$idb]->id_parent); |
|
| 851 | - preg_match(',^ *(-([0-9]+))? *$,', $param[1]->texte, $m); |
|
| 852 | - return array("intval($a1)", ($m[2] ? $m[2] : 0)); |
|
| 853 | - } else { |
|
| 854 | - preg_match(',^ *(([0-9]+)|n) *(- *([0-9]+)? *)?$,', $param[0]->texte, $m); |
|
| 855 | - $a1 = $m[1]; |
|
| 856 | - if (!@$m[3]) |
|
| 857 | - return array($a1, 0); |
|
| 858 | - elseif ($m[4]) |
|
| 859 | - return array($a1, $m[4]); |
|
| 860 | - else return array($a1, |
|
| 861 | - calculer_liste(array($param[1]), array(), $boucles[$idb]->id_parent, $boucles)); |
|
| 862 | - } |
|
| 849 | + if ($param[0]->type!='texte'){ |
|
| 850 | + $a1 = calculer_liste(array($param[0]), array('id_mere' => $idb), $boucles, $boucles[$idb]->id_parent); |
|
| 851 | + preg_match(',^ *(-([0-9]+))? *$,', $param[1]->texte, $m); |
|
| 852 | + return array("intval($a1)", ($m[2] ? $m[2] : 0)); |
|
| 853 | + } else { |
|
| 854 | + preg_match(',^ *(([0-9]+)|n) *(- *([0-9]+)? *)?$,', $param[0]->texte, $m); |
|
| 855 | + $a1 = $m[1]; |
|
| 856 | + if (!@$m[3]) |
|
| 857 | + return array($a1, 0); |
|
| 858 | + elseif ($m[4]) |
|
| 859 | + return array($a1, $m[4]); |
|
| 860 | + else return array($a1, |
|
| 861 | + calculer_liste(array($param[1]), array(), $boucles[$idb]->id_parent, $boucles)); |
|
| 862 | + } |
|
| 863 | 863 | } |
| 864 | 864 | |
| 865 | 865 | |
@@ -886,44 +886,44 @@ discard block |
||
| 886 | 886 | * array : Erreur sur un des critères |
| 887 | 887 | **/ |
| 888 | 888 | function calculer_criteres($idb, &$boucles){ |
| 889 | - $msg = ''; |
|
| 890 | - $boucle = $boucles[$idb]; |
|
| 891 | - $table = strtoupper($boucle->type_requete); |
|
| 892 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 893 | - |
|
| 894 | - $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 895 | - // s'il y avait une erreur de syntaxe, propager cette info |
|
| 896 | - if (!is_array($boucle->criteres)) return array(); |
|
| 897 | - |
|
| 898 | - foreach ($boucle->criteres as $crit){ |
|
| 899 | - $critere = $crit->op; |
|
| 900 | - // critere personnalise ? |
|
| 901 | - if ( |
|
| 902 | - (!$serveur OR |
|
| 903 | - ((!function_exists($f = "critere_".$serveur."_".$table."_".$critere)) |
|
| 904 | - AND (!function_exists($f = $f."_dist")) |
|
| 905 | - AND (!function_exists($f = "critere_".$serveur."_".$critere)) |
|
| 906 | - AND (!function_exists($f = $f."_dist")) |
|
| 907 | - ) |
|
| 908 | - ) |
|
| 909 | - AND (!function_exists($f = "critere_".$table."_".$critere)) |
|
| 910 | - AND (!function_exists($f = $f."_dist")) |
|
| 911 | - AND (!function_exists($f = "critere_".$critere)) |
|
| 912 | - AND (!function_exists($f = $f."_dist")) |
|
| 913 | - ){ |
|
| 914 | - // fonction critere standard |
|
| 915 | - $f = $defaut; |
|
| 916 | - } |
|
| 917 | - // compile le critere |
|
| 918 | - $res = $f($idb, $boucles, $crit); |
|
| 919 | - |
|
| 920 | - // Gestion centralisee des erreurs pour pouvoir propager |
|
| 921 | - if (is_array($res)){ |
|
| 922 | - $msg = $res; |
|
| 923 | - erreur_squelette($msg, $boucle); |
|
| 924 | - } |
|
| 925 | - } |
|
| 926 | - return $msg; |
|
| 889 | + $msg = ''; |
|
| 890 | + $boucle = $boucles[$idb]; |
|
| 891 | + $table = strtoupper($boucle->type_requete); |
|
| 892 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 893 | + |
|
| 894 | + $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 895 | + // s'il y avait une erreur de syntaxe, propager cette info |
|
| 896 | + if (!is_array($boucle->criteres)) return array(); |
|
| 897 | + |
|
| 898 | + foreach ($boucle->criteres as $crit){ |
|
| 899 | + $critere = $crit->op; |
|
| 900 | + // critere personnalise ? |
|
| 901 | + if ( |
|
| 902 | + (!$serveur OR |
|
| 903 | + ((!function_exists($f = "critere_".$serveur."_".$table."_".$critere)) |
|
| 904 | + AND (!function_exists($f = $f."_dist")) |
|
| 905 | + AND (!function_exists($f = "critere_".$serveur."_".$critere)) |
|
| 906 | + AND (!function_exists($f = $f."_dist")) |
|
| 907 | + ) |
|
| 908 | + ) |
|
| 909 | + AND (!function_exists($f = "critere_".$table."_".$critere)) |
|
| 910 | + AND (!function_exists($f = $f."_dist")) |
|
| 911 | + AND (!function_exists($f = "critere_".$critere)) |
|
| 912 | + AND (!function_exists($f = $f."_dist")) |
|
| 913 | + ){ |
|
| 914 | + // fonction critere standard |
|
| 915 | + $f = $defaut; |
|
| 916 | + } |
|
| 917 | + // compile le critere |
|
| 918 | + $res = $f($idb, $boucles, $crit); |
|
| 919 | + |
|
| 920 | + // Gestion centralisee des erreurs pour pouvoir propager |
|
| 921 | + if (is_array($res)){ |
|
| 922 | + $msg = $res; |
|
| 923 | + erreur_squelette($msg, $boucle); |
|
| 924 | + } |
|
| 925 | + } |
|
| 926 | + return $msg; |
|
| 927 | 927 | } |
| 928 | 928 | |
| 929 | 929 | /** |
@@ -938,80 +938,80 @@ discard block |
||
| 938 | 938 | * @return string |
| 939 | 939 | */ |
| 940 | 940 | function kwote($lisp, $serveur='', $type=''){ |
| 941 | - if (preg_match(_CODE_QUOTE, $lisp, $r)) |
|
| 942 | - return $r[1]."\"".sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]),$serveur,$type)."\""; |
|
| 943 | - else |
|
| 944 | - return "sql_quote($lisp)"; |
|
| 941 | + if (preg_match(_CODE_QUOTE, $lisp, $r)) |
|
| 942 | + return $r[1]."\"".sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]),$serveur,$type)."\""; |
|
| 943 | + else |
|
| 944 | + return "sql_quote($lisp)"; |
|
| 945 | 945 | } |
| 946 | 946 | |
| 947 | 947 | // Si on a une liste de valeurs dans #ENV{x}, utiliser la double etoile |
| 948 | 948 | // pour faire par exemple {id_article IN #ENV**{liste_articles}} |
| 949 | 949 | // http://doc.spip.org/@critere_IN_dist |
| 950 | 950 | function critere_IN_dist($idb, &$boucles, $crit){ |
| 951 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 952 | - if (!$r){ |
|
| 953 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op." ?"))); |
|
| 954 | - } |
|
| 955 | - list($arg, $op, $val, $col, $where_complement) = $r; |
|
| 956 | - |
|
| 957 | - $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 958 | - |
|
| 959 | - // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 960 | - $where = $in; |
|
| 961 | - if ($crit->cond){ |
|
| 962 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 963 | - $where = array("'?'", $pred, $where, "''"); |
|
| 964 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 965 | - $where_complement = array("'?'", $pred, $where_complement, "''"); |
|
| 966 | - } |
|
| 967 | - if ($crit->exclus) |
|
| 968 | - if (!preg_match(",^L[0-9]+[.],", $arg)) |
|
| 969 | - $where = array("'NOT'", $where); |
|
| 970 | - else |
|
| 971 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 972 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 973 | - $where = array("'NOT'", array("'IN'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", array("'SELF'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", $where))); |
|
| 974 | - |
|
| 975 | - $boucles[$idb]->where[] = $where; |
|
| 976 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 977 | - $boucles[$idb]->where[] = $where_complement; |
|
| 951 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 952 | + if (!$r){ |
|
| 953 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op." ?"))); |
|
| 954 | + } |
|
| 955 | + list($arg, $op, $val, $col, $where_complement) = $r; |
|
| 956 | + |
|
| 957 | + $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 958 | + |
|
| 959 | + // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 960 | + $where = $in; |
|
| 961 | + if ($crit->cond){ |
|
| 962 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 963 | + $where = array("'?'", $pred, $where, "''"); |
|
| 964 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 965 | + $where_complement = array("'?'", $pred, $where_complement, "''"); |
|
| 966 | + } |
|
| 967 | + if ($crit->exclus) |
|
| 968 | + if (!preg_match(",^L[0-9]+[.],", $arg)) |
|
| 969 | + $where = array("'NOT'", $where); |
|
| 970 | + else |
|
| 971 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 972 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 973 | + $where = array("'NOT'", array("'IN'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", array("'SELF'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", $where))); |
|
| 974 | + |
|
| 975 | + $boucles[$idb]->where[] = $where; |
|
| 976 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 977 | + $boucles[$idb]->where[] = $where_complement; |
|
| 978 | 978 | } |
| 979 | 979 | |
| 980 | 980 | // http://doc.spip.org/@critere_IN_cas |
| 981 | 981 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col){ |
| 982 | - static $num = array(); |
|
| 983 | - $descr = $boucles[$idb]->descr; |
|
| 984 | - $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 985 | - |
|
| 986 | - $var = '$in'.$cpt++; |
|
| 987 | - $x = "\n\t$var = array();"; |
|
| 988 | - foreach ($val as $k => $v){ |
|
| 989 | - if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)){ |
|
| 990 | - // optimiser le traitement des constantes |
|
| 991 | - if (is_numeric($r[2])) |
|
| 992 | - $x .= "\n\t$var"."[]= $r[2];"; |
|
| 993 | - else |
|
| 994 | - $x .= "\n\t$var"."[]= ".sql_quote($r[2]).";"; |
|
| 995 | - } else { |
|
| 996 | - // Pour permettre de passer des tableaux de valeurs |
|
| 997 | - // on repere l'utilisation brute de #ENV**{X}, |
|
| 998 | - // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 999 | - // et on deballe mais en rajoutant l'anti XSS |
|
| 1000 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var"."[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1001 | - } |
|
| 1002 | - } |
|
| 1003 | - |
|
| 1004 | - $boucles[$idb]->in .= $x; |
|
| 1005 | - |
|
| 1006 | - // inserer le tri par defaut selon les ordres du IN ... |
|
| 1007 | - // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un rexgexp) |
|
| 1008 | - // et que l'on limite donc strictement aux cas necessaires : |
|
| 1009 | - // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1010 | - if (!$crit2){ |
|
| 1011 | - $boucles[$idb]->default_order[] = "((!sql_quote($var) OR sql_quote($var)===\"''\") ? 0 : ('FIELD($arg,' . sql_quote($var) . ')'))"; |
|
| 1012 | - } |
|
| 1013 | - |
|
| 1014 | - return "sql_in('$arg',sql_quote($var)".($crit2=='NOT' ? ",'NOT'" : "").")"; |
|
| 982 | + static $num = array(); |
|
| 983 | + $descr = $boucles[$idb]->descr; |
|
| 984 | + $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 985 | + |
|
| 986 | + $var = '$in'.$cpt++; |
|
| 987 | + $x = "\n\t$var = array();"; |
|
| 988 | + foreach ($val as $k => $v){ |
|
| 989 | + if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)){ |
|
| 990 | + // optimiser le traitement des constantes |
|
| 991 | + if (is_numeric($r[2])) |
|
| 992 | + $x .= "\n\t$var"."[]= $r[2];"; |
|
| 993 | + else |
|
| 994 | + $x .= "\n\t$var"."[]= ".sql_quote($r[2]).";"; |
|
| 995 | + } else { |
|
| 996 | + // Pour permettre de passer des tableaux de valeurs |
|
| 997 | + // on repere l'utilisation brute de #ENV**{X}, |
|
| 998 | + // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 999 | + // et on deballe mais en rajoutant l'anti XSS |
|
| 1000 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var"."[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1001 | + } |
|
| 1002 | + } |
|
| 1003 | + |
|
| 1004 | + $boucles[$idb]->in .= $x; |
|
| 1005 | + |
|
| 1006 | + // inserer le tri par defaut selon les ordres du IN ... |
|
| 1007 | + // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un rexgexp) |
|
| 1008 | + // et que l'on limite donc strictement aux cas necessaires : |
|
| 1009 | + // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1010 | + if (!$crit2){ |
|
| 1011 | + $boucles[$idb]->default_order[] = "((!sql_quote($var) OR sql_quote($var)===\"''\") ? 0 : ('FIELD($arg,' . sql_quote($var) . ')'))"; |
|
| 1012 | + } |
|
| 1013 | + |
|
| 1014 | + return "sql_in('$arg',sql_quote($var)".($crit2=='NOT' ? ",'NOT'" : "").")"; |
|
| 1015 | 1015 | } |
| 1016 | 1016 | |
| 1017 | 1017 | /** |
@@ -1023,19 +1023,19 @@ discard block |
||
| 1023 | 1023 | * @param <type> $crit |
| 1024 | 1024 | */ |
| 1025 | 1025 | function critere_where_dist($idb, &$boucles, $crit){ |
| 1026 | - $boucle = &$boucles[$idb]; |
|
| 1027 | - if (isset($crit->param[0])) |
|
| 1028 | - $_where = calculer_liste($crit->param[0], array(), $boucles, $boucle->id_parent); |
|
| 1029 | - else |
|
| 1030 | - $_where = '@$Pile[0]["where"]'; |
|
| 1026 | + $boucle = &$boucles[$idb]; |
|
| 1027 | + if (isset($crit->param[0])) |
|
| 1028 | + $_where = calculer_liste($crit->param[0], array(), $boucles, $boucle->id_parent); |
|
| 1029 | + else |
|
| 1030 | + $_where = '@$Pile[0]["where"]'; |
|
| 1031 | 1031 | |
| 1032 | - if ($crit->cond) |
|
| 1033 | - $_where = "(($_where) ? ($_where) : '')"; |
|
| 1032 | + if ($crit->cond) |
|
| 1033 | + $_where = "(($_where) ? ($_where) : '')"; |
|
| 1034 | 1034 | |
| 1035 | - if ($crit->not) |
|
| 1036 | - $_where = "array('NOT',$_where)"; |
|
| 1035 | + if ($crit->not) |
|
| 1036 | + $_where = "array('NOT',$_where)"; |
|
| 1037 | 1037 | |
| 1038 | - $boucle->where[] = $_where; |
|
| 1038 | + $boucle->where[] = $_where; |
|
| 1039 | 1039 | } |
| 1040 | 1040 | |
| 1041 | 1041 | |
@@ -1085,27 +1085,27 @@ discard block |
||
| 1085 | 1085 | * @param unknown_type $crit |
| 1086 | 1086 | */ |
| 1087 | 1087 | function critere_tri_dist($idb, &$boucles, $crit){ |
| 1088 | - $boucle = &$boucles[$idb]; |
|
| 1089 | - |
|
| 1090 | - // definition du champ par defaut |
|
| 1091 | - $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1092 | - : calculer_liste(array($crit->param[0][0]), array(), $boucles, $boucle->id_parent); |
|
| 1093 | - $_sens_defaut = !isset($crit->param[1][0]) ? "1" |
|
| 1094 | - : calculer_liste(array($crit->param[1][0]), array(), $boucles, $boucle->id_parent); |
|
| 1095 | - $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1096 | - : calculer_liste(array($crit->param[2][0]), array(), $boucles, $boucle->id_parent); |
|
| 1097 | - |
|
| 1098 | - $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:$_champ_defaut)?tri_protege_champ(\$t):'')"; |
|
| 1099 | - |
|
| 1100 | - $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1101 | - $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:$_sens_defaut)==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1102 | - |
|
| 1103 | - $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1104 | - $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1105 | - $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1106 | - // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1107 | - // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1108 | - $boucle->hash .= " |
|
| 1088 | + $boucle = &$boucles[$idb]; |
|
| 1089 | + |
|
| 1090 | + // definition du champ par defaut |
|
| 1091 | + $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1092 | + : calculer_liste(array($crit->param[0][0]), array(), $boucles, $boucle->id_parent); |
|
| 1093 | + $_sens_defaut = !isset($crit->param[1][0]) ? "1" |
|
| 1094 | + : calculer_liste(array($crit->param[1][0]), array(), $boucles, $boucle->id_parent); |
|
| 1095 | + $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1096 | + : calculer_liste(array($crit->param[2][0]), array(), $boucles, $boucle->id_parent); |
|
| 1097 | + |
|
| 1098 | + $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:$_champ_defaut)?tri_protege_champ(\$t):'')"; |
|
| 1099 | + |
|
| 1100 | + $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1101 | + $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:$_sens_defaut)==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1102 | + |
|
| 1103 | + $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1104 | + $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1105 | + $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1106 | + // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1107 | + // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1108 | + $boucle->hash .= " |
|
| 1109 | 1109 | \$senstri = ''; |
| 1110 | 1110 | \$tri = $_tri; |
| 1111 | 1111 | if (\$tri){ |
@@ -1113,264 +1113,264 @@ discard block |
||
| 1113 | 1113 | \$senstri = (\$senstri<0)?' DESC':''; |
| 1114 | 1114 | }; |
| 1115 | 1115 | "; |
| 1116 | - $boucle->select[] = "\".tri_champ_select(\$tri).\""; |
|
| 1117 | - $boucle->order[] = "tri_champ_order(\$tri,\$command['from']).\$senstri"; |
|
| 1116 | + $boucle->select[] = "\".tri_champ_select(\$tri).\""; |
|
| 1117 | + $boucle->order[] = "tri_champ_order(\$tri,\$command['from']).\$senstri"; |
|
| 1118 | 1118 | } |
| 1119 | 1119 | |
| 1120 | 1120 | # Criteres de comparaison |
| 1121 | 1121 | |
| 1122 | 1122 | // http://doc.spip.org/@calculer_critere_DEFAUT |
| 1123 | 1123 | function calculer_critere_DEFAUT_dist($idb, &$boucles, $crit){ |
| 1124 | - // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1125 | - if (($crit->op==",") OR ($crit->op=='/')) |
|
| 1126 | - return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1127 | - |
|
| 1128 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1129 | - if (!$r){ |
|
| 1130 | - # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1131 | - # if (!$crit->cond) { |
|
| 1132 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op))); |
|
| 1133 | - # } |
|
| 1134 | - } else calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1124 | + // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1125 | + if (($crit->op==",") OR ($crit->op=='/')) |
|
| 1126 | + return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1127 | + |
|
| 1128 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1129 | + if (!$r){ |
|
| 1130 | + # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1131 | + # if (!$crit->cond) { |
|
| 1132 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op))); |
|
| 1133 | + # } |
|
| 1134 | + } else calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1135 | 1135 | } |
| 1136 | 1136 | |
| 1137 | 1137 | function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args){ |
| 1138 | - list($arg, $op, $val, $col, $where_complement) = $args; |
|
| 1139 | - |
|
| 1140 | - $where = array("'$op'", "'$arg'", $val[0]); |
|
| 1141 | - |
|
| 1142 | - // inserer la negation (cf !...) |
|
| 1143 | - |
|
| 1144 | - if ($crit->not) $where = array("'NOT'", $where); |
|
| 1145 | - if ($crit->exclus) |
|
| 1146 | - if (!preg_match(",^L[0-9]+[.],", $arg)) |
|
| 1147 | - $where = array("'NOT'", $where); |
|
| 1148 | - else |
|
| 1149 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1150 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1151 | - $where = array("'NOT'", array("'IN'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", array("'SELF'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", $where))); |
|
| 1152 | - |
|
| 1153 | - // inserer la condition (cf {lang?}) |
|
| 1154 | - // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1155 | - if ($crit->cond){ |
|
| 1156 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1157 | - if ($col=="date" OR $col=="date_redac"){ |
|
| 1158 | - if ($pred=="\$Pile[0]['".$col."']"){ |
|
| 1159 | - $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1160 | - } |
|
| 1161 | - } |
|
| 1162 | - |
|
| 1163 | - if ($op=='=' AND !$crit->not) |
|
| 1164 | - $where = array("'?'", "(is_array($pred))", |
|
| 1165 | - critere_IN_cas($idb, $boucles, 'COND', $arg, $op, array($pred), $col), |
|
| 1166 | - $where); |
|
| 1167 | - $where = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where); |
|
| 1168 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1169 | - $where_complement = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement); |
|
| 1170 | - } |
|
| 1171 | - |
|
| 1172 | - $boucles[$idb]->where[] = $where; |
|
| 1173 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1174 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1138 | + list($arg, $op, $val, $col, $where_complement) = $args; |
|
| 1139 | + |
|
| 1140 | + $where = array("'$op'", "'$arg'", $val[0]); |
|
| 1141 | + |
|
| 1142 | + // inserer la negation (cf !...) |
|
| 1143 | + |
|
| 1144 | + if ($crit->not) $where = array("'NOT'", $where); |
|
| 1145 | + if ($crit->exclus) |
|
| 1146 | + if (!preg_match(",^L[0-9]+[.],", $arg)) |
|
| 1147 | + $where = array("'NOT'", $where); |
|
| 1148 | + else |
|
| 1149 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1150 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1151 | + $where = array("'NOT'", array("'IN'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", array("'SELF'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", $where))); |
|
| 1152 | + |
|
| 1153 | + // inserer la condition (cf {lang?}) |
|
| 1154 | + // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1155 | + if ($crit->cond){ |
|
| 1156 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1157 | + if ($col=="date" OR $col=="date_redac"){ |
|
| 1158 | + if ($pred=="\$Pile[0]['".$col."']"){ |
|
| 1159 | + $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1160 | + } |
|
| 1161 | + } |
|
| 1162 | + |
|
| 1163 | + if ($op=='=' AND !$crit->not) |
|
| 1164 | + $where = array("'?'", "(is_array($pred))", |
|
| 1165 | + critere_IN_cas($idb, $boucles, 'COND', $arg, $op, array($pred), $col), |
|
| 1166 | + $where); |
|
| 1167 | + $where = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where); |
|
| 1168 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1169 | + $where_complement = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement); |
|
| 1170 | + } |
|
| 1171 | + |
|
| 1172 | + $boucles[$idb]->where[] = $where; |
|
| 1173 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1174 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1175 | 1175 | } |
| 1176 | 1176 | |
| 1177 | 1177 | // http://doc.spip.org/@calculer_critere_infixe |
| 1178 | 1178 | function calculer_critere_infixe($idb, &$boucles, $crit){ |
| 1179 | 1179 | |
| 1180 | - global $table_criteres_infixes; |
|
| 1181 | - global $exceptions_des_jointures, $exceptions_des_tables; |
|
| 1182 | - |
|
| 1183 | - $boucle = &$boucles[$idb]; |
|
| 1184 | - $type = $boucle->type_requete; |
|
| 1185 | - $table = $boucle->id_table; |
|
| 1186 | - $desc = $boucle->show; |
|
| 1187 | - $col_vraie = null; |
|
| 1188 | - |
|
| 1189 | - list($fct, $col, $op, $val, $args_sql) = |
|
| 1190 | - calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 1191 | - |
|
| 1192 | - $col_alias = $col; |
|
| 1193 | - $where_complement = false; |
|
| 1194 | - |
|
| 1195 | - // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 1196 | - if ($col=='id_enfant') |
|
| 1197 | - $col = $boucle->primary; |
|
| 1198 | - |
|
| 1199 | - // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 1200 | - if (in_array($col,array('id_parent','id_secteur')) |
|
| 1201 | - AND isset($exceptions_des_tables[$table][$col])) |
|
| 1202 | - $col = $exceptions_des_tables[$table][$col]; |
|
| 1203 | - |
|
| 1204 | - // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 1205 | - else if (($col=='id_secteur') AND ($critere_secteur = charger_fonction("critere_secteur_$type", "public", true))){ |
|
| 1206 | - $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 1210 | - // sauf si exception declaree : sauter cette etape |
|
| 1211 | - else if ( |
|
| 1212 | - !isset($exceptions_des_jointures[table_objet_sql($table)][$col]) |
|
| 1213 | - AND !isset($exceptions_des_jointures[$col]) |
|
| 1214 | - AND count(trouver_champs_decomposes($col, $desc))>1 |
|
| 1215 | - ){ |
|
| 1216 | - $e = decompose_champ_id_objet($col); |
|
| 1217 | - $col = array_shift($e); |
|
| 1218 | - $where_complement = primary_doublee($e, $table); |
|
| 1219 | - } |
|
| 1220 | - // Cas particulier : expressions de date |
|
| 1221 | - else if ($c = calculer_critere_infixe_date($idb, $boucles, $col)){ |
|
| 1222 | - list($col,$col_vraie) = $c; |
|
| 1223 | - $table = ''; |
|
| 1224 | - } |
|
| 1225 | - else if (preg_match('/^(.*)\.(.*)$/', $col, $r)){ |
|
| 1226 | - list(, $table, $col) = $r; |
|
| 1227 | - $col_alias = $col; |
|
| 1228 | - |
|
| 1229 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 1230 | - if ($desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 1231 | - AND isset($desc['field'][$col]) |
|
| 1232 | - AND $cle = array_search($desc['table'],$boucle->from)) |
|
| 1233 | - $table = $cle; |
|
| 1234 | - else { |
|
| 1235 | - $table = trouver_jointure_champ($col, $boucle, array($table), ($crit->cond OR $op!='=')); |
|
| 1236 | - } |
|
| 1237 | - #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 1238 | - if (!$table) return ''; |
|
| 1239 | - } |
|
| 1240 | - elseif (@!array_key_exists($col, $desc['field']) |
|
| 1241 | - // Champ joker * des iterateurs DATA qui accepte tout |
|
| 1242 | - AND @!array_key_exists('*', $desc['field']) |
|
| 1243 | - ) { |
|
| 1244 | - $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 1245 | - if (!$r) return ''; |
|
| 1246 | - list($col, $col_alias, $table, $where_complement, $desc) = $r; |
|
| 1247 | - } |
|
| 1248 | - |
|
| 1249 | - $col_vraie = ($col_vraie?$col_vraie:$col); |
|
| 1250 | - // Dans tous les cas, |
|
| 1251 | - // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) et passer dans sql_quote avec le type si connu |
|
| 1252 | - // et int sinon si la valeur est numerique |
|
| 1253 | - // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 1254 | - // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 1255 | - if ($op=='=' OR in_array($op, $table_criteres_infixes)){ |
|
| 1256 | - |
|
| 1257 | - // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 1258 | - // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 1259 | - if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) |
|
| 1260 | - $val[0] = $r[1].'"'.sql_quote($r[2],$boucle->sql_serveur,(isset($desc['field'][$col_vraie])?$desc['field'][$col_vraie]:'int NOT NULL')).'"'; |
|
| 1261 | - |
|
| 1262 | - // sinon expliciter les |
|
| 1263 | - // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 1264 | - // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 1265 | - // sans toucher aux |
|
| 1266 | - // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 1267 | - // sql_quote(truc,'','varchar') |
|
| 1268 | - elseif (preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 1269 | - // si pas deja un type |
|
| 1270 | - AND (!isset($r[3]) OR !$r[3])) { |
|
| 1271 | - $r = $r[1] |
|
| 1272 | - .((isset($r[2]) AND $r[2]) ? $r[2] : ",''") |
|
| 1273 | - .",'".(isset($desc['field'][$col_vraie])?addslashes($desc['field'][$col_vraie]):'int NOT NULL')."'"; |
|
| 1274 | - $val[0] = "sql_quote($r)"; |
|
| 1275 | - } |
|
| 1276 | - } |
|
| 1277 | - // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 1278 | - // leurs requetes par defaut, notamment le champ statut |
|
| 1279 | - // Ne pas confondre champs de la table principale et des jointures |
|
| 1280 | - if ($table===$boucle->id_table){ |
|
| 1281 | - $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 1282 | - if ($col_alias!=$col_vraie) |
|
| 1283 | - $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 1284 | - } |
|
| 1285 | - |
|
| 1286 | - // ajout pour le cas special d'une condition sur le champ statut: |
|
| 1287 | - // il faut alors interdire a la fonction de boucle |
|
| 1288 | - // de mettre ses propres criteres de statut |
|
| 1289 | - // http://www.spip.net/@statut (a documenter) |
|
| 1290 | - // garde pour compatibilite avec code des plugins anterieurs, mais redondant avec la ligne precedente |
|
| 1291 | - if ($col=='statut') $boucles[$idb]->statut = true; |
|
| 1292 | - |
|
| 1293 | - // inserer le nom de la table SQL devant le nom du champ |
|
| 1294 | - if ($table){ |
|
| 1295 | - if ($col[0]=="`") |
|
| 1296 | - $arg = "$table.".substr($col, 1, -1); |
|
| 1297 | - else $arg = "$table.$col"; |
|
| 1298 | - } else $arg = $col; |
|
| 1299 | - |
|
| 1300 | - // inserer la fonction SQL |
|
| 1301 | - if ($fct) $arg = "$fct($arg$args_sql)"; |
|
| 1302 | - |
|
| 1303 | - return array($arg, $op, $val, $col_alias, $where_complement); |
|
| 1180 | + global $table_criteres_infixes; |
|
| 1181 | + global $exceptions_des_jointures, $exceptions_des_tables; |
|
| 1182 | + |
|
| 1183 | + $boucle = &$boucles[$idb]; |
|
| 1184 | + $type = $boucle->type_requete; |
|
| 1185 | + $table = $boucle->id_table; |
|
| 1186 | + $desc = $boucle->show; |
|
| 1187 | + $col_vraie = null; |
|
| 1188 | + |
|
| 1189 | + list($fct, $col, $op, $val, $args_sql) = |
|
| 1190 | + calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 1191 | + |
|
| 1192 | + $col_alias = $col; |
|
| 1193 | + $where_complement = false; |
|
| 1194 | + |
|
| 1195 | + // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 1196 | + if ($col=='id_enfant') |
|
| 1197 | + $col = $boucle->primary; |
|
| 1198 | + |
|
| 1199 | + // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 1200 | + if (in_array($col,array('id_parent','id_secteur')) |
|
| 1201 | + AND isset($exceptions_des_tables[$table][$col])) |
|
| 1202 | + $col = $exceptions_des_tables[$table][$col]; |
|
| 1203 | + |
|
| 1204 | + // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 1205 | + else if (($col=='id_secteur') AND ($critere_secteur = charger_fonction("critere_secteur_$type", "public", true))){ |
|
| 1206 | + $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 1210 | + // sauf si exception declaree : sauter cette etape |
|
| 1211 | + else if ( |
|
| 1212 | + !isset($exceptions_des_jointures[table_objet_sql($table)][$col]) |
|
| 1213 | + AND !isset($exceptions_des_jointures[$col]) |
|
| 1214 | + AND count(trouver_champs_decomposes($col, $desc))>1 |
|
| 1215 | + ){ |
|
| 1216 | + $e = decompose_champ_id_objet($col); |
|
| 1217 | + $col = array_shift($e); |
|
| 1218 | + $where_complement = primary_doublee($e, $table); |
|
| 1219 | + } |
|
| 1220 | + // Cas particulier : expressions de date |
|
| 1221 | + else if ($c = calculer_critere_infixe_date($idb, $boucles, $col)){ |
|
| 1222 | + list($col,$col_vraie) = $c; |
|
| 1223 | + $table = ''; |
|
| 1224 | + } |
|
| 1225 | + else if (preg_match('/^(.*)\.(.*)$/', $col, $r)){ |
|
| 1226 | + list(, $table, $col) = $r; |
|
| 1227 | + $col_alias = $col; |
|
| 1228 | + |
|
| 1229 | + $trouver_table = charger_fonction('trouver_table','base'); |
|
| 1230 | + if ($desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 1231 | + AND isset($desc['field'][$col]) |
|
| 1232 | + AND $cle = array_search($desc['table'],$boucle->from)) |
|
| 1233 | + $table = $cle; |
|
| 1234 | + else { |
|
| 1235 | + $table = trouver_jointure_champ($col, $boucle, array($table), ($crit->cond OR $op!='=')); |
|
| 1236 | + } |
|
| 1237 | + #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 1238 | + if (!$table) return ''; |
|
| 1239 | + } |
|
| 1240 | + elseif (@!array_key_exists($col, $desc['field']) |
|
| 1241 | + // Champ joker * des iterateurs DATA qui accepte tout |
|
| 1242 | + AND @!array_key_exists('*', $desc['field']) |
|
| 1243 | + ) { |
|
| 1244 | + $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 1245 | + if (!$r) return ''; |
|
| 1246 | + list($col, $col_alias, $table, $where_complement, $desc) = $r; |
|
| 1247 | + } |
|
| 1248 | + |
|
| 1249 | + $col_vraie = ($col_vraie?$col_vraie:$col); |
|
| 1250 | + // Dans tous les cas, |
|
| 1251 | + // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) et passer dans sql_quote avec le type si connu |
|
| 1252 | + // et int sinon si la valeur est numerique |
|
| 1253 | + // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 1254 | + // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 1255 | + if ($op=='=' OR in_array($op, $table_criteres_infixes)){ |
|
| 1256 | + |
|
| 1257 | + // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 1258 | + // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 1259 | + if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) |
|
| 1260 | + $val[0] = $r[1].'"'.sql_quote($r[2],$boucle->sql_serveur,(isset($desc['field'][$col_vraie])?$desc['field'][$col_vraie]:'int NOT NULL')).'"'; |
|
| 1261 | + |
|
| 1262 | + // sinon expliciter les |
|
| 1263 | + // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 1264 | + // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 1265 | + // sans toucher aux |
|
| 1266 | + // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 1267 | + // sql_quote(truc,'','varchar') |
|
| 1268 | + elseif (preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 1269 | + // si pas deja un type |
|
| 1270 | + AND (!isset($r[3]) OR !$r[3])) { |
|
| 1271 | + $r = $r[1] |
|
| 1272 | + .((isset($r[2]) AND $r[2]) ? $r[2] : ",''") |
|
| 1273 | + .",'".(isset($desc['field'][$col_vraie])?addslashes($desc['field'][$col_vraie]):'int NOT NULL')."'"; |
|
| 1274 | + $val[0] = "sql_quote($r)"; |
|
| 1275 | + } |
|
| 1276 | + } |
|
| 1277 | + // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 1278 | + // leurs requetes par defaut, notamment le champ statut |
|
| 1279 | + // Ne pas confondre champs de la table principale et des jointures |
|
| 1280 | + if ($table===$boucle->id_table){ |
|
| 1281 | + $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 1282 | + if ($col_alias!=$col_vraie) |
|
| 1283 | + $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 1284 | + } |
|
| 1285 | + |
|
| 1286 | + // ajout pour le cas special d'une condition sur le champ statut: |
|
| 1287 | + // il faut alors interdire a la fonction de boucle |
|
| 1288 | + // de mettre ses propres criteres de statut |
|
| 1289 | + // http://www.spip.net/@statut (a documenter) |
|
| 1290 | + // garde pour compatibilite avec code des plugins anterieurs, mais redondant avec la ligne precedente |
|
| 1291 | + if ($col=='statut') $boucles[$idb]->statut = true; |
|
| 1292 | + |
|
| 1293 | + // inserer le nom de la table SQL devant le nom du champ |
|
| 1294 | + if ($table){ |
|
| 1295 | + if ($col[0]=="`") |
|
| 1296 | + $arg = "$table.".substr($col, 1, -1); |
|
| 1297 | + else $arg = "$table.$col"; |
|
| 1298 | + } else $arg = $col; |
|
| 1299 | + |
|
| 1300 | + // inserer la fonction SQL |
|
| 1301 | + if ($fct) $arg = "$fct($arg$args_sql)"; |
|
| 1302 | + |
|
| 1303 | + return array($arg, $op, $val, $col_alias, $where_complement); |
|
| 1304 | 1304 | } |
| 1305 | 1305 | |
| 1306 | 1306 | function calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table){ |
| 1307 | - global $exceptions_des_jointures; |
|
| 1308 | - $where = ''; |
|
| 1309 | - |
|
| 1310 | - $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 1311 | - // gestion par les plugins des jointures tordues |
|
| 1312 | - // pas automatiques mais necessaires |
|
| 1313 | - $table_sql = table_objet_sql($table); |
|
| 1314 | - if (isset($exceptions_des_jointures[$table_sql]) |
|
| 1315 | - AND is_array($exceptions_des_jointures[$table_sql]) |
|
| 1316 | - AND |
|
| 1317 | - ( |
|
| 1318 | - isset($exceptions_des_jointures[$table_sql][$col]) |
|
| 1319 | - OR |
|
| 1320 | - isset($exceptions_des_jointures[$table_sql]['']) |
|
| 1321 | - ) |
|
| 1322 | - ){ |
|
| 1323 | - $t = $exceptions_des_jointures[$table_sql]; |
|
| 1324 | - $index = isset($t[$col]) |
|
| 1325 | - ? $t[$col] : (isset($t['']) ? $t[''] : array()); |
|
| 1326 | - |
|
| 1327 | - if (count($index)==3) |
|
| 1328 | - list($t, $col, $calculer_critere_externe) = $index; |
|
| 1329 | - elseif (count($index)==2) { |
|
| 1330 | - list($t, $col) = $t[$col]; |
|
| 1331 | - } |
|
| 1332 | - elseif (count($index)==1) { |
|
| 1333 | - list($calculer_critere_externe) = $index; |
|
| 1334 | - $t = $table; |
|
| 1335 | - } |
|
| 1336 | - else |
|
| 1337 | - $t = ''; // jointure non declaree. La trouver. |
|
| 1338 | - } |
|
| 1339 | - elseif (isset($exceptions_des_jointures[$col])) |
|
| 1340 | - list($t, $col) = $exceptions_des_jointures[$col]; |
|
| 1341 | - else |
|
| 1342 | - $t = ''; // jointure non declaree. La trouver. |
|
| 1343 | - |
|
| 1344 | - // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 1345 | - |
|
| 1346 | - // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 1347 | - // permet de forcer une table de lien quand il y a ambiguite |
|
| 1348 | - // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 1349 | - // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 1350 | - $table = ""; |
|
| 1351 | - if ($boucle->jointures_explicites){ |
|
| 1352 | - $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 1353 | - $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond OR $op!='='), $t); |
|
| 1354 | - } |
|
| 1355 | - |
|
| 1356 | - // et sinon on cherche parmi toutes les jointures declarees |
|
| 1357 | - if (!$table) { |
|
| 1358 | - $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond OR $op!='='), $t); |
|
| 1359 | - } |
|
| 1360 | - |
|
| 1361 | - if (!$table) return ''; |
|
| 1362 | - |
|
| 1363 | - // il ne reste plus qu'a trouver le champ dans les from |
|
| 1364 | - list($nom, $desc) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 1365 | - |
|
| 1366 | - if (count(trouver_champs_decomposes($col, $desc))>1){ |
|
| 1367 | - $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 1368 | - $e = decompose_champ_id_objet($col); |
|
| 1369 | - $col = array_shift($e); |
|
| 1370 | - $where = primary_doublee($e, $table); |
|
| 1371 | - } |
|
| 1372 | - |
|
| 1373 | - return array($col, $col_alias, $table, $where, $desc); |
|
| 1307 | + global $exceptions_des_jointures; |
|
| 1308 | + $where = ''; |
|
| 1309 | + |
|
| 1310 | + $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 1311 | + // gestion par les plugins des jointures tordues |
|
| 1312 | + // pas automatiques mais necessaires |
|
| 1313 | + $table_sql = table_objet_sql($table); |
|
| 1314 | + if (isset($exceptions_des_jointures[$table_sql]) |
|
| 1315 | + AND is_array($exceptions_des_jointures[$table_sql]) |
|
| 1316 | + AND |
|
| 1317 | + ( |
|
| 1318 | + isset($exceptions_des_jointures[$table_sql][$col]) |
|
| 1319 | + OR |
|
| 1320 | + isset($exceptions_des_jointures[$table_sql]['']) |
|
| 1321 | + ) |
|
| 1322 | + ){ |
|
| 1323 | + $t = $exceptions_des_jointures[$table_sql]; |
|
| 1324 | + $index = isset($t[$col]) |
|
| 1325 | + ? $t[$col] : (isset($t['']) ? $t[''] : array()); |
|
| 1326 | + |
|
| 1327 | + if (count($index)==3) |
|
| 1328 | + list($t, $col, $calculer_critere_externe) = $index; |
|
| 1329 | + elseif (count($index)==2) { |
|
| 1330 | + list($t, $col) = $t[$col]; |
|
| 1331 | + } |
|
| 1332 | + elseif (count($index)==1) { |
|
| 1333 | + list($calculer_critere_externe) = $index; |
|
| 1334 | + $t = $table; |
|
| 1335 | + } |
|
| 1336 | + else |
|
| 1337 | + $t = ''; // jointure non declaree. La trouver. |
|
| 1338 | + } |
|
| 1339 | + elseif (isset($exceptions_des_jointures[$col])) |
|
| 1340 | + list($t, $col) = $exceptions_des_jointures[$col]; |
|
| 1341 | + else |
|
| 1342 | + $t = ''; // jointure non declaree. La trouver. |
|
| 1343 | + |
|
| 1344 | + // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 1345 | + |
|
| 1346 | + // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 1347 | + // permet de forcer une table de lien quand il y a ambiguite |
|
| 1348 | + // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 1349 | + // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 1350 | + $table = ""; |
|
| 1351 | + if ($boucle->jointures_explicites){ |
|
| 1352 | + $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 1353 | + $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond OR $op!='='), $t); |
|
| 1354 | + } |
|
| 1355 | + |
|
| 1356 | + // et sinon on cherche parmi toutes les jointures declarees |
|
| 1357 | + if (!$table) { |
|
| 1358 | + $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond OR $op!='='), $t); |
|
| 1359 | + } |
|
| 1360 | + |
|
| 1361 | + if (!$table) return ''; |
|
| 1362 | + |
|
| 1363 | + // il ne reste plus qu'a trouver le champ dans les from |
|
| 1364 | + list($nom, $desc) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 1365 | + |
|
| 1366 | + if (count(trouver_champs_decomposes($col, $desc))>1){ |
|
| 1367 | + $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 1368 | + $e = decompose_champ_id_objet($col); |
|
| 1369 | + $col = array_shift($e); |
|
| 1370 | + $where = primary_doublee($e, $table); |
|
| 1371 | + } |
|
| 1372 | + |
|
| 1373 | + return array($col, $col_alias, $table, $where, $desc); |
|
| 1374 | 1374 | } |
| 1375 | 1375 | |
| 1376 | 1376 | // Ne pas appliquer sql_quote lors de la compilation, |
@@ -1378,9 +1378,9 @@ discard block |
||
| 1378 | 1378 | |
| 1379 | 1379 | // http://doc.spip.org/@primary_doublee |
| 1380 | 1380 | function primary_doublee($decompose, $table){ |
| 1381 | - $e1 = reset($decompose); |
|
| 1382 | - $e2 = "sql_quote('".end($decompose)."')"; |
|
| 1383 | - return array("'='", "'$table.".$e1."'", $e2); |
|
| 1381 | + $e1 = reset($decompose); |
|
| 1382 | + $e2 = "sql_quote('".end($decompose)."')"; |
|
| 1383 | + return array("'='", "'$table.".$e1."'", $e2); |
|
| 1384 | 1384 | } |
| 1385 | 1385 | |
| 1386 | 1386 | /** |
@@ -1403,43 +1403,43 @@ discard block |
||
| 1403 | 1403 | * @return mixed|string |
| 1404 | 1404 | */ |
| 1405 | 1405 | function calculer_critere_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false){ |
| 1406 | - // si on demande un truc du genre spip_mots |
|
| 1407 | - // avec aussi spip_mots_liens dans les jointures dispo |
|
| 1408 | - // et qu'on est la |
|
| 1409 | - // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 1410 | - if ($checkarrivee |
|
| 1411 | - AND is_string($checkarrivee) |
|
| 1412 | - AND $a = table_objet($checkarrivee) |
|
| 1413 | - AND in_array($a.'_liens', $joints) |
|
| 1414 | - ){ |
|
| 1415 | - if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 1416 | - return $res; |
|
| 1417 | - } |
|
| 1418 | - } |
|
| 1419 | - foreach ($joints as $joint){ |
|
| 1420 | - if ($arrivee = trouver_champ_exterieur($col, array($joint), $boucle, $checkarrivee)){ |
|
| 1421 | - $t = array_search($arrivee[0], $boucle->from); |
|
| 1422 | - // transformer eventuellement id_xx en (id_objet,objet) |
|
| 1423 | - $cols = trouver_champs_decomposes($col, $arrivee[1]); |
|
| 1424 | - if ($t){ |
|
| 1425 | - $joindre = false; |
|
| 1426 | - foreach ($cols as $col){ |
|
| 1427 | - $c = '/\b'.$t.".$col".'\b/'; |
|
| 1428 | - if (trouver_champ($c, $boucle->where)) $joindre = true; |
|
| 1429 | - else { |
|
| 1430 | - // mais ca peut etre dans le FIELD pour le Having |
|
| 1431 | - $c = "/FIELD.$t".".$col,/"; |
|
| 1432 | - if (trouver_champ($c, $boucle->select)) $joindre = true; |
|
| 1433 | - } |
|
| 1434 | - } |
|
| 1435 | - if (!$joindre) return $t; |
|
| 1436 | - } |
|
| 1437 | - if ($res = calculer_jointure($boucle, array($boucle->id_table, $desc), $arrivee, $cols, $cond, 1)) { |
|
| 1438 | - return $res; |
|
| 1439 | - } |
|
| 1440 | - } |
|
| 1441 | - } |
|
| 1442 | - return ''; |
|
| 1406 | + // si on demande un truc du genre spip_mots |
|
| 1407 | + // avec aussi spip_mots_liens dans les jointures dispo |
|
| 1408 | + // et qu'on est la |
|
| 1409 | + // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 1410 | + if ($checkarrivee |
|
| 1411 | + AND is_string($checkarrivee) |
|
| 1412 | + AND $a = table_objet($checkarrivee) |
|
| 1413 | + AND in_array($a.'_liens', $joints) |
|
| 1414 | + ){ |
|
| 1415 | + if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 1416 | + return $res; |
|
| 1417 | + } |
|
| 1418 | + } |
|
| 1419 | + foreach ($joints as $joint){ |
|
| 1420 | + if ($arrivee = trouver_champ_exterieur($col, array($joint), $boucle, $checkarrivee)){ |
|
| 1421 | + $t = array_search($arrivee[0], $boucle->from); |
|
| 1422 | + // transformer eventuellement id_xx en (id_objet,objet) |
|
| 1423 | + $cols = trouver_champs_decomposes($col, $arrivee[1]); |
|
| 1424 | + if ($t){ |
|
| 1425 | + $joindre = false; |
|
| 1426 | + foreach ($cols as $col){ |
|
| 1427 | + $c = '/\b'.$t.".$col".'\b/'; |
|
| 1428 | + if (trouver_champ($c, $boucle->where)) $joindre = true; |
|
| 1429 | + else { |
|
| 1430 | + // mais ca peut etre dans le FIELD pour le Having |
|
| 1431 | + $c = "/FIELD.$t".".$col,/"; |
|
| 1432 | + if (trouver_champ($c, $boucle->select)) $joindre = true; |
|
| 1433 | + } |
|
| 1434 | + } |
|
| 1435 | + if (!$joindre) return $t; |
|
| 1436 | + } |
|
| 1437 | + if ($res = calculer_jointure($boucle, array($boucle->id_table, $desc), $arrivee, $cols, $cond, 1)) { |
|
| 1438 | + return $res; |
|
| 1439 | + } |
|
| 1440 | + } |
|
| 1441 | + } |
|
| 1442 | + return ''; |
|
| 1443 | 1443 | |
| 1444 | 1444 | } |
| 1445 | 1445 | |
@@ -1455,33 +1455,33 @@ discard block |
||
| 1455 | 1455 | * @return string |
| 1456 | 1456 | */ |
| 1457 | 1457 | function calculer_lien_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false){ |
| 1458 | - $primary_arrivee = id_table_objet($checkarrivee); |
|
| 1458 | + $primary_arrivee = id_table_objet($checkarrivee); |
|
| 1459 | 1459 | |
| 1460 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee."_liens"); |
|
| 1461 | - $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 1460 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee."_liens"); |
|
| 1461 | + $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 1462 | 1462 | |
| 1463 | - if (!$intermediaire OR !$arrivee) return ''; |
|
| 1463 | + if (!$intermediaire OR !$arrivee) return ''; |
|
| 1464 | 1464 | |
| 1465 | - $res = fabrique_jointures($boucle, |
|
| 1466 | - array( |
|
| 1467 | - array($boucle->id_table, $intermediaire, array(id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type'])), |
|
| 1468 | - array(reset($intermediaire), $arrivee, $primary_arrivee) |
|
| 1469 | - ) |
|
| 1470 | - , $cond, $desc, $boucle->id_table, array($col)); |
|
| 1471 | - return $res; |
|
| 1465 | + $res = fabrique_jointures($boucle, |
|
| 1466 | + array( |
|
| 1467 | + array($boucle->id_table, $intermediaire, array(id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type'])), |
|
| 1468 | + array(reset($intermediaire), $arrivee, $primary_arrivee) |
|
| 1469 | + ) |
|
| 1470 | + , $cond, $desc, $boucle->id_table, array($col)); |
|
| 1471 | + return $res; |
|
| 1472 | 1472 | } |
| 1473 | 1473 | |
| 1474 | 1474 | |
| 1475 | 1475 | // http://doc.spip.org/@trouver_champ |
| 1476 | 1476 | function trouver_champ($champ, $where){ |
| 1477 | - if (!is_array($where)) |
|
| 1478 | - return preg_match($champ, $where); |
|
| 1479 | - else { |
|
| 1480 | - foreach ($where as $clause){ |
|
| 1481 | - if (trouver_champ($champ, $clause)) return true; |
|
| 1482 | - } |
|
| 1483 | - return false; |
|
| 1484 | - } |
|
| 1477 | + if (!is_array($where)) |
|
| 1478 | + return preg_match($champ, $where); |
|
| 1479 | + else { |
|
| 1480 | + foreach ($where as $clause){ |
|
| 1481 | + if (trouver_champ($champ, $clause)) return true; |
|
| 1482 | + } |
|
| 1483 | + return false; |
|
| 1484 | + } |
|
| 1485 | 1485 | } |
| 1486 | 1486 | |
| 1487 | 1487 | |
@@ -1489,227 +1489,227 @@ discard block |
||
| 1489 | 1489 | |
| 1490 | 1490 | // http://doc.spip.org/@calculer_critere_infixe_ops |
| 1491 | 1491 | function calculer_critere_infixe_ops($idb, &$boucles, $crit){ |
| 1492 | - // cas d'une valeur comparee a elle-meme ou son referent |
|
| 1493 | - if (count($crit->param)==0){ |
|
| 1494 | - $op = '='; |
|
| 1495 | - $col = $val = $crit->op; |
|
| 1496 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) $val = $r[2]; |
|
| 1497 | - // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 1498 | - if ($val=='lang') |
|
| 1499 | - $val = array(kwote('$GLOBALS[\'spip_lang\']')); |
|
| 1500 | - else { |
|
| 1501 | - $defaut = null; |
|
| 1502 | - if ($val=='id_parent') { |
|
| 1503 | - // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 1504 | - // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 1505 | - // pour eviter l'erreur SQL |
|
| 1506 | - $val = $boucles[$idb]->primary; |
|
| 1507 | - // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 1508 | - $defaut = "\$Pile[0]['id_parent']"; |
|
| 1509 | - } |
|
| 1510 | - elseif ($val=='id_enfant'){ |
|
| 1511 | - // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 1512 | - // de la boucle superieure |
|
| 1513 | - $val = 'id_parent'; |
|
| 1514 | - } |
|
| 1515 | - elseif ($crit->cond AND ($col=="date" OR $col=="date_redac")){ |
|
| 1516 | - // un critere conditionnel sur date est traite a part |
|
| 1517 | - // car la date est mise d'office par SPIP, |
|
| 1518 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['".$col."'])"; |
|
| 1519 | - } |
|
| 1520 | - |
|
| 1521 | - $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 1522 | - $val = array(kwote($val)); |
|
| 1523 | - } |
|
| 1524 | - } else { |
|
| 1525 | - // comparaison explicite |
|
| 1526 | - // le phraseur impose que le premier param soit du texte |
|
| 1527 | - $params = $crit->param; |
|
| 1528 | - $op = $crit->op; |
|
| 1529 | - if ($op=='==') $op = 'REGEXP'; |
|
| 1530 | - $col = array_shift($params); |
|
| 1531 | - $col = $col[0]->texte; |
|
| 1532 | - |
|
| 1533 | - $val = array(); |
|
| 1534 | - $desc = array('id_mere' => $idb); |
|
| 1535 | - $parent = $boucles[$idb]->id_parent; |
|
| 1536 | - |
|
| 1537 | - // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 1538 | - // celui ne sachant pas ce qu'est un critere infixe |
|
| 1539 | - // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 1540 | - if (count($params)==1 |
|
| 1541 | - AND count($params[0]==3) |
|
| 1542 | - AND $params[0][0]->type=='texte' |
|
| 1543 | - AND @$params[0][2]->type=='texte' |
|
| 1544 | - AND ($p = $params[0][0]->texte)==$params[0][2]->texte |
|
| 1545 | - AND (($p=="'") OR ($p=='"')) |
|
| 1546 | - AND $params[0][1]->type=='champ' |
|
| 1547 | - ){ |
|
| 1548 | - $val[] = "$p\\$p#".$params[0][1]->nom_champ."\\$p$p"; |
|
| 1549 | - } else |
|
| 1550 | - foreach ((($op!='IN') ? $params : calculer_vieux_in($params)) as $p){ |
|
| 1551 | - $a = calculer_liste($p, $desc, $boucles, $parent); |
|
| 1552 | - if (strcasecmp($op,'IN')==0) $val[] = $a; |
|
| 1553 | - else $val[] = kwote($a, $boucles[$idb]->sql_serveur, 'char'); // toujours quoter en char ici |
|
| 1554 | - } |
|
| 1555 | - } |
|
| 1556 | - |
|
| 1557 | - $fct = $args_sql = ''; |
|
| 1558 | - // fonction SQL ? |
|
| 1559 | - if (preg_match('/^(.*)'.SQL_ARGS.'$/', $col, $m)){ |
|
| 1560 | - $fct = $m[1]; |
|
| 1561 | - preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 1562 | - $col = $a[1]; |
|
| 1563 | - if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)){ |
|
| 1564 | - $col = $m[1]; |
|
| 1565 | - $args_sql = $m[2]; |
|
| 1566 | - } |
|
| 1567 | - $args_sql .= $a[2]; |
|
| 1568 | - ; |
|
| 1569 | - } |
|
| 1570 | - |
|
| 1571 | - return array($fct, $col, $op, $val, $args_sql); |
|
| 1492 | + // cas d'une valeur comparee a elle-meme ou son referent |
|
| 1493 | + if (count($crit->param)==0){ |
|
| 1494 | + $op = '='; |
|
| 1495 | + $col = $val = $crit->op; |
|
| 1496 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) $val = $r[2]; |
|
| 1497 | + // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 1498 | + if ($val=='lang') |
|
| 1499 | + $val = array(kwote('$GLOBALS[\'spip_lang\']')); |
|
| 1500 | + else { |
|
| 1501 | + $defaut = null; |
|
| 1502 | + if ($val=='id_parent') { |
|
| 1503 | + // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 1504 | + // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 1505 | + // pour eviter l'erreur SQL |
|
| 1506 | + $val = $boucles[$idb]->primary; |
|
| 1507 | + // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 1508 | + $defaut = "\$Pile[0]['id_parent']"; |
|
| 1509 | + } |
|
| 1510 | + elseif ($val=='id_enfant'){ |
|
| 1511 | + // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 1512 | + // de la boucle superieure |
|
| 1513 | + $val = 'id_parent'; |
|
| 1514 | + } |
|
| 1515 | + elseif ($crit->cond AND ($col=="date" OR $col=="date_redac")){ |
|
| 1516 | + // un critere conditionnel sur date est traite a part |
|
| 1517 | + // car la date est mise d'office par SPIP, |
|
| 1518 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['".$col."'])"; |
|
| 1519 | + } |
|
| 1520 | + |
|
| 1521 | + $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 1522 | + $val = array(kwote($val)); |
|
| 1523 | + } |
|
| 1524 | + } else { |
|
| 1525 | + // comparaison explicite |
|
| 1526 | + // le phraseur impose que le premier param soit du texte |
|
| 1527 | + $params = $crit->param; |
|
| 1528 | + $op = $crit->op; |
|
| 1529 | + if ($op=='==') $op = 'REGEXP'; |
|
| 1530 | + $col = array_shift($params); |
|
| 1531 | + $col = $col[0]->texte; |
|
| 1532 | + |
|
| 1533 | + $val = array(); |
|
| 1534 | + $desc = array('id_mere' => $idb); |
|
| 1535 | + $parent = $boucles[$idb]->id_parent; |
|
| 1536 | + |
|
| 1537 | + // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 1538 | + // celui ne sachant pas ce qu'est un critere infixe |
|
| 1539 | + // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 1540 | + if (count($params)==1 |
|
| 1541 | + AND count($params[0]==3) |
|
| 1542 | + AND $params[0][0]->type=='texte' |
|
| 1543 | + AND @$params[0][2]->type=='texte' |
|
| 1544 | + AND ($p = $params[0][0]->texte)==$params[0][2]->texte |
|
| 1545 | + AND (($p=="'") OR ($p=='"')) |
|
| 1546 | + AND $params[0][1]->type=='champ' |
|
| 1547 | + ){ |
|
| 1548 | + $val[] = "$p\\$p#".$params[0][1]->nom_champ."\\$p$p"; |
|
| 1549 | + } else |
|
| 1550 | + foreach ((($op!='IN') ? $params : calculer_vieux_in($params)) as $p){ |
|
| 1551 | + $a = calculer_liste($p, $desc, $boucles, $parent); |
|
| 1552 | + if (strcasecmp($op,'IN')==0) $val[] = $a; |
|
| 1553 | + else $val[] = kwote($a, $boucles[$idb]->sql_serveur, 'char'); // toujours quoter en char ici |
|
| 1554 | + } |
|
| 1555 | + } |
|
| 1556 | + |
|
| 1557 | + $fct = $args_sql = ''; |
|
| 1558 | + // fonction SQL ? |
|
| 1559 | + if (preg_match('/^(.*)'.SQL_ARGS.'$/', $col, $m)){ |
|
| 1560 | + $fct = $m[1]; |
|
| 1561 | + preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 1562 | + $col = $a[1]; |
|
| 1563 | + if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)){ |
|
| 1564 | + $col = $m[1]; |
|
| 1565 | + $args_sql = $m[2]; |
|
| 1566 | + } |
|
| 1567 | + $args_sql .= $a[2]; |
|
| 1568 | + ; |
|
| 1569 | + } |
|
| 1570 | + |
|
| 1571 | + return array($fct, $col, $op, $val, $args_sql); |
|
| 1572 | 1572 | } |
| 1573 | 1573 | |
| 1574 | 1574 | // compatibilite ancienne version |
| 1575 | 1575 | |
| 1576 | 1576 | // http://doc.spip.org/@calculer_vieux_in |
| 1577 | 1577 | function calculer_vieux_in($params){ |
| 1578 | - $deb = $params[0][0]; |
|
| 1579 | - $k = count($params)-1; |
|
| 1580 | - $last = $params[$k]; |
|
| 1581 | - $j = count($last)-1; |
|
| 1582 | - $last = $last[$j]; |
|
| 1583 | - $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 1584 | - |
|
| 1585 | - if (!((isset($deb->texte[0]) AND $deb->texte[0]=='(') |
|
| 1586 | - && (isset($last->texte[$n-1]) AND $last->texte[$n-1]==')'))) |
|
| 1587 | - return $params; |
|
| 1588 | - $params[0][0]->texte = substr($deb->texte, 1); |
|
| 1589 | - // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 1590 | - $last = $params[$k][$j]; |
|
| 1591 | - $n = strlen($last->texte); |
|
| 1592 | - $params[$k][$j]->texte = substr($last->texte, 0, $n-1); |
|
| 1593 | - $newp = array(); |
|
| 1594 | - foreach ($params as $v){ |
|
| 1595 | - if ($v[0]->type!='texte') |
|
| 1596 | - $newp[] = $v; |
|
| 1597 | - else { |
|
| 1598 | - foreach (explode(',', $v[0]->texte) as $x){ |
|
| 1599 | - $t = new Texte; |
|
| 1600 | - $t->texte = $x; |
|
| 1601 | - $newp[] = array($t); |
|
| 1602 | - } |
|
| 1603 | - } |
|
| 1604 | - } |
|
| 1605 | - return $newp; |
|
| 1578 | + $deb = $params[0][0]; |
|
| 1579 | + $k = count($params)-1; |
|
| 1580 | + $last = $params[$k]; |
|
| 1581 | + $j = count($last)-1; |
|
| 1582 | + $last = $last[$j]; |
|
| 1583 | + $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 1584 | + |
|
| 1585 | + if (!((isset($deb->texte[0]) AND $deb->texte[0]=='(') |
|
| 1586 | + && (isset($last->texte[$n-1]) AND $last->texte[$n-1]==')'))) |
|
| 1587 | + return $params; |
|
| 1588 | + $params[0][0]->texte = substr($deb->texte, 1); |
|
| 1589 | + // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 1590 | + $last = $params[$k][$j]; |
|
| 1591 | + $n = strlen($last->texte); |
|
| 1592 | + $params[$k][$j]->texte = substr($last->texte, 0, $n-1); |
|
| 1593 | + $newp = array(); |
|
| 1594 | + foreach ($params as $v){ |
|
| 1595 | + if ($v[0]->type!='texte') |
|
| 1596 | + $newp[] = $v; |
|
| 1597 | + else { |
|
| 1598 | + foreach (explode(',', $v[0]->texte) as $x){ |
|
| 1599 | + $t = new Texte; |
|
| 1600 | + $t->texte = $x; |
|
| 1601 | + $newp[] = array($t); |
|
| 1602 | + } |
|
| 1603 | + } |
|
| 1604 | + } |
|
| 1605 | + return $newp; |
|
| 1606 | 1606 | } |
| 1607 | 1607 | |
| 1608 | 1608 | // http://doc.spip.org/@calculer_critere_infixe_date |
| 1609 | 1609 | function calculer_critere_infixe_date($idb, &$boucles, $col){ |
| 1610 | - if (!preg_match(",^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z]+)?$,", $col, $regs)) return ''; |
|
| 1611 | - $boucle = $boucles[$idb]; |
|
| 1612 | - $table = $boucle->show; |
|
| 1613 | - // si c'est une colonne de la table, ne rien faire |
|
| 1614 | - if(isset($table['field'][$col])) return ''; |
|
| 1615 | - |
|
| 1616 | - if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) return ''; |
|
| 1617 | - $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']])? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 1618 | - $col = $regs[1]; |
|
| 1619 | - if (isset($regs[3]) AND $suite = $regs[3]){ |
|
| 1620 | - # Recherche de l'existence du champ date_xxxx, |
|
| 1621 | - # si oui choisir ce champ, sinon choisir xxxx |
|
| 1622 | - |
|
| 1623 | - if (isset($table['field']["date$suite"])) |
|
| 1624 | - $date_orig = 'date'.$suite; |
|
| 1625 | - else |
|
| 1626 | - $date_orig = substr($suite, 1); |
|
| 1627 | - $pred = $date_orig; |
|
| 1628 | - } |
|
| 1629 | - else |
|
| 1630 | - if (isset($regs[2]) AND $rel = $regs[2]) $pred = 'date'; |
|
| 1631 | - |
|
| 1632 | - $date_compare = "\"' . normaliser_date(". |
|
| 1633 | - calculer_argument_precedent($idb, $pred, $boucles). |
|
| 1634 | - ") . '\""; |
|
| 1635 | - |
|
| 1636 | - $col_vraie = $date_orig; |
|
| 1637 | - $date_orig = $boucle->id_table.'.'.$date_orig; |
|
| 1638 | - |
|
| 1639 | - switch ($col) { |
|
| 1640 | - case 'date': |
|
| 1641 | - $col = $date_orig; |
|
| 1642 | - break; |
|
| 1643 | - case 'jour': |
|
| 1644 | - $col = "DAYOFMONTH($date_orig)"; |
|
| 1645 | - break; |
|
| 1646 | - case 'mois': |
|
| 1647 | - $col = "MONTH($date_orig)"; |
|
| 1648 | - break; |
|
| 1649 | - case 'annee': |
|
| 1650 | - $col = "YEAR($date_orig)"; |
|
| 1651 | - break; |
|
| 1652 | - case 'heure': |
|
| 1653 | - $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 1654 | - break; |
|
| 1655 | - case 'age': |
|
| 1656 | - $col = calculer_param_date("NOW()", $date_orig); |
|
| 1657 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 1658 | - break; |
|
| 1659 | - case 'age_relatif': |
|
| 1660 | - $col = calculer_param_date($date_compare, $date_orig); |
|
| 1661 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 1662 | - break; |
|
| 1663 | - case 'jour_relatif': |
|
| 1664 | - $col = "(TO_DAYS(".$date_compare.")-TO_DAYS(".$date_orig."))"; |
|
| 1665 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 1666 | - break; |
|
| 1667 | - case 'mois_relatif': |
|
| 1668 | - $col = "MONTH(".$date_compare.")-MONTH(". |
|
| 1669 | - $date_orig.")+12*(YEAR(".$date_compare. |
|
| 1670 | - ")-YEAR(".$date_orig."))"; |
|
| 1671 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 1672 | - break; |
|
| 1673 | - case 'annee_relatif': |
|
| 1674 | - $col = "YEAR(".$date_compare.")-YEAR(". |
|
| 1675 | - $date_orig.")"; |
|
| 1676 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 1677 | - break; |
|
| 1678 | - } |
|
| 1679 | - return array($col,$col_vraie); |
|
| 1610 | + if (!preg_match(",^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z]+)?$,", $col, $regs)) return ''; |
|
| 1611 | + $boucle = $boucles[$idb]; |
|
| 1612 | + $table = $boucle->show; |
|
| 1613 | + // si c'est une colonne de la table, ne rien faire |
|
| 1614 | + if(isset($table['field'][$col])) return ''; |
|
| 1615 | + |
|
| 1616 | + if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) return ''; |
|
| 1617 | + $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']])? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 1618 | + $col = $regs[1]; |
|
| 1619 | + if (isset($regs[3]) AND $suite = $regs[3]){ |
|
| 1620 | + # Recherche de l'existence du champ date_xxxx, |
|
| 1621 | + # si oui choisir ce champ, sinon choisir xxxx |
|
| 1622 | + |
|
| 1623 | + if (isset($table['field']["date$suite"])) |
|
| 1624 | + $date_orig = 'date'.$suite; |
|
| 1625 | + else |
|
| 1626 | + $date_orig = substr($suite, 1); |
|
| 1627 | + $pred = $date_orig; |
|
| 1628 | + } |
|
| 1629 | + else |
|
| 1630 | + if (isset($regs[2]) AND $rel = $regs[2]) $pred = 'date'; |
|
| 1631 | + |
|
| 1632 | + $date_compare = "\"' . normaliser_date(". |
|
| 1633 | + calculer_argument_precedent($idb, $pred, $boucles). |
|
| 1634 | + ") . '\""; |
|
| 1635 | + |
|
| 1636 | + $col_vraie = $date_orig; |
|
| 1637 | + $date_orig = $boucle->id_table.'.'.$date_orig; |
|
| 1638 | + |
|
| 1639 | + switch ($col) { |
|
| 1640 | + case 'date': |
|
| 1641 | + $col = $date_orig; |
|
| 1642 | + break; |
|
| 1643 | + case 'jour': |
|
| 1644 | + $col = "DAYOFMONTH($date_orig)"; |
|
| 1645 | + break; |
|
| 1646 | + case 'mois': |
|
| 1647 | + $col = "MONTH($date_orig)"; |
|
| 1648 | + break; |
|
| 1649 | + case 'annee': |
|
| 1650 | + $col = "YEAR($date_orig)"; |
|
| 1651 | + break; |
|
| 1652 | + case 'heure': |
|
| 1653 | + $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 1654 | + break; |
|
| 1655 | + case 'age': |
|
| 1656 | + $col = calculer_param_date("NOW()", $date_orig); |
|
| 1657 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 1658 | + break; |
|
| 1659 | + case 'age_relatif': |
|
| 1660 | + $col = calculer_param_date($date_compare, $date_orig); |
|
| 1661 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 1662 | + break; |
|
| 1663 | + case 'jour_relatif': |
|
| 1664 | + $col = "(TO_DAYS(".$date_compare.")-TO_DAYS(".$date_orig."))"; |
|
| 1665 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 1666 | + break; |
|
| 1667 | + case 'mois_relatif': |
|
| 1668 | + $col = "MONTH(".$date_compare.")-MONTH(". |
|
| 1669 | + $date_orig.")+12*(YEAR(".$date_compare. |
|
| 1670 | + ")-YEAR(".$date_orig."))"; |
|
| 1671 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 1672 | + break; |
|
| 1673 | + case 'annee_relatif': |
|
| 1674 | + $col = "YEAR(".$date_compare.")-YEAR(". |
|
| 1675 | + $date_orig.")"; |
|
| 1676 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 1677 | + break; |
|
| 1678 | + } |
|
| 1679 | + return array($col,$col_vraie); |
|
| 1680 | 1680 | } |
| 1681 | 1681 | |
| 1682 | 1682 | // http://doc.spip.org/@calculer_param_date |
| 1683 | 1683 | function calculer_param_date($date_compare, $date_orig){ |
| 1684 | - if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)){ |
|
| 1685 | - $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 1686 | - $date_compare = '\'$x\''; |
|
| 1687 | - } |
|
| 1688 | - else |
|
| 1689 | - $init = $date_compare; |
|
| 1690 | - |
|
| 1691 | - return |
|
| 1692 | - "LEAST((UNIX_TIMESTAMP(". |
|
| 1693 | - $init. |
|
| 1694 | - ")-UNIX_TIMESTAMP(". |
|
| 1695 | - $date_orig. |
|
| 1696 | - "))/86400,\n\tTO_DAYS(". |
|
| 1697 | - $date_compare. |
|
| 1698 | - ")-TO_DAYS(". |
|
| 1699 | - $date_orig. |
|
| 1700 | - "),\n\tDAYOFMONTH(". |
|
| 1701 | - $date_compare. |
|
| 1702 | - ")-DAYOFMONTH(". |
|
| 1703 | - $date_orig. |
|
| 1704 | - ")+30.4368*(MONTH(". |
|
| 1705 | - $date_compare. |
|
| 1706 | - ")-MONTH(". |
|
| 1707 | - $date_orig. |
|
| 1708 | - "))+365.2422*(YEAR(". |
|
| 1709 | - $date_compare. |
|
| 1710 | - ")-YEAR(". |
|
| 1711 | - $date_orig. |
|
| 1712 | - ")))"; |
|
| 1684 | + if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)){ |
|
| 1685 | + $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 1686 | + $date_compare = '\'$x\''; |
|
| 1687 | + } |
|
| 1688 | + else |
|
| 1689 | + $init = $date_compare; |
|
| 1690 | + |
|
| 1691 | + return |
|
| 1692 | + "LEAST((UNIX_TIMESTAMP(". |
|
| 1693 | + $init. |
|
| 1694 | + ")-UNIX_TIMESTAMP(". |
|
| 1695 | + $date_orig. |
|
| 1696 | + "))/86400,\n\tTO_DAYS(". |
|
| 1697 | + $date_compare. |
|
| 1698 | + ")-TO_DAYS(". |
|
| 1699 | + $date_orig. |
|
| 1700 | + "),\n\tDAYOFMONTH(". |
|
| 1701 | + $date_compare. |
|
| 1702 | + ")-DAYOFMONTH(". |
|
| 1703 | + $date_orig. |
|
| 1704 | + ")+30.4368*(MONTH(". |
|
| 1705 | + $date_compare. |
|
| 1706 | + ")-MONTH(". |
|
| 1707 | + $date_orig. |
|
| 1708 | + "))+365.2422*(YEAR(". |
|
| 1709 | + $date_compare. |
|
| 1710 | + ")-YEAR(". |
|
| 1711 | + $date_orig. |
|
| 1712 | + ")))"; |
|
| 1713 | 1713 | } |
| 1714 | 1714 | |
| 1715 | 1715 | /** |
@@ -1719,17 +1719,17 @@ discard block |
||
| 1719 | 1719 | * @param object $crit |
| 1720 | 1720 | */ |
| 1721 | 1721 | function critere_DATA_source_dist($idb, &$boucles, $crit){ |
| 1722 | - $boucle = &$boucles[$idb]; |
|
| 1722 | + $boucle = &$boucles[$idb]; |
|
| 1723 | 1723 | |
| 1724 | - $args = array(); |
|
| 1725 | - foreach ($crit->param as &$param) |
|
| 1726 | - array_push($args, |
|
| 1727 | - calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent)); |
|
| 1724 | + $args = array(); |
|
| 1725 | + foreach ($crit->param as &$param) |
|
| 1726 | + array_push($args, |
|
| 1727 | + calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent)); |
|
| 1728 | 1728 | |
| 1729 | - $boucle->hash .= ' |
|
| 1729 | + $boucle->hash .= ' |
|
| 1730 | 1730 | $command[\'sourcemode\'] = '.array_shift($args).";\n"; |
| 1731 | 1731 | |
| 1732 | - $boucle->hash .= ' |
|
| 1732 | + $boucle->hash .= ' |
|
| 1733 | 1733 | $command[\'source\'] = array('.join(', ', $args).");\n"; |
| 1734 | 1734 | } |
| 1735 | 1735 | |
@@ -1741,8 +1741,8 @@ discard block |
||
| 1741 | 1741 | * @param object $crit |
| 1742 | 1742 | */ |
| 1743 | 1743 | function critere_DATA_datasource_dist($idb, &$boucles, $crit){ |
| 1744 | - $boucle = &$boucles[$idb]; |
|
| 1745 | - $boucle->hash .= ' |
|
| 1744 | + $boucle = &$boucles[$idb]; |
|
| 1745 | + $boucle->hash .= ' |
|
| 1746 | 1746 | $command[\'source\'] = array('.calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent).'); |
| 1747 | 1747 | $command[\'sourcemode\'] = '.calculer_liste($crit->param[1], array(), $boucles, $boucles[$idb]->id_parent).';'; |
| 1748 | 1748 | } |
@@ -1755,8 +1755,8 @@ discard block |
||
| 1755 | 1755 | * @param object $crit |
| 1756 | 1756 | */ |
| 1757 | 1757 | function critere_DATA_datacache_dist($idb, &$boucles, $crit){ |
| 1758 | - $boucle = &$boucles[$idb]; |
|
| 1759 | - $boucle->hash .= ' |
|
| 1758 | + $boucle = &$boucles[$idb]; |
|
| 1759 | + $boucle->hash .= ' |
|
| 1760 | 1760 | $command[\'datacache\'] = '.calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent).';'; |
| 1761 | 1761 | } |
| 1762 | 1762 | |
@@ -1770,12 +1770,12 @@ discard block |
||
| 1770 | 1770 | * @param object $crit |
| 1771 | 1771 | */ |
| 1772 | 1772 | function critere_php_args_dist($idb, &$boucles, $crit){ |
| 1773 | - $boucle = &$boucles[$idb]; |
|
| 1774 | - $boucle->hash .= '$command[\'args\']=array();'; |
|
| 1775 | - foreach ($crit->param as $param){ |
|
| 1776 | - $boucle->hash .= ' |
|
| 1773 | + $boucle = &$boucles[$idb]; |
|
| 1774 | + $boucle->hash .= '$command[\'args\']=array();'; |
|
| 1775 | + foreach ($crit->param as $param){ |
|
| 1776 | + $boucle->hash .= ' |
|
| 1777 | 1777 | $command[\'args\'][] = '.calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).';'; |
| 1778 | - } |
|
| 1778 | + } |
|
| 1779 | 1779 | } |
| 1780 | 1780 | |
| 1781 | 1781 | /** |
@@ -1787,11 +1787,11 @@ discard block |
||
| 1787 | 1787 | * @param object $crit |
| 1788 | 1788 | */ |
| 1789 | 1789 | function critere_DATA_liste_dist($idb, &$boucles, $crit){ |
| 1790 | - $boucle = &$boucles[$idb]; |
|
| 1791 | - $boucle->hash .= "\n\t".'$command[\'liste\'] = array();'."\n"; |
|
| 1792 | - foreach ($crit->param as $param){ |
|
| 1793 | - $boucle->hash .= "\t".'$command[\'liste\'][] = '.calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).";\n"; |
|
| 1794 | - } |
|
| 1790 | + $boucle = &$boucles[$idb]; |
|
| 1791 | + $boucle->hash .= "\n\t".'$command[\'liste\'] = array();'."\n"; |
|
| 1792 | + foreach ($crit->param as $param){ |
|
| 1793 | + $boucle->hash .= "\t".'$command[\'liste\'][] = '.calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).";\n"; |
|
| 1794 | + } |
|
| 1795 | 1795 | } |
| 1796 | 1796 | |
| 1797 | 1797 | /** |
@@ -1803,11 +1803,11 @@ discard block |
||
| 1803 | 1803 | * @param object $crit |
| 1804 | 1804 | */ |
| 1805 | 1805 | function critere_DATA_enum_dist($idb, &$boucles, $crit){ |
| 1806 | - $boucle = &$boucles[$idb]; |
|
| 1807 | - $boucle->hash .= "\n\t".'$command[\'enum\'] = array();'."\n"; |
|
| 1808 | - foreach ($crit->param as $param){ |
|
| 1809 | - $boucle->hash .= "\t".'$command[\'enum\'][] = '.calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).";\n"; |
|
| 1810 | - } |
|
| 1806 | + $boucle = &$boucles[$idb]; |
|
| 1807 | + $boucle->hash .= "\n\t".'$command[\'enum\'] = array();'."\n"; |
|
| 1808 | + foreach ($crit->param as $param){ |
|
| 1809 | + $boucle->hash .= "\t".'$command[\'enum\'][] = '.calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).";\n"; |
|
| 1810 | + } |
|
| 1811 | 1811 | } |
| 1812 | 1812 | |
| 1813 | 1813 | /** |
@@ -1819,11 +1819,11 @@ discard block |
||
| 1819 | 1819 | * @param object $crit |
| 1820 | 1820 | */ |
| 1821 | 1821 | function critere_DATA_datapath_dist($idb, &$boucles, $crit){ |
| 1822 | - $boucle = &$boucles[$idb]; |
|
| 1823 | - foreach ($crit->param as $param){ |
|
| 1824 | - $boucle->hash .= ' |
|
| 1822 | + $boucle = &$boucles[$idb]; |
|
| 1823 | + foreach ($crit->param as $param){ |
|
| 1824 | + $boucle->hash .= ' |
|
| 1825 | 1825 | $command[\'datapath\'][] = '.calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).';'; |
| 1826 | - } |
|
| 1826 | + } |
|
| 1827 | 1827 | } |
| 1828 | 1828 | |
| 1829 | 1829 | |
@@ -1835,20 +1835,20 @@ discard block |
||
| 1835 | 1835 | * @param object $crit |
| 1836 | 1836 | */ |
| 1837 | 1837 | function critere_si_dist($idb, &$boucles, $crit){ |
| 1838 | - $boucle = &$boucles[$idb]; |
|
| 1839 | - // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 1840 | - // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 1841 | - // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 1842 | - $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 1843 | - if ($crit->param){ |
|
| 1844 | - foreach ($crit->param as $param){ |
|
| 1845 | - $boucle->hash .= "\t\$command['si'][] = " |
|
| 1846 | - . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 1847 | - } |
|
| 1848 | - // interdire {si 0} aussi ! |
|
| 1849 | - } else { |
|
| 1850 | - $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 1851 | - } |
|
| 1838 | + $boucle = &$boucles[$idb]; |
|
| 1839 | + // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 1840 | + // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 1841 | + // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 1842 | + $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 1843 | + if ($crit->param){ |
|
| 1844 | + foreach ($crit->param as $param){ |
|
| 1845 | + $boucle->hash .= "\t\$command['si'][] = " |
|
| 1846 | + . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 1847 | + } |
|
| 1848 | + // interdire {si 0} aussi ! |
|
| 1849 | + } else { |
|
| 1850 | + $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 1851 | + } |
|
| 1852 | 1852 | } |
| 1853 | 1853 | |
| 1854 | 1854 | /** |
@@ -1860,8 +1860,8 @@ discard block |
||
| 1860 | 1860 | * @param object $crit |
| 1861 | 1861 | */ |
| 1862 | 1862 | function critere_POUR_tableau_dist($idb, &$boucles, $crit){ |
| 1863 | - $boucle = &$boucles[$idb]; |
|
| 1864 | - $boucle->hash .= ' |
|
| 1863 | + $boucle = &$boucles[$idb]; |
|
| 1864 | + $boucle->hash .= ' |
|
| 1865 | 1865 | $command[\'source\'] = array('.calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent).'); |
| 1866 | 1866 | $command[\'sourcemode\'] = \'table\';'; |
| 1867 | 1867 | } |
@@ -1878,28 +1878,28 @@ discard block |
||
| 1878 | 1878 | * @param Object $crit |
| 1879 | 1879 | */ |
| 1880 | 1880 | function critere_noeud_dist($idb, &$boucles, $crit){ |
| 1881 | - global $exceptions_des_tables; |
|
| 1882 | - $not = $crit->not; |
|
| 1883 | - $boucle = &$boucles[$idb]; |
|
| 1884 | - $primary = $boucle->primary; |
|
| 1885 | - |
|
| 1886 | - if (!$primary OR strpos($primary, ',')){ |
|
| 1887 | - erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 1888 | - return; |
|
| 1889 | - } |
|
| 1890 | - $table = $boucle->type_requete; |
|
| 1891 | - $table_sql = table_objet_sql(objet_type($table)); |
|
| 1892 | - |
|
| 1893 | - $id_parent = isset($exceptions_des_tables[$boucle->id_table]['id_parent']) ? |
|
| 1894 | - $exceptions_des_tables[$boucle->id_table]['id_parent'] : |
|
| 1895 | - 'id_parent'; |
|
| 1896 | - |
|
| 1897 | - $in = "IN"; |
|
| 1898 | - $where = array("'IN'", "'$boucle->id_table."."$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 1899 | - if ($not) |
|
| 1900 | - $where = array("'NOT'", $where); |
|
| 1901 | - |
|
| 1902 | - $boucle->where[] = $where; |
|
| 1881 | + global $exceptions_des_tables; |
|
| 1882 | + $not = $crit->not; |
|
| 1883 | + $boucle = &$boucles[$idb]; |
|
| 1884 | + $primary = $boucle->primary; |
|
| 1885 | + |
|
| 1886 | + if (!$primary OR strpos($primary, ',')){ |
|
| 1887 | + erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 1888 | + return; |
|
| 1889 | + } |
|
| 1890 | + $table = $boucle->type_requete; |
|
| 1891 | + $table_sql = table_objet_sql(objet_type($table)); |
|
| 1892 | + |
|
| 1893 | + $id_parent = isset($exceptions_des_tables[$boucle->id_table]['id_parent']) ? |
|
| 1894 | + $exceptions_des_tables[$boucle->id_table]['id_parent'] : |
|
| 1895 | + 'id_parent'; |
|
| 1896 | + |
|
| 1897 | + $in = "IN"; |
|
| 1898 | + $where = array("'IN'", "'$boucle->id_table."."$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 1899 | + if ($not) |
|
| 1900 | + $where = array("'NOT'", $where); |
|
| 1901 | + |
|
| 1902 | + $boucle->where[] = $where; |
|
| 1903 | 1903 | } |
| 1904 | 1904 | |
| 1905 | 1905 | /** |
@@ -1913,10 +1913,10 @@ discard block |
||
| 1913 | 1913 | * @param Object $crit |
| 1914 | 1914 | */ |
| 1915 | 1915 | function critere_feuille_dist($idb, &$boucles, $crit){ |
| 1916 | - $not = $crit->not; |
|
| 1917 | - $crit->not = $not ? false : true; |
|
| 1918 | - critere_noeud_dist($idb, $boucles, $crit); |
|
| 1919 | - $crit->not = $not; |
|
| 1916 | + $not = $crit->not; |
|
| 1917 | + $crit->not = $not ? false : true; |
|
| 1918 | + critere_noeud_dist($idb, $boucles, $crit); |
|
| 1919 | + $crit->not = $not; |
|
| 1920 | 1920 | } |
| 1921 | 1921 | |
| 1922 | 1922 | ?> |
@@ -16,7 +16,9 @@ discard block |
||
| 16 | 16 | * @package SPIP\Compilateur\Criteres |
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 19 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 20 | + return; |
|
| 21 | +} |
|
| 20 | 22 | |
| 21 | 23 | /** |
| 22 | 24 | * Une Regexp repérant une chaine produite par le compilateur, |
@@ -78,8 +80,9 @@ discard block |
||
| 78 | 80 | $boucle = &$boucles[$idb]; |
| 79 | 81 | $id = $boucle->primary; |
| 80 | 82 | |
| 81 | - if ($not OR !$id) |
|
| 82 | - return (array('zbug_critere_inconnu', array('critere' => $not.$crit->op))); |
|
| 83 | + if ($not OR !$id) { |
|
| 84 | + return (array('zbug_critere_inconnu', array('critere' => $not.$crit->op))); |
|
| 85 | + } |
|
| 83 | 86 | $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
| 84 | 87 | $boucle->where[] = array("'!='", "'$boucle->id_table."."$id'", $arg); |
| 85 | 88 | } |
@@ -195,8 +198,12 @@ discard block |
||
| 195 | 198 | * AST complété de la gestion du critère |
| 196 | 199 | **/ |
| 197 | 200 | function critere_lang_select_dist($idb, &$boucles, $crit){ |
| 198 | - if (!isset($crit->param[1][0]) OR !($param = $crit->param[1][0]->texte)) $param = 'oui'; |
|
| 199 | - if ($crit->not) $param = ($param=='oui') ? 'non' : 'oui'; |
|
| 201 | + if (!isset($crit->param[1][0]) OR !($param = $crit->param[1][0]->texte)) { |
|
| 202 | + $param = 'oui'; |
|
| 203 | + } |
|
| 204 | + if ($crit->not) { |
|
| 205 | + $param = ($param=='oui') ? 'non' : 'oui'; |
|
| 206 | + } |
|
| 200 | 207 | $boucle = &$boucles[$idb]; |
| 201 | 208 | $boucle->lang_select = $param; |
| 202 | 209 | } |
@@ -214,8 +221,10 @@ discard block |
||
| 214 | 221 | '"]) . ",'. |
| 215 | 222 | $deux. |
| 216 | 223 | '"'; |
| 217 | - } else calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 218 | -} |
|
| 224 | + } else { |
|
| 225 | + calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 226 | + } |
|
| 227 | + } |
|
| 219 | 228 | |
| 220 | 229 | // {pagination} |
| 221 | 230 | // {pagination 20} |
@@ -263,9 +272,10 @@ discard block |
||
| 263 | 272 | if ($boucle->primary |
| 264 | 273 | AND !preg_match('/[,\s]/', $boucle->primary) |
| 265 | 274 | AND !in_array($t, $boucle->select) |
| 266 | - ) |
|
| 267 | - $boucle->select[] = $t; |
|
| 268 | -} |
|
| 275 | + ) { |
|
| 276 | + $boucle->select[] = $t; |
|
| 277 | + } |
|
| 278 | + } |
|
| 269 | 279 | |
| 270 | 280 | |
| 271 | 281 | // {recherche} ou {recherche susan} |
@@ -280,10 +290,11 @@ discard block |
||
| 280 | 290 | return; |
| 281 | 291 | } |
| 282 | 292 | |
| 283 | - if (isset($crit->param[0])) |
|
| 284 | - $quoi = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 285 | - else |
|
| 286 | - $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 293 | + if (isset($crit->param[0])) { |
|
| 294 | + $quoi = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 295 | + } else { |
|
| 296 | + $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 297 | + } |
|
| 287 | 298 | |
| 288 | 299 | $_modificateur = var_export($boucle->modificateur, true); |
| 289 | 300 | $boucle->hash .= ' |
@@ -300,8 +311,10 @@ discard block |
||
| 300 | 311 | |
| 301 | 312 | |
| 302 | 313 | $t = $boucle->id_table.'.'.$boucle->primary; |
| 303 | - if (!in_array($t, $boucles[$idb]->select)) |
|
| 304 | - $boucle->select[] = $t; # pour postgres, neuneu ici |
|
| 314 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 315 | + $boucle->select[] = $t; |
|
| 316 | + } |
|
| 317 | + # pour postgres, neuneu ici |
|
| 305 | 318 | // jointure uniquement sur le serveur principal |
| 306 | 319 | // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
| 307 | 320 | if (!$boucle->sql_serveur){ |
@@ -417,8 +430,9 @@ discard block |
||
| 417 | 430 | $champ = array_shift($decompose); |
| 418 | 431 | $boucle->where[] = array("'='", _q($cle.".".reset($decompose)), '"'.sql_quote(end($decompose)).'"'); |
| 419 | 432 | } |
| 433 | + } else { |
|
| 434 | + $cle = $boucle->id_table; |
|
| 420 | 435 | } |
| 421 | - else $cle = $boucle->id_table; |
|
| 422 | 436 | |
| 423 | 437 | $c = "sql_in('$cle".".$champ', calcul_branche_in($arg)" |
| 424 | 438 | .($not ? ", 'NOT'" : '').")"; |
@@ -437,13 +451,16 @@ discard block |
||
| 437 | 451 | $boucle->id_table.'.'.$boucle->primary |
| 438 | 452 | ."', lister_objets_avec_logos('".$boucle->primary."'), '')"; |
| 439 | 453 | |
| 440 | - if ($crit->cond) $c = "($arg ? $c : 1)"; |
|
| 454 | + if ($crit->cond) { |
|
| 455 | + $c = "($arg ? $c : 1)"; |
|
| 456 | + } |
|
| 441 | 457 | |
| 442 | - if ($not) |
|
| 443 | - $boucle->where[] = array("'NOT'", $c); |
|
| 444 | - else |
|
| 445 | - $boucle->where[] = $c; |
|
| 446 | -} |
|
| 458 | + if ($not) { |
|
| 459 | + $boucle->where[] = array("'NOT'", $c); |
|
| 460 | + } else { |
|
| 461 | + $boucle->where[] = $c; |
|
| 462 | + } |
|
| 463 | + } |
|
| 447 | 464 | |
| 448 | 465 | // c'est la commande SQL "GROUP BY" |
| 449 | 466 | // par exemple <boucle(articles){fusion lang}> |
@@ -456,7 +473,9 @@ discard block |
||
| 456 | 473 | if (preg_match("/^(.*)\.(.*)$/", $t, $r)){ |
| 457 | 474 | $t = table_objet_sql($r[1]); |
| 458 | 475 | $t = array_search($t, $boucles[$idb]->from); |
| 459 | - if ($t) $t .= '.'.$r[2]; |
|
| 476 | + if ($t) { |
|
| 477 | + $t .= '.'.$r[2]; |
|
| 478 | + } |
|
| 460 | 479 | } |
| 461 | 480 | } else { |
| 462 | 481 | $t = '".' |
@@ -466,11 +485,13 @@ discard block |
||
| 466 | 485 | } |
| 467 | 486 | if ($t){ |
| 468 | 487 | $boucles[$idb]->group[] = $t; |
| 469 | - if (!in_array($t, $boucles[$idb]->select)) |
|
| 470 | - $boucles[$idb]->select[] = $t; |
|
| 471 | - } else |
|
| 472 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op.' ?'))); |
|
| 473 | -} |
|
| 488 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 489 | + $boucles[$idb]->select[] = $t; |
|
| 490 | + } |
|
| 491 | + } else { |
|
| 492 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op.' ?'))); |
|
| 493 | + } |
|
| 494 | + } |
|
| 474 | 495 | |
| 475 | 496 | // c'est la commande SQL "COLLATE" |
| 476 | 497 | // qui peut etre appliquee sur les order by, group by, where like ... |
@@ -481,11 +502,13 @@ discard block |
||
| 481 | 502 | $boucle = $boucles[$idb]; |
| 482 | 503 | $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
| 483 | 504 | $n = count($boucle->order); |
| 484 | - if ($n && (strpos($boucle->order[$n-1], 'COLLATE')===false)) |
|
| 485 | - $boucle->order[$n-1] .= " . ".$boucle->modificateur['collate']; |
|
| 486 | - } else |
|
| 487 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op." ".count($boucles[$idb]->order)))); |
|
| 488 | -} |
|
| 505 | + if ($n && (strpos($boucle->order[$n-1], 'COLLATE')===false)) { |
|
| 506 | + $boucle->order[$n-1] .= " . ".$boucle->modificateur['collate']; |
|
| 507 | + } |
|
| 508 | + } else { |
|
| 509 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op." ".count($boucles[$idb]->order)))); |
|
| 510 | + } |
|
| 511 | + } |
|
| 489 | 512 | |
| 490 | 513 | // http://doc.spip.org/@calculer_critere_arg_dynamique |
| 491 | 514 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = ''){ |
@@ -498,7 +521,9 @@ discard block |
||
| 498 | 521 | $desc = implode(',', array_map('_q', array_keys($desc))); |
| 499 | 522 | $boucles[$idb]->in .= "\n\tstatic $var = array(".$desc.");"; |
| 500 | 523 | } |
| 501 | - if ($desc) $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 524 | + if ($desc) { |
|
| 525 | + $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 526 | + } |
|
| 502 | 527 | $arg = calculer_liste($crit, array(), $boucles, $boucle->id_parent); |
| 503 | 528 | return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
| 504 | 529 | } |
@@ -514,7 +539,9 @@ discard block |
||
| 514 | 539 | function critere_parinverse($idb, &$boucles, $crit, $sens = ''){ |
| 515 | 540 | global $exceptions_des_jointures; |
| 516 | 541 | $boucle = &$boucles[$idb]; |
| 517 | - if ($crit->not) $sens = $sens ? "" : " . ' DESC'"; |
|
| 542 | + if ($crit->not) { |
|
| 543 | + $sens = $sens ? "" : " . ' DESC'"; |
|
| 544 | + } |
|
| 518 | 545 | $collecte = (isset($boucle->modificateur['collecte'])) ? " . ".$boucle->modificateur['collecte'] : ""; |
| 519 | 546 | |
| 520 | 547 | foreach ($crit->param as $tri){ |
@@ -528,8 +555,9 @@ discard block |
||
| 528 | 555 | // pour supporter 'hasard' comme tri dynamique |
| 529 | 556 | $par = "rand()"; |
| 530 | 557 | $parha = $par." AS hasard"; |
| 531 | - if (!in_array($parha, $boucle->select)) |
|
| 532 | - $boucle->select[] = $parha; |
|
| 558 | + if (!in_array($parha, $boucle->select)) { |
|
| 559 | + $boucle->select[] = $parha; |
|
| 560 | + } |
|
| 533 | 561 | } else { |
| 534 | 562 | $par = array_shift($tri); |
| 535 | 563 | $par = $par->texte; |
@@ -566,8 +594,9 @@ discard block |
||
| 566 | 594 | if ($cle) { $cle .= '.'; } |
| 567 | 595 | $texte = '0+'. $cle . $champ; |
| 568 | 596 | $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
| 569 | - if ($suite!=="''") |
|
| 570 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')"." . \""; |
|
| 597 | + if ($suite!=="''") { |
|
| 598 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')"." . \""; |
|
| 599 | + } |
|
| 571 | 600 | $as = 'num'.($boucle->order ? count($boucle->order) : ""); |
| 572 | 601 | $boucle->select[] = $texte." AS $as"; |
| 573 | 602 | $order = "'$as'"; |
@@ -589,10 +618,10 @@ discard block |
||
| 589 | 618 | else if (isset($exceptions_des_jointures[$par])){ |
| 590 | 619 | list($table, $champ) = $exceptions_des_jointures[$par]; |
| 591 | 620 | $order = critere_par_joint($table, $champ, $boucle, $idb); |
| 592 | - if (!$order) |
|
| 593 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op." $par"))); |
|
| 594 | - } |
|
| 595 | - else if ($par=='date' |
|
| 621 | + if (!$order) { |
|
| 622 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op." $par"))); |
|
| 623 | + } |
|
| 624 | + } else if ($par=='date' |
|
| 596 | 625 | AND $desc = $boucle->show |
| 597 | 626 | AND $desc['date'] |
| 598 | 627 | ){ |
@@ -608,11 +637,14 @@ discard block |
||
| 608 | 637 | } |
| 609 | 638 | if (!$t){ |
| 610 | 639 | return (array('zbug_critere_inconnu', array('critere' => $crit->op." $par"))); |
| 611 | - } else $order = "'".$t.'.'.$r[2]."'"; |
|
| 640 | + } else { |
|
| 641 | + $order = "'".$t.'.'.$r[2]."'"; |
|
| 642 | + } |
|
| 612 | 643 | } else { |
| 613 | 644 | $desc = $boucle->show; |
| 614 | - if ($desc['field'][$par]) |
|
| 615 | - $par = $boucle->id_table.".".$par; |
|
| 645 | + if ($desc['field'][$par]) { |
|
| 646 | + $par = $boucle->id_table.".".$par; |
|
| 647 | + } |
|
| 616 | 648 | // sinon tant pis, ca doit etre un champ synthetise (cf points) |
| 617 | 649 | $order = "'$par'"; |
| 618 | 650 | } |
@@ -624,16 +656,21 @@ discard block |
||
| 624 | 656 | if (strpos($t, '.') AND !in_array($t, $boucle->select)){ |
| 625 | 657 | $boucle->select[] = $t; |
| 626 | 658 | } |
| 627 | - } else $sens = ''; |
|
| 659 | + } else { |
|
| 660 | + $sens = ''; |
|
| 661 | + } |
|
| 628 | 662 | |
| 629 | 663 | if ($fct){ |
| 630 | - if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) |
|
| 631 | - $order = "'$fct(".$r[1].")'"; |
|
| 632 | - else $order = "'$fct(' . $order . ')'"; |
|
| 664 | + if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 665 | + $order = "'$fct(".$r[1].")'"; |
|
| 666 | + } else { |
|
| 667 | + $order = "'$fct(' . $order . ')'"; |
|
| 668 | + } |
|
| 633 | 669 | } |
| 634 | 670 | $t = $order.$collecte.$sens; |
| 635 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) |
|
| 636 | - $t = $r[1].$r[2]; |
|
| 671 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 672 | + $t = $r[1].$r[2]; |
|
| 673 | + } |
|
| 637 | 674 | $boucle->order[] = $t; |
| 638 | 675 | } |
| 639 | 676 | } |
@@ -641,7 +678,9 @@ discard block |
||
| 641 | 678 | // http://doc.spip.org/@critere_par_joint |
| 642 | 679 | function critere_par_joint($table, $champ, &$boucle, $idb){ |
| 643 | 680 | $t = array_search($table, $boucle->from); |
| 644 | - if (!$t) $t = trouver_jointure_champ($champ, $boucle); |
|
| 681 | + if (!$t) { |
|
| 682 | + $t = trouver_jointure_champ($champ, $boucle); |
|
| 683 | + } |
|
| 645 | 684 | return !$t ? '' : ("'".$t.'.'.$champ."'"); |
| 646 | 685 | } |
| 647 | 686 | |
@@ -653,9 +692,9 @@ discard block |
||
| 653 | 692 | |
| 654 | 693 | $boucle = &$boucles[$idb]; |
| 655 | 694 | // Classement par ordre inverse |
| 656 | - if ($crit->not) |
|
| 657 | - critere_parinverse($idb, $boucles, $crit); |
|
| 658 | - else |
|
| 695 | + if ($crit->not) { |
|
| 696 | + critere_parinverse($idb, $boucles, $crit); |
|
| 697 | + } else |
|
| 659 | 698 | { |
| 660 | 699 | $order = "' DESC'"; |
| 661 | 700 | // Classement par ordre inverse fonction eventuelle de #ENV{...} |
@@ -666,14 +705,16 @@ discard block |
||
| 666 | 705 | |
| 667 | 706 | $n = count($boucle->order); |
| 668 | 707 | if (!$n){ |
| 669 | - if (isset($boucle->default_order[0])) |
|
| 670 | - $boucle->default_order[0] .= ' . " DESC"'; |
|
| 671 | - else |
|
| 672 | - $boucle->default_order[] = ' DESC'; |
|
| 708 | + if (isset($boucle->default_order[0])) { |
|
| 709 | + $boucle->default_order[0] .= ' . " DESC"'; |
|
| 710 | + } else { |
|
| 711 | + $boucle->default_order[] = ' DESC'; |
|
| 712 | + } |
|
| 673 | 713 | } else { |
| 674 | 714 | $t = $boucle->order[$n-1]." . $order"; |
| 675 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) |
|
| 676 | - $t = $r[1].$r[2]; |
|
| 715 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 716 | + $t = $r[1].$r[2]; |
|
| 717 | + } |
|
| 677 | 718 | $boucle->order[$n-1] = $t; |
| 678 | 719 | } |
| 679 | 720 | } |
@@ -683,8 +724,9 @@ discard block |
||
| 683 | 724 | function critere_agenda_dist($idb, &$boucles, $crit){ |
| 684 | 725 | $params = $crit->param; |
| 685 | 726 | |
| 686 | - if (count($params)<1) |
|
| 687 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op." ?"))); |
|
| 727 | + if (count($params)<1) { |
|
| 728 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op." ?"))); |
|
| 729 | + } |
|
| 688 | 730 | |
| 689 | 731 | $parent = $boucles[$idb]->id_parent; |
| 690 | 732 | |
@@ -731,26 +773,27 @@ discard block |
||
| 731 | 773 | $date = $boucle->id_table.".$date"; |
| 732 | 774 | |
| 733 | 775 | $quote_end = ",'".$boucle->sql_serveur."','text'"; |
| 734 | - if ($type=='jour') |
|
| 735 | - $boucle->where[] = array("'='", "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 776 | + if ($type=='jour') { |
|
| 777 | + $boucle->where[] = array("'='", "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 736 | 778 | ("sql_quote($annee . $mois . $jour$quote_end)")); |
| 737 | - elseif ($type=='mois') |
|
| 738 | - $boucle->where[] = array("'='", "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 779 | + } elseif ($type=='mois') { |
|
| 780 | + $boucle->where[] = array("'='", "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 739 | 781 | ("sql_quote($annee . $mois$quote_end)")); |
| 740 | - elseif ($type=='semaine') |
|
| 741 | - $boucle->where[] = array("'AND'", |
|
| 782 | + } elseif ($type=='semaine') { |
|
| 783 | + $boucle->where[] = array("'AND'", |
|
| 742 | 784 | array("'>='", |
| 743 | 785 | "'DATE_FORMAT($date, \'%Y%m%d\')'", |
| 744 | 786 | ("date_debut_semaine($annee, $mois, $jour)")), |
| 745 | 787 | array("'<='", |
| 746 | 788 | "'DATE_FORMAT($date, \'%Y%m%d\')'", |
| 747 | 789 | ("date_fin_semaine($annee, $mois, $jour)"))); |
| 748 | - elseif (count($crit->param)>2) |
|
| 749 | - $boucle->where[] = array("'AND'", |
|
| 790 | + } elseif (count($crit->param)>2) { |
|
| 791 | + $boucle->where[] = array("'AND'", |
|
| 750 | 792 | array("'>='", |
| 751 | 793 | "'DATE_FORMAT($date, \'%Y%m%d\')'", |
| 752 | 794 | ("sql_quote($annee . $mois . $jour$quote_end)")), |
| 753 | 795 | array("'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)"))); |
| 796 | + } |
|
| 754 | 797 | // sinon on prend tout |
| 755 | 798 | } |
| 756 | 799 | |
@@ -766,8 +809,7 @@ discard block |
||
| 766 | 809 | |
| 767 | 810 | if (($op==',') && (is_numeric($a11) && (is_numeric($a21)))){ |
| 768 | 811 | $boucle->limit = $a11.','.$a21; |
| 769 | - } |
|
| 770 | - else { |
|
| 812 | + } else { |
|
| 771 | 813 | $boucle->total_parties = ($a21!='n') ? $a21 : $a22; |
| 772 | 814 | $partie = ($a11!='n') ? $a11 : $a12; |
| 773 | 815 | $mode = (($op=='/') ? '/' : |
@@ -778,9 +820,9 @@ discard block |
||
| 778 | 820 | (is_numeric($a11)?"'$a11'":$a11) |
| 779 | 821 | .".','." |
| 780 | 822 | .(is_numeric($a21)?"'$a21'":$a21); |
| 823 | + } else { |
|
| 824 | + calculer_parties($boucles, $idb, $partie, $mode); |
|
| 781 | 825 | } |
| 782 | - else |
|
| 783 | - calculer_parties($boucles, $idb, $partie, $mode); |
|
| 784 | 826 | } |
| 785 | 827 | } |
| 786 | 828 | |
@@ -803,7 +845,9 @@ discard block |
||
| 803 | 845 | $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
| 804 | 846 | } else { |
| 805 | 847 | // cas {n-1,x} |
| 806 | - if ($op1=='-') $debut = "$nombre_boucle - $debut;"; |
|
| 848 | + if ($op1=='-') { |
|
| 849 | + $debut = "$nombre_boucle - $debut;"; |
|
| 850 | + } |
|
| 807 | 851 | |
| 808 | 852 | // cas {x,n-1} |
| 809 | 853 | if ($op2=='-'){ |
@@ -853,12 +897,14 @@ discard block |
||
| 853 | 897 | } else { |
| 854 | 898 | preg_match(',^ *(([0-9]+)|n) *(- *([0-9]+)? *)?$,', $param[0]->texte, $m); |
| 855 | 899 | $a1 = $m[1]; |
| 856 | - if (!@$m[3]) |
|
| 857 | - return array($a1, 0); |
|
| 858 | - elseif ($m[4]) |
|
| 859 | - return array($a1, $m[4]); |
|
| 860 | - else return array($a1, |
|
| 900 | + if (!@$m[3]) { |
|
| 901 | + return array($a1, 0); |
|
| 902 | + } elseif ($m[4]) { |
|
| 903 | + return array($a1, $m[4]); |
|
| 904 | + } else { |
|
| 905 | + return array($a1, |
|
| 861 | 906 | calculer_liste(array($param[1]), array(), $boucles[$idb]->id_parent, $boucles)); |
| 907 | + } |
|
| 862 | 908 | } |
| 863 | 909 | } |
| 864 | 910 | |
@@ -893,7 +939,9 @@ discard block |
||
| 893 | 939 | |
| 894 | 940 | $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
| 895 | 941 | // s'il y avait une erreur de syntaxe, propager cette info |
| 896 | - if (!is_array($boucle->criteres)) return array(); |
|
| 942 | + if (!is_array($boucle->criteres)) { |
|
| 943 | + return array(); |
|
| 944 | + } |
|
| 897 | 945 | |
| 898 | 946 | foreach ($boucle->criteres as $crit){ |
| 899 | 947 | $critere = $crit->op; |
@@ -938,11 +986,12 @@ discard block |
||
| 938 | 986 | * @return string |
| 939 | 987 | */ |
| 940 | 988 | function kwote($lisp, $serveur='', $type=''){ |
| 941 | - if (preg_match(_CODE_QUOTE, $lisp, $r)) |
|
| 942 | - return $r[1]."\"".sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]),$serveur,$type)."\""; |
|
| 943 | - else |
|
| 944 | - return "sql_quote($lisp)"; |
|
| 945 | -} |
|
| 989 | + if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 990 | + return $r[1]."\"".sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]),$serveur,$type)."\""; |
|
| 991 | + } else { |
|
| 992 | + return "sql_quote($lisp)"; |
|
| 993 | + } |
|
| 994 | + } |
|
| 946 | 995 | |
| 947 | 996 | // Si on a une liste de valeurs dans #ENV{x}, utiliser la double etoile |
| 948 | 997 | // pour faire par exemple {id_article IN #ENV**{liste_articles}} |
@@ -961,21 +1010,26 @@ discard block |
||
| 961 | 1010 | if ($crit->cond){ |
| 962 | 1011 | $pred = calculer_argument_precedent($idb, $col, $boucles); |
| 963 | 1012 | $where = array("'?'", $pred, $where, "''"); |
| 964 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1013 | + if ($where_complement) { |
|
| 1014 | + // condition annexe du type "AND (objet='article')" |
|
| 965 | 1015 | $where_complement = array("'?'", $pred, $where_complement, "''"); |
| 1016 | + } |
|
| 966 | 1017 | } |
| 967 | - if ($crit->exclus) |
|
| 968 | - if (!preg_match(",^L[0-9]+[.],", $arg)) |
|
| 1018 | + if ($crit->exclus) { |
|
| 1019 | + if (!preg_match(",^L[0-9]+[.],", $arg)) |
|
| 969 | 1020 | $where = array("'NOT'", $where); |
| 970 | - else |
|
| 971 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1021 | + } else { |
|
| 1022 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 972 | 1023 | // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
| 973 | 1024 | $where = array("'NOT'", array("'IN'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", array("'SELF'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", $where))); |
| 1025 | + } |
|
| 974 | 1026 | |
| 975 | 1027 | $boucles[$idb]->where[] = $where; |
| 976 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1028 | + if ($where_complement) { |
|
| 1029 | + // condition annexe du type "AND (objet='article')" |
|
| 977 | 1030 | $boucles[$idb]->where[] = $where_complement; |
| 978 | -} |
|
| 1031 | + } |
|
| 1032 | + } |
|
| 979 | 1033 | |
| 980 | 1034 | // http://doc.spip.org/@critere_IN_cas |
| 981 | 1035 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col){ |
@@ -988,10 +1042,11 @@ discard block |
||
| 988 | 1042 | foreach ($val as $k => $v){ |
| 989 | 1043 | if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)){ |
| 990 | 1044 | // optimiser le traitement des constantes |
| 991 | - if (is_numeric($r[2])) |
|
| 992 | - $x .= "\n\t$var"."[]= $r[2];"; |
|
| 993 | - else |
|
| 994 | - $x .= "\n\t$var"."[]= ".sql_quote($r[2]).";"; |
|
| 1045 | + if (is_numeric($r[2])) { |
|
| 1046 | + $x .= "\n\t$var"."[]= $r[2];"; |
|
| 1047 | + } else { |
|
| 1048 | + $x .= "\n\t$var"."[]= ".sql_quote($r[2]).";"; |
|
| 1049 | + } |
|
| 995 | 1050 | } else { |
| 996 | 1051 | // Pour permettre de passer des tableaux de valeurs |
| 997 | 1052 | // on repere l'utilisation brute de #ENV**{X}, |
@@ -1024,16 +1079,19 @@ discard block |
||
| 1024 | 1079 | */ |
| 1025 | 1080 | function critere_where_dist($idb, &$boucles, $crit){ |
| 1026 | 1081 | $boucle = &$boucles[$idb]; |
| 1027 | - if (isset($crit->param[0])) |
|
| 1028 | - $_where = calculer_liste($crit->param[0], array(), $boucles, $boucle->id_parent); |
|
| 1029 | - else |
|
| 1030 | - $_where = '@$Pile[0]["where"]'; |
|
| 1082 | + if (isset($crit->param[0])) { |
|
| 1083 | + $_where = calculer_liste($crit->param[0], array(), $boucles, $boucle->id_parent); |
|
| 1084 | + } else { |
|
| 1085 | + $_where = '@$Pile[0]["where"]'; |
|
| 1086 | + } |
|
| 1031 | 1087 | |
| 1032 | - if ($crit->cond) |
|
| 1033 | - $_where = "(($_where) ? ($_where) : '')"; |
|
| 1088 | + if ($crit->cond) { |
|
| 1089 | + $_where = "(($_where) ? ($_where) : '')"; |
|
| 1090 | + } |
|
| 1034 | 1091 | |
| 1035 | - if ($crit->not) |
|
| 1036 | - $_where = "array('NOT',$_where)"; |
|
| 1092 | + if ($crit->not) { |
|
| 1093 | + $_where = "array('NOT',$_where)"; |
|
| 1094 | + } |
|
| 1037 | 1095 | |
| 1038 | 1096 | $boucle->where[] = $_where; |
| 1039 | 1097 | } |
@@ -1122,8 +1180,9 @@ discard block |
||
| 1122 | 1180 | // http://doc.spip.org/@calculer_critere_DEFAUT |
| 1123 | 1181 | function calculer_critere_DEFAUT_dist($idb, &$boucles, $crit){ |
| 1124 | 1182 | // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
| 1125 | - if (($crit->op==",") OR ($crit->op=='/')) |
|
| 1126 | - return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1183 | + if (($crit->op==",") OR ($crit->op=='/')) { |
|
| 1184 | + return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1185 | + } |
|
| 1127 | 1186 | |
| 1128 | 1187 | $r = calculer_critere_infixe($idb, $boucles, $crit); |
| 1129 | 1188 | if (!$r){ |
@@ -1131,8 +1190,10 @@ discard block |
||
| 1131 | 1190 | # if (!$crit->cond) { |
| 1132 | 1191 | return (array('zbug_critere_inconnu', array('critere' => $crit->op))); |
| 1133 | 1192 | # } |
| 1134 | - } else calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1135 | -} |
|
| 1193 | + } else { |
|
| 1194 | + calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1195 | + } |
|
| 1196 | + } |
|
| 1136 | 1197 | |
| 1137 | 1198 | function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args){ |
| 1138 | 1199 | list($arg, $op, $val, $col, $where_complement) = $args; |
@@ -1141,14 +1202,17 @@ discard block |
||
| 1141 | 1202 | |
| 1142 | 1203 | // inserer la negation (cf !...) |
| 1143 | 1204 | |
| 1144 | - if ($crit->not) $where = array("'NOT'", $where); |
|
| 1145 | - if ($crit->exclus) |
|
| 1146 | - if (!preg_match(",^L[0-9]+[.],", $arg)) |
|
| 1205 | + if ($crit->not) { |
|
| 1206 | + $where = array("'NOT'", $where); |
|
| 1207 | + } |
|
| 1208 | + if ($crit->exclus) { |
|
| 1209 | + if (!preg_match(",^L[0-9]+[.],", $arg)) |
|
| 1147 | 1210 | $where = array("'NOT'", $where); |
| 1148 | - else |
|
| 1149 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1211 | + } else { |
|
| 1212 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1150 | 1213 | // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
| 1151 | 1214 | $where = array("'NOT'", array("'IN'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", array("'SELF'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", $where))); |
| 1215 | + } |
|
| 1152 | 1216 | |
| 1153 | 1217 | // inserer la condition (cf {lang?}) |
| 1154 | 1218 | // traiter a part la date, elle est mise d'office par SPIP, |
@@ -1160,19 +1224,24 @@ discard block |
||
| 1160 | 1224 | } |
| 1161 | 1225 | } |
| 1162 | 1226 | |
| 1163 | - if ($op=='=' AND !$crit->not) |
|
| 1164 | - $where = array("'?'", "(is_array($pred))", |
|
| 1227 | + if ($op=='=' AND !$crit->not) { |
|
| 1228 | + $where = array("'?'", "(is_array($pred))", |
|
| 1165 | 1229 | critere_IN_cas($idb, $boucles, 'COND', $arg, $op, array($pred), $col), |
| 1166 | 1230 | $where); |
| 1231 | + } |
|
| 1167 | 1232 | $where = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where); |
| 1168 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1233 | + if ($where_complement) { |
|
| 1234 | + // condition annexe du type "AND (objet='article')" |
|
| 1169 | 1235 | $where_complement = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement); |
| 1236 | + } |
|
| 1170 | 1237 | } |
| 1171 | 1238 | |
| 1172 | 1239 | $boucles[$idb]->where[] = $where; |
| 1173 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1240 | + if ($where_complement) { |
|
| 1241 | + // condition annexe du type "AND (objet='article')" |
|
| 1174 | 1242 | $boucles[$idb]->where[] = $where_complement; |
| 1175 | -} |
|
| 1243 | + } |
|
| 1244 | + } |
|
| 1176 | 1245 | |
| 1177 | 1246 | // http://doc.spip.org/@calculer_critere_infixe |
| 1178 | 1247 | function calculer_critere_infixe($idb, &$boucles, $crit){ |
@@ -1193,13 +1262,15 @@ discard block |
||
| 1193 | 1262 | $where_complement = false; |
| 1194 | 1263 | |
| 1195 | 1264 | // Cas particulier : id_enfant => utiliser la colonne id_objet |
| 1196 | - if ($col=='id_enfant') |
|
| 1197 | - $col = $boucle->primary; |
|
| 1265 | + if ($col=='id_enfant') { |
|
| 1266 | + $col = $boucle->primary; |
|
| 1267 | + } |
|
| 1198 | 1268 | |
| 1199 | 1269 | // Cas particulier : id_parent => verifier les exceptions de tables |
| 1200 | 1270 | if (in_array($col,array('id_parent','id_secteur')) |
| 1201 | - AND isset($exceptions_des_tables[$table][$col])) |
|
| 1202 | - $col = $exceptions_des_tables[$table][$col]; |
|
| 1271 | + AND isset($exceptions_des_tables[$table][$col])) { |
|
| 1272 | + $col = $exceptions_des_tables[$table][$col]; |
|
| 1273 | + } |
|
| 1203 | 1274 | |
| 1204 | 1275 | // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
| 1205 | 1276 | else if (($col=='id_secteur') AND ($critere_secteur = charger_fonction("critere_secteur_$type", "public", true))){ |
@@ -1221,28 +1292,30 @@ discard block |
||
| 1221 | 1292 | else if ($c = calculer_critere_infixe_date($idb, $boucles, $col)){ |
| 1222 | 1293 | list($col,$col_vraie) = $c; |
| 1223 | 1294 | $table = ''; |
| 1224 | - } |
|
| 1225 | - else if (preg_match('/^(.*)\.(.*)$/', $col, $r)){ |
|
| 1295 | + } else if (preg_match('/^(.*)\.(.*)$/', $col, $r)){ |
|
| 1226 | 1296 | list(, $table, $col) = $r; |
| 1227 | 1297 | $col_alias = $col; |
| 1228 | 1298 | |
| 1229 | 1299 | $trouver_table = charger_fonction('trouver_table','base'); |
| 1230 | 1300 | if ($desc = $trouver_table($table, $boucle->sql_serveur) |
| 1231 | 1301 | AND isset($desc['field'][$col]) |
| 1232 | - AND $cle = array_search($desc['table'],$boucle->from)) |
|
| 1233 | - $table = $cle; |
|
| 1234 | - else { |
|
| 1302 | + AND $cle = array_search($desc['table'],$boucle->from)) { |
|
| 1303 | + $table = $cle; |
|
| 1304 | + } else { |
|
| 1235 | 1305 | $table = trouver_jointure_champ($col, $boucle, array($table), ($crit->cond OR $op!='=')); |
| 1236 | 1306 | } |
| 1237 | 1307 | #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
| 1238 | - if (!$table) return ''; |
|
| 1239 | - } |
|
| 1240 | - elseif (@!array_key_exists($col, $desc['field']) |
|
| 1308 | + if (!$table) { |
|
| 1309 | + return ''; |
|
| 1310 | + } |
|
| 1311 | + } elseif (@!array_key_exists($col, $desc['field']) |
|
| 1241 | 1312 | // Champ joker * des iterateurs DATA qui accepte tout |
| 1242 | 1313 | AND @!array_key_exists('*', $desc['field']) |
| 1243 | 1314 | ) { |
| 1244 | 1315 | $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
| 1245 | - if (!$r) return ''; |
|
| 1316 | + if (!$r) { |
|
| 1317 | + return ''; |
|
| 1318 | + } |
|
| 1246 | 1319 | list($col, $col_alias, $table, $where_complement, $desc) = $r; |
| 1247 | 1320 | } |
| 1248 | 1321 | |
@@ -1256,8 +1329,9 @@ discard block |
||
| 1256 | 1329 | |
| 1257 | 1330 | // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
| 1258 | 1331 | // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
| 1259 | - if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) |
|
| 1260 | - $val[0] = $r[1].'"'.sql_quote($r[2],$boucle->sql_serveur,(isset($desc['field'][$col_vraie])?$desc['field'][$col_vraie]:'int NOT NULL')).'"'; |
|
| 1332 | + if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 1333 | + $val[0] = $r[1].'"'.sql_quote($r[2],$boucle->sql_serveur,(isset($desc['field'][$col_vraie])?$desc['field'][$col_vraie]:'int NOT NULL')).'"'; |
|
| 1334 | + } |
|
| 1261 | 1335 | |
| 1262 | 1336 | // sinon expliciter les |
| 1263 | 1337 | // sql_quote(truc) en sql_quote(truc,'',type) |
@@ -1279,8 +1353,9 @@ discard block |
||
| 1279 | 1353 | // Ne pas confondre champs de la table principale et des jointures |
| 1280 | 1354 | if ($table===$boucle->id_table){ |
| 1281 | 1355 | $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
| 1282 | - if ($col_alias!=$col_vraie) |
|
| 1283 | - $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 1356 | + if ($col_alias!=$col_vraie) { |
|
| 1357 | + $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 1358 | + } |
|
| 1284 | 1359 | } |
| 1285 | 1360 | |
| 1286 | 1361 | // ajout pour le cas special d'une condition sur le champ statut: |
@@ -1288,17 +1363,25 @@ discard block |
||
| 1288 | 1363 | // de mettre ses propres criteres de statut |
| 1289 | 1364 | // http://www.spip.net/@statut (a documenter) |
| 1290 | 1365 | // garde pour compatibilite avec code des plugins anterieurs, mais redondant avec la ligne precedente |
| 1291 | - if ($col=='statut') $boucles[$idb]->statut = true; |
|
| 1366 | + if ($col=='statut') { |
|
| 1367 | + $boucles[$idb]->statut = true; |
|
| 1368 | + } |
|
| 1292 | 1369 | |
| 1293 | 1370 | // inserer le nom de la table SQL devant le nom du champ |
| 1294 | 1371 | if ($table){ |
| 1295 | - if ($col[0]=="`") |
|
| 1296 | - $arg = "$table.".substr($col, 1, -1); |
|
| 1297 | - else $arg = "$table.$col"; |
|
| 1298 | - } else $arg = $col; |
|
| 1372 | + if ($col[0]=="`") { |
|
| 1373 | + $arg = "$table.".substr($col, 1, -1); |
|
| 1374 | + } else { |
|
| 1375 | + $arg = "$table.$col"; |
|
| 1376 | + } |
|
| 1377 | + } else { |
|
| 1378 | + $arg = $col; |
|
| 1379 | + } |
|
| 1299 | 1380 | |
| 1300 | 1381 | // inserer la fonction SQL |
| 1301 | - if ($fct) $arg = "$fct($arg$args_sql)"; |
|
| 1382 | + if ($fct) { |
|
| 1383 | + $arg = "$fct($arg$args_sql)"; |
|
| 1384 | + } |
|
| 1302 | 1385 | |
| 1303 | 1386 | return array($arg, $op, $val, $col_alias, $where_complement); |
| 1304 | 1387 | } |
@@ -1324,22 +1407,23 @@ discard block |
||
| 1324 | 1407 | $index = isset($t[$col]) |
| 1325 | 1408 | ? $t[$col] : (isset($t['']) ? $t[''] : array()); |
| 1326 | 1409 | |
| 1327 | - if (count($index)==3) |
|
| 1328 | - list($t, $col, $calculer_critere_externe) = $index; |
|
| 1329 | - elseif (count($index)==2) { |
|
| 1410 | + if (count($index)==3) { |
|
| 1411 | + list($t, $col, $calculer_critere_externe) = $index; |
|
| 1412 | + } elseif (count($index)==2) { |
|
| 1330 | 1413 | list($t, $col) = $t[$col]; |
| 1331 | - } |
|
| 1332 | - elseif (count($index)==1) { |
|
| 1414 | + } elseif (count($index)==1) { |
|
| 1333 | 1415 | list($calculer_critere_externe) = $index; |
| 1334 | 1416 | $t = $table; |
| 1417 | + } else { |
|
| 1418 | + $t = ''; |
|
| 1335 | 1419 | } |
| 1336 | - else |
|
| 1337 | - $t = ''; // jointure non declaree. La trouver. |
|
| 1420 | + // jointure non declaree. La trouver. |
|
| 1421 | + } elseif (isset($exceptions_des_jointures[$col])) { |
|
| 1422 | + list($t, $col) = $exceptions_des_jointures[$col]; |
|
| 1423 | + } else { |
|
| 1424 | + $t = ''; |
|
| 1338 | 1425 | } |
| 1339 | - elseif (isset($exceptions_des_jointures[$col])) |
|
| 1340 | - list($t, $col) = $exceptions_des_jointures[$col]; |
|
| 1341 | - else |
|
| 1342 | - $t = ''; // jointure non declaree. La trouver. |
|
| 1426 | + // jointure non declaree. La trouver. |
|
| 1343 | 1427 | |
| 1344 | 1428 | // ici on construit le from pour fournir $col en piochant dans les jointures |
| 1345 | 1429 | |
@@ -1358,7 +1442,9 @@ discard block |
||
| 1358 | 1442 | $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond OR $op!='='), $t); |
| 1359 | 1443 | } |
| 1360 | 1444 | |
| 1361 | - if (!$table) return ''; |
|
| 1445 | + if (!$table) { |
|
| 1446 | + return ''; |
|
| 1447 | + } |
|
| 1362 | 1448 | |
| 1363 | 1449 | // il ne reste plus qu'a trouver le champ dans les from |
| 1364 | 1450 | list($nom, $desc) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
@@ -1425,14 +1511,19 @@ discard block |
||
| 1425 | 1511 | $joindre = false; |
| 1426 | 1512 | foreach ($cols as $col){ |
| 1427 | 1513 | $c = '/\b'.$t.".$col".'\b/'; |
| 1428 | - if (trouver_champ($c, $boucle->where)) $joindre = true; |
|
| 1429 | - else { |
|
| 1514 | + if (trouver_champ($c, $boucle->where)) { |
|
| 1515 | + $joindre = true; |
|
| 1516 | + } else { |
|
| 1430 | 1517 | // mais ca peut etre dans le FIELD pour le Having |
| 1431 | 1518 | $c = "/FIELD.$t".".$col,/"; |
| 1432 | - if (trouver_champ($c, $boucle->select)) $joindre = true; |
|
| 1519 | + if (trouver_champ($c, $boucle->select)) { |
|
| 1520 | + $joindre = true; |
|
| 1521 | + } |
|
| 1433 | 1522 | } |
| 1434 | 1523 | } |
| 1435 | - if (!$joindre) return $t; |
|
| 1524 | + if (!$joindre) { |
|
| 1525 | + return $t; |
|
| 1526 | + } |
|
| 1436 | 1527 | } |
| 1437 | 1528 | if ($res = calculer_jointure($boucle, array($boucle->id_table, $desc), $arrivee, $cols, $cond, 1)) { |
| 1438 | 1529 | return $res; |
@@ -1460,7 +1551,9 @@ discard block |
||
| 1460 | 1551 | $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee."_liens"); |
| 1461 | 1552 | $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
| 1462 | 1553 | |
| 1463 | - if (!$intermediaire OR !$arrivee) return ''; |
|
| 1554 | + if (!$intermediaire OR !$arrivee) { |
|
| 1555 | + return ''; |
|
| 1556 | + } |
|
| 1464 | 1557 | |
| 1465 | 1558 | $res = fabrique_jointures($boucle, |
| 1466 | 1559 | array( |
@@ -1474,11 +1567,13 @@ discard block |
||
| 1474 | 1567 | |
| 1475 | 1568 | // http://doc.spip.org/@trouver_champ |
| 1476 | 1569 | function trouver_champ($champ, $where){ |
| 1477 | - if (!is_array($where)) |
|
| 1478 | - return preg_match($champ, $where); |
|
| 1479 | - else { |
|
| 1570 | + if (!is_array($where)) { |
|
| 1571 | + return preg_match($champ, $where); |
|
| 1572 | + } else { |
|
| 1480 | 1573 | foreach ($where as $clause){ |
| 1481 | - if (trouver_champ($champ, $clause)) return true; |
|
| 1574 | + if (trouver_champ($champ, $clause)) { |
|
| 1575 | + return true; |
|
| 1576 | + } |
|
| 1482 | 1577 | } |
| 1483 | 1578 | return false; |
| 1484 | 1579 | } |
@@ -1493,11 +1588,13 @@ discard block |
||
| 1493 | 1588 | if (count($crit->param)==0){ |
| 1494 | 1589 | $op = '='; |
| 1495 | 1590 | $col = $val = $crit->op; |
| 1496 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) $val = $r[2]; |
|
| 1591 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 1592 | + $val = $r[2]; |
|
| 1593 | + } |
|
| 1497 | 1594 | // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
| 1498 | - if ($val=='lang') |
|
| 1499 | - $val = array(kwote('$GLOBALS[\'spip_lang\']')); |
|
| 1500 | - else { |
|
| 1595 | + if ($val=='lang') { |
|
| 1596 | + $val = array(kwote('$GLOBALS[\'spip_lang\']')); |
|
| 1597 | + } else { |
|
| 1501 | 1598 | $defaut = null; |
| 1502 | 1599 | if ($val=='id_parent') { |
| 1503 | 1600 | // Si id_parent, comparer l'id_parent avec l'id_objet |
@@ -1506,13 +1603,11 @@ discard block |
||
| 1506 | 1603 | $val = $boucles[$idb]->primary; |
| 1507 | 1604 | // mais si pas de boucle superieure, prendre id_parent dans l'env |
| 1508 | 1605 | $defaut = "\$Pile[0]['id_parent']"; |
| 1509 | - } |
|
| 1510 | - elseif ($val=='id_enfant'){ |
|
| 1606 | + } elseif ($val=='id_enfant'){ |
|
| 1511 | 1607 | // Si id_enfant, comparer l'id_objet avec l'id_parent |
| 1512 | 1608 | // de la boucle superieure |
| 1513 | 1609 | $val = 'id_parent'; |
| 1514 | - } |
|
| 1515 | - elseif ($crit->cond AND ($col=="date" OR $col=="date_redac")){ |
|
| 1610 | + } elseif ($crit->cond AND ($col=="date" OR $col=="date_redac")){ |
|
| 1516 | 1611 | // un critere conditionnel sur date est traite a part |
| 1517 | 1612 | // car la date est mise d'office par SPIP, |
| 1518 | 1613 | $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['".$col."'])"; |
@@ -1526,7 +1621,9 @@ discard block |
||
| 1526 | 1621 | // le phraseur impose que le premier param soit du texte |
| 1527 | 1622 | $params = $crit->param; |
| 1528 | 1623 | $op = $crit->op; |
| 1529 | - if ($op=='==') $op = 'REGEXP'; |
|
| 1624 | + if ($op=='==') { |
|
| 1625 | + $op = 'REGEXP'; |
|
| 1626 | + } |
|
| 1530 | 1627 | $col = array_shift($params); |
| 1531 | 1628 | $col = $col[0]->texte; |
| 1532 | 1629 | |
@@ -1546,11 +1643,16 @@ discard block |
||
| 1546 | 1643 | AND $params[0][1]->type=='champ' |
| 1547 | 1644 | ){ |
| 1548 | 1645 | $val[] = "$p\\$p#".$params[0][1]->nom_champ."\\$p$p"; |
| 1549 | - } else |
|
| 1550 | - foreach ((($op!='IN') ? $params : calculer_vieux_in($params)) as $p){ |
|
| 1646 | + } else { |
|
| 1647 | + foreach ((($op!='IN') ? $params : calculer_vieux_in($params)) as $p){ |
|
| 1551 | 1648 | $a = calculer_liste($p, $desc, $boucles, $parent); |
| 1552 | - if (strcasecmp($op,'IN')==0) $val[] = $a; |
|
| 1553 | - else $val[] = kwote($a, $boucles[$idb]->sql_serveur, 'char'); // toujours quoter en char ici |
|
| 1649 | + } |
|
| 1650 | + if (strcasecmp($op,'IN')==0) { |
|
| 1651 | + $val[] = $a; |
|
| 1652 | + } else { |
|
| 1653 | + $val[] = kwote($a, $boucles[$idb]->sql_serveur, 'char'); |
|
| 1654 | + } |
|
| 1655 | + // toujours quoter en char ici |
|
| 1554 | 1656 | } |
| 1555 | 1657 | } |
| 1556 | 1658 | |
@@ -1583,8 +1685,9 @@ discard block |
||
| 1583 | 1685 | $n = isset($last->texte) ? strlen($last->texte) : 0; |
| 1584 | 1686 | |
| 1585 | 1687 | if (!((isset($deb->texte[0]) AND $deb->texte[0]=='(') |
| 1586 | - && (isset($last->texte[$n-1]) AND $last->texte[$n-1]==')'))) |
|
| 1587 | - return $params; |
|
| 1688 | + && (isset($last->texte[$n-1]) AND $last->texte[$n-1]==')'))) { |
|
| 1689 | + return $params; |
|
| 1690 | + } |
|
| 1588 | 1691 | $params[0][0]->texte = substr($deb->texte, 1); |
| 1589 | 1692 | // attention, on peut avoir k=0,j=0 ==> recalculer |
| 1590 | 1693 | $last = $params[$k][$j]; |
@@ -1592,9 +1695,9 @@ discard block |
||
| 1592 | 1695 | $params[$k][$j]->texte = substr($last->texte, 0, $n-1); |
| 1593 | 1696 | $newp = array(); |
| 1594 | 1697 | foreach ($params as $v){ |
| 1595 | - if ($v[0]->type!='texte') |
|
| 1596 | - $newp[] = $v; |
|
| 1597 | - else { |
|
| 1698 | + if ($v[0]->type!='texte') { |
|
| 1699 | + $newp[] = $v; |
|
| 1700 | + } else { |
|
| 1598 | 1701 | foreach (explode(',', $v[0]->texte) as $x){ |
| 1599 | 1702 | $t = new Texte; |
| 1600 | 1703 | $t->texte = $x; |
@@ -1607,27 +1710,35 @@ discard block |
||
| 1607 | 1710 | |
| 1608 | 1711 | // http://doc.spip.org/@calculer_critere_infixe_date |
| 1609 | 1712 | function calculer_critere_infixe_date($idb, &$boucles, $col){ |
| 1610 | - if (!preg_match(",^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z]+)?$,", $col, $regs)) return ''; |
|
| 1713 | + if (!preg_match(",^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z]+)?$,", $col, $regs)) { |
|
| 1714 | + return ''; |
|
| 1715 | + } |
|
| 1611 | 1716 | $boucle = $boucles[$idb]; |
| 1612 | 1717 | $table = $boucle->show; |
| 1613 | 1718 | // si c'est une colonne de la table, ne rien faire |
| 1614 | - if(isset($table['field'][$col])) return ''; |
|
| 1719 | + if(isset($table['field'][$col])) { |
|
| 1720 | + return ''; |
|
| 1721 | + } |
|
| 1615 | 1722 | |
| 1616 | - if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) return ''; |
|
| 1723 | + if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 1724 | + return ''; |
|
| 1725 | + } |
|
| 1617 | 1726 | $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']])? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
| 1618 | 1727 | $col = $regs[1]; |
| 1619 | 1728 | if (isset($regs[3]) AND $suite = $regs[3]){ |
| 1620 | 1729 | # Recherche de l'existence du champ date_xxxx, |
| 1621 | 1730 | # si oui choisir ce champ, sinon choisir xxxx |
| 1622 | 1731 | |
| 1623 | - if (isset($table['field']["date$suite"])) |
|
| 1624 | - $date_orig = 'date'.$suite; |
|
| 1625 | - else |
|
| 1626 | - $date_orig = substr($suite, 1); |
|
| 1732 | + if (isset($table['field']["date$suite"])) { |
|
| 1733 | + $date_orig = 'date'.$suite; |
|
| 1734 | + } else { |
|
| 1735 | + $date_orig = substr($suite, 1); |
|
| 1736 | + } |
|
| 1627 | 1737 | $pred = $date_orig; |
| 1628 | - } |
|
| 1629 | - else |
|
| 1630 | - if (isset($regs[2]) AND $rel = $regs[2]) $pred = 'date'; |
|
| 1738 | + } else |
|
| 1739 | + if (isset($regs[2]) AND $rel = $regs[2]) { |
|
| 1740 | + $pred = 'date'; |
|
| 1741 | + } |
|
| 1631 | 1742 | |
| 1632 | 1743 | $date_compare = "\"' . normaliser_date(". |
| 1633 | 1744 | calculer_argument_precedent($idb, $pred, $boucles). |
@@ -1684,9 +1795,9 @@ discard block |
||
| 1684 | 1795 | if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)){ |
| 1685 | 1796 | $init = "'\" . (\$x = $r[1]) . \"'"; |
| 1686 | 1797 | $date_compare = '\'$x\''; |
| 1798 | + } else { |
|
| 1799 | + $init = $date_compare; |
|
| 1687 | 1800 | } |
| 1688 | - else |
|
| 1689 | - $init = $date_compare; |
|
| 1690 | 1801 | |
| 1691 | 1802 | return |
| 1692 | 1803 | "LEAST((UNIX_TIMESTAMP(". |
@@ -1722,9 +1833,10 @@ discard block |
||
| 1722 | 1833 | $boucle = &$boucles[$idb]; |
| 1723 | 1834 | |
| 1724 | 1835 | $args = array(); |
| 1725 | - foreach ($crit->param as &$param) |
|
| 1726 | - array_push($args, |
|
| 1836 | + foreach ($crit->param as &$param) { |
|
| 1837 | + array_push($args, |
|
| 1727 | 1838 | calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent)); |
| 1839 | + } |
|
| 1728 | 1840 | |
| 1729 | 1841 | $boucle->hash .= ' |
| 1730 | 1842 | $command[\'sourcemode\'] = '.array_shift($args).";\n"; |
@@ -1896,8 +2008,9 @@ discard block |
||
| 1896 | 2008 | |
| 1897 | 2009 | $in = "IN"; |
| 1898 | 2010 | $where = array("'IN'", "'$boucle->id_table."."$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
| 1899 | - if ($not) |
|
| 1900 | - $where = array("'NOT'", $where); |
|
| 2011 | + if ($not) { |
|
| 2012 | + $where = array("'NOT'", $where); |
|
| 2013 | + } |
|
| 1901 | 2014 | |
| 1902 | 2015 | $boucle->where[] = $where; |
| 1903 | 2016 | } |
@@ -44,13 +44,12 @@ discard block |
||
| 44 | 44 | * @return |
| 45 | 45 | * AST complété de la gestion du critère |
| 46 | 46 | **/ |
| 47 | -function critere_racine_dist($idb, &$boucles, $crit){ |
|
| 47 | +function critere_racine_dist($idb, &$boucles, $crit) { |
|
| 48 | 48 | global $exceptions_des_tables; |
| 49 | 49 | $not = $crit->not; |
| 50 | 50 | $boucle = &$boucles[$idb]; |
| 51 | 51 | $id_parent = isset($exceptions_des_tables[$boucle->id_table]['id_parent']) ? |
| 52 | - $exceptions_des_tables[$boucle->id_table]['id_parent'] : |
|
| 53 | - 'id_parent'; |
|
| 52 | + $exceptions_des_tables[$boucle->id_table]['id_parent'] : 'id_parent'; |
|
| 54 | 53 | |
| 55 | 54 | $c = array("'='", "'$boucle->id_table."."$id_parent'", 0); |
| 56 | 55 | $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
@@ -73,7 +72,7 @@ discard block |
||
| 73 | 72 | * @return |
| 74 | 73 | * AST complété de la gestion du critère |
| 75 | 74 | **/ |
| 76 | -function critere_exclus_dist($idb, &$boucles, $crit){ |
|
| 75 | +function critere_exclus_dist($idb, &$boucles, $crit) { |
|
| 77 | 76 | $not = $crit->not; |
| 78 | 77 | $boucle = &$boucles[$idb]; |
| 79 | 78 | $id = $boucle->primary; |
@@ -104,24 +103,24 @@ discard block |
||
| 104 | 103 | * @return |
| 105 | 104 | * AST complété de la gestion du critère |
| 106 | 105 | **/ |
| 107 | -function critere_doublons_dist($idb, &$boucles, $crit){ |
|
| 106 | +function critere_doublons_dist($idb, &$boucles, $crit) { |
|
| 108 | 107 | $boucle = &$boucles[$idb]; |
| 109 | 108 | $primary = $boucle->primary; |
| 110 | 109 | |
| 111 | 110 | // la table nécessite une clé primaire, non composée |
| 112 | - if (!$primary OR strpos($primary, ',')){ |
|
| 111 | + if (!$primary OR strpos($primary, ',')) { |
|
| 113 | 112 | return (array('zbug_doublon_sur_table_sans_cle_primaire')); |
| 114 | 113 | } |
| 115 | 114 | |
| 116 | 115 | $not = ($crit->not ? '' : 'NOT'); |
| 117 | 116 | |
| 118 | 117 | // le doublon s'applique sur un type de boucle (article) |
| 119 | - $nom = "'" . $boucle->type_requete. "'"; |
|
| 118 | + $nom = "'".$boucle->type_requete."'"; |
|
| 120 | 119 | |
| 121 | 120 | // compléter le nom avec un nom précisé {doublons nom} |
| 122 | 121 | // on obtient $nom = "'article' . 'nom'" |
| 123 | 122 | if (isset($crit->param[0])) { |
| 124 | - $nom .= "." . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 123 | + $nom .= ".".calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 125 | 124 | } |
| 126 | 125 | |
| 127 | 126 | // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
@@ -136,10 +135,10 @@ discard block |
||
| 136 | 135 | $debut_in = "sql_in('".$boucle->id_table.'.'.$primary."', "; |
| 137 | 136 | // lecture des données du doublon "$doublons[$doublon_index[] = " |
| 138 | 137 | // Attention : boucle->doublons désigne une variable qu'on affecte |
| 139 | - $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons."[]= ")); |
|
| 138 | + $debut_doub = '$doublons['.(!$not ? '' : ($boucle->doublons."[]= ")); |
|
| 140 | 139 | |
| 141 | 140 | // le debut complet du code des doublons |
| 142 | - $debut_doub = $debut_in . $debut_doub; |
|
| 141 | + $debut_doub = $debut_in.$debut_doub; |
|
| 143 | 142 | |
| 144 | 143 | // nom du doublon "('article' . 'nom')]" |
| 145 | 144 | $fin_doub = "($nom)]"; |
@@ -147,23 +146,23 @@ discard block |
||
| 147 | 146 | // si on trouve un autre critère doublon, |
| 148 | 147 | // on fusionne pour avoir un seul IN, et on s'en va ! |
| 149 | 148 | foreach ($boucle->where as $k => $w) { |
| 150 | - if (strpos($w[0], $debut_doub)===0) { |
|
| 149 | + if (strpos($w[0], $debut_doub) === 0) { |
|
| 151 | 150 | // fusionner le sql_in (du where) |
| 152 | - $boucle->where[$k][0] = $debut_doub . $fin_doub.' . '.substr($w[0], strlen($debut_in)); |
|
| 151 | + $boucle->where[$k][0] = $debut_doub.$fin_doub.' . '.substr($w[0], strlen($debut_in)); |
|
| 153 | 152 | // fusionner l'initialisation (du hash) pour faire plus joli |
| 154 | 153 | $x = strpos($boucle->hash, $init_comment); |
| 155 | 154 | $len = strlen($init_comment); |
| 156 | 155 | $boucle->hash = |
| 157 | - substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 156 | + substr($boucle->hash, 0, $x + $len).$init_code.substr($boucle->hash, $x + $len); |
|
| 158 | 157 | return; |
| 159 | 158 | } |
| 160 | 159 | } |
| 161 | 160 | |
| 162 | 161 | // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
| 163 | - $boucle->where[] = array($debut_doub . $fin_doub.", '".$not."')"); |
|
| 162 | + $boucle->where[] = array($debut_doub.$fin_doub.", '".$not."')"); |
|
| 164 | 163 | |
| 165 | 164 | // déclarer le doublon s'il n'existe pas encore |
| 166 | - $boucle->hash .= $init_comment . $init_code; |
|
| 165 | + $boucle->hash .= $init_comment.$init_code; |
|
| 167 | 166 | |
| 168 | 167 | |
| 169 | 168 | # la ligne suivante avait l'intention d'eviter une collecte deja faite |
@@ -194,9 +193,9 @@ discard block |
||
| 194 | 193 | * @return |
| 195 | 194 | * AST complété de la gestion du critère |
| 196 | 195 | **/ |
| 197 | -function critere_lang_select_dist($idb, &$boucles, $crit){ |
|
| 196 | +function critere_lang_select_dist($idb, &$boucles, $crit) { |
|
| 198 | 197 | if (!isset($crit->param[1][0]) OR !($param = $crit->param[1][0]->texte)) $param = 'oui'; |
| 199 | - if ($crit->not) $param = ($param=='oui') ? 'non' : 'oui'; |
|
| 198 | + if ($crit->not) $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 200 | 199 | $boucle = &$boucles[$idb]; |
| 201 | 200 | $boucle->lang_select = $param; |
| 202 | 201 | } |
@@ -204,11 +203,11 @@ discard block |
||
| 204 | 203 | // {debut_xxx} |
| 205 | 204 | // http://www.spip.net/@debut_ |
| 206 | 205 | // http://doc.spip.org/@critere_debut_dist |
| 207 | -function critere_debut_dist($idb, &$boucles, $crit){ |
|
| 206 | +function critere_debut_dist($idb, &$boucles, $crit) { |
|
| 208 | 207 | list($un, $deux) = $crit->param; |
| 209 | 208 | $un = $un[0]->texte; |
| 210 | 209 | $deux = $deux[0]->texte; |
| 211 | - if ($deux){ |
|
| 210 | + if ($deux) { |
|
| 212 | 211 | $boucles[$idb]->limit = 'intval($Pile[0]["debut'. |
| 213 | 212 | $un. |
| 214 | 213 | '"]) . ",'. |
@@ -223,14 +222,14 @@ discard block |
||
| 223 | 222 | // {pagination 20 #ENV{truc,chose}} pour utiliser la variable debut_#ENV{truc,chose} |
| 224 | 223 | // http://www.spip.net/@pagination |
| 225 | 224 | // http://doc.spip.org/@critere_pagination_dist |
| 226 | -function critere_pagination_dist($idb, &$boucles, $crit){ |
|
| 225 | +function critere_pagination_dist($idb, &$boucles, $crit) { |
|
| 227 | 226 | |
| 228 | 227 | $boucle = &$boucles[$idb]; |
| 229 | 228 | // definition de la taille de la page |
| 230 | 229 | $pas = !isset($crit->param[0][0]) ? "''" |
| 231 | 230 | : calculer_liste(array($crit->param[0][0]), array(), $boucles, $boucle->id_parent); |
| 232 | 231 | |
| 233 | - if (!preg_match(_CODE_QUOTE, $pas, $r)){ |
|
| 232 | + if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 234 | 233 | $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
| 235 | 234 | } else { |
| 236 | 235 | $r = intval($r[2]); |
@@ -238,7 +237,7 @@ discard block |
||
| 238 | 237 | } |
| 239 | 238 | $type = !isset($crit->param[0][1]) ? "'$idb'" |
| 240 | 239 | : calculer_liste(array($crit->param[0][1]), array(), $boucles, $boucle->id_parent); |
| 241 | - $debut = ($type[0]!=="'") ? "'debut'.$type" |
|
| 240 | + $debut = ($type[0] !== "'") ? "'debut'.$type" |
|
| 242 | 241 | : ("'debut".substr($type, 1)); |
| 243 | 242 | |
| 244 | 243 | $boucle->modificateur['debut_nom'] = $type; |
@@ -252,7 +251,7 @@ discard block |
||
| 252 | 251 | ."\t".'$debut_boucle = intval($debut_boucle)'; |
| 253 | 252 | |
| 254 | 253 | $boucle->hash .= ' |
| 255 | - $command[\'pagination\'] = array((isset($Pile[0]['.$debut.']) ? $Pile[0]['.$debut.'] : null), ' . $pas . ');'; |
|
| 254 | + $command[\'pagination\'] = array((isset($Pile[0]['.$debut.']) ? $Pile[0]['.$debut.'] : null), '.$pas.');'; |
|
| 256 | 255 | |
| 257 | 256 | $boucle->total_parties = $pas; |
| 258 | 257 | calculer_parties($boucles, $idb, $partie, 'p+'); |
@@ -271,12 +270,12 @@ discard block |
||
| 271 | 270 | // {recherche} ou {recherche susan} |
| 272 | 271 | // http://www.spip.net/@recherche |
| 273 | 272 | // http://doc.spip.org/@critere_recherche_dist |
| 274 | -function critere_recherche_dist($idb, &$boucles, $crit){ |
|
| 273 | +function critere_recherche_dist($idb, &$boucles, $crit) { |
|
| 275 | 274 | |
| 276 | 275 | $boucle = &$boucles[$idb]; |
| 277 | 276 | |
| 278 | - if (!$boucle->primary OR strpos($boucle->primary, ',')){ |
|
| 279 | - erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire',array('critere'=>'recherche')), $boucle); |
|
| 277 | + if (!$boucle->primary OR strpos($boucle->primary, ',')) { |
|
| 278 | + erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', array('critere'=>'recherche')), $boucle); |
|
| 280 | 279 | return; |
| 281 | 280 | } |
| 282 | 281 | |
@@ -304,7 +303,7 @@ discard block |
||
| 304 | 303 | $boucle->select[] = $t; # pour postgres, neuneu ici |
| 305 | 304 | // jointure uniquement sur le serveur principal |
| 306 | 305 | // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
| 307 | - if (!$boucle->sql_serveur){ |
|
| 306 | + if (!$boucle->sql_serveur) { |
|
| 308 | 307 | $boucle->join['resultats'] = array("'".$boucle->id_table."'", "'id'", "'".$boucle->primary."'"); |
| 309 | 308 | $boucle->from['resultats'] = 'spip_resultats'; |
| 310 | 309 | } |
@@ -320,7 +319,7 @@ discard block |
||
| 320 | 319 | // (id_trad>0 AND id_trad=id_trad(precedent)) |
| 321 | 320 | // OR id_article=id_article(precedent) |
| 322 | 321 | // http://doc.spip.org/@critere_traduction_dist |
| 323 | -function critere_traduction_dist($idb, &$boucles, $crit){ |
|
| 322 | +function critere_traduction_dist($idb, &$boucles, $crit) { |
|
| 324 | 323 | $boucle = &$boucles[$idb]; |
| 325 | 324 | $prim = $boucle->primary; |
| 326 | 325 | $table = $boucle->id_table; |
@@ -343,7 +342,7 @@ discard block |
||
| 343 | 342 | // (id_trad>0 AND id_article=id_trad) OR (id_trad=0) |
| 344 | 343 | // http://www.spip.net/@origine_traduction |
| 345 | 344 | // http://doc.spip.org/@critere_origine_traduction_dist |
| 346 | -function critere_origine_traduction_dist($idb, &$boucles, $crit){ |
|
| 345 | +function critere_origine_traduction_dist($idb, &$boucles, $crit) { |
|
| 347 | 346 | $boucle = &$boucles[$idb]; |
| 348 | 347 | $prim = $boucle->primary; |
| 349 | 348 | $table = $boucle->id_table; |
@@ -359,16 +358,15 @@ discard block |
||
| 359 | 358 | // {meme_parent} |
| 360 | 359 | // http://www.spip.net/@meme_parent |
| 361 | 360 | // http://doc.spip.org/@critere_meme_parent_dist |
| 362 | -function critere_meme_parent_dist($idb, &$boucles, $crit){ |
|
| 361 | +function critere_meme_parent_dist($idb, &$boucles, $crit) { |
|
| 363 | 362 | global $exceptions_des_tables; |
| 364 | 363 | $boucle = &$boucles[$idb]; |
| 365 | 364 | $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
| 366 | 365 | $id_parent = isset($exceptions_des_tables[$boucle->id_table]['id_parent']) ? |
| 367 | - $exceptions_des_tables[$boucle->id_table]['id_parent'] : |
|
| 368 | - 'id_parent'; |
|
| 366 | + $exceptions_des_tables[$boucle->id_table]['id_parent'] : 'id_parent'; |
|
| 369 | 367 | $mparent = $boucle->id_table.'.'.$id_parent; |
| 370 | 368 | |
| 371 | - if ($boucle->type_requete=='rubriques' OR isset($exceptions_des_tables[$boucle->id_table]['id_parent'])){ |
|
| 369 | + if ($boucle->type_requete == 'rubriques' OR isset($exceptions_des_tables[$boucle->id_table]['id_parent'])) { |
|
| 372 | 370 | $boucle->where[] = array("'='", "'$mparent'", $arg); |
| 373 | 371 | |
| 374 | 372 | } |
@@ -398,7 +396,7 @@ discard block |
||
| 398 | 396 | * AST complété de la condition where au niveau de la boucle, |
| 399 | 397 | * restreignant celle ci aux rubriques de la branche |
| 400 | 398 | **/ |
| 401 | -function critere_branche_dist($idb, &$boucles, $crit){ |
|
| 399 | +function critere_branche_dist($idb, &$boucles, $crit) { |
|
| 402 | 400 | |
| 403 | 401 | $not = $crit->not; |
| 404 | 402 | $boucle = &$boucles[$idb]; |
@@ -408,11 +406,11 @@ discard block |
||
| 408 | 406 | $champ = "id_rubrique"; |
| 409 | 407 | $desc = $boucle->show; |
| 410 | 408 | //Seulement si necessaire |
| 411 | - if (!array_key_exists($champ, $desc['field'])){ |
|
| 409 | + if (!array_key_exists($champ, $desc['field'])) { |
|
| 412 | 410 | $cle = trouver_jointure_champ($champ, $boucle); |
| 413 | 411 | $trouver_table = charger_fonction("trouver_table", "base"); |
| 414 | 412 | $desc = $trouver_table($boucle->from[$cle]); |
| 415 | - if (count(trouver_champs_decomposes($champ, $desc))>1){ |
|
| 413 | + if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 416 | 414 | $decompose = decompose_champ_id_objet($champ); |
| 417 | 415 | $champ = array_shift($decompose); |
| 418 | 416 | $boucle->where[] = array("'='", _q($cle.".".reset($decompose)), '"'.sql_quote(end($decompose)).'"'); |
@@ -422,13 +420,12 @@ discard block |
||
| 422 | 420 | |
| 423 | 421 | $c = "sql_in('$cle".".$champ', calcul_branche_in($arg)" |
| 424 | 422 | .($not ? ", 'NOT'" : '').")"; |
| 425 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 426 | - ("($arg ? $c : ".($not ? "'0=1'" : "'1=1'").')'); |
|
| 423 | + $boucle->where[] = !$crit->cond ? $c : ("($arg ? $c : ".($not ? "'0=1'" : "'1=1'").')'); |
|
| 427 | 424 | } |
| 428 | 425 | |
| 429 | 426 | // {logo} liste les objets qui ont un logo |
| 430 | 427 | // http://doc.spip.org/@critere_logo_dist |
| 431 | -function critere_logo_dist($idb, &$boucles, $crit){ |
|
| 428 | +function critere_logo_dist($idb, &$boucles, $crit) { |
|
| 432 | 429 | |
| 433 | 430 | $not = $crit->not; |
| 434 | 431 | $boucle = &$boucles[$idb]; |
@@ -448,12 +445,12 @@ discard block |
||
| 448 | 445 | // c'est la commande SQL "GROUP BY" |
| 449 | 446 | // par exemple <boucle(articles){fusion lang}> |
| 450 | 447 | // http://doc.spip.org/@critere_fusion_dist |
| 451 | -function critere_fusion_dist($idb, &$boucles, $crit){ |
|
| 452 | - if ($t = isset($crit->param[0])){ |
|
| 448 | +function critere_fusion_dist($idb, &$boucles, $crit) { |
|
| 449 | + if ($t = isset($crit->param[0])) { |
|
| 453 | 450 | $t = $crit->param[0]; |
| 454 | - if ($t[0]->type=='texte'){ |
|
| 451 | + if ($t[0]->type == 'texte') { |
|
| 455 | 452 | $t = $t[0]->texte; |
| 456 | - if (preg_match("/^(.*)\.(.*)$/", $t, $r)){ |
|
| 453 | + if (preg_match("/^(.*)\.(.*)$/", $t, $r)) { |
|
| 457 | 454 | $t = table_objet_sql($r[1]); |
| 458 | 455 | $t = array_search($t, $boucles[$idb]->from); |
| 459 | 456 | if ($t) $t .= '.'.$r[2]; |
@@ -464,7 +461,7 @@ discard block |
||
| 464 | 461 | .'."'; |
| 465 | 462 | } |
| 466 | 463 | } |
| 467 | - if ($t){ |
|
| 464 | + if ($t) { |
|
| 468 | 465 | $boucles[$idb]->group[] = $t; |
| 469 | 466 | if (!in_array($t, $boucles[$idb]->select)) |
| 470 | 467 | $boucles[$idb]->select[] = $t; |
@@ -475,25 +472,25 @@ discard block |
||
| 475 | 472 | // c'est la commande SQL "COLLATE" |
| 476 | 473 | // qui peut etre appliquee sur les order by, group by, where like ... |
| 477 | 474 | // http://doc.spip.org/@critere_collecte_dist |
| 478 | -function critere_collecte_dist($idb, &$boucles, $crit){ |
|
| 479 | - if (isset($crit->param[0])){ |
|
| 475 | +function critere_collecte_dist($idb, &$boucles, $crit) { |
|
| 476 | + if (isset($crit->param[0])) { |
|
| 480 | 477 | $_coll = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
| 481 | 478 | $boucle = $boucles[$idb]; |
| 482 | 479 | $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
| 483 | 480 | $n = count($boucle->order); |
| 484 | - if ($n && (strpos($boucle->order[$n-1], 'COLLATE')===false)) |
|
| 485 | - $boucle->order[$n-1] .= " . ".$boucle->modificateur['collate']; |
|
| 481 | + if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) |
|
| 482 | + $boucle->order[$n - 1] .= " . ".$boucle->modificateur['collate']; |
|
| 486 | 483 | } else |
| 487 | 484 | return (array('zbug_critere_inconnu', array('critere' => $crit->op." ".count($boucles[$idb]->order)))); |
| 488 | 485 | } |
| 489 | 486 | |
| 490 | 487 | // http://doc.spip.org/@calculer_critere_arg_dynamique |
| 491 | -function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = ''){ |
|
| 488 | +function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
|
| 492 | 489 | $boucle = $boucles[$idb]; |
| 493 | 490 | $alt = "('".$boucle->id_table.'.\' . $x'.$suffix.')'; |
| 494 | 491 | $var = '$champs_'.$idb; |
| 495 | - $desc = (strpos($boucle->in, "static $var =")!==false); |
|
| 496 | - if (!$desc){ |
|
| 492 | + $desc = (strpos($boucle->in, "static $var =") !== false); |
|
| 493 | + if (!$desc) { |
|
| 497 | 494 | $desc = $boucle->show['field']; |
| 498 | 495 | $desc = implode(',', array_map('_q', array_keys($desc))); |
| 499 | 496 | $boucles[$idb]->in .= "\n\tstatic $var = array(".$desc.");"; |
@@ -506,22 +503,22 @@ discard block |
||
| 506 | 503 | // Tri : {par xxxx} |
| 507 | 504 | // http://www.spip.net/@par |
| 508 | 505 | // http://doc.spip.org/@critere_par_dist |
| 509 | -function critere_par_dist($idb, &$boucles, $crit){ |
|
| 506 | +function critere_par_dist($idb, &$boucles, $crit) { |
|
| 510 | 507 | return critere_parinverse($idb, $boucles, $crit); |
| 511 | 508 | } |
| 512 | 509 | |
| 513 | 510 | // http://doc.spip.org/@critere_parinverse |
| 514 | -function critere_parinverse($idb, &$boucles, $crit, $sens = ''){ |
|
| 511 | +function critere_parinverse($idb, &$boucles, $crit, $sens = '') { |
|
| 515 | 512 | global $exceptions_des_jointures; |
| 516 | 513 | $boucle = &$boucles[$idb]; |
| 517 | 514 | if ($crit->not) $sens = $sens ? "" : " . ' DESC'"; |
| 518 | 515 | $collecte = (isset($boucle->modificateur['collecte'])) ? " . ".$boucle->modificateur['collecte'] : ""; |
| 519 | 516 | |
| 520 | - foreach ($crit->param as $tri){ |
|
| 517 | + foreach ($crit->param as $tri) { |
|
| 521 | 518 | |
| 522 | 519 | $order = $fct = ""; // en cas de fonction SQL |
| 523 | 520 | // tris specifies dynamiquement |
| 524 | - if ($tri[0]->type!='texte'){ |
|
| 521 | + if ($tri[0]->type != 'texte') { |
|
| 525 | 522 | // calculer le order dynamique qui verifie les champs |
| 526 | 523 | $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
| 527 | 524 | // et si ce n'est fait, ajouter un champ 'hasard' |
@@ -534,13 +531,13 @@ discard block |
||
| 534 | 531 | $par = array_shift($tri); |
| 535 | 532 | $par = $par->texte; |
| 536 | 533 | // par multi champ |
| 537 | - if (preg_match(",^multi[\s]*(.*)$,", $par, $m)){ |
|
| 534 | + if (preg_match(",^multi[\s]*(.*)$,", $par, $m)) { |
|
| 538 | 535 | $champ = trim($m[1]); |
| 539 | 536 | // par multi L1.champ |
| 540 | 537 | if (strpos($champ, '.')) { |
| 541 | 538 | $cle = ''; |
| 542 | 539 | // par multi champ (champ sur une autre table) |
| 543 | - } elseif (!array_key_exists($champ, $boucle->show['field'])){ |
|
| 540 | + } elseif (!array_key_exists($champ, $boucle->show['field'])) { |
|
| 544 | 541 | $cle = trouver_jointure_champ($champ, $boucle); |
| 545 | 542 | // par multi champ (champ dans la table en cours) |
| 546 | 543 | } else { |
@@ -557,45 +554,45 @@ discard block |
||
| 557 | 554 | if (strpos($champ, '.')) { |
| 558 | 555 | $cle = ''; |
| 559 | 556 | // par num champ (champ sur une autre table) |
| 560 | - } elseif (!array_key_exists($champ, $boucle->show['field'])){ |
|
| 557 | + } elseif (!array_key_exists($champ, $boucle->show['field'])) { |
|
| 561 | 558 | $cle = trouver_jointure_champ($champ, $boucle); |
| 562 | 559 | // par num champ (champ dans la table en cours) |
| 563 | 560 | } else { |
| 564 | 561 | $cle = $boucle->id_table; |
| 565 | 562 | } |
| 566 | 563 | if ($cle) { $cle .= '.'; } |
| 567 | - $texte = '0+'. $cle . $champ; |
|
| 564 | + $texte = '0+'.$cle.$champ; |
|
| 568 | 565 | $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
| 569 | - if ($suite!=="''") |
|
| 566 | + if ($suite !== "''") |
|
| 570 | 567 | $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')"." . \""; |
| 571 | 568 | $as = 'num'.($boucle->order ? count($boucle->order) : ""); |
| 572 | 569 | $boucle->select[] = $texte." AS $as"; |
| 573 | 570 | $order = "'$as'"; |
| 574 | 571 | } else { |
| 575 | - if (!preg_match(",^".CHAMP_SQL_PLUS_FONC.'$,is', $par, $match)){ |
|
| 572 | + if (!preg_match(",^".CHAMP_SQL_PLUS_FONC.'$,is', $par, $match)) { |
|
| 576 | 573 | return (array('zbug_critere_inconnu', array('critere' => $crit->op." $par"))); |
| 577 | 574 | } else { |
| 578 | - if (count($match)>2){ |
|
| 575 | + if (count($match) > 2) { |
|
| 579 | 576 | $par = substr($match[2], 1, -1); |
| 580 | 577 | $fct = $match[1]; |
| 581 | 578 | } |
| 582 | 579 | // par hasard |
| 583 | - if ($par=='hasard'){ |
|
| 580 | + if ($par == 'hasard') { |
|
| 584 | 581 | $par = "rand()"; |
| 585 | 582 | $boucle->select[] = $par." AS alea"; |
| 586 | 583 | $order = "'alea'"; |
| 587 | 584 | } |
| 588 | 585 | // par titre_mot ou type_mot voire d'autres |
| 589 | - else if (isset($exceptions_des_jointures[$par])){ |
|
| 586 | + else if (isset($exceptions_des_jointures[$par])) { |
|
| 590 | 587 | list($table, $champ) = $exceptions_des_jointures[$par]; |
| 591 | 588 | $order = critere_par_joint($table, $champ, $boucle, $idb); |
| 592 | 589 | if (!$order) |
| 593 | 590 | return (array('zbug_critere_inconnu', array('critere' => $crit->op." $par"))); |
| 594 | 591 | } |
| 595 | - else if ($par=='date' |
|
| 592 | + else if ($par == 'date' |
|
| 596 | 593 | AND $desc = $boucle->show |
| 597 | 594 | AND $desc['date'] |
| 598 | - ){ |
|
| 595 | + ) { |
|
| 599 | 596 | $m = $desc['date']; |
| 600 | 597 | $order = "'".$boucle->id_table.".".$m."'"; |
| 601 | 598 | } |
@@ -603,10 +600,10 @@ discard block |
||
| 603 | 600 | elseif (preg_match("/^([^,]*)\.(.*)$/", $par, $r)) { |
| 604 | 601 | // cas du tri sur champ de jointure explicite |
| 605 | 602 | $t = array_search($r[1], $boucle->from); |
| 606 | - if (!$t){ |
|
| 603 | + if (!$t) { |
|
| 607 | 604 | $t = trouver_jointure_champ($r[2], $boucle, array($r[1])); |
| 608 | 605 | } |
| 609 | - if (!$t){ |
|
| 606 | + if (!$t) { |
|
| 610 | 607 | return (array('zbug_critere_inconnu', array('critere' => $crit->op." $par"))); |
| 611 | 608 | } else $order = "'".$t.'.'.$r[2]."'"; |
| 612 | 609 | } else { |
@@ -619,14 +616,14 @@ discard block |
||
| 619 | 616 | } |
| 620 | 617 | } |
| 621 | 618 | } |
| 622 | - if (preg_match('/^\'([^"]*)\'$/', $order, $m)){ |
|
| 619 | + if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 623 | 620 | $t = $m[1]; |
| 624 | - if (strpos($t, '.') AND !in_array($t, $boucle->select)){ |
|
| 621 | + if (strpos($t, '.') AND !in_array($t, $boucle->select)) { |
|
| 625 | 622 | $boucle->select[] = $t; |
| 626 | 623 | } |
| 627 | 624 | } else $sens = ''; |
| 628 | 625 | |
| 629 | - if ($fct){ |
|
| 626 | + if ($fct) { |
|
| 630 | 627 | if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) |
| 631 | 628 | $order = "'$fct(".$r[1].")'"; |
| 632 | 629 | else $order = "'$fct(' . $order . ')'"; |
@@ -639,7 +636,7 @@ discard block |
||
| 639 | 636 | } |
| 640 | 637 | |
| 641 | 638 | // http://doc.spip.org/@critere_par_joint |
| 642 | -function critere_par_joint($table, $champ, &$boucle, $idb){ |
|
| 639 | +function critere_par_joint($table, $champ, &$boucle, $idb) { |
|
| 643 | 640 | $t = array_search($table, $boucle->from); |
| 644 | 641 | if (!$t) $t = trouver_jointure_champ($champ, $boucle); |
| 645 | 642 | return !$t ? '' : ("'".$t.'.'.$champ."'"); |
@@ -649,7 +646,7 @@ discard block |
||
| 649 | 646 | // http://www.spip.net/@inverse |
| 650 | 647 | |
| 651 | 648 | // http://doc.spip.org/@critere_inverse_dist |
| 652 | -function critere_inverse_dist($idb, &$boucles, $crit){ |
|
| 649 | +function critere_inverse_dist($idb, &$boucles, $crit) { |
|
| 653 | 650 | |
| 654 | 651 | $boucle = &$boucles[$idb]; |
| 655 | 652 | // Classement par ordre inverse |
@@ -659,31 +656,31 @@ discard block |
||
| 659 | 656 | { |
| 660 | 657 | $order = "' DESC'"; |
| 661 | 658 | // Classement par ordre inverse fonction eventuelle de #ENV{...} |
| 662 | - if (isset($crit->param[0])){ |
|
| 659 | + if (isset($crit->param[0])) { |
|
| 663 | 660 | $critere = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
| 664 | 661 | $order = "(($critere)?' DESC':'')"; |
| 665 | 662 | } |
| 666 | 663 | |
| 667 | 664 | $n = count($boucle->order); |
| 668 | - if (!$n){ |
|
| 665 | + if (!$n) { |
|
| 669 | 666 | if (isset($boucle->default_order[0])) |
| 670 | 667 | $boucle->default_order[0] .= ' . " DESC"'; |
| 671 | 668 | else |
| 672 | 669 | $boucle->default_order[] = ' DESC'; |
| 673 | 670 | } else { |
| 674 | - $t = $boucle->order[$n-1]." . $order"; |
|
| 671 | + $t = $boucle->order[$n - 1]." . $order"; |
|
| 675 | 672 | if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) |
| 676 | 673 | $t = $r[1].$r[2]; |
| 677 | - $boucle->order[$n-1] = $t; |
|
| 674 | + $boucle->order[$n - 1] = $t; |
|
| 678 | 675 | } |
| 679 | 676 | } |
| 680 | 677 | } |
| 681 | 678 | |
| 682 | 679 | // http://doc.spip.org/@critere_agenda_dist |
| 683 | -function critere_agenda_dist($idb, &$boucles, $crit){ |
|
| 680 | +function critere_agenda_dist($idb, &$boucles, $crit) { |
|
| 684 | 681 | $params = $crit->param; |
| 685 | 682 | |
| 686 | - if (count($params)<1) |
|
| 683 | + if (count($params) < 1) |
|
| 687 | 684 | return (array('zbug_critere_inconnu', array('critere' => $crit->op." ?"))); |
| 688 | 685 | |
| 689 | 686 | $parent = $boucles[$idb]->id_parent; |
@@ -731,13 +728,13 @@ discard block |
||
| 731 | 728 | $date = $boucle->id_table.".$date"; |
| 732 | 729 | |
| 733 | 730 | $quote_end = ",'".$boucle->sql_serveur."','text'"; |
| 734 | - if ($type=='jour') |
|
| 731 | + if ($type == 'jour') |
|
| 735 | 732 | $boucle->where[] = array("'='", "'DATE_FORMAT($date, \'%Y%m%d\')'", |
| 736 | 733 | ("sql_quote($annee . $mois . $jour$quote_end)")); |
| 737 | - elseif ($type=='mois') |
|
| 734 | + elseif ($type == 'mois') |
|
| 738 | 735 | $boucle->where[] = array("'='", "'DATE_FORMAT($date, \'%Y%m\')'", |
| 739 | 736 | ("sql_quote($annee . $mois$quote_end)")); |
| 740 | - elseif ($type=='semaine') |
|
| 737 | + elseif ($type == 'semaine') |
|
| 741 | 738 | $boucle->where[] = array("'AND'", |
| 742 | 739 | array("'>='", |
| 743 | 740 | "'DATE_FORMAT($date, \'%Y%m%d\')'", |
@@ -745,7 +742,7 @@ discard block |
||
| 745 | 742 | array("'<='", |
| 746 | 743 | "'DATE_FORMAT($date, \'%Y%m%d\')'", |
| 747 | 744 | ("date_fin_semaine($annee, $mois, $jour)"))); |
| 748 | - elseif (count($crit->param)>2) |
|
| 745 | + elseif (count($crit->param) > 2) |
|
| 749 | 746 | $boucle->where[] = array("'AND'", |
| 750 | 747 | array("'>='", |
| 751 | 748 | "'DATE_FORMAT($date, \'%Y%m%d\')'", |
@@ -755,7 +752,7 @@ discard block |
||
| 755 | 752 | } |
| 756 | 753 | |
| 757 | 754 | // http://doc.spip.org/@calculer_critere_parties |
| 758 | -function calculer_critere_parties($idb, &$boucles, $crit){ |
|
| 755 | +function calculer_critere_parties($idb, &$boucles, $crit) { |
|
| 759 | 756 | $boucle = &$boucles[$idb]; |
| 760 | 757 | $a1 = $crit->param[0]; |
| 761 | 758 | $a2 = $crit->param[1]; |
@@ -764,20 +761,19 @@ discard block |
||
| 764 | 761 | list($a11, $a12) = calculer_critere_parties_aux($idb, $boucles, $a1); |
| 765 | 762 | list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
| 766 | 763 | |
| 767 | - if (($op==',') && (is_numeric($a11) && (is_numeric($a21)))){ |
|
| 764 | + if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 768 | 765 | $boucle->limit = $a11.','.$a21; |
| 769 | 766 | } |
| 770 | 767 | else { |
| 771 | - $boucle->total_parties = ($a21!='n') ? $a21 : $a22; |
|
| 772 | - $partie = ($a11!='n') ? $a11 : $a12; |
|
| 773 | - $mode = (($op=='/') ? '/' : |
|
| 774 | - (($a11=='n') ? '-' : '+').(($a21=='n') ? '-' : '+')); |
|
| 768 | + $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 769 | + $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 770 | + $mode = (($op == '/') ? '/' : (($a11 == 'n') ? '-' : '+').(($a21 == 'n') ? '-' : '+')); |
|
| 775 | 771 | // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
| 776 | - if ($a11!=='n' AND $a21!=='n' AND $mode=="++" AND $op==','){ |
|
| 772 | + if ($a11 !== 'n' AND $a21 !== 'n' AND $mode == "++" AND $op == ',') { |
|
| 777 | 773 | $boucle->limit = |
| 778 | - (is_numeric($a11)?"'$a11'":$a11) |
|
| 774 | + (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 779 | 775 | .".','." |
| 780 | - .(is_numeric($a21)?"'$a21'":$a21); |
|
| 776 | + .(is_numeric($a21) ? "'$a21'" : $a21); |
|
| 781 | 777 | } |
| 782 | 778 | else |
| 783 | 779 | calculer_parties($boucles, $idb, $partie, $mode); |
@@ -788,38 +784,35 @@ discard block |
||
| 788 | 784 | // Code specifique aux criteres {pagination}, {1,n} {n/m} etc |
| 789 | 785 | // |
| 790 | 786 | |
| 791 | -function calculer_parties(&$boucles, $id_boucle, $debut, $mode){ |
|
| 787 | +function calculer_parties(&$boucles, $id_boucle, $debut, $mode) { |
|
| 792 | 788 | $total_parties = $boucles[$id_boucle]->total_parties; |
| 793 | 789 | |
| 794 | 790 | preg_match(",([+-/p])([+-/])?,", $mode, $regs); |
| 795 | 791 | list(, $op1, $op2) = array_pad($regs, 3, null); |
| 796 | 792 | $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
| 797 | 793 | // {1/3} |
| 798 | - if ($op1=='/'){ |
|
| 799 | - $pmoins1 = is_numeric($debut) ? ($debut-1) : "($debut-1)"; |
|
| 800 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 801 | - "($total_parties ? $total_parties : 1)"; |
|
| 794 | + if ($op1 == '/') { |
|
| 795 | + $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 796 | + $totpos = is_numeric($total_parties) ? ($total_parties) : "($total_parties ? $total_parties : 1)"; |
|
| 802 | 797 | $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
| 803 | 798 | $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
| 804 | 799 | } else { |
| 805 | 800 | // cas {n-1,x} |
| 806 | - if ($op1=='-') $debut = "$nombre_boucle - $debut;"; |
|
| 801 | + if ($op1 == '-') $debut = "$nombre_boucle - $debut;"; |
|
| 807 | 802 | |
| 808 | 803 | // cas {x,n-1} |
| 809 | - if ($op2=='-'){ |
|
| 804 | + if ($op2 == '-') { |
|
| 810 | 805 | $fin = '$debut_boucle + '.$nombre_boucle.' - ' |
| 811 | - .(is_numeric($total_parties) ? ($total_parties+1) : |
|
| 812 | - ($total_parties.' - 1')); |
|
| 806 | + .(is_numeric($total_parties) ? ($total_parties + 1) : ($total_parties.' - 1')); |
|
| 813 | 807 | } else { |
| 814 | 808 | // {x,1} ou {pagination} |
| 815 | 809 | $fin = '$debut_boucle' |
| 816 | 810 | .(is_numeric($total_parties) ? |
| 817 | - (($total_parties==1) ? "" : (' + '.($total_parties-1))) : |
|
| 818 | - ('+'.$total_parties.' - 1')); |
|
| 811 | + (($total_parties == 1) ? "" : (' + '.($total_parties - 1))) : ('+'.$total_parties.' - 1')); |
|
| 819 | 812 | } |
| 820 | 813 | |
| 821 | 814 | // {pagination}, gerer le debut_xx=-1 pour tout voir |
| 822 | - if ($op1=='p'){ |
|
| 815 | + if ($op1 == 'p') { |
|
| 823 | 816 | $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
| 824 | 817 | $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
| 825 | 818 | $fin = "(\$tout ? $nombre_boucle : $fin)"; |
@@ -845,8 +838,8 @@ discard block |
||
| 845 | 838 | } |
| 846 | 839 | |
| 847 | 840 | // http://doc.spip.org/@calculer_critere_parties_aux |
| 848 | -function calculer_critere_parties_aux($idb, &$boucles, $param){ |
|
| 849 | - if ($param[0]->type!='texte'){ |
|
| 841 | +function calculer_critere_parties_aux($idb, &$boucles, $param) { |
|
| 842 | + if ($param[0]->type != 'texte') { |
|
| 850 | 843 | $a1 = calculer_liste(array($param[0]), array('id_mere' => $idb), $boucles, $boucles[$idb]->id_parent); |
| 851 | 844 | preg_match(',^ *(-([0-9]+))? *$,', $param[1]->texte, $m); |
| 852 | 845 | return array("intval($a1)", ($m[2] ? $m[2] : 0)); |
@@ -885,7 +878,7 @@ discard block |
||
| 885 | 878 | * string : Chaine vide sans erreur |
| 886 | 879 | * array : Erreur sur un des critères |
| 887 | 880 | **/ |
| 888 | -function calculer_criteres($idb, &$boucles){ |
|
| 881 | +function calculer_criteres($idb, &$boucles) { |
|
| 889 | 882 | $msg = ''; |
| 890 | 883 | $boucle = $boucles[$idb]; |
| 891 | 884 | $table = strtoupper($boucle->type_requete); |
@@ -895,7 +888,7 @@ discard block |
||
| 895 | 888 | // s'il y avait une erreur de syntaxe, propager cette info |
| 896 | 889 | if (!is_array($boucle->criteres)) return array(); |
| 897 | 890 | |
| 898 | - foreach ($boucle->criteres as $crit){ |
|
| 891 | + foreach ($boucle->criteres as $crit) { |
|
| 899 | 892 | $critere = $crit->op; |
| 900 | 893 | // critere personnalise ? |
| 901 | 894 | if ( |
@@ -910,7 +903,7 @@ discard block |
||
| 910 | 903 | AND (!function_exists($f = $f."_dist")) |
| 911 | 904 | AND (!function_exists($f = "critere_".$critere)) |
| 912 | 905 | AND (!function_exists($f = $f."_dist")) |
| 913 | - ){ |
|
| 906 | + ) { |
|
| 914 | 907 | // fonction critere standard |
| 915 | 908 | $f = $defaut; |
| 916 | 909 | } |
@@ -918,7 +911,7 @@ discard block |
||
| 918 | 911 | $res = $f($idb, $boucles, $crit); |
| 919 | 912 | |
| 920 | 913 | // Gestion centralisee des erreurs pour pouvoir propager |
| 921 | - if (is_array($res)){ |
|
| 914 | + if (is_array($res)) { |
|
| 922 | 915 | $msg = $res; |
| 923 | 916 | erreur_squelette($msg, $boucle); |
| 924 | 917 | } |
@@ -937,9 +930,9 @@ discard block |
||
| 937 | 930 | * @param string $type |
| 938 | 931 | * @return string |
| 939 | 932 | */ |
| 940 | -function kwote($lisp, $serveur='', $type=''){ |
|
| 933 | +function kwote($lisp, $serveur = '', $type = '') { |
|
| 941 | 934 | if (preg_match(_CODE_QUOTE, $lisp, $r)) |
| 942 | - return $r[1]."\"".sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]),$serveur,$type)."\""; |
|
| 935 | + return $r[1]."\"".sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]), $serveur, $type)."\""; |
|
| 943 | 936 | else |
| 944 | 937 | return "sql_quote($lisp)"; |
| 945 | 938 | } |
@@ -947,9 +940,9 @@ discard block |
||
| 947 | 940 | // Si on a une liste de valeurs dans #ENV{x}, utiliser la double etoile |
| 948 | 941 | // pour faire par exemple {id_article IN #ENV**{liste_articles}} |
| 949 | 942 | // http://doc.spip.org/@critere_IN_dist |
| 950 | -function critere_IN_dist($idb, &$boucles, $crit){ |
|
| 943 | +function critere_IN_dist($idb, &$boucles, $crit) { |
|
| 951 | 944 | $r = calculer_critere_infixe($idb, $boucles, $crit); |
| 952 | - if (!$r){ |
|
| 945 | + if (!$r) { |
|
| 953 | 946 | return (array('zbug_critere_inconnu', array('critere' => $crit->op." ?"))); |
| 954 | 947 | } |
| 955 | 948 | list($arg, $op, $val, $col, $where_complement) = $r; |
@@ -958,7 +951,7 @@ discard block |
||
| 958 | 951 | |
| 959 | 952 | // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
| 960 | 953 | $where = $in; |
| 961 | - if ($crit->cond){ |
|
| 954 | + if ($crit->cond) { |
|
| 962 | 955 | $pred = calculer_argument_precedent($idb, $col, $boucles); |
| 963 | 956 | $where = array("'?'", $pred, $where, "''"); |
| 964 | 957 | if ($where_complement) // condition annexe du type "AND (objet='article')" |
@@ -978,15 +971,15 @@ discard block |
||
| 978 | 971 | } |
| 979 | 972 | |
| 980 | 973 | // http://doc.spip.org/@critere_IN_cas |
| 981 | -function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col){ |
|
| 974 | +function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col) { |
|
| 982 | 975 | static $num = array(); |
| 983 | 976 | $descr = $boucles[$idb]->descr; |
| 984 | 977 | $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
| 985 | 978 | |
| 986 | 979 | $var = '$in'.$cpt++; |
| 987 | 980 | $x = "\n\t$var = array();"; |
| 988 | - foreach ($val as $k => $v){ |
|
| 989 | - if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)){ |
|
| 981 | + foreach ($val as $k => $v) { |
|
| 982 | + if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 990 | 983 | // optimiser le traitement des constantes |
| 991 | 984 | if (is_numeric($r[2])) |
| 992 | 985 | $x .= "\n\t$var"."[]= $r[2];"; |
@@ -1007,11 +1000,11 @@ discard block |
||
| 1007 | 1000 | // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un rexgexp) |
| 1008 | 1001 | // et que l'on limite donc strictement aux cas necessaires : |
| 1009 | 1002 | // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
| 1010 | - if (!$crit2){ |
|
| 1003 | + if (!$crit2) { |
|
| 1011 | 1004 | $boucles[$idb]->default_order[] = "((!sql_quote($var) OR sql_quote($var)===\"''\") ? 0 : ('FIELD($arg,' . sql_quote($var) . ')'))"; |
| 1012 | 1005 | } |
| 1013 | 1006 | |
| 1014 | - return "sql_in('$arg',sql_quote($var)".($crit2=='NOT' ? ",'NOT'" : "").")"; |
|
| 1007 | + return "sql_in('$arg',sql_quote($var)".($crit2 == 'NOT' ? ",'NOT'" : "").")"; |
|
| 1015 | 1008 | } |
| 1016 | 1009 | |
| 1017 | 1010 | /** |
@@ -1022,7 +1015,7 @@ discard block |
||
| 1022 | 1015 | * @param <type> $boucles |
| 1023 | 1016 | * @param <type> $crit |
| 1024 | 1017 | */ |
| 1025 | -function critere_where_dist($idb, &$boucles, $crit){ |
|
| 1018 | +function critere_where_dist($idb, &$boucles, $crit) { |
|
| 1026 | 1019 | $boucle = &$boucles[$idb]; |
| 1027 | 1020 | if (isset($crit->param[0])) |
| 1028 | 1021 | $_where = calculer_liste($crit->param[0], array(), $boucles, $boucle->id_parent); |
@@ -1084,7 +1077,7 @@ discard block |
||
| 1084 | 1077 | * @param unknown_type $boucles |
| 1085 | 1078 | * @param unknown_type $crit |
| 1086 | 1079 | */ |
| 1087 | -function critere_tri_dist($idb, &$boucles, $crit){ |
|
| 1080 | +function critere_tri_dist($idb, &$boucles, $crit) { |
|
| 1088 | 1081 | $boucle = &$boucles[$idb]; |
| 1089 | 1082 | |
| 1090 | 1083 | // definition du champ par defaut |
@@ -1120,13 +1113,13 @@ discard block |
||
| 1120 | 1113 | # Criteres de comparaison |
| 1121 | 1114 | |
| 1122 | 1115 | // http://doc.spip.org/@calculer_critere_DEFAUT |
| 1123 | -function calculer_critere_DEFAUT_dist($idb, &$boucles, $crit){ |
|
| 1116 | +function calculer_critere_DEFAUT_dist($idb, &$boucles, $crit) { |
|
| 1124 | 1117 | // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
| 1125 | - if (($crit->op==",") OR ($crit->op=='/')) |
|
| 1118 | + if (($crit->op == ",") OR ($crit->op == '/')) |
|
| 1126 | 1119 | return calculer_critere_parties($idb, $boucles, $crit); |
| 1127 | 1120 | |
| 1128 | 1121 | $r = calculer_critere_infixe($idb, $boucles, $crit); |
| 1129 | - if (!$r){ |
|
| 1122 | + if (!$r) { |
|
| 1130 | 1123 | # // on produit une erreur seulement si le critere n'a pas de '?' |
| 1131 | 1124 | # if (!$crit->cond) { |
| 1132 | 1125 | return (array('zbug_critere_inconnu', array('critere' => $crit->op))); |
@@ -1134,7 +1127,7 @@ discard block |
||
| 1134 | 1127 | } else calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
| 1135 | 1128 | } |
| 1136 | 1129 | |
| 1137 | -function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args){ |
|
| 1130 | +function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args) { |
|
| 1138 | 1131 | list($arg, $op, $val, $col, $where_complement) = $args; |
| 1139 | 1132 | |
| 1140 | 1133 | $where = array("'$op'", "'$arg'", $val[0]); |
@@ -1152,15 +1145,15 @@ discard block |
||
| 1152 | 1145 | |
| 1153 | 1146 | // inserer la condition (cf {lang?}) |
| 1154 | 1147 | // traiter a part la date, elle est mise d'office par SPIP, |
| 1155 | - if ($crit->cond){ |
|
| 1148 | + if ($crit->cond) { |
|
| 1156 | 1149 | $pred = calculer_argument_precedent($idb, $col, $boucles); |
| 1157 | - if ($col=="date" OR $col=="date_redac"){ |
|
| 1158 | - if ($pred=="\$Pile[0]['".$col."']"){ |
|
| 1150 | + if ($col == "date" OR $col == "date_redac") { |
|
| 1151 | + if ($pred == "\$Pile[0]['".$col."']") { |
|
| 1159 | 1152 | $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
| 1160 | 1153 | } |
| 1161 | 1154 | } |
| 1162 | 1155 | |
| 1163 | - if ($op=='=' AND !$crit->not) |
|
| 1156 | + if ($op == '=' AND !$crit->not) |
|
| 1164 | 1157 | $where = array("'?'", "(is_array($pred))", |
| 1165 | 1158 | critere_IN_cas($idb, $boucles, 'COND', $arg, $op, array($pred), $col), |
| 1166 | 1159 | $where); |
@@ -1175,7 +1168,7 @@ discard block |
||
| 1175 | 1168 | } |
| 1176 | 1169 | |
| 1177 | 1170 | // http://doc.spip.org/@calculer_critere_infixe |
| 1178 | -function calculer_critere_infixe($idb, &$boucles, $crit){ |
|
| 1171 | +function calculer_critere_infixe($idb, &$boucles, $crit) { |
|
| 1179 | 1172 | |
| 1180 | 1173 | global $table_criteres_infixes; |
| 1181 | 1174 | global $exceptions_des_jointures, $exceptions_des_tables; |
@@ -1193,16 +1186,16 @@ discard block |
||
| 1193 | 1186 | $where_complement = false; |
| 1194 | 1187 | |
| 1195 | 1188 | // Cas particulier : id_enfant => utiliser la colonne id_objet |
| 1196 | - if ($col=='id_enfant') |
|
| 1189 | + if ($col == 'id_enfant') |
|
| 1197 | 1190 | $col = $boucle->primary; |
| 1198 | 1191 | |
| 1199 | 1192 | // Cas particulier : id_parent => verifier les exceptions de tables |
| 1200 | - if (in_array($col,array('id_parent','id_secteur')) |
|
| 1193 | + if (in_array($col, array('id_parent', 'id_secteur')) |
|
| 1201 | 1194 | AND isset($exceptions_des_tables[$table][$col])) |
| 1202 | 1195 | $col = $exceptions_des_tables[$table][$col]; |
| 1203 | 1196 | |
| 1204 | 1197 | // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
| 1205 | - else if (($col=='id_secteur') AND ($critere_secteur = charger_fonction("critere_secteur_$type", "public", true))){ |
|
| 1198 | + else if (($col == 'id_secteur') AND ($critere_secteur = charger_fonction("critere_secteur_$type", "public", true))) { |
|
| 1206 | 1199 | $table = $critere_secteur($idb, $boucles, $val, $crit); |
| 1207 | 1200 | } |
| 1208 | 1201 | |
@@ -1211,28 +1204,28 @@ discard block |
||
| 1211 | 1204 | else if ( |
| 1212 | 1205 | !isset($exceptions_des_jointures[table_objet_sql($table)][$col]) |
| 1213 | 1206 | AND !isset($exceptions_des_jointures[$col]) |
| 1214 | - AND count(trouver_champs_decomposes($col, $desc))>1 |
|
| 1215 | - ){ |
|
| 1207 | + AND count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 1208 | + ) { |
|
| 1216 | 1209 | $e = decompose_champ_id_objet($col); |
| 1217 | 1210 | $col = array_shift($e); |
| 1218 | 1211 | $where_complement = primary_doublee($e, $table); |
| 1219 | 1212 | } |
| 1220 | 1213 | // Cas particulier : expressions de date |
| 1221 | - else if ($c = calculer_critere_infixe_date($idb, $boucles, $col)){ |
|
| 1222 | - list($col,$col_vraie) = $c; |
|
| 1214 | + else if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 1215 | + list($col, $col_vraie) = $c; |
|
| 1223 | 1216 | $table = ''; |
| 1224 | 1217 | } |
| 1225 | - else if (preg_match('/^(.*)\.(.*)$/', $col, $r)){ |
|
| 1218 | + else if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 1226 | 1219 | list(, $table, $col) = $r; |
| 1227 | 1220 | $col_alias = $col; |
| 1228 | 1221 | |
| 1229 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 1222 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1230 | 1223 | if ($desc = $trouver_table($table, $boucle->sql_serveur) |
| 1231 | 1224 | AND isset($desc['field'][$col]) |
| 1232 | - AND $cle = array_search($desc['table'],$boucle->from)) |
|
| 1225 | + AND $cle = array_search($desc['table'], $boucle->from)) |
|
| 1233 | 1226 | $table = $cle; |
| 1234 | 1227 | else { |
| 1235 | - $table = trouver_jointure_champ($col, $boucle, array($table), ($crit->cond OR $op!='=')); |
|
| 1228 | + $table = trouver_jointure_champ($col, $boucle, array($table), ($crit->cond OR $op != '=')); |
|
| 1236 | 1229 | } |
| 1237 | 1230 | #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
| 1238 | 1231 | if (!$table) return ''; |
@@ -1246,18 +1239,18 @@ discard block |
||
| 1246 | 1239 | list($col, $col_alias, $table, $where_complement, $desc) = $r; |
| 1247 | 1240 | } |
| 1248 | 1241 | |
| 1249 | - $col_vraie = ($col_vraie?$col_vraie:$col); |
|
| 1242 | + $col_vraie = ($col_vraie ? $col_vraie : $col); |
|
| 1250 | 1243 | // Dans tous les cas, |
| 1251 | 1244 | // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) et passer dans sql_quote avec le type si connu |
| 1252 | 1245 | // et int sinon si la valeur est numerique |
| 1253 | 1246 | // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
| 1254 | 1247 | // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
| 1255 | - if ($op=='=' OR in_array($op, $table_criteres_infixes)){ |
|
| 1248 | + if ($op == '=' OR in_array($op, $table_criteres_infixes)) { |
|
| 1256 | 1249 | |
| 1257 | 1250 | // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
| 1258 | 1251 | // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
| 1259 | 1252 | if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) |
| 1260 | - $val[0] = $r[1].'"'.sql_quote($r[2],$boucle->sql_serveur,(isset($desc['field'][$col_vraie])?$desc['field'][$col_vraie]:'int NOT NULL')).'"'; |
|
| 1253 | + $val[0] = $r[1].'"'.sql_quote($r[2], $boucle->sql_serveur, (isset($desc['field'][$col_vraie]) ? $desc['field'][$col_vraie] : 'int NOT NULL')).'"'; |
|
| 1261 | 1254 | |
| 1262 | 1255 | // sinon expliciter les |
| 1263 | 1256 | // sql_quote(truc) en sql_quote(truc,'',type) |
@@ -1270,16 +1263,16 @@ discard block |
||
| 1270 | 1263 | AND (!isset($r[3]) OR !$r[3])) { |
| 1271 | 1264 | $r = $r[1] |
| 1272 | 1265 | .((isset($r[2]) AND $r[2]) ? $r[2] : ",''") |
| 1273 | - .",'".(isset($desc['field'][$col_vraie])?addslashes($desc['field'][$col_vraie]):'int NOT NULL')."'"; |
|
| 1266 | + .",'".(isset($desc['field'][$col_vraie]) ?addslashes($desc['field'][$col_vraie]) : 'int NOT NULL')."'"; |
|
| 1274 | 1267 | $val[0] = "sql_quote($r)"; |
| 1275 | 1268 | } |
| 1276 | 1269 | } |
| 1277 | 1270 | // Indicateur pour permettre aux fonctionx boucle_X de modifier |
| 1278 | 1271 | // leurs requetes par defaut, notamment le champ statut |
| 1279 | 1272 | // Ne pas confondre champs de la table principale et des jointures |
| 1280 | - if ($table===$boucle->id_table){ |
|
| 1273 | + if ($table === $boucle->id_table) { |
|
| 1281 | 1274 | $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
| 1282 | - if ($col_alias!=$col_vraie) |
|
| 1275 | + if ($col_alias != $col_vraie) |
|
| 1283 | 1276 | $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
| 1284 | 1277 | } |
| 1285 | 1278 | |
@@ -1288,11 +1281,11 @@ discard block |
||
| 1288 | 1281 | // de mettre ses propres criteres de statut |
| 1289 | 1282 | // http://www.spip.net/@statut (a documenter) |
| 1290 | 1283 | // garde pour compatibilite avec code des plugins anterieurs, mais redondant avec la ligne precedente |
| 1291 | - if ($col=='statut') $boucles[$idb]->statut = true; |
|
| 1284 | + if ($col == 'statut') $boucles[$idb]->statut = true; |
|
| 1292 | 1285 | |
| 1293 | 1286 | // inserer le nom de la table SQL devant le nom du champ |
| 1294 | - if ($table){ |
|
| 1295 | - if ($col[0]=="`") |
|
| 1287 | + if ($table) { |
|
| 1288 | + if ($col[0] == "`") |
|
| 1296 | 1289 | $arg = "$table.".substr($col, 1, -1); |
| 1297 | 1290 | else $arg = "$table.$col"; |
| 1298 | 1291 | } else $arg = $col; |
@@ -1303,7 +1296,7 @@ discard block |
||
| 1303 | 1296 | return array($arg, $op, $val, $col_alias, $where_complement); |
| 1304 | 1297 | } |
| 1305 | 1298 | |
| 1306 | -function calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table){ |
|
| 1299 | +function calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table) { |
|
| 1307 | 1300 | global $exceptions_des_jointures; |
| 1308 | 1301 | $where = ''; |
| 1309 | 1302 | |
@@ -1319,17 +1312,17 @@ discard block |
||
| 1319 | 1312 | OR |
| 1320 | 1313 | isset($exceptions_des_jointures[$table_sql]['']) |
| 1321 | 1314 | ) |
| 1322 | - ){ |
|
| 1315 | + ) { |
|
| 1323 | 1316 | $t = $exceptions_des_jointures[$table_sql]; |
| 1324 | 1317 | $index = isset($t[$col]) |
| 1325 | 1318 | ? $t[$col] : (isset($t['']) ? $t[''] : array()); |
| 1326 | 1319 | |
| 1327 | - if (count($index)==3) |
|
| 1320 | + if (count($index) == 3) |
|
| 1328 | 1321 | list($t, $col, $calculer_critere_externe) = $index; |
| 1329 | - elseif (count($index)==2) { |
|
| 1322 | + elseif (count($index) == 2) { |
|
| 1330 | 1323 | list($t, $col) = $t[$col]; |
| 1331 | 1324 | } |
| 1332 | - elseif (count($index)==1) { |
|
| 1325 | + elseif (count($index) == 1) { |
|
| 1333 | 1326 | list($calculer_critere_externe) = $index; |
| 1334 | 1327 | $t = $table; |
| 1335 | 1328 | } |
@@ -1348,14 +1341,14 @@ discard block |
||
| 1348 | 1341 | // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
| 1349 | 1342 | // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
| 1350 | 1343 | $table = ""; |
| 1351 | - if ($boucle->jointures_explicites){ |
|
| 1344 | + if ($boucle->jointures_explicites) { |
|
| 1352 | 1345 | $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
| 1353 | - $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond OR $op!='='), $t); |
|
| 1346 | + $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond OR $op != '='), $t); |
|
| 1354 | 1347 | } |
| 1355 | 1348 | |
| 1356 | 1349 | // et sinon on cherche parmi toutes les jointures declarees |
| 1357 | 1350 | if (!$table) { |
| 1358 | - $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond OR $op!='='), $t); |
|
| 1351 | + $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond OR $op != '='), $t); |
|
| 1359 | 1352 | } |
| 1360 | 1353 | |
| 1361 | 1354 | if (!$table) return ''; |
@@ -1363,7 +1356,7 @@ discard block |
||
| 1363 | 1356 | // il ne reste plus qu'a trouver le champ dans les from |
| 1364 | 1357 | list($nom, $desc) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
| 1365 | 1358 | |
| 1366 | - if (count(trouver_champs_decomposes($col, $desc))>1){ |
|
| 1359 | + if (count(trouver_champs_decomposes($col, $desc)) > 1) { |
|
| 1367 | 1360 | $col_alias = $col; // id_article devient juste le nom d'origine |
| 1368 | 1361 | $e = decompose_champ_id_objet($col); |
| 1369 | 1362 | $col = array_shift($e); |
@@ -1377,7 +1370,7 @@ discard block |
||
| 1377 | 1370 | // car on ne connait pas le serveur SQL, donc s'il faut \' ou '' |
| 1378 | 1371 | |
| 1379 | 1372 | // http://doc.spip.org/@primary_doublee |
| 1380 | -function primary_doublee($decompose, $table){ |
|
| 1373 | +function primary_doublee($decompose, $table) { |
|
| 1381 | 1374 | $e1 = reset($decompose); |
| 1382 | 1375 | $e2 = "sql_quote('".end($decompose)."')"; |
| 1383 | 1376 | return array("'='", "'$table.".$e1."'", $e2); |
@@ -1402,7 +1395,7 @@ discard block |
||
| 1402 | 1395 | * @param bool|string $checkarrivee |
| 1403 | 1396 | * @return mixed|string |
| 1404 | 1397 | */ |
| 1405 | -function calculer_critere_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false){ |
|
| 1398 | +function calculer_critere_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
|
| 1406 | 1399 | // si on demande un truc du genre spip_mots |
| 1407 | 1400 | // avec aussi spip_mots_liens dans les jointures dispo |
| 1408 | 1401 | // et qu'on est la |
@@ -1411,19 +1404,19 @@ discard block |
||
| 1411 | 1404 | AND is_string($checkarrivee) |
| 1412 | 1405 | AND $a = table_objet($checkarrivee) |
| 1413 | 1406 | AND in_array($a.'_liens', $joints) |
| 1414 | - ){ |
|
| 1407 | + ) { |
|
| 1415 | 1408 | if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
| 1416 | 1409 | return $res; |
| 1417 | 1410 | } |
| 1418 | 1411 | } |
| 1419 | - foreach ($joints as $joint){ |
|
| 1420 | - if ($arrivee = trouver_champ_exterieur($col, array($joint), $boucle, $checkarrivee)){ |
|
| 1412 | + foreach ($joints as $joint) { |
|
| 1413 | + if ($arrivee = trouver_champ_exterieur($col, array($joint), $boucle, $checkarrivee)) { |
|
| 1421 | 1414 | $t = array_search($arrivee[0], $boucle->from); |
| 1422 | 1415 | // transformer eventuellement id_xx en (id_objet,objet) |
| 1423 | 1416 | $cols = trouver_champs_decomposes($col, $arrivee[1]); |
| 1424 | - if ($t){ |
|
| 1417 | + if ($t) { |
|
| 1425 | 1418 | $joindre = false; |
| 1426 | - foreach ($cols as $col){ |
|
| 1419 | + foreach ($cols as $col) { |
|
| 1427 | 1420 | $c = '/\b'.$t.".$col".'\b/'; |
| 1428 | 1421 | if (trouver_champ($c, $boucle->where)) $joindre = true; |
| 1429 | 1422 | else { |
@@ -1454,7 +1447,7 @@ discard block |
||
| 1454 | 1447 | * @param bool $checkarrivee |
| 1455 | 1448 | * @return string |
| 1456 | 1449 | */ |
| 1457 | -function calculer_lien_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false){ |
|
| 1450 | +function calculer_lien_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
|
| 1458 | 1451 | $primary_arrivee = id_table_objet($checkarrivee); |
| 1459 | 1452 | |
| 1460 | 1453 | $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee."_liens"); |
@@ -1473,11 +1466,11 @@ discard block |
||
| 1473 | 1466 | |
| 1474 | 1467 | |
| 1475 | 1468 | // http://doc.spip.org/@trouver_champ |
| 1476 | -function trouver_champ($champ, $where){ |
|
| 1469 | +function trouver_champ($champ, $where) { |
|
| 1477 | 1470 | if (!is_array($where)) |
| 1478 | 1471 | return preg_match($champ, $where); |
| 1479 | 1472 | else { |
| 1480 | - foreach ($where as $clause){ |
|
| 1473 | + foreach ($where as $clause) { |
|
| 1481 | 1474 | if (trouver_champ($champ, $clause)) return true; |
| 1482 | 1475 | } |
| 1483 | 1476 | return false; |
@@ -1488,18 +1481,18 @@ discard block |
||
| 1488 | 1481 | // determine l'operateur et les operandes |
| 1489 | 1482 | |
| 1490 | 1483 | // http://doc.spip.org/@calculer_critere_infixe_ops |
| 1491 | -function calculer_critere_infixe_ops($idb, &$boucles, $crit){ |
|
| 1484 | +function calculer_critere_infixe_ops($idb, &$boucles, $crit) { |
|
| 1492 | 1485 | // cas d'une valeur comparee a elle-meme ou son referent |
| 1493 | - if (count($crit->param)==0){ |
|
| 1486 | + if (count($crit->param) == 0) { |
|
| 1494 | 1487 | $op = '='; |
| 1495 | 1488 | $col = $val = $crit->op; |
| 1496 | 1489 | if (preg_match('/^(.*)\.(.*)$/', $col, $r)) $val = $r[2]; |
| 1497 | 1490 | // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
| 1498 | - if ($val=='lang') |
|
| 1491 | + if ($val == 'lang') |
|
| 1499 | 1492 | $val = array(kwote('$GLOBALS[\'spip_lang\']')); |
| 1500 | 1493 | else { |
| 1501 | 1494 | $defaut = null; |
| 1502 | - if ($val=='id_parent') { |
|
| 1495 | + if ($val == 'id_parent') { |
|
| 1503 | 1496 | // Si id_parent, comparer l'id_parent avec l'id_objet |
| 1504 | 1497 | // de la boucle superieure.... faudrait verifier qu'il existe |
| 1505 | 1498 | // pour eviter l'erreur SQL |
@@ -1507,12 +1500,12 @@ discard block |
||
| 1507 | 1500 | // mais si pas de boucle superieure, prendre id_parent dans l'env |
| 1508 | 1501 | $defaut = "\$Pile[0]['id_parent']"; |
| 1509 | 1502 | } |
| 1510 | - elseif ($val=='id_enfant'){ |
|
| 1503 | + elseif ($val == 'id_enfant') { |
|
| 1511 | 1504 | // Si id_enfant, comparer l'id_objet avec l'id_parent |
| 1512 | 1505 | // de la boucle superieure |
| 1513 | 1506 | $val = 'id_parent'; |
| 1514 | 1507 | } |
| 1515 | - elseif ($crit->cond AND ($col=="date" OR $col=="date_redac")){ |
|
| 1508 | + elseif ($crit->cond AND ($col == "date" OR $col == "date_redac")) { |
|
| 1516 | 1509 | // un critere conditionnel sur date est traite a part |
| 1517 | 1510 | // car la date est mise d'office par SPIP, |
| 1518 | 1511 | $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['".$col."'])"; |
@@ -1526,7 +1519,7 @@ discard block |
||
| 1526 | 1519 | // le phraseur impose que le premier param soit du texte |
| 1527 | 1520 | $params = $crit->param; |
| 1528 | 1521 | $op = $crit->op; |
| 1529 | - if ($op=='==') $op = 'REGEXP'; |
|
| 1522 | + if ($op == '==') $op = 'REGEXP'; |
|
| 1530 | 1523 | $col = array_shift($params); |
| 1531 | 1524 | $col = $col[0]->texte; |
| 1532 | 1525 | |
@@ -1537,30 +1530,30 @@ discard block |
||
| 1537 | 1530 | // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
| 1538 | 1531 | // celui ne sachant pas ce qu'est un critere infixe |
| 1539 | 1532 | // et a fortiori son 2e operande qu'entoure " ou ' |
| 1540 | - if (count($params)==1 |
|
| 1541 | - AND count($params[0]==3) |
|
| 1542 | - AND $params[0][0]->type=='texte' |
|
| 1543 | - AND @$params[0][2]->type=='texte' |
|
| 1544 | - AND ($p = $params[0][0]->texte)==$params[0][2]->texte |
|
| 1545 | - AND (($p=="'") OR ($p=='"')) |
|
| 1546 | - AND $params[0][1]->type=='champ' |
|
| 1547 | - ){ |
|
| 1533 | + if (count($params) == 1 |
|
| 1534 | + AND count($params[0] == 3) |
|
| 1535 | + AND $params[0][0]->type == 'texte' |
|
| 1536 | + AND @$params[0][2]->type == 'texte' |
|
| 1537 | + AND ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 1538 | + AND (($p == "'") OR ($p == '"')) |
|
| 1539 | + AND $params[0][1]->type == 'champ' |
|
| 1540 | + ) { |
|
| 1548 | 1541 | $val[] = "$p\\$p#".$params[0][1]->nom_champ."\\$p$p"; |
| 1549 | 1542 | } else |
| 1550 | - foreach ((($op!='IN') ? $params : calculer_vieux_in($params)) as $p){ |
|
| 1543 | + foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 1551 | 1544 | $a = calculer_liste($p, $desc, $boucles, $parent); |
| 1552 | - if (strcasecmp($op,'IN')==0) $val[] = $a; |
|
| 1545 | + if (strcasecmp($op, 'IN') == 0) $val[] = $a; |
|
| 1553 | 1546 | else $val[] = kwote($a, $boucles[$idb]->sql_serveur, 'char'); // toujours quoter en char ici |
| 1554 | 1547 | } |
| 1555 | 1548 | } |
| 1556 | 1549 | |
| 1557 | 1550 | $fct = $args_sql = ''; |
| 1558 | 1551 | // fonction SQL ? |
| 1559 | - if (preg_match('/^(.*)'.SQL_ARGS.'$/', $col, $m)){ |
|
| 1552 | + if (preg_match('/^(.*)'.SQL_ARGS.'$/', $col, $m)) { |
|
| 1560 | 1553 | $fct = $m[1]; |
| 1561 | 1554 | preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
| 1562 | 1555 | $col = $a[1]; |
| 1563 | - if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)){ |
|
| 1556 | + if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 1564 | 1557 | $col = $m[1]; |
| 1565 | 1558 | $args_sql = $m[2]; |
| 1566 | 1559 | } |
@@ -1574,28 +1567,28 @@ discard block |
||
| 1574 | 1567 | // compatibilite ancienne version |
| 1575 | 1568 | |
| 1576 | 1569 | // http://doc.spip.org/@calculer_vieux_in |
| 1577 | -function calculer_vieux_in($params){ |
|
| 1570 | +function calculer_vieux_in($params) { |
|
| 1578 | 1571 | $deb = $params[0][0]; |
| 1579 | - $k = count($params)-1; |
|
| 1572 | + $k = count($params) - 1; |
|
| 1580 | 1573 | $last = $params[$k]; |
| 1581 | - $j = count($last)-1; |
|
| 1574 | + $j = count($last) - 1; |
|
| 1582 | 1575 | $last = $last[$j]; |
| 1583 | 1576 | $n = isset($last->texte) ? strlen($last->texte) : 0; |
| 1584 | 1577 | |
| 1585 | - if (!((isset($deb->texte[0]) AND $deb->texte[0]=='(') |
|
| 1586 | - && (isset($last->texte[$n-1]) AND $last->texte[$n-1]==')'))) |
|
| 1578 | + if (!((isset($deb->texte[0]) AND $deb->texte[0] == '(') |
|
| 1579 | + && (isset($last->texte[$n - 1]) AND $last->texte[$n - 1] == ')'))) |
|
| 1587 | 1580 | return $params; |
| 1588 | 1581 | $params[0][0]->texte = substr($deb->texte, 1); |
| 1589 | 1582 | // attention, on peut avoir k=0,j=0 ==> recalculer |
| 1590 | 1583 | $last = $params[$k][$j]; |
| 1591 | 1584 | $n = strlen($last->texte); |
| 1592 | - $params[$k][$j]->texte = substr($last->texte, 0, $n-1); |
|
| 1585 | + $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 1593 | 1586 | $newp = array(); |
| 1594 | - foreach ($params as $v){ |
|
| 1595 | - if ($v[0]->type!='texte') |
|
| 1587 | + foreach ($params as $v) { |
|
| 1588 | + if ($v[0]->type != 'texte') |
|
| 1596 | 1589 | $newp[] = $v; |
| 1597 | 1590 | else { |
| 1598 | - foreach (explode(',', $v[0]->texte) as $x){ |
|
| 1591 | + foreach (explode(',', $v[0]->texte) as $x) { |
|
| 1599 | 1592 | $t = new Texte; |
| 1600 | 1593 | $t->texte = $x; |
| 1601 | 1594 | $newp[] = array($t); |
@@ -1606,17 +1599,17 @@ discard block |
||
| 1606 | 1599 | } |
| 1607 | 1600 | |
| 1608 | 1601 | // http://doc.spip.org/@calculer_critere_infixe_date |
| 1609 | -function calculer_critere_infixe_date($idb, &$boucles, $col){ |
|
| 1602 | +function calculer_critere_infixe_date($idb, &$boucles, $col) { |
|
| 1610 | 1603 | if (!preg_match(",^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z]+)?$,", $col, $regs)) return ''; |
| 1611 | 1604 | $boucle = $boucles[$idb]; |
| 1612 | 1605 | $table = $boucle->show; |
| 1613 | 1606 | // si c'est une colonne de la table, ne rien faire |
| 1614 | - if(isset($table['field'][$col])) return ''; |
|
| 1607 | + if (isset($table['field'][$col])) return ''; |
|
| 1615 | 1608 | |
| 1616 | 1609 | if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) return ''; |
| 1617 | - $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']])? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 1610 | + $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']]) ? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 1618 | 1611 | $col = $regs[1]; |
| 1619 | - if (isset($regs[3]) AND $suite = $regs[3]){ |
|
| 1612 | + if (isset($regs[3]) AND $suite = $regs[3]) { |
|
| 1620 | 1613 | # Recherche de l'existence du champ date_xxxx, |
| 1621 | 1614 | # si oui choisir ce champ, sinon choisir xxxx |
| 1622 | 1615 | |
@@ -1654,34 +1647,34 @@ discard block |
||
| 1654 | 1647 | break; |
| 1655 | 1648 | case 'age': |
| 1656 | 1649 | $col = calculer_param_date("NOW()", $date_orig); |
| 1657 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 1650 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 1658 | 1651 | break; |
| 1659 | 1652 | case 'age_relatif': |
| 1660 | 1653 | $col = calculer_param_date($date_compare, $date_orig); |
| 1661 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 1654 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 1662 | 1655 | break; |
| 1663 | 1656 | case 'jour_relatif': |
| 1664 | 1657 | $col = "(TO_DAYS(".$date_compare.")-TO_DAYS(".$date_orig."))"; |
| 1665 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 1658 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 1666 | 1659 | break; |
| 1667 | 1660 | case 'mois_relatif': |
| 1668 | 1661 | $col = "MONTH(".$date_compare.")-MONTH(". |
| 1669 | 1662 | $date_orig.")+12*(YEAR(".$date_compare. |
| 1670 | 1663 | ")-YEAR(".$date_orig."))"; |
| 1671 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 1664 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 1672 | 1665 | break; |
| 1673 | 1666 | case 'annee_relatif': |
| 1674 | 1667 | $col = "YEAR(".$date_compare.")-YEAR(". |
| 1675 | 1668 | $date_orig.")"; |
| 1676 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 1669 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 1677 | 1670 | break; |
| 1678 | 1671 | } |
| 1679 | - return array($col,$col_vraie); |
|
| 1672 | + return array($col, $col_vraie); |
|
| 1680 | 1673 | } |
| 1681 | 1674 | |
| 1682 | 1675 | // http://doc.spip.org/@calculer_param_date |
| 1683 | -function calculer_param_date($date_compare, $date_orig){ |
|
| 1684 | - if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)){ |
|
| 1676 | +function calculer_param_date($date_compare, $date_orig) { |
|
| 1677 | + if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 1685 | 1678 | $init = "'\" . (\$x = $r[1]) . \"'"; |
| 1686 | 1679 | $date_compare = '\'$x\''; |
| 1687 | 1680 | } |
@@ -1718,7 +1711,7 @@ discard block |
||
| 1718 | 1711 | * @param object $boucles |
| 1719 | 1712 | * @param object $crit |
| 1720 | 1713 | */ |
| 1721 | -function critere_DATA_source_dist($idb, &$boucles, $crit){ |
|
| 1714 | +function critere_DATA_source_dist($idb, &$boucles, $crit) { |
|
| 1722 | 1715 | $boucle = &$boucles[$idb]; |
| 1723 | 1716 | |
| 1724 | 1717 | $args = array(); |
@@ -1740,7 +1733,7 @@ discard block |
||
| 1740 | 1733 | * @param object $boucles |
| 1741 | 1734 | * @param object $crit |
| 1742 | 1735 | */ |
| 1743 | -function critere_DATA_datasource_dist($idb, &$boucles, $crit){ |
|
| 1736 | +function critere_DATA_datasource_dist($idb, &$boucles, $crit) { |
|
| 1744 | 1737 | $boucle = &$boucles[$idb]; |
| 1745 | 1738 | $boucle->hash .= ' |
| 1746 | 1739 | $command[\'source\'] = array('.calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent).'); |
@@ -1754,7 +1747,7 @@ discard block |
||
| 1754 | 1747 | * @param object $boucles |
| 1755 | 1748 | * @param object $crit |
| 1756 | 1749 | */ |
| 1757 | -function critere_DATA_datacache_dist($idb, &$boucles, $crit){ |
|
| 1750 | +function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
|
| 1758 | 1751 | $boucle = &$boucles[$idb]; |
| 1759 | 1752 | $boucle->hash .= ' |
| 1760 | 1753 | $command[\'datacache\'] = '.calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent).';'; |
@@ -1769,10 +1762,10 @@ discard block |
||
| 1769 | 1762 | * @param object $boucles |
| 1770 | 1763 | * @param object $crit |
| 1771 | 1764 | */ |
| 1772 | -function critere_php_args_dist($idb, &$boucles, $crit){ |
|
| 1765 | +function critere_php_args_dist($idb, &$boucles, $crit) { |
|
| 1773 | 1766 | $boucle = &$boucles[$idb]; |
| 1774 | 1767 | $boucle->hash .= '$command[\'args\']=array();'; |
| 1775 | - foreach ($crit->param as $param){ |
|
| 1768 | + foreach ($crit->param as $param) { |
|
| 1776 | 1769 | $boucle->hash .= ' |
| 1777 | 1770 | $command[\'args\'][] = '.calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).';'; |
| 1778 | 1771 | } |
@@ -1786,10 +1779,10 @@ discard block |
||
| 1786 | 1779 | * @param object $boucles |
| 1787 | 1780 | * @param object $crit |
| 1788 | 1781 | */ |
| 1789 | -function critere_DATA_liste_dist($idb, &$boucles, $crit){ |
|
| 1782 | +function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
|
| 1790 | 1783 | $boucle = &$boucles[$idb]; |
| 1791 | 1784 | $boucle->hash .= "\n\t".'$command[\'liste\'] = array();'."\n"; |
| 1792 | - foreach ($crit->param as $param){ |
|
| 1785 | + foreach ($crit->param as $param) { |
|
| 1793 | 1786 | $boucle->hash .= "\t".'$command[\'liste\'][] = '.calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).";\n"; |
| 1794 | 1787 | } |
| 1795 | 1788 | } |
@@ -1802,10 +1795,10 @@ discard block |
||
| 1802 | 1795 | * @param object $boucles |
| 1803 | 1796 | * @param object $crit |
| 1804 | 1797 | */ |
| 1805 | -function critere_DATA_enum_dist($idb, &$boucles, $crit){ |
|
| 1798 | +function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
|
| 1806 | 1799 | $boucle = &$boucles[$idb]; |
| 1807 | 1800 | $boucle->hash .= "\n\t".'$command[\'enum\'] = array();'."\n"; |
| 1808 | - foreach ($crit->param as $param){ |
|
| 1801 | + foreach ($crit->param as $param) { |
|
| 1809 | 1802 | $boucle->hash .= "\t".'$command[\'enum\'][] = '.calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).";\n"; |
| 1810 | 1803 | } |
| 1811 | 1804 | } |
@@ -1818,9 +1811,9 @@ discard block |
||
| 1818 | 1811 | * @param object $boucles |
| 1819 | 1812 | * @param object $crit |
| 1820 | 1813 | */ |
| 1821 | -function critere_DATA_datapath_dist($idb, &$boucles, $crit){ |
|
| 1814 | +function critere_DATA_datapath_dist($idb, &$boucles, $crit) { |
|
| 1822 | 1815 | $boucle = &$boucles[$idb]; |
| 1823 | - foreach ($crit->param as $param){ |
|
| 1816 | + foreach ($crit->param as $param) { |
|
| 1824 | 1817 | $boucle->hash .= ' |
| 1825 | 1818 | $command[\'datapath\'][] = '.calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).';'; |
| 1826 | 1819 | } |
@@ -1834,16 +1827,16 @@ discard block |
||
| 1834 | 1827 | * @param object $boucles |
| 1835 | 1828 | * @param object $crit |
| 1836 | 1829 | */ |
| 1837 | -function critere_si_dist($idb, &$boucles, $crit){ |
|
| 1830 | +function critere_si_dist($idb, &$boucles, $crit) { |
|
| 1838 | 1831 | $boucle = &$boucles[$idb]; |
| 1839 | 1832 | // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
| 1840 | 1833 | // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
| 1841 | 1834 | // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
| 1842 | 1835 | $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
| 1843 | - if ($crit->param){ |
|
| 1844 | - foreach ($crit->param as $param){ |
|
| 1836 | + if ($crit->param) { |
|
| 1837 | + foreach ($crit->param as $param) { |
|
| 1845 | 1838 | $boucle->hash .= "\t\$command['si'][] = " |
| 1846 | - . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 1839 | + . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).";\n"; |
|
| 1847 | 1840 | } |
| 1848 | 1841 | // interdire {si 0} aussi ! |
| 1849 | 1842 | } else { |
@@ -1859,7 +1852,7 @@ discard block |
||
| 1859 | 1852 | * @param object $boucles |
| 1860 | 1853 | * @param object $crit |
| 1861 | 1854 | */ |
| 1862 | -function critere_POUR_tableau_dist($idb, &$boucles, $crit){ |
|
| 1855 | +function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
|
| 1863 | 1856 | $boucle = &$boucles[$idb]; |
| 1864 | 1857 | $boucle->hash .= ' |
| 1865 | 1858 | $command[\'source\'] = array('.calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent).'); |
@@ -1877,13 +1870,13 @@ discard block |
||
| 1877 | 1870 | * @param array $boucles |
| 1878 | 1871 | * @param Object $crit |
| 1879 | 1872 | */ |
| 1880 | -function critere_noeud_dist($idb, &$boucles, $crit){ |
|
| 1873 | +function critere_noeud_dist($idb, &$boucles, $crit) { |
|
| 1881 | 1874 | global $exceptions_des_tables; |
| 1882 | 1875 | $not = $crit->not; |
| 1883 | 1876 | $boucle = &$boucles[$idb]; |
| 1884 | 1877 | $primary = $boucle->primary; |
| 1885 | 1878 | |
| 1886 | - if (!$primary OR strpos($primary, ',')){ |
|
| 1879 | + if (!$primary OR strpos($primary, ',')) { |
|
| 1887 | 1880 | erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
| 1888 | 1881 | return; |
| 1889 | 1882 | } |
@@ -1891,8 +1884,7 @@ discard block |
||
| 1891 | 1884 | $table_sql = table_objet_sql(objet_type($table)); |
| 1892 | 1885 | |
| 1893 | 1886 | $id_parent = isset($exceptions_des_tables[$boucle->id_table]['id_parent']) ? |
| 1894 | - $exceptions_des_tables[$boucle->id_table]['id_parent'] : |
|
| 1895 | - 'id_parent'; |
|
| 1887 | + $exceptions_des_tables[$boucle->id_table]['id_parent'] : 'id_parent'; |
|
| 1896 | 1888 | |
| 1897 | 1889 | $in = "IN"; |
| 1898 | 1890 | $where = array("'IN'", "'$boucle->id_table."."$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
@@ -1912,7 +1904,7 @@ discard block |
||
| 1912 | 1904 | * @param array $boucles |
| 1913 | 1905 | * @param Object $crit |
| 1914 | 1906 | */ |
| 1915 | -function critere_feuille_dist($idb, &$boucles, $crit){ |
|
| 1907 | +function critere_feuille_dist($idb, &$boucles, $crit) { |
|
| 1916 | 1908 | $not = $crit->not; |
| 1917 | 1909 | $crit->not = $not ? false : true; |
| 1918 | 1910 | critere_noeud_dist($idb, $boucles, $crit); |
@@ -374,6 +374,10 @@ discard block |
||
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | // http://doc.spip.org/@reference_boucle_debug |
| 377 | +/** |
|
| 378 | + * @param string $nom |
|
| 379 | + * @param string $self |
|
| 380 | + */ |
|
| 377 | 381 | function reference_boucle_debug($n, $nom, $self){ |
| 378 | 382 | list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
| 379 | 383 | |
@@ -459,6 +463,9 @@ discard block |
||
| 459 | 463 | |
| 460 | 464 | // l'environnement graphique du debuggueur |
| 461 | 465 | |
| 466 | +/** |
|
| 467 | + * @param null|string $self |
|
| 468 | + */ |
|
| 462 | 469 | function debusquer_squelette($fonc, $mode, $self){ |
| 463 | 470 | global $debug_objets; |
| 464 | 471 | |
@@ -745,6 +752,9 @@ discard block |
||
| 745 | 752 | } |
| 746 | 753 | |
| 747 | 754 | // http://doc.spip.org/@debusquer_entete |
| 755 | +/** |
|
| 756 | + * @param string $corps |
|
| 757 | + */ |
|
| 748 | 758 | function debusquer_entete($titre, $corps){ |
| 749 | 759 | global $debug_objets; |
| 750 | 760 | include_spip('balise/formulaire_admin'); |
@@ -64,136 +64,136 @@ discard block |
||
| 64 | 64 | * - string si $message à false. |
| 65 | 65 | **/ |
| 66 | 66 | function public_debusquer_dist($message = '', $lieu = '', $opt = array()){ |
| 67 | - global $visiteur_session; |
|
| 68 | - global $debug_objets; |
|
| 69 | - static $tableau_des_erreurs = array(); |
|
| 70 | - |
|
| 71 | - // Pour des tests unitaires, pouvoir récupérer les erreurs générées |
|
| 72 | - if (isset($opt['erreurs'])) { |
|
| 73 | - if ($opt['erreurs'] == 'get') { |
|
| 74 | - return $tableau_des_erreurs; |
|
| 75 | - } |
|
| 76 | - if ($opt['erreurs'] == 'reset') { |
|
| 77 | - $tableau_des_erreurs = array(); |
|
| 78 | - return true; |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - // Erreur ou appel final ? |
|
| 83 | - if ($message){ |
|
| 84 | - $message = debusquer_compose_message($message); |
|
| 85 | - $tableau_des_erreurs[] = array($message, $lieu); |
|
| 86 | - set_request('var_mode', 'debug'); |
|
| 87 | - $GLOBALS['bouton_admin_debug'] = true; |
|
| 88 | - // Permettre a la compil de continuer |
|
| 89 | - if (is_object($lieu) AND (!isset($lieu->code) OR !$lieu->code)) |
|
| 90 | - $lieu->code = "''"; |
|
| 91 | - // forcer l'appel au debusqueur en cas de boucles infernales |
|
| 92 | - $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS AND count($tableau_des_erreurs)>_DEBUG_MAX_SQUELETTE_ERREURS); |
|
| 93 | - if (!$urgence) return; |
|
| 94 | - } |
|
| 95 | - if (empty($debug_objets['principal'])) |
|
| 96 | - $debug_objets['principal'] = $GLOBALS['fond']; |
|
| 97 | - |
|
| 98 | - include_spip('inc/autoriser'); |
|
| 99 | - if (!autoriser('debug')) return; |
|
| 100 | - include_spip('inc/headers'); |
|
| 101 | - include_spip('inc/filtres'); |
|
| 102 | - |
|
| 103 | - // en cas de squelette inclus, virer le code de l'incluant: |
|
| 104 | - // - il contient souvent une Div restreignant la largeur a 3 fois rien |
|
| 105 | - // - ca fait 2 headers ! |
|
| 106 | - // sauf si l'on se trouve deja dans un flux compresse (plugin compresseur |
|
| 107 | - // actif par exemple) |
|
| 108 | - if (ob_get_length() |
|
| 109 | - AND |
|
| 110 | - !in_array('ob_gzhandler', ob_get_status()) |
|
| 111 | - ){ |
|
| 112 | - ob_end_clean(); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - lang_select($visiteur_session['lang']); |
|
| 116 | - $fonc = _request('var_mode_objet'); |
|
| 117 | - $mode = _request('var_mode_affiche'); |
|
| 118 | - $self = str_replace("\\'", ''', self()); |
|
| 119 | - $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 67 | + global $visiteur_session; |
|
| 68 | + global $debug_objets; |
|
| 69 | + static $tableau_des_erreurs = array(); |
|
| 70 | + |
|
| 71 | + // Pour des tests unitaires, pouvoir récupérer les erreurs générées |
|
| 72 | + if (isset($opt['erreurs'])) { |
|
| 73 | + if ($opt['erreurs'] == 'get') { |
|
| 74 | + return $tableau_des_erreurs; |
|
| 75 | + } |
|
| 76 | + if ($opt['erreurs'] == 'reset') { |
|
| 77 | + $tableau_des_erreurs = array(); |
|
| 78 | + return true; |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + // Erreur ou appel final ? |
|
| 83 | + if ($message){ |
|
| 84 | + $message = debusquer_compose_message($message); |
|
| 85 | + $tableau_des_erreurs[] = array($message, $lieu); |
|
| 86 | + set_request('var_mode', 'debug'); |
|
| 87 | + $GLOBALS['bouton_admin_debug'] = true; |
|
| 88 | + // Permettre a la compil de continuer |
|
| 89 | + if (is_object($lieu) AND (!isset($lieu->code) OR !$lieu->code)) |
|
| 90 | + $lieu->code = "''"; |
|
| 91 | + // forcer l'appel au debusqueur en cas de boucles infernales |
|
| 92 | + $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS AND count($tableau_des_erreurs)>_DEBUG_MAX_SQUELETTE_ERREURS); |
|
| 93 | + if (!$urgence) return; |
|
| 94 | + } |
|
| 95 | + if (empty($debug_objets['principal'])) |
|
| 96 | + $debug_objets['principal'] = $GLOBALS['fond']; |
|
| 97 | + |
|
| 98 | + include_spip('inc/autoriser'); |
|
| 99 | + if (!autoriser('debug')) return; |
|
| 100 | + include_spip('inc/headers'); |
|
| 101 | + include_spip('inc/filtres'); |
|
| 102 | + |
|
| 103 | + // en cas de squelette inclus, virer le code de l'incluant: |
|
| 104 | + // - il contient souvent une Div restreignant la largeur a 3 fois rien |
|
| 105 | + // - ca fait 2 headers ! |
|
| 106 | + // sauf si l'on se trouve deja dans un flux compresse (plugin compresseur |
|
| 107 | + // actif par exemple) |
|
| 108 | + if (ob_get_length() |
|
| 109 | + AND |
|
| 110 | + !in_array('ob_gzhandler', ob_get_status()) |
|
| 111 | + ){ |
|
| 112 | + ob_end_clean(); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + lang_select($visiteur_session['lang']); |
|
| 116 | + $fonc = _request('var_mode_objet'); |
|
| 117 | + $mode = _request('var_mode_affiche'); |
|
| 118 | + $self = str_replace("\\'", ''', self()); |
|
| 119 | + $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 120 | 120 | |
| 121 | - $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 122 | - . '<br />' |
|
| 123 | - . debusquer_squelette($fonc, $mode, $self); |
|
| 124 | - |
|
| 125 | - if (!_DIR_RESTREINT OR headers_sent()) return $res; |
|
| 126 | - if ($tableau_des_erreurs) http_status(503); |
|
| 127 | - |
|
| 128 | - http_no_cache(); |
|
| 129 | - if (isset($_GET['var_profile'])){ |
|
| 130 | - $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 131 | - $titre = parametre_url($titre, 'var_mode', ''); |
|
| 132 | - } |
|
| 133 | - else { |
|
| 134 | - if (!$fonc) $fonc = $debug_objets['principal']; |
|
| 135 | - $titre = !$mode ? $fonc : ($mode . ' ' . $debug_objets['sourcefile'][$fonc]); |
|
| 136 | - } |
|
| 137 | - if ($message===false){ |
|
| 138 | - lang_select(); |
|
| 139 | - return debusquer_entete($titre, $res); |
|
| 140 | - } |
|
| 141 | - else |
|
| 142 | - echo debusquer_entete($titre, $res); |
|
| 143 | - exit; |
|
| 121 | + $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 122 | + . '<br />' |
|
| 123 | + . debusquer_squelette($fonc, $mode, $self); |
|
| 124 | + |
|
| 125 | + if (!_DIR_RESTREINT OR headers_sent()) return $res; |
|
| 126 | + if ($tableau_des_erreurs) http_status(503); |
|
| 127 | + |
|
| 128 | + http_no_cache(); |
|
| 129 | + if (isset($_GET['var_profile'])){ |
|
| 130 | + $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 131 | + $titre = parametre_url($titre, 'var_mode', ''); |
|
| 132 | + } |
|
| 133 | + else { |
|
| 134 | + if (!$fonc) $fonc = $debug_objets['principal']; |
|
| 135 | + $titre = !$mode ? $fonc : ($mode . ' ' . $debug_objets['sourcefile'][$fonc]); |
|
| 136 | + } |
|
| 137 | + if ($message===false){ |
|
| 138 | + lang_select(); |
|
| 139 | + return debusquer_entete($titre, $res); |
|
| 140 | + } |
|
| 141 | + else |
|
| 142 | + echo debusquer_entete($titre, $res); |
|
| 143 | + exit; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | function debusquer_compose_message($msg){ |
| 147 | - if (is_array($msg)){ |
|
| 148 | - // si c'est un texte, c'est une traduction a faire, mais |
|
| 149 | - // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 150 | - if (!is_numeric($msg[0]) AND count($msg)==2) { |
|
| 151 | - // message avec argument: instancier |
|
| 152 | - $msg = _T($msg[0], $msg[1], 'spip-debug-arg'); |
|
| 153 | - } else { |
|
| 154 | - // message SQL: interpreter |
|
| 155 | - $msg = debusquer_requete($msg); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 159 | - // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 160 | - $fond = isset($GLOBALS['fond']) ? $GLOBALS['fond'] : ""; |
|
| 161 | - // une erreur critique sort $message en array |
|
| 162 | - $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 163 | - spip_log("Debug: " . $debug . " (" . $fond . ")"); |
|
| 164 | - return $msg; |
|
| 147 | + if (is_array($msg)){ |
|
| 148 | + // si c'est un texte, c'est une traduction a faire, mais |
|
| 149 | + // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 150 | + if (!is_numeric($msg[0]) AND count($msg)==2) { |
|
| 151 | + // message avec argument: instancier |
|
| 152 | + $msg = _T($msg[0], $msg[1], 'spip-debug-arg'); |
|
| 153 | + } else { |
|
| 154 | + // message SQL: interpreter |
|
| 155 | + $msg = debusquer_requete($msg); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 159 | + // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 160 | + $fond = isset($GLOBALS['fond']) ? $GLOBALS['fond'] : ""; |
|
| 161 | + // une erreur critique sort $message en array |
|
| 162 | + $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 163 | + spip_log("Debug: " . $debug . " (" . $fond . ")"); |
|
| 164 | + return $msg; |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | function debusquer_bandeau($erreurs){ |
| 168 | 168 | |
| 169 | - if (!empty($erreurs)){ |
|
| 170 | - $n = array(count($erreurs) . ' ' . _T('zbug_erreur_squelette')); |
|
| 171 | - return debusquer_navigation($erreurs, $n); |
|
| 172 | - } |
|
| 173 | - elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 174 | - include_spip('public/tracer'); |
|
| 175 | - list($temps, $nav) = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 176 | - return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 177 | - } |
|
| 178 | - else |
|
| 179 | - return ''; |
|
| 169 | + if (!empty($erreurs)){ |
|
| 170 | + $n = array(count($erreurs) . ' ' . _T('zbug_erreur_squelette')); |
|
| 171 | + return debusquer_navigation($erreurs, $n); |
|
| 172 | + } |
|
| 173 | + elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 174 | + include_spip('public/tracer'); |
|
| 175 | + list($temps, $nav) = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 176 | + return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 177 | + } |
|
| 178 | + else |
|
| 179 | + return ''; |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | function debusquer_contexte($env){ |
| 183 | 183 | |
| 184 | - if (is_array($env_tab = @unserialize($env))) $env = $env_tab; |
|
| 184 | + if (is_array($env_tab = @unserialize($env))) $env = $env_tab; |
|
| 185 | 185 | |
| 186 | - if (!$env) return ''; |
|
| 187 | - $res = ""; |
|
| 188 | - foreach ($env as $nom => $valeur){ |
|
| 189 | - if (is_array($valeur)) |
|
| 190 | - $valeur = '(' . count($valeur) . ' items) [' . join(',', $valeur) . ']'; |
|
| 191 | - $res .= "\n<tr><td><strong>" . nl2br(entites_html($nom)) |
|
| 192 | - . "</strong></td><td>: " . nl2br(entites_html($valeur)) |
|
| 193 | - . "</td></tr>\n"; |
|
| 194 | - } |
|
| 186 | + if (!$env) return ''; |
|
| 187 | + $res = ""; |
|
| 188 | + foreach ($env as $nom => $valeur){ |
|
| 189 | + if (is_array($valeur)) |
|
| 190 | + $valeur = '(' . count($valeur) . ' items) [' . join(',', $valeur) . ']'; |
|
| 191 | + $res .= "\n<tr><td><strong>" . nl2br(entites_html($nom)) |
|
| 192 | + . "</strong></td><td>: " . nl2br(entites_html($valeur)) |
|
| 193 | + . "</td></tr>\n"; |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - return "<div class='spip-env'><fieldset><legend>#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n"; |
|
| 196 | + return "<div class='spip-env'><fieldset><legend>#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n"; |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | // Affichage du tableau des erreurs ou des temps de calcul |
@@ -201,65 +201,65 @@ discard block |
||
| 201 | 201 | |
| 202 | 202 | function debusquer_navigation($tableau, $caption = array(), $id = 'debug-nav'){ |
| 203 | 203 | |
| 204 | - if (_request('exec')=='valider_xml') return ''; |
|
| 205 | - $GLOBALS['bouton_admin_debug'] = true; |
|
| 206 | - $res = ''; |
|
| 207 | - $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
|
| 208 | - foreach ($tableau as $i => $err){ |
|
| 209 | - $boucle = $ligne = $skel = ''; |
|
| 210 | - list($msg, $lieu) = $err; |
|
| 211 | - if (is_object($lieu)){ |
|
| 212 | - $ligne = $lieu->ligne; |
|
| 213 | - $boucle = $lieu->id_boucle ? $lieu->id_boucle : ''; |
|
| 214 | - if (isset($lieu->descr['nom'])){ |
|
| 215 | - $nom_code = $lieu->descr['nom']; |
|
| 216 | - $skel = $lieu->descr['sourcefile']; |
|
| 217 | - $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
|
| 218 | - $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 219 | - $skel = "<a href='$h3'><b>$skel</b></a>"; |
|
| 220 | - if ($boucle){ |
|
| 221 | - $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 222 | - $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - $j = ($i+1); |
|
| 228 | - $res .= "<tr id='req$j'><td style='text-align: right'>" |
|
| 229 | - . $j |
|
| 230 | - . " </td><td style='text-align: left'>" |
|
| 231 | - . $msg |
|
| 232 | - . "</td><td style='text-align: left'>" |
|
| 233 | - . ($skel ? $skel : " / ") |
|
| 234 | - . "</td><td class='spip-debug-arg' style='text-align: left'>" |
|
| 235 | - . ($boucle ? $boucle : " / ") |
|
| 236 | - . "</td><td style='text-align: right'>" |
|
| 237 | - . $ligne |
|
| 238 | - . "</td></tr>\n"; |
|
| 239 | - |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - return "\n<table id='$id'>" |
|
| 243 | - . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 244 | - . $caption[0] |
|
| 204 | + if (_request('exec')=='valider_xml') return ''; |
|
| 205 | + $GLOBALS['bouton_admin_debug'] = true; |
|
| 206 | + $res = ''; |
|
| 207 | + $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
|
| 208 | + foreach ($tableau as $i => $err){ |
|
| 209 | + $boucle = $ligne = $skel = ''; |
|
| 210 | + list($msg, $lieu) = $err; |
|
| 211 | + if (is_object($lieu)){ |
|
| 212 | + $ligne = $lieu->ligne; |
|
| 213 | + $boucle = $lieu->id_boucle ? $lieu->id_boucle : ''; |
|
| 214 | + if (isset($lieu->descr['nom'])){ |
|
| 215 | + $nom_code = $lieu->descr['nom']; |
|
| 216 | + $skel = $lieu->descr['sourcefile']; |
|
| 217 | + $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
|
| 218 | + $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 219 | + $skel = "<a href='$h3'><b>$skel</b></a>"; |
|
| 220 | + if ($boucle){ |
|
| 221 | + $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 222 | + $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + $j = ($i+1); |
|
| 228 | + $res .= "<tr id='req$j'><td style='text-align: right'>" |
|
| 229 | + . $j |
|
| 230 | + . " </td><td style='text-align: left'>" |
|
| 231 | + . $msg |
|
| 232 | + . "</td><td style='text-align: left'>" |
|
| 233 | + . ($skel ? $skel : " / ") |
|
| 234 | + . "</td><td class='spip-debug-arg' style='text-align: left'>" |
|
| 235 | + . ($boucle ? $boucle : " / ") |
|
| 236 | + . "</td><td style='text-align: right'>" |
|
| 237 | + . $ligne |
|
| 238 | + . "</td></tr>\n"; |
|
| 239 | + |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + return "\n<table id='$id'>" |
|
| 243 | + . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 244 | + . $caption[0] |
|
| 245 | 245 | ## aide locale courte a ecrire, avec lien vers une grosse page de documentation |
| 246 | 246 | # aide('erreur_compilation'), |
| 247 | - . "</caption>" |
|
| 248 | - // fausse caption du chrono (mais vraie nav) |
|
| 249 | - . (!empty($caption[1]) ? $caption[1] : '') |
|
| 250 | - . "<tr><th>" |
|
| 251 | - . _T('numero') |
|
| 252 | - . "</th><th>" |
|
| 253 | - . _T('public:message') |
|
| 254 | - . "</th><th>" |
|
| 255 | - . _T('squelette') |
|
| 256 | - . "</th><th>" |
|
| 257 | - . _T('zbug_boucle') |
|
| 258 | - . "</th><th>" |
|
| 259 | - . _T('ligne') |
|
| 260 | - . "</th></tr>" |
|
| 261 | - . $res |
|
| 262 | - . "</table>"; |
|
| 247 | + . "</caption>" |
|
| 248 | + // fausse caption du chrono (mais vraie nav) |
|
| 249 | + . (!empty($caption[1]) ? $caption[1] : '') |
|
| 250 | + . "<tr><th>" |
|
| 251 | + . _T('numero') |
|
| 252 | + . "</th><th>" |
|
| 253 | + . _T('public:message') |
|
| 254 | + . "</th><th>" |
|
| 255 | + . _T('squelette') |
|
| 256 | + . "</th><th>" |
|
| 257 | + . _T('zbug_boucle') |
|
| 258 | + . "</th><th>" |
|
| 259 | + . _T('ligne') |
|
| 260 | + . "</th></tr>" |
|
| 261 | + . $res |
|
| 262 | + . "</table>"; |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | |
@@ -279,116 +279,116 @@ discard block |
||
| 279 | 279 | * ou un tableau si l'erreur est critique |
| 280 | 280 | **/ |
| 281 | 281 | function debusquer_requete($message){ |
| 282 | - list($errno, $msg, $query) = $message; |
|
| 283 | - |
|
| 284 | - // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 285 | - // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 286 | - if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)){ |
|
| 287 | - $errno = $regs[2]; |
|
| 288 | - } |
|
| 289 | - elseif (is_numeric($errno) and ($errno==1030 OR $errno<=1026) |
|
| 290 | - AND preg_match(',[^[:alnum:]]([0-9]+)[^[:alnum:]],', $msg, $regs) |
|
| 291 | - ) { |
|
| 292 | - $errno = $regs[1]; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - // Erreur systeme |
|
| 296 | - if (is_numeric($errno) and $errno>0 AND $errno<200){ |
|
| 297 | - $retour = "<tt><br /><br /><blink>" |
|
| 298 | - . _T('info_erreur_systeme', array('errsys' => $errno)) |
|
| 299 | - . "</blink><br />\n<b>" |
|
| 300 | - . _T('info_erreur_systeme2', |
|
| 301 | - array('script' => generer_url_ecrire('base_repair'))) |
|
| 302 | - . '</b><br />'; |
|
| 303 | - spip_log("Erreur systeme $errno"); |
|
| 304 | - return array($retour, ''); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - // Requete erronee |
|
| 308 | - $err = "<b>" . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 309 | - . spip_htmlspecialchars($msg) |
|
| 310 | - . "\n<br /><span style='color: red'><b>" |
|
| 311 | - . spip_htmlspecialchars($query) |
|
| 312 | - . "</b></span></tt><br />"; |
|
| 313 | - //. aide('erreur_mysql'); |
|
| 314 | - |
|
| 315 | - return $err; |
|
| 282 | + list($errno, $msg, $query) = $message; |
|
| 283 | + |
|
| 284 | + // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 285 | + // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 286 | + if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)){ |
|
| 287 | + $errno = $regs[2]; |
|
| 288 | + } |
|
| 289 | + elseif (is_numeric($errno) and ($errno==1030 OR $errno<=1026) |
|
| 290 | + AND preg_match(',[^[:alnum:]]([0-9]+)[^[:alnum:]],', $msg, $regs) |
|
| 291 | + ) { |
|
| 292 | + $errno = $regs[1]; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + // Erreur systeme |
|
| 296 | + if (is_numeric($errno) and $errno>0 AND $errno<200){ |
|
| 297 | + $retour = "<tt><br /><br /><blink>" |
|
| 298 | + . _T('info_erreur_systeme', array('errsys' => $errno)) |
|
| 299 | + . "</blink><br />\n<b>" |
|
| 300 | + . _T('info_erreur_systeme2', |
|
| 301 | + array('script' => generer_url_ecrire('base_repair'))) |
|
| 302 | + . '</b><br />'; |
|
| 303 | + spip_log("Erreur systeme $errno"); |
|
| 304 | + return array($retour, ''); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + // Requete erronee |
|
| 308 | + $err = "<b>" . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 309 | + . spip_htmlspecialchars($msg) |
|
| 310 | + . "\n<br /><span style='color: red'><b>" |
|
| 311 | + . spip_htmlspecialchars($query) |
|
| 312 | + . "</b></span></tt><br />"; |
|
| 313 | + //. aide('erreur_mysql'); |
|
| 314 | + |
|
| 315 | + return $err; |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | |
| 319 | 319 | |
| 320 | 320 | // http://doc.spip.org/@trouve_boucle_debug |
| 321 | 321 | function trouve_boucle_debug($n, $nom, $debut = 0, $boucle = ""){ |
| 322 | - global $debug_objets; |
|
| 323 | - |
|
| 324 | - $id = $nom . $boucle; |
|
| 325 | - if (is_array($debug_objets['sequence'][$id])){ |
|
| 326 | - foreach ($debug_objets['sequence'][$id] as $v){ |
|
| 327 | - |
|
| 328 | - if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) |
|
| 329 | - $y = substr_count($v[0], "\n"); |
|
| 330 | - else { |
|
| 331 | - if ($v[1][0]=='#') |
|
| 332 | - // balise dynamique |
|
| 333 | - $incl = $debug_objets['resultat'][$v[2]]; |
|
| 334 | - else |
|
| 335 | - // inclusion |
|
| 336 | - $incl = $debug_objets['squelette'][trouve_squelette_inclus($v[0])]; |
|
| 337 | - $y = substr_count($incl, "\n") |
|
| 338 | - +substr_count($r[1], "\n") |
|
| 339 | - +substr_count($r[3], "\n"); |
|
| 340 | - } |
|
| 341 | - if ($n<=($y+$debut)){ |
|
| 342 | - if ($v[1][0]=='?') |
|
| 343 | - return trouve_boucle_debug($n, $nom, $debut, substr($v[1], 1)); |
|
| 344 | - elseif ($v[1][0]=='!') { |
|
| 345 | - if ($incl = trouve_squelette_inclus($v[1])) |
|
| 346 | - return trouve_boucle_debug($n, $incl, $debut); |
|
| 347 | - } |
|
| 348 | - return array($nom, $boucle, $v[2]-1+$n-$debut); |
|
| 349 | - } |
|
| 350 | - $debut += $y; |
|
| 351 | - } |
|
| 352 | - } |
|
| 353 | - return array($nom, $boucle, $n-$debut); |
|
| 322 | + global $debug_objets; |
|
| 323 | + |
|
| 324 | + $id = $nom . $boucle; |
|
| 325 | + if (is_array($debug_objets['sequence'][$id])){ |
|
| 326 | + foreach ($debug_objets['sequence'][$id] as $v){ |
|
| 327 | + |
|
| 328 | + if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) |
|
| 329 | + $y = substr_count($v[0], "\n"); |
|
| 330 | + else { |
|
| 331 | + if ($v[1][0]=='#') |
|
| 332 | + // balise dynamique |
|
| 333 | + $incl = $debug_objets['resultat'][$v[2]]; |
|
| 334 | + else |
|
| 335 | + // inclusion |
|
| 336 | + $incl = $debug_objets['squelette'][trouve_squelette_inclus($v[0])]; |
|
| 337 | + $y = substr_count($incl, "\n") |
|
| 338 | + +substr_count($r[1], "\n") |
|
| 339 | + +substr_count($r[3], "\n"); |
|
| 340 | + } |
|
| 341 | + if ($n<=($y+$debut)){ |
|
| 342 | + if ($v[1][0]=='?') |
|
| 343 | + return trouve_boucle_debug($n, $nom, $debut, substr($v[1], 1)); |
|
| 344 | + elseif ($v[1][0]=='!') { |
|
| 345 | + if ($incl = trouve_squelette_inclus($v[1])) |
|
| 346 | + return trouve_boucle_debug($n, $incl, $debut); |
|
| 347 | + } |
|
| 348 | + return array($nom, $boucle, $v[2]-1+$n-$debut); |
|
| 349 | + } |
|
| 350 | + $debut += $y; |
|
| 351 | + } |
|
| 352 | + } |
|
| 353 | + return array($nom, $boucle, $n-$debut); |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | // http://doc.spip.org/@trouve_squelette_inclus |
| 357 | 357 | function trouve_squelette_inclus($script){ |
| 358 | - global $debug_objets; |
|
| 359 | - preg_match('/include\(.(.*).php3?.\);/', $script, $reg); |
|
| 360 | - // si le script X.php n'est pas ecrire/public.php |
|
| 361 | - // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
|
| 362 | - if ($reg[1]=='ecrire/public') |
|
| 363 | - // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 364 | - if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) |
|
| 365 | - // a defaut on cherche le param 'page' |
|
| 366 | - if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) |
|
| 367 | - $reg[1] = "inconnu"; |
|
| 368 | - $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 369 | - |
|
| 370 | - foreach ($debug_objets['sourcefile'] as $k => $v){ |
|
| 371 | - if (preg_match($incl, $v)) return $k; |
|
| 372 | - } |
|
| 373 | - return ""; |
|
| 358 | + global $debug_objets; |
|
| 359 | + preg_match('/include\(.(.*).php3?.\);/', $script, $reg); |
|
| 360 | + // si le script X.php n'est pas ecrire/public.php |
|
| 361 | + // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
|
| 362 | + if ($reg[1]=='ecrire/public') |
|
| 363 | + // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 364 | + if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) |
|
| 365 | + // a defaut on cherche le param 'page' |
|
| 366 | + if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) |
|
| 367 | + $reg[1] = "inconnu"; |
|
| 368 | + $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 369 | + |
|
| 370 | + foreach ($debug_objets['sourcefile'] as $k => $v){ |
|
| 371 | + if (preg_match($incl, $v)) return $k; |
|
| 372 | + } |
|
| 373 | + return ""; |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | // http://doc.spip.org/@reference_boucle_debug |
| 377 | 377 | function reference_boucle_debug($n, $nom, $self){ |
| 378 | - list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
|
| 379 | - |
|
| 380 | - if (!$boucle) |
|
| 381 | - return !$ligne ? "" : |
|
| 382 | - (" (" . |
|
| 383 | - (($nom!=$skel) ? _T('squelette_inclus_ligne') : |
|
| 384 | - _T('squelette_ligne')) . |
|
| 385 | - " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
|
| 386 | - else { |
|
| 387 | - $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 388 | - |
|
| 389 | - return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 390 | - " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 391 | - } |
|
| 378 | + list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
|
| 379 | + |
|
| 380 | + if (!$boucle) |
|
| 381 | + return !$ligne ? "" : |
|
| 382 | + (" (" . |
|
| 383 | + (($nom!=$skel) ? _T('squelette_inclus_ligne') : |
|
| 384 | + _T('squelette_ligne')) . |
|
| 385 | + " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
|
| 386 | + else { |
|
| 387 | + $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 388 | + |
|
| 389 | + return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 390 | + " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 391 | + } |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | // affiche un texte avec numero de ligne et ancre. |
@@ -396,380 +396,380 @@ discard block |
||
| 396 | 396 | // http://doc.spip.org/@ancre_texte |
| 397 | 397 | function ancre_texte($texte, $fautifs = array(), $nocpt = false){ |
| 398 | 398 | |
| 399 | - $var_mode_ligne = _request('var_mode_ligne'); |
|
| 400 | - if ($var_mode_ligne) $fautifs[] = array($var_mode_ligne); |
|
| 401 | - $res = ''; |
|
| 402 | - |
|
| 403 | - $s = highlight_string($texte, true); |
|
| 404 | - if (substr($s, 0, 6)=='<code>'){ |
|
| 405 | - $s = substr($s, 6); |
|
| 406 | - $res = '<code>'; |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - $s = preg_replace(',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 410 | - '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 411 | - $s); |
|
| 412 | - |
|
| 413 | - |
|
| 414 | - $tableau = explode("<br />", $s); |
|
| 415 | - |
|
| 416 | - $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: " . ($nocpt ? 'hidden' : 'visible') . ";%s' href='#T%s' title=\"%s\">%0" . strval(@strlen(count($tableau))) . "d</a></span> %s<br />\n"; |
|
| 417 | - |
|
| 418 | - $format10 = str_replace('white', 'lightgrey', $format); |
|
| 419 | - $formaterr = "color: red;"; |
|
| 420 | - $i = 1; |
|
| 421 | - $flignes = array(); |
|
| 422 | - $loc = array(0, 0); |
|
| 423 | - foreach ($fautifs as $lc) |
|
| 424 | - if (is_array($lc)){ |
|
| 425 | - $l = array_shift($lc); |
|
| 426 | - $flignes[$l] = $lc; |
|
| 427 | - } else $flignes[$lc] = $loc; |
|
| 428 | - |
|
| 429 | - $ancre = md5($texte); |
|
| 430 | - foreach ($tableau as $ligne){ |
|
| 431 | - if (isset($flignes[$i])){ |
|
| 432 | - $ligne = str_replace(' ', ' ', $ligne); |
|
| 433 | - $indexmesg = $flignes[$i][1]; |
|
| 434 | - $err = textebrut($flignes[$i][2]); |
|
| 435 | - // tentative de pointer sur la colonne fautive; |
|
| 436 | - // marche pas car highlight_string rajoute des entites. A revoir. |
|
| 437 | - // $m = $flignes[$i][0]; |
|
| 438 | - // $ligne = substr($ligne, 0, $m-1) . |
|
| 439 | - // sprintf($formaterr, substr($ligne,$m)); |
|
| 440 | - $bg = $formaterr; |
|
| 441 | - } else { |
|
| 442 | - $indexmesg = $ancre; |
|
| 443 | - $err = $bg = ''; |
|
| 444 | - } |
|
| 445 | - $res .= sprintf((($i%10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 446 | - $i++; |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - return "<div id='T$ancre'>" |
|
| 450 | - . '<div onclick="' |
|
| 451 | - . "jQuery(this).parent().find('a').toggle();" |
|
| 452 | - . '" title="' |
|
| 453 | - . _T('masquer_colonne') |
|
| 454 | - . '" style="cursor: pointer;">' |
|
| 455 | - . ($nocpt ? '' : _T('info_numero_abbreviation')) |
|
| 456 | - . "</div> |
|
| 399 | + $var_mode_ligne = _request('var_mode_ligne'); |
|
| 400 | + if ($var_mode_ligne) $fautifs[] = array($var_mode_ligne); |
|
| 401 | + $res = ''; |
|
| 402 | + |
|
| 403 | + $s = highlight_string($texte, true); |
|
| 404 | + if (substr($s, 0, 6)=='<code>'){ |
|
| 405 | + $s = substr($s, 6); |
|
| 406 | + $res = '<code>'; |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + $s = preg_replace(',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 410 | + '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 411 | + $s); |
|
| 412 | + |
|
| 413 | + |
|
| 414 | + $tableau = explode("<br />", $s); |
|
| 415 | + |
|
| 416 | + $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: " . ($nocpt ? 'hidden' : 'visible') . ";%s' href='#T%s' title=\"%s\">%0" . strval(@strlen(count($tableau))) . "d</a></span> %s<br />\n"; |
|
| 417 | + |
|
| 418 | + $format10 = str_replace('white', 'lightgrey', $format); |
|
| 419 | + $formaterr = "color: red;"; |
|
| 420 | + $i = 1; |
|
| 421 | + $flignes = array(); |
|
| 422 | + $loc = array(0, 0); |
|
| 423 | + foreach ($fautifs as $lc) |
|
| 424 | + if (is_array($lc)){ |
|
| 425 | + $l = array_shift($lc); |
|
| 426 | + $flignes[$l] = $lc; |
|
| 427 | + } else $flignes[$lc] = $loc; |
|
| 428 | + |
|
| 429 | + $ancre = md5($texte); |
|
| 430 | + foreach ($tableau as $ligne){ |
|
| 431 | + if (isset($flignes[$i])){ |
|
| 432 | + $ligne = str_replace(' ', ' ', $ligne); |
|
| 433 | + $indexmesg = $flignes[$i][1]; |
|
| 434 | + $err = textebrut($flignes[$i][2]); |
|
| 435 | + // tentative de pointer sur la colonne fautive; |
|
| 436 | + // marche pas car highlight_string rajoute des entites. A revoir. |
|
| 437 | + // $m = $flignes[$i][0]; |
|
| 438 | + // $ligne = substr($ligne, 0, $m-1) . |
|
| 439 | + // sprintf($formaterr, substr($ligne,$m)); |
|
| 440 | + $bg = $formaterr; |
|
| 441 | + } else { |
|
| 442 | + $indexmesg = $ancre; |
|
| 443 | + $err = $bg = ''; |
|
| 444 | + } |
|
| 445 | + $res .= sprintf((($i%10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 446 | + $i++; |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + return "<div id='T$ancre'>" |
|
| 450 | + . '<div onclick="' |
|
| 451 | + . "jQuery(this).parent().find('a').toggle();" |
|
| 452 | + . '" title="' |
|
| 453 | + . _T('masquer_colonne') |
|
| 454 | + . '" style="cursor: pointer;">' |
|
| 455 | + . ($nocpt ? '' : _T('info_numero_abbreviation')) |
|
| 456 | + . "</div> |
|
| 457 | 457 | " . $res . "</div>\n"; |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | // l'environnement graphique du debuggueur |
| 461 | 461 | |
| 462 | 462 | function debusquer_squelette($fonc, $mode, $self){ |
| 463 | - global $debug_objets; |
|
| 464 | - |
|
| 465 | - if ($mode!=='validation'){ |
|
| 466 | - if (isset($debug_objets['sourcefile']) and $debug_objets['sourcefile']){ |
|
| 467 | - $res = "<div id='spip-boucles'>\n" |
|
| 468 | - . debusquer_navigation_squelettes($self) |
|
| 469 | - . "</div>"; |
|
| 470 | - } |
|
| 471 | - else |
|
| 472 | - $res = ''; |
|
| 473 | - if ($fonc){ |
|
| 474 | - $id = " id='$fonc'"; |
|
| 475 | - if (!empty($GLOBALS['debug_objets'][$mode][$fonc])){ |
|
| 476 | - list($legend, $texte, $res2) = debusquer_source($fonc, $mode); |
|
| 477 | - $texte .= $res2; |
|
| 478 | - } |
|
| 479 | - elseif (!empty($debug_objets[$mode][$fonc . 'tout'])) { |
|
| 480 | - $legend = _T('zbug_' . $mode); |
|
| 481 | - $texte = $debug_objets[$mode][$fonc . 'tout']; |
|
| 482 | - $texte = ancre_texte($texte, array('', '')); |
|
| 483 | - } |
|
| 484 | - } |
|
| 485 | - else |
|
| 486 | - return strlen(trim($res)) |
|
| 487 | - ? "<img src='".chemin_image('compat-16.png')."' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>" |
|
| 488 | - // cas de l'appel sur erreur: montre la page |
|
| 489 | - : $GLOBALS['debug_objets']['resultat']['tout']; |
|
| 490 | - } |
|
| 491 | - else { |
|
| 492 | - $valider = charger_fonction('valider', 'xml'); |
|
| 493 | - $val = $valider($debug_objets['validation'][$fonc . 'tout']); |
|
| 494 | - // Si erreur, signaler leur nombre dans le formulaire admin |
|
| 495 | - $debug_objets['validation'] = $val->err ? count($val->err) : ''; |
|
| 496 | - list($texte, $err) = emboite_texte($val, $fonc, $self); |
|
| 497 | - if ($err===false) |
|
| 498 | - $err = _T('impossible'); |
|
| 499 | - elseif ($err===true) |
|
| 500 | - $err = _T('correcte'); |
|
| 501 | - else |
|
| 502 | - $err = ": $err"; |
|
| 503 | - $legend = _T('validation') . ' ' . $err; |
|
| 504 | - $res = $id = ''; |
|
| 505 | - } |
|
| 506 | - return !trim($texte) ? '' : ( |
|
| 507 | - "<img src='".chemin_image('compat-16.png')."' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 508 | - . "<div id='debug_boucle'><fieldset$id><legend>" |
|
| 509 | - . "<a href='".$self."#f_".substr($fonc, 0, 37)."'> ↑ " |
|
| 510 | - . ($legend ? $legend : $mode) |
|
| 511 | - . "</a></legend>" |
|
| 512 | - . $texte |
|
| 513 | - . "</fieldset></div>" |
|
| 514 | - . "</div>"); |
|
| 463 | + global $debug_objets; |
|
| 464 | + |
|
| 465 | + if ($mode!=='validation'){ |
|
| 466 | + if (isset($debug_objets['sourcefile']) and $debug_objets['sourcefile']){ |
|
| 467 | + $res = "<div id='spip-boucles'>\n" |
|
| 468 | + . debusquer_navigation_squelettes($self) |
|
| 469 | + . "</div>"; |
|
| 470 | + } |
|
| 471 | + else |
|
| 472 | + $res = ''; |
|
| 473 | + if ($fonc){ |
|
| 474 | + $id = " id='$fonc'"; |
|
| 475 | + if (!empty($GLOBALS['debug_objets'][$mode][$fonc])){ |
|
| 476 | + list($legend, $texte, $res2) = debusquer_source($fonc, $mode); |
|
| 477 | + $texte .= $res2; |
|
| 478 | + } |
|
| 479 | + elseif (!empty($debug_objets[$mode][$fonc . 'tout'])) { |
|
| 480 | + $legend = _T('zbug_' . $mode); |
|
| 481 | + $texte = $debug_objets[$mode][$fonc . 'tout']; |
|
| 482 | + $texte = ancre_texte($texte, array('', '')); |
|
| 483 | + } |
|
| 484 | + } |
|
| 485 | + else |
|
| 486 | + return strlen(trim($res)) |
|
| 487 | + ? "<img src='".chemin_image('compat-16.png')."' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>" |
|
| 488 | + // cas de l'appel sur erreur: montre la page |
|
| 489 | + : $GLOBALS['debug_objets']['resultat']['tout']; |
|
| 490 | + } |
|
| 491 | + else { |
|
| 492 | + $valider = charger_fonction('valider', 'xml'); |
|
| 493 | + $val = $valider($debug_objets['validation'][$fonc . 'tout']); |
|
| 494 | + // Si erreur, signaler leur nombre dans le formulaire admin |
|
| 495 | + $debug_objets['validation'] = $val->err ? count($val->err) : ''; |
|
| 496 | + list($texte, $err) = emboite_texte($val, $fonc, $self); |
|
| 497 | + if ($err===false) |
|
| 498 | + $err = _T('impossible'); |
|
| 499 | + elseif ($err===true) |
|
| 500 | + $err = _T('correcte'); |
|
| 501 | + else |
|
| 502 | + $err = ": $err"; |
|
| 503 | + $legend = _T('validation') . ' ' . $err; |
|
| 504 | + $res = $id = ''; |
|
| 505 | + } |
|
| 506 | + return !trim($texte) ? '' : ( |
|
| 507 | + "<img src='".chemin_image('compat-16.png')."' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 508 | + . "<div id='debug_boucle'><fieldset$id><legend>" |
|
| 509 | + . "<a href='".$self."#f_".substr($fonc, 0, 37)."'> ↑ " |
|
| 510 | + . ($legend ? $legend : $mode) |
|
| 511 | + . "</a></legend>" |
|
| 512 | + . $texte |
|
| 513 | + . "</fieldset></div>" |
|
| 514 | + . "</div>"); |
|
| 515 | 515 | } |
| 516 | 516 | |
| 517 | 517 | |
| 518 | 518 | // http://doc.spip.org/@emboite_texte |
| 519 | 519 | function emboite_texte($res, $fonc = '', $self = ''){ |
| 520 | - $errs = $res->err; |
|
| 521 | - $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 522 | - |
|
| 523 | - if (!$texte and !$errs) |
|
| 524 | - return array(ancre_texte('', array('', '')), false); |
|
| 525 | - if (!$errs) |
|
| 526 | - return array(ancre_texte($texte, array('', '')), true); |
|
| 527 | - |
|
| 528 | - if (!isset($GLOBALS['debug_objets'])){ |
|
| 529 | - |
|
| 530 | - $colors = array('#e0e0f0', '#f8f8ff'); |
|
| 531 | - $encore = count_occ($errs); |
|
| 532 | - $encore2 = array(); |
|
| 533 | - $fautifs = array(); |
|
| 534 | - |
|
| 535 | - $err = '<tr><th>' |
|
| 536 | - . _T('numero') |
|
| 537 | - . "</th><th>" |
|
| 538 | - . _T('occurence') |
|
| 539 | - . "</th><th>" |
|
| 540 | - . _T('ligne') |
|
| 541 | - . "</th><th>" |
|
| 542 | - . _T('colonne') |
|
| 543 | - . "</th><th>" |
|
| 544 | - . _T('erreur') |
|
| 545 | - . "</th></tr>"; |
|
| 546 | - |
|
| 547 | - $i = 0; |
|
| 548 | - $style = "style='text-align: right; padding-right: 5px'"; |
|
| 549 | - foreach ($errs as $r){ |
|
| 550 | - $i++; |
|
| 551 | - list($msg, $ligne, $col) = $r; |
|
| 552 | - #spip_log("$r = list($msg, $ligne, $col"); |
|
| 553 | - if (isset($encore2[$msg])) |
|
| 554 | - $ref = ++$encore2[$msg]; |
|
| 555 | - else { |
|
| 556 | - $encore2[$msg] = $ref = 1; |
|
| 557 | - } |
|
| 558 | - $err .= "<tr style='background-color: " |
|
| 559 | - . $colors[$i%2] |
|
| 560 | - . "'><td $style><a href='#debut_err'>" |
|
| 561 | - . $i |
|
| 562 | - . "</a></td><td $style>" |
|
| 563 | - . "$ref/$encore[$msg]</td>" |
|
| 564 | - . "<td $style><a href='#L" |
|
| 565 | - . $ligne |
|
| 566 | - . "' id='T$i'>" |
|
| 567 | - . $ligne |
|
| 568 | - . "</a></td><td $style>" |
|
| 569 | - . $col |
|
| 570 | - . "</td><td>$msg</td></tr>\n"; |
|
| 571 | - $fautifs[] = array($ligne, $col, $i, $msg); |
|
| 572 | - } |
|
| 573 | - $err = "<h2 style='text-align: center'>" |
|
| 574 | - . $i |
|
| 575 | - . "<a href='#fin_err'>" |
|
| 576 | - . " " . _T('erreur_texte') |
|
| 577 | - . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 578 | - . $err |
|
| 579 | - . " </table><a id='fin_err'></a>"; |
|
| 580 | - return array(ancre_texte($texte, $fautifs), $err); |
|
| 581 | - } |
|
| 582 | - else { |
|
| 583 | - list($msg, $fermant, $ouvrant) = $errs[0]; |
|
| 584 | - $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 585 | - $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 586 | - $err = $msg . |
|
| 587 | - "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 588 | - "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 589 | - return array(ancre_texte($texte, array(array($ouvrant), array($fermant))), $err); |
|
| 590 | - } |
|
| 520 | + $errs = $res->err; |
|
| 521 | + $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 522 | + |
|
| 523 | + if (!$texte and !$errs) |
|
| 524 | + return array(ancre_texte('', array('', '')), false); |
|
| 525 | + if (!$errs) |
|
| 526 | + return array(ancre_texte($texte, array('', '')), true); |
|
| 527 | + |
|
| 528 | + if (!isset($GLOBALS['debug_objets'])){ |
|
| 529 | + |
|
| 530 | + $colors = array('#e0e0f0', '#f8f8ff'); |
|
| 531 | + $encore = count_occ($errs); |
|
| 532 | + $encore2 = array(); |
|
| 533 | + $fautifs = array(); |
|
| 534 | + |
|
| 535 | + $err = '<tr><th>' |
|
| 536 | + . _T('numero') |
|
| 537 | + . "</th><th>" |
|
| 538 | + . _T('occurence') |
|
| 539 | + . "</th><th>" |
|
| 540 | + . _T('ligne') |
|
| 541 | + . "</th><th>" |
|
| 542 | + . _T('colonne') |
|
| 543 | + . "</th><th>" |
|
| 544 | + . _T('erreur') |
|
| 545 | + . "</th></tr>"; |
|
| 546 | + |
|
| 547 | + $i = 0; |
|
| 548 | + $style = "style='text-align: right; padding-right: 5px'"; |
|
| 549 | + foreach ($errs as $r){ |
|
| 550 | + $i++; |
|
| 551 | + list($msg, $ligne, $col) = $r; |
|
| 552 | + #spip_log("$r = list($msg, $ligne, $col"); |
|
| 553 | + if (isset($encore2[$msg])) |
|
| 554 | + $ref = ++$encore2[$msg]; |
|
| 555 | + else { |
|
| 556 | + $encore2[$msg] = $ref = 1; |
|
| 557 | + } |
|
| 558 | + $err .= "<tr style='background-color: " |
|
| 559 | + . $colors[$i%2] |
|
| 560 | + . "'><td $style><a href='#debut_err'>" |
|
| 561 | + . $i |
|
| 562 | + . "</a></td><td $style>" |
|
| 563 | + . "$ref/$encore[$msg]</td>" |
|
| 564 | + . "<td $style><a href='#L" |
|
| 565 | + . $ligne |
|
| 566 | + . "' id='T$i'>" |
|
| 567 | + . $ligne |
|
| 568 | + . "</a></td><td $style>" |
|
| 569 | + . $col |
|
| 570 | + . "</td><td>$msg</td></tr>\n"; |
|
| 571 | + $fautifs[] = array($ligne, $col, $i, $msg); |
|
| 572 | + } |
|
| 573 | + $err = "<h2 style='text-align: center'>" |
|
| 574 | + . $i |
|
| 575 | + . "<a href='#fin_err'>" |
|
| 576 | + . " " . _T('erreur_texte') |
|
| 577 | + . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 578 | + . $err |
|
| 579 | + . " </table><a id='fin_err'></a>"; |
|
| 580 | + return array(ancre_texte($texte, $fautifs), $err); |
|
| 581 | + } |
|
| 582 | + else { |
|
| 583 | + list($msg, $fermant, $ouvrant) = $errs[0]; |
|
| 584 | + $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 585 | + $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 586 | + $err = $msg . |
|
| 587 | + "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 588 | + "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 589 | + return array(ancre_texte($texte, array(array($ouvrant), array($fermant))), $err); |
|
| 590 | + } |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | // http://doc.spip.org/@count_occ |
| 594 | 594 | function count_occ($regs){ |
| 595 | - $encore = array(); |
|
| 596 | - foreach ($regs as $r){ |
|
| 597 | - if (isset($encore[$r[0]])) |
|
| 598 | - $encore[$r[0]]++; |
|
| 599 | - else |
|
| 600 | - $encore[$r[0]] = 1; |
|
| 601 | - } |
|
| 602 | - return $encore; |
|
| 595 | + $encore = array(); |
|
| 596 | + foreach ($regs as $r){ |
|
| 597 | + if (isset($encore[$r[0]])) |
|
| 598 | + $encore[$r[0]]++; |
|
| 599 | + else |
|
| 600 | + $encore[$r[0]] = 1; |
|
| 601 | + } |
|
| 602 | + return $encore; |
|
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | function debusquer_navigation_squelettes($self){ |
| 606 | - global $debug_objets, $spip_lang_right; |
|
| 607 | - |
|
| 608 | - $res = ''; |
|
| 609 | - $boucles = !empty($debug_objets['boucle']) ? $debug_objets['boucle'] : ''; |
|
| 610 | - $contexte = $debug_objets['contexte']; |
|
| 611 | - $t_skel = _T('squelette'); |
|
| 612 | - foreach ($debug_objets['sourcefile'] as $nom => $sourcefile){ |
|
| 613 | - $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 614 | - $nav = !$boucles ? '' : debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile); |
|
| 615 | - $temps = !isset($debug_objets['profile'][$sourcefile]) ? '' : _T('zbug_profile', array('time' => $debug_objets['profile'][$sourcefile])); |
|
| 616 | - |
|
| 617 | - $res .= "<fieldset id='f_".$nom."'><legend>" |
|
| 618 | - . $t_skel |
|
| 619 | - . ' ' |
|
| 620 | - . $sourcefile |
|
| 621 | - . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 622 | - . $t_skel |
|
| 623 | - . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 624 | - . _T('zbug_resultat') |
|
| 625 | - . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 626 | - . _T('zbug_code') |
|
| 627 | - . "</a>\n<a href='" |
|
| 628 | - . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', $self) |
|
| 629 | - . "'>" |
|
| 630 | - . _T('zbug_calcul') |
|
| 631 | - . "</a></legend>" |
|
| 632 | - . (!$temps ? '' : ("\n<span style='display:block;float:$spip_lang_right'>$temps</span><br />")) |
|
| 633 | - . debusquer_contexte($contexte[$sourcefile]) |
|
| 634 | - . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
|
| 635 | - . "</fieldset>\n"; |
|
| 636 | - } |
|
| 637 | - return $res; |
|
| 606 | + global $debug_objets, $spip_lang_right; |
|
| 607 | + |
|
| 608 | + $res = ''; |
|
| 609 | + $boucles = !empty($debug_objets['boucle']) ? $debug_objets['boucle'] : ''; |
|
| 610 | + $contexte = $debug_objets['contexte']; |
|
| 611 | + $t_skel = _T('squelette'); |
|
| 612 | + foreach ($debug_objets['sourcefile'] as $nom => $sourcefile){ |
|
| 613 | + $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 614 | + $nav = !$boucles ? '' : debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile); |
|
| 615 | + $temps = !isset($debug_objets['profile'][$sourcefile]) ? '' : _T('zbug_profile', array('time' => $debug_objets['profile'][$sourcefile])); |
|
| 616 | + |
|
| 617 | + $res .= "<fieldset id='f_".$nom."'><legend>" |
|
| 618 | + . $t_skel |
|
| 619 | + . ' ' |
|
| 620 | + . $sourcefile |
|
| 621 | + . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 622 | + . $t_skel |
|
| 623 | + . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 624 | + . _T('zbug_resultat') |
|
| 625 | + . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 626 | + . _T('zbug_code') |
|
| 627 | + . "</a>\n<a href='" |
|
| 628 | + . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', $self) |
|
| 629 | + . "'>" |
|
| 630 | + . _T('zbug_calcul') |
|
| 631 | + . "</a></legend>" |
|
| 632 | + . (!$temps ? '' : ("\n<span style='display:block;float:$spip_lang_right'>$temps</span><br />")) |
|
| 633 | + . debusquer_contexte($contexte[$sourcefile]) |
|
| 634 | + . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
|
| 635 | + . "</fieldset>\n"; |
|
| 636 | + } |
|
| 637 | + return $res; |
|
| 638 | 638 | } |
| 639 | 639 | |
| 640 | 640 | function debusquer_navigation_boucles($boucles, $nom_skel, $self, $nom_source){ |
| 641 | - $i = 0; |
|
| 642 | - $res = ''; |
|
| 643 | - $var_mode_objet = _request('var_mode_objet'); |
|
| 644 | - $gram = preg_match('/[.](\w+)$/', $nom_source, $r) ? $r[1] : ''; |
|
| 645 | - |
|
| 646 | - foreach ($boucles as $objet => $boucle){ |
|
| 647 | - if (substr($objet, 0, strlen($nom_skel))==$nom_skel){ |
|
| 648 | - $i++; |
|
| 649 | - $nom = $boucle->id_boucle; |
|
| 650 | - $req = $boucle->type_requete; |
|
| 651 | - $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 652 | - $self2 = $self . "&var_mode_objet=" . $objet; |
|
| 653 | - |
|
| 654 | - $res .= "\n<tr style='background-color: " . |
|
| 655 | - ($i%2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 656 | - "'><td align='right'>$i</td><td>\n" . |
|
| 657 | - "<a class='debug_link_boucle' href='" . |
|
| 658 | - $self2 . |
|
| 659 | - "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 660 | - _T('zbug_boucle') . |
|
| 661 | - "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 662 | - $self2 . |
|
| 663 | - "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 664 | - _T('zbug_resultat') . |
|
| 665 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 666 | - $self2 . |
|
| 667 | - "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 668 | - _T('zbug_code') . |
|
| 669 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 670 | - str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 671 | - "'>" . |
|
| 672 | - _T('zbug_calcul') . |
|
| 673 | - "</a></td><td>\n" . |
|
| 674 | - (($var_mode_objet==$objet) ? "<b>$nom</b>" : $nom) . |
|
| 675 | - "</td><td>\n" . |
|
| 676 | - $req . |
|
| 677 | - "</td><td>\n" . |
|
| 678 | - spip_htmlspecialchars($crit) . |
|
| 679 | - "</td></tr>"; |
|
| 680 | - } |
|
| 681 | - } |
|
| 682 | - return $res; |
|
| 641 | + $i = 0; |
|
| 642 | + $res = ''; |
|
| 643 | + $var_mode_objet = _request('var_mode_objet'); |
|
| 644 | + $gram = preg_match('/[.](\w+)$/', $nom_source, $r) ? $r[1] : ''; |
|
| 645 | + |
|
| 646 | + foreach ($boucles as $objet => $boucle){ |
|
| 647 | + if (substr($objet, 0, strlen($nom_skel))==$nom_skel){ |
|
| 648 | + $i++; |
|
| 649 | + $nom = $boucle->id_boucle; |
|
| 650 | + $req = $boucle->type_requete; |
|
| 651 | + $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 652 | + $self2 = $self . "&var_mode_objet=" . $objet; |
|
| 653 | + |
|
| 654 | + $res .= "\n<tr style='background-color: " . |
|
| 655 | + ($i%2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 656 | + "'><td align='right'>$i</td><td>\n" . |
|
| 657 | + "<a class='debug_link_boucle' href='" . |
|
| 658 | + $self2 . |
|
| 659 | + "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 660 | + _T('zbug_boucle') . |
|
| 661 | + "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 662 | + $self2 . |
|
| 663 | + "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 664 | + _T('zbug_resultat') . |
|
| 665 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 666 | + $self2 . |
|
| 667 | + "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 668 | + _T('zbug_code') . |
|
| 669 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 670 | + str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 671 | + "'>" . |
|
| 672 | + _T('zbug_calcul') . |
|
| 673 | + "</a></td><td>\n" . |
|
| 674 | + (($var_mode_objet==$objet) ? "<b>$nom</b>" : $nom) . |
|
| 675 | + "</td><td>\n" . |
|
| 676 | + $req . |
|
| 677 | + "</td><td>\n" . |
|
| 678 | + spip_htmlspecialchars($crit) . |
|
| 679 | + "</td></tr>"; |
|
| 680 | + } |
|
| 681 | + } |
|
| 682 | + return $res; |
|
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | function debusquer_source($objet, $affiche){ |
| 686 | - $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 687 | - $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 688 | - $res2 = ""; |
|
| 689 | - |
|
| 690 | - if ($affiche=='resultat'){ |
|
| 691 | - $legend = $nom; |
|
| 692 | - $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 693 | - if (function_exists('traite_query')){ |
|
| 694 | - $c = strtolower(_request('connect')); |
|
| 695 | - $c = $GLOBALS['connexions'][$c ? $c : 0]['prefixe']; |
|
| 696 | - $req = traite_query($req, '', $c); |
|
| 697 | - } |
|
| 698 | - // permettre le copier/coller facile |
|
| 699 | - // $res = ancre_texte($req, array(), true); |
|
| 700 | - $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 701 | - // formatage et affichage des resultats bruts de la requete |
|
| 702 | - $ress_req = spip_query($req); |
|
| 703 | - $brut_sql = ''; |
|
| 704 | - $num = 1; |
|
| 705 | - // eviter l'affichage de milliers de lignes |
|
| 706 | - // personnalisation possible dans mes_options |
|
| 707 | - $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 708 | - while ($retours_sql = sql_fetch($ress_req)){ |
|
| 709 | - if ($num<=$max_aff){ |
|
| 710 | - $brut_sql .= "<h3>" . ($num==1 ? $num . " sur " . sql_count($ress_req) : $num) . "</h3>"; |
|
| 711 | - $brut_sql .= "<p>"; |
|
| 712 | - foreach ($retours_sql as $key => $val){ |
|
| 713 | - $brut_sql .= "<strong>" . $key . "</strong> => " . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 714 | - } |
|
| 715 | - $brut_sql .= "</p>"; |
|
| 716 | - } |
|
| 717 | - $num++; |
|
| 718 | - } |
|
| 719 | - $res2 = interdire_scripts($brut_sql); |
|
| 720 | - foreach ($quoi as $view){ |
|
| 721 | - // ne pas afficher les $contexte_inclus |
|
| 722 | - $view = preg_replace(",<\?php.+\?[>],Uims", "", $view); |
|
| 723 | - if ($view){ |
|
| 724 | - $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . "</fieldset>"; |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - } |
|
| 729 | - elseif ($affiche=='code'){ |
|
| 730 | - $legend = $nom; |
|
| 731 | - $res = ancre_texte("<" . "?php\n" . $quoi . "\n?" . ">"); |
|
| 732 | - } |
|
| 733 | - elseif ($affiche=='boucle'){ |
|
| 734 | - $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 735 | - // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
|
| 736 | - $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
|
| 737 | - $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
|
| 738 | - } |
|
| 739 | - elseif ($affiche=='squelette'){ |
|
| 740 | - $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 741 | - $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - return array($legend, $res, $res2); |
|
| 686 | + $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 687 | + $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 688 | + $res2 = ""; |
|
| 689 | + |
|
| 690 | + if ($affiche=='resultat'){ |
|
| 691 | + $legend = $nom; |
|
| 692 | + $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 693 | + if (function_exists('traite_query')){ |
|
| 694 | + $c = strtolower(_request('connect')); |
|
| 695 | + $c = $GLOBALS['connexions'][$c ? $c : 0]['prefixe']; |
|
| 696 | + $req = traite_query($req, '', $c); |
|
| 697 | + } |
|
| 698 | + // permettre le copier/coller facile |
|
| 699 | + // $res = ancre_texte($req, array(), true); |
|
| 700 | + $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 701 | + // formatage et affichage des resultats bruts de la requete |
|
| 702 | + $ress_req = spip_query($req); |
|
| 703 | + $brut_sql = ''; |
|
| 704 | + $num = 1; |
|
| 705 | + // eviter l'affichage de milliers de lignes |
|
| 706 | + // personnalisation possible dans mes_options |
|
| 707 | + $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 708 | + while ($retours_sql = sql_fetch($ress_req)){ |
|
| 709 | + if ($num<=$max_aff){ |
|
| 710 | + $brut_sql .= "<h3>" . ($num==1 ? $num . " sur " . sql_count($ress_req) : $num) . "</h3>"; |
|
| 711 | + $brut_sql .= "<p>"; |
|
| 712 | + foreach ($retours_sql as $key => $val){ |
|
| 713 | + $brut_sql .= "<strong>" . $key . "</strong> => " . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 714 | + } |
|
| 715 | + $brut_sql .= "</p>"; |
|
| 716 | + } |
|
| 717 | + $num++; |
|
| 718 | + } |
|
| 719 | + $res2 = interdire_scripts($brut_sql); |
|
| 720 | + foreach ($quoi as $view){ |
|
| 721 | + // ne pas afficher les $contexte_inclus |
|
| 722 | + $view = preg_replace(",<\?php.+\?[>],Uims", "", $view); |
|
| 723 | + if ($view){ |
|
| 724 | + $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . "</fieldset>"; |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + } |
|
| 729 | + elseif ($affiche=='code'){ |
|
| 730 | + $legend = $nom; |
|
| 731 | + $res = ancre_texte("<" . "?php\n" . $quoi . "\n?" . ">"); |
|
| 732 | + } |
|
| 733 | + elseif ($affiche=='boucle'){ |
|
| 734 | + $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 735 | + // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
|
| 736 | + $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
|
| 737 | + $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
|
| 738 | + } |
|
| 739 | + elseif ($affiche=='squelette'){ |
|
| 740 | + $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 741 | + $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + return array($legend, $res, $res2); |
|
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | // http://doc.spip.org/@debusquer_entete |
| 748 | 748 | function debusquer_entete($titre, $corps){ |
| 749 | - global $debug_objets; |
|
| 750 | - include_spip('balise/formulaire_admin'); |
|
| 751 | - include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 752 | - include_spip('inc/texte'); // pour corriger_typo |
|
| 753 | - |
|
| 754 | - return _DOCTYPE_ECRIRE . |
|
| 755 | - html_lang_attributes() . |
|
| 756 | - "<head>\n<title>" . |
|
| 757 | - ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 758 | - _T('admin_debug') . ' ' . $titre . ' (' . |
|
| 759 | - supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 760 | - ")</title>\n" . |
|
| 761 | - "<meta http-equiv='Content-Type' content='text/html" . |
|
| 762 | - (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 763 | - "' />\n" . |
|
| 764 | - http_script('', 'jquery.js') |
|
| 765 | - . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 766 | - . "' type='text/css' />" . |
|
| 767 | - "</head>\n" . |
|
| 768 | - "<body style='margin:0 10px;'>\n" . |
|
| 769 | - "<div id='spip-debug-header'>" . |
|
| 770 | - $corps . |
|
| 771 | - inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $debug_objets), false) . |
|
| 772 | - '</div></body></html>'; |
|
| 749 | + global $debug_objets; |
|
| 750 | + include_spip('balise/formulaire_admin'); |
|
| 751 | + include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 752 | + include_spip('inc/texte'); // pour corriger_typo |
|
| 753 | + |
|
| 754 | + return _DOCTYPE_ECRIRE . |
|
| 755 | + html_lang_attributes() . |
|
| 756 | + "<head>\n<title>" . |
|
| 757 | + ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 758 | + _T('admin_debug') . ' ' . $titre . ' (' . |
|
| 759 | + supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 760 | + ")</title>\n" . |
|
| 761 | + "<meta http-equiv='Content-Type' content='text/html" . |
|
| 762 | + (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 763 | + "' />\n" . |
|
| 764 | + http_script('', 'jquery.js') |
|
| 765 | + . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 766 | + . "' type='text/css' />" . |
|
| 767 | + "</head>\n" . |
|
| 768 | + "<body style='margin:0 10px;'>\n" . |
|
| 769 | + "<div id='spip-debug-header'>" . |
|
| 770 | + $corps . |
|
| 771 | + inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $debug_objets), false) . |
|
| 772 | + '</div></body></html>'; |
|
| 773 | 773 | } |
| 774 | 774 | |
| 775 | 775 | ?> |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | * @return null|string |
| 64 | 64 | * - string si $message à false. |
| 65 | 65 | **/ |
| 66 | -function public_debusquer_dist($message = '', $lieu = '', $opt = array()){ |
|
| 66 | +function public_debusquer_dist($message = '', $lieu = '', $opt = array()) { |
|
| 67 | 67 | global $visiteur_session; |
| 68 | 68 | global $debug_objets; |
| 69 | 69 | static $tableau_des_erreurs = array(); |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | // Erreur ou appel final ? |
| 83 | - if ($message){ |
|
| 83 | + if ($message) { |
|
| 84 | 84 | $message = debusquer_compose_message($message); |
| 85 | 85 | $tableau_des_erreurs[] = array($message, $lieu); |
| 86 | 86 | set_request('var_mode', 'debug'); |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | if (is_object($lieu) AND (!isset($lieu->code) OR !$lieu->code)) |
| 90 | 90 | $lieu->code = "''"; |
| 91 | 91 | // forcer l'appel au debusqueur en cas de boucles infernales |
| 92 | - $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS AND count($tableau_des_erreurs)>_DEBUG_MAX_SQUELETTE_ERREURS); |
|
| 92 | + $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS AND count($tableau_des_erreurs) > _DEBUG_MAX_SQUELETTE_ERREURS); |
|
| 93 | 93 | if (!$urgence) return; |
| 94 | 94 | } |
| 95 | 95 | if (empty($debug_objets['principal'])) |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | if (ob_get_length() |
| 109 | 109 | AND |
| 110 | 110 | !in_array('ob_gzhandler', ob_get_status()) |
| 111 | - ){ |
|
| 111 | + ) { |
|
| 112 | 112 | ob_end_clean(); |
| 113 | 113 | } |
| 114 | 114 | |
@@ -126,15 +126,15 @@ discard block |
||
| 126 | 126 | if ($tableau_des_erreurs) http_status(503); |
| 127 | 127 | |
| 128 | 128 | http_no_cache(); |
| 129 | - if (isset($_GET['var_profile'])){ |
|
| 129 | + if (isset($_GET['var_profile'])) { |
|
| 130 | 130 | $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
| 131 | 131 | $titre = parametre_url($titre, 'var_mode', ''); |
| 132 | 132 | } |
| 133 | 133 | else { |
| 134 | 134 | if (!$fonc) $fonc = $debug_objets['principal']; |
| 135 | - $titre = !$mode ? $fonc : ($mode . ' ' . $debug_objets['sourcefile'][$fonc]); |
|
| 135 | + $titre = !$mode ? $fonc : ($mode.' '.$debug_objets['sourcefile'][$fonc]); |
|
| 136 | 136 | } |
| 137 | - if ($message===false){ |
|
| 137 | + if ($message === false) { |
|
| 138 | 138 | lang_select(); |
| 139 | 139 | return debusquer_entete($titre, $res); |
| 140 | 140 | } |
@@ -143,11 +143,11 @@ discard block |
||
| 143 | 143 | exit; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | -function debusquer_compose_message($msg){ |
|
| 147 | - if (is_array($msg)){ |
|
| 146 | +function debusquer_compose_message($msg) { |
|
| 147 | + if (is_array($msg)) { |
|
| 148 | 148 | // si c'est un texte, c'est une traduction a faire, mais |
| 149 | 149 | // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
| 150 | - if (!is_numeric($msg[0]) AND count($msg)==2) { |
|
| 150 | + if (!is_numeric($msg[0]) AND count($msg) == 2) { |
|
| 151 | 151 | // message avec argument: instancier |
| 152 | 152 | $msg = _T($msg[0], $msg[1], 'spip-debug-arg'); |
| 153 | 153 | } else { |
@@ -157,17 +157,17 @@ discard block |
||
| 157 | 157 | } |
| 158 | 158 | // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
| 159 | 159 | // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
| 160 | - $fond = isset($GLOBALS['fond']) ? $GLOBALS['fond'] : ""; |
|
| 160 | + $fond = isset($GLOBALS['fond']) ? $GLOBALS['fond'] : ""; |
|
| 161 | 161 | // une erreur critique sort $message en array |
| 162 | 162 | $debug = is_array($msg) ? $msg[1] : $msg; |
| 163 | - spip_log("Debug: " . $debug . " (" . $fond . ")"); |
|
| 163 | + spip_log("Debug: ".$debug." (".$fond.")"); |
|
| 164 | 164 | return $msg; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | -function debusquer_bandeau($erreurs){ |
|
| 167 | +function debusquer_bandeau($erreurs) { |
|
| 168 | 168 | |
| 169 | - if (!empty($erreurs)){ |
|
| 170 | - $n = array(count($erreurs) . ' ' . _T('zbug_erreur_squelette')); |
|
| 169 | + if (!empty($erreurs)) { |
|
| 170 | + $n = array(count($erreurs).' '._T('zbug_erreur_squelette')); |
|
| 171 | 171 | return debusquer_navigation($erreurs, $n); |
| 172 | 172 | } |
| 173 | 173 | elseif (!empty($GLOBALS['tableau_des_temps'])) { |
@@ -179,17 +179,17 @@ discard block |
||
| 179 | 179 | return ''; |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | -function debusquer_contexte($env){ |
|
| 182 | +function debusquer_contexte($env) { |
|
| 183 | 183 | |
| 184 | 184 | if (is_array($env_tab = @unserialize($env))) $env = $env_tab; |
| 185 | 185 | |
| 186 | 186 | if (!$env) return ''; |
| 187 | 187 | $res = ""; |
| 188 | - foreach ($env as $nom => $valeur){ |
|
| 188 | + foreach ($env as $nom => $valeur) { |
|
| 189 | 189 | if (is_array($valeur)) |
| 190 | - $valeur = '(' . count($valeur) . ' items) [' . join(',', $valeur) . ']'; |
|
| 191 | - $res .= "\n<tr><td><strong>" . nl2br(entites_html($nom)) |
|
| 192 | - . "</strong></td><td>: " . nl2br(entites_html($valeur)) |
|
| 190 | + $valeur = '('.count($valeur).' items) ['.join(',', $valeur).']'; |
|
| 191 | + $res .= "\n<tr><td><strong>".nl2br(entites_html($nom)) |
|
| 192 | + . "</strong></td><td>: ".nl2br(entites_html($valeur)) |
|
| 193 | 193 | . "</td></tr>\n"; |
| 194 | 194 | } |
| 195 | 195 | |
@@ -199,32 +199,32 @@ discard block |
||
| 199 | 199 | // Affichage du tableau des erreurs ou des temps de calcul |
| 200 | 200 | // Cliquer sur les numeros en premiere colonne permet de voir le code |
| 201 | 201 | |
| 202 | -function debusquer_navigation($tableau, $caption = array(), $id = 'debug-nav'){ |
|
| 202 | +function debusquer_navigation($tableau, $caption = array(), $id = 'debug-nav') { |
|
| 203 | 203 | |
| 204 | - if (_request('exec')=='valider_xml') return ''; |
|
| 204 | + if (_request('exec') == 'valider_xml') return ''; |
|
| 205 | 205 | $GLOBALS['bouton_admin_debug'] = true; |
| 206 | 206 | $res = ''; |
| 207 | 207 | $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
| 208 | - foreach ($tableau as $i => $err){ |
|
| 208 | + foreach ($tableau as $i => $err) { |
|
| 209 | 209 | $boucle = $ligne = $skel = ''; |
| 210 | 210 | list($msg, $lieu) = $err; |
| 211 | - if (is_object($lieu)){ |
|
| 211 | + if (is_object($lieu)) { |
|
| 212 | 212 | $ligne = $lieu->ligne; |
| 213 | 213 | $boucle = $lieu->id_boucle ? $lieu->id_boucle : ''; |
| 214 | - if (isset($lieu->descr['nom'])){ |
|
| 214 | + if (isset($lieu->descr['nom'])) { |
|
| 215 | 215 | $nom_code = $lieu->descr['nom']; |
| 216 | 216 | $skel = $lieu->descr['sourcefile']; |
| 217 | 217 | $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
| 218 | - $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 218 | + $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette').'#L'.$ligne; |
|
| 219 | 219 | $skel = "<a href='$h3'><b>$skel</b></a>"; |
| 220 | - if ($boucle){ |
|
| 221 | - $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 220 | + if ($boucle) { |
|
| 221 | + $h3 = parametre_url($h2.$boucle, 'var_mode_affiche', 'boucle'); |
|
| 222 | 222 | $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
| 223 | 223 | } |
| 224 | 224 | } |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - $j = ($i+1); |
|
| 227 | + $j = ($i + 1); |
|
| 228 | 228 | $res .= "<tr id='req$j'><td style='text-align: right'>" |
| 229 | 229 | . $j |
| 230 | 230 | . " </td><td style='text-align: left'>" |
@@ -278,22 +278,22 @@ discard block |
||
| 278 | 278 | * Retourne le texte de l'erreur a afficher |
| 279 | 279 | * ou un tableau si l'erreur est critique |
| 280 | 280 | **/ |
| 281 | -function debusquer_requete($message){ |
|
| 281 | +function debusquer_requete($message) { |
|
| 282 | 282 | list($errno, $msg, $query) = $message; |
| 283 | 283 | |
| 284 | 284 | // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
| 285 | 285 | // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
| 286 | - if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)){ |
|
| 286 | + if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)) { |
|
| 287 | 287 | $errno = $regs[2]; |
| 288 | 288 | } |
| 289 | - elseif (is_numeric($errno) and ($errno==1030 OR $errno<=1026) |
|
| 289 | + elseif (is_numeric($errno) and ($errno == 1030 OR $errno <= 1026) |
|
| 290 | 290 | AND preg_match(',[^[:alnum:]]([0-9]+)[^[:alnum:]],', $msg, $regs) |
| 291 | 291 | ) { |
| 292 | 292 | $errno = $regs[1]; |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | // Erreur systeme |
| 296 | - if (is_numeric($errno) and $errno>0 AND $errno<200){ |
|
| 296 | + if (is_numeric($errno) and $errno > 0 AND $errno < 200) { |
|
| 297 | 297 | $retour = "<tt><br /><br /><blink>" |
| 298 | 298 | . _T('info_erreur_systeme', array('errsys' => $errno)) |
| 299 | 299 | . "</blink><br />\n<b>" |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | // Requete erronee |
| 308 | - $err = "<b>" . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 308 | + $err = "<b>"._T('avis_erreur_mysql')." $errno</b><br /><tt>\n" |
|
| 309 | 309 | . spip_htmlspecialchars($msg) |
| 310 | 310 | . "\n<br /><span style='color: red'><b>" |
| 311 | 311 | . spip_htmlspecialchars($query) |
@@ -318,17 +318,17 @@ discard block |
||
| 318 | 318 | |
| 319 | 319 | |
| 320 | 320 | // http://doc.spip.org/@trouve_boucle_debug |
| 321 | -function trouve_boucle_debug($n, $nom, $debut = 0, $boucle = ""){ |
|
| 321 | +function trouve_boucle_debug($n, $nom, $debut = 0, $boucle = "") { |
|
| 322 | 322 | global $debug_objets; |
| 323 | 323 | |
| 324 | - $id = $nom . $boucle; |
|
| 325 | - if (is_array($debug_objets['sequence'][$id])){ |
|
| 326 | - foreach ($debug_objets['sequence'][$id] as $v){ |
|
| 324 | + $id = $nom.$boucle; |
|
| 325 | + if (is_array($debug_objets['sequence'][$id])) { |
|
| 326 | + foreach ($debug_objets['sequence'][$id] as $v) { |
|
| 327 | 327 | |
| 328 | 328 | if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) |
| 329 | 329 | $y = substr_count($v[0], "\n"); |
| 330 | 330 | else { |
| 331 | - if ($v[1][0]=='#') |
|
| 331 | + if ($v[1][0] == '#') |
|
| 332 | 332 | // balise dynamique |
| 333 | 333 | $incl = $debug_objets['resultat'][$v[2]]; |
| 334 | 334 | else |
@@ -338,82 +338,79 @@ discard block |
||
| 338 | 338 | +substr_count($r[1], "\n") |
| 339 | 339 | +substr_count($r[3], "\n"); |
| 340 | 340 | } |
| 341 | - if ($n<=($y+$debut)){ |
|
| 342 | - if ($v[1][0]=='?') |
|
| 341 | + if ($n <= ($y + $debut)) { |
|
| 342 | + if ($v[1][0] == '?') |
|
| 343 | 343 | return trouve_boucle_debug($n, $nom, $debut, substr($v[1], 1)); |
| 344 | - elseif ($v[1][0]=='!') { |
|
| 344 | + elseif ($v[1][0] == '!') { |
|
| 345 | 345 | if ($incl = trouve_squelette_inclus($v[1])) |
| 346 | 346 | return trouve_boucle_debug($n, $incl, $debut); |
| 347 | 347 | } |
| 348 | - return array($nom, $boucle, $v[2]-1+$n-$debut); |
|
| 348 | + return array($nom, $boucle, $v[2] - 1 + $n - $debut); |
|
| 349 | 349 | } |
| 350 | 350 | $debut += $y; |
| 351 | 351 | } |
| 352 | 352 | } |
| 353 | - return array($nom, $boucle, $n-$debut); |
|
| 353 | + return array($nom, $boucle, $n - $debut); |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | // http://doc.spip.org/@trouve_squelette_inclus |
| 357 | -function trouve_squelette_inclus($script){ |
|
| 357 | +function trouve_squelette_inclus($script) { |
|
| 358 | 358 | global $debug_objets; |
| 359 | 359 | preg_match('/include\(.(.*).php3?.\);/', $script, $reg); |
| 360 | 360 | // si le script X.php n'est pas ecrire/public.php |
| 361 | 361 | // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
| 362 | - if ($reg[1]=='ecrire/public') |
|
| 362 | + if ($reg[1] == 'ecrire/public') |
|
| 363 | 363 | // si c'est bien ecrire/public on cherche le param 'fond' |
| 364 | 364 | if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) |
| 365 | 365 | // a defaut on cherche le param 'page' |
| 366 | 366 | if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) |
| 367 | 367 | $reg[1] = "inconnu"; |
| 368 | - $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 368 | + $incl = ','.$reg[1].'[.]\w$,'; |
|
| 369 | 369 | |
| 370 | - foreach ($debug_objets['sourcefile'] as $k => $v){ |
|
| 370 | + foreach ($debug_objets['sourcefile'] as $k => $v) { |
|
| 371 | 371 | if (preg_match($incl, $v)) return $k; |
| 372 | 372 | } |
| 373 | 373 | return ""; |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | // http://doc.spip.org/@reference_boucle_debug |
| 377 | -function reference_boucle_debug($n, $nom, $self){ |
|
| 377 | +function reference_boucle_debug($n, $nom, $self) { |
|
| 378 | 378 | list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
| 379 | 379 | |
| 380 | 380 | if (!$boucle) |
| 381 | - return !$ligne ? "" : |
|
| 382 | - (" (" . |
|
| 383 | - (($nom!=$skel) ? _T('squelette_inclus_ligne') : |
|
| 384 | - _T('squelette_ligne')) . |
|
| 381 | + return !$ligne ? "" : (" (". |
|
| 382 | + (($nom != $skel) ? _T('squelette_inclus_ligne') : _T('squelette_ligne')). |
|
| 385 | 383 | " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
| 386 | 384 | else { |
| 387 | 385 | $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
| 388 | 386 | |
| 389 | - return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 390 | - " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 387 | + return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 391 | 388 | } |
| 392 | 389 | } |
| 393 | 390 | |
| 394 | 391 | // affiche un texte avec numero de ligne et ancre. |
| 395 | 392 | |
| 396 | 393 | // http://doc.spip.org/@ancre_texte |
| 397 | -function ancre_texte($texte, $fautifs = array(), $nocpt = false){ |
|
| 394 | +function ancre_texte($texte, $fautifs = array(), $nocpt = false) { |
|
| 398 | 395 | |
| 399 | 396 | $var_mode_ligne = _request('var_mode_ligne'); |
| 400 | 397 | if ($var_mode_ligne) $fautifs[] = array($var_mode_ligne); |
| 401 | 398 | $res = ''; |
| 402 | 399 | |
| 403 | 400 | $s = highlight_string($texte, true); |
| 404 | - if (substr($s, 0, 6)=='<code>'){ |
|
| 401 | + if (substr($s, 0, 6) == '<code>') { |
|
| 405 | 402 | $s = substr($s, 6); |
| 406 | 403 | $res = '<code>'; |
| 407 | 404 | } |
| 408 | 405 | |
| 409 | 406 | $s = preg_replace(',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
| 410 | - '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 407 | + '<\1>\2</\1><br />'."\n".'<\1>\3</\1>', |
|
| 411 | 408 | $s); |
| 412 | 409 | |
| 413 | 410 | |
| 414 | 411 | $tableau = explode("<br />", $s); |
| 415 | 412 | |
| 416 | - $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: " . ($nocpt ? 'hidden' : 'visible') . ";%s' href='#T%s' title=\"%s\">%0" . strval(@strlen(count($tableau))) . "d</a></span> %s<br />\n"; |
|
| 413 | + $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: ".($nocpt ? 'hidden' : 'visible').";%s' href='#T%s' title=\"%s\">%0".strval(@strlen(count($tableau)))."d</a></span> %s<br />\n"; |
|
| 417 | 414 | |
| 418 | 415 | $format10 = str_replace('white', 'lightgrey', $format); |
| 419 | 416 | $formaterr = "color: red;"; |
@@ -421,14 +418,14 @@ discard block |
||
| 421 | 418 | $flignes = array(); |
| 422 | 419 | $loc = array(0, 0); |
| 423 | 420 | foreach ($fautifs as $lc) |
| 424 | - if (is_array($lc)){ |
|
| 421 | + if (is_array($lc)) { |
|
| 425 | 422 | $l = array_shift($lc); |
| 426 | 423 | $flignes[$l] = $lc; |
| 427 | 424 | } else $flignes[$lc] = $loc; |
| 428 | 425 | |
| 429 | 426 | $ancre = md5($texte); |
| 430 | - foreach ($tableau as $ligne){ |
|
| 431 | - if (isset($flignes[$i])){ |
|
| 427 | + foreach ($tableau as $ligne) { |
|
| 428 | + if (isset($flignes[$i])) { |
|
| 432 | 429 | $ligne = str_replace(' ', ' ', $ligne); |
| 433 | 430 | $indexmesg = $flignes[$i][1]; |
| 434 | 431 | $err = textebrut($flignes[$i][2]); |
@@ -442,7 +439,7 @@ discard block |
||
| 442 | 439 | $indexmesg = $ancre; |
| 443 | 440 | $err = $bg = ''; |
| 444 | 441 | } |
| 445 | - $res .= sprintf((($i%10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 442 | + $res .= sprintf((($i % 10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 446 | 443 | $i++; |
| 447 | 444 | } |
| 448 | 445 | |
@@ -454,31 +451,31 @@ discard block |
||
| 454 | 451 | . '" style="cursor: pointer;">' |
| 455 | 452 | . ($nocpt ? '' : _T('info_numero_abbreviation')) |
| 456 | 453 | . "</div> |
| 457 | - " . $res . "</div>\n"; |
|
| 454 | + " . $res."</div>\n"; |
|
| 458 | 455 | } |
| 459 | 456 | |
| 460 | 457 | // l'environnement graphique du debuggueur |
| 461 | 458 | |
| 462 | -function debusquer_squelette($fonc, $mode, $self){ |
|
| 459 | +function debusquer_squelette($fonc, $mode, $self) { |
|
| 463 | 460 | global $debug_objets; |
| 464 | 461 | |
| 465 | - if ($mode!=='validation'){ |
|
| 466 | - if (isset($debug_objets['sourcefile']) and $debug_objets['sourcefile']){ |
|
| 462 | + if ($mode !== 'validation') { |
|
| 463 | + if (isset($debug_objets['sourcefile']) and $debug_objets['sourcefile']) { |
|
| 467 | 464 | $res = "<div id='spip-boucles'>\n" |
| 468 | 465 | . debusquer_navigation_squelettes($self) |
| 469 | 466 | . "</div>"; |
| 470 | 467 | } |
| 471 | 468 | else |
| 472 | 469 | $res = ''; |
| 473 | - if ($fonc){ |
|
| 470 | + if ($fonc) { |
|
| 474 | 471 | $id = " id='$fonc'"; |
| 475 | - if (!empty($GLOBALS['debug_objets'][$mode][$fonc])){ |
|
| 472 | + if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
|
| 476 | 473 | list($legend, $texte, $res2) = debusquer_source($fonc, $mode); |
| 477 | 474 | $texte .= $res2; |
| 478 | 475 | } |
| 479 | - elseif (!empty($debug_objets[$mode][$fonc . 'tout'])) { |
|
| 480 | - $legend = _T('zbug_' . $mode); |
|
| 481 | - $texte = $debug_objets[$mode][$fonc . 'tout']; |
|
| 476 | + elseif (!empty($debug_objets[$mode][$fonc.'tout'])) { |
|
| 477 | + $legend = _T('zbug_'.$mode); |
|
| 478 | + $texte = $debug_objets[$mode][$fonc.'tout']; |
|
| 482 | 479 | $texte = ancre_texte($texte, array('', '')); |
| 483 | 480 | } |
| 484 | 481 | } |
@@ -490,17 +487,17 @@ discard block |
||
| 490 | 487 | } |
| 491 | 488 | else { |
| 492 | 489 | $valider = charger_fonction('valider', 'xml'); |
| 493 | - $val = $valider($debug_objets['validation'][$fonc . 'tout']); |
|
| 490 | + $val = $valider($debug_objets['validation'][$fonc.'tout']); |
|
| 494 | 491 | // Si erreur, signaler leur nombre dans le formulaire admin |
| 495 | 492 | $debug_objets['validation'] = $val->err ? count($val->err) : ''; |
| 496 | 493 | list($texte, $err) = emboite_texte($val, $fonc, $self); |
| 497 | - if ($err===false) |
|
| 494 | + if ($err === false) |
|
| 498 | 495 | $err = _T('impossible'); |
| 499 | - elseif ($err===true) |
|
| 496 | + elseif ($err === true) |
|
| 500 | 497 | $err = _T('correcte'); |
| 501 | 498 | else |
| 502 | 499 | $err = ": $err"; |
| 503 | - $legend = _T('validation') . ' ' . $err; |
|
| 500 | + $legend = _T('validation').' '.$err; |
|
| 504 | 501 | $res = $id = ''; |
| 505 | 502 | } |
| 506 | 503 | return !trim($texte) ? '' : ( |
@@ -516,16 +513,16 @@ discard block |
||
| 516 | 513 | |
| 517 | 514 | |
| 518 | 515 | // http://doc.spip.org/@emboite_texte |
| 519 | -function emboite_texte($res, $fonc = '', $self = ''){ |
|
| 516 | +function emboite_texte($res, $fonc = '', $self = '') { |
|
| 520 | 517 | $errs = $res->err; |
| 521 | - $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 518 | + $texte = $res->entete.($errs ? '' : $res->page); |
|
| 522 | 519 | |
| 523 | 520 | if (!$texte and !$errs) |
| 524 | 521 | return array(ancre_texte('', array('', '')), false); |
| 525 | 522 | if (!$errs) |
| 526 | 523 | return array(ancre_texte($texte, array('', '')), true); |
| 527 | 524 | |
| 528 | - if (!isset($GLOBALS['debug_objets'])){ |
|
| 525 | + if (!isset($GLOBALS['debug_objets'])) { |
|
| 529 | 526 | |
| 530 | 527 | $colors = array('#e0e0f0', '#f8f8ff'); |
| 531 | 528 | $encore = count_occ($errs); |
@@ -546,7 +543,7 @@ discard block |
||
| 546 | 543 | |
| 547 | 544 | $i = 0; |
| 548 | 545 | $style = "style='text-align: right; padding-right: 5px'"; |
| 549 | - foreach ($errs as $r){ |
|
| 546 | + foreach ($errs as $r) { |
|
| 550 | 547 | $i++; |
| 551 | 548 | list($msg, $ligne, $col) = $r; |
| 552 | 549 | #spip_log("$r = list($msg, $ligne, $col"); |
@@ -556,7 +553,7 @@ discard block |
||
| 556 | 553 | $encore2[$msg] = $ref = 1; |
| 557 | 554 | } |
| 558 | 555 | $err .= "<tr style='background-color: " |
| 559 | - . $colors[$i%2] |
|
| 556 | + . $colors[$i % 2] |
|
| 560 | 557 | . "'><td $style><a href='#debut_err'>" |
| 561 | 558 | . $i |
| 562 | 559 | . "</a></td><td $style>" |
@@ -573,7 +570,7 @@ discard block |
||
| 573 | 570 | $err = "<h2 style='text-align: center'>" |
| 574 | 571 | . $i |
| 575 | 572 | . "<a href='#fin_err'>" |
| 576 | - . " " . _T('erreur_texte') |
|
| 573 | + . " "._T('erreur_texte') |
|
| 577 | 574 | . "</a></h2><table id='debut_err' style='width: 100%'>" |
| 578 | 575 | . $err |
| 579 | 576 | . " </table><a id='fin_err'></a>"; |
@@ -583,17 +580,17 @@ discard block |
||
| 583 | 580 | list($msg, $fermant, $ouvrant) = $errs[0]; |
| 584 | 581 | $rf = reference_boucle_debug($fermant, $fonc, $self); |
| 585 | 582 | $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
| 586 | - $err = $msg . |
|
| 587 | - "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 588 | - "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 583 | + $err = $msg. |
|
| 584 | + "<a href='#L".$fermant."'>$fermant</a>$rf<br />". |
|
| 585 | + "<a href='#L".$ouvrant."'>$ouvrant</a>$ro"; |
|
| 589 | 586 | return array(ancre_texte($texte, array(array($ouvrant), array($fermant))), $err); |
| 590 | 587 | } |
| 591 | 588 | } |
| 592 | 589 | |
| 593 | 590 | // http://doc.spip.org/@count_occ |
| 594 | -function count_occ($regs){ |
|
| 591 | +function count_occ($regs) { |
|
| 595 | 592 | $encore = array(); |
| 596 | - foreach ($regs as $r){ |
|
| 593 | + foreach ($regs as $r) { |
|
| 597 | 594 | if (isset($encore[$r[0]])) |
| 598 | 595 | $encore[$r[0]]++; |
| 599 | 596 | else |
@@ -602,14 +599,14 @@ discard block |
||
| 602 | 599 | return $encore; |
| 603 | 600 | } |
| 604 | 601 | |
| 605 | -function debusquer_navigation_squelettes($self){ |
|
| 602 | +function debusquer_navigation_squelettes($self) { |
|
| 606 | 603 | global $debug_objets, $spip_lang_right; |
| 607 | 604 | |
| 608 | 605 | $res = ''; |
| 609 | 606 | $boucles = !empty($debug_objets['boucle']) ? $debug_objets['boucle'] : ''; |
| 610 | 607 | $contexte = $debug_objets['contexte']; |
| 611 | 608 | $t_skel = _T('squelette'); |
| 612 | - foreach ($debug_objets['sourcefile'] as $nom => $sourcefile){ |
|
| 609 | + foreach ($debug_objets['sourcefile'] as $nom => $sourcefile) { |
|
| 613 | 610 | $self2 = parametre_url($self, 'var_mode_objet', $nom); |
| 614 | 611 | $nav = !$boucles ? '' : debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile); |
| 615 | 612 | $temps = !isset($debug_objets['profile'][$sourcefile]) ? '' : _T('zbug_profile', array('time' => $debug_objets['profile'][$sourcefile])); |
@@ -637,67 +634,67 @@ discard block |
||
| 637 | 634 | return $res; |
| 638 | 635 | } |
| 639 | 636 | |
| 640 | -function debusquer_navigation_boucles($boucles, $nom_skel, $self, $nom_source){ |
|
| 637 | +function debusquer_navigation_boucles($boucles, $nom_skel, $self, $nom_source) { |
|
| 641 | 638 | $i = 0; |
| 642 | 639 | $res = ''; |
| 643 | 640 | $var_mode_objet = _request('var_mode_objet'); |
| 644 | 641 | $gram = preg_match('/[.](\w+)$/', $nom_source, $r) ? $r[1] : ''; |
| 645 | 642 | |
| 646 | - foreach ($boucles as $objet => $boucle){ |
|
| 647 | - if (substr($objet, 0, strlen($nom_skel))==$nom_skel){ |
|
| 643 | + foreach ($boucles as $objet => $boucle) { |
|
| 644 | + if (substr($objet, 0, strlen($nom_skel)) == $nom_skel) { |
|
| 648 | 645 | $i++; |
| 649 | 646 | $nom = $boucle->id_boucle; |
| 650 | 647 | $req = $boucle->type_requete; |
| 651 | 648 | $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
| 652 | - $self2 = $self . "&var_mode_objet=" . $objet; |
|
| 653 | - |
|
| 654 | - $res .= "\n<tr style='background-color: " . |
|
| 655 | - ($i%2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 656 | - "'><td align='right'>$i</td><td>\n" . |
|
| 657 | - "<a class='debug_link_boucle' href='" . |
|
| 658 | - $self2 . |
|
| 659 | - "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 660 | - _T('zbug_boucle') . |
|
| 661 | - "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 662 | - $self2 . |
|
| 663 | - "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 664 | - _T('zbug_resultat') . |
|
| 665 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 666 | - $self2 . |
|
| 667 | - "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 668 | - _T('zbug_code') . |
|
| 669 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 670 | - str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 671 | - "'>" . |
|
| 672 | - _T('zbug_calcul') . |
|
| 673 | - "</a></td><td>\n" . |
|
| 674 | - (($var_mode_objet==$objet) ? "<b>$nom</b>" : $nom) . |
|
| 675 | - "</td><td>\n" . |
|
| 676 | - $req . |
|
| 677 | - "</td><td>\n" . |
|
| 678 | - spip_htmlspecialchars($crit) . |
|
| 649 | + $self2 = $self."&var_mode_objet=".$objet; |
|
| 650 | + |
|
| 651 | + $res .= "\n<tr style='background-color: ". |
|
| 652 | + ($i % 2 ? '#e0e0f0' : '#f8f8ff'). |
|
| 653 | + "'><td align='right'>$i</td><td>\n". |
|
| 654 | + "<a class='debug_link_boucle' href='". |
|
| 655 | + $self2. |
|
| 656 | + "&var_mode_affiche=boucle#f_$nom_skel'>". |
|
| 657 | + _T('zbug_boucle'). |
|
| 658 | + "</a></td><td>\n<a class='debug_link_boucle' href='". |
|
| 659 | + $self2. |
|
| 660 | + "&var_mode_affiche=resultat#f_$nom_skel'>". |
|
| 661 | + _T('zbug_resultat'). |
|
| 662 | + "</a></td><td>\n<a class='debug_link_resultat' href='". |
|
| 663 | + $self2. |
|
| 664 | + "&var_mode_affiche=code#f_$nom_skel'>". |
|
| 665 | + _T('zbug_code'). |
|
| 666 | + "</a></td><td>\n<a class='debug_link_resultat' href='". |
|
| 667 | + str_replace('var_mode=', 'var_profile=', $self2). |
|
| 668 | + "'>". |
|
| 669 | + _T('zbug_calcul'). |
|
| 670 | + "</a></td><td>\n". |
|
| 671 | + (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom). |
|
| 672 | + "</td><td>\n". |
|
| 673 | + $req. |
|
| 674 | + "</td><td>\n". |
|
| 675 | + spip_htmlspecialchars($crit). |
|
| 679 | 676 | "</td></tr>"; |
| 680 | 677 | } |
| 681 | 678 | } |
| 682 | 679 | return $res; |
| 683 | 680 | } |
| 684 | 681 | |
| 685 | -function debusquer_source($objet, $affiche){ |
|
| 682 | +function debusquer_source($objet, $affiche) { |
|
| 686 | 683 | $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
| 687 | 684 | $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
| 688 | 685 | $res2 = ""; |
| 689 | 686 | |
| 690 | - if ($affiche=='resultat'){ |
|
| 687 | + if ($affiche == 'resultat') { |
|
| 691 | 688 | $legend = $nom; |
| 692 | 689 | $req = $GLOBALS['debug_objets']['requete'][$objet]; |
| 693 | - if (function_exists('traite_query')){ |
|
| 690 | + if (function_exists('traite_query')) { |
|
| 694 | 691 | $c = strtolower(_request('connect')); |
| 695 | 692 | $c = $GLOBALS['connexions'][$c ? $c : 0]['prefixe']; |
| 696 | 693 | $req = traite_query($req, '', $c); |
| 697 | 694 | } |
| 698 | 695 | // permettre le copier/coller facile |
| 699 | 696 | // $res = ancre_texte($req, array(), true); |
| 700 | - $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 697 | + $res = "<div id='T".md5($req)."'>\n<pre>\n".$req."</pre>\n</div>\n"; |
|
| 701 | 698 | // formatage et affichage des resultats bruts de la requete |
| 702 | 699 | $ress_req = spip_query($req); |
| 703 | 700 | $brut_sql = ''; |
@@ -705,38 +702,38 @@ discard block |
||
| 705 | 702 | // eviter l'affichage de milliers de lignes |
| 706 | 703 | // personnalisation possible dans mes_options |
| 707 | 704 | $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
| 708 | - while ($retours_sql = sql_fetch($ress_req)){ |
|
| 709 | - if ($num<=$max_aff){ |
|
| 710 | - $brut_sql .= "<h3>" . ($num==1 ? $num . " sur " . sql_count($ress_req) : $num) . "</h3>"; |
|
| 705 | + while ($retours_sql = sql_fetch($ress_req)) { |
|
| 706 | + if ($num <= $max_aff) { |
|
| 707 | + $brut_sql .= "<h3>".($num == 1 ? $num." sur ".sql_count($ress_req) : $num)."</h3>"; |
|
| 711 | 708 | $brut_sql .= "<p>"; |
| 712 | - foreach ($retours_sql as $key => $val){ |
|
| 713 | - $brut_sql .= "<strong>" . $key . "</strong> => " . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 709 | + foreach ($retours_sql as $key => $val) { |
|
| 710 | + $brut_sql .= "<strong>".$key."</strong> => ".spip_htmlspecialchars(couper($val, 150))."<br />\n"; |
|
| 714 | 711 | } |
| 715 | 712 | $brut_sql .= "</p>"; |
| 716 | 713 | } |
| 717 | 714 | $num++; |
| 718 | 715 | } |
| 719 | 716 | $res2 = interdire_scripts($brut_sql); |
| 720 | - foreach ($quoi as $view){ |
|
| 717 | + foreach ($quoi as $view) { |
|
| 721 | 718 | // ne pas afficher les $contexte_inclus |
| 722 | 719 | $view = preg_replace(",<\?php.+\?[>],Uims", "", $view); |
| 723 | - if ($view){ |
|
| 724 | - $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . "</fieldset>"; |
|
| 720 | + if ($view) { |
|
| 721 | + $res2 .= "\n<br /><fieldset>".interdire_scripts($view)."</fieldset>"; |
|
| 725 | 722 | } |
| 726 | 723 | } |
| 727 | 724 | |
| 728 | 725 | } |
| 729 | - elseif ($affiche=='code'){ |
|
| 726 | + elseif ($affiche == 'code') { |
|
| 730 | 727 | $legend = $nom; |
| 731 | - $res = ancre_texte("<" . "?php\n" . $quoi . "\n?" . ">"); |
|
| 728 | + $res = ancre_texte("<"."?php\n".$quoi."\n?".">"); |
|
| 732 | 729 | } |
| 733 | - elseif ($affiche=='boucle'){ |
|
| 734 | - $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 730 | + elseif ($affiche == 'boucle') { |
|
| 731 | + $legend = _T('zbug_boucle').' '.$nom; |
|
| 735 | 732 | // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
| 736 | 733 | $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
| 737 | 734 | $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
| 738 | 735 | } |
| 739 | - elseif ($affiche=='squelette'){ |
|
| 736 | + elseif ($affiche == 'squelette') { |
|
| 740 | 737 | $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
| 741 | 738 | $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
| 742 | 739 | } |
@@ -745,30 +742,30 @@ discard block |
||
| 745 | 742 | } |
| 746 | 743 | |
| 747 | 744 | // http://doc.spip.org/@debusquer_entete |
| 748 | -function debusquer_entete($titre, $corps){ |
|
| 745 | +function debusquer_entete($titre, $corps) { |
|
| 749 | 746 | global $debug_objets; |
| 750 | 747 | include_spip('balise/formulaire_admin'); |
| 751 | 748 | include_spip('public/assembler'); // pour inclure_balise_dynamique |
| 752 | 749 | include_spip('inc/texte'); // pour corriger_typo |
| 753 | 750 | |
| 754 | - return _DOCTYPE_ECRIRE . |
|
| 755 | - html_lang_attributes() . |
|
| 756 | - "<head>\n<title>" . |
|
| 757 | - ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 758 | - _T('admin_debug') . ' ' . $titre . ' (' . |
|
| 759 | - supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 760 | - ")</title>\n" . |
|
| 761 | - "<meta http-equiv='Content-Type' content='text/html" . |
|
| 762 | - (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 763 | - "' />\n" . |
|
| 751 | + return _DOCTYPE_ECRIRE. |
|
| 752 | + html_lang_attributes(). |
|
| 753 | + "<head>\n<title>". |
|
| 754 | + ('SPIP '.$GLOBALS['spip_version_affichee'].' '. |
|
| 755 | + _T('admin_debug').' '.$titre.' ('. |
|
| 756 | + supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))). |
|
| 757 | + ")</title>\n". |
|
| 758 | + "<meta http-equiv='Content-Type' content='text/html". |
|
| 759 | + (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : ''). |
|
| 760 | + "' />\n". |
|
| 764 | 761 | http_script('', 'jquery.js') |
| 765 | - . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 766 | - . "' type='text/css' />" . |
|
| 767 | - "</head>\n" . |
|
| 768 | - "<body style='margin:0 10px;'>\n" . |
|
| 769 | - "<div id='spip-debug-header'>" . |
|
| 770 | - $corps . |
|
| 771 | - inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $debug_objets), false) . |
|
| 762 | + . "<link rel='stylesheet' href='".url_absolue(find_in_path('spip_admin.css')) |
|
| 763 | + . "' type='text/css' />". |
|
| 764 | + "</head>\n". |
|
| 765 | + "<body style='margin:0 10px;'>\n". |
|
| 766 | + "<div id='spip-debug-header'>". |
|
| 767 | + $corps. |
|
| 768 | + inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $debug_objets), false). |
|
| 772 | 769 | '</div></body></html>'; |
| 773 | 770 | } |
| 774 | 771 | |
@@ -10,7 +10,9 @@ 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 | 17 | include_spip('public/decompiler'); |
| 16 | 18 | include_spip('inc/filtres_mini'); |
@@ -86,17 +88,23 @@ discard block |
||
| 86 | 88 | set_request('var_mode', 'debug'); |
| 87 | 89 | $GLOBALS['bouton_admin_debug'] = true; |
| 88 | 90 | // Permettre a la compil de continuer |
| 89 | - if (is_object($lieu) AND (!isset($lieu->code) OR !$lieu->code)) |
|
| 90 | - $lieu->code = "''"; |
|
| 91 | + if (is_object($lieu) AND (!isset($lieu->code) OR !$lieu->code)) { |
|
| 92 | + $lieu->code = "''"; |
|
| 93 | + } |
|
| 91 | 94 | // forcer l'appel au debusqueur en cas de boucles infernales |
| 92 | 95 | $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS AND count($tableau_des_erreurs)>_DEBUG_MAX_SQUELETTE_ERREURS); |
| 93 | - if (!$urgence) return; |
|
| 96 | + if (!$urgence) { |
|
| 97 | + return; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + if (empty($debug_objets['principal'])) { |
|
| 101 | + $debug_objets['principal'] = $GLOBALS['fond']; |
|
| 94 | 102 | } |
| 95 | - if (empty($debug_objets['principal'])) |
|
| 96 | - $debug_objets['principal'] = $GLOBALS['fond']; |
|
| 97 | 103 | |
| 98 | 104 | include_spip('inc/autoriser'); |
| 99 | - if (!autoriser('debug')) return; |
|
| 105 | + if (!autoriser('debug')) { |
|
| 106 | + return; |
|
| 107 | + } |
|
| 100 | 108 | include_spip('inc/headers'); |
| 101 | 109 | include_spip('inc/filtres'); |
| 102 | 110 | |
@@ -122,24 +130,29 @@ discard block |
||
| 122 | 130 | . '<br />' |
| 123 | 131 | . debusquer_squelette($fonc, $mode, $self); |
| 124 | 132 | |
| 125 | - if (!_DIR_RESTREINT OR headers_sent()) return $res; |
|
| 126 | - if ($tableau_des_erreurs) http_status(503); |
|
| 133 | + if (!_DIR_RESTREINT OR headers_sent()) { |
|
| 134 | + return $res; |
|
| 135 | + } |
|
| 136 | + if ($tableau_des_erreurs) { |
|
| 137 | + http_status(503); |
|
| 138 | + } |
|
| 127 | 139 | |
| 128 | 140 | http_no_cache(); |
| 129 | 141 | if (isset($_GET['var_profile'])){ |
| 130 | 142 | $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
| 131 | 143 | $titre = parametre_url($titre, 'var_mode', ''); |
| 132 | - } |
|
| 133 | - else { |
|
| 134 | - if (!$fonc) $fonc = $debug_objets['principal']; |
|
| 144 | + } else { |
|
| 145 | + if (!$fonc) { |
|
| 146 | + $fonc = $debug_objets['principal']; |
|
| 147 | + } |
|
| 135 | 148 | $titre = !$mode ? $fonc : ($mode . ' ' . $debug_objets['sourcefile'][$fonc]); |
| 136 | 149 | } |
| 137 | 150 | if ($message===false){ |
| 138 | 151 | lang_select(); |
| 139 | 152 | return debusquer_entete($titre, $res); |
| 153 | + } else { |
|
| 154 | + echo debusquer_entete($titre, $res); |
|
| 140 | 155 | } |
| 141 | - else |
|
| 142 | - echo debusquer_entete($titre, $res); |
|
| 143 | 156 | exit; |
| 144 | 157 | } |
| 145 | 158 | |
@@ -169,25 +182,29 @@ discard block |
||
| 169 | 182 | if (!empty($erreurs)){ |
| 170 | 183 | $n = array(count($erreurs) . ' ' . _T('zbug_erreur_squelette')); |
| 171 | 184 | return debusquer_navigation($erreurs, $n); |
| 172 | - } |
|
| 173 | - elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 185 | + } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 174 | 186 | include_spip('public/tracer'); |
| 175 | 187 | list($temps, $nav) = chrono_requete($GLOBALS['tableau_des_temps']); |
| 176 | 188 | return debusquer_navigation($temps, $nav, 'debug-profile'); |
| 189 | + } else { |
|
| 190 | + return ''; |
|
| 191 | + } |
|
| 177 | 192 | } |
| 178 | - else |
|
| 179 | - return ''; |
|
| 180 | -} |
|
| 181 | 193 | |
| 182 | 194 | function debusquer_contexte($env){ |
| 183 | 195 | |
| 184 | - if (is_array($env_tab = @unserialize($env))) $env = $env_tab; |
|
| 196 | + if (is_array($env_tab = @unserialize($env))) { |
|
| 197 | + $env = $env_tab; |
|
| 198 | + } |
|
| 185 | 199 | |
| 186 | - if (!$env) return ''; |
|
| 200 | + if (!$env) { |
|
| 201 | + return ''; |
|
| 202 | + } |
|
| 187 | 203 | $res = ""; |
| 188 | 204 | foreach ($env as $nom => $valeur){ |
| 189 | - if (is_array($valeur)) |
|
| 190 | - $valeur = '(' . count($valeur) . ' items) [' . join(',', $valeur) . ']'; |
|
| 205 | + if (is_array($valeur)) { |
|
| 206 | + $valeur = '(' . count($valeur) . ' items) [' . join(',', $valeur) . ']'; |
|
| 207 | + } |
|
| 191 | 208 | $res .= "\n<tr><td><strong>" . nl2br(entites_html($nom)) |
| 192 | 209 | . "</strong></td><td>: " . nl2br(entites_html($valeur)) |
| 193 | 210 | . "</td></tr>\n"; |
@@ -201,7 +218,9 @@ discard block |
||
| 201 | 218 | |
| 202 | 219 | function debusquer_navigation($tableau, $caption = array(), $id = 'debug-nav'){ |
| 203 | 220 | |
| 204 | - if (_request('exec')=='valider_xml') return ''; |
|
| 221 | + if (_request('exec')=='valider_xml') { |
|
| 222 | + return ''; |
|
| 223 | + } |
|
| 205 | 224 | $GLOBALS['bouton_admin_debug'] = true; |
| 206 | 225 | $res = ''; |
| 207 | 226 | $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
@@ -285,8 +304,7 @@ discard block |
||
| 285 | 304 | // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
| 286 | 305 | if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)){ |
| 287 | 306 | $errno = $regs[2]; |
| 288 | - } |
|
| 289 | - elseif (is_numeric($errno) and ($errno==1030 OR $errno<=1026) |
|
| 307 | + } elseif (is_numeric($errno) and ($errno==1030 OR $errno<=1026) |
|
| 290 | 308 | AND preg_match(',[^[:alnum:]]([0-9]+)[^[:alnum:]],', $msg, $regs) |
| 291 | 309 | ) { |
| 292 | 310 | $errno = $regs[1]; |
@@ -325,25 +343,27 @@ discard block |
||
| 325 | 343 | if (is_array($debug_objets['sequence'][$id])){ |
| 326 | 344 | foreach ($debug_objets['sequence'][$id] as $v){ |
| 327 | 345 | |
| 328 | - if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) |
|
| 329 | - $y = substr_count($v[0], "\n"); |
|
| 330 | - else { |
|
| 331 | - if ($v[1][0]=='#') |
|
| 332 | - // balise dynamique |
|
| 346 | + if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) { |
|
| 347 | + $y = substr_count($v[0], "\n"); |
|
| 348 | + } else { |
|
| 349 | + if ($v[1][0]=='#') { |
|
| 350 | + // balise dynamique |
|
| 333 | 351 | $incl = $debug_objets['resultat'][$v[2]]; |
| 334 | - else |
|
| 335 | - // inclusion |
|
| 352 | + } else { |
|
| 353 | + // inclusion |
|
| 336 | 354 | $incl = $debug_objets['squelette'][trouve_squelette_inclus($v[0])]; |
| 355 | + } |
|
| 337 | 356 | $y = substr_count($incl, "\n") |
| 338 | 357 | +substr_count($r[1], "\n") |
| 339 | 358 | +substr_count($r[3], "\n"); |
| 340 | 359 | } |
| 341 | 360 | if ($n<=($y+$debut)){ |
| 342 | - if ($v[1][0]=='?') |
|
| 343 | - return trouve_boucle_debug($n, $nom, $debut, substr($v[1], 1)); |
|
| 344 | - elseif ($v[1][0]=='!') { |
|
| 345 | - if ($incl = trouve_squelette_inclus($v[1])) |
|
| 346 | - return trouve_boucle_debug($n, $incl, $debut); |
|
| 361 | + if ($v[1][0]=='?') { |
|
| 362 | + return trouve_boucle_debug($n, $nom, $debut, substr($v[1], 1)); |
|
| 363 | + } elseif ($v[1][0]=='!') { |
|
| 364 | + if ($incl = trouve_squelette_inclus($v[1])) { |
|
| 365 | + return trouve_boucle_debug($n, $incl, $debut); |
|
| 366 | + } |
|
| 347 | 367 | } |
| 348 | 368 | return array($nom, $boucle, $v[2]-1+$n-$debut); |
| 349 | 369 | } |
@@ -359,16 +379,19 @@ discard block |
||
| 359 | 379 | preg_match('/include\(.(.*).php3?.\);/', $script, $reg); |
| 360 | 380 | // si le script X.php n'est pas ecrire/public.php |
| 361 | 381 | // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
| 362 | - if ($reg[1]=='ecrire/public') |
|
| 363 | - // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 382 | + if ($reg[1]=='ecrire/public') { |
|
| 383 | + // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 364 | 384 | if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) |
| 365 | 385 | // a defaut on cherche le param 'page' |
| 366 | 386 | if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) |
| 367 | 387 | $reg[1] = "inconnu"; |
| 388 | + } |
|
| 368 | 389 | $incl = ',' . $reg[1] . '[.]\w$,'; |
| 369 | 390 | |
| 370 | 391 | foreach ($debug_objets['sourcefile'] as $k => $v){ |
| 371 | - if (preg_match($incl, $v)) return $k; |
|
| 392 | + if (preg_match($incl, $v)) { |
|
| 393 | + return $k; |
|
| 394 | + } |
|
| 372 | 395 | } |
| 373 | 396 | return ""; |
| 374 | 397 | } |
@@ -377,13 +400,13 @@ discard block |
||
| 377 | 400 | function reference_boucle_debug($n, $nom, $self){ |
| 378 | 401 | list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
| 379 | 402 | |
| 380 | - if (!$boucle) |
|
| 381 | - return !$ligne ? "" : |
|
| 403 | + if (!$boucle) { |
|
| 404 | + return !$ligne ? "" : |
|
| 382 | 405 | (" (" . |
| 383 | 406 | (($nom!=$skel) ? _T('squelette_inclus_ligne') : |
| 384 | 407 | _T('squelette_ligne')) . |
| 385 | 408 | " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
| 386 | - else { |
|
| 409 | + } else { |
|
| 387 | 410 | $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
| 388 | 411 | |
| 389 | 412 | return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
@@ -397,7 +420,9 @@ discard block |
||
| 397 | 420 | function ancre_texte($texte, $fautifs = array(), $nocpt = false){ |
| 398 | 421 | |
| 399 | 422 | $var_mode_ligne = _request('var_mode_ligne'); |
| 400 | - if ($var_mode_ligne) $fautifs[] = array($var_mode_ligne); |
|
| 423 | + if ($var_mode_ligne) { |
|
| 424 | + $fautifs[] = array($var_mode_ligne); |
|
| 425 | + } |
|
| 401 | 426 | $res = ''; |
| 402 | 427 | |
| 403 | 428 | $s = highlight_string($texte, true); |
@@ -420,11 +445,14 @@ discard block |
||
| 420 | 445 | $i = 1; |
| 421 | 446 | $flignes = array(); |
| 422 | 447 | $loc = array(0, 0); |
| 423 | - foreach ($fautifs as $lc) |
|
| 424 | - if (is_array($lc)){ |
|
| 448 | + foreach ($fautifs as $lc) { |
|
| 449 | + if (is_array($lc)){ |
|
| 425 | 450 | $l = array_shift($lc); |
| 451 | + } |
|
| 426 | 452 | $flignes[$l] = $lc; |
| 427 | - } else $flignes[$lc] = $loc; |
|
| 453 | + } else { |
|
| 454 | + $flignes[$lc] = $loc; |
|
| 455 | + } |
|
| 428 | 456 | |
| 429 | 457 | $ancre = md5($texte); |
| 430 | 458 | foreach ($tableau as $ligne){ |
@@ -467,39 +495,38 @@ discard block |
||
| 467 | 495 | $res = "<div id='spip-boucles'>\n" |
| 468 | 496 | . debusquer_navigation_squelettes($self) |
| 469 | 497 | . "</div>"; |
| 498 | + } else { |
|
| 499 | + $res = ''; |
|
| 470 | 500 | } |
| 471 | - else |
|
| 472 | - $res = ''; |
|
| 473 | 501 | if ($fonc){ |
| 474 | 502 | $id = " id='$fonc'"; |
| 475 | 503 | if (!empty($GLOBALS['debug_objets'][$mode][$fonc])){ |
| 476 | 504 | list($legend, $texte, $res2) = debusquer_source($fonc, $mode); |
| 477 | 505 | $texte .= $res2; |
| 478 | - } |
|
| 479 | - elseif (!empty($debug_objets[$mode][$fonc . 'tout'])) { |
|
| 506 | + } elseif (!empty($debug_objets[$mode][$fonc . 'tout'])) { |
|
| 480 | 507 | $legend = _T('zbug_' . $mode); |
| 481 | 508 | $texte = $debug_objets[$mode][$fonc . 'tout']; |
| 482 | 509 | $texte = ancre_texte($texte, array('', '')); |
| 483 | 510 | } |
| 484 | - } |
|
| 485 | - else |
|
| 486 | - return strlen(trim($res)) |
|
| 511 | + } else { |
|
| 512 | + return strlen(trim($res)) |
|
| 487 | 513 | ? "<img src='".chemin_image('compat-16.png')."' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>" |
| 488 | 514 | // cas de l'appel sur erreur: montre la page |
| 489 | 515 | : $GLOBALS['debug_objets']['resultat']['tout']; |
| 490 | - } |
|
| 491 | - else { |
|
| 516 | + } |
|
| 517 | + } else { |
|
| 492 | 518 | $valider = charger_fonction('valider', 'xml'); |
| 493 | 519 | $val = $valider($debug_objets['validation'][$fonc . 'tout']); |
| 494 | 520 | // Si erreur, signaler leur nombre dans le formulaire admin |
| 495 | 521 | $debug_objets['validation'] = $val->err ? count($val->err) : ''; |
| 496 | 522 | list($texte, $err) = emboite_texte($val, $fonc, $self); |
| 497 | - if ($err===false) |
|
| 498 | - $err = _T('impossible'); |
|
| 499 | - elseif ($err===true) |
|
| 500 | - $err = _T('correcte'); |
|
| 501 | - else |
|
| 502 | - $err = ": $err"; |
|
| 523 | + if ($err===false) { |
|
| 524 | + $err = _T('impossible'); |
|
| 525 | + } elseif ($err===true) { |
|
| 526 | + $err = _T('correcte'); |
|
| 527 | + } else { |
|
| 528 | + $err = ": $err"; |
|
| 529 | + } |
|
| 503 | 530 | $legend = _T('validation') . ' ' . $err; |
| 504 | 531 | $res = $id = ''; |
| 505 | 532 | } |
@@ -520,10 +547,12 @@ discard block |
||
| 520 | 547 | $errs = $res->err; |
| 521 | 548 | $texte = $res->entete . ($errs ? '' : $res->page); |
| 522 | 549 | |
| 523 | - if (!$texte and !$errs) |
|
| 524 | - return array(ancre_texte('', array('', '')), false); |
|
| 525 | - if (!$errs) |
|
| 526 | - return array(ancre_texte($texte, array('', '')), true); |
|
| 550 | + if (!$texte and !$errs) { |
|
| 551 | + return array(ancre_texte('', array('', '')), false); |
|
| 552 | + } |
|
| 553 | + if (!$errs) { |
|
| 554 | + return array(ancre_texte($texte, array('', '')), true); |
|
| 555 | + } |
|
| 527 | 556 | |
| 528 | 557 | if (!isset($GLOBALS['debug_objets'])){ |
| 529 | 558 | |
@@ -550,9 +579,9 @@ discard block |
||
| 550 | 579 | $i++; |
| 551 | 580 | list($msg, $ligne, $col) = $r; |
| 552 | 581 | #spip_log("$r = list($msg, $ligne, $col"); |
| 553 | - if (isset($encore2[$msg])) |
|
| 554 | - $ref = ++$encore2[$msg]; |
|
| 555 | - else { |
|
| 582 | + if (isset($encore2[$msg])) { |
|
| 583 | + $ref = ++$encore2[$msg]; |
|
| 584 | + } else { |
|
| 556 | 585 | $encore2[$msg] = $ref = 1; |
| 557 | 586 | } |
| 558 | 587 | $err .= "<tr style='background-color: " |
@@ -578,8 +607,7 @@ discard block |
||
| 578 | 607 | . $err |
| 579 | 608 | . " </table><a id='fin_err'></a>"; |
| 580 | 609 | return array(ancre_texte($texte, $fautifs), $err); |
| 581 | - } |
|
| 582 | - else { |
|
| 610 | + } else { |
|
| 583 | 611 | list($msg, $fermant, $ouvrant) = $errs[0]; |
| 584 | 612 | $rf = reference_boucle_debug($fermant, $fonc, $self); |
| 585 | 613 | $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
@@ -594,10 +622,11 @@ discard block |
||
| 594 | 622 | function count_occ($regs){ |
| 595 | 623 | $encore = array(); |
| 596 | 624 | foreach ($regs as $r){ |
| 597 | - if (isset($encore[$r[0]])) |
|
| 598 | - $encore[$r[0]]++; |
|
| 599 | - else |
|
| 600 | - $encore[$r[0]] = 1; |
|
| 625 | + if (isset($encore[$r[0]])) { |
|
| 626 | + $encore[$r[0]]++; |
|
| 627 | + } else { |
|
| 628 | + $encore[$r[0]] = 1; |
|
| 629 | + } |
|
| 601 | 630 | } |
| 602 | 631 | return $encore; |
| 603 | 632 | } |
@@ -725,18 +754,15 @@ discard block |
||
| 725 | 754 | } |
| 726 | 755 | } |
| 727 | 756 | |
| 728 | - } |
|
| 729 | - elseif ($affiche=='code'){ |
|
| 757 | + } elseif ($affiche=='code'){ |
|
| 730 | 758 | $legend = $nom; |
| 731 | 759 | $res = ancre_texte("<" . "?php\n" . $quoi . "\n?" . ">"); |
| 732 | - } |
|
| 733 | - elseif ($affiche=='boucle'){ |
|
| 760 | + } elseif ($affiche=='boucle'){ |
|
| 734 | 761 | $legend = _T('zbug_boucle') . ' ' . $nom; |
| 735 | 762 | // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
| 736 | 763 | $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
| 737 | 764 | $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
| 738 | - } |
|
| 739 | - elseif ($affiche=='squelette'){ |
|
| 765 | + } elseif ($affiche=='squelette'){ |
|
| 740 | 766 | $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
| 741 | 767 | $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
| 742 | 768 | } |
@@ -130,6 +130,10 @@ discard block |
||
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | // http://doc.spip.org/@index_tables_en_pile |
| 133 | +/** |
|
| 134 | + * @param string $nom_champ |
|
| 135 | + * @param boolean $joker |
|
| 136 | + */ |
|
| 133 | 137 | function index_tables_en_pile($idb, $nom_champ, &$boucles, &$joker) { |
| 134 | 138 | global $exceptions_des_tables; |
| 135 | 139 | |
@@ -568,6 +572,9 @@ discard block |
||
| 568 | 572 | |
| 569 | 573 | // Filtres et,ou,oui,non,sinon,xou,xor,and,or,not,yes |
| 570 | 574 | // et comparateurs |
| 575 | +/** |
|
| 576 | + * @param string $arg |
|
| 577 | + */ |
|
| 571 | 578 | function filtre_logique($fonc, $code, $arg) |
| 572 | 579 | { |
| 573 | 580 | global $table_criteres_infixes; |
@@ -591,6 +598,9 @@ discard block |
||
| 591 | 598 | } |
| 592 | 599 | |
| 593 | 600 | // http://doc.spip.org/@compose_filtres_args |
| 601 | +/** |
|
| 602 | + * @param string $sep |
|
| 603 | + */ |
|
| 594 | 604 | function compose_filtres_args($p, $args, $sep) |
| 595 | 605 | { |
| 596 | 606 | $arglist = ""; |
@@ -607,6 +617,9 @@ discard block |
||
| 607 | 617 | // ET chez sa maman |
| 608 | 618 | // |
| 609 | 619 | // http://doc.spip.org/@calculer_argument_precedent |
| 620 | +/** |
|
| 621 | + * @param string $defaut |
|
| 622 | + */ |
|
| 610 | 623 | function calculer_argument_precedent($idb, $nom_champ, &$boucles, $defaut=null) { |
| 611 | 624 | |
| 612 | 625 | // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
@@ -631,6 +644,10 @@ discard block |
||
| 631 | 644 | // |
| 632 | 645 | |
| 633 | 646 | // http://doc.spip.org/@rindex_pile |
| 647 | +/** |
|
| 648 | + * @param string $champ |
|
| 649 | + * @param string $motif |
|
| 650 | + */ |
|
| 634 | 651 | function rindex_pile($p, $champ, $motif) |
| 635 | 652 | { |
| 636 | 653 | $n = 0; |
@@ -29,17 +29,17 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | function index_boucle($p){ |
| 31 | 31 | |
| 32 | - $idb = $p->id_boucle; |
|
| 33 | - $explicite = $p->nom_boucle; |
|
| 32 | + $idb = $p->id_boucle; |
|
| 33 | + $explicite = $p->nom_boucle; |
|
| 34 | 34 | |
| 35 | - if (strlen($explicite)) { |
|
| 36 | - // Recherche d'un champ dans un etage superieur |
|
| 37 | - while (($idb !== $explicite) && ($idb !=='')) { |
|
| 38 | - $idb = $p->boucles[$idb]->id_parent; |
|
| 39 | - } |
|
| 40 | - } |
|
| 35 | + if (strlen($explicite)) { |
|
| 36 | + // Recherche d'un champ dans un etage superieur |
|
| 37 | + while (($idb !== $explicite) && ($idb !=='')) { |
|
| 38 | + $idb = $p->boucles[$idb]->id_parent; |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - return $idb; |
|
| 42 | + return $idb; |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -65,52 +65,52 @@ discard block |
||
| 65 | 65 | * @return string |
| 66 | 66 | */ |
| 67 | 67 | function index_pile($idb, $nom_champ, &$boucles, $explicite='', $defaut=null, $remonte_pile=true) { |
| 68 | - if (!is_string($defaut)) |
|
| 69 | - $defaut = '@$Pile[0][\''. strtolower($nom_champ) . '\']'; |
|
| 70 | - |
|
| 71 | - $i = 0; |
|
| 72 | - if (strlen($explicite)) { |
|
| 73 | - // Recherche d'un champ dans un etage superieur |
|
| 74 | - while (($idb !== $explicite) && ($idb !=='')) { |
|
| 75 | - # spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'"); |
|
| 76 | - $i++; |
|
| 77 | - $idb = $boucles[$idb]->id_parent; |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - # spip_log("Cherche: $nom_champ a partir de '$idb'"); |
|
| 82 | - $nom_champ = strtolower($nom_champ); |
|
| 83 | - $conditionnel = array(); |
|
| 84 | - // attention: entre la boucle nommee 0, "" et le tableau vide, |
|
| 85 | - // il y a incoherences qu'il vaut mieux eviter |
|
| 86 | - while (isset($boucles[$idb])) { |
|
| 87 | - $joker = true; |
|
| 88 | - list ($t, $c) = index_tables_en_pile($idb, $nom_champ, $boucles, $joker); |
|
| 89 | - if ($t) { |
|
| 90 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 91 | - $boucles[$idb]->select[] = $t; |
|
| 92 | - } |
|
| 93 | - $champ = '$Pile[$SP' . ($i ? "-$i" : "") . '][\'' . $c . '\']'; |
|
| 94 | - if (!$joker) |
|
| 95 | - return index_compose($conditionnel,$champ); |
|
| 96 | - |
|
| 97 | - $conditionnel[] = "isset($champ)?$champ"; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - if ($remonte_pile){ |
|
| 101 | - # spip_log("On remonte vers $i"); |
|
| 102 | - // Sinon on remonte d'un cran |
|
| 103 | - $idb = $boucles[$idb]->id_parent; |
|
| 104 | - $i++; |
|
| 105 | - } |
|
| 106 | - else |
|
| 107 | - $idb = null; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - # spip_log("Pas vu $nom_champ"); |
|
| 111 | - // esperons qu'il y sera |
|
| 112 | - // on qu'on a fourni une valeur par "defaut" plus pertinent |
|
| 113 | - return index_compose($conditionnel,$defaut); |
|
| 68 | + if (!is_string($defaut)) |
|
| 69 | + $defaut = '@$Pile[0][\''. strtolower($nom_champ) . '\']'; |
|
| 70 | + |
|
| 71 | + $i = 0; |
|
| 72 | + if (strlen($explicite)) { |
|
| 73 | + // Recherche d'un champ dans un etage superieur |
|
| 74 | + while (($idb !== $explicite) && ($idb !=='')) { |
|
| 75 | + # spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'"); |
|
| 76 | + $i++; |
|
| 77 | + $idb = $boucles[$idb]->id_parent; |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + # spip_log("Cherche: $nom_champ a partir de '$idb'"); |
|
| 82 | + $nom_champ = strtolower($nom_champ); |
|
| 83 | + $conditionnel = array(); |
|
| 84 | + // attention: entre la boucle nommee 0, "" et le tableau vide, |
|
| 85 | + // il y a incoherences qu'il vaut mieux eviter |
|
| 86 | + while (isset($boucles[$idb])) { |
|
| 87 | + $joker = true; |
|
| 88 | + list ($t, $c) = index_tables_en_pile($idb, $nom_champ, $boucles, $joker); |
|
| 89 | + if ($t) { |
|
| 90 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 91 | + $boucles[$idb]->select[] = $t; |
|
| 92 | + } |
|
| 93 | + $champ = '$Pile[$SP' . ($i ? "-$i" : "") . '][\'' . $c . '\']'; |
|
| 94 | + if (!$joker) |
|
| 95 | + return index_compose($conditionnel,$champ); |
|
| 96 | + |
|
| 97 | + $conditionnel[] = "isset($champ)?$champ"; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + if ($remonte_pile){ |
|
| 101 | + # spip_log("On remonte vers $i"); |
|
| 102 | + // Sinon on remonte d'un cran |
|
| 103 | + $idb = $boucles[$idb]->id_parent; |
|
| 104 | + $i++; |
|
| 105 | + } |
|
| 106 | + else |
|
| 107 | + $idb = null; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + # spip_log("Pas vu $nom_champ"); |
|
| 111 | + // esperons qu'il y sera |
|
| 112 | + // on qu'on a fourni une valeur par "defaut" plus pertinent |
|
| 113 | + return index_compose($conditionnel,$defaut); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -123,59 +123,59 @@ discard block |
||
| 123 | 123 | * @return string |
| 124 | 124 | */ |
| 125 | 125 | function index_compose($conditionnel,$defaut){ |
| 126 | - while ($c = array_pop($conditionnel)) |
|
| 127 | - // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 128 | - $defaut = "($c:(".($defaut?$defaut:"''")."))"; |
|
| 129 | - return $defaut; |
|
| 126 | + while ($c = array_pop($conditionnel)) |
|
| 127 | + // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 128 | + $defaut = "($c:(".($defaut?$defaut:"''")."))"; |
|
| 129 | + return $defaut; |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | // http://doc.spip.org/@index_tables_en_pile |
| 133 | 133 | function index_tables_en_pile($idb, $nom_champ, &$boucles, &$joker) { |
| 134 | - global $exceptions_des_tables; |
|
| 135 | - |
|
| 136 | - $r = $boucles[$idb]->type_requete; |
|
| 137 | - |
|
| 138 | - if ($r == 'boucle') return array(); |
|
| 139 | - if (!$r) { |
|
| 140 | - $joker = false; // indiquer a l'appelant |
|
| 141 | - # continuer pour chercher l'erreur suivante |
|
| 142 | - return array("'#" . $r . ':' . $nom_champ . "'",''); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - $desc = $boucles[$idb]->show; |
|
| 146 | - $excep = isset($exceptions_des_tables[$r]) ? $exceptions_des_tables[$r] : ''; |
|
| 147 | - if ($excep) |
|
| 148 | - $excep = isset($excep[$nom_champ]) ? $excep[$nom_champ] : ''; |
|
| 149 | - if ($excep) { |
|
| 150 | - $joker = false; // indiquer a l'appelant |
|
| 151 | - return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 152 | - } |
|
| 153 | - else { |
|
| 154 | - if (isset($desc['field'][$nom_champ])) { |
|
| 155 | - $t = $boucles[$idb]->id_table; |
|
| 156 | - $joker = false; // indiquer a l'appelant |
|
| 157 | - return array("$t.$nom_champ", $nom_champ); |
|
| 158 | - } |
|
| 159 | - // Champ joker * des iterateurs DATA qui accepte tout |
|
| 160 | - elseif (/*$joker AND */isset($desc['field']['*'])) { |
|
| 161 | - $joker = true; // indiquer a l'appelant |
|
| 162 | - return array($nom_champ, $nom_champ); |
|
| 163 | - } |
|
| 164 | - else { |
|
| 165 | - $joker = false; // indiquer a l'appelant |
|
| 166 | - if ($boucles[$idb]->jointures_explicites) { |
|
| 167 | - $t = trouver_champ_exterieur($nom_champ, |
|
| 168 | - $boucles[$idb]->jointures, |
|
| 169 | - $boucles[$idb]); |
|
| 170 | - if ($t) |
|
| 171 | - return index_exception($boucles[$idb], |
|
| 172 | - $desc, |
|
| 173 | - $nom_champ, |
|
| 174 | - array($t[1]['id_table'], $nom_champ)); |
|
| 175 | - } |
|
| 176 | - return array('',''); |
|
| 177 | - } |
|
| 178 | - } |
|
| 134 | + global $exceptions_des_tables; |
|
| 135 | + |
|
| 136 | + $r = $boucles[$idb]->type_requete; |
|
| 137 | + |
|
| 138 | + if ($r == 'boucle') return array(); |
|
| 139 | + if (!$r) { |
|
| 140 | + $joker = false; // indiquer a l'appelant |
|
| 141 | + # continuer pour chercher l'erreur suivante |
|
| 142 | + return array("'#" . $r . ':' . $nom_champ . "'",''); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + $desc = $boucles[$idb]->show; |
|
| 146 | + $excep = isset($exceptions_des_tables[$r]) ? $exceptions_des_tables[$r] : ''; |
|
| 147 | + if ($excep) |
|
| 148 | + $excep = isset($excep[$nom_champ]) ? $excep[$nom_champ] : ''; |
|
| 149 | + if ($excep) { |
|
| 150 | + $joker = false; // indiquer a l'appelant |
|
| 151 | + return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 152 | + } |
|
| 153 | + else { |
|
| 154 | + if (isset($desc['field'][$nom_champ])) { |
|
| 155 | + $t = $boucles[$idb]->id_table; |
|
| 156 | + $joker = false; // indiquer a l'appelant |
|
| 157 | + return array("$t.$nom_champ", $nom_champ); |
|
| 158 | + } |
|
| 159 | + // Champ joker * des iterateurs DATA qui accepte tout |
|
| 160 | + elseif (/*$joker AND */isset($desc['field']['*'])) { |
|
| 161 | + $joker = true; // indiquer a l'appelant |
|
| 162 | + return array($nom_champ, $nom_champ); |
|
| 163 | + } |
|
| 164 | + else { |
|
| 165 | + $joker = false; // indiquer a l'appelant |
|
| 166 | + if ($boucles[$idb]->jointures_explicites) { |
|
| 167 | + $t = trouver_champ_exterieur($nom_champ, |
|
| 168 | + $boucles[$idb]->jointures, |
|
| 169 | + $boucles[$idb]); |
|
| 170 | + if ($t) |
|
| 171 | + return index_exception($boucles[$idb], |
|
| 172 | + $desc, |
|
| 173 | + $nom_champ, |
|
| 174 | + array($t[1]['id_table'], $nom_champ)); |
|
| 175 | + } |
|
| 176 | + return array('',''); |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | // Reference a une entite SPIP alias d'un champ SQL |
@@ -185,44 +185,44 @@ discard block |
||
| 185 | 185 | // http://doc.spip.org/@index_exception |
| 186 | 186 | function index_exception(&$boucle, $desc, $nom_champ, $excep) |
| 187 | 187 | { |
| 188 | - static $trouver_table; |
|
| 189 | - if (!$trouver_table) |
|
| 190 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 191 | - |
|
| 192 | - if (is_array($excep)) { |
|
| 193 | - // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 194 | - $t = NULL; |
|
| 195 | - if (count($excep)==3){ |
|
| 196 | - $index_exception_derogatoire = array_pop($excep); |
|
| 197 | - $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 198 | - } |
|
| 199 | - if ($t == NULL) { |
|
| 200 | - list($e, $x) = $excep; #PHP4 affecte de gauche a droite |
|
| 201 | - $excep = $x; #PHP5 de droite a gauche ! |
|
| 202 | - $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 203 | - if (!$j) return array('',''); |
|
| 204 | - $e = $j['table']; |
|
| 205 | - if (!$t = array_search($e, $boucle->from)) { |
|
| 206 | - $k = $j['key']['PRIMARY KEY']; |
|
| 207 | - if (strpos($k,',')) { |
|
| 208 | - $l = (preg_split('/\s*,\s*/', $k)); |
|
| 209 | - $k = $desc['key']['PRIMARY KEY']; |
|
| 210 | - if (!in_array($k, $l)) { |
|
| 211 | - spip_log("jointure impossible $e " . join(',', $l)); |
|
| 212 | - return array('',''); |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - $k = array($boucle->id_table, array($e), $k); |
|
| 216 | - fabrique_jointures($boucle, array($k)); |
|
| 217 | - $t = array_search($e, $boucle->from); |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - } |
|
| 221 | - else $t = $boucle->id_table; |
|
| 222 | - // demander a SQL de gerer le synonyme |
|
| 223 | - // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 224 | - if ($excep != $nom_champ) $excep .= ' AS '. $nom_champ; |
|
| 225 | - return array("$t.$excep", $nom_champ); |
|
| 188 | + static $trouver_table; |
|
| 189 | + if (!$trouver_table) |
|
| 190 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 191 | + |
|
| 192 | + if (is_array($excep)) { |
|
| 193 | + // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 194 | + $t = NULL; |
|
| 195 | + if (count($excep)==3){ |
|
| 196 | + $index_exception_derogatoire = array_pop($excep); |
|
| 197 | + $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 198 | + } |
|
| 199 | + if ($t == NULL) { |
|
| 200 | + list($e, $x) = $excep; #PHP4 affecte de gauche a droite |
|
| 201 | + $excep = $x; #PHP5 de droite a gauche ! |
|
| 202 | + $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 203 | + if (!$j) return array('',''); |
|
| 204 | + $e = $j['table']; |
|
| 205 | + if (!$t = array_search($e, $boucle->from)) { |
|
| 206 | + $k = $j['key']['PRIMARY KEY']; |
|
| 207 | + if (strpos($k,',')) { |
|
| 208 | + $l = (preg_split('/\s*,\s*/', $k)); |
|
| 209 | + $k = $desc['key']['PRIMARY KEY']; |
|
| 210 | + if (!in_array($k, $l)) { |
|
| 211 | + spip_log("jointure impossible $e " . join(',', $l)); |
|
| 212 | + return array('',''); |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + $k = array($boucle->id_table, array($e), $k); |
|
| 216 | + fabrique_jointures($boucle, array($k)); |
|
| 217 | + $t = array_search($e, $boucle->from); |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + } |
|
| 221 | + else $t = $boucle->id_table; |
|
| 222 | + // demander a SQL de gerer le synonyme |
|
| 223 | + // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 224 | + if ($excep != $nom_champ) $excep .= ' AS '. $nom_champ; |
|
| 225 | + return array("$t.$excep", $nom_champ); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
@@ -241,15 +241,15 @@ discard block |
||
| 241 | 241 | * @return string |
| 242 | 242 | */ |
| 243 | 243 | function champ_sql($champ, $p, $defaut = null, $remonte_pile = true) { |
| 244 | - return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 244 | + return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | // cette fonction sert d'API pour demander une balise Spip avec filtres |
| 248 | 248 | |
| 249 | 249 | // http://doc.spip.org/@calculer_champ |
| 250 | 250 | function calculer_champ($p) { |
| 251 | - $p = calculer_balise($p->nom_champ, $p); |
|
| 252 | - return applique_filtres($p); |
|
| 251 | + $p = calculer_balise($p->nom_champ, $p); |
|
| 252 | + return applique_filtres($p); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | // Cette fonction sert d'API pour demander une balise SPIP sans filtres. |
@@ -264,57 +264,57 @@ discard block |
||
| 264 | 264 | // http://doc.spip.org/@calculer_balise |
| 265 | 265 | function calculer_balise($nom, $p) { |
| 266 | 266 | |
| 267 | - // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 268 | - if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 269 | - $p->balise_calculee = true; |
|
| 270 | - $res = $f($p); |
|
| 271 | - if ($res !== NULL) |
|
| 272 | - return $res; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - // Certaines des balises comportant un _ sont generiques |
|
| 276 | - if ($f = strpos($nom, '_') |
|
| 277 | - AND $f = charger_fonction(substr($nom,0,$f+1), 'balise', true)) { |
|
| 278 | - $res = $f($p); |
|
| 279 | - if ($res !== NULL) |
|
| 280 | - return $res; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 284 | - |
|
| 285 | - return $f($nom, $p); |
|
| 267 | + // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 268 | + if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 269 | + $p->balise_calculee = true; |
|
| 270 | + $res = $f($p); |
|
| 271 | + if ($res !== NULL) |
|
| 272 | + return $res; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + // Certaines des balises comportant un _ sont generiques |
|
| 276 | + if ($f = strpos($nom, '_') |
|
| 277 | + AND $f = charger_fonction(substr($nom,0,$f+1), 'balise', true)) { |
|
| 278 | + $res = $f($p); |
|
| 279 | + if ($res !== NULL) |
|
| 280 | + return $res; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 284 | + |
|
| 285 | + return $f($nom, $p); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | function calculer_balise_DEFAUT_dist($nom, $p) { |
| 289 | 289 | |
| 290 | - // ca pourrait etre un champ SQL homonyme, |
|
| 291 | - $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 292 | - |
|
| 293 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 294 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 295 | - if ($p->fonctions AND (!$p->fonctions[0][0]) AND $p->fonctions[0][1]) { |
|
| 296 | - $code = addslashes($p->fonctions[0][1]); |
|
| 297 | - $p->code .= " . '$code'"; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - // ne pas passer le filtre securite sur les id_xxx |
|
| 301 | - if (strpos($nom, 'ID_') === 0) |
|
| 302 | - $p->interdire_scripts = false; |
|
| 303 | - |
|
| 304 | - // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 305 | - // SI le champ SQL n'est pas trouve |
|
| 306 | - // ET si la balise a une forme de couleur |
|
| 307 | - // ET s'il n'y a ni filtre ni etoile |
|
| 308 | - // ALORS retourner la couleur. |
|
| 309 | - // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 310 | - if (preg_match("/^[A-F]{1,6}$/i", $nom) |
|
| 311 | - AND !$p->etoile |
|
| 312 | - AND !$p->fonctions) { |
|
| 313 | - $p->code = "'#$nom'"; |
|
| 314 | - $p->interdire_scripts = false; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - return $p; |
|
| 290 | + // ca pourrait etre un champ SQL homonyme, |
|
| 291 | + $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 292 | + |
|
| 293 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 294 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 295 | + if ($p->fonctions AND (!$p->fonctions[0][0]) AND $p->fonctions[0][1]) { |
|
| 296 | + $code = addslashes($p->fonctions[0][1]); |
|
| 297 | + $p->code .= " . '$code'"; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + // ne pas passer le filtre securite sur les id_xxx |
|
| 301 | + if (strpos($nom, 'ID_') === 0) |
|
| 302 | + $p->interdire_scripts = false; |
|
| 303 | + |
|
| 304 | + // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 305 | + // SI le champ SQL n'est pas trouve |
|
| 306 | + // ET si la balise a une forme de couleur |
|
| 307 | + // ET s'il n'y a ni filtre ni etoile |
|
| 308 | + // ALORS retourner la couleur. |
|
| 309 | + // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 310 | + if (preg_match("/^[A-F]{1,6}$/i", $nom) |
|
| 311 | + AND !$p->etoile |
|
| 312 | + AND !$p->fonctions) { |
|
| 313 | + $p->code = "'#$nom'"; |
|
| 314 | + $p->interdire_scripts = false; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + return $p; |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | |
@@ -334,32 +334,32 @@ discard block |
||
| 334 | 334 | // http://doc.spip.org/@calculer_balise_dynamique |
| 335 | 335 | function calculer_balise_dynamique($p, $nom, $l, $supp=array()) { |
| 336 | 336 | |
| 337 | - if (!balise_distante_interdite($p)) { |
|
| 338 | - $p->code = "''"; |
|
| 339 | - return $p; |
|
| 340 | - } |
|
| 341 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 342 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 343 | - if ($p->fonctions AND (!$p->fonctions[0][0]) AND $p->fonctions[0][1]) { |
|
| 344 | - $p->fonctions = null; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - if ($p->param AND ($c = $p->param[0])) { |
|
| 348 | - // liste d'arguments commence toujours par la chaine vide |
|
| 349 | - array_shift($c); |
|
| 350 | - // construire la liste d'arguments comme pour un filtre |
|
| 351 | - $param = compose_filtres_args($p, $c, ','); |
|
| 352 | - } else $param = ""; |
|
| 353 | - $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 354 | - |
|
| 355 | - $p->code = sprintf(CODE_EXECUTER_BALISE, $nom, |
|
| 356 | - join(',', $collecte), |
|
| 357 | - ($collecte ? $param : substr($param,1)), # virer la virgule |
|
| 358 | - memoriser_contexte_compil($p), |
|
| 359 | - (!$supp ? '' : (', ' . join(',', $supp)))); |
|
| 360 | - |
|
| 361 | - $p->interdire_scripts = false; |
|
| 362 | - return $p; |
|
| 337 | + if (!balise_distante_interdite($p)) { |
|
| 338 | + $p->code = "''"; |
|
| 339 | + return $p; |
|
| 340 | + } |
|
| 341 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 342 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 343 | + if ($p->fonctions AND (!$p->fonctions[0][0]) AND $p->fonctions[0][1]) { |
|
| 344 | + $p->fonctions = null; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + if ($p->param AND ($c = $p->param[0])) { |
|
| 348 | + // liste d'arguments commence toujours par la chaine vide |
|
| 349 | + array_shift($c); |
|
| 350 | + // construire la liste d'arguments comme pour un filtre |
|
| 351 | + $param = compose_filtres_args($p, $c, ','); |
|
| 352 | + } else $param = ""; |
|
| 353 | + $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 354 | + |
|
| 355 | + $p->code = sprintf(CODE_EXECUTER_BALISE, $nom, |
|
| 356 | + join(',', $collecte), |
|
| 357 | + ($collecte ? $param : substr($param,1)), # virer la virgule |
|
| 358 | + memoriser_contexte_compil($p), |
|
| 359 | + (!$supp ? '' : (', ' . join(',', $supp)))); |
|
| 360 | + |
|
| 361 | + $p->interdire_scripts = false; |
|
| 362 | + return $p; |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | // Construction du tableau des arguments d'une balise dynamique. |
@@ -370,9 +370,9 @@ discard block |
||
| 370 | 370 | |
| 371 | 371 | // http://doc.spip.org/@collecter_balise_dynamique |
| 372 | 372 | function collecter_balise_dynamique($l, &$p, $nom) { |
| 373 | - $args = array(); |
|
| 374 | - foreach($l as $c) { $x = calculer_balise($c, $p); $args[] = $x->code;} |
|
| 375 | - return $args; |
|
| 373 | + $args = array(); |
|
| 374 | + foreach($l as $c) { $x = calculer_balise($c, $p); $args[] = $x->code;} |
|
| 375 | + return $args; |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | |
@@ -389,17 +389,17 @@ discard block |
||
| 389 | 389 | * Nom de la connexion |
| 390 | 390 | **/ |
| 391 | 391 | function trouver_nom_serveur_distant($p) { |
| 392 | - $nom = $p->id_boucle; |
|
| 393 | - if ($nom |
|
| 394 | - AND isset($p->boucles[$nom])) { |
|
| 395 | - $s = $p->boucles[$nom]->sql_serveur; |
|
| 396 | - if (strlen($s) |
|
| 397 | - AND strlen($serveur = strtolower($s)) |
|
| 398 | - AND !in_array($serveur,$GLOBALS['exception_des_connect'])) { |
|
| 399 | - return $serveur; |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - return ""; |
|
| 392 | + $nom = $p->id_boucle; |
|
| 393 | + if ($nom |
|
| 394 | + AND isset($p->boucles[$nom])) { |
|
| 395 | + $s = $p->boucles[$nom]->sql_serveur; |
|
| 396 | + if (strlen($s) |
|
| 397 | + AND strlen($serveur = strtolower($s)) |
|
| 398 | + AND !in_array($serveur,$GLOBALS['exception_des_connect'])) { |
|
| 399 | + return $serveur; |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + return ""; |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | |
@@ -422,13 +422,13 @@ discard block |
||
| 422 | 422 | * - false : La balise est interdite car le serveur est distant |
| 423 | 423 | **/ |
| 424 | 424 | function balise_distante_interdite($p) { |
| 425 | - $nom = $p->id_boucle; |
|
| 425 | + $nom = $p->id_boucle; |
|
| 426 | 426 | |
| 427 | - if ($nom AND trouver_nom_serveur_distant($p)) { |
|
| 428 | - spip_log( $nom .':' . $p->nom_champ .' '._T('zbug_distant_interdit')); |
|
| 429 | - return false; |
|
| 430 | - } |
|
| 431 | - return true; |
|
| 427 | + if ($nom AND trouver_nom_serveur_distant($p)) { |
|
| 428 | + spip_log( $nom .':' . $p->nom_champ .' '._T('zbug_distant_interdit')); |
|
| 429 | + return false; |
|
| 430 | + } |
|
| 431 | + return true; |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | |
@@ -438,63 +438,63 @@ discard block |
||
| 438 | 438 | // |
| 439 | 439 | // http://doc.spip.org/@champs_traitements |
| 440 | 440 | function champs_traitements ($p) { |
| 441 | - global $table_des_traitements; |
|
| 442 | - |
|
| 443 | - if (isset($table_des_traitements[$p->nom_champ])) |
|
| 444 | - $ps = $table_des_traitements[$p->nom_champ]; |
|
| 445 | - else { |
|
| 446 | - // quand on utilise un traitement catch-all * |
|
| 447 | - // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 448 | - // leur propre securite |
|
| 449 | - if (!$p->balise_calculee) |
|
| 450 | - $ps = $table_des_traitements['*']; |
|
| 451 | - else |
|
| 452 | - $ps = false; |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - if (is_array($ps)) { |
|
| 456 | - // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 457 | - $idb = index_boucle($p); |
|
| 458 | - // mais on peut aussi etre hors boucle. Se mefier. |
|
| 459 | - $type_requete = isset($p->boucles[$idb]->type_requete) ? $p->boucles[$idb]->type_requete : false; |
|
| 460 | - $table_sql = isset($p->boucles[$idb]->show['table_sql'])?$p->boucles[$idb]->show['table_sql']:false; |
|
| 461 | - |
|
| 462 | - // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 463 | - if ($table_sql AND isset($ps[$table_sql])) |
|
| 464 | - $ps = $ps[$table_sql]; |
|
| 465 | - // ou pour une boucle en particulier "DATA","articles" |
|
| 466 | - elseif ($type_requete AND isset($ps[$type_requete])) |
|
| 467 | - $ps = $ps[$type_requete]; |
|
| 468 | - // ou pour indiferrement quelle que soit la boucle |
|
| 469 | - elseif(isset($ps[0])) |
|
| 470 | - $ps = $ps[0]; |
|
| 471 | - else |
|
| 472 | - $ps=false; |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - if (!$ps) return $p->code; |
|
| 476 | - |
|
| 477 | - // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 478 | - // ou si in INCLURE contient {doublons} |
|
| 479 | - // on insere une fonction de remplissage du tableau des doublons |
|
| 480 | - // dans les filtres propre() ou typo() |
|
| 481 | - // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 482 | - |
|
| 483 | - if (isset($p->descr['documents']) |
|
| 484 | - AND |
|
| 485 | - $p->descr['documents'] |
|
| 486 | - AND ( |
|
| 487 | - (strpos($ps,'propre') !== false) |
|
| 488 | - OR |
|
| 489 | - (strpos($ps,'typo') !== false) |
|
| 490 | - )) |
|
| 491 | - $ps = 'traiter_doublons_documents($doublons, '.$ps.')'; |
|
| 492 | - |
|
| 493 | - // La protection des champs par |safehtml est assuree par les extensions |
|
| 494 | - // dans la declaration des traitements des champs sensibles |
|
| 495 | - |
|
| 496 | - // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 497 | - return str_replace('%s', $p->code, $ps); |
|
| 441 | + global $table_des_traitements; |
|
| 442 | + |
|
| 443 | + if (isset($table_des_traitements[$p->nom_champ])) |
|
| 444 | + $ps = $table_des_traitements[$p->nom_champ]; |
|
| 445 | + else { |
|
| 446 | + // quand on utilise un traitement catch-all * |
|
| 447 | + // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 448 | + // leur propre securite |
|
| 449 | + if (!$p->balise_calculee) |
|
| 450 | + $ps = $table_des_traitements['*']; |
|
| 451 | + else |
|
| 452 | + $ps = false; |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + if (is_array($ps)) { |
|
| 456 | + // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 457 | + $idb = index_boucle($p); |
|
| 458 | + // mais on peut aussi etre hors boucle. Se mefier. |
|
| 459 | + $type_requete = isset($p->boucles[$idb]->type_requete) ? $p->boucles[$idb]->type_requete : false; |
|
| 460 | + $table_sql = isset($p->boucles[$idb]->show['table_sql'])?$p->boucles[$idb]->show['table_sql']:false; |
|
| 461 | + |
|
| 462 | + // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 463 | + if ($table_sql AND isset($ps[$table_sql])) |
|
| 464 | + $ps = $ps[$table_sql]; |
|
| 465 | + // ou pour une boucle en particulier "DATA","articles" |
|
| 466 | + elseif ($type_requete AND isset($ps[$type_requete])) |
|
| 467 | + $ps = $ps[$type_requete]; |
|
| 468 | + // ou pour indiferrement quelle que soit la boucle |
|
| 469 | + elseif(isset($ps[0])) |
|
| 470 | + $ps = $ps[0]; |
|
| 471 | + else |
|
| 472 | + $ps=false; |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + if (!$ps) return $p->code; |
|
| 476 | + |
|
| 477 | + // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 478 | + // ou si in INCLURE contient {doublons} |
|
| 479 | + // on insere une fonction de remplissage du tableau des doublons |
|
| 480 | + // dans les filtres propre() ou typo() |
|
| 481 | + // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 482 | + |
|
| 483 | + if (isset($p->descr['documents']) |
|
| 484 | + AND |
|
| 485 | + $p->descr['documents'] |
|
| 486 | + AND ( |
|
| 487 | + (strpos($ps,'propre') !== false) |
|
| 488 | + OR |
|
| 489 | + (strpos($ps,'typo') !== false) |
|
| 490 | + )) |
|
| 491 | + $ps = 'traiter_doublons_documents($doublons, '.$ps.')'; |
|
| 492 | + |
|
| 493 | + // La protection des champs par |safehtml est assuree par les extensions |
|
| 494 | + // dans la declaration des traitements des champs sensibles |
|
| 495 | + |
|
| 496 | + // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 497 | + return str_replace('%s', $p->code, $ps); |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | |
@@ -507,98 +507,98 @@ discard block |
||
| 507 | 507 | // http://doc.spip.org/@applique_filtres |
| 508 | 508 | function applique_filtres($p) { |
| 509 | 509 | |
| 510 | - // Traitements standards (cf. supra) |
|
| 511 | - if ($p->etoile == '') |
|
| 512 | - $code = champs_traitements($p); |
|
| 513 | - else |
|
| 514 | - $code = $p->code; |
|
| 510 | + // Traitements standards (cf. supra) |
|
| 511 | + if ($p->etoile == '') |
|
| 512 | + $code = champs_traitements($p); |
|
| 513 | + else |
|
| 514 | + $code = $p->code; |
|
| 515 | 515 | |
| 516 | - // Appliquer les filtres perso |
|
| 517 | - if ($p->param) |
|
| 518 | - $code = compose_filtres($p, $code); |
|
| 516 | + // Appliquer les filtres perso |
|
| 517 | + if ($p->param) |
|
| 518 | + $code = compose_filtres($p, $code); |
|
| 519 | 519 | |
| 520 | - // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 521 | - // un drapeau dans la structure d'invalidation $Cache |
|
| 522 | - if (isset($p->descr['session'])) |
|
| 523 | - $code = "invalideur_session(\$Cache, $code)"; |
|
| 520 | + // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 521 | + // un drapeau dans la structure d'invalidation $Cache |
|
| 522 | + if (isset($p->descr['session'])) |
|
| 523 | + $code = "invalideur_session(\$Cache, $code)"; |
|
| 524 | 524 | |
| 525 | - $code = sandbox_composer_interdire_scripts($code, $p); |
|
| 526 | - return $code; |
|
| 525 | + $code = sandbox_composer_interdire_scripts($code, $p); |
|
| 526 | + return $code; |
|
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | // Cf. function pipeline dans ecrire/inc_utils.php |
| 530 | 530 | // http://doc.spip.org/@compose_filtres |
| 531 | 531 | function compose_filtres(&$p, $code) { |
| 532 | 532 | |
| 533 | - $image_miette = false; |
|
| 534 | - foreach($p->param as $filtre) { |
|
| 535 | - $fonc = array_shift($filtre); |
|
| 536 | - if (!$fonc) continue; // normalement qu'au premier tour. |
|
| 537 | - $is_filtre_image = ((substr($fonc,0,6)=='image_') AND $fonc!='image_graver'); |
|
| 538 | - if ($image_miette AND !$is_filtre_image){ |
|
| 539 | - // il faut graver maintenant car apres le filtre en cours |
|
| 540 | - // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 541 | - $code = "filtrer('image_graver', $code)"; |
|
| 542 | - $image_miette = false; |
|
| 543 | - } |
|
| 544 | - // recuperer les arguments du filtre, |
|
| 545 | - // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 546 | - if ($fonc !== '?') { |
|
| 547 | - $sep = ','; |
|
| 548 | - } else {$sep = ':'; |
|
| 549 | - // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 550 | - if (count($filtre) != 2) |
|
| 551 | - $filtre = array(isset($filtre[0])?$filtre[0]:"", isset($filtre[1])?$filtre[1]:""); |
|
| 552 | - } |
|
| 553 | - $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 554 | - $logique = filtre_logique($fonc, $code, substr($arglist,1)); |
|
| 555 | - if ($logique) |
|
| 556 | - $code = $logique; |
|
| 557 | - else { |
|
| 558 | - $code = sandbox_composer_filtre($fonc,$code,$arglist,$p); |
|
| 559 | - if ($is_filtre_image) $image_miette = true; |
|
| 560 | - } |
|
| 561 | - } |
|
| 562 | - // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 563 | - if ($image_miette) |
|
| 564 | - $code = "filtrer('image_graver',$code)"; |
|
| 565 | - |
|
| 566 | - return $code; |
|
| 533 | + $image_miette = false; |
|
| 534 | + foreach($p->param as $filtre) { |
|
| 535 | + $fonc = array_shift($filtre); |
|
| 536 | + if (!$fonc) continue; // normalement qu'au premier tour. |
|
| 537 | + $is_filtre_image = ((substr($fonc,0,6)=='image_') AND $fonc!='image_graver'); |
|
| 538 | + if ($image_miette AND !$is_filtre_image){ |
|
| 539 | + // il faut graver maintenant car apres le filtre en cours |
|
| 540 | + // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 541 | + $code = "filtrer('image_graver', $code)"; |
|
| 542 | + $image_miette = false; |
|
| 543 | + } |
|
| 544 | + // recuperer les arguments du filtre, |
|
| 545 | + // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 546 | + if ($fonc !== '?') { |
|
| 547 | + $sep = ','; |
|
| 548 | + } else {$sep = ':'; |
|
| 549 | + // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 550 | + if (count($filtre) != 2) |
|
| 551 | + $filtre = array(isset($filtre[0])?$filtre[0]:"", isset($filtre[1])?$filtre[1]:""); |
|
| 552 | + } |
|
| 553 | + $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 554 | + $logique = filtre_logique($fonc, $code, substr($arglist,1)); |
|
| 555 | + if ($logique) |
|
| 556 | + $code = $logique; |
|
| 557 | + else { |
|
| 558 | + $code = sandbox_composer_filtre($fonc,$code,$arglist,$p); |
|
| 559 | + if ($is_filtre_image) $image_miette = true; |
|
| 560 | + } |
|
| 561 | + } |
|
| 562 | + // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 563 | + if ($image_miette) |
|
| 564 | + $code = "filtrer('image_graver',$code)"; |
|
| 565 | + |
|
| 566 | + return $code; |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | // Filtres et,ou,oui,non,sinon,xou,xor,and,or,not,yes |
| 570 | 570 | // et comparateurs |
| 571 | 571 | function filtre_logique($fonc, $code, $arg) |
| 572 | 572 | { |
| 573 | - global $table_criteres_infixes; |
|
| 574 | - switch (true) { |
|
| 575 | - case in_array($fonc, $table_criteres_infixes): |
|
| 576 | - return "($code $fonc $arg)"; |
|
| 577 | - case ($fonc == 'and') OR ($fonc == 'et'): |
|
| 578 | - return "((($code) AND ($arg)) ?' ' :'')"; |
|
| 579 | - case ($fonc == 'or') OR ($fonc == 'ou'): |
|
| 580 | - return "((($code) OR ($arg)) ?' ' :'')"; |
|
| 581 | - case ($fonc == 'xor') OR ($fonc == 'xou'): |
|
| 582 | - return "((($code) XOR ($arg)) ?' ' :'')"; |
|
| 583 | - case ($fonc == 'sinon'): |
|
| 584 | - return "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)"; |
|
| 585 | - case ($fonc == 'not') OR ($fonc == 'non'): |
|
| 586 | - return "(($code) ?'' :' ')"; |
|
| 587 | - case ($fonc == 'yes') OR ($fonc == 'oui'): |
|
| 588 | - return "(($code) ?' ' :'')"; |
|
| 589 | - } |
|
| 590 | - return ''; |
|
| 573 | + global $table_criteres_infixes; |
|
| 574 | + switch (true) { |
|
| 575 | + case in_array($fonc, $table_criteres_infixes): |
|
| 576 | + return "($code $fonc $arg)"; |
|
| 577 | + case ($fonc == 'and') OR ($fonc == 'et'): |
|
| 578 | + return "((($code) AND ($arg)) ?' ' :'')"; |
|
| 579 | + case ($fonc == 'or') OR ($fonc == 'ou'): |
|
| 580 | + return "((($code) OR ($arg)) ?' ' :'')"; |
|
| 581 | + case ($fonc == 'xor') OR ($fonc == 'xou'): |
|
| 582 | + return "((($code) XOR ($arg)) ?' ' :'')"; |
|
| 583 | + case ($fonc == 'sinon'): |
|
| 584 | + return "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)"; |
|
| 585 | + case ($fonc == 'not') OR ($fonc == 'non'): |
|
| 586 | + return "(($code) ?'' :' ')"; |
|
| 587 | + case ($fonc == 'yes') OR ($fonc == 'oui'): |
|
| 588 | + return "(($code) ?' ' :'')"; |
|
| 589 | + } |
|
| 590 | + return ''; |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | // http://doc.spip.org/@compose_filtres_args |
| 594 | 594 | function compose_filtres_args($p, $args, $sep) |
| 595 | 595 | { |
| 596 | - $arglist = ""; |
|
| 597 | - foreach ($args as $arg) { |
|
| 598 | - $arglist .= $sep . |
|
| 599 | - calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 600 | - } |
|
| 601 | - return $arglist; |
|
| 596 | + $arglist = ""; |
|
| 597 | + foreach ($args as $arg) { |
|
| 598 | + $arglist .= $sep . |
|
| 599 | + calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 600 | + } |
|
| 601 | + return $arglist; |
|
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | // |
@@ -609,15 +609,15 @@ discard block |
||
| 609 | 609 | // http://doc.spip.org/@calculer_argument_precedent |
| 610 | 610 | function calculer_argument_precedent($idb, $nom_champ, &$boucles, $defaut=null) { |
| 611 | 611 | |
| 612 | - // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 613 | - if ($boucles[$idb]->externe) { |
|
| 614 | - index_pile ($idb, $nom_champ, $boucles,'', $defaut); |
|
| 615 | - // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 616 | - // on ignore le defaut fourni dans ce cas |
|
| 617 | - $defaut = "@\$Pile[\$SP]['$nom_champ']"; |
|
| 618 | - } |
|
| 612 | + // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 613 | + if ($boucles[$idb]->externe) { |
|
| 614 | + index_pile ($idb, $nom_champ, $boucles,'', $defaut); |
|
| 615 | + // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 616 | + // on ignore le defaut fourni dans ce cas |
|
| 617 | + $defaut = "@\$Pile[\$SP]['$nom_champ']"; |
|
| 618 | + } |
|
| 619 | 619 | |
| 620 | - return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles,'', $defaut); |
|
| 620 | + return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles,'', $defaut); |
|
| 621 | 621 | } |
| 622 | 622 | |
| 623 | 623 | // |
@@ -633,28 +633,28 @@ discard block |
||
| 633 | 633 | // http://doc.spip.org/@rindex_pile |
| 634 | 634 | function rindex_pile($p, $champ, $motif) |
| 635 | 635 | { |
| 636 | - $n = 0; |
|
| 637 | - $b = $p->id_boucle; |
|
| 638 | - $p->code = ''; |
|
| 639 | - while ($b != '') { |
|
| 640 | - foreach($p->boucles[$b]->criteres as $critere) { |
|
| 641 | - if ($critere->op == $motif) { |
|
| 642 | - $p->code = '$Pile[$SP' . (($n==0) ? "" : "-$n") . |
|
| 643 | - "]['$champ']"; |
|
| 644 | - $b = ''; |
|
| 645 | - break 2; |
|
| 646 | - } |
|
| 647 | - } |
|
| 648 | - $n++; |
|
| 649 | - $b = $p->boucles[$b]->id_parent; |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 653 | - if (!$p->code) |
|
| 654 | - $p->code = "''"; |
|
| 655 | - |
|
| 656 | - $p->interdire_scripts = false; |
|
| 657 | - return $p; |
|
| 636 | + $n = 0; |
|
| 637 | + $b = $p->id_boucle; |
|
| 638 | + $p->code = ''; |
|
| 639 | + while ($b != '') { |
|
| 640 | + foreach($p->boucles[$b]->criteres as $critere) { |
|
| 641 | + if ($critere->op == $motif) { |
|
| 642 | + $p->code = '$Pile[$SP' . (($n==0) ? "" : "-$n") . |
|
| 643 | + "]['$champ']"; |
|
| 644 | + $b = ''; |
|
| 645 | + break 2; |
|
| 646 | + } |
|
| 647 | + } |
|
| 648 | + $n++; |
|
| 649 | + $b = $p->boucles[$b]->id_parent; |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 653 | + if (!$p->code) |
|
| 654 | + $p->code = "''"; |
|
| 655 | + |
|
| 656 | + $p->interdire_scripts = false; |
|
| 657 | + return $p; |
|
| 658 | 658 | } |
| 659 | 659 | |
| 660 | 660 | ?> |
@@ -27,14 +27,14 @@ discard block |
||
| 27 | 27 | * @param Object $p |
| 28 | 28 | * @return string |
| 29 | 29 | */ |
| 30 | -function index_boucle($p){ |
|
| 30 | +function index_boucle($p) { |
|
| 31 | 31 | |
| 32 | 32 | $idb = $p->id_boucle; |
| 33 | 33 | $explicite = $p->nom_boucle; |
| 34 | 34 | |
| 35 | 35 | if (strlen($explicite)) { |
| 36 | 36 | // Recherche d'un champ dans un etage superieur |
| 37 | - while (($idb !== $explicite) && ($idb !=='')) { |
|
| 37 | + while (($idb !== $explicite) && ($idb !== '')) { |
|
| 38 | 38 | $idb = $p->boucles[$idb]->id_parent; |
| 39 | 39 | } |
| 40 | 40 | } |
@@ -64,14 +64,14 @@ discard block |
||
| 64 | 64 | * permettre de remonter la pile des boucles ou non (dans ce cas on ne cherche que ds la 1ere boucle englobante) |
| 65 | 65 | * @return string |
| 66 | 66 | */ |
| 67 | -function index_pile($idb, $nom_champ, &$boucles, $explicite='', $defaut=null, $remonte_pile=true) { |
|
| 67 | +function index_pile($idb, $nom_champ, &$boucles, $explicite = '', $defaut = null, $remonte_pile = true) { |
|
| 68 | 68 | if (!is_string($defaut)) |
| 69 | - $defaut = '@$Pile[0][\''. strtolower($nom_champ) . '\']'; |
|
| 69 | + $defaut = '@$Pile[0][\''.strtolower($nom_champ).'\']'; |
|
| 70 | 70 | |
| 71 | 71 | $i = 0; |
| 72 | 72 | if (strlen($explicite)) { |
| 73 | 73 | // Recherche d'un champ dans un etage superieur |
| 74 | - while (($idb !== $explicite) && ($idb !=='')) { |
|
| 74 | + while (($idb !== $explicite) && ($idb !== '')) { |
|
| 75 | 75 | # spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'"); |
| 76 | 76 | $i++; |
| 77 | 77 | $idb = $boucles[$idb]->id_parent; |
@@ -90,14 +90,14 @@ discard block |
||
| 90 | 90 | if (!in_array($t, $boucles[$idb]->select)) { |
| 91 | 91 | $boucles[$idb]->select[] = $t; |
| 92 | 92 | } |
| 93 | - $champ = '$Pile[$SP' . ($i ? "-$i" : "") . '][\'' . $c . '\']'; |
|
| 93 | + $champ = '$Pile[$SP'.($i ? "-$i" : "").'][\''.$c.'\']'; |
|
| 94 | 94 | if (!$joker) |
| 95 | - return index_compose($conditionnel,$champ); |
|
| 95 | + return index_compose($conditionnel, $champ); |
|
| 96 | 96 | |
| 97 | 97 | $conditionnel[] = "isset($champ)?$champ"; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - if ($remonte_pile){ |
|
| 100 | + if ($remonte_pile) { |
|
| 101 | 101 | # spip_log("On remonte vers $i"); |
| 102 | 102 | // Sinon on remonte d'un cran |
| 103 | 103 | $idb = $boucles[$idb]->id_parent; |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | # spip_log("Pas vu $nom_champ"); |
| 111 | 111 | // esperons qu'il y sera |
| 112 | 112 | // on qu'on a fourni une valeur par "defaut" plus pertinent |
| 113 | - return index_compose($conditionnel,$defaut); |
|
| 113 | + return index_compose($conditionnel, $defaut); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -122,10 +122,10 @@ discard block |
||
| 122 | 122 | * @param string $defaut |
| 123 | 123 | * @return string |
| 124 | 124 | */ |
| 125 | -function index_compose($conditionnel,$defaut){ |
|
| 125 | +function index_compose($conditionnel, $defaut) { |
|
| 126 | 126 | while ($c = array_pop($conditionnel)) |
| 127 | 127 | // si on passe defaut = '', ne pas générer d'erreur de compilation. |
| 128 | - $defaut = "($c:(".($defaut?$defaut:"''")."))"; |
|
| 128 | + $defaut = "($c:(".($defaut ? $defaut : "''")."))"; |
|
| 129 | 129 | return $defaut; |
| 130 | 130 | } |
| 131 | 131 | |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | if (!$r) { |
| 140 | 140 | $joker = false; // indiquer a l'appelant |
| 141 | 141 | # continuer pour chercher l'erreur suivante |
| 142 | - return array("'#" . $r . ':' . $nom_champ . "'",''); |
|
| 142 | + return array("'#".$r.':'.$nom_champ."'", ''); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | $desc = $boucles[$idb]->show; |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | $nom_champ, |
| 174 | 174 | array($t[1]['id_table'], $nom_champ)); |
| 175 | 175 | } |
| 176 | - return array('',''); |
|
| 176 | + return array('', ''); |
|
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | } |
@@ -192,24 +192,24 @@ discard block |
||
| 192 | 192 | if (is_array($excep)) { |
| 193 | 193 | // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
| 194 | 194 | $t = NULL; |
| 195 | - if (count($excep)==3){ |
|
| 195 | + if (count($excep) == 3) { |
|
| 196 | 196 | $index_exception_derogatoire = array_pop($excep); |
| 197 | 197 | $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
| 198 | 198 | } |
| 199 | 199 | if ($t == NULL) { |
| 200 | - list($e, $x) = $excep; #PHP4 affecte de gauche a droite |
|
| 201 | - $excep = $x; #PHP5 de droite a gauche ! |
|
| 200 | + list($e, $x) = $excep; #PHP4 affecte de gauche a droite |
|
| 201 | + $excep = $x; #PHP5 de droite a gauche ! |
|
| 202 | 202 | $j = $trouver_table($e, $boucle->sql_serveur); |
| 203 | - if (!$j) return array('',''); |
|
| 203 | + if (!$j) return array('', ''); |
|
| 204 | 204 | $e = $j['table']; |
| 205 | 205 | if (!$t = array_search($e, $boucle->from)) { |
| 206 | 206 | $k = $j['key']['PRIMARY KEY']; |
| 207 | - if (strpos($k,',')) { |
|
| 207 | + if (strpos($k, ',')) { |
|
| 208 | 208 | $l = (preg_split('/\s*,\s*/', $k)); |
| 209 | 209 | $k = $desc['key']['PRIMARY KEY']; |
| 210 | 210 | if (!in_array($k, $l)) { |
| 211 | - spip_log("jointure impossible $e " . join(',', $l)); |
|
| 212 | - return array('',''); |
|
| 211 | + spip_log("jointure impossible $e ".join(',', $l)); |
|
| 212 | + return array('', ''); |
|
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | 215 | $k = array($boucle->id_table, array($e), $k); |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | else $t = $boucle->id_table; |
| 222 | 222 | // demander a SQL de gerer le synonyme |
| 223 | 223 | // ca permet que excep soit dynamique (Cedric, 2/3/06) |
| 224 | - if ($excep != $nom_champ) $excep .= ' AS '. $nom_champ; |
|
| 224 | + if ($excep != $nom_champ) $excep .= ' AS '.$nom_champ; |
|
| 225 | 225 | return array("$t.$excep", $nom_champ); |
| 226 | 226 | } |
| 227 | 227 | |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | |
| 275 | 275 | // Certaines des balises comportant un _ sont generiques |
| 276 | 276 | if ($f = strpos($nom, '_') |
| 277 | - AND $f = charger_fonction(substr($nom,0,$f+1), 'balise', true)) { |
|
| 277 | + AND $f = charger_fonction(substr($nom, 0, $f + 1), 'balise', true)) { |
|
| 278 | 278 | $res = $f($p); |
| 279 | 279 | if ($res !== NULL) |
| 280 | 280 | return $res; |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | array(%s%s))"); |
| 333 | 333 | |
| 334 | 334 | // http://doc.spip.org/@calculer_balise_dynamique |
| 335 | -function calculer_balise_dynamique($p, $nom, $l, $supp=array()) { |
|
| 335 | +function calculer_balise_dynamique($p, $nom, $l, $supp = array()) { |
|
| 336 | 336 | |
| 337 | 337 | if (!balise_distante_interdite($p)) { |
| 338 | 338 | $p->code = "''"; |
@@ -354,9 +354,9 @@ discard block |
||
| 354 | 354 | |
| 355 | 355 | $p->code = sprintf(CODE_EXECUTER_BALISE, $nom, |
| 356 | 356 | join(',', $collecte), |
| 357 | - ($collecte ? $param : substr($param,1)), # virer la virgule |
|
| 357 | + ($collecte ? $param : substr($param, 1)), # virer la virgule |
|
| 358 | 358 | memoriser_contexte_compil($p), |
| 359 | - (!$supp ? '' : (', ' . join(',', $supp)))); |
|
| 359 | + (!$supp ? '' : (', '.join(',', $supp)))); |
|
| 360 | 360 | |
| 361 | 361 | $p->interdire_scripts = false; |
| 362 | 362 | return $p; |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | // http://doc.spip.org/@collecter_balise_dynamique |
| 372 | 372 | function collecter_balise_dynamique($l, &$p, $nom) { |
| 373 | 373 | $args = array(); |
| 374 | - foreach($l as $c) { $x = calculer_balise($c, $p); $args[] = $x->code;} |
|
| 374 | + foreach ($l as $c) { $x = calculer_balise($c, $p); $args[] = $x->code; } |
|
| 375 | 375 | return $args; |
| 376 | 376 | } |
| 377 | 377 | |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | $s = $p->boucles[$nom]->sql_serveur; |
| 396 | 396 | if (strlen($s) |
| 397 | 397 | AND strlen($serveur = strtolower($s)) |
| 398 | - AND !in_array($serveur,$GLOBALS['exception_des_connect'])) { |
|
| 398 | + AND !in_array($serveur, $GLOBALS['exception_des_connect'])) { |
|
| 399 | 399 | return $serveur; |
| 400 | 400 | } |
| 401 | 401 | } |
@@ -425,7 +425,7 @@ discard block |
||
| 425 | 425 | $nom = $p->id_boucle; |
| 426 | 426 | |
| 427 | 427 | if ($nom AND trouver_nom_serveur_distant($p)) { |
| 428 | - spip_log( $nom .':' . $p->nom_champ .' '._T('zbug_distant_interdit')); |
|
| 428 | + spip_log($nom.':'.$p->nom_champ.' '._T('zbug_distant_interdit')); |
|
| 429 | 429 | return false; |
| 430 | 430 | } |
| 431 | 431 | return true; |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | // definis par $table_des_traitements, cf. ecrire/public/interfaces |
| 438 | 438 | // |
| 439 | 439 | // http://doc.spip.org/@champs_traitements |
| 440 | -function champs_traitements ($p) { |
|
| 440 | +function champs_traitements($p) { |
|
| 441 | 441 | global $table_des_traitements; |
| 442 | 442 | |
| 443 | 443 | if (isset($table_des_traitements[$p->nom_champ])) |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | $idb = index_boucle($p); |
| 458 | 458 | // mais on peut aussi etre hors boucle. Se mefier. |
| 459 | 459 | $type_requete = isset($p->boucles[$idb]->type_requete) ? $p->boucles[$idb]->type_requete : false; |
| 460 | - $table_sql = isset($p->boucles[$idb]->show['table_sql'])?$p->boucles[$idb]->show['table_sql']:false; |
|
| 460 | + $table_sql = isset($p->boucles[$idb]->show['table_sql']) ? $p->boucles[$idb]->show['table_sql'] : false; |
|
| 461 | 461 | |
| 462 | 462 | // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
| 463 | 463 | if ($table_sql AND isset($ps[$table_sql])) |
@@ -466,10 +466,10 @@ discard block |
||
| 466 | 466 | elseif ($type_requete AND isset($ps[$type_requete])) |
| 467 | 467 | $ps = $ps[$type_requete]; |
| 468 | 468 | // ou pour indiferrement quelle que soit la boucle |
| 469 | - elseif(isset($ps[0])) |
|
| 469 | + elseif (isset($ps[0])) |
|
| 470 | 470 | $ps = $ps[0]; |
| 471 | 471 | else |
| 472 | - $ps=false; |
|
| 472 | + $ps = false; |
|
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | if (!$ps) return $p->code; |
@@ -484,9 +484,9 @@ discard block |
||
| 484 | 484 | AND |
| 485 | 485 | $p->descr['documents'] |
| 486 | 486 | AND ( |
| 487 | - (strpos($ps,'propre') !== false) |
|
| 487 | + (strpos($ps, 'propre') !== false) |
|
| 488 | 488 | OR |
| 489 | - (strpos($ps,'typo') !== false) |
|
| 489 | + (strpos($ps, 'typo') !== false) |
|
| 490 | 490 | )) |
| 491 | 491 | $ps = 'traiter_doublons_documents($doublons, '.$ps.')'; |
| 492 | 492 | |
@@ -531,11 +531,11 @@ discard block |
||
| 531 | 531 | function compose_filtres(&$p, $code) { |
| 532 | 532 | |
| 533 | 533 | $image_miette = false; |
| 534 | - foreach($p->param as $filtre) { |
|
| 534 | + foreach ($p->param as $filtre) { |
|
| 535 | 535 | $fonc = array_shift($filtre); |
| 536 | 536 | if (!$fonc) continue; // normalement qu'au premier tour. |
| 537 | - $is_filtre_image = ((substr($fonc,0,6)=='image_') AND $fonc!='image_graver'); |
|
| 538 | - if ($image_miette AND !$is_filtre_image){ |
|
| 537 | + $is_filtre_image = ((substr($fonc, 0, 6) == 'image_') AND $fonc != 'image_graver'); |
|
| 538 | + if ($image_miette AND !$is_filtre_image) { |
|
| 539 | 539 | // il faut graver maintenant car apres le filtre en cours |
| 540 | 540 | // on est pas sur d'avoir encore le nom du fichier dans le pipe |
| 541 | 541 | $code = "filtrer('image_graver', $code)"; |
@@ -548,14 +548,14 @@ discard block |
||
| 548 | 548 | } else {$sep = ':'; |
| 549 | 549 | // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
| 550 | 550 | if (count($filtre) != 2) |
| 551 | - $filtre = array(isset($filtre[0])?$filtre[0]:"", isset($filtre[1])?$filtre[1]:""); |
|
| 551 | + $filtre = array(isset($filtre[0]) ? $filtre[0] : "", isset($filtre[1]) ? $filtre[1] : ""); |
|
| 552 | 552 | } |
| 553 | 553 | $arglist = compose_filtres_args($p, $filtre, $sep); |
| 554 | - $logique = filtre_logique($fonc, $code, substr($arglist,1)); |
|
| 554 | + $logique = filtre_logique($fonc, $code, substr($arglist, 1)); |
|
| 555 | 555 | if ($logique) |
| 556 | 556 | $code = $logique; |
| 557 | 557 | else { |
| 558 | - $code = sandbox_composer_filtre($fonc,$code,$arglist,$p); |
|
| 558 | + $code = sandbox_composer_filtre($fonc, $code, $arglist, $p); |
|
| 559 | 559 | if ($is_filtre_image) $image_miette = true; |
| 560 | 560 | } |
| 561 | 561 | } |
@@ -595,7 +595,7 @@ discard block |
||
| 595 | 595 | { |
| 596 | 596 | $arglist = ""; |
| 597 | 597 | foreach ($args as $arg) { |
| 598 | - $arglist .= $sep . |
|
| 598 | + $arglist .= $sep. |
|
| 599 | 599 | calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
| 600 | 600 | } |
| 601 | 601 | return $arglist; |
@@ -607,17 +607,17 @@ discard block |
||
| 607 | 607 | // ET chez sa maman |
| 608 | 608 | // |
| 609 | 609 | // http://doc.spip.org/@calculer_argument_precedent |
| 610 | -function calculer_argument_precedent($idb, $nom_champ, &$boucles, $defaut=null) { |
|
| 610 | +function calculer_argument_precedent($idb, $nom_champ, &$boucles, $defaut = null) { |
|
| 611 | 611 | |
| 612 | 612 | // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
| 613 | 613 | if ($boucles[$idb]->externe) { |
| 614 | - index_pile ($idb, $nom_champ, $boucles,'', $defaut); |
|
| 614 | + index_pile($idb, $nom_champ, $boucles, '', $defaut); |
|
| 615 | 615 | // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
| 616 | 616 | // on ignore le defaut fourni dans ce cas |
| 617 | 617 | $defaut = "@\$Pile[\$SP]['$nom_champ']"; |
| 618 | 618 | } |
| 619 | 619 | |
| 620 | - return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles,'', $defaut); |
|
| 620 | + return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut); |
|
| 621 | 621 | } |
| 622 | 622 | |
| 623 | 623 | // |
@@ -637,9 +637,9 @@ discard block |
||
| 637 | 637 | $b = $p->id_boucle; |
| 638 | 638 | $p->code = ''; |
| 639 | 639 | while ($b != '') { |
| 640 | - foreach($p->boucles[$b]->criteres as $critere) { |
|
| 640 | + foreach ($p->boucles[$b]->criteres as $critere) { |
|
| 641 | 641 | if ($critere->op == $motif) { |
| 642 | - $p->code = '$Pile[$SP' . (($n==0) ? "" : "-$n") . |
|
| 642 | + $p->code = '$Pile[$SP'.(($n == 0) ? "" : "-$n"). |
|
| 643 | 643 | "]['$champ']"; |
| 644 | 644 | $b = ''; |
| 645 | 645 | break 2; |
@@ -13,7 +13,9 @@ discard block |
||
| 13 | 13 | // fonctions de recherche et de reservation |
| 14 | 14 | // dans l'arborescence des boucles |
| 15 | 15 | |
| 16 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 16 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 17 | + return; |
|
| 18 | +} |
|
| 17 | 19 | |
| 18 | 20 | /** |
| 19 | 21 | * Retrouver l'index de la boucle dans le cas ou une reference explicite est demandee |
@@ -65,8 +67,9 @@ discard block |
||
| 65 | 67 | * @return string |
| 66 | 68 | */ |
| 67 | 69 | function index_pile($idb, $nom_champ, &$boucles, $explicite='', $defaut=null, $remonte_pile=true) { |
| 68 | - if (!is_string($defaut)) |
|
| 69 | - $defaut = '@$Pile[0][\''. strtolower($nom_champ) . '\']'; |
|
| 70 | + if (!is_string($defaut)) { |
|
| 71 | + $defaut = '@$Pile[0][\''. strtolower($nom_champ) . '\']'; |
|
| 72 | + } |
|
| 70 | 73 | |
| 71 | 74 | $i = 0; |
| 72 | 75 | if (strlen($explicite)) { |
@@ -91,8 +94,9 @@ discard block |
||
| 91 | 94 | $boucles[$idb]->select[] = $t; |
| 92 | 95 | } |
| 93 | 96 | $champ = '$Pile[$SP' . ($i ? "-$i" : "") . '][\'' . $c . '\']'; |
| 94 | - if (!$joker) |
|
| 95 | - return index_compose($conditionnel,$champ); |
|
| 97 | + if (!$joker) { |
|
| 98 | + return index_compose($conditionnel,$champ); |
|
| 99 | + } |
|
| 96 | 100 | |
| 97 | 101 | $conditionnel[] = "isset($champ)?$champ"; |
| 98 | 102 | } |
@@ -102,9 +106,9 @@ discard block |
||
| 102 | 106 | // Sinon on remonte d'un cran |
| 103 | 107 | $idb = $boucles[$idb]->id_parent; |
| 104 | 108 | $i++; |
| 109 | + } else { |
|
| 110 | + $idb = null; |
|
| 105 | 111 | } |
| 106 | - else |
|
| 107 | - $idb = null; |
|
| 108 | 112 | } |
| 109 | 113 | |
| 110 | 114 | # spip_log("Pas vu $nom_champ"); |
@@ -123,9 +127,10 @@ discard block |
||
| 123 | 127 | * @return string |
| 124 | 128 | */ |
| 125 | 129 | function index_compose($conditionnel,$defaut){ |
| 126 | - while ($c = array_pop($conditionnel)) |
|
| 127 | - // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 130 | + while ($c = array_pop($conditionnel)) { |
|
| 131 | + // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 128 | 132 | $defaut = "($c:(".($defaut?$defaut:"''")."))"; |
| 133 | + } |
|
| 129 | 134 | return $defaut; |
| 130 | 135 | } |
| 131 | 136 | |
@@ -135,7 +140,9 @@ discard block |
||
| 135 | 140 | |
| 136 | 141 | $r = $boucles[$idb]->type_requete; |
| 137 | 142 | |
| 138 | - if ($r == 'boucle') return array(); |
|
| 143 | + if ($r == 'boucle') { |
|
| 144 | + return array(); |
|
| 145 | + } |
|
| 139 | 146 | if (!$r) { |
| 140 | 147 | $joker = false; // indiquer a l'appelant |
| 141 | 148 | # continuer pour chercher l'erreur suivante |
@@ -144,13 +151,13 @@ discard block |
||
| 144 | 151 | |
| 145 | 152 | $desc = $boucles[$idb]->show; |
| 146 | 153 | $excep = isset($exceptions_des_tables[$r]) ? $exceptions_des_tables[$r] : ''; |
| 147 | - if ($excep) |
|
| 148 | - $excep = isset($excep[$nom_champ]) ? $excep[$nom_champ] : ''; |
|
| 154 | + if ($excep) { |
|
| 155 | + $excep = isset($excep[$nom_champ]) ? $excep[$nom_champ] : ''; |
|
| 156 | + } |
|
| 149 | 157 | if ($excep) { |
| 150 | 158 | $joker = false; // indiquer a l'appelant |
| 151 | 159 | return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
| 152 | - } |
|
| 153 | - else { |
|
| 160 | + } else { |
|
| 154 | 161 | if (isset($desc['field'][$nom_champ])) { |
| 155 | 162 | $t = $boucles[$idb]->id_table; |
| 156 | 163 | $joker = false; // indiquer a l'appelant |
@@ -160,18 +167,18 @@ discard block |
||
| 160 | 167 | elseif (/*$joker AND */isset($desc['field']['*'])) { |
| 161 | 168 | $joker = true; // indiquer a l'appelant |
| 162 | 169 | return array($nom_champ, $nom_champ); |
| 163 | - } |
|
| 164 | - else { |
|
| 170 | + } else { |
|
| 165 | 171 | $joker = false; // indiquer a l'appelant |
| 166 | 172 | if ($boucles[$idb]->jointures_explicites) { |
| 167 | 173 | $t = trouver_champ_exterieur($nom_champ, |
| 168 | 174 | $boucles[$idb]->jointures, |
| 169 | 175 | $boucles[$idb]); |
| 170 | - if ($t) |
|
| 171 | - return index_exception($boucles[$idb], |
|
| 176 | + if ($t) { |
|
| 177 | + return index_exception($boucles[$idb], |
|
| 172 | 178 | $desc, |
| 173 | 179 | $nom_champ, |
| 174 | 180 | array($t[1]['id_table'], $nom_champ)); |
| 181 | + } |
|
| 175 | 182 | } |
| 176 | 183 | return array('',''); |
| 177 | 184 | } |
@@ -186,8 +193,9 @@ discard block |
||
| 186 | 193 | function index_exception(&$boucle, $desc, $nom_champ, $excep) |
| 187 | 194 | { |
| 188 | 195 | static $trouver_table; |
| 189 | - if (!$trouver_table) |
|
| 190 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 196 | + if (!$trouver_table) { |
|
| 197 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 198 | + } |
|
| 191 | 199 | |
| 192 | 200 | if (is_array($excep)) { |
| 193 | 201 | // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
@@ -200,7 +208,9 @@ discard block |
||
| 200 | 208 | list($e, $x) = $excep; #PHP4 affecte de gauche a droite |
| 201 | 209 | $excep = $x; #PHP5 de droite a gauche ! |
| 202 | 210 | $j = $trouver_table($e, $boucle->sql_serveur); |
| 203 | - if (!$j) return array('',''); |
|
| 211 | + if (!$j) { |
|
| 212 | + return array('',''); |
|
| 213 | + } |
|
| 204 | 214 | $e = $j['table']; |
| 205 | 215 | if (!$t = array_search($e, $boucle->from)) { |
| 206 | 216 | $k = $j['key']['PRIMARY KEY']; |
@@ -217,11 +227,14 @@ discard block |
||
| 217 | 227 | $t = array_search($e, $boucle->from); |
| 218 | 228 | } |
| 219 | 229 | } |
| 230 | + } else { |
|
| 231 | + $t = $boucle->id_table; |
|
| 220 | 232 | } |
| 221 | - else $t = $boucle->id_table; |
|
| 222 | 233 | // demander a SQL de gerer le synonyme |
| 223 | 234 | // ca permet que excep soit dynamique (Cedric, 2/3/06) |
| 224 | - if ($excep != $nom_champ) $excep .= ' AS '. $nom_champ; |
|
| 235 | + if ($excep != $nom_champ) { |
|
| 236 | + $excep .= ' AS '. $nom_champ; |
|
| 237 | + } |
|
| 225 | 238 | return array("$t.$excep", $nom_champ); |
| 226 | 239 | } |
| 227 | 240 | |
@@ -268,16 +281,18 @@ discard block |
||
| 268 | 281 | if ($f = charger_fonction($nom, 'balise', true)) { |
| 269 | 282 | $p->balise_calculee = true; |
| 270 | 283 | $res = $f($p); |
| 271 | - if ($res !== NULL) |
|
| 272 | - return $res; |
|
| 284 | + if ($res !== NULL) { |
|
| 285 | + return $res; |
|
| 286 | + } |
|
| 273 | 287 | } |
| 274 | 288 | |
| 275 | 289 | // Certaines des balises comportant un _ sont generiques |
| 276 | 290 | if ($f = strpos($nom, '_') |
| 277 | 291 | AND $f = charger_fonction(substr($nom,0,$f+1), 'balise', true)) { |
| 278 | 292 | $res = $f($p); |
| 279 | - if ($res !== NULL) |
|
| 280 | - return $res; |
|
| 293 | + if ($res !== NULL) { |
|
| 294 | + return $res; |
|
| 295 | + } |
|
| 281 | 296 | } |
| 282 | 297 | |
| 283 | 298 | $f = charger_fonction('DEFAUT', 'calculer_balise'); |
@@ -298,8 +313,9 @@ discard block |
||
| 298 | 313 | } |
| 299 | 314 | |
| 300 | 315 | // ne pas passer le filtre securite sur les id_xxx |
| 301 | - if (strpos($nom, 'ID_') === 0) |
|
| 302 | - $p->interdire_scripts = false; |
|
| 316 | + if (strpos($nom, 'ID_') === 0) { |
|
| 317 | + $p->interdire_scripts = false; |
|
| 318 | + } |
|
| 303 | 319 | |
| 304 | 320 | // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
| 305 | 321 | // SI le champ SQL n'est pas trouve |
@@ -349,7 +365,9 @@ discard block |
||
| 349 | 365 | array_shift($c); |
| 350 | 366 | // construire la liste d'arguments comme pour un filtre |
| 351 | 367 | $param = compose_filtres_args($p, $c, ','); |
| 352 | - } else $param = ""; |
|
| 368 | + } else { |
|
| 369 | + $param = ""; |
|
| 370 | + } |
|
| 353 | 371 | $collecte = collecter_balise_dynamique($l, $p, $nom); |
| 354 | 372 | |
| 355 | 373 | $p->code = sprintf(CODE_EXECUTER_BALISE, $nom, |
@@ -440,16 +458,17 @@ discard block |
||
| 440 | 458 | function champs_traitements ($p) { |
| 441 | 459 | global $table_des_traitements; |
| 442 | 460 | |
| 443 | - if (isset($table_des_traitements[$p->nom_champ])) |
|
| 444 | - $ps = $table_des_traitements[$p->nom_champ]; |
|
| 445 | - else { |
|
| 461 | + if (isset($table_des_traitements[$p->nom_champ])) { |
|
| 462 | + $ps = $table_des_traitements[$p->nom_champ]; |
|
| 463 | + } else { |
|
| 446 | 464 | // quand on utilise un traitement catch-all * |
| 447 | 465 | // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
| 448 | 466 | // leur propre securite |
| 449 | - if (!$p->balise_calculee) |
|
| 450 | - $ps = $table_des_traitements['*']; |
|
| 451 | - else |
|
| 452 | - $ps = false; |
|
| 467 | + if (!$p->balise_calculee) { |
|
| 468 | + $ps = $table_des_traitements['*']; |
|
| 469 | + } else { |
|
| 470 | + $ps = false; |
|
| 471 | + } |
|
| 453 | 472 | } |
| 454 | 473 | |
| 455 | 474 | if (is_array($ps)) { |
@@ -460,19 +479,24 @@ discard block |
||
| 460 | 479 | $table_sql = isset($p->boucles[$idb]->show['table_sql'])?$p->boucles[$idb]->show['table_sql']:false; |
| 461 | 480 | |
| 462 | 481 | // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
| 463 | - if ($table_sql AND isset($ps[$table_sql])) |
|
| 464 | - $ps = $ps[$table_sql]; |
|
| 482 | + if ($table_sql AND isset($ps[$table_sql])) { |
|
| 483 | + $ps = $ps[$table_sql]; |
|
| 484 | + } |
|
| 465 | 485 | // ou pour une boucle en particulier "DATA","articles" |
| 466 | - elseif ($type_requete AND isset($ps[$type_requete])) |
|
| 467 | - $ps = $ps[$type_requete]; |
|
| 486 | + elseif ($type_requete AND isset($ps[$type_requete])) { |
|
| 487 | + $ps = $ps[$type_requete]; |
|
| 488 | + } |
|
| 468 | 489 | // ou pour indiferrement quelle que soit la boucle |
| 469 | - elseif(isset($ps[0])) |
|
| 470 | - $ps = $ps[0]; |
|
| 471 | - else |
|
| 472 | - $ps=false; |
|
| 490 | + elseif(isset($ps[0])) { |
|
| 491 | + $ps = $ps[0]; |
|
| 492 | + } else { |
|
| 493 | + $ps=false; |
|
| 494 | + } |
|
| 473 | 495 | } |
| 474 | 496 | |
| 475 | - if (!$ps) return $p->code; |
|
| 497 | + if (!$ps) { |
|
| 498 | + return $p->code; |
|
| 499 | + } |
|
| 476 | 500 | |
| 477 | 501 | // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
| 478 | 502 | // ou si in INCLURE contient {doublons} |
@@ -487,8 +511,9 @@ discard block |
||
| 487 | 511 | (strpos($ps,'propre') !== false) |
| 488 | 512 | OR |
| 489 | 513 | (strpos($ps,'typo') !== false) |
| 490 | - )) |
|
| 491 | - $ps = 'traiter_doublons_documents($doublons, '.$ps.')'; |
|
| 514 | + )) { |
|
| 515 | + $ps = 'traiter_doublons_documents($doublons, '.$ps.')'; |
|
| 516 | + } |
|
| 492 | 517 | |
| 493 | 518 | // La protection des champs par |safehtml est assuree par les extensions |
| 494 | 519 | // dans la declaration des traitements des champs sensibles |
@@ -508,19 +533,22 @@ discard block |
||
| 508 | 533 | function applique_filtres($p) { |
| 509 | 534 | |
| 510 | 535 | // Traitements standards (cf. supra) |
| 511 | - if ($p->etoile == '') |
|
| 512 | - $code = champs_traitements($p); |
|
| 513 | - else |
|
| 514 | - $code = $p->code; |
|
| 536 | + if ($p->etoile == '') { |
|
| 537 | + $code = champs_traitements($p); |
|
| 538 | + } else { |
|
| 539 | + $code = $p->code; |
|
| 540 | + } |
|
| 515 | 541 | |
| 516 | 542 | // Appliquer les filtres perso |
| 517 | - if ($p->param) |
|
| 518 | - $code = compose_filtres($p, $code); |
|
| 543 | + if ($p->param) { |
|
| 544 | + $code = compose_filtres($p, $code); |
|
| 545 | + } |
|
| 519 | 546 | |
| 520 | 547 | // S'il y a un lien avec la session, ajouter un code qui levera |
| 521 | 548 | // un drapeau dans la structure d'invalidation $Cache |
| 522 | - if (isset($p->descr['session'])) |
|
| 523 | - $code = "invalideur_session(\$Cache, $code)"; |
|
| 549 | + if (isset($p->descr['session'])) { |
|
| 550 | + $code = "invalideur_session(\$Cache, $code)"; |
|
| 551 | + } |
|
| 524 | 552 | |
| 525 | 553 | $code = sandbox_composer_interdire_scripts($code, $p); |
| 526 | 554 | return $code; |
@@ -533,7 +561,10 @@ discard block |
||
| 533 | 561 | $image_miette = false; |
| 534 | 562 | foreach($p->param as $filtre) { |
| 535 | 563 | $fonc = array_shift($filtre); |
| 536 | - if (!$fonc) continue; // normalement qu'au premier tour. |
|
| 564 | + if (!$fonc) { |
|
| 565 | + continue; |
|
| 566 | + } |
|
| 567 | + // normalement qu'au premier tour. |
|
| 537 | 568 | $is_filtre_image = ((substr($fonc,0,6)=='image_') AND $fonc!='image_graver'); |
| 538 | 569 | if ($image_miette AND !$is_filtre_image){ |
| 539 | 570 | // il faut graver maintenant car apres le filtre en cours |
@@ -547,21 +578,25 @@ discard block |
||
| 547 | 578 | $sep = ','; |
| 548 | 579 | } else {$sep = ':'; |
| 549 | 580 | // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
| 550 | - if (count($filtre) != 2) |
|
| 551 | - $filtre = array(isset($filtre[0])?$filtre[0]:"", isset($filtre[1])?$filtre[1]:""); |
|
| 581 | + if (count($filtre) != 2) { |
|
| 582 | + $filtre = array(isset($filtre[0])?$filtre[0]:"", isset($filtre[1])?$filtre[1]:""); |
|
| 583 | + } |
|
| 552 | 584 | } |
| 553 | 585 | $arglist = compose_filtres_args($p, $filtre, $sep); |
| 554 | 586 | $logique = filtre_logique($fonc, $code, substr($arglist,1)); |
| 555 | - if ($logique) |
|
| 556 | - $code = $logique; |
|
| 557 | - else { |
|
| 587 | + if ($logique) { |
|
| 588 | + $code = $logique; |
|
| 589 | + } else { |
|
| 558 | 590 | $code = sandbox_composer_filtre($fonc,$code,$arglist,$p); |
| 559 | - if ($is_filtre_image) $image_miette = true; |
|
| 591 | + if ($is_filtre_image) { |
|
| 592 | + $image_miette = true; |
|
| 593 | + } |
|
| 560 | 594 | } |
| 561 | 595 | } |
| 562 | 596 | // ramasser les images intermediaires inutiles et graver l'image finale |
| 563 | - if ($image_miette) |
|
| 564 | - $code = "filtrer('image_graver',$code)"; |
|
| 597 | + if ($image_miette) { |
|
| 598 | + $code = "filtrer('image_graver',$code)"; |
|
| 599 | + } |
|
| 565 | 600 | |
| 566 | 601 | return $code; |
| 567 | 602 | } |
@@ -650,8 +685,9 @@ discard block |
||
| 650 | 685 | } |
| 651 | 686 | |
| 652 | 687 | // si on est hors d'une boucle de {recherche}, cette balise est vide |
| 653 | - if (!$p->code) |
|
| 654 | - $p->code = "''"; |
|
| 688 | + if (!$p->code) { |
|
| 689 | + $p->code = "''"; |
|
| 690 | + } |
|
| 655 | 691 | |
| 656 | 692 | $p->interdire_scripts = false; |
| 657 | 693 | return $p; |
@@ -20,8 +20,6 @@ discard block |
||
| 20 | 20 | * dans les squelette |
| 21 | 21 | * |
| 22 | 22 | * @param string $texte |
| 23 | - * @param string $code |
|
| 24 | - * @param string $arglist |
|
| 25 | 23 | * @param Object $p |
| 26 | 24 | * @return string |
| 27 | 25 | */ |
@@ -85,7 +83,7 @@ discard block |
||
| 85 | 83 | * Composer le code d'inclusion PHP |
| 86 | 84 | * |
| 87 | 85 | * @param string $fichier |
| 88 | - * @param Object $p |
|
| 86 | + * @param Inclure $p |
|
| 89 | 87 | * @param array $_contexte |
| 90 | 88 | * @return string |
| 91 | 89 | */ |
@@ -26,8 +26,8 @@ discard block |
||
| 26 | 26 | * @return string |
| 27 | 27 | */ |
| 28 | 28 | function sandbox_composer_texte($texte, &$p){ |
| 29 | - $code = "'".str_replace(array("\\","'"),array("\\\\","\\'"), $texte)."'"; |
|
| 30 | - return $code; |
|
| 29 | + $code = "'".str_replace(array("\\","'"),array("\\\\","\\'"), $texte)."'"; |
|
| 30 | + return $code; |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | |
@@ -41,33 +41,33 @@ discard block |
||
| 41 | 41 | * @return string |
| 42 | 42 | */ |
| 43 | 43 | function sandbox_composer_filtre($fonc, $code, $arglist, &$p){ |
| 44 | - if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 45 | - $code = "filtrer('$fonc',$code$arglist)"; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - // le filtre est defini sous forme de fonction ou de methode |
|
| 49 | - // par ex. dans inc_texte, inc_filtres ou mes_fonctions |
|
| 50 | - elseif ($f = chercher_filtre($fonc)) { |
|
| 51 | - // cas particulier : le filtre |set doit acceder a la $Pile |
|
| 52 | - // proto: filtre_set(&$Pile, $val, $args...) |
|
| 53 | - if (strpbrk($f, ':')) { // Class::method |
|
| 54 | - $refl = new ReflectionMethod($f); |
|
| 55 | - } else { |
|
| 56 | - $refl = new ReflectionFunction($f); |
|
| 57 | - } |
|
| 58 | - $refs = $refl->getParameters(); |
|
| 59 | - if (isset($refs[0]) AND $refs[0]->name == 'Pile') { |
|
| 60 | - $code = "$f(\$Pile,$code$arglist)"; |
|
| 61 | - } |
|
| 62 | - else { |
|
| 63 | - $code = "$f($code$arglist)"; |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - // le filtre n'existe pas, |
|
| 67 | - // on le notifie |
|
| 68 | - else erreur_squelette(array('zbug_erreur_filtre', array('filtre'=> texte_script($fonc))), $p); |
|
| 69 | - |
|
| 70 | - return $code; |
|
| 44 | + if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 45 | + $code = "filtrer('$fonc',$code$arglist)"; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + // le filtre est defini sous forme de fonction ou de methode |
|
| 49 | + // par ex. dans inc_texte, inc_filtres ou mes_fonctions |
|
| 50 | + elseif ($f = chercher_filtre($fonc)) { |
|
| 51 | + // cas particulier : le filtre |set doit acceder a la $Pile |
|
| 52 | + // proto: filtre_set(&$Pile, $val, $args...) |
|
| 53 | + if (strpbrk($f, ':')) { // Class::method |
|
| 54 | + $refl = new ReflectionMethod($f); |
|
| 55 | + } else { |
|
| 56 | + $refl = new ReflectionFunction($f); |
|
| 57 | + } |
|
| 58 | + $refs = $refl->getParameters(); |
|
| 59 | + if (isset($refs[0]) AND $refs[0]->name == 'Pile') { |
|
| 60 | + $code = "$f(\$Pile,$code$arglist)"; |
|
| 61 | + } |
|
| 62 | + else { |
|
| 63 | + $code = "$f($code$arglist)"; |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + // le filtre n'existe pas, |
|
| 67 | + // on le notifie |
|
| 68 | + else erreur_squelette(array('zbug_erreur_filtre', array('filtre'=> texte_script($fonc))), $p); |
|
| 69 | + |
|
| 70 | + return $code; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // Calculer un <INCLURE(xx.php)> |
@@ -90,13 +90,13 @@ discard block |
||
| 90 | 90 | * @return string |
| 91 | 91 | */ |
| 92 | 92 | function sandbox_composer_inclure_php($fichier, &$p, $_contexte){ |
| 93 | - $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 94 | - // si inexistant, on essaiera a l'execution |
|
| 95 | - if ($path = find_in_path($fichier)) |
|
| 96 | - $path = "\"$path\""; |
|
| 97 | - else $path = "find_in_path(\"$fichier\")"; |
|
| 93 | + $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 94 | + // si inexistant, on essaiera a l'execution |
|
| 95 | + if ($path = find_in_path($fichier)) |
|
| 96 | + $path = "\"$path\""; |
|
| 97 | + else $path = "find_in_path(\"$fichier\")"; |
|
| 98 | 98 | |
| 99 | - return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte); |
|
| 99 | + return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -107,17 +107,17 @@ discard block |
||
| 107 | 107 | * @return string |
| 108 | 108 | */ |
| 109 | 109 | function sandbox_composer_interdire_scripts($code, &$p){ |
| 110 | - // Securite |
|
| 111 | - if ($p->interdire_scripts |
|
| 112 | - AND $p->etoile != '**') { |
|
| 113 | - if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) |
|
| 114 | - $code = "interdire_scripts($code)"; |
|
| 115 | - else { |
|
| 116 | - $code = interdire_scripts($r[2]); |
|
| 117 | - $code = "sinon(interdire_scripts($r[1]),'$code')"; |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - return $code; |
|
| 110 | + // Securite |
|
| 111 | + if ($p->interdire_scripts |
|
| 112 | + AND $p->etoile != '**') { |
|
| 113 | + if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) |
|
| 114 | + $code = "interdire_scripts($code)"; |
|
| 115 | + else { |
|
| 116 | + $code = interdire_scripts($r[2]); |
|
| 117 | + $code = "sinon(interdire_scripts($r[1]),'$code')"; |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + return $code; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | |
@@ -133,45 +133,45 @@ discard block |
||
| 133 | 133 | * @return mixed|string |
| 134 | 134 | */ |
| 135 | 135 | function sandbox_filtrer_squelette($skel, $corps, $filtres){ |
| 136 | - $series_filtres = func_get_args(); |
|
| 137 | - array_shift($series_filtres);// skel |
|
| 138 | - array_shift($series_filtres);// corps |
|
| 139 | - |
|
| 140 | - // proteger les <INCLUDE> et tous les morceaux de php licites |
|
| 141 | - if ($skel['process_ins'] == 'php') |
|
| 142 | - $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS','echapper_php_callback', $corps); |
|
| 143 | - |
|
| 144 | - // recuperer les couples de remplacement |
|
| 145 | - $replace = echapper_php_callback(); |
|
| 146 | - |
|
| 147 | - foreach($series_filtres as $filtres){ |
|
| 148 | - if (count($filtres)) |
|
| 149 | - foreach ($filtres as $filtre) { |
|
| 150 | - if ($filtre AND $f = chercher_filtre($filtre)) |
|
| 151 | - $corps = $f($corps); |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - // restaurer les echappements |
|
| 156 | - return str_replace($replace[0],$replace[1],$corps); |
|
| 136 | + $series_filtres = func_get_args(); |
|
| 137 | + array_shift($series_filtres);// skel |
|
| 138 | + array_shift($series_filtres);// corps |
|
| 139 | + |
|
| 140 | + // proteger les <INCLUDE> et tous les morceaux de php licites |
|
| 141 | + if ($skel['process_ins'] == 'php') |
|
| 142 | + $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS','echapper_php_callback', $corps); |
|
| 143 | + |
|
| 144 | + // recuperer les couples de remplacement |
|
| 145 | + $replace = echapper_php_callback(); |
|
| 146 | + |
|
| 147 | + foreach($series_filtres as $filtres){ |
|
| 148 | + if (count($filtres)) |
|
| 149 | + foreach ($filtres as $filtre) { |
|
| 150 | + if ($filtre AND $f = chercher_filtre($filtre)) |
|
| 151 | + $corps = $f($corps); |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + // restaurer les echappements |
|
| 156 | + return str_replace($replace[0],$replace[1],$corps); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | |
| 160 | 160 | // http://doc.spip.org/@echapper_php_callback |
| 161 | 161 | function echapper_php_callback($r=null) { |
| 162 | - static $src = array(); |
|
| 163 | - static $dst = array(); |
|
| 164 | - |
|
| 165 | - // si on recoit un tableau, on est en mode echappement |
|
| 166 | - // on enregistre le code a echapper dans dst, et le code echappe dans src |
|
| 167 | - if (is_array($r)) { |
|
| 168 | - $dst[] = $r[0]; |
|
| 169 | - return $src[] = '___'.md5($r[0]).'___'; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - // si on recoit pas un tableau, on renvoit les couples de substitution |
|
| 173 | - // et on RAZ les remplacements |
|
| 174 | - $r = array($src,$dst); |
|
| 175 | - $src = $dst = array(); |
|
| 176 | - return $r; |
|
| 162 | + static $src = array(); |
|
| 163 | + static $dst = array(); |
|
| 164 | + |
|
| 165 | + // si on recoit un tableau, on est en mode echappement |
|
| 166 | + // on enregistre le code a echapper dans dst, et le code echappe dans src |
|
| 167 | + if (is_array($r)) { |
|
| 168 | + $dst[] = $r[0]; |
|
| 169 | + return $src[] = '___'.md5($r[0]).'___'; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + // si on recoit pas un tableau, on renvoit les couples de substitution |
|
| 173 | + // et on RAZ les remplacements |
|
| 174 | + $r = array($src,$dst); |
|
| 175 | + $src = $dst = array(); |
|
| 176 | + return $r; |
|
| 177 | 177 | } |
@@ -25,8 +25,8 @@ discard block |
||
| 25 | 25 | * @param Object $p |
| 26 | 26 | * @return string |
| 27 | 27 | */ |
| 28 | -function sandbox_composer_texte($texte, &$p){ |
|
| 29 | - $code = "'".str_replace(array("\\","'"),array("\\\\","\\'"), $texte)."'"; |
|
| 28 | +function sandbox_composer_texte($texte, &$p) { |
|
| 29 | + $code = "'".str_replace(array("\\", "'"), array("\\\\", "\\'"), $texte)."'"; |
|
| 30 | 30 | return $code; |
| 31 | 31 | } |
| 32 | 32 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * @param Object $p |
| 41 | 41 | * @return string |
| 42 | 42 | */ |
| 43 | -function sandbox_composer_filtre($fonc, $code, $arglist, &$p){ |
|
| 43 | +function sandbox_composer_filtre($fonc, $code, $arglist, &$p) { |
|
| 44 | 44 | if (isset($GLOBALS['spip_matrice'][$fonc])) { |
| 45 | 45 | $code = "filtrer('$fonc',$code$arglist)"; |
| 46 | 46 | } |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | * @param array $_contexte |
| 90 | 90 | * @return string |
| 91 | 91 | */ |
| 92 | -function sandbox_composer_inclure_php($fichier, &$p, $_contexte){ |
|
| 92 | +function sandbox_composer_inclure_php($fichier, &$p, $_contexte) { |
|
| 93 | 93 | $compil = texte_script(memoriser_contexte_compil($p)); |
| 94 | 94 | // si inexistant, on essaiera a l'execution |
| 95 | 95 | if ($path = find_in_path($fichier)) |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | * @param Object $p |
| 107 | 107 | * @return string |
| 108 | 108 | */ |
| 109 | -function sandbox_composer_interdire_scripts($code, &$p){ |
|
| 109 | +function sandbox_composer_interdire_scripts($code, &$p) { |
|
| 110 | 110 | // Securite |
| 111 | 111 | if ($p->interdire_scripts |
| 112 | 112 | AND $p->etoile != '**') { |
@@ -132,19 +132,19 @@ discard block |
||
| 132 | 132 | * @param array ... |
| 133 | 133 | * @return mixed|string |
| 134 | 134 | */ |
| 135 | -function sandbox_filtrer_squelette($skel, $corps, $filtres){ |
|
| 135 | +function sandbox_filtrer_squelette($skel, $corps, $filtres) { |
|
| 136 | 136 | $series_filtres = func_get_args(); |
| 137 | - array_shift($series_filtres);// skel |
|
| 138 | - array_shift($series_filtres);// corps |
|
| 137 | + array_shift($series_filtres); // skel |
|
| 138 | + array_shift($series_filtres); // corps |
|
| 139 | 139 | |
| 140 | 140 | // proteger les <INCLUDE> et tous les morceaux de php licites |
| 141 | 141 | if ($skel['process_ins'] == 'php') |
| 142 | - $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS','echapper_php_callback', $corps); |
|
| 142 | + $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps); |
|
| 143 | 143 | |
| 144 | 144 | // recuperer les couples de remplacement |
| 145 | 145 | $replace = echapper_php_callback(); |
| 146 | 146 | |
| 147 | - foreach($series_filtres as $filtres){ |
|
| 147 | + foreach ($series_filtres as $filtres) { |
|
| 148 | 148 | if (count($filtres)) |
| 149 | 149 | foreach ($filtres as $filtre) { |
| 150 | 150 | if ($filtre AND $f = chercher_filtre($filtre)) |
@@ -153,12 +153,12 @@ discard block |
||
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | // restaurer les echappements |
| 156 | - return str_replace($replace[0],$replace[1],$corps); |
|
| 156 | + return str_replace($replace[0], $replace[1], $corps); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | |
| 160 | 160 | // http://doc.spip.org/@echapper_php_callback |
| 161 | -function echapper_php_callback($r=null) { |
|
| 161 | +function echapper_php_callback($r = null) { |
|
| 162 | 162 | static $src = array(); |
| 163 | 163 | static $dst = array(); |
| 164 | 164 | |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | |
| 172 | 172 | // si on recoit pas un tableau, on renvoit les couples de substitution |
| 173 | 173 | // et on RAZ les remplacements |
| 174 | - $r = array($src,$dst); |
|
| 174 | + $r = array($src, $dst); |
|
| 175 | 175 | $src = $dst = array(); |
| 176 | 176 | return $r; |
| 177 | 177 | } |
@@ -11,7 +11,9 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | |
| 14 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 14 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 15 | + return; |
|
| 16 | +} |
|
| 15 | 17 | |
| 16 | 18 | /** |
| 17 | 19 | * Composer le code d'execution d'un texte |
@@ -58,14 +60,15 @@ discard block |
||
| 58 | 60 | $refs = $refl->getParameters(); |
| 59 | 61 | if (isset($refs[0]) AND $refs[0]->name == 'Pile') { |
| 60 | 62 | $code = "$f(\$Pile,$code$arglist)"; |
| 61 | - } |
|
| 62 | - else { |
|
| 63 | + } else { |
|
| 63 | 64 | $code = "$f($code$arglist)"; |
| 64 | 65 | } |
| 65 | 66 | } |
| 66 | 67 | // le filtre n'existe pas, |
| 67 | 68 | // on le notifie |
| 68 | - else erreur_squelette(array('zbug_erreur_filtre', array('filtre'=> texte_script($fonc))), $p); |
|
| 69 | + else { |
|
| 70 | + erreur_squelette(array('zbug_erreur_filtre', array('filtre'=> texte_script($fonc))), $p); |
|
| 71 | + } |
|
| 69 | 72 | |
| 70 | 73 | return $code; |
| 71 | 74 | } |
@@ -92,9 +95,11 @@ discard block |
||
| 92 | 95 | function sandbox_composer_inclure_php($fichier, &$p, $_contexte){ |
| 93 | 96 | $compil = texte_script(memoriser_contexte_compil($p)); |
| 94 | 97 | // si inexistant, on essaiera a l'execution |
| 95 | - if ($path = find_in_path($fichier)) |
|
| 96 | - $path = "\"$path\""; |
|
| 97 | - else $path = "find_in_path(\"$fichier\")"; |
|
| 98 | + if ($path = find_in_path($fichier)) { |
|
| 99 | + $path = "\"$path\""; |
|
| 100 | + } else { |
|
| 101 | + $path = "find_in_path(\"$fichier\")"; |
|
| 102 | + } |
|
| 98 | 103 | |
| 99 | 104 | return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte); |
| 100 | 105 | } |
@@ -110,9 +115,9 @@ discard block |
||
| 110 | 115 | // Securite |
| 111 | 116 | if ($p->interdire_scripts |
| 112 | 117 | AND $p->etoile != '**') { |
| 113 | - if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) |
|
| 114 | - $code = "interdire_scripts($code)"; |
|
| 115 | - else { |
|
| 118 | + if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) { |
|
| 119 | + $code = "interdire_scripts($code)"; |
|
| 120 | + } else { |
|
| 116 | 121 | $code = interdire_scripts($r[2]); |
| 117 | 122 | $code = "sinon(interdire_scripts($r[1]),'$code')"; |
| 118 | 123 | } |
@@ -138,17 +143,19 @@ discard block |
||
| 138 | 143 | array_shift($series_filtres);// corps |
| 139 | 144 | |
| 140 | 145 | // proteger les <INCLUDE> et tous les morceaux de php licites |
| 141 | - if ($skel['process_ins'] == 'php') |
|
| 142 | - $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS','echapper_php_callback', $corps); |
|
| 146 | + if ($skel['process_ins'] == 'php') { |
|
| 147 | + $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS','echapper_php_callback', $corps); |
|
| 148 | + } |
|
| 143 | 149 | |
| 144 | 150 | // recuperer les couples de remplacement |
| 145 | 151 | $replace = echapper_php_callback(); |
| 146 | 152 | |
| 147 | 153 | foreach($series_filtres as $filtres){ |
| 148 | - if (count($filtres)) |
|
| 149 | - foreach ($filtres as $filtre) { |
|
| 154 | + if (count($filtres)) { |
|
| 155 | + foreach ($filtres as $filtre) { |
|
| 150 | 156 | if ($filtre AND $f = chercher_filtre($filtre)) |
| 151 | 157 | $corps = $f($corps); |
| 158 | + } |
|
| 152 | 159 | } |
| 153 | 160 | } |
| 154 | 161 | |
@@ -26,7 +26,6 @@ |
||
| 26 | 26 | * @param array $contexte |
| 27 | 27 | * @param string $lang |
| 28 | 28 | * @param string $connect |
| 29 | - * @param string $ext |
|
| 30 | 29 | * @return array |
| 31 | 30 | * |
| 32 | 31 | * http://doc.spip.org/@public_styliser_dist |
@@ -32,74 +32,74 @@ discard block |
||
| 32 | 32 | * http://doc.spip.org/@public_styliser_dist |
| 33 | 33 | */ |
| 34 | 34 | function public_styliser_dist($fond, $contexte, $lang='', $connect='') { |
| 35 | - static $styliser_par_z; |
|
| 35 | + static $styliser_par_z; |
|
| 36 | 36 | |
| 37 | - // s'assurer que le fond est licite |
|
| 38 | - // car il peut etre construit a partir d'une variable d'environnement |
|
| 39 | - if (strpos($fond,"../")!==false OR strncmp($fond,'/',1)==0) |
|
| 40 | - $fond = "404"; |
|
| 37 | + // s'assurer que le fond est licite |
|
| 38 | + // car il peut etre construit a partir d'une variable d'environnement |
|
| 39 | + if (strpos($fond,"../")!==false OR strncmp($fond,'/',1)==0) |
|
| 40 | + $fond = "404"; |
|
| 41 | 41 | |
| 42 | - // Choisir entre $fond-dist.html, $fond=7.html, etc? |
|
| 43 | - $id_rubrique = 0; |
|
| 44 | - // Chercher le fond qui va servir de squelette |
|
| 45 | - if ($r = quete_rubrique_fond($contexte)) |
|
| 46 | - list($id_rubrique, $lang) = $r; |
|
| 47 | - |
|
| 48 | - // trouver un squelette du nom demande |
|
| 49 | - // ne rien dire si on ne trouve pas, |
|
| 50 | - // c'est l'appelant qui sait comment gerer la situation |
|
| 51 | - // ou les plugins qui feront mieux dans le pipeline |
|
| 52 | - $squelette = trouver_fond($fond,"",true); |
|
| 53 | - $ext = $squelette['extension']; |
|
| 54 | - |
|
| 55 | - $flux = array( |
|
| 56 | - 'args' => array( |
|
| 57 | - 'id_rubrique' => $id_rubrique, |
|
| 58 | - 'ext' => $ext, |
|
| 59 | - 'fond' => $fond, |
|
| 60 | - 'lang' => $lang, |
|
| 61 | - 'contexte' => $contexte, // le style d'un objet peut dependre de lui meme |
|
| 62 | - 'connect' => $connect |
|
| 63 | - ), |
|
| 64 | - 'data' => $squelette['fond'], |
|
| 65 | - ); |
|
| 66 | - |
|
| 67 | - if (test_espace_prive() OR defined('_ZPIP')) { |
|
| 68 | - if (!$styliser_par_z) |
|
| 69 | - $styliser_par_z = charger_fonction('styliser_par_z','public'); |
|
| 70 | - $flux = $styliser_par_z($flux); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - $flux = styliser_par_objets($flux); |
|
| 74 | - |
|
| 75 | - // pipeline styliser |
|
| 76 | - $squelette = pipeline('styliser', $flux); |
|
| 77 | - |
|
| 78 | - return array($squelette, $ext, $ext, "$squelette.$ext"); |
|
| 42 | + // Choisir entre $fond-dist.html, $fond=7.html, etc? |
|
| 43 | + $id_rubrique = 0; |
|
| 44 | + // Chercher le fond qui va servir de squelette |
|
| 45 | + if ($r = quete_rubrique_fond($contexte)) |
|
| 46 | + list($id_rubrique, $lang) = $r; |
|
| 47 | + |
|
| 48 | + // trouver un squelette du nom demande |
|
| 49 | + // ne rien dire si on ne trouve pas, |
|
| 50 | + // c'est l'appelant qui sait comment gerer la situation |
|
| 51 | + // ou les plugins qui feront mieux dans le pipeline |
|
| 52 | + $squelette = trouver_fond($fond,"",true); |
|
| 53 | + $ext = $squelette['extension']; |
|
| 54 | + |
|
| 55 | + $flux = array( |
|
| 56 | + 'args' => array( |
|
| 57 | + 'id_rubrique' => $id_rubrique, |
|
| 58 | + 'ext' => $ext, |
|
| 59 | + 'fond' => $fond, |
|
| 60 | + 'lang' => $lang, |
|
| 61 | + 'contexte' => $contexte, // le style d'un objet peut dependre de lui meme |
|
| 62 | + 'connect' => $connect |
|
| 63 | + ), |
|
| 64 | + 'data' => $squelette['fond'], |
|
| 65 | + ); |
|
| 66 | + |
|
| 67 | + if (test_espace_prive() OR defined('_ZPIP')) { |
|
| 68 | + if (!$styliser_par_z) |
|
| 69 | + $styliser_par_z = charger_fonction('styliser_par_z','public'); |
|
| 70 | + $flux = $styliser_par_z($flux); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + $flux = styliser_par_objets($flux); |
|
| 74 | + |
|
| 75 | + // pipeline styliser |
|
| 76 | + $squelette = pipeline('styliser', $flux); |
|
| 77 | + |
|
| 78 | + return array($squelette, $ext, $ext, "$squelette.$ext"); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | function styliser_par_objets($flux){ |
| 82 | - if (test_espace_prive() |
|
| 83 | - AND !$squelette = $flux['data'] |
|
| 84 | - AND strncmp($flux['args']['fond'],'prive/objets/',13)==0 |
|
| 85 | - AND $echafauder = charger_fonction('echafauder','prive',true)) { |
|
| 86 | - if (strncmp($flux['args']['fond'],'prive/objets/liste/',19)==0){ |
|
| 87 | - $table = table_objet(substr($flux['args']['fond'],19)); |
|
| 88 | - $table_sql = table_objet_sql($table); |
|
| 89 | - $objets = lister_tables_objets_sql(); |
|
| 90 | - if (isset($objets[$table_sql])) |
|
| 91 | - $flux['data'] = $echafauder($table,$table,$table_sql,"prive/objets/liste/objets",$flux['args']['ext']); |
|
| 92 | - } |
|
| 93 | - if (strncmp($flux['args']['fond'],'prive/objets/contenu/',21)==0){ |
|
| 94 | - $type = substr($flux['args']['fond'],21); |
|
| 95 | - $table = table_objet($type); |
|
| 96 | - $table_sql = table_objet_sql($table); |
|
| 97 | - $objets = lister_tables_objets_sql(); |
|
| 98 | - if (isset($objets[$table_sql])) |
|
| 99 | - $flux['data'] = $echafauder($type,$table,$table_sql,"prive/objets/contenu/objet",$flux['args']['ext']); |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - return $flux; |
|
| 82 | + if (test_espace_prive() |
|
| 83 | + AND !$squelette = $flux['data'] |
|
| 84 | + AND strncmp($flux['args']['fond'],'prive/objets/',13)==0 |
|
| 85 | + AND $echafauder = charger_fonction('echafauder','prive',true)) { |
|
| 86 | + if (strncmp($flux['args']['fond'],'prive/objets/liste/',19)==0){ |
|
| 87 | + $table = table_objet(substr($flux['args']['fond'],19)); |
|
| 88 | + $table_sql = table_objet_sql($table); |
|
| 89 | + $objets = lister_tables_objets_sql(); |
|
| 90 | + if (isset($objets[$table_sql])) |
|
| 91 | + $flux['data'] = $echafauder($table,$table,$table_sql,"prive/objets/liste/objets",$flux['args']['ext']); |
|
| 92 | + } |
|
| 93 | + if (strncmp($flux['args']['fond'],'prive/objets/contenu/',21)==0){ |
|
| 94 | + $type = substr($flux['args']['fond'],21); |
|
| 95 | + $table = table_objet($type); |
|
| 96 | + $table_sql = table_objet_sql($table); |
|
| 97 | + $objets = lister_tables_objets_sql(); |
|
| 98 | + if (isset($objets[$table_sql])) |
|
| 99 | + $flux['data'] = $echafauder($type,$table,$table_sql,"prive/objets/contenu/objet",$flux['args']['ext']); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + return $flux; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -117,43 +117,43 @@ discard block |
||
| 117 | 117 | * @return array |
| 118 | 118 | */ |
| 119 | 119 | function quete_rubrique_fond($contexte) { |
| 120 | - static $liste_objets = null; |
|
| 121 | - static $quete = array(); |
|
| 122 | - if (is_null($liste_objets)) { |
|
| 123 | - $liste_objets = array(); |
|
| 124 | - include_spip('inc/urls'); |
|
| 125 | - include_spip('public/quete'); |
|
| 126 | - $l = urls_liste_objets(false); |
|
| 127 | - // placer la rubrique en tete des objets |
|
| 128 | - $l = array_diff($l,array('rubrique')); |
|
| 129 | - array_unshift($l, 'rubrique'); |
|
| 130 | - foreach($l as $objet){ |
|
| 131 | - $id = id_table_objet($objet); |
|
| 132 | - if (!isset($liste_objets[$id])) |
|
| 133 | - $liste_objets[$id] = objet_type($objet,false); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - $c = array_intersect_key($contexte,$liste_objets); |
|
| 137 | - if (!count($c)) return false; |
|
| 138 | - |
|
| 139 | - $c = array_map('intval',$c); |
|
| 140 | - $s = serialize($c); |
|
| 141 | - if (isset($quete[$s])) |
|
| 142 | - return $quete[$s]; |
|
| 143 | - |
|
| 144 | - if (isset($c['id_rubrique']) AND $r = $c['id_rubrique']){ |
|
| 145 | - unset($c['id_rubrique']); |
|
| 146 | - $c = array('id_rubrique'=>$r) + $c; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - foreach($c as $_id=>$id) { |
|
| 150 | - if ($id |
|
| 151 | - AND $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]),$id)) { |
|
| 152 | - $lang = isset($row['lang']) ? $row['lang'] : ''; |
|
| 153 | - if ($_id=='id_rubrique' OR (isset($row['id_rubrique']) AND $id=$row['id_rubrique'])) |
|
| 154 | - return $quete[$s] = array ($id, $lang); |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - return $quete[$s] = false; |
|
| 120 | + static $liste_objets = null; |
|
| 121 | + static $quete = array(); |
|
| 122 | + if (is_null($liste_objets)) { |
|
| 123 | + $liste_objets = array(); |
|
| 124 | + include_spip('inc/urls'); |
|
| 125 | + include_spip('public/quete'); |
|
| 126 | + $l = urls_liste_objets(false); |
|
| 127 | + // placer la rubrique en tete des objets |
|
| 128 | + $l = array_diff($l,array('rubrique')); |
|
| 129 | + array_unshift($l, 'rubrique'); |
|
| 130 | + foreach($l as $objet){ |
|
| 131 | + $id = id_table_objet($objet); |
|
| 132 | + if (!isset($liste_objets[$id])) |
|
| 133 | + $liste_objets[$id] = objet_type($objet,false); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + $c = array_intersect_key($contexte,$liste_objets); |
|
| 137 | + if (!count($c)) return false; |
|
| 138 | + |
|
| 139 | + $c = array_map('intval',$c); |
|
| 140 | + $s = serialize($c); |
|
| 141 | + if (isset($quete[$s])) |
|
| 142 | + return $quete[$s]; |
|
| 143 | + |
|
| 144 | + if (isset($c['id_rubrique']) AND $r = $c['id_rubrique']){ |
|
| 145 | + unset($c['id_rubrique']); |
|
| 146 | + $c = array('id_rubrique'=>$r) + $c; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + foreach($c as $_id=>$id) { |
|
| 150 | + if ($id |
|
| 151 | + AND $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]),$id)) { |
|
| 152 | + $lang = isset($row['lang']) ? $row['lang'] : ''; |
|
| 153 | + if ($_id=='id_rubrique' OR (isset($row['id_rubrique']) AND $id=$row['id_rubrique'])) |
|
| 154 | + return $quete[$s] = array ($id, $lang); |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + return $quete[$s] = false; |
|
| 158 | 158 | } |
| 159 | 159 | ?> |
@@ -31,12 +31,12 @@ discard block |
||
| 31 | 31 | * |
| 32 | 32 | * http://doc.spip.org/@public_styliser_dist |
| 33 | 33 | */ |
| 34 | -function public_styliser_dist($fond, $contexte, $lang='', $connect='') { |
|
| 34 | +function public_styliser_dist($fond, $contexte, $lang = '', $connect = '') { |
|
| 35 | 35 | static $styliser_par_z; |
| 36 | 36 | |
| 37 | 37 | // s'assurer que le fond est licite |
| 38 | 38 | // car il peut etre construit a partir d'une variable d'environnement |
| 39 | - if (strpos($fond,"../")!==false OR strncmp($fond,'/',1)==0) |
|
| 39 | + if (strpos($fond, "../") !== false OR strncmp($fond, '/', 1) == 0) |
|
| 40 | 40 | $fond = "404"; |
| 41 | 41 | |
| 42 | 42 | // Choisir entre $fond-dist.html, $fond=7.html, etc? |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | // ne rien dire si on ne trouve pas, |
| 50 | 50 | // c'est l'appelant qui sait comment gerer la situation |
| 51 | 51 | // ou les plugins qui feront mieux dans le pipeline |
| 52 | - $squelette = trouver_fond($fond,"",true); |
|
| 52 | + $squelette = trouver_fond($fond, "", true); |
|
| 53 | 53 | $ext = $squelette['extension']; |
| 54 | 54 | |
| 55 | 55 | $flux = array( |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | |
| 67 | 67 | if (test_espace_prive() OR defined('_ZPIP')) { |
| 68 | 68 | if (!$styliser_par_z) |
| 69 | - $styliser_par_z = charger_fonction('styliser_par_z','public'); |
|
| 69 | + $styliser_par_z = charger_fonction('styliser_par_z', 'public'); |
|
| 70 | 70 | $flux = $styliser_par_z($flux); |
| 71 | 71 | } |
| 72 | 72 | |
@@ -78,25 +78,25 @@ discard block |
||
| 78 | 78 | return array($squelette, $ext, $ext, "$squelette.$ext"); |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | -function styliser_par_objets($flux){ |
|
| 81 | +function styliser_par_objets($flux) { |
|
| 82 | 82 | if (test_espace_prive() |
| 83 | 83 | AND !$squelette = $flux['data'] |
| 84 | - AND strncmp($flux['args']['fond'],'prive/objets/',13)==0 |
|
| 85 | - AND $echafauder = charger_fonction('echafauder','prive',true)) { |
|
| 86 | - if (strncmp($flux['args']['fond'],'prive/objets/liste/',19)==0){ |
|
| 87 | - $table = table_objet(substr($flux['args']['fond'],19)); |
|
| 84 | + AND strncmp($flux['args']['fond'], 'prive/objets/', 13) == 0 |
|
| 85 | + AND $echafauder = charger_fonction('echafauder', 'prive', true)) { |
|
| 86 | + if (strncmp($flux['args']['fond'], 'prive/objets/liste/', 19) == 0) { |
|
| 87 | + $table = table_objet(substr($flux['args']['fond'], 19)); |
|
| 88 | 88 | $table_sql = table_objet_sql($table); |
| 89 | 89 | $objets = lister_tables_objets_sql(); |
| 90 | 90 | if (isset($objets[$table_sql])) |
| 91 | - $flux['data'] = $echafauder($table,$table,$table_sql,"prive/objets/liste/objets",$flux['args']['ext']); |
|
| 91 | + $flux['data'] = $echafauder($table, $table, $table_sql, "prive/objets/liste/objets", $flux['args']['ext']); |
|
| 92 | 92 | } |
| 93 | - if (strncmp($flux['args']['fond'],'prive/objets/contenu/',21)==0){ |
|
| 94 | - $type = substr($flux['args']['fond'],21); |
|
| 93 | + if (strncmp($flux['args']['fond'], 'prive/objets/contenu/', 21) == 0) { |
|
| 94 | + $type = substr($flux['args']['fond'], 21); |
|
| 95 | 95 | $table = table_objet($type); |
| 96 | 96 | $table_sql = table_objet_sql($table); |
| 97 | 97 | $objets = lister_tables_objets_sql(); |
| 98 | 98 | if (isset($objets[$table_sql])) |
| 99 | - $flux['data'] = $echafauder($type,$table,$table_sql,"prive/objets/contenu/objet",$flux['args']['ext']); |
|
| 99 | + $flux['data'] = $echafauder($type, $table, $table_sql, "prive/objets/contenu/objet", $flux['args']['ext']); |
|
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | return $flux; |
@@ -125,33 +125,33 @@ discard block |
||
| 125 | 125 | include_spip('public/quete'); |
| 126 | 126 | $l = urls_liste_objets(false); |
| 127 | 127 | // placer la rubrique en tete des objets |
| 128 | - $l = array_diff($l,array('rubrique')); |
|
| 128 | + $l = array_diff($l, array('rubrique')); |
|
| 129 | 129 | array_unshift($l, 'rubrique'); |
| 130 | - foreach($l as $objet){ |
|
| 130 | + foreach ($l as $objet) { |
|
| 131 | 131 | $id = id_table_objet($objet); |
| 132 | 132 | if (!isset($liste_objets[$id])) |
| 133 | - $liste_objets[$id] = objet_type($objet,false); |
|
| 133 | + $liste_objets[$id] = objet_type($objet, false); |
|
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | - $c = array_intersect_key($contexte,$liste_objets); |
|
| 136 | + $c = array_intersect_key($contexte, $liste_objets); |
|
| 137 | 137 | if (!count($c)) return false; |
| 138 | 138 | |
| 139 | - $c = array_map('intval',$c); |
|
| 139 | + $c = array_map('intval', $c); |
|
| 140 | 140 | $s = serialize($c); |
| 141 | 141 | if (isset($quete[$s])) |
| 142 | 142 | return $quete[$s]; |
| 143 | 143 | |
| 144 | - if (isset($c['id_rubrique']) AND $r = $c['id_rubrique']){ |
|
| 144 | + if (isset($c['id_rubrique']) AND $r = $c['id_rubrique']) { |
|
| 145 | 145 | unset($c['id_rubrique']); |
| 146 | 146 | $c = array('id_rubrique'=>$r) + $c; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - foreach($c as $_id=>$id) { |
|
| 149 | + foreach ($c as $_id=>$id) { |
|
| 150 | 150 | if ($id |
| 151 | - AND $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]),$id)) { |
|
| 151 | + AND $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id)) { |
|
| 152 | 152 | $lang = isset($row['lang']) ? $row['lang'] : ''; |
| 153 | - if ($_id=='id_rubrique' OR (isset($row['id_rubrique']) AND $id=$row['id_rubrique'])) |
|
| 154 | - return $quete[$s] = array ($id, $lang); |
|
| 153 | + if ($_id == 'id_rubrique' OR (isset($row['id_rubrique']) AND $id = $row['id_rubrique'])) |
|
| 154 | + return $quete[$s] = array($id, $lang); |
|
| 155 | 155 | } |
| 156 | 156 | } |
| 157 | 157 | return $quete[$s] = false; |
@@ -11,7 +11,9 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | |
| 14 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 14 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 15 | + return; |
|
| 16 | +} |
|
| 15 | 17 | |
| 16 | 18 | // Ce fichier doit imperativement definir la fonction ci-dessous: |
| 17 | 19 | |
@@ -36,14 +38,16 @@ discard block |
||
| 36 | 38 | |
| 37 | 39 | // s'assurer que le fond est licite |
| 38 | 40 | // car il peut etre construit a partir d'une variable d'environnement |
| 39 | - if (strpos($fond,"../")!==false OR strncmp($fond,'/',1)==0) |
|
| 40 | - $fond = "404"; |
|
| 41 | + if (strpos($fond,"../")!==false OR strncmp($fond,'/',1)==0) { |
|
| 42 | + $fond = "404"; |
|
| 43 | + } |
|
| 41 | 44 | |
| 42 | 45 | // Choisir entre $fond-dist.html, $fond=7.html, etc? |
| 43 | 46 | $id_rubrique = 0; |
| 44 | 47 | // Chercher le fond qui va servir de squelette |
| 45 | - if ($r = quete_rubrique_fond($contexte)) |
|
| 46 | - list($id_rubrique, $lang) = $r; |
|
| 48 | + if ($r = quete_rubrique_fond($contexte)) { |
|
| 49 | + list($id_rubrique, $lang) = $r; |
|
| 50 | + } |
|
| 47 | 51 | |
| 48 | 52 | // trouver un squelette du nom demande |
| 49 | 53 | // ne rien dire si on ne trouve pas, |
@@ -65,8 +69,9 @@ discard block |
||
| 65 | 69 | ); |
| 66 | 70 | |
| 67 | 71 | if (test_espace_prive() OR defined('_ZPIP')) { |
| 68 | - if (!$styliser_par_z) |
|
| 69 | - $styliser_par_z = charger_fonction('styliser_par_z','public'); |
|
| 72 | + if (!$styliser_par_z) { |
|
| 73 | + $styliser_par_z = charger_fonction('styliser_par_z','public'); |
|
| 74 | + } |
|
| 70 | 75 | $flux = $styliser_par_z($flux); |
| 71 | 76 | } |
| 72 | 77 | |
@@ -87,16 +92,18 @@ discard block |
||
| 87 | 92 | $table = table_objet(substr($flux['args']['fond'],19)); |
| 88 | 93 | $table_sql = table_objet_sql($table); |
| 89 | 94 | $objets = lister_tables_objets_sql(); |
| 90 | - if (isset($objets[$table_sql])) |
|
| 91 | - $flux['data'] = $echafauder($table,$table,$table_sql,"prive/objets/liste/objets",$flux['args']['ext']); |
|
| 95 | + if (isset($objets[$table_sql])) { |
|
| 96 | + $flux['data'] = $echafauder($table,$table,$table_sql,"prive/objets/liste/objets",$flux['args']['ext']); |
|
| 97 | + } |
|
| 92 | 98 | } |
| 93 | 99 | if (strncmp($flux['args']['fond'],'prive/objets/contenu/',21)==0){ |
| 94 | 100 | $type = substr($flux['args']['fond'],21); |
| 95 | 101 | $table = table_objet($type); |
| 96 | 102 | $table_sql = table_objet_sql($table); |
| 97 | 103 | $objets = lister_tables_objets_sql(); |
| 98 | - if (isset($objets[$table_sql])) |
|
| 99 | - $flux['data'] = $echafauder($type,$table,$table_sql,"prive/objets/contenu/objet",$flux['args']['ext']); |
|
| 104 | + if (isset($objets[$table_sql])) { |
|
| 105 | + $flux['data'] = $echafauder($type,$table,$table_sql,"prive/objets/contenu/objet",$flux['args']['ext']); |
|
| 106 | + } |
|
| 100 | 107 | } |
| 101 | 108 | } |
| 102 | 109 | return $flux; |
@@ -129,17 +136,21 @@ discard block |
||
| 129 | 136 | array_unshift($l, 'rubrique'); |
| 130 | 137 | foreach($l as $objet){ |
| 131 | 138 | $id = id_table_objet($objet); |
| 132 | - if (!isset($liste_objets[$id])) |
|
| 133 | - $liste_objets[$id] = objet_type($objet,false); |
|
| 139 | + if (!isset($liste_objets[$id])) { |
|
| 140 | + $liste_objets[$id] = objet_type($objet,false); |
|
| 141 | + } |
|
| 134 | 142 | } |
| 135 | 143 | } |
| 136 | 144 | $c = array_intersect_key($contexte,$liste_objets); |
| 137 | - if (!count($c)) return false; |
|
| 145 | + if (!count($c)) { |
|
| 146 | + return false; |
|
| 147 | + } |
|
| 138 | 148 | |
| 139 | 149 | $c = array_map('intval',$c); |
| 140 | 150 | $s = serialize($c); |
| 141 | - if (isset($quete[$s])) |
|
| 142 | - return $quete[$s]; |
|
| 151 | + if (isset($quete[$s])) { |
|
| 152 | + return $quete[$s]; |
|
| 153 | + } |
|
| 143 | 154 | |
| 144 | 155 | if (isset($c['id_rubrique']) AND $r = $c['id_rubrique']){ |
| 145 | 156 | unset($c['id_rubrique']); |
@@ -150,8 +161,9 @@ discard block |
||
| 150 | 161 | if ($id |
| 151 | 162 | AND $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]),$id)) { |
| 152 | 163 | $lang = isset($row['lang']) ? $row['lang'] : ''; |
| 153 | - if ($_id=='id_rubrique' OR (isset($row['id_rubrique']) AND $id=$row['id_rubrique'])) |
|
| 154 | - return $quete[$s] = array ($id, $lang); |
|
| 164 | + if ($_id=='id_rubrique' OR (isset($row['id_rubrique']) AND $id=$row['id_rubrique'])) { |
|
| 165 | + return $quete[$s] = array ($id, $lang); |
|
| 166 | + } |
|
| 155 | 167 | } |
| 156 | 168 | } |
| 157 | 169 | return $quete[$s] = false; |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | * @param string $type |
| 202 | 202 | * @param string $ext |
| 203 | 203 | * @param bool $echafauder |
| 204 | - * @return mixed |
|
| 204 | + * @return string|boolean |
|
| 205 | 205 | */ |
| 206 | 206 | function z_contenu_disponible($prefix_path,$z_contenu,$type,$ext,$echafauder=true){ |
| 207 | 207 | if ($d = z_trouver_bloc($prefix_path,$z_contenu,$type,$ext)) |
@@ -295,10 +295,8 @@ discard block |
||
| 295 | 295 | * tous les squelettes d'echafaudage du prive sont en fait explicites dans prive/echafaudage |
| 296 | 296 | * on ne fait qu'un mini squelette d'inclusion pour reecrire les variables d'env |
| 297 | 297 | * |
| 298 | - * @param string $type |
|
| 299 | 298 | * @param string $table |
| 300 | 299 | * @param string $table_sql |
| 301 | - * @param array $desc |
|
| 302 | 300 | * @param string $ext |
| 303 | 301 | * @return string |
| 304 | 302 | */ |
@@ -20,164 +20,164 @@ discard block |
||
| 20 | 20 | * @return array |
| 21 | 21 | */ |
| 22 | 22 | function public_styliser_par_z_dist($flux){ |
| 23 | - static $prefix_path=null; |
|
| 24 | - static $prefix_length; |
|
| 25 | - static $z_blocs; |
|
| 26 | - static $apl_constant; |
|
| 27 | - static $page; |
|
| 28 | - static $disponible = array(); |
|
| 29 | - static $echafauder; |
|
| 30 | - static $prepend = ""; |
|
| 23 | + static $prefix_path=null; |
|
| 24 | + static $prefix_length; |
|
| 25 | + static $z_blocs; |
|
| 26 | + static $apl_constant; |
|
| 27 | + static $page; |
|
| 28 | + static $disponible = array(); |
|
| 29 | + static $echafauder; |
|
| 30 | + static $prepend = ""; |
|
| 31 | 31 | |
| 32 | - if (!isset($prefix_path)) { |
|
| 33 | - $z_blocs = z_blocs(test_espace_prive()); |
|
| 34 | - if (test_espace_prive ()){ |
|
| 35 | - $prefix_path = "prive/squelettes/"; |
|
| 36 | - $prefix_length = strlen($prefix_path); |
|
| 37 | - $apl_constant = '_ECRIRE_AJAX_PARALLEL_LOAD'; |
|
| 38 | - $page = 'exec'; |
|
| 39 | - $echafauder = charger_fonction('echafauder','prive',true); |
|
| 40 | - define('_ZCORE_EXCLURE_PATH',''); |
|
| 41 | - } |
|
| 42 | - else { |
|
| 43 | - $prefix_path = ""; |
|
| 44 | - $prefix_length = 0; |
|
| 45 | - $apl_constant = '_Z_AJAX_PARALLEL_LOAD'; |
|
| 46 | - $page = _SPIP_PAGE; |
|
| 47 | - $echafauder = charger_fonction('echafauder','public',true); |
|
| 48 | - define('_ZCORE_EXCLURE_PATH','\bprive|\bsquelettes-dist'.(defined('_DIR_PLUGIN_DIST')?'|\b'.rtrim(_DIR_PLUGIN_DIST,'/'):'')); |
|
| 49 | - } |
|
| 50 | - $prepend = (defined('_Z_PREPEND_PATH')?_Z_PREPEND_PATH:""); |
|
| 51 | - } |
|
| 52 | - $z_contenu = reset($z_blocs); // contenu par defaut |
|
| 32 | + if (!isset($prefix_path)) { |
|
| 33 | + $z_blocs = z_blocs(test_espace_prive()); |
|
| 34 | + if (test_espace_prive ()){ |
|
| 35 | + $prefix_path = "prive/squelettes/"; |
|
| 36 | + $prefix_length = strlen($prefix_path); |
|
| 37 | + $apl_constant = '_ECRIRE_AJAX_PARALLEL_LOAD'; |
|
| 38 | + $page = 'exec'; |
|
| 39 | + $echafauder = charger_fonction('echafauder','prive',true); |
|
| 40 | + define('_ZCORE_EXCLURE_PATH',''); |
|
| 41 | + } |
|
| 42 | + else { |
|
| 43 | + $prefix_path = ""; |
|
| 44 | + $prefix_length = 0; |
|
| 45 | + $apl_constant = '_Z_AJAX_PARALLEL_LOAD'; |
|
| 46 | + $page = _SPIP_PAGE; |
|
| 47 | + $echafauder = charger_fonction('echafauder','public',true); |
|
| 48 | + define('_ZCORE_EXCLURE_PATH','\bprive|\bsquelettes-dist'.(defined('_DIR_PLUGIN_DIST')?'|\b'.rtrim(_DIR_PLUGIN_DIST,'/'):'')); |
|
| 49 | + } |
|
| 50 | + $prepend = (defined('_Z_PREPEND_PATH')?_Z_PREPEND_PATH:""); |
|
| 51 | + } |
|
| 52 | + $z_contenu = reset($z_blocs); // contenu par defaut |
|
| 53 | 53 | |
| 54 | - $fond = $flux['args']['fond']; |
|
| 54 | + $fond = $flux['args']['fond']; |
|
| 55 | 55 | |
| 56 | - if ($prepend OR strncmp($fond,$prefix_path,$prefix_length)==0) { |
|
| 57 | - $fond = substr($fond, $prefix_length); |
|
| 58 | - $squelette = $flux['data']; |
|
| 59 | - $ext = $flux['args']['ext']; |
|
| 60 | - // Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera en ajax |
|
| 61 | - if (defined('_Z_AJAX_PARALLEL_LOAD_OK') |
|
| 62 | - AND $dir = explode('/',$fond) |
|
| 63 | - AND count($dir)==2 // pas un sous repertoire |
|
| 64 | - AND $dir = reset($dir) |
|
| 65 | - AND in_array($dir,$z_blocs) // verifier deja qu'on est dans un bloc Z |
|
| 66 | - AND defined($apl_constant) |
|
| 67 | - AND in_array($dir,explode(',',constant($apl_constant))) // et dans un demande en APL |
|
| 68 | - AND $pipe = z_trouver_bloc($prefix_path.$prepend,$dir,'z_apl',$ext) // et qui contient le squelette APL |
|
| 69 | - ){ |
|
| 70 | - $flux['data'] = $pipe; |
|
| 71 | - return $flux; |
|
| 72 | - } |
|
| 56 | + if ($prepend OR strncmp($fond,$prefix_path,$prefix_length)==0) { |
|
| 57 | + $fond = substr($fond, $prefix_length); |
|
| 58 | + $squelette = $flux['data']; |
|
| 59 | + $ext = $flux['args']['ext']; |
|
| 60 | + // Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera en ajax |
|
| 61 | + if (defined('_Z_AJAX_PARALLEL_LOAD_OK') |
|
| 62 | + AND $dir = explode('/',$fond) |
|
| 63 | + AND count($dir)==2 // pas un sous repertoire |
|
| 64 | + AND $dir = reset($dir) |
|
| 65 | + AND in_array($dir,$z_blocs) // verifier deja qu'on est dans un bloc Z |
|
| 66 | + AND defined($apl_constant) |
|
| 67 | + AND in_array($dir,explode(',',constant($apl_constant))) // et dans un demande en APL |
|
| 68 | + AND $pipe = z_trouver_bloc($prefix_path.$prepend,$dir,'z_apl',$ext) // et qui contient le squelette APL |
|
| 69 | + ){ |
|
| 70 | + $flux['data'] = $pipe; |
|
| 71 | + return $flux; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - // surcharger aussi les squelettes venant de squelettes-dist/ |
|
| 75 | - if ($squelette AND !z_fond_valide($squelette)){ |
|
| 76 | - $squelette = ""; |
|
| 77 | - $echafauder = ""; |
|
| 78 | - } |
|
| 79 | - if ($prepend){ |
|
| 80 | - $squelette = substr(find_in_path($prefix_path.$prepend."$fond.$ext"), 0, - strlen(".$ext")); |
|
| 81 | - if ($squelette) |
|
| 82 | - $flux['data'] = $squelette; |
|
| 83 | - } |
|
| 74 | + // surcharger aussi les squelettes venant de squelettes-dist/ |
|
| 75 | + if ($squelette AND !z_fond_valide($squelette)){ |
|
| 76 | + $squelette = ""; |
|
| 77 | + $echafauder = ""; |
|
| 78 | + } |
|
| 79 | + if ($prepend){ |
|
| 80 | + $squelette = substr(find_in_path($prefix_path.$prepend."$fond.$ext"), 0, - strlen(".$ext")); |
|
| 81 | + if ($squelette) |
|
| 82 | + $flux['data'] = $squelette; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - // gerer les squelettes non trouves |
|
| 86 | - // -> router vers les /dist.html |
|
| 87 | - // ou scaffolding ou page automatique les contenus |
|
| 88 | - if (!$squelette){ |
|
| 85 | + // gerer les squelettes non trouves |
|
| 86 | + // -> router vers les /dist.html |
|
| 87 | + // ou scaffolding ou page automatique les contenus |
|
| 88 | + if (!$squelette){ |
|
| 89 | 89 | |
| 90 | - // si on est sur un ?page=XX non trouve |
|
| 91 | - if ($flux['args']['contexte'][$page] == $fond |
|
| 92 | - OR $flux['args']['contexte']['type-page'] == $fond |
|
| 93 | - OR ($fond=='sommaire' AND !$flux['args']['contexte'][$page])) { |
|
| 90 | + // si on est sur un ?page=XX non trouve |
|
| 91 | + if ($flux['args']['contexte'][$page] == $fond |
|
| 92 | + OR $flux['args']['contexte']['type-page'] == $fond |
|
| 93 | + OR ($fond=='sommaire' AND !$flux['args']['contexte'][$page])) { |
|
| 94 | 94 | |
| 95 | - // si on est sur un ?page=XX non trouve |
|
| 96 | - // se brancher sur contenu/xx si il existe |
|
| 97 | - // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
|
| 98 | - if (!isset($disponible[$fond])) |
|
| 99 | - $disponible[$fond] = z_contenu_disponible($prefix_path.$prepend,$z_contenu,$fond,$ext,$echafauder); |
|
| 95 | + // si on est sur un ?page=XX non trouve |
|
| 96 | + // se brancher sur contenu/xx si il existe |
|
| 97 | + // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
|
| 98 | + if (!isset($disponible[$fond])) |
|
| 99 | + $disponible[$fond] = z_contenu_disponible($prefix_path.$prepend,$z_contenu,$fond,$ext,$echafauder); |
|
| 100 | 100 | |
| 101 | - if ($disponible[$fond]) |
|
| 102 | - $flux['data'] = substr(find_in_path($prefix_path."page.$ext"), 0, - strlen(".$ext")); |
|
| 103 | - } |
|
| 101 | + if ($disponible[$fond]) |
|
| 102 | + $flux['data'] = substr(find_in_path($prefix_path."page.$ext"), 0, - strlen(".$ext")); |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - // echafaudage : |
|
| 106 | - // si c'est un fond de contenu d'un objet en base |
|
| 107 | - // generer un fond automatique a la volee pour les webmestres |
|
| 108 | - elseif (strncmp($fond, "$z_contenu/", strlen($z_contenu)+1)==0){ |
|
| 109 | - $type = substr($fond,strlen($z_contenu)+1); |
|
| 110 | - if (($type=='page') AND isset($flux['args']['contexte'][$page])) |
|
| 111 | - $type = $flux['args']['contexte'][$page]; |
|
| 112 | - if (!isset($disponible[$type])) |
|
| 113 | - $disponible[$type] = z_contenu_disponible($prefix_path.$prepend,$z_contenu,$type,$ext,$echafauder); |
|
| 114 | - if (is_string($disponible[$type])) { |
|
| 115 | - $flux['data'] = $disponible[$type]; |
|
| 116 | - } |
|
| 117 | - elseif ($echafauder |
|
| 118 | - AND include_spip('inc/autoriser') |
|
| 119 | - AND isset($GLOBALS['visiteur_session']['statut']) // performance |
|
| 120 | - AND autoriser('echafauder',$type) |
|
| 121 | - AND $is = $disponible[$type] |
|
| 122 | - AND is_array($is)) { |
|
| 123 | - $flux['data'] = $echafauder($type,$is[0],$is[1],$is[2],$ext); |
|
| 124 | - } |
|
| 125 | - else{ |
|
| 126 | - $flux['data'] = ($disponible['404'] = z_contenu_disponible($prefix_path.$prepend,$z_contenu,'404',$ext,$echafauder)); |
|
| 127 | - } |
|
| 128 | - } |
|
| 105 | + // echafaudage : |
|
| 106 | + // si c'est un fond de contenu d'un objet en base |
|
| 107 | + // generer un fond automatique a la volee pour les webmestres |
|
| 108 | + elseif (strncmp($fond, "$z_contenu/", strlen($z_contenu)+1)==0){ |
|
| 109 | + $type = substr($fond,strlen($z_contenu)+1); |
|
| 110 | + if (($type=='page') AND isset($flux['args']['contexte'][$page])) |
|
| 111 | + $type = $flux['args']['contexte'][$page]; |
|
| 112 | + if (!isset($disponible[$type])) |
|
| 113 | + $disponible[$type] = z_contenu_disponible($prefix_path.$prepend,$z_contenu,$type,$ext,$echafauder); |
|
| 114 | + if (is_string($disponible[$type])) { |
|
| 115 | + $flux['data'] = $disponible[$type]; |
|
| 116 | + } |
|
| 117 | + elseif ($echafauder |
|
| 118 | + AND include_spip('inc/autoriser') |
|
| 119 | + AND isset($GLOBALS['visiteur_session']['statut']) // performance |
|
| 120 | + AND autoriser('echafauder',$type) |
|
| 121 | + AND $is = $disponible[$type] |
|
| 122 | + AND is_array($is)) { |
|
| 123 | + $flux['data'] = $echafauder($type,$is[0],$is[1],$is[2],$ext); |
|
| 124 | + } |
|
| 125 | + else{ |
|
| 126 | + $flux['data'] = ($disponible['404'] = z_contenu_disponible($prefix_path.$prepend,$z_contenu,'404',$ext,$echafauder)); |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - // sinon, si on demande un fond non trouve dans un des autres blocs |
|
| 131 | - // et si il y a bien un contenu correspondant ou echafaudable |
|
| 132 | - // se rabbatre sur le dist.html du bloc concerne |
|
| 133 | - else{ |
|
| 134 | - if ( $dir = explode('/',$fond) |
|
| 135 | - AND $dir = reset($dir) |
|
| 136 | - AND $dir !== $z_contenu |
|
| 137 | - AND in_array($dir,$z_blocs)){ |
|
| 138 | - $type = substr($fond,strlen("$dir/")); |
|
| 139 | - if (($type=='page') AND isset($flux['args']['contexte'][$page])) |
|
| 140 | - $type = $flux['args']['contexte'][$page]; |
|
| 141 | - if ($type!=='page' AND !isset($disponible[$type])) |
|
| 142 | - $disponible[$type] = z_contenu_disponible($prefix_path.$prepend,$z_contenu,$type,$ext,$echafauder); |
|
| 143 | - if ($type=='page' OR $disponible[$type]) |
|
| 144 | - $flux['data'] = z_trouver_bloc($prefix_path.$prepend,$dir,'dist',$ext); |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - $squelette = $flux['data']; |
|
| 148 | - } |
|
| 149 | - // layout specifiques par type et compositions : |
|
| 150 | - // body-article.html |
|
| 151 | - // body-sommaire.html |
|
| 152 | - // pour des raisons de perfo, les declinaisons doivent etre dans le |
|
| 153 | - // meme dossier que body.html |
|
| 154 | - if ($fond=='body' AND substr($squelette,-strlen($fond))==$fond){ |
|
| 155 | - if (isset($flux['args']['contexte']['type-page']) |
|
| 156 | - AND ( |
|
| 157 | - (isset($flux['args']['contexte']['composition']) |
|
| 158 | - AND file_exists(($f=$squelette."-".$flux['args']['contexte']['type-page']."-".$flux['args']['contexte']['composition']).".$ext")) |
|
| 159 | - OR |
|
| 160 | - file_exists(($f=$squelette."-".$flux['args']['contexte']['type-page']).".$ext") |
|
| 161 | - )) |
|
| 162 | - $flux['data'] = $f; |
|
| 163 | - } |
|
| 164 | - elseif ($fond=='structure' |
|
| 165 | - AND z_sanitize_var_zajax() |
|
| 166 | - AND $f = find_in_path($prefix_path.$prepend.'ajax'.".$ext")) { |
|
| 167 | - $flux['data'] = substr($f,0,-strlen(".$ext")); |
|
| 168 | - } |
|
| 169 | - // chercher le fond correspondant a la composition |
|
| 170 | - elseif (isset($flux['args']['contexte']['composition']) |
|
| 171 | - AND (basename($fond)=='page' OR ($squelette AND substr($squelette,-strlen($fond))==$fond)) |
|
| 172 | - AND $dir = substr($fond,$prefix_length) |
|
| 173 | - AND $dir = explode('/',$dir) |
|
| 174 | - AND $dir = reset($dir) |
|
| 175 | - AND in_array($dir,$z_blocs) |
|
| 176 | - AND $f=find_in_path($prefix_path.$prepend.$fond."-".$flux['args']['contexte']['composition'].".$ext")){ |
|
| 177 | - $flux['data'] = substr($f,0,-strlen(".$ext")); |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - return $flux; |
|
| 130 | + // sinon, si on demande un fond non trouve dans un des autres blocs |
|
| 131 | + // et si il y a bien un contenu correspondant ou echafaudable |
|
| 132 | + // se rabbatre sur le dist.html du bloc concerne |
|
| 133 | + else{ |
|
| 134 | + if ( $dir = explode('/',$fond) |
|
| 135 | + AND $dir = reset($dir) |
|
| 136 | + AND $dir !== $z_contenu |
|
| 137 | + AND in_array($dir,$z_blocs)){ |
|
| 138 | + $type = substr($fond,strlen("$dir/")); |
|
| 139 | + if (($type=='page') AND isset($flux['args']['contexte'][$page])) |
|
| 140 | + $type = $flux['args']['contexte'][$page]; |
|
| 141 | + if ($type!=='page' AND !isset($disponible[$type])) |
|
| 142 | + $disponible[$type] = z_contenu_disponible($prefix_path.$prepend,$z_contenu,$type,$ext,$echafauder); |
|
| 143 | + if ($type=='page' OR $disponible[$type]) |
|
| 144 | + $flux['data'] = z_trouver_bloc($prefix_path.$prepend,$dir,'dist',$ext); |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + $squelette = $flux['data']; |
|
| 148 | + } |
|
| 149 | + // layout specifiques par type et compositions : |
|
| 150 | + // body-article.html |
|
| 151 | + // body-sommaire.html |
|
| 152 | + // pour des raisons de perfo, les declinaisons doivent etre dans le |
|
| 153 | + // meme dossier que body.html |
|
| 154 | + if ($fond=='body' AND substr($squelette,-strlen($fond))==$fond){ |
|
| 155 | + if (isset($flux['args']['contexte']['type-page']) |
|
| 156 | + AND ( |
|
| 157 | + (isset($flux['args']['contexte']['composition']) |
|
| 158 | + AND file_exists(($f=$squelette."-".$flux['args']['contexte']['type-page']."-".$flux['args']['contexte']['composition']).".$ext")) |
|
| 159 | + OR |
|
| 160 | + file_exists(($f=$squelette."-".$flux['args']['contexte']['type-page']).".$ext") |
|
| 161 | + )) |
|
| 162 | + $flux['data'] = $f; |
|
| 163 | + } |
|
| 164 | + elseif ($fond=='structure' |
|
| 165 | + AND z_sanitize_var_zajax() |
|
| 166 | + AND $f = find_in_path($prefix_path.$prepend.'ajax'.".$ext")) { |
|
| 167 | + $flux['data'] = substr($f,0,-strlen(".$ext")); |
|
| 168 | + } |
|
| 169 | + // chercher le fond correspondant a la composition |
|
| 170 | + elseif (isset($flux['args']['contexte']['composition']) |
|
| 171 | + AND (basename($fond)=='page' OR ($squelette AND substr($squelette,-strlen($fond))==$fond)) |
|
| 172 | + AND $dir = substr($fond,$prefix_length) |
|
| 173 | + AND $dir = explode('/',$dir) |
|
| 174 | + AND $dir = reset($dir) |
|
| 175 | + AND in_array($dir,$z_blocs) |
|
| 176 | + AND $f=find_in_path($prefix_path.$prepend.$fond."-".$flux['args']['contexte']['composition'].".$ext")){ |
|
| 177 | + $flux['data'] = substr($f,0,-strlen(".$ext")); |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + return $flux; |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
@@ -187,9 +187,9 @@ discard block |
||
| 187 | 187 | * @return array |
| 188 | 188 | */ |
| 189 | 189 | function z_blocs($espace_prive=false) { |
| 190 | - if ($espace_prive) |
|
| 191 | - return (isset($GLOBALS['z_blocs_ecrire'])?$GLOBALS['z_blocs_ecrire']:array('contenu','navigation','extra','head','hierarchie','top')); |
|
| 192 | - return (isset($GLOBALS['z_blocs'])?$GLOBALS['z_blocs']:array('contenu')); |
|
| 190 | + if ($espace_prive) |
|
| 191 | + return (isset($GLOBALS['z_blocs_ecrire'])?$GLOBALS['z_blocs_ecrire']:array('contenu','navigation','extra','head','hierarchie','top')); |
|
| 192 | + return (isset($GLOBALS['z_blocs'])?$GLOBALS['z_blocs']:array('contenu')); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -204,16 +204,16 @@ discard block |
||
| 204 | 204 | * @return mixed |
| 205 | 205 | */ |
| 206 | 206 | function z_contenu_disponible($prefix_path,$z_contenu,$type,$ext,$echafauder=true){ |
| 207 | - if ($d = z_trouver_bloc($prefix_path,$z_contenu,$type,$ext)) |
|
| 208 | - return $d; |
|
| 209 | - return $echafauder?z_echafaudable($type):false; |
|
| 207 | + if ($d = z_trouver_bloc($prefix_path,$z_contenu,$type,$ext)) |
|
| 208 | + return $d; |
|
| 209 | + return $echafauder?z_echafaudable($type):false; |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | function z_fond_valide($squelette){ |
| 213 | - if (!_ZCORE_EXCLURE_PATH |
|
| 214 | - OR !preg_match(',('._ZCORE_EXCLURE_PATH.')/,',$squelette)) |
|
| 215 | - return true; |
|
| 216 | - return false; |
|
| 213 | + if (!_ZCORE_EXCLURE_PATH |
|
| 214 | + OR !preg_match(',('._ZCORE_EXCLURE_PATH.')/,',$squelette)) |
|
| 215 | + return true; |
|
| 216 | + return false; |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -233,13 +233,13 @@ discard block |
||
| 233 | 233 | * @return string |
| 234 | 234 | */ |
| 235 | 235 | function z_trouver_bloc($prefix_path,$bloc,$fond,$ext){ |
| 236 | - if ( |
|
| 237 | - (defined('_ZCORE_BLOC_PREFIX_SKEL') AND $f = find_in_path("$prefix_path$bloc/$bloc.$fond.$ext") AND z_fond_valide($f)) |
|
| 238 | - OR ($f = find_in_path("$prefix_path$bloc/$fond.$ext") AND z_fond_valide($f)) |
|
| 239 | - ){ |
|
| 240 | - return substr($f, 0, - strlen(".$ext")); |
|
| 241 | - } |
|
| 242 | - return ""; |
|
| 236 | + if ( |
|
| 237 | + (defined('_ZCORE_BLOC_PREFIX_SKEL') AND $f = find_in_path("$prefix_path$bloc/$bloc.$fond.$ext") AND z_fond_valide($f)) |
|
| 238 | + OR ($f = find_in_path("$prefix_path$bloc/$fond.$ext") AND z_fond_valide($f)) |
|
| 239 | + ){ |
|
| 240 | + return substr($f, 0, - strlen(".$ext")); |
|
| 241 | + } |
|
| 242 | + return ""; |
|
| 243 | 243 | } |
| 244 | 244 | /** |
| 245 | 245 | * Tester si un type est echafaudable |
@@ -250,43 +250,43 @@ discard block |
||
| 250 | 250 | * @return bool |
| 251 | 251 | */ |
| 252 | 252 | function z_echafaudable($type){ |
| 253 | - static $pages = null; |
|
| 254 | - static $echafaudable = array(); |
|
| 255 | - if (isset($echafaudable[$type])) |
|
| 256 | - return $echafaudable[$type]; |
|
| 257 | - if (preg_match(',[^\w],',$type)) |
|
| 258 | - return $echafaudable[$type] = false; |
|
| 253 | + static $pages = null; |
|
| 254 | + static $echafaudable = array(); |
|
| 255 | + if (isset($echafaudable[$type])) |
|
| 256 | + return $echafaudable[$type]; |
|
| 257 | + if (preg_match(',[^\w],',$type)) |
|
| 258 | + return $echafaudable[$type] = false; |
|
| 259 | 259 | |
| 260 | - if (test_espace_prive()){ |
|
| 261 | - if (!function_exists('trouver_objet_exec')) |
|
| 262 | - include_spip('inc/pipelines_ecrire'); |
|
| 263 | - if ($e=trouver_objet_exec($type)){ |
|
| 264 | - return $echafaudable[$type] = array($e['table'],$e['table_objet_sql'],$e); |
|
| 265 | - } |
|
| 266 | - else { |
|
| 267 | - // peut etre c'est un exec=types qui liste tous les objets "type" |
|
| 268 | - if (($t=objet_type($type,false))!==$type |
|
| 269 | - AND $e=trouver_objet_exec($t)){ |
|
| 270 | - return $echafaudable[$type] = array($e['table'],$e['table_objet_sql'],$t); |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - else { |
|
| 275 | - if (is_null($pages)) { |
|
| 276 | - $pages = array(); |
|
| 277 | - $liste = lister_tables_objets_sql(); |
|
| 278 | - foreach($liste as $t=>$d) |
|
| 279 | - if ($d['page']) $pages[$d['page']] = array($d['table_objet'],$t); |
|
| 280 | - } |
|
| 281 | - if (!isset($pages[$type])) |
|
| 282 | - return $echafaudable[$type] = false; |
|
| 283 | - if (count($pages[$type])==2){ |
|
| 284 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 285 | - $pages[$type][] = $trouver_table(reset($pages[$type])); |
|
| 286 | - } |
|
| 287 | - return $echafaudable[$type] = $pages[$type]; |
|
| 288 | - } |
|
| 289 | - return $echafaudable[$type] = false; |
|
| 260 | + if (test_espace_prive()){ |
|
| 261 | + if (!function_exists('trouver_objet_exec')) |
|
| 262 | + include_spip('inc/pipelines_ecrire'); |
|
| 263 | + if ($e=trouver_objet_exec($type)){ |
|
| 264 | + return $echafaudable[$type] = array($e['table'],$e['table_objet_sql'],$e); |
|
| 265 | + } |
|
| 266 | + else { |
|
| 267 | + // peut etre c'est un exec=types qui liste tous les objets "type" |
|
| 268 | + if (($t=objet_type($type,false))!==$type |
|
| 269 | + AND $e=trouver_objet_exec($t)){ |
|
| 270 | + return $echafaudable[$type] = array($e['table'],$e['table_objet_sql'],$t); |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + else { |
|
| 275 | + if (is_null($pages)) { |
|
| 276 | + $pages = array(); |
|
| 277 | + $liste = lister_tables_objets_sql(); |
|
| 278 | + foreach($liste as $t=>$d) |
|
| 279 | + if ($d['page']) $pages[$d['page']] = array($d['table_objet'],$t); |
|
| 280 | + } |
|
| 281 | + if (!isset($pages[$type])) |
|
| 282 | + return $echafaudable[$type] = false; |
|
| 283 | + if (count($pages[$type])==2){ |
|
| 284 | + $trouver_table = charger_fonction('trouver_table','base'); |
|
| 285 | + $pages[$type][] = $trouver_table(reset($pages[$type])); |
|
| 286 | + } |
|
| 287 | + return $echafaudable[$type] = $pages[$type]; |
|
| 288 | + } |
|
| 289 | + return $echafaudable[$type] = false; |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | |
@@ -303,45 +303,45 @@ discard block |
||
| 303 | 303 | * @return string |
| 304 | 304 | */ |
| 305 | 305 | function prive_echafauder_dist($exec,$table,$table_sql,$desc_exec,$ext){ |
| 306 | - $scaffold = ""; |
|
| 306 | + $scaffold = ""; |
|
| 307 | 307 | |
| 308 | - // page objet ou objet_edit |
|
| 309 | - if (is_array($desc_exec)) { |
|
| 310 | - $type = $desc_exec['type']; |
|
| 311 | - $primary = $desc_exec['id_table_objet']; |
|
| 308 | + // page objet ou objet_edit |
|
| 309 | + if (is_array($desc_exec)) { |
|
| 310 | + $type = $desc_exec['type']; |
|
| 311 | + $primary = $desc_exec['id_table_objet']; |
|
| 312 | 312 | |
| 313 | - if ($desc_exec['edition']===false) |
|
| 314 | - $fond = "objet"; |
|
| 315 | - else { |
|
| 316 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 317 | - $desc = $trouver_table($table_sql); |
|
| 318 | - if (isset($desc['field']['id_rubrique'])) |
|
| 319 | - $fond = 'objet_edit'; |
|
| 320 | - else |
|
| 321 | - $fond = 'objet_edit.sans_rubrique'; |
|
| 322 | - } |
|
| 323 | - $dir = z_blocs(test_espace_prive()); |
|
| 324 | - $dir = reset($dir); |
|
| 325 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/".$fond.",objet=".$type.",id_objet=#".strtoupper($primary).",env}>"; |
|
| 326 | - } |
|
| 327 | - // page objets |
|
| 328 | - elseif($type = $desc_exec AND strpos($type,"/")===false){ |
|
| 329 | - $dir = z_blocs(test_espace_prive()); |
|
| 330 | - $dir = reset($dir); |
|
| 331 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=".$type.",env} />"; |
|
| 332 | - } |
|
| 333 | - // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec |
|
| 334 | - // et objet et tire de $table |
|
| 335 | - elseif($fond = $desc_exec){ |
|
| 336 | - $dir = md5(dirname($fond)); |
|
| 337 | - $scaffold = "<INCLURE{fond=$fond,objet=".objet_type($table).",env} />"; |
|
| 338 | - } |
|
| 313 | + if ($desc_exec['edition']===false) |
|
| 314 | + $fond = "objet"; |
|
| 315 | + else { |
|
| 316 | + $trouver_table = charger_fonction('trouver_table','base'); |
|
| 317 | + $desc = $trouver_table($table_sql); |
|
| 318 | + if (isset($desc['field']['id_rubrique'])) |
|
| 319 | + $fond = 'objet_edit'; |
|
| 320 | + else |
|
| 321 | + $fond = 'objet_edit.sans_rubrique'; |
|
| 322 | + } |
|
| 323 | + $dir = z_blocs(test_espace_prive()); |
|
| 324 | + $dir = reset($dir); |
|
| 325 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/".$fond.",objet=".$type.",id_objet=#".strtoupper($primary).",env}>"; |
|
| 326 | + } |
|
| 327 | + // page objets |
|
| 328 | + elseif($type = $desc_exec AND strpos($type,"/")===false){ |
|
| 329 | + $dir = z_blocs(test_espace_prive()); |
|
| 330 | + $dir = reset($dir); |
|
| 331 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=".$type.",env} />"; |
|
| 332 | + } |
|
| 333 | + // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec |
|
| 334 | + // et objet et tire de $table |
|
| 335 | + elseif($fond = $desc_exec){ |
|
| 336 | + $dir = md5(dirname($fond)); |
|
| 337 | + $scaffold = "<INCLURE{fond=$fond,objet=".objet_type($table).",env} />"; |
|
| 338 | + } |
|
| 339 | 339 | |
| 340 | - $base_dir = sous_repertoire(_DIR_CACHE,"scaffold",false); |
|
| 341 | - $base_dir = sous_repertoire($base_dir,$dir,false); |
|
| 342 | - $f = $base_dir."$exec"; |
|
| 343 | - ecrire_fichier("$f.$ext",$scaffold); |
|
| 344 | - return $f; |
|
| 340 | + $base_dir = sous_repertoire(_DIR_CACHE,"scaffold",false); |
|
| 341 | + $base_dir = sous_repertoire($base_dir,$dir,false); |
|
| 342 | + $f = $base_dir."$exec"; |
|
| 343 | + ecrire_fichier("$f.$ext",$scaffold); |
|
| 344 | + return $f; |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | /** |
@@ -349,13 +349,13 @@ discard block |
||
| 349 | 349 | * @return bool|string |
| 350 | 350 | */ |
| 351 | 351 | function z_sanitize_var_zajax(){ |
| 352 | - $z_ajax = _request('var_zajax'); |
|
| 353 | - if (!$z_ajax) return false; |
|
| 354 | - if (!$z_blocs = z_blocs(test_espace_prive()) |
|
| 355 | - OR !in_array($z_ajax,$z_blocs)) { |
|
| 356 | - set_request('var_zajax'); // enlever cette demande incongrue |
|
| 357 | - $z_ajax = false; |
|
| 358 | - } |
|
| 359 | - return $z_ajax; |
|
| 352 | + $z_ajax = _request('var_zajax'); |
|
| 353 | + if (!$z_ajax) return false; |
|
| 354 | + if (!$z_blocs = z_blocs(test_espace_prive()) |
|
| 355 | + OR !in_array($z_ajax,$z_blocs)) { |
|
| 356 | + set_request('var_zajax'); // enlever cette demande incongrue |
|
| 357 | + $z_ajax = false; |
|
| 358 | + } |
|
| 359 | + return $z_ajax; |
|
| 360 | 360 | } |
| 361 | 361 | ?> |
@@ -11,7 +11,9 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | |
| 14 | -if (!defined("_ECRIRE_INC_VERSION")) return; |
|
| 14 | +if (!defined("_ECRIRE_INC_VERSION")) { |
|
| 15 | + return; |
|
| 16 | +} |
|
| 15 | 17 | |
| 16 | 18 | /** |
| 17 | 19 | * Fonction Page automatique a partir de contenu/xx |
@@ -38,8 +40,7 @@ discard block |
||
| 38 | 40 | $page = 'exec'; |
| 39 | 41 | $echafauder = charger_fonction('echafauder','prive',true); |
| 40 | 42 | define('_ZCORE_EXCLURE_PATH',''); |
| 41 | - } |
|
| 42 | - else { |
|
| 43 | + } else { |
|
| 43 | 44 | $prefix_path = ""; |
| 44 | 45 | $prefix_length = 0; |
| 45 | 46 | $apl_constant = '_Z_AJAX_PARALLEL_LOAD'; |
@@ -78,8 +79,9 @@ discard block |
||
| 78 | 79 | } |
| 79 | 80 | if ($prepend){ |
| 80 | 81 | $squelette = substr(find_in_path($prefix_path.$prepend."$fond.$ext"), 0, - strlen(".$ext")); |
| 81 | - if ($squelette) |
|
| 82 | - $flux['data'] = $squelette; |
|
| 82 | + if ($squelette) { |
|
| 83 | + $flux['data'] = $squelette; |
|
| 84 | + } |
|
| 83 | 85 | } |
| 84 | 86 | |
| 85 | 87 | // gerer les squelettes non trouves |
@@ -95,11 +97,13 @@ discard block |
||
| 95 | 97 | // si on est sur un ?page=XX non trouve |
| 96 | 98 | // se brancher sur contenu/xx si il existe |
| 97 | 99 | // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
| 98 | - if (!isset($disponible[$fond])) |
|
| 99 | - $disponible[$fond] = z_contenu_disponible($prefix_path.$prepend,$z_contenu,$fond,$ext,$echafauder); |
|
| 100 | + if (!isset($disponible[$fond])) { |
|
| 101 | + $disponible[$fond] = z_contenu_disponible($prefix_path.$prepend,$z_contenu,$fond,$ext,$echafauder); |
|
| 102 | + } |
|
| 100 | 103 | |
| 101 | - if ($disponible[$fond]) |
|
| 102 | - $flux['data'] = substr(find_in_path($prefix_path."page.$ext"), 0, - strlen(".$ext")); |
|
| 104 | + if ($disponible[$fond]) { |
|
| 105 | + $flux['data'] = substr(find_in_path($prefix_path."page.$ext"), 0, - strlen(".$ext")); |
|
| 106 | + } |
|
| 103 | 107 | } |
| 104 | 108 | |
| 105 | 109 | // echafaudage : |
@@ -107,22 +111,22 @@ discard block |
||
| 107 | 111 | // generer un fond automatique a la volee pour les webmestres |
| 108 | 112 | elseif (strncmp($fond, "$z_contenu/", strlen($z_contenu)+1)==0){ |
| 109 | 113 | $type = substr($fond,strlen($z_contenu)+1); |
| 110 | - if (($type=='page') AND isset($flux['args']['contexte'][$page])) |
|
| 111 | - $type = $flux['args']['contexte'][$page]; |
|
| 112 | - if (!isset($disponible[$type])) |
|
| 113 | - $disponible[$type] = z_contenu_disponible($prefix_path.$prepend,$z_contenu,$type,$ext,$echafauder); |
|
| 114 | + if (($type=='page') AND isset($flux['args']['contexte'][$page])) { |
|
| 115 | + $type = $flux['args']['contexte'][$page]; |
|
| 116 | + } |
|
| 117 | + if (!isset($disponible[$type])) { |
|
| 118 | + $disponible[$type] = z_contenu_disponible($prefix_path.$prepend,$z_contenu,$type,$ext,$echafauder); |
|
| 119 | + } |
|
| 114 | 120 | if (is_string($disponible[$type])) { |
| 115 | 121 | $flux['data'] = $disponible[$type]; |
| 116 | - } |
|
| 117 | - elseif ($echafauder |
|
| 122 | + } elseif ($echafauder |
|
| 118 | 123 | AND include_spip('inc/autoriser') |
| 119 | 124 | AND isset($GLOBALS['visiteur_session']['statut']) // performance |
| 120 | 125 | AND autoriser('echafauder',$type) |
| 121 | 126 | AND $is = $disponible[$type] |
| 122 | 127 | AND is_array($is)) { |
| 123 | 128 | $flux['data'] = $echafauder($type,$is[0],$is[1],$is[2],$ext); |
| 124 | - } |
|
| 125 | - else{ |
|
| 129 | + } else{ |
|
| 126 | 130 | $flux['data'] = ($disponible['404'] = z_contenu_disponible($prefix_path.$prepend,$z_contenu,'404',$ext,$echafauder)); |
| 127 | 131 | } |
| 128 | 132 | } |
@@ -136,12 +140,15 @@ discard block |
||
| 136 | 140 | AND $dir !== $z_contenu |
| 137 | 141 | AND in_array($dir,$z_blocs)){ |
| 138 | 142 | $type = substr($fond,strlen("$dir/")); |
| 139 | - if (($type=='page') AND isset($flux['args']['contexte'][$page])) |
|
| 140 | - $type = $flux['args']['contexte'][$page]; |
|
| 141 | - if ($type!=='page' AND !isset($disponible[$type])) |
|
| 142 | - $disponible[$type] = z_contenu_disponible($prefix_path.$prepend,$z_contenu,$type,$ext,$echafauder); |
|
| 143 | - if ($type=='page' OR $disponible[$type]) |
|
| 144 | - $flux['data'] = z_trouver_bloc($prefix_path.$prepend,$dir,'dist',$ext); |
|
| 143 | + if (($type=='page') AND isset($flux['args']['contexte'][$page])) { |
|
| 144 | + $type = $flux['args']['contexte'][$page]; |
|
| 145 | + } |
|
| 146 | + if ($type!=='page' AND !isset($disponible[$type])) { |
|
| 147 | + $disponible[$type] = z_contenu_disponible($prefix_path.$prepend,$z_contenu,$type,$ext,$echafauder); |
|
| 148 | + } |
|
| 149 | + if ($type=='page' OR $disponible[$type]) { |
|
| 150 | + $flux['data'] = z_trouver_bloc($prefix_path.$prepend,$dir,'dist',$ext); |
|
| 151 | + } |
|
| 145 | 152 | } |
| 146 | 153 | } |
| 147 | 154 | $squelette = $flux['data']; |
@@ -158,10 +165,10 @@ discard block |
||
| 158 | 165 | AND file_exists(($f=$squelette."-".$flux['args']['contexte']['type-page']."-".$flux['args']['contexte']['composition']).".$ext")) |
| 159 | 166 | OR |
| 160 | 167 | file_exists(($f=$squelette."-".$flux['args']['contexte']['type-page']).".$ext") |
| 161 | - )) |
|
| 162 | - $flux['data'] = $f; |
|
| 163 | - } |
|
| 164 | - elseif ($fond=='structure' |
|
| 168 | + )) { |
|
| 169 | + $flux['data'] = $f; |
|
| 170 | + } |
|
| 171 | + } elseif ($fond=='structure' |
|
| 165 | 172 | AND z_sanitize_var_zajax() |
| 166 | 173 | AND $f = find_in_path($prefix_path.$prepend.'ajax'.".$ext")) { |
| 167 | 174 | $flux['data'] = substr($f,0,-strlen(".$ext")); |
@@ -187,8 +194,9 @@ discard block |
||
| 187 | 194 | * @return array |
| 188 | 195 | */ |
| 189 | 196 | function z_blocs($espace_prive=false) { |
| 190 | - if ($espace_prive) |
|
| 191 | - return (isset($GLOBALS['z_blocs_ecrire'])?$GLOBALS['z_blocs_ecrire']:array('contenu','navigation','extra','head','hierarchie','top')); |
|
| 197 | + if ($espace_prive) { |
|
| 198 | + return (isset($GLOBALS['z_blocs_ecrire'])?$GLOBALS['z_blocs_ecrire']:array('contenu','navigation','extra','head','hierarchie','top')); |
|
| 199 | + } |
|
| 192 | 200 | return (isset($GLOBALS['z_blocs'])?$GLOBALS['z_blocs']:array('contenu')); |
| 193 | 201 | } |
| 194 | 202 | |
@@ -204,15 +212,17 @@ discard block |
||
| 204 | 212 | * @return mixed |
| 205 | 213 | */ |
| 206 | 214 | function z_contenu_disponible($prefix_path,$z_contenu,$type,$ext,$echafauder=true){ |
| 207 | - if ($d = z_trouver_bloc($prefix_path,$z_contenu,$type,$ext)) |
|
| 208 | - return $d; |
|
| 215 | + if ($d = z_trouver_bloc($prefix_path,$z_contenu,$type,$ext)) { |
|
| 216 | + return $d; |
|
| 217 | + } |
|
| 209 | 218 | return $echafauder?z_echafaudable($type):false; |
| 210 | 219 | } |
| 211 | 220 | |
| 212 | 221 | function z_fond_valide($squelette){ |
| 213 | 222 | if (!_ZCORE_EXCLURE_PATH |
| 214 | - OR !preg_match(',('._ZCORE_EXCLURE_PATH.')/,',$squelette)) |
|
| 215 | - return true; |
|
| 223 | + OR !preg_match(',('._ZCORE_EXCLURE_PATH.')/,',$squelette)) { |
|
| 224 | + return true; |
|
| 225 | + } |
|
| 216 | 226 | return false; |
| 217 | 227 | } |
| 218 | 228 | |
@@ -252,34 +262,37 @@ discard block |
||
| 252 | 262 | function z_echafaudable($type){ |
| 253 | 263 | static $pages = null; |
| 254 | 264 | static $echafaudable = array(); |
| 255 | - if (isset($echafaudable[$type])) |
|
| 256 | - return $echafaudable[$type]; |
|
| 257 | - if (preg_match(',[^\w],',$type)) |
|
| 258 | - return $echafaudable[$type] = false; |
|
| 265 | + if (isset($echafaudable[$type])) { |
|
| 266 | + return $echafaudable[$type]; |
|
| 267 | + } |
|
| 268 | + if (preg_match(',[^\w],',$type)) { |
|
| 269 | + return $echafaudable[$type] = false; |
|
| 270 | + } |
|
| 259 | 271 | |
| 260 | 272 | if (test_espace_prive()){ |
| 261 | - if (!function_exists('trouver_objet_exec')) |
|
| 262 | - include_spip('inc/pipelines_ecrire'); |
|
| 273 | + if (!function_exists('trouver_objet_exec')) { |
|
| 274 | + include_spip('inc/pipelines_ecrire'); |
|
| 275 | + } |
|
| 263 | 276 | if ($e=trouver_objet_exec($type)){ |
| 264 | 277 | return $echafaudable[$type] = array($e['table'],$e['table_objet_sql'],$e); |
| 265 | - } |
|
| 266 | - else { |
|
| 278 | + } else { |
|
| 267 | 279 | // peut etre c'est un exec=types qui liste tous les objets "type" |
| 268 | 280 | if (($t=objet_type($type,false))!==$type |
| 269 | 281 | AND $e=trouver_objet_exec($t)){ |
| 270 | 282 | return $echafaudable[$type] = array($e['table'],$e['table_objet_sql'],$t); |
| 271 | 283 | } |
| 272 | 284 | } |
| 273 | - } |
|
| 274 | - else { |
|
| 285 | + } else { |
|
| 275 | 286 | if (is_null($pages)) { |
| 276 | 287 | $pages = array(); |
| 277 | 288 | $liste = lister_tables_objets_sql(); |
| 278 | - foreach($liste as $t=>$d) |
|
| 279 | - if ($d['page']) $pages[$d['page']] = array($d['table_objet'],$t); |
|
| 289 | + foreach($liste as $t=>$d) { |
|
| 290 | + if ($d['page']) $pages[$d['page']] = array($d['table_objet'],$t); |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + if (!isset($pages[$type])) { |
|
| 294 | + return $echafaudable[$type] = false; |
|
| 280 | 295 | } |
| 281 | - if (!isset($pages[$type])) |
|
| 282 | - return $echafaudable[$type] = false; |
|
| 283 | 296 | if (count($pages[$type])==2){ |
| 284 | 297 | $trouver_table = charger_fonction('trouver_table','base'); |
| 285 | 298 | $pages[$type][] = $trouver_table(reset($pages[$type])); |
@@ -310,15 +323,16 @@ discard block |
||
| 310 | 323 | $type = $desc_exec['type']; |
| 311 | 324 | $primary = $desc_exec['id_table_objet']; |
| 312 | 325 | |
| 313 | - if ($desc_exec['edition']===false) |
|
| 314 | - $fond = "objet"; |
|
| 315 | - else { |
|
| 326 | + if ($desc_exec['edition']===false) { |
|
| 327 | + $fond = "objet"; |
|
| 328 | + } else { |
|
| 316 | 329 | $trouver_table = charger_fonction('trouver_table','base'); |
| 317 | 330 | $desc = $trouver_table($table_sql); |
| 318 | - if (isset($desc['field']['id_rubrique'])) |
|
| 319 | - $fond = 'objet_edit'; |
|
| 320 | - else |
|
| 321 | - $fond = 'objet_edit.sans_rubrique'; |
|
| 331 | + if (isset($desc['field']['id_rubrique'])) { |
|
| 332 | + $fond = 'objet_edit'; |
|
| 333 | + } else { |
|
| 334 | + $fond = 'objet_edit.sans_rubrique'; |
|
| 335 | + } |
|
| 322 | 336 | } |
| 323 | 337 | $dir = z_blocs(test_espace_prive()); |
| 324 | 338 | $dir = reset($dir); |
@@ -350,7 +364,9 @@ discard block |
||
| 350 | 364 | */ |
| 351 | 365 | function z_sanitize_var_zajax(){ |
| 352 | 366 | $z_ajax = _request('var_zajax'); |
| 353 | - if (!$z_ajax) return false; |
|
| 367 | + if (!$z_ajax) { |
|
| 368 | + return false; |
|
| 369 | + } |
|
| 354 | 370 | if (!$z_blocs = z_blocs(test_espace_prive()) |
| 355 | 371 | OR !in_array($z_ajax,$z_blocs)) { |
| 356 | 372 | set_request('var_zajax'); // enlever cette demande incongrue |
@@ -19,8 +19,8 @@ discard block |
||
| 19 | 19 | * @param array $flux |
| 20 | 20 | * @return array |
| 21 | 21 | */ |
| 22 | -function public_styliser_par_z_dist($flux){ |
|
| 23 | - static $prefix_path=null; |
|
| 22 | +function public_styliser_par_z_dist($flux) { |
|
| 23 | + static $prefix_path = null; |
|
| 24 | 24 | static $prefix_length; |
| 25 | 25 | static $z_blocs; |
| 26 | 26 | static $apl_constant; |
@@ -31,52 +31,52 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | if (!isset($prefix_path)) { |
| 33 | 33 | $z_blocs = z_blocs(test_espace_prive()); |
| 34 | - if (test_espace_prive ()){ |
|
| 34 | + if (test_espace_prive()) { |
|
| 35 | 35 | $prefix_path = "prive/squelettes/"; |
| 36 | 36 | $prefix_length = strlen($prefix_path); |
| 37 | 37 | $apl_constant = '_ECRIRE_AJAX_PARALLEL_LOAD'; |
| 38 | 38 | $page = 'exec'; |
| 39 | - $echafauder = charger_fonction('echafauder','prive',true); |
|
| 40 | - define('_ZCORE_EXCLURE_PATH',''); |
|
| 39 | + $echafauder = charger_fonction('echafauder', 'prive', true); |
|
| 40 | + define('_ZCORE_EXCLURE_PATH', ''); |
|
| 41 | 41 | } |
| 42 | 42 | else { |
| 43 | 43 | $prefix_path = ""; |
| 44 | 44 | $prefix_length = 0; |
| 45 | 45 | $apl_constant = '_Z_AJAX_PARALLEL_LOAD'; |
| 46 | 46 | $page = _SPIP_PAGE; |
| 47 | - $echafauder = charger_fonction('echafauder','public',true); |
|
| 48 | - define('_ZCORE_EXCLURE_PATH','\bprive|\bsquelettes-dist'.(defined('_DIR_PLUGIN_DIST')?'|\b'.rtrim(_DIR_PLUGIN_DIST,'/'):'')); |
|
| 47 | + $echafauder = charger_fonction('echafauder', 'public', true); |
|
| 48 | + define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist'.(defined('_DIR_PLUGIN_DIST') ? '|\b'.rtrim(_DIR_PLUGIN_DIST, '/') : '')); |
|
| 49 | 49 | } |
| 50 | - $prepend = (defined('_Z_PREPEND_PATH')?_Z_PREPEND_PATH:""); |
|
| 50 | + $prepend = (defined('_Z_PREPEND_PATH') ?_Z_PREPEND_PATH:""); |
|
| 51 | 51 | } |
| 52 | 52 | $z_contenu = reset($z_blocs); // contenu par defaut |
| 53 | 53 | |
| 54 | 54 | $fond = $flux['args']['fond']; |
| 55 | 55 | |
| 56 | - if ($prepend OR strncmp($fond,$prefix_path,$prefix_length)==0) { |
|
| 56 | + if ($prepend OR strncmp($fond, $prefix_path, $prefix_length) == 0) { |
|
| 57 | 57 | $fond = substr($fond, $prefix_length); |
| 58 | 58 | $squelette = $flux['data']; |
| 59 | 59 | $ext = $flux['args']['ext']; |
| 60 | 60 | // Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera en ajax |
| 61 | 61 | if (defined('_Z_AJAX_PARALLEL_LOAD_OK') |
| 62 | - AND $dir = explode('/',$fond) |
|
| 63 | - AND count($dir)==2 // pas un sous repertoire |
|
| 62 | + AND $dir = explode('/', $fond) |
|
| 63 | + AND count($dir) == 2 // pas un sous repertoire |
|
| 64 | 64 | AND $dir = reset($dir) |
| 65 | - AND in_array($dir,$z_blocs) // verifier deja qu'on est dans un bloc Z |
|
| 65 | + AND in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z |
|
| 66 | 66 | AND defined($apl_constant) |
| 67 | - AND in_array($dir,explode(',',constant($apl_constant))) // et dans un demande en APL |
|
| 68 | - AND $pipe = z_trouver_bloc($prefix_path.$prepend,$dir,'z_apl',$ext) // et qui contient le squelette APL |
|
| 69 | - ){ |
|
| 67 | + AND in_array($dir, explode(',', constant($apl_constant))) // et dans un demande en APL |
|
| 68 | + AND $pipe = z_trouver_bloc($prefix_path.$prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL |
|
| 69 | + ) { |
|
| 70 | 70 | $flux['data'] = $pipe; |
| 71 | 71 | return $flux; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | // surcharger aussi les squelettes venant de squelettes-dist/ |
| 75 | - if ($squelette AND !z_fond_valide($squelette)){ |
|
| 75 | + if ($squelette AND !z_fond_valide($squelette)) { |
|
| 76 | 76 | $squelette = ""; |
| 77 | 77 | $echafauder = ""; |
| 78 | 78 | } |
| 79 | - if ($prepend){ |
|
| 79 | + if ($prepend) { |
|
| 80 | 80 | $squelette = substr(find_in_path($prefix_path.$prepend."$fond.$ext"), 0, - strlen(".$ext")); |
| 81 | 81 | if ($squelette) |
| 82 | 82 | $flux['data'] = $squelette; |
@@ -85,18 +85,18 @@ discard block |
||
| 85 | 85 | // gerer les squelettes non trouves |
| 86 | 86 | // -> router vers les /dist.html |
| 87 | 87 | // ou scaffolding ou page automatique les contenus |
| 88 | - if (!$squelette){ |
|
| 88 | + if (!$squelette) { |
|
| 89 | 89 | |
| 90 | 90 | // si on est sur un ?page=XX non trouve |
| 91 | 91 | if ($flux['args']['contexte'][$page] == $fond |
| 92 | 92 | OR $flux['args']['contexte']['type-page'] == $fond |
| 93 | - OR ($fond=='sommaire' AND !$flux['args']['contexte'][$page])) { |
|
| 93 | + OR ($fond == 'sommaire' AND !$flux['args']['contexte'][$page])) { |
|
| 94 | 94 | |
| 95 | 95 | // si on est sur un ?page=XX non trouve |
| 96 | 96 | // se brancher sur contenu/xx si il existe |
| 97 | 97 | // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
| 98 | 98 | if (!isset($disponible[$fond])) |
| 99 | - $disponible[$fond] = z_contenu_disponible($prefix_path.$prepend,$z_contenu,$fond,$ext,$echafauder); |
|
| 99 | + $disponible[$fond] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 100 | 100 | |
| 101 | 101 | if ($disponible[$fond]) |
| 102 | 102 | $flux['data'] = substr(find_in_path($prefix_path."page.$ext"), 0, - strlen(".$ext")); |
@@ -105,43 +105,43 @@ discard block |
||
| 105 | 105 | // echafaudage : |
| 106 | 106 | // si c'est un fond de contenu d'un objet en base |
| 107 | 107 | // generer un fond automatique a la volee pour les webmestres |
| 108 | - elseif (strncmp($fond, "$z_contenu/", strlen($z_contenu)+1)==0){ |
|
| 109 | - $type = substr($fond,strlen($z_contenu)+1); |
|
| 110 | - if (($type=='page') AND isset($flux['args']['contexte'][$page])) |
|
| 108 | + elseif (strncmp($fond, "$z_contenu/", strlen($z_contenu) + 1) == 0) { |
|
| 109 | + $type = substr($fond, strlen($z_contenu) + 1); |
|
| 110 | + if (($type == 'page') AND isset($flux['args']['contexte'][$page])) |
|
| 111 | 111 | $type = $flux['args']['contexte'][$page]; |
| 112 | 112 | if (!isset($disponible[$type])) |
| 113 | - $disponible[$type] = z_contenu_disponible($prefix_path.$prepend,$z_contenu,$type,$ext,$echafauder); |
|
| 113 | + $disponible[$type] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 114 | 114 | if (is_string($disponible[$type])) { |
| 115 | 115 | $flux['data'] = $disponible[$type]; |
| 116 | 116 | } |
| 117 | 117 | elseif ($echafauder |
| 118 | 118 | AND include_spip('inc/autoriser') |
| 119 | 119 | AND isset($GLOBALS['visiteur_session']['statut']) // performance |
| 120 | - AND autoriser('echafauder',$type) |
|
| 120 | + AND autoriser('echafauder', $type) |
|
| 121 | 121 | AND $is = $disponible[$type] |
| 122 | 122 | AND is_array($is)) { |
| 123 | - $flux['data'] = $echafauder($type,$is[0],$is[1],$is[2],$ext); |
|
| 123 | + $flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext); |
|
| 124 | 124 | } |
| 125 | - else{ |
|
| 126 | - $flux['data'] = ($disponible['404'] = z_contenu_disponible($prefix_path.$prepend,$z_contenu,'404',$ext,$echafauder)); |
|
| 125 | + else { |
|
| 126 | + $flux['data'] = ($disponible['404'] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, '404', $ext, $echafauder)); |
|
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | // sinon, si on demande un fond non trouve dans un des autres blocs |
| 131 | 131 | // et si il y a bien un contenu correspondant ou echafaudable |
| 132 | 132 | // se rabbatre sur le dist.html du bloc concerne |
| 133 | - else{ |
|
| 134 | - if ( $dir = explode('/',$fond) |
|
| 133 | + else { |
|
| 134 | + if ($dir = explode('/', $fond) |
|
| 135 | 135 | AND $dir = reset($dir) |
| 136 | 136 | AND $dir !== $z_contenu |
| 137 | - AND in_array($dir,$z_blocs)){ |
|
| 138 | - $type = substr($fond,strlen("$dir/")); |
|
| 139 | - if (($type=='page') AND isset($flux['args']['contexte'][$page])) |
|
| 137 | + AND in_array($dir, $z_blocs)) { |
|
| 138 | + $type = substr($fond, strlen("$dir/")); |
|
| 139 | + if (($type == 'page') AND isset($flux['args']['contexte'][$page])) |
|
| 140 | 140 | $type = $flux['args']['contexte'][$page]; |
| 141 | - if ($type!=='page' AND !isset($disponible[$type])) |
|
| 142 | - $disponible[$type] = z_contenu_disponible($prefix_path.$prepend,$z_contenu,$type,$ext,$echafauder); |
|
| 143 | - if ($type=='page' OR $disponible[$type]) |
|
| 144 | - $flux['data'] = z_trouver_bloc($prefix_path.$prepend,$dir,'dist',$ext); |
|
| 141 | + if ($type !== 'page' AND !isset($disponible[$type])) |
|
| 142 | + $disponible[$type] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 143 | + if ($type == 'page' OR $disponible[$type]) |
|
| 144 | + $flux['data'] = z_trouver_bloc($prefix_path.$prepend, $dir, 'dist', $ext); |
|
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | $squelette = $flux['data']; |
@@ -151,30 +151,30 @@ discard block |
||
| 151 | 151 | // body-sommaire.html |
| 152 | 152 | // pour des raisons de perfo, les declinaisons doivent etre dans le |
| 153 | 153 | // meme dossier que body.html |
| 154 | - if ($fond=='body' AND substr($squelette,-strlen($fond))==$fond){ |
|
| 154 | + if ($fond == 'body' AND substr($squelette, -strlen($fond)) == $fond) { |
|
| 155 | 155 | if (isset($flux['args']['contexte']['type-page']) |
| 156 | 156 | AND ( |
| 157 | 157 | (isset($flux['args']['contexte']['composition']) |
| 158 | - AND file_exists(($f=$squelette."-".$flux['args']['contexte']['type-page']."-".$flux['args']['contexte']['composition']).".$ext")) |
|
| 158 | + AND file_exists(($f = $squelette."-".$flux['args']['contexte']['type-page']."-".$flux['args']['contexte']['composition']).".$ext")) |
|
| 159 | 159 | OR |
| 160 | - file_exists(($f=$squelette."-".$flux['args']['contexte']['type-page']).".$ext") |
|
| 160 | + file_exists(($f = $squelette."-".$flux['args']['contexte']['type-page']).".$ext") |
|
| 161 | 161 | )) |
| 162 | 162 | $flux['data'] = $f; |
| 163 | 163 | } |
| 164 | - elseif ($fond=='structure' |
|
| 164 | + elseif ($fond == 'structure' |
|
| 165 | 165 | AND z_sanitize_var_zajax() |
| 166 | 166 | AND $f = find_in_path($prefix_path.$prepend.'ajax'.".$ext")) { |
| 167 | - $flux['data'] = substr($f,0,-strlen(".$ext")); |
|
| 167 | + $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 168 | 168 | } |
| 169 | 169 | // chercher le fond correspondant a la composition |
| 170 | 170 | elseif (isset($flux['args']['contexte']['composition']) |
| 171 | - AND (basename($fond)=='page' OR ($squelette AND substr($squelette,-strlen($fond))==$fond)) |
|
| 172 | - AND $dir = substr($fond,$prefix_length) |
|
| 173 | - AND $dir = explode('/',$dir) |
|
| 171 | + AND (basename($fond) == 'page' OR ($squelette AND substr($squelette, -strlen($fond)) == $fond)) |
|
| 172 | + AND $dir = substr($fond, $prefix_length) |
|
| 173 | + AND $dir = explode('/', $dir) |
|
| 174 | 174 | AND $dir = reset($dir) |
| 175 | - AND in_array($dir,$z_blocs) |
|
| 176 | - AND $f=find_in_path($prefix_path.$prepend.$fond."-".$flux['args']['contexte']['composition'].".$ext")){ |
|
| 177 | - $flux['data'] = substr($f,0,-strlen(".$ext")); |
|
| 175 | + AND in_array($dir, $z_blocs) |
|
| 176 | + AND $f = find_in_path($prefix_path.$prepend.$fond."-".$flux['args']['contexte']['composition'].".$ext")) { |
|
| 177 | + $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | return $flux; |
@@ -186,10 +186,10 @@ discard block |
||
| 186 | 186 | * @param bool $espace_prive |
| 187 | 187 | * @return array |
| 188 | 188 | */ |
| 189 | -function z_blocs($espace_prive=false) { |
|
| 189 | +function z_blocs($espace_prive = false) { |
|
| 190 | 190 | if ($espace_prive) |
| 191 | - return (isset($GLOBALS['z_blocs_ecrire'])?$GLOBALS['z_blocs_ecrire']:array('contenu','navigation','extra','head','hierarchie','top')); |
|
| 192 | - return (isset($GLOBALS['z_blocs'])?$GLOBALS['z_blocs']:array('contenu')); |
|
| 191 | + return (isset($GLOBALS['z_blocs_ecrire']) ? $GLOBALS['z_blocs_ecrire'] : array('contenu', 'navigation', 'extra', 'head', 'hierarchie', 'top')); |
|
| 192 | + return (isset($GLOBALS['z_blocs']) ? $GLOBALS['z_blocs'] : array('contenu')); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -203,15 +203,15 @@ discard block |
||
| 203 | 203 | * @param bool $echafauder |
| 204 | 204 | * @return mixed |
| 205 | 205 | */ |
| 206 | -function z_contenu_disponible($prefix_path,$z_contenu,$type,$ext,$echafauder=true){ |
|
| 207 | - if ($d = z_trouver_bloc($prefix_path,$z_contenu,$type,$ext)) |
|
| 206 | +function z_contenu_disponible($prefix_path, $z_contenu, $type, $ext, $echafauder = true) { |
|
| 207 | + if ($d = z_trouver_bloc($prefix_path, $z_contenu, $type, $ext)) |
|
| 208 | 208 | return $d; |
| 209 | - return $echafauder?z_echafaudable($type):false; |
|
| 209 | + return $echafauder ?z_echafaudable($type) : false; |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | -function z_fond_valide($squelette){ |
|
| 212 | +function z_fond_valide($squelette) { |
|
| 213 | 213 | if (!_ZCORE_EXCLURE_PATH |
| 214 | - OR !preg_match(',('._ZCORE_EXCLURE_PATH.')/,',$squelette)) |
|
| 214 | + OR !preg_match(',('._ZCORE_EXCLURE_PATH.')/,', $squelette)) |
|
| 215 | 215 | return true; |
| 216 | 216 | return false; |
| 217 | 217 | } |
@@ -232,11 +232,11 @@ discard block |
||
| 232 | 232 | * extension du squelette |
| 233 | 233 | * @return string |
| 234 | 234 | */ |
| 235 | -function z_trouver_bloc($prefix_path,$bloc,$fond,$ext){ |
|
| 235 | +function z_trouver_bloc($prefix_path, $bloc, $fond, $ext) { |
|
| 236 | 236 | if ( |
| 237 | 237 | (defined('_ZCORE_BLOC_PREFIX_SKEL') AND $f = find_in_path("$prefix_path$bloc/$bloc.$fond.$ext") AND z_fond_valide($f)) |
| 238 | 238 | OR ($f = find_in_path("$prefix_path$bloc/$fond.$ext") AND z_fond_valide($f)) |
| 239 | - ){ |
|
| 239 | + ) { |
|
| 240 | 240 | return substr($f, 0, - strlen(".$ext")); |
| 241 | 241 | } |
| 242 | 242 | return ""; |
@@ -249,25 +249,25 @@ discard block |
||
| 249 | 249 | * @param string $type |
| 250 | 250 | * @return bool |
| 251 | 251 | */ |
| 252 | -function z_echafaudable($type){ |
|
| 252 | +function z_echafaudable($type) { |
|
| 253 | 253 | static $pages = null; |
| 254 | 254 | static $echafaudable = array(); |
| 255 | 255 | if (isset($echafaudable[$type])) |
| 256 | 256 | return $echafaudable[$type]; |
| 257 | - if (preg_match(',[^\w],',$type)) |
|
| 257 | + if (preg_match(',[^\w],', $type)) |
|
| 258 | 258 | return $echafaudable[$type] = false; |
| 259 | 259 | |
| 260 | - if (test_espace_prive()){ |
|
| 260 | + if (test_espace_prive()) { |
|
| 261 | 261 | if (!function_exists('trouver_objet_exec')) |
| 262 | 262 | include_spip('inc/pipelines_ecrire'); |
| 263 | - if ($e=trouver_objet_exec($type)){ |
|
| 264 | - return $echafaudable[$type] = array($e['table'],$e['table_objet_sql'],$e); |
|
| 263 | + if ($e = trouver_objet_exec($type)) { |
|
| 264 | + return $echafaudable[$type] = array($e['table'], $e['table_objet_sql'], $e); |
|
| 265 | 265 | } |
| 266 | 266 | else { |
| 267 | 267 | // peut etre c'est un exec=types qui liste tous les objets "type" |
| 268 | - if (($t=objet_type($type,false))!==$type |
|
| 269 | - AND $e=trouver_objet_exec($t)){ |
|
| 270 | - return $echafaudable[$type] = array($e['table'],$e['table_objet_sql'],$t); |
|
| 268 | + if (($t = objet_type($type, false)) !== $type |
|
| 269 | + AND $e = trouver_objet_exec($t)) { |
|
| 270 | + return $echafaudable[$type] = array($e['table'], $e['table_objet_sql'], $t); |
|
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | 273 | } |
@@ -275,13 +275,13 @@ discard block |
||
| 275 | 275 | if (is_null($pages)) { |
| 276 | 276 | $pages = array(); |
| 277 | 277 | $liste = lister_tables_objets_sql(); |
| 278 | - foreach($liste as $t=>$d) |
|
| 279 | - if ($d['page']) $pages[$d['page']] = array($d['table_objet'],$t); |
|
| 278 | + foreach ($liste as $t=>$d) |
|
| 279 | + if ($d['page']) $pages[$d['page']] = array($d['table_objet'], $t); |
|
| 280 | 280 | } |
| 281 | 281 | if (!isset($pages[$type])) |
| 282 | 282 | return $echafaudable[$type] = false; |
| 283 | - if (count($pages[$type])==2){ |
|
| 284 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 283 | + if (count($pages[$type]) == 2) { |
|
| 284 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 285 | 285 | $pages[$type][] = $trouver_table(reset($pages[$type])); |
| 286 | 286 | } |
| 287 | 287 | return $echafaudable[$type] = $pages[$type]; |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | * @param string $ext |
| 303 | 303 | * @return string |
| 304 | 304 | */ |
| 305 | -function prive_echafauder_dist($exec,$table,$table_sql,$desc_exec,$ext){ |
|
| 305 | +function prive_echafauder_dist($exec, $table, $table_sql, $desc_exec, $ext) { |
|
| 306 | 306 | $scaffold = ""; |
| 307 | 307 | |
| 308 | 308 | // page objet ou objet_edit |
@@ -310,10 +310,10 @@ discard block |
||
| 310 | 310 | $type = $desc_exec['type']; |
| 311 | 311 | $primary = $desc_exec['id_table_objet']; |
| 312 | 312 | |
| 313 | - if ($desc_exec['edition']===false) |
|
| 313 | + if ($desc_exec['edition'] === false) |
|
| 314 | 314 | $fond = "objet"; |
| 315 | 315 | else { |
| 316 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 316 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 317 | 317 | $desc = $trouver_table($table_sql); |
| 318 | 318 | if (isset($desc['field']['id_rubrique'])) |
| 319 | 319 | $fond = 'objet_edit'; |
@@ -325,22 +325,22 @@ discard block |
||
| 325 | 325 | $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/".$fond.",objet=".$type.",id_objet=#".strtoupper($primary).",env}>"; |
| 326 | 326 | } |
| 327 | 327 | // page objets |
| 328 | - elseif($type = $desc_exec AND strpos($type,"/")===false){ |
|
| 328 | + elseif ($type = $desc_exec AND strpos($type, "/") === false) { |
|
| 329 | 329 | $dir = z_blocs(test_espace_prive()); |
| 330 | 330 | $dir = reset($dir); |
| 331 | 331 | $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=".$type.",env} />"; |
| 332 | 332 | } |
| 333 | 333 | // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec |
| 334 | 334 | // et objet et tire de $table |
| 335 | - elseif($fond = $desc_exec){ |
|
| 335 | + elseif ($fond = $desc_exec) { |
|
| 336 | 336 | $dir = md5(dirname($fond)); |
| 337 | 337 | $scaffold = "<INCLURE{fond=$fond,objet=".objet_type($table).",env} />"; |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | - $base_dir = sous_repertoire(_DIR_CACHE,"scaffold",false); |
|
| 341 | - $base_dir = sous_repertoire($base_dir,$dir,false); |
|
| 340 | + $base_dir = sous_repertoire(_DIR_CACHE, "scaffold", false); |
|
| 341 | + $base_dir = sous_repertoire($base_dir, $dir, false); |
|
| 342 | 342 | $f = $base_dir."$exec"; |
| 343 | - ecrire_fichier("$f.$ext",$scaffold); |
|
| 343 | + ecrire_fichier("$f.$ext", $scaffold); |
|
| 344 | 344 | return $f; |
| 345 | 345 | } |
| 346 | 346 | |
@@ -348,11 +348,11 @@ discard block |
||
| 348 | 348 | * Recuperer et verifier var_zajax si demande dans l'url |
| 349 | 349 | * @return bool|string |
| 350 | 350 | */ |
| 351 | -function z_sanitize_var_zajax(){ |
|
| 351 | +function z_sanitize_var_zajax() { |
|
| 352 | 352 | $z_ajax = _request('var_zajax'); |
| 353 | 353 | if (!$z_ajax) return false; |
| 354 | 354 | if (!$z_blocs = z_blocs(test_espace_prive()) |
| 355 | - OR !in_array($z_ajax,$z_blocs)) { |
|
| 355 | + OR !in_array($z_ajax, $z_blocs)) { |
|
| 356 | 356 | set_request('var_zajax'); // enlever cette demande incongrue |
| 357 | 357 | $z_ajax = false; |
| 358 | 358 | } |
@@ -120,6 +120,11 @@ discard block |
||
| 120 | 120 | |
| 121 | 121 | // Par ou ca passe une fois les traductions faites |
| 122 | 122 | // http://doc.spip.org/@spip_pg_trace_query |
| 123 | +/** |
|
| 124 | + * @param string $query |
|
| 125 | + * |
|
| 126 | + * @return resource |
|
| 127 | + */ |
|
| 123 | 128 | function spip_pg_trace_query($query, $serveur='') |
| 124 | 129 | { |
| 125 | 130 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
@@ -255,6 +260,9 @@ discard block |
||
| 255 | 260 | } |
| 256 | 261 | |
| 257 | 262 | // http://doc.spip.org/@spip_pg_alter_change |
| 263 | +/** |
|
| 264 | + * @param string $arg |
|
| 265 | + */ |
|
| 258 | 266 | function spip_pg_alter_change($table, $arg, $serveur='',$requeter=true) |
| 259 | 267 | { |
| 260 | 268 | if (!preg_match('/^`?(\w+)`?\s+`?(\w+)`?\s+(.*?)\s*(DEFAULT .*?)?(NOT\s+NULL)?\s*(DEFAULT .*?)?$/i',$arg, $r)) { |
@@ -373,7 +381,7 @@ discard block |
||
| 373 | 381 | * |
| 374 | 382 | * @param string $nom : nom de l'index |
| 375 | 383 | * @param string $table : table sql de l'index |
| 376 | - * @param string/array $champs : liste de champs sur lesquels s'applique l'index |
|
| 384 | + * @param string $champs : liste de champs sur lesquels s'applique l'index |
|
| 377 | 385 | * @param string $serveur : nom de la connexion sql utilisee |
| 378 | 386 | * @param bool $requeter : true pour executer la requete ou false pour retourner le texte de la requete |
| 379 | 387 | * |
@@ -424,8 +432,6 @@ discard block |
||
| 424 | 432 | /** |
| 425 | 433 | * Selectionne une base de donnees |
| 426 | 434 | * |
| 427 | - * @param string $nom |
|
| 428 | - * Nom de la base a utiliser |
|
| 429 | 435 | * @param string $serveur |
| 430 | 436 | * Nom du connecteur |
| 431 | 437 | * @param bool $requeter |
@@ -519,6 +525,9 @@ discard block |
||
| 519 | 525 | } |
| 520 | 526 | |
| 521 | 527 | // http://doc.spip.org/@spip_pg_orderby |
| 528 | +/** |
|
| 529 | + * @param string $order |
|
| 530 | + */ |
|
| 522 | 531 | function spip_pg_orderby($order, $select) |
| 523 | 532 | { |
| 524 | 533 | $res = array(); |
@@ -680,6 +689,9 @@ discard block |
||
| 680 | 689 | } |
| 681 | 690 | |
| 682 | 691 | // http://doc.spip.org/@calculer_pg_where |
| 692 | +/** |
|
| 693 | + * @param string $v |
|
| 694 | + */ |
|
| 683 | 695 | function calculer_pg_where($v) |
| 684 | 696 | { |
| 685 | 697 | if (!is_array($v)) |
@@ -703,6 +715,9 @@ discard block |
||
| 703 | 715 | |
| 704 | 716 | |
| 705 | 717 | // http://doc.spip.org/@calculer_pg_expression |
| 718 | +/** |
|
| 719 | + * @param string $expression |
|
| 720 | + */ |
|
| 706 | 721 | function calculer_pg_expression($expression, $v, $join = 'AND'){ |
| 707 | 722 | if (empty($v)) |
| 708 | 723 | return ''; |
@@ -749,6 +764,9 @@ discard block |
||
| 749 | 764 | } |
| 750 | 765 | |
| 751 | 766 | // http://doc.spip.org/@spip_pg_fetch |
| 767 | +/** |
|
| 768 | + * @param resource $res |
|
| 769 | + */ |
|
| 752 | 770 | function spip_pg_fetch($res, $t='', $serveur='',$requeter=true) { |
| 753 | 771 | |
| 754 | 772 | if ($res) $res = pg_fetch_array($res, NULL, PGSQL_ASSOC); |
@@ -805,6 +823,10 @@ discard block |
||
| 805 | 823 | } |
| 806 | 824 | |
| 807 | 825 | // http://doc.spip.org/@spip_pg_insert |
| 826 | +/** |
|
| 827 | + * @param string $champs |
|
| 828 | + * @param string $valeurs |
|
| 829 | + */ |
|
| 808 | 830 | function spip_pg_insert($table, $champs, $valeurs, $desc=array(), $serveur='',$requeter=true) { |
| 809 | 831 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 810 | 832 | $prefixe = $connexion['prefixe']; |
@@ -1115,6 +1137,9 @@ discard block |
||
| 1115 | 1137 | } |
| 1116 | 1138 | |
| 1117 | 1139 | // http://doc.spip.org/@spip_pg_error |
| 1140 | +/** |
|
| 1141 | + * @param string $serveur |
|
| 1142 | + */ |
|
| 1118 | 1143 | function spip_pg_error($query='', $serveur, $requeter=true) { |
| 1119 | 1144 | $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
| 1120 | 1145 | $s = $link ? pg_last_error($link) : pg_last_error(); |
@@ -1158,7 +1183,7 @@ discard block |
||
| 1158 | 1183 | * @param bool $requeter |
| 1159 | 1184 | * true pour éxecuter la requête |
| 1160 | 1185 | * false pour retourner le texte de la requête. |
| 1161 | - * @return ressource |
|
| 1186 | + * @return resource |
|
| 1162 | 1187 | * Ressource à utiliser avec sql_fetch() |
| 1163 | 1188 | **/ |
| 1164 | 1189 | function spip_pg_showbase($match, $serveur='',$requeter=true) |
@@ -30,114 +30,114 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | // http://doc.spip.org/@req_pg_dist |
| 32 | 32 | function req_pg_dist($addr, $port, $login, $pass, $db='', $prefixe='') { |
| 33 | - static $last_connect = array(); |
|
| 34 | - if (!charger_php_extension('pgsql')) return false; |
|
| 33 | + static $last_connect = array(); |
|
| 34 | + if (!charger_php_extension('pgsql')) return false; |
|
| 35 | 35 | |
| 36 | - // si provient de selectdb |
|
| 37 | - if (empty($addr) && empty($port) && empty($login) && empty($pass)){ |
|
| 38 | - foreach (array('addr','port','login','pass','prefixe') as $a){ |
|
| 39 | - $$a = $last_connect[$a]; |
|
| 40 | - } |
|
| 41 | - } |
|
| 42 | - @list($host, $p) = explode(';', $addr); |
|
| 43 | - if ($p >0) $port = " port=$p" ; else $port = ''; |
|
| 44 | - $erreurs = array(); |
|
| 45 | - if ($db) { |
|
| 46 | - @$link = pg_connect("host=$host$port dbname=$db user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW); |
|
| 47 | - } elseif (!@$link = pg_connect("host=$host$port user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW)) { |
|
| 48 | - $erreurs[] = pg_last_error(); |
|
| 49 | - if (@$link = pg_connect("host=$host$port dbname=$login user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW)) { |
|
| 50 | - $db = $login; |
|
| 51 | - } else { |
|
| 52 | - $erreurs[] = pg_last_error(); |
|
| 53 | - $db = _DEFAULT_DB; |
|
| 54 | - $link = pg_connect("host=$host$port dbname=$db user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW); |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - if (!$link) { |
|
| 58 | - $erreurs[] = pg_last_error(); |
|
| 59 | - foreach($erreurs as $e) |
|
| 60 | - spip_log('Echec pg_connect. Erreur : ' . $e,'pg.'._LOG_HS); |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - if ($link) |
|
| 65 | - $last_connect = array ( |
|
| 66 | - 'addr' => $addr, |
|
| 67 | - 'port' => $port, |
|
| 68 | - 'login' => $login, |
|
| 69 | - 'pass' => $pass, |
|
| 70 | - 'db' => $db, |
|
| 71 | - 'prefixe' => $prefixe, |
|
| 72 | - ); |
|
| 36 | + // si provient de selectdb |
|
| 37 | + if (empty($addr) && empty($port) && empty($login) && empty($pass)){ |
|
| 38 | + foreach (array('addr','port','login','pass','prefixe') as $a){ |
|
| 39 | + $$a = $last_connect[$a]; |
|
| 40 | + } |
|
| 41 | + } |
|
| 42 | + @list($host, $p) = explode(';', $addr); |
|
| 43 | + if ($p >0) $port = " port=$p" ; else $port = ''; |
|
| 44 | + $erreurs = array(); |
|
| 45 | + if ($db) { |
|
| 46 | + @$link = pg_connect("host=$host$port dbname=$db user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW); |
|
| 47 | + } elseif (!@$link = pg_connect("host=$host$port user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW)) { |
|
| 48 | + $erreurs[] = pg_last_error(); |
|
| 49 | + if (@$link = pg_connect("host=$host$port dbname=$login user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW)) { |
|
| 50 | + $db = $login; |
|
| 51 | + } else { |
|
| 52 | + $erreurs[] = pg_last_error(); |
|
| 53 | + $db = _DEFAULT_DB; |
|
| 54 | + $link = pg_connect("host=$host$port dbname=$db user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + if (!$link) { |
|
| 58 | + $erreurs[] = pg_last_error(); |
|
| 59 | + foreach($erreurs as $e) |
|
| 60 | + spip_log('Echec pg_connect. Erreur : ' . $e,'pg.'._LOG_HS); |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + if ($link) |
|
| 65 | + $last_connect = array ( |
|
| 66 | + 'addr' => $addr, |
|
| 67 | + 'port' => $port, |
|
| 68 | + 'login' => $login, |
|
| 69 | + 'pass' => $pass, |
|
| 70 | + 'db' => $db, |
|
| 71 | + 'prefixe' => $prefixe, |
|
| 72 | + ); |
|
| 73 | 73 | |
| 74 | - spip_log("Connexion vers $host, base $db, prefixe $prefixe " . ($link ? 'operationnelle' : 'impossible'),'pg.'._LOG_DEBUG); |
|
| 74 | + spip_log("Connexion vers $host, base $db, prefixe $prefixe " . ($link ? 'operationnelle' : 'impossible'),'pg.'._LOG_DEBUG); |
|
| 75 | 75 | |
| 76 | - return !$link ? false : array( |
|
| 77 | - 'db' => $db, |
|
| 78 | - 'prefixe' => $prefixe ? $prefixe : $db, |
|
| 79 | - 'link' => $link, |
|
| 80 | - ); |
|
| 76 | + return !$link ? false : array( |
|
| 77 | + 'db' => $db, |
|
| 78 | + 'prefixe' => $prefixe ? $prefixe : $db, |
|
| 79 | + 'link' => $link, |
|
| 80 | + ); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | $GLOBALS['spip_pg_functions_1'] = array( |
| 84 | - 'alter' => 'spip_pg_alter', |
|
| 85 | - 'count' => 'spip_pg_count', |
|
| 86 | - 'countsel' => 'spip_pg_countsel', |
|
| 87 | - 'create' => 'spip_pg_create', |
|
| 88 | - 'create_base' => 'spip_pg_create_base', |
|
| 89 | - 'create_view' => 'spip_pg_create_view', |
|
| 90 | - 'date_proche' => 'spip_pg_date_proche', |
|
| 91 | - 'delete' => 'spip_pg_delete', |
|
| 92 | - 'drop_table' => 'spip_pg_drop_table', |
|
| 93 | - 'drop_view' => 'spip_pg_drop_view', |
|
| 94 | - 'errno' => 'spip_pg_errno', |
|
| 95 | - 'error' => 'spip_pg_error', |
|
| 96 | - 'explain' => 'spip_pg_explain', |
|
| 97 | - 'fetch' => 'spip_pg_fetch', |
|
| 98 | - 'seek' => 'spip_pg_seek', |
|
| 99 | - 'free' => 'spip_pg_free', |
|
| 100 | - 'hex' => 'spip_pg_hex', |
|
| 101 | - 'in' => 'spip_pg_in', |
|
| 102 | - 'insert' => 'spip_pg_insert', |
|
| 103 | - 'insertq' => 'spip_pg_insertq', |
|
| 104 | - 'insertq_multi' => 'spip_pg_insertq_multi', |
|
| 105 | - 'listdbs' => 'spip_pg_listdbs', |
|
| 106 | - 'multi' => 'spip_pg_multi', |
|
| 107 | - 'optimize' => 'spip_pg_optimize', |
|
| 108 | - 'query' => 'spip_pg_query', |
|
| 109 | - 'quote' => 'spip_pg_quote', |
|
| 110 | - 'replace' => 'spip_pg_replace', |
|
| 111 | - 'replace_multi' => 'spip_pg_replace_multi', |
|
| 112 | - 'select' => 'spip_pg_select', |
|
| 113 | - 'selectdb' => 'spip_pg_selectdb', |
|
| 114 | - 'set_connect_charset' => 'spip_pg_set_connect_charset', |
|
| 115 | - 'showbase' => 'spip_pg_showbase', |
|
| 116 | - 'showtable' => 'spip_pg_showtable', |
|
| 117 | - 'update' => 'spip_pg_update', |
|
| 118 | - 'updateq' => 'spip_pg_updateq', |
|
| 119 | - ); |
|
| 84 | + 'alter' => 'spip_pg_alter', |
|
| 85 | + 'count' => 'spip_pg_count', |
|
| 86 | + 'countsel' => 'spip_pg_countsel', |
|
| 87 | + 'create' => 'spip_pg_create', |
|
| 88 | + 'create_base' => 'spip_pg_create_base', |
|
| 89 | + 'create_view' => 'spip_pg_create_view', |
|
| 90 | + 'date_proche' => 'spip_pg_date_proche', |
|
| 91 | + 'delete' => 'spip_pg_delete', |
|
| 92 | + 'drop_table' => 'spip_pg_drop_table', |
|
| 93 | + 'drop_view' => 'spip_pg_drop_view', |
|
| 94 | + 'errno' => 'spip_pg_errno', |
|
| 95 | + 'error' => 'spip_pg_error', |
|
| 96 | + 'explain' => 'spip_pg_explain', |
|
| 97 | + 'fetch' => 'spip_pg_fetch', |
|
| 98 | + 'seek' => 'spip_pg_seek', |
|
| 99 | + 'free' => 'spip_pg_free', |
|
| 100 | + 'hex' => 'spip_pg_hex', |
|
| 101 | + 'in' => 'spip_pg_in', |
|
| 102 | + 'insert' => 'spip_pg_insert', |
|
| 103 | + 'insertq' => 'spip_pg_insertq', |
|
| 104 | + 'insertq_multi' => 'spip_pg_insertq_multi', |
|
| 105 | + 'listdbs' => 'spip_pg_listdbs', |
|
| 106 | + 'multi' => 'spip_pg_multi', |
|
| 107 | + 'optimize' => 'spip_pg_optimize', |
|
| 108 | + 'query' => 'spip_pg_query', |
|
| 109 | + 'quote' => 'spip_pg_quote', |
|
| 110 | + 'replace' => 'spip_pg_replace', |
|
| 111 | + 'replace_multi' => 'spip_pg_replace_multi', |
|
| 112 | + 'select' => 'spip_pg_select', |
|
| 113 | + 'selectdb' => 'spip_pg_selectdb', |
|
| 114 | + 'set_connect_charset' => 'spip_pg_set_connect_charset', |
|
| 115 | + 'showbase' => 'spip_pg_showbase', |
|
| 116 | + 'showtable' => 'spip_pg_showtable', |
|
| 117 | + 'update' => 'spip_pg_update', |
|
| 118 | + 'updateq' => 'spip_pg_updateq', |
|
| 119 | + ); |
|
| 120 | 120 | |
| 121 | 121 | // Par ou ca passe une fois les traductions faites |
| 122 | 122 | // http://doc.spip.org/@spip_pg_trace_query |
| 123 | 123 | function spip_pg_trace_query($query, $serveur='') |
| 124 | 124 | { |
| 125 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 126 | - $prefixe = $connexion['prefixe']; |
|
| 127 | - $link = $connexion['link']; |
|
| 128 | - $db = $connexion['db']; |
|
| 129 | - |
|
| 130 | - if (isset($_GET['var_profile'])) { |
|
| 131 | - include_spip('public/tracer'); |
|
| 132 | - $t = trace_query_start(); |
|
| 133 | - } else $t = 0 ; |
|
| 125 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 126 | + $prefixe = $connexion['prefixe']; |
|
| 127 | + $link = $connexion['link']; |
|
| 128 | + $db = $connexion['db']; |
|
| 129 | + |
|
| 130 | + if (isset($_GET['var_profile'])) { |
|
| 131 | + include_spip('public/tracer'); |
|
| 132 | + $t = trace_query_start(); |
|
| 133 | + } else $t = 0 ; |
|
| 134 | 134 | |
| 135 | - $connexion['last'] = $query; |
|
| 136 | - $r = spip_pg_query_simple($link, $query); |
|
| 135 | + $connexion['last'] = $query; |
|
| 136 | + $r = spip_pg_query_simple($link, $query); |
|
| 137 | 137 | |
| 138 | - if ($e = spip_pg_errno($serveur)) // Log de l'erreur eventuelle |
|
| 139 | - $e .= spip_pg_error($query, $serveur); // et du fautif |
|
| 140 | - return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 138 | + if ($e = spip_pg_errno($serveur)) // Log de l'erreur eventuelle |
|
| 139 | + $e .= spip_pg_error($query, $serveur); // et du fautif |
|
| 140 | + return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | // Fonction de requete generale quand on est sur que c'est SQL standard. |
@@ -146,26 +146,26 @@ discard block |
||
| 146 | 146 | // http://doc.spip.org/@spip_pg_query |
| 147 | 147 | function spip_pg_query($query, $serveur='',$requeter=true) |
| 148 | 148 | { |
| 149 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 150 | - $prefixe = $connexion['prefixe']; |
|
| 151 | - $link = $connexion['link']; |
|
| 152 | - $db = $connexion['db']; |
|
| 149 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 150 | + $prefixe = $connexion['prefixe']; |
|
| 151 | + $link = $connexion['link']; |
|
| 152 | + $db = $connexion['db']; |
|
| 153 | 153 | |
| 154 | - if (preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
|
| 155 | - $suite = strstr($query, $regs[0]); |
|
| 156 | - $query = substr($query, 0, -strlen($suite)); |
|
| 157 | - } else $suite =''; |
|
| 158 | - $query = preg_replace('/([,\s])spip_/', '\1'.$prefixe.'_', $query) . $suite; |
|
| 154 | + if (preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
|
| 155 | + $suite = strstr($query, $regs[0]); |
|
| 156 | + $query = substr($query, 0, -strlen($suite)); |
|
| 157 | + } else $suite =''; |
|
| 158 | + $query = preg_replace('/([,\s])spip_/', '\1'.$prefixe.'_', $query) . $suite; |
|
| 159 | 159 | |
| 160 | - // renvoyer la requete inerte si demandee |
|
| 161 | - if (!$requeter) return $query; |
|
| 160 | + // renvoyer la requete inerte si demandee |
|
| 161 | + if (!$requeter) return $query; |
|
| 162 | 162 | |
| 163 | - return spip_pg_trace_query($query, $serveur); |
|
| 163 | + return spip_pg_trace_query($query, $serveur); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | function spip_pg_query_simple($link, $query){ |
| 167 | - #spip_log(var_export($query,true), 'pg.'._LOG_DEBUG); |
|
| 168 | - return pg_query($link, $query); |
|
| 167 | + #spip_log(var_export($query,true), 'pg.'._LOG_DEBUG); |
|
| 168 | + return pg_query($link, $query); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | /* |
@@ -177,176 +177,176 @@ discard block |
||
| 177 | 177 | * de requetes showtable intempestives |
| 178 | 178 | */ |
| 179 | 179 | function spip_pg_ajouter_champs_timestamp($table, $couples, $desc='', $serveur=''){ |
| 180 | - static $tables = array(); |
|
| 180 | + static $tables = array(); |
|
| 181 | 181 | |
| 182 | - if (!isset($tables[$table])){ |
|
| 182 | + if (!isset($tables[$table])){ |
|
| 183 | 183 | |
| 184 | - if (!$desc){ |
|
| 185 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 186 | - $desc = $trouver_table($table, $serveur); |
|
| 187 | - // si pas de description, on ne fait rien, ou on die() ? |
|
| 188 | - if (!$desc) return $couples; |
|
| 189 | - } |
|
| 184 | + if (!$desc){ |
|
| 185 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 186 | + $desc = $trouver_table($table, $serveur); |
|
| 187 | + // si pas de description, on ne fait rien, ou on die() ? |
|
| 188 | + if (!$desc) return $couples; |
|
| 189 | + } |
|
| 190 | 190 | |
| 191 | - // recherche des champs avec simplement 'TIMESTAMP' |
|
| 192 | - // cependant, il faudra peut etre etendre |
|
| 193 | - // avec la gestion de DEFAULT et ON UPDATE |
|
| 194 | - // mais ceux-ci ne sont pas utilises dans le core |
|
| 195 | - $tables[$table] = array(); |
|
| 196 | - foreach ($desc['field'] as $k=>$v){ |
|
| 197 | - $v = strtolower(ltrim($v)); |
|
| 198 | - // ne pas ajouter de timestamp now() si un default est specifie |
|
| 199 | - if (strpos($v, 'timestamp')===0 AND strpos($v, 'default')===false) |
|
| 200 | - $tables[$table][] = $k; |
|
| 201 | - } |
|
| 202 | - } |
|
| 191 | + // recherche des champs avec simplement 'TIMESTAMP' |
|
| 192 | + // cependant, il faudra peut etre etendre |
|
| 193 | + // avec la gestion de DEFAULT et ON UPDATE |
|
| 194 | + // mais ceux-ci ne sont pas utilises dans le core |
|
| 195 | + $tables[$table] = array(); |
|
| 196 | + foreach ($desc['field'] as $k=>$v){ |
|
| 197 | + $v = strtolower(ltrim($v)); |
|
| 198 | + // ne pas ajouter de timestamp now() si un default est specifie |
|
| 199 | + if (strpos($v, 'timestamp')===0 AND strpos($v, 'default')===false) |
|
| 200 | + $tables[$table][] = $k; |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - // ajout des champs type 'timestamp' absents |
|
| 205 | - foreach ($tables[$table] as $maj){ |
|
| 206 | - if (!array_key_exists($maj, $couples)) |
|
| 207 | - $couples[$maj] = "NOW()"; |
|
| 208 | - } |
|
| 209 | - return $couples; |
|
| 204 | + // ajout des champs type 'timestamp' absents |
|
| 205 | + foreach ($tables[$table] as $maj){ |
|
| 206 | + if (!array_key_exists($maj, $couples)) |
|
| 207 | + $couples[$maj] = "NOW()"; |
|
| 208 | + } |
|
| 209 | + return $couples; |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | |
| 213 | 213 | // Alter en PG ne traite pas les index |
| 214 | 214 | // http://doc.spip.org/@spip_pg_alter |
| 215 | 215 | function spip_pg_alter($query, $serveur='',$requeter=true) { |
| 216 | - // il faudrait une regexp pour eviter de spliter ADD PRIMARY KEY (colA, colB) |
|
| 217 | - // tout en cassant en deux alter distincts "ADD PRIMARY KEY (colA, colB), ADD INDEX (chose)"... |
|
| 218 | - // ou revoir l'api de sql_alter en creant un |
|
| 219 | - // sql_alter_table($table,array($actions)); |
|
| 220 | - if (!preg_match("/\s*((\s*IGNORE)?\s*TABLE\s*([^\s]*))\s*(.*)?/is", $query, $regs)){ |
|
| 221 | - spip_log("$query mal comprise", 'pg.'._LOG_ERREUR); |
|
| 222 | - return false; |
|
| 223 | - } |
|
| 224 | - $debut = $regs[1]; |
|
| 225 | - $table = $regs[3]; |
|
| 226 | - $suite = $regs[4]; |
|
| 227 | - $todo = explode(',', $suite); |
|
| 228 | - // on remet les morceaux dechires ensembles... que c'est laid ! |
|
| 229 | - $todo2 = array(); $i=0; |
|
| 230 | - $ouverte = false; |
|
| 231 | - while ($do = array_shift($todo)) { |
|
| 232 | - $todo2[$i] = isset($todo2[$i]) ? $todo2[$i] . "," . $do : $do; |
|
| 233 | - $o=(false!==strpos($do,"(")); |
|
| 234 | - $f=(false!==strpos($do,")")); |
|
| 235 | - if ($o AND !$f) $ouverte=true; |
|
| 236 | - elseif ($f) $ouverte=false; |
|
| 237 | - if (!$ouverte) $i++; |
|
| 238 | - } |
|
| 239 | - $todo=$todo2; |
|
| 240 | - $query = $debut.' '.array_shift($todo); |
|
| 241 | - |
|
| 242 | - if (!preg_match('/^\s*(IGNORE\s*)?TABLE\s+(\w+)\s+(ADD|DROP|CHANGE|MODIFY|RENAME)\s*(.*)$/is', $query, $r)) { |
|
| 243 | - spip_log("$query incompris", 'pg.'._LOG_ERREUR); |
|
| 244 | - } else { |
|
| 245 | - if ($r[1]) spip_log("j'ignore IGNORE dans $query", 'pg.'._LOG_AVERTISSEMENT); |
|
| 246 | - $f = 'spip_pg_alter_' . strtolower($r[3]); |
|
| 247 | - if (function_exists($f)) |
|
| 248 | - $f($r[2], $r[4], $serveur, $requeter); |
|
| 249 | - else spip_log("$query non prevu", 'pg.'._LOG_ERREUR); |
|
| 250 | - } |
|
| 251 | - // Alter a plusieurs args. Faudrait optimiser. |
|
| 252 | - if ($todo) |
|
| 253 | - spip_pg_alter("TABLE $table " . join(',',$todo)); |
|
| 216 | + // il faudrait une regexp pour eviter de spliter ADD PRIMARY KEY (colA, colB) |
|
| 217 | + // tout en cassant en deux alter distincts "ADD PRIMARY KEY (colA, colB), ADD INDEX (chose)"... |
|
| 218 | + // ou revoir l'api de sql_alter en creant un |
|
| 219 | + // sql_alter_table($table,array($actions)); |
|
| 220 | + if (!preg_match("/\s*((\s*IGNORE)?\s*TABLE\s*([^\s]*))\s*(.*)?/is", $query, $regs)){ |
|
| 221 | + spip_log("$query mal comprise", 'pg.'._LOG_ERREUR); |
|
| 222 | + return false; |
|
| 223 | + } |
|
| 224 | + $debut = $regs[1]; |
|
| 225 | + $table = $regs[3]; |
|
| 226 | + $suite = $regs[4]; |
|
| 227 | + $todo = explode(',', $suite); |
|
| 228 | + // on remet les morceaux dechires ensembles... que c'est laid ! |
|
| 229 | + $todo2 = array(); $i=0; |
|
| 230 | + $ouverte = false; |
|
| 231 | + while ($do = array_shift($todo)) { |
|
| 232 | + $todo2[$i] = isset($todo2[$i]) ? $todo2[$i] . "," . $do : $do; |
|
| 233 | + $o=(false!==strpos($do,"(")); |
|
| 234 | + $f=(false!==strpos($do,")")); |
|
| 235 | + if ($o AND !$f) $ouverte=true; |
|
| 236 | + elseif ($f) $ouverte=false; |
|
| 237 | + if (!$ouverte) $i++; |
|
| 238 | + } |
|
| 239 | + $todo=$todo2; |
|
| 240 | + $query = $debut.' '.array_shift($todo); |
|
| 241 | + |
|
| 242 | + if (!preg_match('/^\s*(IGNORE\s*)?TABLE\s+(\w+)\s+(ADD|DROP|CHANGE|MODIFY|RENAME)\s*(.*)$/is', $query, $r)) { |
|
| 243 | + spip_log("$query incompris", 'pg.'._LOG_ERREUR); |
|
| 244 | + } else { |
|
| 245 | + if ($r[1]) spip_log("j'ignore IGNORE dans $query", 'pg.'._LOG_AVERTISSEMENT); |
|
| 246 | + $f = 'spip_pg_alter_' . strtolower($r[3]); |
|
| 247 | + if (function_exists($f)) |
|
| 248 | + $f($r[2], $r[4], $serveur, $requeter); |
|
| 249 | + else spip_log("$query non prevu", 'pg.'._LOG_ERREUR); |
|
| 250 | + } |
|
| 251 | + // Alter a plusieurs args. Faudrait optimiser. |
|
| 252 | + if ($todo) |
|
| 253 | + spip_pg_alter("TABLE $table " . join(',',$todo)); |
|
| 254 | 254 | |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | // http://doc.spip.org/@spip_pg_alter_change |
| 258 | 258 | function spip_pg_alter_change($table, $arg, $serveur='',$requeter=true) |
| 259 | 259 | { |
| 260 | - if (!preg_match('/^`?(\w+)`?\s+`?(\w+)`?\s+(.*?)\s*(DEFAULT .*?)?(NOT\s+NULL)?\s*(DEFAULT .*?)?$/i',$arg, $r)) { |
|
| 261 | - spip_log("alter change: $arg incompris", 'pg.'._LOG_ERREUR); |
|
| 262 | - } else { |
|
| 263 | - list(,$old, $new, $type, $default, $null, $def2) = $r; |
|
| 264 | - $actions = array("ALTER $old TYPE " . mysql2pg_type($type)); |
|
| 265 | - if ($null) |
|
| 266 | - $actions[]= "ALTER $old SET NOT NULL"; |
|
| 267 | - else |
|
| 268 | - $actions[]= "ALTER $old DROP NOT NULL"; |
|
| 269 | - |
|
| 270 | - if ($d = ($default ? $default : $def2)) |
|
| 271 | - $actions[]= "ALTER $old SET $d"; |
|
| 272 | - else |
|
| 273 | - $actions[]= "ALTER $old DROP DEFAULT"; |
|
| 274 | - |
|
| 275 | - spip_pg_query("ALTER TABLE $table " . join(', ', $actions)); |
|
| 276 | - |
|
| 277 | - if ($old != $new) |
|
| 278 | - spip_pg_query("ALTER TABLE $table RENAME $old TO $new", $serveur); |
|
| 279 | - } |
|
| 260 | + if (!preg_match('/^`?(\w+)`?\s+`?(\w+)`?\s+(.*?)\s*(DEFAULT .*?)?(NOT\s+NULL)?\s*(DEFAULT .*?)?$/i',$arg, $r)) { |
|
| 261 | + spip_log("alter change: $arg incompris", 'pg.'._LOG_ERREUR); |
|
| 262 | + } else { |
|
| 263 | + list(,$old, $new, $type, $default, $null, $def2) = $r; |
|
| 264 | + $actions = array("ALTER $old TYPE " . mysql2pg_type($type)); |
|
| 265 | + if ($null) |
|
| 266 | + $actions[]= "ALTER $old SET NOT NULL"; |
|
| 267 | + else |
|
| 268 | + $actions[]= "ALTER $old DROP NOT NULL"; |
|
| 269 | + |
|
| 270 | + if ($d = ($default ? $default : $def2)) |
|
| 271 | + $actions[]= "ALTER $old SET $d"; |
|
| 272 | + else |
|
| 273 | + $actions[]= "ALTER $old DROP DEFAULT"; |
|
| 274 | + |
|
| 275 | + spip_pg_query("ALTER TABLE $table " . join(', ', $actions)); |
|
| 276 | + |
|
| 277 | + if ($old != $new) |
|
| 278 | + spip_pg_query("ALTER TABLE $table RENAME $old TO $new", $serveur); |
|
| 279 | + } |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | // http://doc.spip.org/@spip_pg_alter_add |
| 283 | 283 | function spip_pg_alter_add($table, $arg, $serveur='',$requeter=true) { |
| 284 | - if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*(.*)$/', $arg, $r)) { |
|
| 285 | - spip_log("alter add $arg incompris", 'pg.'._LOG_ERREUR); |
|
| 286 | - return NULL; |
|
| 287 | - } |
|
| 288 | - if (!$r[1] OR $r[1]=='COLUMN') { |
|
| 289 | - preg_match('/`?(\w+)`?(.*)/',$r[2], $m); |
|
| 290 | - if (preg_match('/^(.*)(BEFORE|AFTER|FIRST)(.*)$/is', $m[2], $n)) { |
|
| 291 | - $m[2]=$n[1]; |
|
| 292 | - } |
|
| 293 | - return spip_pg_query("ALTER TABLE $table ADD " . $m[1] . ' ' . mysql2pg_type($m[2]), $serveur, $requeter); |
|
| 294 | - } elseif ($r[1][0] == 'P') { |
|
| 295 | - // la primary peut etre sur plusieurs champs |
|
| 296 | - $r[2] = trim(str_replace('`','',$r[2])); |
|
| 297 | - $m = ($r[2][0]=='(') ? substr($r[2],1,-1) : $r[2]; |
|
| 298 | - return spip_pg_query("ALTER TABLE $table ADD CONSTRAINT $table" .'_pkey PRIMARY KEY (' . $m . ')', $serveur, $requeter); |
|
| 299 | - } else { |
|
| 300 | - preg_match('/([^\s,]*)\s*(.*)?/',$r[2], $m); |
|
| 301 | - // peut etre "(colonne)" ou "nom_index (colonnes)" |
|
| 302 | - // bug potentiel si qqn met "(colonne, colonne)" |
|
| 303 | - // |
|
| 304 | - // nom_index (colonnes) |
|
| 305 | - if ($m[2]) { |
|
| 306 | - $colonnes = substr($m[2],1,-1); |
|
| 307 | - $nom_index = $m[1]; |
|
| 308 | - } |
|
| 309 | - else { |
|
| 310 | - // (colonne) |
|
| 311 | - if ($m[1][0] == "(") { |
|
| 312 | - $colonnes = substr($m[1],1,-1); |
|
| 313 | - if (false!==strpos(",",$colonnes)) { |
|
| 314 | - spip_log(_LOG_GRAVITE_ERREUR,"PG : Erreur, impossible de creer un index sur plusieurs colonnes" |
|
| 315 | - ." sans qu'il ait de nom ($table, ($colonnes))", 'pg'); |
|
| 316 | - } else { |
|
| 317 | - $nom_index = $colonnes; |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - // nom_index |
|
| 321 | - else { |
|
| 322 | - $nom_index = $colonnes = $m[1]; |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - return spip_pg_create_index($nom_index, $table, $colonnes, $serveur, $requeter); |
|
| 326 | - } |
|
| 284 | + if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*(.*)$/', $arg, $r)) { |
|
| 285 | + spip_log("alter add $arg incompris", 'pg.'._LOG_ERREUR); |
|
| 286 | + return NULL; |
|
| 287 | + } |
|
| 288 | + if (!$r[1] OR $r[1]=='COLUMN') { |
|
| 289 | + preg_match('/`?(\w+)`?(.*)/',$r[2], $m); |
|
| 290 | + if (preg_match('/^(.*)(BEFORE|AFTER|FIRST)(.*)$/is', $m[2], $n)) { |
|
| 291 | + $m[2]=$n[1]; |
|
| 292 | + } |
|
| 293 | + return spip_pg_query("ALTER TABLE $table ADD " . $m[1] . ' ' . mysql2pg_type($m[2]), $serveur, $requeter); |
|
| 294 | + } elseif ($r[1][0] == 'P') { |
|
| 295 | + // la primary peut etre sur plusieurs champs |
|
| 296 | + $r[2] = trim(str_replace('`','',$r[2])); |
|
| 297 | + $m = ($r[2][0]=='(') ? substr($r[2],1,-1) : $r[2]; |
|
| 298 | + return spip_pg_query("ALTER TABLE $table ADD CONSTRAINT $table" .'_pkey PRIMARY KEY (' . $m . ')', $serveur, $requeter); |
|
| 299 | + } else { |
|
| 300 | + preg_match('/([^\s,]*)\s*(.*)?/',$r[2], $m); |
|
| 301 | + // peut etre "(colonne)" ou "nom_index (colonnes)" |
|
| 302 | + // bug potentiel si qqn met "(colonne, colonne)" |
|
| 303 | + // |
|
| 304 | + // nom_index (colonnes) |
|
| 305 | + if ($m[2]) { |
|
| 306 | + $colonnes = substr($m[2],1,-1); |
|
| 307 | + $nom_index = $m[1]; |
|
| 308 | + } |
|
| 309 | + else { |
|
| 310 | + // (colonne) |
|
| 311 | + if ($m[1][0] == "(") { |
|
| 312 | + $colonnes = substr($m[1],1,-1); |
|
| 313 | + if (false!==strpos(",",$colonnes)) { |
|
| 314 | + spip_log(_LOG_GRAVITE_ERREUR,"PG : Erreur, impossible de creer un index sur plusieurs colonnes" |
|
| 315 | + ." sans qu'il ait de nom ($table, ($colonnes))", 'pg'); |
|
| 316 | + } else { |
|
| 317 | + $nom_index = $colonnes; |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + // nom_index |
|
| 321 | + else { |
|
| 322 | + $nom_index = $colonnes = $m[1]; |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + return spip_pg_create_index($nom_index, $table, $colonnes, $serveur, $requeter); |
|
| 326 | + } |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | // http://doc.spip.org/@spip_pg_alter_drop |
| 330 | 330 | function spip_pg_alter_drop($table, $arg, $serveur='',$requeter=true) { |
| 331 | - if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*`?(\w*)`?/', $arg, $r)) |
|
| 332 | - spip_log("alter drop: $arg incompris", 'pg.'._LOG_ERREUR); |
|
| 333 | - else { |
|
| 334 | - if (!$r[1] OR $r[1]=='COLUMN') |
|
| 335 | - return spip_pg_query("ALTER TABLE $table DROP " . $r[2], $serveur); |
|
| 336 | - elseif ($r[1][0] == 'P') |
|
| 337 | - return spip_pg_query("ALTER TABLE $table DROP CONSTRAINT $table" . '_pkey', $serveur); |
|
| 338 | - else { |
|
| 339 | - return spip_pg_query("DROP INDEX " . $table . '_' . $r[2], $serveur); |
|
| 340 | - } |
|
| 341 | - } |
|
| 331 | + if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*`?(\w*)`?/', $arg, $r)) |
|
| 332 | + spip_log("alter drop: $arg incompris", 'pg.'._LOG_ERREUR); |
|
| 333 | + else { |
|
| 334 | + if (!$r[1] OR $r[1]=='COLUMN') |
|
| 335 | + return spip_pg_query("ALTER TABLE $table DROP " . $r[2], $serveur); |
|
| 336 | + elseif ($r[1][0] == 'P') |
|
| 337 | + return spip_pg_query("ALTER TABLE $table DROP CONSTRAINT $table" . '_pkey', $serveur); |
|
| 338 | + else { |
|
| 339 | + return spip_pg_query("DROP INDEX " . $table . '_' . $r[2], $serveur); |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | function spip_pg_alter_modify($table, $arg, $serveur='',$requeter=true) { |
| 345 | - if (!preg_match('/^`?(\w+)`?\s+(.*)$/',$arg, $r)) { |
|
| 346 | - spip_log("alter modify: $arg incompris", 'pg.'._LOG_ERREUR); |
|
| 347 | - } else { |
|
| 348 | - return spip_pg_alter_change($table, $r[1].' '.$arg, $serveur='',$requeter=true); |
|
| 349 | - } |
|
| 345 | + if (!preg_match('/^`?(\w+)`?\s+(.*)$/',$arg, $r)) { |
|
| 346 | + spip_log("alter modify: $arg incompris", 'pg.'._LOG_ERREUR); |
|
| 347 | + } else { |
|
| 348 | + return spip_pg_alter_change($table, $r[1].' '.$arg, $serveur='',$requeter=true); |
|
| 349 | + } |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | // attention (en pg) : |
@@ -354,17 +354,17 @@ discard block |
||
| 354 | 354 | // - alter table A rename X to Y = changer le nom de la colonne X en Y |
| 355 | 355 | // pour l'instant, traiter simplement RENAME TO X |
| 356 | 356 | function spip_pg_alter_rename($table, $arg, $serveur='',$requeter=true) { |
| 357 | - $rename=""; |
|
| 358 | - // si TO, mais pas au debut |
|
| 359 | - if (!stripos($arg,'TO ')){ |
|
| 360 | - $rename=$arg; |
|
| 361 | - } |
|
| 362 | - elseif (preg_match('/^(TO)\s*`?(\w*)`?/', $arg, $r)) { |
|
| 363 | - $rename=$r[2]; |
|
| 364 | - } else { |
|
| 365 | - spip_log("alter rename: $arg incompris", 'pg.'._LOG_ERREUR); |
|
| 366 | - } |
|
| 367 | - return $rename?spip_pg_query("ALTER TABLE $table RENAME TO $rename"):false; |
|
| 357 | + $rename=""; |
|
| 358 | + // si TO, mais pas au debut |
|
| 359 | + if (!stripos($arg,'TO ')){ |
|
| 360 | + $rename=$arg; |
|
| 361 | + } |
|
| 362 | + elseif (preg_match('/^(TO)\s*`?(\w*)`?/', $arg, $r)) { |
|
| 363 | + $rename=$r[2]; |
|
| 364 | + } else { |
|
| 365 | + spip_log("alter rename: $arg incompris", 'pg.'._LOG_ERREUR); |
|
| 366 | + } |
|
| 367 | + return $rename?spip_pg_query("ALTER TABLE $table RENAME TO $rename"):false; |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | |
@@ -380,44 +380,44 @@ discard block |
||
| 380 | 380 | * @return bool ou requete |
| 381 | 381 | */ |
| 382 | 382 | function spip_pg_create_index($nom, $table, $champs, $serveur='', $requeter=true) { |
| 383 | - if (!($nom OR $table OR $champs)) { |
|
| 384 | - spip_log("Champ manquant pour creer un index pg ($nom, $table, (".@join(',',$champs)."))",'pg.'._LOG_ERREUR); |
|
| 385 | - return false; |
|
| 386 | - } |
|
| 383 | + if (!($nom OR $table OR $champs)) { |
|
| 384 | + spip_log("Champ manquant pour creer un index pg ($nom, $table, (".@join(',',$champs)."))",'pg.'._LOG_ERREUR); |
|
| 385 | + return false; |
|
| 386 | + } |
|
| 387 | 387 | |
| 388 | - $nom = str_replace("`","",$nom); |
|
| 389 | - $champs = str_replace("`","",$champs); |
|
| 388 | + $nom = str_replace("`","",$nom); |
|
| 389 | + $champs = str_replace("`","",$champs); |
|
| 390 | 390 | |
| 391 | - // PG ne differentie pas noms des index en fonction des tables |
|
| 392 | - // il faut donc creer des noms uniques d'index pour une base pg |
|
| 393 | - $nom = $table.'_'.$nom; |
|
| 394 | - // enlever d'eventuelles parentheses deja presentes sur champs |
|
| 395 | - if (!is_array($champs)){ |
|
| 396 | - if ($champs[0]=="(") $champs = substr($champs,1,-1); |
|
| 397 | - $champs = array($champs); |
|
| 398 | - } |
|
| 399 | - $query = "CREATE INDEX $nom ON $table (" . join(',',$champs) . ")"; |
|
| 400 | - if (!$requeter) return $query; |
|
| 401 | - $res = spip_pg_query($query, $serveur, $requeter); |
|
| 402 | - return $res; |
|
| 391 | + // PG ne differentie pas noms des index en fonction des tables |
|
| 392 | + // il faut donc creer des noms uniques d'index pour une base pg |
|
| 393 | + $nom = $table.'_'.$nom; |
|
| 394 | + // enlever d'eventuelles parentheses deja presentes sur champs |
|
| 395 | + if (!is_array($champs)){ |
|
| 396 | + if ($champs[0]=="(") $champs = substr($champs,1,-1); |
|
| 397 | + $champs = array($champs); |
|
| 398 | + } |
|
| 399 | + $query = "CREATE INDEX $nom ON $table (" . join(',',$champs) . ")"; |
|
| 400 | + if (!$requeter) return $query; |
|
| 401 | + $res = spip_pg_query($query, $serveur, $requeter); |
|
| 402 | + return $res; |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | |
| 406 | 406 | // http://doc.spip.org/@spip_pg_explain |
| 407 | 407 | function spip_pg_explain($query, $serveur='',$requeter=true){ |
| 408 | - if (strpos(ltrim($query), 'SELECT') !== 0) return array(); |
|
| 409 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 410 | - $prefixe = $connexion['prefixe']; |
|
| 411 | - $link = $connexion['link']; |
|
| 412 | - if (preg_match('/\s(SET|VALUES|WHERE)\s/i', $query, $regs)) { |
|
| 413 | - $suite = strstr($query, $regs[0]); |
|
| 414 | - $query = substr($query, 0, -strlen($suite)); |
|
| 415 | - } else $suite =''; |
|
| 416 | - $query = 'EXPLAIN ' . preg_replace('/([,\s])spip_/', '\1'.$prefixe.'_', $query) . $suite; |
|
| 417 | - |
|
| 418 | - if (!$requeter) return $query; |
|
| 419 | - $r = spip_pg_query_simple($link,$query); |
|
| 420 | - return spip_pg_fetch($r, NULL, $serveur); |
|
| 408 | + if (strpos(ltrim($query), 'SELECT') !== 0) return array(); |
|
| 409 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 410 | + $prefixe = $connexion['prefixe']; |
|
| 411 | + $link = $connexion['link']; |
|
| 412 | + if (preg_match('/\s(SET|VALUES|WHERE)\s/i', $query, $regs)) { |
|
| 413 | + $suite = strstr($query, $regs[0]); |
|
| 414 | + $query = substr($query, 0, -strlen($suite)); |
|
| 415 | + } else $suite =''; |
|
| 416 | + $query = 'EXPLAIN ' . preg_replace('/([,\s])spip_/', '\1'.$prefixe.'_', $query) . $suite; |
|
| 417 | + |
|
| 418 | + if (!$requeter) return $query; |
|
| 419 | + $r = spip_pg_query_simple($link,$query); |
|
| 420 | + return spip_pg_fetch($r, NULL, $serveur); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | |
@@ -436,76 +436,76 @@ discard block |
||
| 436 | 436 | * False en cas d'erreur. |
| 437 | 437 | **/ |
| 438 | 438 | function spip_pg_selectdb($db, $serveur='',$requeter=true) { |
| 439 | - // se connecter a la base indiquee |
|
| 440 | - // avec les identifiants connus |
|
| 441 | - $index = $serveur ? strtolower($serveur) : 0; |
|
| 442 | - |
|
| 443 | - if ($link = spip_connect_db('', '', '', '', $db, 'pg', '', '')){ |
|
| 444 | - if (($db==$link['db']) && $GLOBALS['connexions'][$index] = $link) |
|
| 445 | - return $db; |
|
| 446 | - } else |
|
| 447 | - return false; |
|
| 439 | + // se connecter a la base indiquee |
|
| 440 | + // avec les identifiants connus |
|
| 441 | + $index = $serveur ? strtolower($serveur) : 0; |
|
| 442 | + |
|
| 443 | + if ($link = spip_connect_db('', '', '', '', $db, 'pg', '', '')){ |
|
| 444 | + if (($db==$link['db']) && $GLOBALS['connexions'][$index] = $link) |
|
| 445 | + return $db; |
|
| 446 | + } else |
|
| 447 | + return false; |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | // Qu'une seule base pour le moment |
| 451 | 451 | |
| 452 | 452 | // http://doc.spip.org/@spip_pg_listdbs |
| 453 | 453 | function spip_pg_listdbs($serveur) { |
| 454 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 455 | - $link = $connexion['link']; |
|
| 456 | - $dbs = array(); |
|
| 457 | - $res = spip_pg_query_simple($link, "select * From pg_database"); |
|
| 458 | - while ($row = pg_fetch_array($res, NULL, PGSQL_NUM)) |
|
| 459 | - $dbs[] = reset($row); |
|
| 460 | - |
|
| 461 | - return $dbs; |
|
| 454 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 455 | + $link = $connexion['link']; |
|
| 456 | + $dbs = array(); |
|
| 457 | + $res = spip_pg_query_simple($link, "select * From pg_database"); |
|
| 458 | + while ($row = pg_fetch_array($res, NULL, PGSQL_NUM)) |
|
| 459 | + $dbs[] = reset($row); |
|
| 460 | + |
|
| 461 | + return $dbs; |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | // http://doc.spip.org/@spip_pg_select |
| 465 | 465 | function spip_pg_select($select, $from, $where='', |
| 466 | - $groupby=array(), $orderby='', $limit='', |
|
| 467 | - $having='', $serveur='',$requeter=true){ |
|
| 468 | - |
|
| 469 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 470 | - $prefixe = $connexion['prefixe']; |
|
| 471 | - $link = $connexion['link']; |
|
| 472 | - $db = $connexion['db']; |
|
| 473 | - |
|
| 474 | - $limit = preg_match("/^\s*(([0-9]+),)?\s*([0-9]+)\s*$/", $limit,$limatch); |
|
| 475 | - if ($limit) { |
|
| 476 | - $offset = $limatch[2]; |
|
| 477 | - $count = $limatch[3]; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - $select = spip_pg_frommysql($select); |
|
| 481 | - |
|
| 482 | - // si pas de tri explicitement demande, le GROUP BY ne |
|
| 483 | - // contient que la clef primaire. |
|
| 484 | - // lui ajouter alors le champ de tri par defaut |
|
| 485 | - if (preg_match("/FIELD\(([a-z]+\.[a-z]+),/i", $orderby[0], $groupbyplus)) { |
|
| 486 | - $groupby[] = $groupbyplus[1]; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - $orderby = spip_pg_orderby($orderby, $select); |
|
| 490 | - |
|
| 491 | - if ($having) { |
|
| 492 | - if (is_array($having)) |
|
| 493 | - $having = join("\n\tAND ", array_map('calculer_pg_where', $having)); |
|
| 494 | - } |
|
| 495 | - $from = spip_pg_from($from, $prefixe); |
|
| 496 | - $query = "SELECT ". $select |
|
| 497 | - . (!$from ? '' : "\nFROM $from") |
|
| 498 | - . (!$where ? '' : ("\nWHERE " . (!is_array($where) ? calculer_pg_where($where) : (join("\n\tAND ", array_map('calculer_pg_where', $where)))))) |
|
| 499 | - . spip_pg_groupby($groupby, $from, $select) |
|
| 500 | - . (!$having ? '' : "\nHAVING $having") |
|
| 501 | - . ($orderby ? ("\nORDER BY $orderby") :'') |
|
| 502 | - . (!$limit ? '' : (" LIMIT $count" . (!$offset ? '' : " OFFSET $offset"))); |
|
| 503 | - |
|
| 504 | - // renvoyer la requete inerte si demandee |
|
| 505 | - if ($requeter === false) return $query; |
|
| 466 | + $groupby=array(), $orderby='', $limit='', |
|
| 467 | + $having='', $serveur='',$requeter=true){ |
|
| 468 | + |
|
| 469 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 470 | + $prefixe = $connexion['prefixe']; |
|
| 471 | + $link = $connexion['link']; |
|
| 472 | + $db = $connexion['db']; |
|
| 473 | + |
|
| 474 | + $limit = preg_match("/^\s*(([0-9]+),)?\s*([0-9]+)\s*$/", $limit,$limatch); |
|
| 475 | + if ($limit) { |
|
| 476 | + $offset = $limatch[2]; |
|
| 477 | + $count = $limatch[3]; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + $select = spip_pg_frommysql($select); |
|
| 481 | + |
|
| 482 | + // si pas de tri explicitement demande, le GROUP BY ne |
|
| 483 | + // contient que la clef primaire. |
|
| 484 | + // lui ajouter alors le champ de tri par defaut |
|
| 485 | + if (preg_match("/FIELD\(([a-z]+\.[a-z]+),/i", $orderby[0], $groupbyplus)) { |
|
| 486 | + $groupby[] = $groupbyplus[1]; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + $orderby = spip_pg_orderby($orderby, $select); |
|
| 490 | + |
|
| 491 | + if ($having) { |
|
| 492 | + if (is_array($having)) |
|
| 493 | + $having = join("\n\tAND ", array_map('calculer_pg_where', $having)); |
|
| 494 | + } |
|
| 495 | + $from = spip_pg_from($from, $prefixe); |
|
| 496 | + $query = "SELECT ". $select |
|
| 497 | + . (!$from ? '' : "\nFROM $from") |
|
| 498 | + . (!$where ? '' : ("\nWHERE " . (!is_array($where) ? calculer_pg_where($where) : (join("\n\tAND ", array_map('calculer_pg_where', $where)))))) |
|
| 499 | + . spip_pg_groupby($groupby, $from, $select) |
|
| 500 | + . (!$having ? '' : "\nHAVING $having") |
|
| 501 | + . ($orderby ? ("\nORDER BY $orderby") :'') |
|
| 502 | + . (!$limit ? '' : (" LIMIT $count" . (!$offset ? '' : " OFFSET $offset"))); |
|
| 503 | + |
|
| 504 | + // renvoyer la requete inerte si demandee |
|
| 505 | + if ($requeter === false) return $query; |
|
| 506 | 506 | |
| 507 | - $r = spip_pg_trace_query($query, $serveur); |
|
| 508 | - return $r ? $r : $query;; |
|
| 507 | + $r = spip_pg_trace_query($query, $serveur); |
|
| 508 | + return $r ? $r : $query;; |
|
| 509 | 509 | } |
| 510 | 510 | |
| 511 | 511 | // Le traitement des prefixes de table dans un Select se limite au FROM |
@@ -514,23 +514,23 @@ discard block |
||
| 514 | 514 | // http://doc.spip.org/@spip_pg_from |
| 515 | 515 | function spip_pg_from($from, $prefixe) |
| 516 | 516 | { |
| 517 | - if (is_array($from)) $from = spip_pg_select_as($from); |
|
| 518 | - return !$prefixe ? $from : preg_replace('/(\b)spip_/','\1'.$prefixe.'_', $from); |
|
| 517 | + if (is_array($from)) $from = spip_pg_select_as($from); |
|
| 518 | + return !$prefixe ? $from : preg_replace('/(\b)spip_/','\1'.$prefixe.'_', $from); |
|
| 519 | 519 | } |
| 520 | 520 | |
| 521 | 521 | // http://doc.spip.org/@spip_pg_orderby |
| 522 | 522 | function spip_pg_orderby($order, $select) |
| 523 | 523 | { |
| 524 | - $res = array(); |
|
| 525 | - $arg = (is_array($order) ? $order : preg_split('/\s*,\s*/',$order)); |
|
| 524 | + $res = array(); |
|
| 525 | + $arg = (is_array($order) ? $order : preg_split('/\s*,\s*/',$order)); |
|
| 526 | 526 | |
| 527 | - foreach($arg as $v) { |
|
| 528 | - if (preg_match('/(case\s+.*?else\s+0\s+end)\s*AS\s+' . $v .'/', $select, $m)) { |
|
| 527 | + foreach($arg as $v) { |
|
| 528 | + if (preg_match('/(case\s+.*?else\s+0\s+end)\s*AS\s+' . $v .'/', $select, $m)) { |
|
| 529 | 529 | |
| 530 | - $res[] = $m[1]; |
|
| 531 | - } else $res[]=$v; |
|
| 532 | - } |
|
| 533 | - return spip_pg_frommysql(join(',',$res)); |
|
| 530 | + $res[] = $m[1]; |
|
| 531 | + } else $res[]=$v; |
|
| 532 | + } |
|
| 533 | + return spip_pg_frommysql(join(',',$res)); |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | // Conversion a l'arrach' des jointures MySQL en jointures PG |
@@ -540,47 +540,47 @@ discard block |
||
| 540 | 540 | // http://doc.spip.org/@spip_pg_groupby |
| 541 | 541 | function spip_pg_groupby($groupby, $from, $select) |
| 542 | 542 | { |
| 543 | - $join = strpos($from, ","); |
|
| 544 | - // ismplifier avant de decouper |
|
| 545 | - if (is_string($select)) |
|
| 546 | - // fct SQL sur colonne et constante apostrophee ==> la colonne |
|
| 547 | - $select = preg_replace('/\w+\(\s*([^(),\']*),\s*\'[^\']*\'[^)]*\)/','\\1', $select); |
|
| 548 | - |
|
| 549 | - if ($join OR $groupby) $join = is_array($select) ? $select : explode(", ", $select); |
|
| 550 | - if ($join) { |
|
| 551 | - // enlever les 0 as points, '', ... |
|
| 552 | - foreach($join as $k=>$v){ |
|
| 553 | - $v = str_replace('DISTINCT ','',$v); |
|
| 554 | - // fct SQL sur colonne et constante apostrophee ==> la colonne |
|
| 555 | - $v = preg_replace('/\w+\(\s*([^(),\']*),\s*\'[^\']*\'[^)]*\)/','\\1', $v); |
|
| 556 | - $v = preg_replace('/CAST\(\s*([^(),\' ]*\s+)as\s*\w+\)/','\\1', $v); |
|
| 557 | - // resultat d'agregat ne sont pas a mettre dans le groupby |
|
| 558 | - $v = preg_replace('/(SUM|COUNT|MAX|MIN|UPPER)\([^)]+\)(\s*AS\s+\w+)\s*,?/i','', $v); |
|
| 559 | - // idem sans AS (fetch numerique) |
|
| 560 | - $v = preg_replace('/(SUM|COUNT|MAX|MIN|UPPER)\([^)]+\)\s*,?/i','', $v); |
|
| 561 | - // des AS simples : on garde le cote droit du AS |
|
| 562 | - $v = preg_replace('/^.*\sAS\s+(\w+)\s*$/i','\\1', $v); |
|
| 563 | - // ne reste plus que les vrais colonnes, ou des constantes a virer |
|
| 564 | - if (preg_match(',^[\'"],',$v) OR is_numeric($v)) |
|
| 565 | - unset($join[$k]); |
|
| 566 | - else |
|
| 567 | - $join[$k] = trim($v); |
|
| 568 | - } |
|
| 569 | - $join = array_diff($join,array('')); |
|
| 570 | - $join = implode(',',$join); |
|
| 571 | - } |
|
| 572 | - if (is_array($groupby)) $groupby = join(',',$groupby); |
|
| 573 | - if ($join) $groupby = $groupby ? "$groupby, $join" : $join; |
|
| 574 | - if (!$groupby) return ''; |
|
| 575 | - |
|
| 576 | - $groupby = spip_pg_frommysql($groupby); |
|
| 577 | - // Ne pas mettre dans le Group-By des valeurs numeriques |
|
| 578 | - // issue de prepare_recherche |
|
| 579 | - $groupby = preg_replace('/^\s*\d+\s+AS\s+\w+\s*,?\s*/i','', $groupby); |
|
| 580 | - $groupby = preg_replace('/,\s*\d+\s+AS\s+\w+\s*/i','', $groupby); |
|
| 581 | - $groupby = preg_replace('/\s+AS\s+\w+\s*/i','', $groupby); |
|
| 582 | - |
|
| 583 | - return "\nGROUP BY $groupby"; |
|
| 543 | + $join = strpos($from, ","); |
|
| 544 | + // ismplifier avant de decouper |
|
| 545 | + if (is_string($select)) |
|
| 546 | + // fct SQL sur colonne et constante apostrophee ==> la colonne |
|
| 547 | + $select = preg_replace('/\w+\(\s*([^(),\']*),\s*\'[^\']*\'[^)]*\)/','\\1', $select); |
|
| 548 | + |
|
| 549 | + if ($join OR $groupby) $join = is_array($select) ? $select : explode(", ", $select); |
|
| 550 | + if ($join) { |
|
| 551 | + // enlever les 0 as points, '', ... |
|
| 552 | + foreach($join as $k=>$v){ |
|
| 553 | + $v = str_replace('DISTINCT ','',$v); |
|
| 554 | + // fct SQL sur colonne et constante apostrophee ==> la colonne |
|
| 555 | + $v = preg_replace('/\w+\(\s*([^(),\']*),\s*\'[^\']*\'[^)]*\)/','\\1', $v); |
|
| 556 | + $v = preg_replace('/CAST\(\s*([^(),\' ]*\s+)as\s*\w+\)/','\\1', $v); |
|
| 557 | + // resultat d'agregat ne sont pas a mettre dans le groupby |
|
| 558 | + $v = preg_replace('/(SUM|COUNT|MAX|MIN|UPPER)\([^)]+\)(\s*AS\s+\w+)\s*,?/i','', $v); |
|
| 559 | + // idem sans AS (fetch numerique) |
|
| 560 | + $v = preg_replace('/(SUM|COUNT|MAX|MIN|UPPER)\([^)]+\)\s*,?/i','', $v); |
|
| 561 | + // des AS simples : on garde le cote droit du AS |
|
| 562 | + $v = preg_replace('/^.*\sAS\s+(\w+)\s*$/i','\\1', $v); |
|
| 563 | + // ne reste plus que les vrais colonnes, ou des constantes a virer |
|
| 564 | + if (preg_match(',^[\'"],',$v) OR is_numeric($v)) |
|
| 565 | + unset($join[$k]); |
|
| 566 | + else |
|
| 567 | + $join[$k] = trim($v); |
|
| 568 | + } |
|
| 569 | + $join = array_diff($join,array('')); |
|
| 570 | + $join = implode(',',$join); |
|
| 571 | + } |
|
| 572 | + if (is_array($groupby)) $groupby = join(',',$groupby); |
|
| 573 | + if ($join) $groupby = $groupby ? "$groupby, $join" : $join; |
|
| 574 | + if (!$groupby) return ''; |
|
| 575 | + |
|
| 576 | + $groupby = spip_pg_frommysql($groupby); |
|
| 577 | + // Ne pas mettre dans le Group-By des valeurs numeriques |
|
| 578 | + // issue de prepare_recherche |
|
| 579 | + $groupby = preg_replace('/^\s*\d+\s+AS\s+\w+\s*,?\s*/i','', $groupby); |
|
| 580 | + $groupby = preg_replace('/,\s*\d+\s+AS\s+\w+\s*/i','', $groupby); |
|
| 581 | + $groupby = preg_replace('/\s+AS\s+\w+\s*/i','', $groupby); |
|
| 582 | + |
|
| 583 | + return "\nGROUP BY $groupby"; |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | // Conversion des operateurs MySQL en PG |
@@ -593,270 +593,270 @@ discard block |
||
| 593 | 593 | // http://doc.spip.org/@spip_pg_frommysql |
| 594 | 594 | function spip_pg_frommysql($arg) |
| 595 | 595 | { |
| 596 | - if (is_array($arg)) $arg = join(", ", $arg); |
|
| 596 | + if (is_array($arg)) $arg = join(", ", $arg); |
|
| 597 | 597 | |
| 598 | - $res = spip_pg_fromfield($arg); |
|
| 598 | + $res = spip_pg_fromfield($arg); |
|
| 599 | 599 | |
| 600 | - $res = preg_replace('/\brand[(][)]/i','random()', $res); |
|
| 600 | + $res = preg_replace('/\brand[(][)]/i','random()', $res); |
|
| 601 | 601 | |
| 602 | - $res = preg_replace('/\b0\.0[+]([a-zA-Z0-9_.]+)\s*/', |
|
| 603 | - 'CAST(substring(\1, \'^ *[0-9.]+\') as float)', |
|
| 604 | - $res); |
|
| 605 | - $res = preg_replace('/\b0[+]([a-zA-Z0-9_.]+)\s*/', |
|
| 606 | - 'CAST(substring(\1, \'^ *[0-9]+\') as int)', |
|
| 607 | - $res); |
|
| 608 | - $res = preg_replace('/\bconv[(]([^,]*)[^)]*[)]/i', |
|
| 609 | - 'CAST(substring(\1, \'^ *[0-9]+\') as int)', |
|
| 610 | - $res); |
|
| 602 | + $res = preg_replace('/\b0\.0[+]([a-zA-Z0-9_.]+)\s*/', |
|
| 603 | + 'CAST(substring(\1, \'^ *[0-9.]+\') as float)', |
|
| 604 | + $res); |
|
| 605 | + $res = preg_replace('/\b0[+]([a-zA-Z0-9_.]+)\s*/', |
|
| 606 | + 'CAST(substring(\1, \'^ *[0-9]+\') as int)', |
|
| 607 | + $res); |
|
| 608 | + $res = preg_replace('/\bconv[(]([^,]*)[^)]*[)]/i', |
|
| 609 | + 'CAST(substring(\1, \'^ *[0-9]+\') as int)', |
|
| 610 | + $res); |
|
| 611 | 611 | |
| 612 | - $res = preg_replace('/UNIX_TIMESTAMP\s*[(]\s*[)]/', |
|
| 613 | - ' EXTRACT(epoch FROM NOW())', $res); |
|
| 612 | + $res = preg_replace('/UNIX_TIMESTAMP\s*[(]\s*[)]/', |
|
| 613 | + ' EXTRACT(epoch FROM NOW())', $res); |
|
| 614 | 614 | |
| 615 | - // la fonction md5(integer) n'est pas connu en pg |
|
| 616 | - // il faut donc forcer les types en text (cas de md5(id_article)) |
|
| 617 | - $res = preg_replace('/md5\s*[(]([^)]*)[)]/i', |
|
| 618 | - 'MD5(CAST(\1 AS text))', $res); |
|
| 615 | + // la fonction md5(integer) n'est pas connu en pg |
|
| 616 | + // il faut donc forcer les types en text (cas de md5(id_article)) |
|
| 617 | + $res = preg_replace('/md5\s*[(]([^)]*)[)]/i', |
|
| 618 | + 'MD5(CAST(\1 AS text))', $res); |
|
| 619 | 619 | |
| 620 | - $res = preg_replace('/UNIX_TIMESTAMP\s*[(]([^)]*)[)]/', |
|
| 621 | - ' EXTRACT(epoch FROM \1)', $res); |
|
| 620 | + $res = preg_replace('/UNIX_TIMESTAMP\s*[(]([^)]*)[)]/', |
|
| 621 | + ' EXTRACT(epoch FROM \1)', $res); |
|
| 622 | 622 | |
| 623 | - $res = preg_replace('/\bDAYOFMONTH\s*[(]([^()]*([(][^()]*[)][^()]*)*[^)]*)[)]/', |
|
| 624 | - ' EXTRACT(day FROM \1)', |
|
| 625 | - $res); |
|
| 623 | + $res = preg_replace('/\bDAYOFMONTH\s*[(]([^()]*([(][^()]*[)][^()]*)*[^)]*)[)]/', |
|
| 624 | + ' EXTRACT(day FROM \1)', |
|
| 625 | + $res); |
|
| 626 | 626 | |
| 627 | - $res = preg_replace('/\bMONTH\s*[(]([^()]*([(][^)]*[)][^()]*)*[^)]*)[)]/', |
|
| 628 | - ' EXTRACT(month FROM \1)', |
|
| 629 | - $res); |
|
| 627 | + $res = preg_replace('/\bMONTH\s*[(]([^()]*([(][^)]*[)][^()]*)*[^)]*)[)]/', |
|
| 628 | + ' EXTRACT(month FROM \1)', |
|
| 629 | + $res); |
|
| 630 | 630 | |
| 631 | - $res = preg_replace('/\bYEAR\s*[(]([^()]*([(][^)]*[)][^()]*)*[^)]*)[)]/', |
|
| 632 | - ' EXTRACT(year FROM \1)', |
|
| 633 | - $res); |
|
| 631 | + $res = preg_replace('/\bYEAR\s*[(]([^()]*([(][^)]*[)][^()]*)*[^)]*)[)]/', |
|
| 632 | + ' EXTRACT(year FROM \1)', |
|
| 633 | + $res); |
|
| 634 | 634 | |
| 635 | - $res = preg_replace('/TO_DAYS\s*[(]([^()]*([(][^)]*[)][()]*)*)[)]/', |
|
| 636 | - ' EXTRACT(day FROM \1 - \'0001-01-01\')', |
|
| 637 | - $res); |
|
| 635 | + $res = preg_replace('/TO_DAYS\s*[(]([^()]*([(][^)]*[)][()]*)*)[)]/', |
|
| 636 | + ' EXTRACT(day FROM \1 - \'0001-01-01\')', |
|
| 637 | + $res); |
|
| 638 | 638 | |
| 639 | - $res = preg_replace("/(EXTRACT[(][^ ]* FROM *)\"([^\"]*)\"/", '\1\'\2\'', $res); |
|
| 639 | + $res = preg_replace("/(EXTRACT[(][^ ]* FROM *)\"([^\"]*)\"/", '\1\'\2\'', $res); |
|
| 640 | 640 | |
| 641 | - $res = preg_replace('/DATE_FORMAT\s*[(]([^,]*),\s*\'%Y%m%d\'[)]/', 'to_char(\1, \'YYYYMMDD\')', $res); |
|
| 641 | + $res = preg_replace('/DATE_FORMAT\s*[(]([^,]*),\s*\'%Y%m%d\'[)]/', 'to_char(\1, \'YYYYMMDD\')', $res); |
|
| 642 | 642 | |
| 643 | - $res = preg_replace('/DATE_FORMAT\s*[(]([^,]*),\s*\'%Y%m\'[)]/', 'to_char(\1, \'YYYYMM\')', $res); |
|
| 643 | + $res = preg_replace('/DATE_FORMAT\s*[(]([^,]*),\s*\'%Y%m\'[)]/', 'to_char(\1, \'YYYYMM\')', $res); |
|
| 644 | 644 | |
| 645 | - $res = preg_replace('/DATE_SUB\s*[(]([^,]*),/', '(\1 -', $res); |
|
| 646 | - $res = preg_replace('/DATE_ADD\s*[(]([^,]*),/', '(\1 +', $res); |
|
| 647 | - $res = preg_replace('/INTERVAL\s+(\d+\s+\w+)/', 'INTERVAL \'\1\'', $res); |
|
| 648 | - $res = preg_replace('/([+<>-]=?)\s*(\'\d+-\d+-\d+\s+\d+:\d+(:\d+)\')/', '\1 timestamp \2', $res); |
|
| 649 | - $res = preg_replace('/(\'\d+-\d+-\d+\s+\d+:\d+:\d+\')\s*([+<>-]=?)/', 'timestamp \1 \2', $res); |
|
| 645 | + $res = preg_replace('/DATE_SUB\s*[(]([^,]*),/', '(\1 -', $res); |
|
| 646 | + $res = preg_replace('/DATE_ADD\s*[(]([^,]*),/', '(\1 +', $res); |
|
| 647 | + $res = preg_replace('/INTERVAL\s+(\d+\s+\w+)/', 'INTERVAL \'\1\'', $res); |
|
| 648 | + $res = preg_replace('/([+<>-]=?)\s*(\'\d+-\d+-\d+\s+\d+:\d+(:\d+)\')/', '\1 timestamp \2', $res); |
|
| 649 | + $res = preg_replace('/(\'\d+-\d+-\d+\s+\d+:\d+:\d+\')\s*([+<>-]=?)/', 'timestamp \1 \2', $res); |
|
| 650 | 650 | |
| 651 | - $res = preg_replace('/([+<>-]=?)\s*(\'\d+-\d+-\d+\')/', '\1 timestamp \2', $res); |
|
| 652 | - $res = preg_replace('/(\'\d+-\d+-\d+\')\s*([+<>-]=?)/', 'timestamp \1 \2', $res); |
|
| 651 | + $res = preg_replace('/([+<>-]=?)\s*(\'\d+-\d+-\d+\')/', '\1 timestamp \2', $res); |
|
| 652 | + $res = preg_replace('/(\'\d+-\d+-\d+\')\s*([+<>-]=?)/', 'timestamp \1 \2', $res); |
|
| 653 | 653 | |
| 654 | - $res = preg_replace('/(timestamp .\d+)-00-/','\1-01-', $res); |
|
| 655 | - $res = preg_replace('/(timestamp .\d+-\d+)-00/','\1-01',$res); |
|
| 654 | + $res = preg_replace('/(timestamp .\d+)-00-/','\1-01-', $res); |
|
| 655 | + $res = preg_replace('/(timestamp .\d+-\d+)-00/','\1-01',$res); |
|
| 656 | 656 | # correct en theorie mais produit des debordements arithmetiques |
| 657 | 657 | # $res = preg_replace("/(EXTRACT[(][^ ]* FROM *)(timestamp *'[^']*' *[+-] *timestamp *'[^']*') *[)]/", '\2', $res); |
| 658 | - $res = preg_replace("/(EXTRACT[(][^ ]* FROM *)('[^']*')/", '\1 timestamp \2', $res); |
|
| 659 | - $res = preg_replace("/\sLIKE\s+/", ' ILIKE ', $res); |
|
| 660 | - return str_replace('REGEXP', '~', $res); |
|
| 658 | + $res = preg_replace("/(EXTRACT[(][^ ]* FROM *)('[^']*')/", '\1 timestamp \2', $res); |
|
| 659 | + $res = preg_replace("/\sLIKE\s+/", ' ILIKE ', $res); |
|
| 660 | + return str_replace('REGEXP', '~', $res); |
|
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | // http://doc.spip.org/@spip_pg_fromfield |
| 664 | 664 | function spip_pg_fromfield($arg) |
| 665 | 665 | { |
| 666 | - while(preg_match('/^(.*?)FIELD\s*\(([^,]*)((,[^,)]*)*)\)/', $arg, $m)) { |
|
| 667 | - |
|
| 668 | - preg_match_all('/,([^,]*)/', $m[3], $r, PREG_PATTERN_ORDER); |
|
| 669 | - $res = ''; |
|
| 670 | - $n=0; |
|
| 671 | - $index = $m[2]; |
|
| 672 | - foreach($r[1] as $v) { |
|
| 673 | - $n++; |
|
| 674 | - $res .= "\nwhen $index=$v then $n"; |
|
| 675 | - } |
|
| 676 | - $arg = $m[1] . "case $res else 0 end " |
|
| 677 | - . substr($arg,strlen($m[0])); |
|
| 678 | - } |
|
| 679 | - return $arg; |
|
| 666 | + while(preg_match('/^(.*?)FIELD\s*\(([^,]*)((,[^,)]*)*)\)/', $arg, $m)) { |
|
| 667 | + |
|
| 668 | + preg_match_all('/,([^,]*)/', $m[3], $r, PREG_PATTERN_ORDER); |
|
| 669 | + $res = ''; |
|
| 670 | + $n=0; |
|
| 671 | + $index = $m[2]; |
|
| 672 | + foreach($r[1] as $v) { |
|
| 673 | + $n++; |
|
| 674 | + $res .= "\nwhen $index=$v then $n"; |
|
| 675 | + } |
|
| 676 | + $arg = $m[1] . "case $res else 0 end " |
|
| 677 | + . substr($arg,strlen($m[0])); |
|
| 678 | + } |
|
| 679 | + return $arg; |
|
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | // http://doc.spip.org/@calculer_pg_where |
| 683 | 683 | function calculer_pg_where($v) |
| 684 | 684 | { |
| 685 | - if (!is_array($v)) |
|
| 686 | - return spip_pg_frommysql($v); |
|
| 687 | - |
|
| 688 | - $op = str_replace('REGEXP', '~', array_shift($v)); |
|
| 689 | - if (!($n=count($v))) |
|
| 690 | - return $op; |
|
| 691 | - else { |
|
| 692 | - $arg = calculer_pg_where(array_shift($v)); |
|
| 693 | - if ($n==1) { |
|
| 694 | - return "$op($arg)"; |
|
| 695 | - } else { |
|
| 696 | - $arg2 = calculer_pg_where(array_shift($v)); |
|
| 697 | - if ($n==2) { |
|
| 698 | - return "($arg $op $arg2)"; |
|
| 699 | - } else return "($arg $op ($arg2) : $v[0])"; |
|
| 700 | - } |
|
| 701 | - } |
|
| 685 | + if (!is_array($v)) |
|
| 686 | + return spip_pg_frommysql($v); |
|
| 687 | + |
|
| 688 | + $op = str_replace('REGEXP', '~', array_shift($v)); |
|
| 689 | + if (!($n=count($v))) |
|
| 690 | + return $op; |
|
| 691 | + else { |
|
| 692 | + $arg = calculer_pg_where(array_shift($v)); |
|
| 693 | + if ($n==1) { |
|
| 694 | + return "$op($arg)"; |
|
| 695 | + } else { |
|
| 696 | + $arg2 = calculer_pg_where(array_shift($v)); |
|
| 697 | + if ($n==2) { |
|
| 698 | + return "($arg $op $arg2)"; |
|
| 699 | + } else return "($arg $op ($arg2) : $v[0])"; |
|
| 700 | + } |
|
| 701 | + } |
|
| 702 | 702 | } |
| 703 | 703 | |
| 704 | 704 | |
| 705 | 705 | // http://doc.spip.org/@calculer_pg_expression |
| 706 | 706 | function calculer_pg_expression($expression, $v, $join = 'AND'){ |
| 707 | - if (empty($v)) |
|
| 708 | - return ''; |
|
| 707 | + if (empty($v)) |
|
| 708 | + return ''; |
|
| 709 | 709 | |
| 710 | - $exp = "\n$expression "; |
|
| 710 | + $exp = "\n$expression "; |
|
| 711 | 711 | |
| 712 | - if (!is_array($v)) $v = array($v); |
|
| 712 | + if (!is_array($v)) $v = array($v); |
|
| 713 | 713 | |
| 714 | - if (strtoupper($join) === 'AND') |
|
| 715 | - return $exp . join("\n\t$join ", array_map('calculer_pg_where', $v)); |
|
| 716 | - else |
|
| 717 | - return $exp . join($join, $v); |
|
| 714 | + if (strtoupper($join) === 'AND') |
|
| 715 | + return $exp . join("\n\t$join ", array_map('calculer_pg_where', $v)); |
|
| 716 | + else |
|
| 717 | + return $exp . join($join, $v); |
|
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | // http://doc.spip.org/@spip_pg_select_as |
| 721 | 721 | function spip_pg_select_as($args) |
| 722 | 722 | { |
| 723 | - $argsas = ""; |
|
| 724 | - foreach($args as $k => $v) { |
|
| 725 | - if (substr($k,-1)=='@') { |
|
| 726 | - // c'est une jointure qui se refere au from precedent |
|
| 727 | - // pas de virgule |
|
| 728 | - $argsas .= ' ' . $v ; |
|
| 729 | - } |
|
| 730 | - else { |
|
| 731 | - $as = ''; |
|
| 732 | - // spip_log("$k : $v", _LOG_DEBUG); |
|
| 733 | - if (!is_numeric($k)) { |
|
| 734 | - if (preg_match('/\.(.*)$/', $k, $r)) |
|
| 735 | - $v = $k; |
|
| 736 | - elseif ($v != $k) { |
|
| 737 | - $p = strpos($v, " "); |
|
| 738 | - if ($p) |
|
| 739 | - $v = substr($v,0,$p) . " AS $k" . substr($v,$p); |
|
| 740 | - else $as = " AS $k"; |
|
| 741 | - } |
|
| 742 | - } |
|
| 743 | - // spip_log("subs $k : $v avec $as", _LOG_DEBUG); |
|
| 744 | - // if (strpos($v, 'JOIN') === false) $argsas .= ', '; |
|
| 745 | - $argsas .= ', '. $v . $as; |
|
| 746 | - } |
|
| 747 | - } |
|
| 748 | - return substr($argsas,2); |
|
| 723 | + $argsas = ""; |
|
| 724 | + foreach($args as $k => $v) { |
|
| 725 | + if (substr($k,-1)=='@') { |
|
| 726 | + // c'est une jointure qui se refere au from precedent |
|
| 727 | + // pas de virgule |
|
| 728 | + $argsas .= ' ' . $v ; |
|
| 729 | + } |
|
| 730 | + else { |
|
| 731 | + $as = ''; |
|
| 732 | + // spip_log("$k : $v", _LOG_DEBUG); |
|
| 733 | + if (!is_numeric($k)) { |
|
| 734 | + if (preg_match('/\.(.*)$/', $k, $r)) |
|
| 735 | + $v = $k; |
|
| 736 | + elseif ($v != $k) { |
|
| 737 | + $p = strpos($v, " "); |
|
| 738 | + if ($p) |
|
| 739 | + $v = substr($v,0,$p) . " AS $k" . substr($v,$p); |
|
| 740 | + else $as = " AS $k"; |
|
| 741 | + } |
|
| 742 | + } |
|
| 743 | + // spip_log("subs $k : $v avec $as", _LOG_DEBUG); |
|
| 744 | + // if (strpos($v, 'JOIN') === false) $argsas .= ', '; |
|
| 745 | + $argsas .= ', '. $v . $as; |
|
| 746 | + } |
|
| 747 | + } |
|
| 748 | + return substr($argsas,2); |
|
| 749 | 749 | } |
| 750 | 750 | |
| 751 | 751 | // http://doc.spip.org/@spip_pg_fetch |
| 752 | 752 | function spip_pg_fetch($res, $t='', $serveur='',$requeter=true) { |
| 753 | 753 | |
| 754 | - if ($res) $res = pg_fetch_array($res, NULL, PGSQL_ASSOC); |
|
| 755 | - return $res; |
|
| 754 | + if ($res) $res = pg_fetch_array($res, NULL, PGSQL_ASSOC); |
|
| 755 | + return $res; |
|
| 756 | 756 | } |
| 757 | 757 | |
| 758 | 758 | function spip_pg_seek($r, $row_number, $serveur='',$requeter=true) { |
| 759 | - if ($r) return pg_result_seek($r,$row_number); |
|
| 759 | + if ($r) return pg_result_seek($r,$row_number); |
|
| 760 | 760 | } |
| 761 | 761 | |
| 762 | 762 | |
| 763 | 763 | // http://doc.spip.org/@spip_pg_countsel |
| 764 | 764 | function spip_pg_countsel($from = array(), $where = array(), $groupby=array(), |
| 765 | - $having = array(), $serveur='',$requeter=true) |
|
| 765 | + $having = array(), $serveur='',$requeter=true) |
|
| 766 | 766 | { |
| 767 | - $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 768 | - $r = spip_pg_select("COUNT($c)", $from, $where,'', '', '', $having, $serveur, $requeter); |
|
| 769 | - if (!$requeter) return $r; |
|
| 770 | - if (!is_resource($r)) return 0; |
|
| 771 | - list($c) = pg_fetch_array($r, NULL, PGSQL_NUM); |
|
| 772 | - return $c; |
|
| 767 | + $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 768 | + $r = spip_pg_select("COUNT($c)", $from, $where,'', '', '', $having, $serveur, $requeter); |
|
| 769 | + if (!$requeter) return $r; |
|
| 770 | + if (!is_resource($r)) return 0; |
|
| 771 | + list($c) = pg_fetch_array($r, NULL, PGSQL_NUM); |
|
| 772 | + return $c; |
|
| 773 | 773 | } |
| 774 | 774 | |
| 775 | 775 | // http://doc.spip.org/@spip_pg_count |
| 776 | 776 | function spip_pg_count($res, $serveur='',$requeter=true) { |
| 777 | - return !$res ? 0 : pg_numrows($res); |
|
| 777 | + return !$res ? 0 : pg_numrows($res); |
|
| 778 | 778 | } |
| 779 | 779 | |
| 780 | 780 | // http://doc.spip.org/@spip_pg_free |
| 781 | 781 | function spip_pg_free($res, $serveur='',$requeter=true) { |
| 782 | - // rien a faire en postgres |
|
| 782 | + // rien a faire en postgres |
|
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | // http://doc.spip.org/@spip_pg_delete |
| 786 | 786 | function spip_pg_delete($table, $where='', $serveur='',$requeter=true) { |
| 787 | 787 | |
| 788 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 789 | - $prefixe = $connexion['prefixe']; |
|
| 790 | - $link = $connexion['link']; |
|
| 791 | - $db = $connexion['db']; |
|
| 792 | - if ($prefixe) $table = preg_replace('/^spip/', $prefixe, $table); |
|
| 788 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 789 | + $prefixe = $connexion['prefixe']; |
|
| 790 | + $link = $connexion['link']; |
|
| 791 | + $db = $connexion['db']; |
|
| 792 | + if ($prefixe) $table = preg_replace('/^spip/', $prefixe, $table); |
|
| 793 | 793 | |
| 794 | - $query = calculer_pg_expression('DELETE FROM', $table, ',') |
|
| 795 | - . calculer_pg_expression('WHERE', $where, 'AND'); |
|
| 794 | + $query = calculer_pg_expression('DELETE FROM', $table, ',') |
|
| 795 | + . calculer_pg_expression('WHERE', $where, 'AND'); |
|
| 796 | 796 | |
| 797 | - // renvoyer la requete inerte si demandee |
|
| 798 | - if (!$requeter) return $query; |
|
| 797 | + // renvoyer la requete inerte si demandee |
|
| 798 | + if (!$requeter) return $query; |
|
| 799 | 799 | |
| 800 | - $res = spip_pg_trace_query($query, $serveur); |
|
| 801 | - if ($res) |
|
| 802 | - return pg_affected_rows($res); |
|
| 803 | - else |
|
| 804 | - return false; |
|
| 800 | + $res = spip_pg_trace_query($query, $serveur); |
|
| 801 | + if ($res) |
|
| 802 | + return pg_affected_rows($res); |
|
| 803 | + else |
|
| 804 | + return false; |
|
| 805 | 805 | } |
| 806 | 806 | |
| 807 | 807 | // http://doc.spip.org/@spip_pg_insert |
| 808 | 808 | function spip_pg_insert($table, $champs, $valeurs, $desc=array(), $serveur='',$requeter=true) { |
| 809 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 810 | - $prefixe = $connexion['prefixe']; |
|
| 811 | - $link = $connexion['link']; |
|
| 812 | - $db = $connexion['db']; |
|
| 813 | - |
|
| 814 | - if (!$desc) $desc = description_table($table, $serveur); |
|
| 815 | - $seq = spip_pg_sequence($table,true); |
|
| 816 | - // si pas de cle primaire dans l'insertion, renvoyer curval |
|
| 817 | - if (!preg_match(",\b$seq\b,",$champs)){ |
|
| 818 | - $seq = spip_pg_sequence($table); |
|
| 819 | - if ($prefixe) |
|
| 820 | - $seq = preg_replace('/^spip/', $prefixe, $seq); |
|
| 821 | - $seq = "currval('$seq')"; |
|
| 822 | - } |
|
| 823 | - |
|
| 824 | - |
|
| 825 | - if ($prefixe) { |
|
| 826 | - $table = preg_replace('/^spip/', $prefixe, $table); |
|
| 827 | - } |
|
| 828 | - $ret = !$seq ? '' : (" RETURNING $seq"); |
|
| 829 | - $ins = (strlen($champs)<3) |
|
| 830 | - ? " DEFAULT VALUES" |
|
| 831 | - : "$champs VALUES $valeurs"; |
|
| 832 | - $q ="INSERT INTO $table $ins $ret"; |
|
| 833 | - if (!$requeter) return $q; |
|
| 834 | - $connexion['last'] = $q; |
|
| 835 | - $r = spip_pg_query_simple($link, $q); |
|
| 809 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 810 | + $prefixe = $connexion['prefixe']; |
|
| 811 | + $link = $connexion['link']; |
|
| 812 | + $db = $connexion['db']; |
|
| 813 | + |
|
| 814 | + if (!$desc) $desc = description_table($table, $serveur); |
|
| 815 | + $seq = spip_pg_sequence($table,true); |
|
| 816 | + // si pas de cle primaire dans l'insertion, renvoyer curval |
|
| 817 | + if (!preg_match(",\b$seq\b,",$champs)){ |
|
| 818 | + $seq = spip_pg_sequence($table); |
|
| 819 | + if ($prefixe) |
|
| 820 | + $seq = preg_replace('/^spip/', $prefixe, $seq); |
|
| 821 | + $seq = "currval('$seq')"; |
|
| 822 | + } |
|
| 823 | + |
|
| 824 | + |
|
| 825 | + if ($prefixe) { |
|
| 826 | + $table = preg_replace('/^spip/', $prefixe, $table); |
|
| 827 | + } |
|
| 828 | + $ret = !$seq ? '' : (" RETURNING $seq"); |
|
| 829 | + $ins = (strlen($champs)<3) |
|
| 830 | + ? " DEFAULT VALUES" |
|
| 831 | + : "$champs VALUES $valeurs"; |
|
| 832 | + $q ="INSERT INTO $table $ins $ret"; |
|
| 833 | + if (!$requeter) return $q; |
|
| 834 | + $connexion['last'] = $q; |
|
| 835 | + $r = spip_pg_query_simple($link, $q); |
|
| 836 | 836 | # spip_log($q,'pg.'._LOG_DEBUG); |
| 837 | - if ($r) { |
|
| 838 | - if (!$ret) return 0; |
|
| 839 | - if ($r2 = pg_fetch_array($r, NULL, PGSQL_NUM)) |
|
| 840 | - return $r2[0]; |
|
| 841 | - } |
|
| 842 | - return false; |
|
| 837 | + if ($r) { |
|
| 838 | + if (!$ret) return 0; |
|
| 839 | + if ($r2 = pg_fetch_array($r, NULL, PGSQL_NUM)) |
|
| 840 | + return $r2[0]; |
|
| 841 | + } |
|
| 842 | + return false; |
|
| 843 | 843 | } |
| 844 | 844 | |
| 845 | 845 | // http://doc.spip.org/@spip_pg_insertq |
| 846 | 846 | function spip_pg_insertq($table, $couples=array(), $desc=array(), $serveur='',$requeter=true) { |
| 847 | 847 | |
| 848 | - if (!$desc) $desc = description_table($table, $serveur); |
|
| 849 | - if (!$desc) die("$table insertion sans description"); |
|
| 850 | - $fields = $desc['field']; |
|
| 848 | + if (!$desc) $desc = description_table($table, $serveur); |
|
| 849 | + if (!$desc) die("$table insertion sans description"); |
|
| 850 | + $fields = $desc['field']; |
|
| 851 | 851 | |
| 852 | - foreach ($couples as $champ => $val) { |
|
| 853 | - $couples[$champ]= spip_pg_cite($val, $fields[$champ]); |
|
| 854 | - } |
|
| 852 | + foreach ($couples as $champ => $val) { |
|
| 853 | + $couples[$champ]= spip_pg_cite($val, $fields[$champ]); |
|
| 854 | + } |
|
| 855 | 855 | |
| 856 | - // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 857 | - $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 856 | + // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 857 | + $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 858 | 858 | |
| 859 | - return spip_pg_insert($table, "(".join(',',array_keys($couples)).")", "(".join(',', $couples).")", $desc, $serveur, $requeter); |
|
| 859 | + return spip_pg_insert($table, "(".join(',',array_keys($couples)).")", "(".join(',', $couples).")", $desc, $serveur, $requeter); |
|
| 860 | 860 | } |
| 861 | 861 | |
| 862 | 862 | |
@@ -864,148 +864,148 @@ discard block |
||
| 864 | 864 | // http://doc.spip.org/@spip_pg_insertq_multi |
| 865 | 865 | function spip_pg_insertq_multi($table, $tab_couples=array(), $desc=array(), $serveur='',$requeter=true) { |
| 866 | 866 | |
| 867 | - if (!$desc) $desc = description_table($table, $serveur); |
|
| 868 | - if (!$desc) die("$table insertion sans description"); |
|
| 869 | - $fields = isset($desc['field'])?$desc['field']:array(); |
|
| 867 | + if (!$desc) $desc = description_table($table, $serveur); |
|
| 868 | + if (!$desc) die("$table insertion sans description"); |
|
| 869 | + $fields = isset($desc['field'])?$desc['field']:array(); |
|
| 870 | 870 | |
| 871 | - // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 872 | - // une premiere fois pour ajouter maj dans les cles |
|
| 873 | - $c = isset($tab_couples[0]) ? $tab_couples[0] : array(); |
|
| 874 | - $les_cles = spip_pg_ajouter_champs_timestamp($table, $c, $desc, $serveur); |
|
| 871 | + // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 872 | + // une premiere fois pour ajouter maj dans les cles |
|
| 873 | + $c = isset($tab_couples[0]) ? $tab_couples[0] : array(); |
|
| 874 | + $les_cles = spip_pg_ajouter_champs_timestamp($table, $c, $desc, $serveur); |
|
| 875 | 875 | |
| 876 | - $cles = "(" . join(',',array_keys($les_cles)). ')'; |
|
| 877 | - $valeurs = array(); |
|
| 878 | - foreach ($tab_couples as $couples) { |
|
| 879 | - foreach ($couples as $champ => $val){ |
|
| 880 | - $couples[$champ]= spip_pg_cite($val, $fields[$champ]); |
|
| 881 | - } |
|
| 882 | - // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 883 | - $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 876 | + $cles = "(" . join(',',array_keys($les_cles)). ')'; |
|
| 877 | + $valeurs = array(); |
|
| 878 | + foreach ($tab_couples as $couples) { |
|
| 879 | + foreach ($couples as $champ => $val){ |
|
| 880 | + $couples[$champ]= spip_pg_cite($val, $fields[$champ]); |
|
| 881 | + } |
|
| 882 | + // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 883 | + $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 884 | 884 | |
| 885 | - $valeurs[] = '(' .join(',', $couples) . ')'; |
|
| 886 | - } |
|
| 887 | - $valeurs = implode(', ',$valeurs); |
|
| 885 | + $valeurs[] = '(' .join(',', $couples) . ')'; |
|
| 886 | + } |
|
| 887 | + $valeurs = implode(', ',$valeurs); |
|
| 888 | 888 | |
| 889 | - return spip_pg_insert($table, $cles, $valeurs, $desc, $serveur, $requeter); |
|
| 889 | + return spip_pg_insert($table, $cles, $valeurs, $desc, $serveur, $requeter); |
|
| 890 | 890 | } |
| 891 | 891 | |
| 892 | 892 | |
| 893 | 893 | // http://doc.spip.org/@spip_pg_update |
| 894 | 894 | function spip_pg_update($table, $couples, $where='', $desc='', $serveur='',$requeter=true) { |
| 895 | 895 | |
| 896 | - if (!$couples) return; |
|
| 897 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 898 | - $prefixe = $connexion['prefixe']; |
|
| 899 | - $link = $connexion['link']; |
|
| 900 | - $db = $connexion['db']; |
|
| 901 | - if ($prefixe) $table = preg_replace('/^spip/', $prefixe, $table); |
|
| 896 | + if (!$couples) return; |
|
| 897 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 898 | + $prefixe = $connexion['prefixe']; |
|
| 899 | + $link = $connexion['link']; |
|
| 900 | + $db = $connexion['db']; |
|
| 901 | + if ($prefixe) $table = preg_replace('/^spip/', $prefixe, $table); |
|
| 902 | 902 | |
| 903 | - // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 904 | - $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 903 | + // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 904 | + $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 905 | 905 | |
| 906 | - $set = array(); |
|
| 907 | - foreach ($couples as $champ => $val) { |
|
| 908 | - $set[] = $champ . '=' . $val; |
|
| 909 | - } |
|
| 906 | + $set = array(); |
|
| 907 | + foreach ($couples as $champ => $val) { |
|
| 908 | + $set[] = $champ . '=' . $val; |
|
| 909 | + } |
|
| 910 | 910 | |
| 911 | - $query = calculer_pg_expression('UPDATE', $table, ',') |
|
| 912 | - . calculer_pg_expression('SET', $set, ',') |
|
| 913 | - . calculer_pg_expression('WHERE', $where, 'AND'); |
|
| 911 | + $query = calculer_pg_expression('UPDATE', $table, ',') |
|
| 912 | + . calculer_pg_expression('SET', $set, ',') |
|
| 913 | + . calculer_pg_expression('WHERE', $where, 'AND'); |
|
| 914 | 914 | |
| 915 | - // renvoyer la requete inerte si demandee |
|
| 916 | - if (!$requeter) return $query; |
|
| 915 | + // renvoyer la requete inerte si demandee |
|
| 916 | + if (!$requeter) return $query; |
|
| 917 | 917 | |
| 918 | - return spip_pg_trace_query($query, $serveur); |
|
| 918 | + return spip_pg_trace_query($query, $serveur); |
|
| 919 | 919 | } |
| 920 | 920 | |
| 921 | 921 | // idem, mais les valeurs sont des constantes a mettre entre apostrophes |
| 922 | 922 | // sauf les expressions de date lorsqu'il s'agit de fonctions SQL (NOW etc) |
| 923 | 923 | // http://doc.spip.org/@spip_pg_updateq |
| 924 | 924 | function spip_pg_updateq($table, $couples, $where='', $desc=array(), $serveur='',$requeter=true) { |
| 925 | - if (!$couples) return; |
|
| 926 | - if (!$desc) $desc = description_table($table, $serveur); |
|
| 927 | - $fields = $desc['field']; |
|
| 928 | - foreach ($couples as $k => $val) { |
|
| 929 | - $couples[$k] = spip_pg_cite($val, $fields[$k]); |
|
| 930 | - } |
|
| 931 | - |
|
| 932 | - return spip_pg_update($table, $couples, $where, $desc, $serveur, $requeter); |
|
| 925 | + if (!$couples) return; |
|
| 926 | + if (!$desc) $desc = description_table($table, $serveur); |
|
| 927 | + $fields = $desc['field']; |
|
| 928 | + foreach ($couples as $k => $val) { |
|
| 929 | + $couples[$k] = spip_pg_cite($val, $fields[$k]); |
|
| 930 | + } |
|
| 931 | + |
|
| 932 | + return spip_pg_update($table, $couples, $where, $desc, $serveur, $requeter); |
|
| 933 | 933 | } |
| 934 | 934 | |
| 935 | 935 | |
| 936 | 936 | // http://doc.spip.org/@spip_pg_replace |
| 937 | 937 | function spip_pg_replace($table, $values, $desc, $serveur='',$requeter=true) { |
| 938 | - if (!$values) {spip_log("replace vide $table",'pg.'._LOG_AVERTISSEMENT); return 0;} |
|
| 939 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 940 | - $prefixe = $connexion['prefixe']; |
|
| 941 | - $link = $connexion['link']; |
|
| 942 | - $db = $connexion['db']; |
|
| 943 | - |
|
| 944 | - if (!$desc) $desc = description_table($table, $serveur); |
|
| 945 | - if (!$desc) die("$table insertion sans description"); |
|
| 946 | - $prim = $desc['key']['PRIMARY KEY']; |
|
| 947 | - $ids = preg_split('/,\s*/', $prim); |
|
| 948 | - $noprims = $prims = array(); |
|
| 949 | - foreach($values as $k=>$v) { |
|
| 950 | - $values[$k] = $v = spip_pg_cite($v, $desc['field'][$k]); |
|
| 951 | - |
|
| 952 | - if (!in_array($k, $ids)) |
|
| 953 | - $noprims[$k]= "$k=$v"; |
|
| 954 | - else $prims[$k]= "$k=$v"; |
|
| 955 | - } |
|
| 956 | - |
|
| 957 | - // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 958 | - $values = spip_pg_ajouter_champs_timestamp($table, $values, $desc, $serveur); |
|
| 938 | + if (!$values) {spip_log("replace vide $table",'pg.'._LOG_AVERTISSEMENT); return 0;} |
|
| 939 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 940 | + $prefixe = $connexion['prefixe']; |
|
| 941 | + $link = $connexion['link']; |
|
| 942 | + $db = $connexion['db']; |
|
| 943 | + |
|
| 944 | + if (!$desc) $desc = description_table($table, $serveur); |
|
| 945 | + if (!$desc) die("$table insertion sans description"); |
|
| 946 | + $prim = $desc['key']['PRIMARY KEY']; |
|
| 947 | + $ids = preg_split('/,\s*/', $prim); |
|
| 948 | + $noprims = $prims = array(); |
|
| 949 | + foreach($values as $k=>$v) { |
|
| 950 | + $values[$k] = $v = spip_pg_cite($v, $desc['field'][$k]); |
|
| 951 | + |
|
| 952 | + if (!in_array($k, $ids)) |
|
| 953 | + $noprims[$k]= "$k=$v"; |
|
| 954 | + else $prims[$k]= "$k=$v"; |
|
| 955 | + } |
|
| 956 | + |
|
| 957 | + // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 958 | + $values = spip_pg_ajouter_champs_timestamp($table, $values, $desc, $serveur); |
|
| 959 | 959 | |
| 960 | - $where = join(' AND ', $prims); |
|
| 961 | - if (!$where) { |
|
| 962 | - return spip_pg_insert($table, "(".join(',',array_keys($values)).")", "(".join(',', $values).")", $desc, $serveur); |
|
| 963 | - } |
|
| 964 | - $couples = join(',', $noprims); |
|
| 965 | - |
|
| 966 | - $seq = spip_pg_sequence($table); |
|
| 967 | - if ($prefixe) { |
|
| 968 | - $table = preg_replace('/^spip/', $prefixe, $table); |
|
| 969 | - $seq = preg_replace('/^spip/', $prefixe, $seq); |
|
| 970 | - } |
|
| 971 | - |
|
| 972 | - $connexion['last'] = $q = "UPDATE $table SET $couples WHERE $where"; |
|
| 973 | - if ($couples) { |
|
| 974 | - $couples = spip_pg_query_simple($link, $q); |
|
| 960 | + $where = join(' AND ', $prims); |
|
| 961 | + if (!$where) { |
|
| 962 | + return spip_pg_insert($table, "(".join(',',array_keys($values)).")", "(".join(',', $values).")", $desc, $serveur); |
|
| 963 | + } |
|
| 964 | + $couples = join(',', $noprims); |
|
| 965 | + |
|
| 966 | + $seq = spip_pg_sequence($table); |
|
| 967 | + if ($prefixe) { |
|
| 968 | + $table = preg_replace('/^spip/', $prefixe, $table); |
|
| 969 | + $seq = preg_replace('/^spip/', $prefixe, $seq); |
|
| 970 | + } |
|
| 971 | + |
|
| 972 | + $connexion['last'] = $q = "UPDATE $table SET $couples WHERE $where"; |
|
| 973 | + if ($couples) { |
|
| 974 | + $couples = spip_pg_query_simple($link, $q); |
|
| 975 | 975 | # spip_log($q,'pg.'._LOG_DEBUG); |
| 976 | - if (!$couples) return false; |
|
| 977 | - $couples = pg_affected_rows($couples); |
|
| 978 | - } |
|
| 979 | - if (!$couples) { |
|
| 980 | - $ret = !$seq ? '' : |
|
| 981 | - (" RETURNING nextval('$seq') < $prim"); |
|
| 982 | - $connexion['last'] = $q = "INSERT INTO $table (" . join(',',array_keys($values)) . ') VALUES (' .join(',', $values) . ")$ret"; |
|
| 983 | - $couples = spip_pg_query_simple($link, $q); |
|
| 984 | - if (!$couples) { |
|
| 985 | - return false; |
|
| 986 | - } elseif ($ret) { |
|
| 987 | - $r = pg_fetch_array($couples, NULL, PGSQL_NUM); |
|
| 988 | - if ($r[0]) { |
|
| 989 | - $connexion['last'] = $q = "SELECT setval('$seq', $prim) from $table"; |
|
| 990 | - // Le code de SPIP met parfois la sequence a 0 (dans l'import) |
|
| 991 | - // MySQL n'en dit rien, on fait pareil pour PG |
|
| 992 | - $r = @pg_query($link, $q); |
|
| 993 | - } |
|
| 994 | - } |
|
| 995 | - } |
|
| 996 | - |
|
| 997 | - return $couples; |
|
| 976 | + if (!$couples) return false; |
|
| 977 | + $couples = pg_affected_rows($couples); |
|
| 978 | + } |
|
| 979 | + if (!$couples) { |
|
| 980 | + $ret = !$seq ? '' : |
|
| 981 | + (" RETURNING nextval('$seq') < $prim"); |
|
| 982 | + $connexion['last'] = $q = "INSERT INTO $table (" . join(',',array_keys($values)) . ') VALUES (' .join(',', $values) . ")$ret"; |
|
| 983 | + $couples = spip_pg_query_simple($link, $q); |
|
| 984 | + if (!$couples) { |
|
| 985 | + return false; |
|
| 986 | + } elseif ($ret) { |
|
| 987 | + $r = pg_fetch_array($couples, NULL, PGSQL_NUM); |
|
| 988 | + if ($r[0]) { |
|
| 989 | + $connexion['last'] = $q = "SELECT setval('$seq', $prim) from $table"; |
|
| 990 | + // Le code de SPIP met parfois la sequence a 0 (dans l'import) |
|
| 991 | + // MySQL n'en dit rien, on fait pareil pour PG |
|
| 992 | + $r = @pg_query($link, $q); |
|
| 993 | + } |
|
| 994 | + } |
|
| 995 | + } |
|
| 996 | + |
|
| 997 | + return $couples; |
|
| 998 | 998 | } |
| 999 | 999 | |
| 1000 | 1000 | |
| 1001 | 1001 | // http://doc.spip.org/@spip_pg_replace_multi |
| 1002 | 1002 | function spip_pg_replace_multi($table, $tab_couples, $desc=array(), $serveur='',$requeter=true) { |
| 1003 | - // boucler pour traiter chaque requete independemment |
|
| 1004 | - foreach ($tab_couples as $couples){ |
|
| 1005 | - $retour = spip_pg_replace($table, $couples, $desc, $serveur,$requeter); |
|
| 1006 | - } |
|
| 1007 | - // renvoie le dernier id |
|
| 1008 | - return $retour; |
|
| 1003 | + // boucler pour traiter chaque requete independemment |
|
| 1004 | + foreach ($tab_couples as $couples){ |
|
| 1005 | + $retour = spip_pg_replace($table, $couples, $desc, $serveur,$requeter); |
|
| 1006 | + } |
|
| 1007 | + // renvoie le dernier id |
|
| 1008 | + return $retour; |
|
| 1009 | 1009 | } |
| 1010 | 1010 | |
| 1011 | 1011 | |
@@ -1016,15 +1016,15 @@ discard block |
||
| 1016 | 1016 | // http://doc.spip.org/@spip_pg_sequence |
| 1017 | 1017 | function spip_pg_sequence($table,$raw=false) |
| 1018 | 1018 | { |
| 1019 | - global $tables_principales; |
|
| 1020 | - include_spip('base/serial'); |
|
| 1021 | - if (!isset($tables_principales[$table])) return false; |
|
| 1022 | - $desc = $tables_principales[$table]; |
|
| 1023 | - $prim = @$desc['key']['PRIMARY KEY']; |
|
| 1024 | - if (!preg_match('/^\w+$/', $prim) |
|
| 1025 | - OR strpos($desc['field'][$prim], 'int') === false) |
|
| 1026 | - return ''; |
|
| 1027 | - else { return $raw?$prim:$table . '_' . $prim . "_seq";} |
|
| 1019 | + global $tables_principales; |
|
| 1020 | + include_spip('base/serial'); |
|
| 1021 | + if (!isset($tables_principales[$table])) return false; |
|
| 1022 | + $desc = $tables_principales[$table]; |
|
| 1023 | + $prim = @$desc['key']['PRIMARY KEY']; |
|
| 1024 | + if (!preg_match('/^\w+$/', $prim) |
|
| 1025 | + OR strpos($desc['field'][$prim], 'int') === false) |
|
| 1026 | + return ''; |
|
| 1027 | + else { return $raw?$prim:$table . '_' . $prim . "_seq";} |
|
| 1028 | 1028 | } |
| 1029 | 1029 | |
| 1030 | 1030 | // Explicite les conversions de Mysql d'une valeur $v de type $t |
@@ -1032,60 +1032,60 @@ discard block |
||
| 1032 | 1032 | |
| 1033 | 1033 | // http://doc.spip.org/@spip_pg_cite |
| 1034 | 1034 | function spip_pg_cite($v, $t){ |
| 1035 | - if(is_null($v)) return 'NULL'; // null php se traduit en NULL SQL |
|
| 1036 | - |
|
| 1037 | - if (sql_test_date($t)) { |
|
| 1038 | - if ($v AND (strpos("0123456789", $v[0]) === false)) |
|
| 1039 | - return spip_pg_frommysql($v); |
|
| 1040 | - else { |
|
| 1041 | - if (strncmp($v,'0000',4)==0) |
|
| 1042 | - $v = "0001" . substr($v,4); |
|
| 1043 | - if (strpos($v, "-00-00") === 4) |
|
| 1044 | - $v = substr($v,0,4)."-01-01".substr($v,10); |
|
| 1045 | - return "timestamp '$v'"; |
|
| 1046 | - } |
|
| 1047 | - } |
|
| 1048 | - elseif (!sql_test_int($t)) |
|
| 1049 | - return ("'" . pg_escape_string($v) . "'"); |
|
| 1050 | - elseif (is_numeric($v) OR (strpos($v, 'CAST(') === 0)) |
|
| 1051 | - return $v; |
|
| 1052 | - elseif ($v[0]== '0' AND $v[1]!=='x' AND ctype_xdigit(substr($v,1))) |
|
| 1053 | - return substr($v,1); |
|
| 1054 | - else { |
|
| 1055 | - spip_log("Warning: '$v' n'est pas de type $t", 'pg.'._LOG_AVERTISSEMENT); |
|
| 1056 | - return intval($v); |
|
| 1057 | - } |
|
| 1035 | + if(is_null($v)) return 'NULL'; // null php se traduit en NULL SQL |
|
| 1036 | + |
|
| 1037 | + if (sql_test_date($t)) { |
|
| 1038 | + if ($v AND (strpos("0123456789", $v[0]) === false)) |
|
| 1039 | + return spip_pg_frommysql($v); |
|
| 1040 | + else { |
|
| 1041 | + if (strncmp($v,'0000',4)==0) |
|
| 1042 | + $v = "0001" . substr($v,4); |
|
| 1043 | + if (strpos($v, "-00-00") === 4) |
|
| 1044 | + $v = substr($v,0,4)."-01-01".substr($v,10); |
|
| 1045 | + return "timestamp '$v'"; |
|
| 1046 | + } |
|
| 1047 | + } |
|
| 1048 | + elseif (!sql_test_int($t)) |
|
| 1049 | + return ("'" . pg_escape_string($v) . "'"); |
|
| 1050 | + elseif (is_numeric($v) OR (strpos($v, 'CAST(') === 0)) |
|
| 1051 | + return $v; |
|
| 1052 | + elseif ($v[0]== '0' AND $v[1]!=='x' AND ctype_xdigit(substr($v,1))) |
|
| 1053 | + return substr($v,1); |
|
| 1054 | + else { |
|
| 1055 | + spip_log("Warning: '$v' n'est pas de type $t", 'pg.'._LOG_AVERTISSEMENT); |
|
| 1056 | + return intval($v); |
|
| 1057 | + } |
|
| 1058 | 1058 | } |
| 1059 | 1059 | |
| 1060 | 1060 | // http://doc.spip.org/@spip_pg_hex |
| 1061 | 1061 | function spip_pg_hex($v) |
| 1062 | 1062 | { |
| 1063 | - return "CAST(x'" . $v . "' as bigint)"; |
|
| 1063 | + return "CAST(x'" . $v . "' as bigint)"; |
|
| 1064 | 1064 | } |
| 1065 | 1065 | |
| 1066 | 1066 | function spip_pg_quote($v, $type='') |
| 1067 | 1067 | { |
| 1068 | - if (!is_array($v)) |
|
| 1069 | - return spip_pg_cite($v,$type); |
|
| 1070 | - // si c'est un tableau, le parcourir en propageant le type |
|
| 1071 | - foreach($v as $k=>$r) |
|
| 1072 | - $v[$k] = spip_pg_quote($r, $type); |
|
| 1073 | - return join(",", $v); |
|
| 1068 | + if (!is_array($v)) |
|
| 1069 | + return spip_pg_cite($v,$type); |
|
| 1070 | + // si c'est un tableau, le parcourir en propageant le type |
|
| 1071 | + foreach($v as $k=>$r) |
|
| 1072 | + $v[$k] = spip_pg_quote($r, $type); |
|
| 1073 | + return join(",", $v); |
|
| 1074 | 1074 | } |
| 1075 | 1075 | |
| 1076 | 1076 | function spip_pg_date_proche($champ, $interval, $unite) |
| 1077 | 1077 | { |
| 1078 | - return '(' |
|
| 1079 | - . $champ |
|
| 1078 | + return '(' |
|
| 1079 | + . $champ |
|
| 1080 | 1080 | . (($interval <= 0) ? '>' : '<') |
| 1081 | 1081 | . (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD') |
| 1082 | - . '(' |
|
| 1083 | - . sql_quote(date('Y-m-d H:i:s')) |
|
| 1084 | - . ', INTERVAL ' |
|
| 1085 | - . (($interval > 0) ? $interval : (0-$interval)) |
|
| 1086 | - . ' ' |
|
| 1087 | - . $unite |
|
| 1088 | - . '))'; |
|
| 1082 | + . '(' |
|
| 1083 | + . sql_quote(date('Y-m-d H:i:s')) |
|
| 1084 | + . ', INTERVAL ' |
|
| 1085 | + . (($interval > 0) ? $interval : (0-$interval)) |
|
| 1086 | + . ' ' |
|
| 1087 | + . $unite |
|
| 1088 | + . '))'; |
|
| 1089 | 1089 | } |
| 1090 | 1090 | |
| 1091 | 1091 | // http://doc.spip.org/@spip_pg_in |
@@ -1093,59 +1093,59 @@ discard block |
||
| 1093 | 1093 | // |
| 1094 | 1094 | // IN (...) souvent limite a 255 elements, d'ou cette fonction assistante |
| 1095 | 1095 | // |
| 1096 | - // s'il n'y a pas de valeur, eviter de produire un IN vide: PG rale. |
|
| 1097 | - if (!$valeurs) return $not ? '0=0' : '0=1'; |
|
| 1098 | - if (strpos($valeurs, "CAST(x'") !== false) |
|
| 1099 | - return "($val=" . join("OR $val=", explode(',',$valeurs)).')'; |
|
| 1100 | - $n = $i = 0; |
|
| 1101 | - $in_sql =""; |
|
| 1102 | - while ($n = strpos($valeurs, ',', $n+1)) { |
|
| 1103 | - if ((++$i) >= 255) { |
|
| 1104 | - $in_sql .= "($val $not IN (" . |
|
| 1105 | - substr($valeurs, 0, $n) . |
|
| 1106 | - "))\n" . |
|
| 1107 | - ($not ? "AND\t" : "OR\t"); |
|
| 1108 | - $valeurs = substr($valeurs, $n+1); |
|
| 1109 | - $i = $n = 0; |
|
| 1110 | - } |
|
| 1111 | - } |
|
| 1112 | - $in_sql .= "($val $not IN ($valeurs))"; |
|
| 1113 | - |
|
| 1114 | - return "($in_sql)"; |
|
| 1096 | + // s'il n'y a pas de valeur, eviter de produire un IN vide: PG rale. |
|
| 1097 | + if (!$valeurs) return $not ? '0=0' : '0=1'; |
|
| 1098 | + if (strpos($valeurs, "CAST(x'") !== false) |
|
| 1099 | + return "($val=" . join("OR $val=", explode(',',$valeurs)).')'; |
|
| 1100 | + $n = $i = 0; |
|
| 1101 | + $in_sql =""; |
|
| 1102 | + while ($n = strpos($valeurs, ',', $n+1)) { |
|
| 1103 | + if ((++$i) >= 255) { |
|
| 1104 | + $in_sql .= "($val $not IN (" . |
|
| 1105 | + substr($valeurs, 0, $n) . |
|
| 1106 | + "))\n" . |
|
| 1107 | + ($not ? "AND\t" : "OR\t"); |
|
| 1108 | + $valeurs = substr($valeurs, $n+1); |
|
| 1109 | + $i = $n = 0; |
|
| 1110 | + } |
|
| 1111 | + } |
|
| 1112 | + $in_sql .= "($val $not IN ($valeurs))"; |
|
| 1113 | + |
|
| 1114 | + return "($in_sql)"; |
|
| 1115 | 1115 | } |
| 1116 | 1116 | |
| 1117 | 1117 | // http://doc.spip.org/@spip_pg_error |
| 1118 | 1118 | function spip_pg_error($query='', $serveur, $requeter=true) { |
| 1119 | - $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 1120 | - $s = $link ? pg_last_error($link) : pg_last_error(); |
|
| 1121 | - if ($s) { |
|
| 1122 | - $s = str_replace('ERROR', 'errcode: 1000 ', $s); |
|
| 1123 | - spip_log("$s - $query", 'pg.'._LOG_ERREUR); |
|
| 1124 | - } |
|
| 1125 | - return $s; |
|
| 1119 | + $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 1120 | + $s = $link ? pg_last_error($link) : pg_last_error(); |
|
| 1121 | + if ($s) { |
|
| 1122 | + $s = str_replace('ERROR', 'errcode: 1000 ', $s); |
|
| 1123 | + spip_log("$s - $query", 'pg.'._LOG_ERREUR); |
|
| 1124 | + } |
|
| 1125 | + return $s; |
|
| 1126 | 1126 | } |
| 1127 | 1127 | |
| 1128 | 1128 | // http://doc.spip.org/@spip_pg_errno |
| 1129 | 1129 | function spip_pg_errno($serveur='') { |
| 1130 | - // il faudrait avoir la derniere ressource retournee et utiliser |
|
| 1131 | - // http://fr2.php.net/manual/fr/function.pg-result-error.php |
|
| 1132 | - return 0; |
|
| 1130 | + // il faudrait avoir la derniere ressource retournee et utiliser |
|
| 1131 | + // http://fr2.php.net/manual/fr/function.pg-result-error.php |
|
| 1132 | + return 0; |
|
| 1133 | 1133 | } |
| 1134 | 1134 | |
| 1135 | 1135 | // http://doc.spip.org/@spip_pg_drop_table |
| 1136 | 1136 | function spip_pg_drop_table($table, $exist='', $serveur='',$requeter=true) |
| 1137 | 1137 | { |
| 1138 | - if ($exist) $exist =" IF EXISTS"; |
|
| 1139 | - if (spip_pg_query("DROP TABLE$exist $table", $serveur, $requeter)) |
|
| 1140 | - return true; |
|
| 1141 | - else return false; |
|
| 1138 | + if ($exist) $exist =" IF EXISTS"; |
|
| 1139 | + if (spip_pg_query("DROP TABLE$exist $table", $serveur, $requeter)) |
|
| 1140 | + return true; |
|
| 1141 | + else return false; |
|
| 1142 | 1142 | } |
| 1143 | 1143 | |
| 1144 | 1144 | // supprime une vue |
| 1145 | 1145 | // http://doc.spip.org/@spip_pg_drop_view |
| 1146 | 1146 | function spip_pg_drop_view($view, $exist='', $serveur='',$requeter=true) { |
| 1147 | - if ($exist) $exist =" IF EXISTS"; |
|
| 1148 | - return spip_pg_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 1147 | + if ($exist) $exist =" IF EXISTS"; |
|
| 1148 | + return spip_pg_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 1149 | 1149 | } |
| 1150 | 1150 | |
| 1151 | 1151 | /** |
@@ -1163,39 +1163,39 @@ discard block |
||
| 1163 | 1163 | **/ |
| 1164 | 1164 | function spip_pg_showbase($match, $serveur='',$requeter=true) |
| 1165 | 1165 | { |
| 1166 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1167 | - $link = $connexion['link']; |
|
| 1168 | - $connexion['last'] = $q = "SELECT tablename FROM pg_tables WHERE tablename ILIKE "._q($match); |
|
| 1169 | - return spip_pg_query_simple($link, $q); |
|
| 1166 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1167 | + $link = $connexion['link']; |
|
| 1168 | + $connexion['last'] = $q = "SELECT tablename FROM pg_tables WHERE tablename ILIKE "._q($match); |
|
| 1169 | + return spip_pg_query_simple($link, $q); |
|
| 1170 | 1170 | } |
| 1171 | 1171 | |
| 1172 | 1172 | // http://doc.spip.org/@spip_pg_showtable |
| 1173 | 1173 | function spip_pg_showtable($nom_table, $serveur='',$requeter=true) |
| 1174 | 1174 | { |
| 1175 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1176 | - $link = $connexion['link']; |
|
| 1177 | - $connexion['last'] = $q = "SELECT column_name, column_default, data_type FROM information_schema.columns WHERE table_name ILIKE " . _q($nom_table); |
|
| 1175 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1176 | + $link = $connexion['link']; |
|
| 1177 | + $connexion['last'] = $q = "SELECT column_name, column_default, data_type FROM information_schema.columns WHERE table_name ILIKE " . _q($nom_table); |
|
| 1178 | 1178 | |
| 1179 | - $res = spip_pg_query_simple($link, $q); |
|
| 1180 | - if (!$res) return false; |
|
| 1179 | + $res = spip_pg_query_simple($link, $q); |
|
| 1180 | + if (!$res) return false; |
|
| 1181 | 1181 | |
| 1182 | - // etrangement, $res peut ne rien contenir, mais arriver ici... |
|
| 1183 | - // il faut en tenir compte dans le return |
|
| 1184 | - $fields = array(); |
|
| 1185 | - while($field = pg_fetch_array($res, NULL, PGSQL_NUM)) { |
|
| 1186 | - $fields[$field[0]] = $field[2] . (!$field[1] ? '' : (" DEFAULT " . $field[1])); |
|
| 1187 | - } |
|
| 1188 | - $connexion['last'] = $q = "SELECT indexdef FROM pg_indexes WHERE tablename ILIKE " . _q($nom_table); |
|
| 1189 | - $res = spip_pg_query_simple($link, $q); |
|
| 1190 | - $keys = array(); |
|
| 1191 | - while($index = pg_fetch_array($res, NULL, PGSQL_NUM)) { |
|
| 1192 | - if (preg_match('/CREATE\s+(UNIQUE\s+)?INDEX\s([^\s]+).*\((.*)\)$/', $index[0],$r)) { |
|
| 1193 | - $nom = str_replace($nom_table.'_','',$r[2]); |
|
| 1194 | - $keys[($r[1] ? "PRIMARY KEY" : ("KEY " . $nom))] = $r[3]; |
|
| 1195 | - } |
|
| 1196 | - } |
|
| 1197 | - |
|
| 1198 | - return count($fields) ? array('field' => $fields, 'key' => $keys) : false; |
|
| 1182 | + // etrangement, $res peut ne rien contenir, mais arriver ici... |
|
| 1183 | + // il faut en tenir compte dans le return |
|
| 1184 | + $fields = array(); |
|
| 1185 | + while($field = pg_fetch_array($res, NULL, PGSQL_NUM)) { |
|
| 1186 | + $fields[$field[0]] = $field[2] . (!$field[1] ? '' : (" DEFAULT " . $field[1])); |
|
| 1187 | + } |
|
| 1188 | + $connexion['last'] = $q = "SELECT indexdef FROM pg_indexes WHERE tablename ILIKE " . _q($nom_table); |
|
| 1189 | + $res = spip_pg_query_simple($link, $q); |
|
| 1190 | + $keys = array(); |
|
| 1191 | + while($index = pg_fetch_array($res, NULL, PGSQL_NUM)) { |
|
| 1192 | + if (preg_match('/CREATE\s+(UNIQUE\s+)?INDEX\s([^\s]+).*\((.*)\)$/', $index[0],$r)) { |
|
| 1193 | + $nom = str_replace($nom_table.'_','',$r[2]); |
|
| 1194 | + $keys[($r[1] ? "PRIMARY KEY" : ("KEY " . $nom))] = $r[3]; |
|
| 1195 | + } |
|
| 1196 | + } |
|
| 1197 | + |
|
| 1198 | + return count($fields) ? array('field' => $fields, 'key' => $keys) : false; |
|
| 1199 | 1199 | } |
| 1200 | 1200 | |
| 1201 | 1201 | // Fonction de creation d'une table SQL nommee $nom |
@@ -1207,104 +1207,104 @@ discard block |
||
| 1207 | 1207 | // http://doc.spip.org/@spip_pg_create |
| 1208 | 1208 | function spip_pg_create($nom, $champs, $cles, $autoinc=false, $temporary=false, $serveur='',$requeter=true) { |
| 1209 | 1209 | |
| 1210 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1211 | - $prefixe = $connexion['prefixe']; |
|
| 1212 | - $link = $connexion['link']; |
|
| 1213 | - $db = $connexion['db']; |
|
| 1214 | - if ($prefixe) $nom = preg_replace('/^spip/', $prefixe, $nom); |
|
| 1215 | - $query = $prim = $prim_name = $v = $s = $p=''; |
|
| 1216 | - $keys = array(); |
|
| 1217 | - |
|
| 1218 | - // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 1219 | - // sans les renseigner (laisse le compilo recuperer la description) |
|
| 1220 | - if (!is_array($champs) || !is_array($cles)) |
|
| 1221 | - return; |
|
| 1222 | - |
|
| 1223 | - foreach($cles as $k => $v) { |
|
| 1224 | - if (strpos($k, "KEY ") === 0) { |
|
| 1225 | - $n = str_replace('`','',$k); |
|
| 1226 | - $v = str_replace('`','"',$v); |
|
| 1227 | - $i = $nom . preg_replace("/KEY +/", '_',$n); |
|
| 1228 | - if ($k != $n) $i = "\"$i\""; |
|
| 1229 | - $keys[] = "CREATE INDEX $i ON $nom ($v);"; |
|
| 1230 | - } |
|
| 1231 | - elseif (strpos($k, "UNIQUE ") === 0) { |
|
| 1232 | - $k = preg_replace("/^UNIQUE +/", '',$k); |
|
| 1233 | - $prim .= "$s\n\t\tCONSTRAINT " . str_replace('`','"',$k) ." UNIQUE ($v)"; |
|
| 1234 | - } |
|
| 1235 | - else { |
|
| 1236 | - $prim .= "$s\n\t\t" . str_replace('`','"',$k) ." ($v)"; |
|
| 1237 | - } |
|
| 1238 | - if ($k == "PRIMARY KEY") |
|
| 1239 | - $prim_name = $v; |
|
| 1240 | - $s = ","; |
|
| 1241 | - } |
|
| 1242 | - $s = ''; |
|
| 1210 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1211 | + $prefixe = $connexion['prefixe']; |
|
| 1212 | + $link = $connexion['link']; |
|
| 1213 | + $db = $connexion['db']; |
|
| 1214 | + if ($prefixe) $nom = preg_replace('/^spip/', $prefixe, $nom); |
|
| 1215 | + $query = $prim = $prim_name = $v = $s = $p=''; |
|
| 1216 | + $keys = array(); |
|
| 1217 | + |
|
| 1218 | + // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 1219 | + // sans les renseigner (laisse le compilo recuperer la description) |
|
| 1220 | + if (!is_array($champs) || !is_array($cles)) |
|
| 1221 | + return; |
|
| 1222 | + |
|
| 1223 | + foreach($cles as $k => $v) { |
|
| 1224 | + if (strpos($k, "KEY ") === 0) { |
|
| 1225 | + $n = str_replace('`','',$k); |
|
| 1226 | + $v = str_replace('`','"',$v); |
|
| 1227 | + $i = $nom . preg_replace("/KEY +/", '_',$n); |
|
| 1228 | + if ($k != $n) $i = "\"$i\""; |
|
| 1229 | + $keys[] = "CREATE INDEX $i ON $nom ($v);"; |
|
| 1230 | + } |
|
| 1231 | + elseif (strpos($k, "UNIQUE ") === 0) { |
|
| 1232 | + $k = preg_replace("/^UNIQUE +/", '',$k); |
|
| 1233 | + $prim .= "$s\n\t\tCONSTRAINT " . str_replace('`','"',$k) ." UNIQUE ($v)"; |
|
| 1234 | + } |
|
| 1235 | + else { |
|
| 1236 | + $prim .= "$s\n\t\t" . str_replace('`','"',$k) ." ($v)"; |
|
| 1237 | + } |
|
| 1238 | + if ($k == "PRIMARY KEY") |
|
| 1239 | + $prim_name = $v; |
|
| 1240 | + $s = ","; |
|
| 1241 | + } |
|
| 1242 | + $s = ''; |
|
| 1243 | 1243 | |
| 1244 | - $character_set = ""; |
|
| 1245 | - if (@$GLOBALS['meta']['charset_sql_base']) |
|
| 1246 | - $character_set .= " CHARACTER SET ".$GLOBALS['meta']['charset_sql_base']; |
|
| 1247 | - if (@$GLOBALS['meta']['charset_collation_sql_base']) |
|
| 1248 | - $character_set .= " COLLATE ".$GLOBALS['meta']['charset_collation_sql_base']; |
|
| 1249 | - |
|
| 1250 | - foreach($champs as $k => $v) { |
|
| 1251 | - $k = str_replace('`','"',$k); |
|
| 1252 | - if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i',$v,$defs)){ |
|
| 1253 | - if (preg_match(',(char|text),i',$defs[1]) AND !preg_match(',binary,i',$defs[1]) ){ |
|
| 1254 | - $v = $defs[1] . $character_set . ' ' . substr($v,strlen($defs[1])); |
|
| 1255 | - } |
|
| 1256 | - } |
|
| 1257 | - |
|
| 1258 | - $query .= "$s\n\t\t$k " |
|
| 1259 | - . (($autoinc && ($prim_name == $k) && preg_match(',\b(big|small|medium|tiny)?int\b,i', $v)) |
|
| 1260 | - ? " bigserial" |
|
| 1261 | - : mysql2pg_type($v) |
|
| 1262 | - ); |
|
| 1263 | - $s = ","; |
|
| 1264 | - } |
|
| 1265 | - $temporary = $temporary ? 'TEMPORARY':''; |
|
| 1266 | - |
|
| 1267 | - // En l'absence de "if not exists" en PG, on neutralise les erreurs |
|
| 1268 | - |
|
| 1269 | - $q = "CREATE $temporary TABLE $nom ($query" . ($prim ? ",$prim" : '') . ")". |
|
| 1270 | - ($character_set?" DEFAULT $character_set":"") |
|
| 1271 | - ."\n"; |
|
| 1272 | - |
|
| 1273 | - if (!$requeter) return $q; |
|
| 1274 | - $connexion['last'] = $q; |
|
| 1275 | - $r = @pg_query($link, $q); |
|
| 1276 | - |
|
| 1277 | - if (!$r) |
|
| 1278 | - spip_log("Impossible de creer cette table: $q",'pg.'._LOG_ERREUR); |
|
| 1279 | - else { |
|
| 1280 | - foreach($keys as $index) {pg_query($link, $index);} |
|
| 1281 | - } |
|
| 1282 | - return $r; |
|
| 1244 | + $character_set = ""; |
|
| 1245 | + if (@$GLOBALS['meta']['charset_sql_base']) |
|
| 1246 | + $character_set .= " CHARACTER SET ".$GLOBALS['meta']['charset_sql_base']; |
|
| 1247 | + if (@$GLOBALS['meta']['charset_collation_sql_base']) |
|
| 1248 | + $character_set .= " COLLATE ".$GLOBALS['meta']['charset_collation_sql_base']; |
|
| 1249 | + |
|
| 1250 | + foreach($champs as $k => $v) { |
|
| 1251 | + $k = str_replace('`','"',$k); |
|
| 1252 | + if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i',$v,$defs)){ |
|
| 1253 | + if (preg_match(',(char|text),i',$defs[1]) AND !preg_match(',binary,i',$defs[1]) ){ |
|
| 1254 | + $v = $defs[1] . $character_set . ' ' . substr($v,strlen($defs[1])); |
|
| 1255 | + } |
|
| 1256 | + } |
|
| 1257 | + |
|
| 1258 | + $query .= "$s\n\t\t$k " |
|
| 1259 | + . (($autoinc && ($prim_name == $k) && preg_match(',\b(big|small|medium|tiny)?int\b,i', $v)) |
|
| 1260 | + ? " bigserial" |
|
| 1261 | + : mysql2pg_type($v) |
|
| 1262 | + ); |
|
| 1263 | + $s = ","; |
|
| 1264 | + } |
|
| 1265 | + $temporary = $temporary ? 'TEMPORARY':''; |
|
| 1266 | + |
|
| 1267 | + // En l'absence de "if not exists" en PG, on neutralise les erreurs |
|
| 1268 | + |
|
| 1269 | + $q = "CREATE $temporary TABLE $nom ($query" . ($prim ? ",$prim" : '') . ")". |
|
| 1270 | + ($character_set?" DEFAULT $character_set":"") |
|
| 1271 | + ."\n"; |
|
| 1272 | + |
|
| 1273 | + if (!$requeter) return $q; |
|
| 1274 | + $connexion['last'] = $q; |
|
| 1275 | + $r = @pg_query($link, $q); |
|
| 1276 | + |
|
| 1277 | + if (!$r) |
|
| 1278 | + spip_log("Impossible de creer cette table: $q",'pg.'._LOG_ERREUR); |
|
| 1279 | + else { |
|
| 1280 | + foreach($keys as $index) {pg_query($link, $index);} |
|
| 1281 | + } |
|
| 1282 | + return $r; |
|
| 1283 | 1283 | } |
| 1284 | 1284 | |
| 1285 | 1285 | |
| 1286 | 1286 | function spip_pg_create_base($nom, $serveur='',$requeter=true) { |
| 1287 | - return spip_pg_query("CREATE DATABASE $nom", $serveur, $requeter); |
|
| 1287 | + return spip_pg_query("CREATE DATABASE $nom", $serveur, $requeter); |
|
| 1288 | 1288 | } |
| 1289 | 1289 | |
| 1290 | 1290 | // Fonction de creation d'une vue SQL nommee $nom |
| 1291 | 1291 | // http://doc.spip.org/@spip_pg_create_view |
| 1292 | 1292 | function spip_pg_create_view($nom, $query_select, $serveur='',$requeter=true) { |
| 1293 | - if (!$query_select) return false; |
|
| 1294 | - // vue deja presente |
|
| 1295 | - if (sql_showtable($nom, false, $serveur)) { |
|
| 1296 | - if ($requeter) spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)",'pg.'._LOG_ERREUR); |
|
| 1297 | - return false; |
|
| 1298 | - } |
|
| 1293 | + if (!$query_select) return false; |
|
| 1294 | + // vue deja presente |
|
| 1295 | + if (sql_showtable($nom, false, $serveur)) { |
|
| 1296 | + if ($requeter) spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)",'pg.'._LOG_ERREUR); |
|
| 1297 | + return false; |
|
| 1298 | + } |
|
| 1299 | 1299 | |
| 1300 | - $query = "CREATE VIEW $nom AS ". $query_select; |
|
| 1301 | - return spip_pg_query($query, $serveur, $requeter); |
|
| 1300 | + $query = "CREATE VIEW $nom AS ". $query_select; |
|
| 1301 | + return spip_pg_query($query, $serveur, $requeter); |
|
| 1302 | 1302 | } |
| 1303 | 1303 | |
| 1304 | 1304 | |
| 1305 | 1305 | // http://doc.spip.org/@spip_pg_set_connect_charset |
| 1306 | 1306 | function spip_pg_set_connect_charset($charset, $serveur='',$requeter=true){ |
| 1307 | - spip_log("changement de charset sql a ecrire en PG",'pg.'._LOG_ERREUR); |
|
| 1307 | + spip_log("changement de charset sql a ecrire en PG",'pg.'._LOG_ERREUR); |
|
| 1308 | 1308 | } |
| 1309 | 1309 | |
| 1310 | 1310 | |
@@ -1318,7 +1318,7 @@ discard block |
||
| 1318 | 1318 | **/ |
| 1319 | 1319 | // http://doc.spip.org/@spip_sqlite_optimize |
| 1320 | 1320 | function spip_pg_optimize($table, $serveur='',$requeter=true){ |
| 1321 | - return spip_pg_query("VACUUM ". $table, $serveur, $requeter); |
|
| 1321 | + return spip_pg_query("VACUUM ". $table, $serveur, $requeter); |
|
| 1322 | 1322 | } |
| 1323 | 1323 | |
| 1324 | 1324 | // Selectionner la sous-chaine dans $objet |
@@ -1326,12 +1326,12 @@ discard block |
||
| 1326 | 1326 | |
| 1327 | 1327 | // http://doc.spip.org/@spip_pg_multi |
| 1328 | 1328 | function spip_pg_multi ($objet, $lang) { |
| 1329 | - $r = "regexp_replace(" |
|
| 1330 | - . $objet |
|
| 1331 | - . ",'<multi>.*[[]" |
|
| 1332 | - . $lang |
|
| 1333 | - . "[]]([^[]*).*</multi>', E'\\\\1') AS multi"; |
|
| 1334 | - return $r; |
|
| 1329 | + $r = "regexp_replace(" |
|
| 1330 | + . $objet |
|
| 1331 | + . ",'<multi>.*[[]" |
|
| 1332 | + . $lang |
|
| 1333 | + . "[]]([^[]*).*</multi>', E'\\\\1') AS multi"; |
|
| 1334 | + return $r; |
|
| 1335 | 1335 | } |
| 1336 | 1336 | |
| 1337 | 1337 | // Palanquee d'idiosyncrasies MySQL dans les creations de table |
@@ -1339,34 +1339,34 @@ discard block |
||
| 1339 | 1339 | |
| 1340 | 1340 | // http://doc.spip.org/@mysql2pg_type |
| 1341 | 1341 | function mysql2pg_type($v){ |
| 1342 | - $remplace = array( |
|
| 1343 | - '/auto_increment/i' => '', // non reconnu |
|
| 1344 | - '/bigint/i' => 'bigint', |
|
| 1345 | - '/mediumint/i' => 'mediumint', |
|
| 1346 | - '/smallint/i'=> 'smallint', |
|
| 1347 | - "/tinyint/i" => 'int', |
|
| 1348 | - '/int\s*[(]\s*\d+\s*[)]/i' => 'int', |
|
| 1349 | - "/longtext/i" => 'text', |
|
| 1350 | - "/mediumtext/i" => 'text', |
|
| 1351 | - "/tinytext/i" => 'text', |
|
| 1352 | - "/longblob/i" => 'text', |
|
| 1353 | - "/0000-00-00/" =>'0001-01-01', |
|
| 1354 | - "/datetime/i" => 'timestamp', |
|
| 1355 | - "/unsigned/i" => '', |
|
| 1356 | - "/double/i" => 'double precision', |
|
| 1357 | - '/VARCHAR\((\d+)\)\s+BINARY/i' => 'varchar(\1)', |
|
| 1358 | - "/ENUM *[(][^)]*[)]/i" => "varchar(255)", |
|
| 1359 | - '/(timestamp .* )ON .*$/is' => '\\1', |
|
| 1360 | - ); |
|
| 1342 | + $remplace = array( |
|
| 1343 | + '/auto_increment/i' => '', // non reconnu |
|
| 1344 | + '/bigint/i' => 'bigint', |
|
| 1345 | + '/mediumint/i' => 'mediumint', |
|
| 1346 | + '/smallint/i'=> 'smallint', |
|
| 1347 | + "/tinyint/i" => 'int', |
|
| 1348 | + '/int\s*[(]\s*\d+\s*[)]/i' => 'int', |
|
| 1349 | + "/longtext/i" => 'text', |
|
| 1350 | + "/mediumtext/i" => 'text', |
|
| 1351 | + "/tinytext/i" => 'text', |
|
| 1352 | + "/longblob/i" => 'text', |
|
| 1353 | + "/0000-00-00/" =>'0001-01-01', |
|
| 1354 | + "/datetime/i" => 'timestamp', |
|
| 1355 | + "/unsigned/i" => '', |
|
| 1356 | + "/double/i" => 'double precision', |
|
| 1357 | + '/VARCHAR\((\d+)\)\s+BINARY/i' => 'varchar(\1)', |
|
| 1358 | + "/ENUM *[(][^)]*[)]/i" => "varchar(255)", |
|
| 1359 | + '/(timestamp .* )ON .*$/is' => '\\1', |
|
| 1360 | + ); |
|
| 1361 | 1361 | |
| 1362 | - return preg_replace(array_keys($remplace),array_values($remplace),$v); |
|
| 1362 | + return preg_replace(array_keys($remplace),array_values($remplace),$v); |
|
| 1363 | 1363 | } |
| 1364 | 1364 | |
| 1365 | 1365 | // Renvoie false si on n'a pas les fonctions pg (pour l'install) |
| 1366 | 1366 | // http://doc.spip.org/@spip_versions_pg |
| 1367 | 1367 | function spip_versions_pg(){ |
| 1368 | - charger_php_extension('pgsql'); |
|
| 1369 | - return function_exists('pg_connect'); |
|
| 1368 | + charger_php_extension('pgsql'); |
|
| 1369 | + return function_exists('pg_connect'); |
|
| 1370 | 1370 | } |
| 1371 | 1371 | |
| 1372 | 1372 | ?> |
@@ -17,7 +17,9 @@ discard block |
||
| 17 | 17 | * @package SPIP\SQL\PostgreSQL |
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 20 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 21 | + return; |
|
| 22 | +} |
|
| 21 | 23 | |
| 22 | 24 | define('_DEFAULT_DB', 'spip'); |
| 23 | 25 | |
@@ -31,7 +33,9 @@ discard block |
||
| 31 | 33 | // http://doc.spip.org/@req_pg_dist |
| 32 | 34 | function req_pg_dist($addr, $port, $login, $pass, $db='', $prefixe='') { |
| 33 | 35 | static $last_connect = array(); |
| 34 | - if (!charger_php_extension('pgsql')) return false; |
|
| 36 | + if (!charger_php_extension('pgsql')) { |
|
| 37 | + return false; |
|
| 38 | + } |
|
| 35 | 39 | |
| 36 | 40 | // si provient de selectdb |
| 37 | 41 | if (empty($addr) && empty($port) && empty($login) && empty($pass)){ |
@@ -40,7 +44,11 @@ discard block |
||
| 40 | 44 | } |
| 41 | 45 | } |
| 42 | 46 | @list($host, $p) = explode(';', $addr); |
| 43 | - if ($p >0) $port = " port=$p" ; else $port = ''; |
|
| 47 | + if ($p >0) { |
|
| 48 | + $port = " port=$p" ; |
|
| 49 | + } else { |
|
| 50 | + $port = ''; |
|
| 51 | + } |
|
| 44 | 52 | $erreurs = array(); |
| 45 | 53 | if ($db) { |
| 46 | 54 | @$link = pg_connect("host=$host$port dbname=$db user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW); |
@@ -56,13 +64,14 @@ discard block |
||
| 56 | 64 | } |
| 57 | 65 | if (!$link) { |
| 58 | 66 | $erreurs[] = pg_last_error(); |
| 59 | - foreach($erreurs as $e) |
|
| 60 | - spip_log('Echec pg_connect. Erreur : ' . $e,'pg.'._LOG_HS); |
|
| 67 | + foreach($erreurs as $e) { |
|
| 68 | + spip_log('Echec pg_connect. Erreur : ' . $e,'pg.'._LOG_HS); |
|
| 69 | + } |
|
| 61 | 70 | return false; |
| 62 | 71 | } |
| 63 | 72 | |
| 64 | - if ($link) |
|
| 65 | - $last_connect = array ( |
|
| 73 | + if ($link) { |
|
| 74 | + $last_connect = array ( |
|
| 66 | 75 | 'addr' => $addr, |
| 67 | 76 | 'port' => $port, |
| 68 | 77 | 'login' => $login, |
@@ -70,6 +79,7 @@ discard block |
||
| 70 | 79 | 'db' => $db, |
| 71 | 80 | 'prefixe' => $prefixe, |
| 72 | 81 | ); |
| 82 | + } |
|
| 73 | 83 | |
| 74 | 84 | spip_log("Connexion vers $host, base $db, prefixe $prefixe " . ($link ? 'operationnelle' : 'impossible'),'pg.'._LOG_DEBUG); |
| 75 | 85 | |
@@ -130,13 +140,18 @@ discard block |
||
| 130 | 140 | if (isset($_GET['var_profile'])) { |
| 131 | 141 | include_spip('public/tracer'); |
| 132 | 142 | $t = trace_query_start(); |
| 133 | - } else $t = 0 ; |
|
| 143 | + } else { |
|
| 144 | + $t = 0 ; |
|
| 145 | + } |
|
| 134 | 146 | |
| 135 | 147 | $connexion['last'] = $query; |
| 136 | 148 | $r = spip_pg_query_simple($link, $query); |
| 137 | 149 | |
| 138 | - if ($e = spip_pg_errno($serveur)) // Log de l'erreur eventuelle |
|
| 139 | - $e .= spip_pg_error($query, $serveur); // et du fautif |
|
| 150 | + if ($e = spip_pg_errno($serveur)) { |
|
| 151 | + // Log de l'erreur eventuelle |
|
| 152 | + $e .= spip_pg_error($query, $serveur); |
|
| 153 | + } |
|
| 154 | + // et du fautif |
|
| 140 | 155 | return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
| 141 | 156 | } |
| 142 | 157 | |
@@ -154,11 +169,15 @@ discard block |
||
| 154 | 169 | if (preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
| 155 | 170 | $suite = strstr($query, $regs[0]); |
| 156 | 171 | $query = substr($query, 0, -strlen($suite)); |
| 157 | - } else $suite =''; |
|
| 172 | + } else { |
|
| 173 | + $suite =''; |
|
| 174 | + } |
|
| 158 | 175 | $query = preg_replace('/([,\s])spip_/', '\1'.$prefixe.'_', $query) . $suite; |
| 159 | 176 | |
| 160 | 177 | // renvoyer la requete inerte si demandee |
| 161 | - if (!$requeter) return $query; |
|
| 178 | + if (!$requeter) { |
|
| 179 | + return $query; |
|
| 180 | + } |
|
| 162 | 181 | |
| 163 | 182 | return spip_pg_trace_query($query, $serveur); |
| 164 | 183 | } |
@@ -185,7 +204,9 @@ discard block |
||
| 185 | 204 | $trouver_table = charger_fonction('trouver_table', 'base'); |
| 186 | 205 | $desc = $trouver_table($table, $serveur); |
| 187 | 206 | // si pas de description, on ne fait rien, ou on die() ? |
| 188 | - if (!$desc) return $couples; |
|
| 207 | + if (!$desc) { |
|
| 208 | + return $couples; |
|
| 209 | + } |
|
| 189 | 210 | } |
| 190 | 211 | |
| 191 | 212 | // recherche des champs avec simplement 'TIMESTAMP' |
@@ -196,15 +217,17 @@ discard block |
||
| 196 | 217 | foreach ($desc['field'] as $k=>$v){ |
| 197 | 218 | $v = strtolower(ltrim($v)); |
| 198 | 219 | // ne pas ajouter de timestamp now() si un default est specifie |
| 199 | - if (strpos($v, 'timestamp')===0 AND strpos($v, 'default')===false) |
|
| 200 | - $tables[$table][] = $k; |
|
| 220 | + if (strpos($v, 'timestamp')===0 AND strpos($v, 'default')===false) { |
|
| 221 | + $tables[$table][] = $k; |
|
| 222 | + } |
|
| 201 | 223 | } |
| 202 | 224 | } |
| 203 | 225 | |
| 204 | 226 | // ajout des champs type 'timestamp' absents |
| 205 | 227 | foreach ($tables[$table] as $maj){ |
| 206 | - if (!array_key_exists($maj, $couples)) |
|
| 207 | - $couples[$maj] = "NOW()"; |
|
| 228 | + if (!array_key_exists($maj, $couples)) { |
|
| 229 | + $couples[$maj] = "NOW()"; |
|
| 230 | + } |
|
| 208 | 231 | } |
| 209 | 232 | return $couples; |
| 210 | 233 | } |
@@ -232,9 +255,14 @@ discard block |
||
| 232 | 255 | $todo2[$i] = isset($todo2[$i]) ? $todo2[$i] . "," . $do : $do; |
| 233 | 256 | $o=(false!==strpos($do,"(")); |
| 234 | 257 | $f=(false!==strpos($do,")")); |
| 235 | - if ($o AND !$f) $ouverte=true; |
|
| 236 | - elseif ($f) $ouverte=false; |
|
| 237 | - if (!$ouverte) $i++; |
|
| 258 | + if ($o AND !$f) { |
|
| 259 | + $ouverte=true; |
|
| 260 | + } elseif ($f) { |
|
| 261 | + $ouverte=false; |
|
| 262 | + } |
|
| 263 | + if (!$ouverte) { |
|
| 264 | + $i++; |
|
| 265 | + } |
|
| 238 | 266 | } |
| 239 | 267 | $todo=$todo2; |
| 240 | 268 | $query = $debut.' '.array_shift($todo); |
@@ -242,15 +270,20 @@ discard block |
||
| 242 | 270 | if (!preg_match('/^\s*(IGNORE\s*)?TABLE\s+(\w+)\s+(ADD|DROP|CHANGE|MODIFY|RENAME)\s*(.*)$/is', $query, $r)) { |
| 243 | 271 | spip_log("$query incompris", 'pg.'._LOG_ERREUR); |
| 244 | 272 | } else { |
| 245 | - if ($r[1]) spip_log("j'ignore IGNORE dans $query", 'pg.'._LOG_AVERTISSEMENT); |
|
| 273 | + if ($r[1]) { |
|
| 274 | + spip_log("j'ignore IGNORE dans $query", 'pg.'._LOG_AVERTISSEMENT); |
|
| 275 | + } |
|
| 246 | 276 | $f = 'spip_pg_alter_' . strtolower($r[3]); |
| 247 | - if (function_exists($f)) |
|
| 248 | - $f($r[2], $r[4], $serveur, $requeter); |
|
| 249 | - else spip_log("$query non prevu", 'pg.'._LOG_ERREUR); |
|
| 277 | + if (function_exists($f)) { |
|
| 278 | + $f($r[2], $r[4], $serveur, $requeter); |
|
| 279 | + } else { |
|
| 280 | + spip_log("$query non prevu", 'pg.'._LOG_ERREUR); |
|
| 281 | + } |
|
| 250 | 282 | } |
| 251 | 283 | // Alter a plusieurs args. Faudrait optimiser. |
| 252 | - if ($todo) |
|
| 253 | - spip_pg_alter("TABLE $table " . join(',',$todo)); |
|
| 284 | + if ($todo) { |
|
| 285 | + spip_pg_alter("TABLE $table " . join(',',$todo)); |
|
| 286 | + } |
|
| 254 | 287 | |
| 255 | 288 | } |
| 256 | 289 | |
@@ -262,20 +295,23 @@ discard block |
||
| 262 | 295 | } else { |
| 263 | 296 | list(,$old, $new, $type, $default, $null, $def2) = $r; |
| 264 | 297 | $actions = array("ALTER $old TYPE " . mysql2pg_type($type)); |
| 265 | - if ($null) |
|
| 266 | - $actions[]= "ALTER $old SET NOT NULL"; |
|
| 267 | - else |
|
| 268 | - $actions[]= "ALTER $old DROP NOT NULL"; |
|
| 269 | - |
|
| 270 | - if ($d = ($default ? $default : $def2)) |
|
| 271 | - $actions[]= "ALTER $old SET $d"; |
|
| 272 | - else |
|
| 273 | - $actions[]= "ALTER $old DROP DEFAULT"; |
|
| 298 | + if ($null) { |
|
| 299 | + $actions[]= "ALTER $old SET NOT NULL"; |
|
| 300 | + } else { |
|
| 301 | + $actions[]= "ALTER $old DROP NOT NULL"; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + if ($d = ($default ? $default : $def2)) { |
|
| 305 | + $actions[]= "ALTER $old SET $d"; |
|
| 306 | + } else { |
|
| 307 | + $actions[]= "ALTER $old DROP DEFAULT"; |
|
| 308 | + } |
|
| 274 | 309 | |
| 275 | 310 | spip_pg_query("ALTER TABLE $table " . join(', ', $actions)); |
| 276 | 311 | |
| 277 | - if ($old != $new) |
|
| 278 | - spip_pg_query("ALTER TABLE $table RENAME $old TO $new", $serveur); |
|
| 312 | + if ($old != $new) { |
|
| 313 | + spip_pg_query("ALTER TABLE $table RENAME $old TO $new", $serveur); |
|
| 314 | + } |
|
| 279 | 315 | } |
| 280 | 316 | } |
| 281 | 317 | |
@@ -305,8 +341,7 @@ discard block |
||
| 305 | 341 | if ($m[2]) { |
| 306 | 342 | $colonnes = substr($m[2],1,-1); |
| 307 | 343 | $nom_index = $m[1]; |
| 308 | - } |
|
| 309 | - else { |
|
| 344 | + } else { |
|
| 310 | 345 | // (colonne) |
| 311 | 346 | if ($m[1][0] == "(") { |
| 312 | 347 | $colonnes = substr($m[1],1,-1); |
@@ -328,14 +363,14 @@ discard block |
||
| 328 | 363 | |
| 329 | 364 | // http://doc.spip.org/@spip_pg_alter_drop |
| 330 | 365 | function spip_pg_alter_drop($table, $arg, $serveur='',$requeter=true) { |
| 331 | - if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*`?(\w*)`?/', $arg, $r)) |
|
| 332 | - spip_log("alter drop: $arg incompris", 'pg.'._LOG_ERREUR); |
|
| 333 | - else { |
|
| 334 | - if (!$r[1] OR $r[1]=='COLUMN') |
|
| 335 | - return spip_pg_query("ALTER TABLE $table DROP " . $r[2], $serveur); |
|
| 336 | - elseif ($r[1][0] == 'P') |
|
| 337 | - return spip_pg_query("ALTER TABLE $table DROP CONSTRAINT $table" . '_pkey', $serveur); |
|
| 338 | - else { |
|
| 366 | + if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*`?(\w*)`?/', $arg, $r)) { |
|
| 367 | + spip_log("alter drop: $arg incompris", 'pg.'._LOG_ERREUR); |
|
| 368 | + } else { |
|
| 369 | + if (!$r[1] OR $r[1]=='COLUMN') { |
|
| 370 | + return spip_pg_query("ALTER TABLE $table DROP " . $r[2], $serveur); |
|
| 371 | + } elseif ($r[1][0] == 'P') { |
|
| 372 | + return spip_pg_query("ALTER TABLE $table DROP CONSTRAINT $table" . '_pkey', $serveur); |
|
| 373 | + } else { |
|
| 339 | 374 | return spip_pg_query("DROP INDEX " . $table . '_' . $r[2], $serveur); |
| 340 | 375 | } |
| 341 | 376 | } |
@@ -358,8 +393,7 @@ discard block |
||
| 358 | 393 | // si TO, mais pas au debut |
| 359 | 394 | if (!stripos($arg,'TO ')){ |
| 360 | 395 | $rename=$arg; |
| 361 | - } |
|
| 362 | - elseif (preg_match('/^(TO)\s*`?(\w*)`?/', $arg, $r)) { |
|
| 396 | + } elseif (preg_match('/^(TO)\s*`?(\w*)`?/', $arg, $r)) { |
|
| 363 | 397 | $rename=$r[2]; |
| 364 | 398 | } else { |
| 365 | 399 | spip_log("alter rename: $arg incompris", 'pg.'._LOG_ERREUR); |
@@ -393,11 +427,15 @@ discard block |
||
| 393 | 427 | $nom = $table.'_'.$nom; |
| 394 | 428 | // enlever d'eventuelles parentheses deja presentes sur champs |
| 395 | 429 | if (!is_array($champs)){ |
| 396 | - if ($champs[0]=="(") $champs = substr($champs,1,-1); |
|
| 430 | + if ($champs[0]=="(") { |
|
| 431 | + $champs = substr($champs,1,-1); |
|
| 432 | + } |
|
| 397 | 433 | $champs = array($champs); |
| 398 | 434 | } |
| 399 | 435 | $query = "CREATE INDEX $nom ON $table (" . join(',',$champs) . ")"; |
| 400 | - if (!$requeter) return $query; |
|
| 436 | + if (!$requeter) { |
|
| 437 | + return $query; |
|
| 438 | + } |
|
| 401 | 439 | $res = spip_pg_query($query, $serveur, $requeter); |
| 402 | 440 | return $res; |
| 403 | 441 | } |
@@ -405,17 +443,23 @@ discard block |
||
| 405 | 443 | |
| 406 | 444 | // http://doc.spip.org/@spip_pg_explain |
| 407 | 445 | function spip_pg_explain($query, $serveur='',$requeter=true){ |
| 408 | - if (strpos(ltrim($query), 'SELECT') !== 0) return array(); |
|
| 446 | + if (strpos(ltrim($query), 'SELECT') !== 0) { |
|
| 447 | + return array(); |
|
| 448 | + } |
|
| 409 | 449 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 410 | 450 | $prefixe = $connexion['prefixe']; |
| 411 | 451 | $link = $connexion['link']; |
| 412 | 452 | if (preg_match('/\s(SET|VALUES|WHERE)\s/i', $query, $regs)) { |
| 413 | 453 | $suite = strstr($query, $regs[0]); |
| 414 | 454 | $query = substr($query, 0, -strlen($suite)); |
| 415 | - } else $suite =''; |
|
| 455 | + } else { |
|
| 456 | + $suite =''; |
|
| 457 | + } |
|
| 416 | 458 | $query = 'EXPLAIN ' . preg_replace('/([,\s])spip_/', '\1'.$prefixe.'_', $query) . $suite; |
| 417 | 459 | |
| 418 | - if (!$requeter) return $query; |
|
| 460 | + if (!$requeter) { |
|
| 461 | + return $query; |
|
| 462 | + } |
|
| 419 | 463 | $r = spip_pg_query_simple($link,$query); |
| 420 | 464 | return spip_pg_fetch($r, NULL, $serveur); |
| 421 | 465 | } |
@@ -441,11 +485,13 @@ discard block |
||
| 441 | 485 | $index = $serveur ? strtolower($serveur) : 0; |
| 442 | 486 | |
| 443 | 487 | if ($link = spip_connect_db('', '', '', '', $db, 'pg', '', '')){ |
| 444 | - if (($db==$link['db']) && $GLOBALS['connexions'][$index] = $link) |
|
| 445 | - return $db; |
|
| 446 | - } else |
|
| 447 | - return false; |
|
| 448 | -} |
|
| 488 | + if (($db==$link['db']) && $GLOBALS['connexions'][$index] = $link) { |
|
| 489 | + return $db; |
|
| 490 | + } |
|
| 491 | + } else { |
|
| 492 | + return false; |
|
| 493 | + } |
|
| 494 | + } |
|
| 449 | 495 | |
| 450 | 496 | // Qu'une seule base pour le moment |
| 451 | 497 | |
@@ -455,8 +501,9 @@ discard block |
||
| 455 | 501 | $link = $connexion['link']; |
| 456 | 502 | $dbs = array(); |
| 457 | 503 | $res = spip_pg_query_simple($link, "select * From pg_database"); |
| 458 | - while ($row = pg_fetch_array($res, NULL, PGSQL_NUM)) |
|
| 459 | - $dbs[] = reset($row); |
|
| 504 | + while ($row = pg_fetch_array($res, NULL, PGSQL_NUM)) { |
|
| 505 | + $dbs[] = reset($row); |
|
| 506 | + } |
|
| 460 | 507 | |
| 461 | 508 | return $dbs; |
| 462 | 509 | } |
@@ -489,8 +536,9 @@ discard block |
||
| 489 | 536 | $orderby = spip_pg_orderby($orderby, $select); |
| 490 | 537 | |
| 491 | 538 | if ($having) { |
| 492 | - if (is_array($having)) |
|
| 493 | - $having = join("\n\tAND ", array_map('calculer_pg_where', $having)); |
|
| 539 | + if (is_array($having)) { |
|
| 540 | + $having = join("\n\tAND ", array_map('calculer_pg_where', $having)); |
|
| 541 | + } |
|
| 494 | 542 | } |
| 495 | 543 | $from = spip_pg_from($from, $prefixe); |
| 496 | 544 | $query = "SELECT ". $select |
@@ -502,7 +550,9 @@ discard block |
||
| 502 | 550 | . (!$limit ? '' : (" LIMIT $count" . (!$offset ? '' : " OFFSET $offset"))); |
| 503 | 551 | |
| 504 | 552 | // renvoyer la requete inerte si demandee |
| 505 | - if ($requeter === false) return $query; |
|
| 553 | + if ($requeter === false) { |
|
| 554 | + return $query; |
|
| 555 | + } |
|
| 506 | 556 | |
| 507 | 557 | $r = spip_pg_trace_query($query, $serveur); |
| 508 | 558 | return $r ? $r : $query;; |
@@ -514,7 +564,9 @@ discard block |
||
| 514 | 564 | // http://doc.spip.org/@spip_pg_from |
| 515 | 565 | function spip_pg_from($from, $prefixe) |
| 516 | 566 | { |
| 517 | - if (is_array($from)) $from = spip_pg_select_as($from); |
|
| 567 | + if (is_array($from)) { |
|
| 568 | + $from = spip_pg_select_as($from); |
|
| 569 | + } |
|
| 518 | 570 | return !$prefixe ? $from : preg_replace('/(\b)spip_/','\1'.$prefixe.'_', $from); |
| 519 | 571 | } |
| 520 | 572 | |
@@ -528,7 +580,9 @@ discard block |
||
| 528 | 580 | if (preg_match('/(case\s+.*?else\s+0\s+end)\s*AS\s+' . $v .'/', $select, $m)) { |
| 529 | 581 | |
| 530 | 582 | $res[] = $m[1]; |
| 531 | - } else $res[]=$v; |
|
| 583 | + } else { |
|
| 584 | + $res[]=$v; |
|
| 585 | + } |
|
| 532 | 586 | } |
| 533 | 587 | return spip_pg_frommysql(join(',',$res)); |
| 534 | 588 | } |
@@ -542,11 +596,14 @@ discard block |
||
| 542 | 596 | { |
| 543 | 597 | $join = strpos($from, ","); |
| 544 | 598 | // ismplifier avant de decouper |
| 545 | - if (is_string($select)) |
|
| 546 | - // fct SQL sur colonne et constante apostrophee ==> la colonne |
|
| 599 | + if (is_string($select)) { |
|
| 600 | + // fct SQL sur colonne et constante apostrophee ==> la colonne |
|
| 547 | 601 | $select = preg_replace('/\w+\(\s*([^(),\']*),\s*\'[^\']*\'[^)]*\)/','\\1', $select); |
| 602 | + } |
|
| 548 | 603 | |
| 549 | - if ($join OR $groupby) $join = is_array($select) ? $select : explode(", ", $select); |
|
| 604 | + if ($join OR $groupby) { |
|
| 605 | + $join = is_array($select) ? $select : explode(", ", $select); |
|
| 606 | + } |
|
| 550 | 607 | if ($join) { |
| 551 | 608 | // enlever les 0 as points, '', ... |
| 552 | 609 | foreach($join as $k=>$v){ |
@@ -561,17 +618,24 @@ discard block |
||
| 561 | 618 | // des AS simples : on garde le cote droit du AS |
| 562 | 619 | $v = preg_replace('/^.*\sAS\s+(\w+)\s*$/i','\\1', $v); |
| 563 | 620 | // ne reste plus que les vrais colonnes, ou des constantes a virer |
| 564 | - if (preg_match(',^[\'"],',$v) OR is_numeric($v)) |
|
| 565 | - unset($join[$k]); |
|
| 566 | - else |
|
| 567 | - $join[$k] = trim($v); |
|
| 621 | + if (preg_match(',^[\'"],',$v) OR is_numeric($v)) { |
|
| 622 | + unset($join[$k]); |
|
| 623 | + } else { |
|
| 624 | + $join[$k] = trim($v); |
|
| 625 | + } |
|
| 568 | 626 | } |
| 569 | 627 | $join = array_diff($join,array('')); |
| 570 | 628 | $join = implode(',',$join); |
| 571 | 629 | } |
| 572 | - if (is_array($groupby)) $groupby = join(',',$groupby); |
|
| 573 | - if ($join) $groupby = $groupby ? "$groupby, $join" : $join; |
|
| 574 | - if (!$groupby) return ''; |
|
| 630 | + if (is_array($groupby)) { |
|
| 631 | + $groupby = join(',',$groupby); |
|
| 632 | + } |
|
| 633 | + if ($join) { |
|
| 634 | + $groupby = $groupby ? "$groupby, $join" : $join; |
|
| 635 | + } |
|
| 636 | + if (!$groupby) { |
|
| 637 | + return ''; |
|
| 638 | + } |
|
| 575 | 639 | |
| 576 | 640 | $groupby = spip_pg_frommysql($groupby); |
| 577 | 641 | // Ne pas mettre dans le Group-By des valeurs numeriques |
@@ -593,7 +657,9 @@ discard block |
||
| 593 | 657 | // http://doc.spip.org/@spip_pg_frommysql |
| 594 | 658 | function spip_pg_frommysql($arg) |
| 595 | 659 | { |
| 596 | - if (is_array($arg)) $arg = join(", ", $arg); |
|
| 660 | + if (is_array($arg)) { |
|
| 661 | + $arg = join(", ", $arg); |
|
| 662 | + } |
|
| 597 | 663 | |
| 598 | 664 | $res = spip_pg_fromfield($arg); |
| 599 | 665 | |
@@ -682,13 +748,14 @@ discard block |
||
| 682 | 748 | // http://doc.spip.org/@calculer_pg_where |
| 683 | 749 | function calculer_pg_where($v) |
| 684 | 750 | { |
| 685 | - if (!is_array($v)) |
|
| 686 | - return spip_pg_frommysql($v); |
|
| 751 | + if (!is_array($v)) { |
|
| 752 | + return spip_pg_frommysql($v); |
|
| 753 | + } |
|
| 687 | 754 | |
| 688 | 755 | $op = str_replace('REGEXP', '~', array_shift($v)); |
| 689 | - if (!($n=count($v))) |
|
| 690 | - return $op; |
|
| 691 | - else { |
|
| 756 | + if (!($n=count($v))) { |
|
| 757 | + return $op; |
|
| 758 | + } else { |
|
| 692 | 759 | $arg = calculer_pg_where(array_shift($v)); |
| 693 | 760 | if ($n==1) { |
| 694 | 761 | return "$op($arg)"; |
@@ -696,7 +763,9 @@ discard block |
||
| 696 | 763 | $arg2 = calculer_pg_where(array_shift($v)); |
| 697 | 764 | if ($n==2) { |
| 698 | 765 | return "($arg $op $arg2)"; |
| 699 | - } else return "($arg $op ($arg2) : $v[0])"; |
|
| 766 | + } else { |
|
| 767 | + return "($arg $op ($arg2) : $v[0])"; |
|
| 768 | + } |
|
| 700 | 769 | } |
| 701 | 770 | } |
| 702 | 771 | } |
@@ -704,18 +773,22 @@ discard block |
||
| 704 | 773 | |
| 705 | 774 | // http://doc.spip.org/@calculer_pg_expression |
| 706 | 775 | function calculer_pg_expression($expression, $v, $join = 'AND'){ |
| 707 | - if (empty($v)) |
|
| 708 | - return ''; |
|
| 776 | + if (empty($v)) { |
|
| 777 | + return ''; |
|
| 778 | + } |
|
| 709 | 779 | |
| 710 | 780 | $exp = "\n$expression "; |
| 711 | 781 | |
| 712 | - if (!is_array($v)) $v = array($v); |
|
| 782 | + if (!is_array($v)) { |
|
| 783 | + $v = array($v); |
|
| 784 | + } |
|
| 713 | 785 | |
| 714 | - if (strtoupper($join) === 'AND') |
|
| 715 | - return $exp . join("\n\t$join ", array_map('calculer_pg_where', $v)); |
|
| 716 | - else |
|
| 717 | - return $exp . join($join, $v); |
|
| 718 | -} |
|
| 786 | + if (strtoupper($join) === 'AND') { |
|
| 787 | + return $exp . join("\n\t$join ", array_map('calculer_pg_where', $v)); |
|
| 788 | + } else { |
|
| 789 | + return $exp . join($join, $v); |
|
| 790 | + } |
|
| 791 | + } |
|
| 719 | 792 | |
| 720 | 793 | // http://doc.spip.org/@spip_pg_select_as |
| 721 | 794 | function spip_pg_select_as($args) |
@@ -726,18 +799,19 @@ discard block |
||
| 726 | 799 | // c'est une jointure qui se refere au from precedent |
| 727 | 800 | // pas de virgule |
| 728 | 801 | $argsas .= ' ' . $v ; |
| 729 | - } |
|
| 730 | - else { |
|
| 802 | + } else { |
|
| 731 | 803 | $as = ''; |
| 732 | 804 | // spip_log("$k : $v", _LOG_DEBUG); |
| 733 | 805 | if (!is_numeric($k)) { |
| 734 | - if (preg_match('/\.(.*)$/', $k, $r)) |
|
| 735 | - $v = $k; |
|
| 736 | - elseif ($v != $k) { |
|
| 806 | + if (preg_match('/\.(.*)$/', $k, $r)) { |
|
| 807 | + $v = $k; |
|
| 808 | + } elseif ($v != $k) { |
|
| 737 | 809 | $p = strpos($v, " "); |
| 738 | - if ($p) |
|
| 739 | - $v = substr($v,0,$p) . " AS $k" . substr($v,$p); |
|
| 740 | - else $as = " AS $k"; |
|
| 810 | + if ($p) { |
|
| 811 | + $v = substr($v,0,$p) . " AS $k" . substr($v,$p); |
|
| 812 | + } else { |
|
| 813 | + $as = " AS $k"; |
|
| 814 | + } |
|
| 741 | 815 | } |
| 742 | 816 | } |
| 743 | 817 | // spip_log("subs $k : $v avec $as", _LOG_DEBUG); |
@@ -751,13 +825,17 @@ discard block |
||
| 751 | 825 | // http://doc.spip.org/@spip_pg_fetch |
| 752 | 826 | function spip_pg_fetch($res, $t='', $serveur='',$requeter=true) { |
| 753 | 827 | |
| 754 | - if ($res) $res = pg_fetch_array($res, NULL, PGSQL_ASSOC); |
|
| 828 | + if ($res) { |
|
| 829 | + $res = pg_fetch_array($res, NULL, PGSQL_ASSOC); |
|
| 830 | + } |
|
| 755 | 831 | return $res; |
| 756 | 832 | } |
| 757 | 833 | |
| 758 | 834 | function spip_pg_seek($r, $row_number, $serveur='',$requeter=true) { |
| 759 | - if ($r) return pg_result_seek($r,$row_number); |
|
| 760 | -} |
|
| 835 | + if ($r) { |
|
| 836 | + return pg_result_seek($r,$row_number); |
|
| 837 | + } |
|
| 838 | + } |
|
| 761 | 839 | |
| 762 | 840 | |
| 763 | 841 | // http://doc.spip.org/@spip_pg_countsel |
@@ -766,8 +844,12 @@ discard block |
||
| 766 | 844 | { |
| 767 | 845 | $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
| 768 | 846 | $r = spip_pg_select("COUNT($c)", $from, $where,'', '', '', $having, $serveur, $requeter); |
| 769 | - if (!$requeter) return $r; |
|
| 770 | - if (!is_resource($r)) return 0; |
|
| 847 | + if (!$requeter) { |
|
| 848 | + return $r; |
|
| 849 | + } |
|
| 850 | + if (!is_resource($r)) { |
|
| 851 | + return 0; |
|
| 852 | + } |
|
| 771 | 853 | list($c) = pg_fetch_array($r, NULL, PGSQL_NUM); |
| 772 | 854 | return $c; |
| 773 | 855 | } |
@@ -789,20 +871,25 @@ discard block |
||
| 789 | 871 | $prefixe = $connexion['prefixe']; |
| 790 | 872 | $link = $connexion['link']; |
| 791 | 873 | $db = $connexion['db']; |
| 792 | - if ($prefixe) $table = preg_replace('/^spip/', $prefixe, $table); |
|
| 874 | + if ($prefixe) { |
|
| 875 | + $table = preg_replace('/^spip/', $prefixe, $table); |
|
| 876 | + } |
|
| 793 | 877 | |
| 794 | 878 | $query = calculer_pg_expression('DELETE FROM', $table, ',') |
| 795 | 879 | . calculer_pg_expression('WHERE', $where, 'AND'); |
| 796 | 880 | |
| 797 | 881 | // renvoyer la requete inerte si demandee |
| 798 | - if (!$requeter) return $query; |
|
| 882 | + if (!$requeter) { |
|
| 883 | + return $query; |
|
| 884 | + } |
|
| 799 | 885 | |
| 800 | 886 | $res = spip_pg_trace_query($query, $serveur); |
| 801 | - if ($res) |
|
| 802 | - return pg_affected_rows($res); |
|
| 803 | - else |
|
| 804 | - return false; |
|
| 805 | -} |
|
| 887 | + if ($res) { |
|
| 888 | + return pg_affected_rows($res); |
|
| 889 | + } else { |
|
| 890 | + return false; |
|
| 891 | + } |
|
| 892 | + } |
|
| 806 | 893 | |
| 807 | 894 | // http://doc.spip.org/@spip_pg_insert |
| 808 | 895 | function spip_pg_insert($table, $champs, $valeurs, $desc=array(), $serveur='',$requeter=true) { |
@@ -811,13 +898,16 @@ discard block |
||
| 811 | 898 | $link = $connexion['link']; |
| 812 | 899 | $db = $connexion['db']; |
| 813 | 900 | |
| 814 | - if (!$desc) $desc = description_table($table, $serveur); |
|
| 901 | + if (!$desc) { |
|
| 902 | + $desc = description_table($table, $serveur); |
|
| 903 | + } |
|
| 815 | 904 | $seq = spip_pg_sequence($table,true); |
| 816 | 905 | // si pas de cle primaire dans l'insertion, renvoyer curval |
| 817 | 906 | if (!preg_match(",\b$seq\b,",$champs)){ |
| 818 | 907 | $seq = spip_pg_sequence($table); |
| 819 | - if ($prefixe) |
|
| 820 | - $seq = preg_replace('/^spip/', $prefixe, $seq); |
|
| 908 | + if ($prefixe) { |
|
| 909 | + $seq = preg_replace('/^spip/', $prefixe, $seq); |
|
| 910 | + } |
|
| 821 | 911 | $seq = "currval('$seq')"; |
| 822 | 912 | } |
| 823 | 913 | |
@@ -830,14 +920,19 @@ discard block |
||
| 830 | 920 | ? " DEFAULT VALUES" |
| 831 | 921 | : "$champs VALUES $valeurs"; |
| 832 | 922 | $q ="INSERT INTO $table $ins $ret"; |
| 833 | - if (!$requeter) return $q; |
|
| 923 | + if (!$requeter) { |
|
| 924 | + return $q; |
|
| 925 | + } |
|
| 834 | 926 | $connexion['last'] = $q; |
| 835 | 927 | $r = spip_pg_query_simple($link, $q); |
| 836 | 928 | # spip_log($q,'pg.'._LOG_DEBUG); |
| 837 | 929 | if ($r) { |
| 838 | - if (!$ret) return 0; |
|
| 839 | - if ($r2 = pg_fetch_array($r, NULL, PGSQL_NUM)) |
|
| 840 | - return $r2[0]; |
|
| 930 | + if (!$ret) { |
|
| 931 | + return 0; |
|
| 932 | + } |
|
| 933 | + if ($r2 = pg_fetch_array($r, NULL, PGSQL_NUM)) { |
|
| 934 | + return $r2[0]; |
|
| 935 | + } |
|
| 841 | 936 | } |
| 842 | 937 | return false; |
| 843 | 938 | } |
@@ -845,8 +940,12 @@ discard block |
||
| 845 | 940 | // http://doc.spip.org/@spip_pg_insertq |
| 846 | 941 | function spip_pg_insertq($table, $couples=array(), $desc=array(), $serveur='',$requeter=true) { |
| 847 | 942 | |
| 848 | - if (!$desc) $desc = description_table($table, $serveur); |
|
| 849 | - if (!$desc) die("$table insertion sans description"); |
|
| 943 | + if (!$desc) { |
|
| 944 | + $desc = description_table($table, $serveur); |
|
| 945 | + } |
|
| 946 | + if (!$desc) { |
|
| 947 | + die("$table insertion sans description"); |
|
| 948 | + } |
|
| 850 | 949 | $fields = $desc['field']; |
| 851 | 950 | |
| 852 | 951 | foreach ($couples as $champ => $val) { |
@@ -864,8 +963,12 @@ discard block |
||
| 864 | 963 | // http://doc.spip.org/@spip_pg_insertq_multi |
| 865 | 964 | function spip_pg_insertq_multi($table, $tab_couples=array(), $desc=array(), $serveur='',$requeter=true) { |
| 866 | 965 | |
| 867 | - if (!$desc) $desc = description_table($table, $serveur); |
|
| 868 | - if (!$desc) die("$table insertion sans description"); |
|
| 966 | + if (!$desc) { |
|
| 967 | + $desc = description_table($table, $serveur); |
|
| 968 | + } |
|
| 969 | + if (!$desc) { |
|
| 970 | + die("$table insertion sans description"); |
|
| 971 | + } |
|
| 869 | 972 | $fields = isset($desc['field'])?$desc['field']:array(); |
| 870 | 973 | |
| 871 | 974 | // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
@@ -893,12 +996,16 @@ discard block |
||
| 893 | 996 | // http://doc.spip.org/@spip_pg_update |
| 894 | 997 | function spip_pg_update($table, $couples, $where='', $desc='', $serveur='',$requeter=true) { |
| 895 | 998 | |
| 896 | - if (!$couples) return; |
|
| 999 | + if (!$couples) { |
|
| 1000 | + return; |
|
| 1001 | + } |
|
| 897 | 1002 | $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 898 | 1003 | $prefixe = $connexion['prefixe']; |
| 899 | 1004 | $link = $connexion['link']; |
| 900 | 1005 | $db = $connexion['db']; |
| 901 | - if ($prefixe) $table = preg_replace('/^spip/', $prefixe, $table); |
|
| 1006 | + if ($prefixe) { |
|
| 1007 | + $table = preg_replace('/^spip/', $prefixe, $table); |
|
| 1008 | + } |
|
| 902 | 1009 | |
| 903 | 1010 | // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
| 904 | 1011 | $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
@@ -913,7 +1020,9 @@ discard block |
||
| 913 | 1020 | . calculer_pg_expression('WHERE', $where, 'AND'); |
| 914 | 1021 | |
| 915 | 1022 | // renvoyer la requete inerte si demandee |
| 916 | - if (!$requeter) return $query; |
|
| 1023 | + if (!$requeter) { |
|
| 1024 | + return $query; |
|
| 1025 | + } |
|
| 917 | 1026 | |
| 918 | 1027 | return spip_pg_trace_query($query, $serveur); |
| 919 | 1028 | } |
@@ -922,8 +1031,12 @@ discard block |
||
| 922 | 1031 | // sauf les expressions de date lorsqu'il s'agit de fonctions SQL (NOW etc) |
| 923 | 1032 | // http://doc.spip.org/@spip_pg_updateq |
| 924 | 1033 | function spip_pg_updateq($table, $couples, $where='', $desc=array(), $serveur='',$requeter=true) { |
| 925 | - if (!$couples) return; |
|
| 926 | - if (!$desc) $desc = description_table($table, $serveur); |
|
| 1034 | + if (!$couples) { |
|
| 1035 | + return; |
|
| 1036 | + } |
|
| 1037 | + if (!$desc) { |
|
| 1038 | + $desc = description_table($table, $serveur); |
|
| 1039 | + } |
|
| 927 | 1040 | $fields = $desc['field']; |
| 928 | 1041 | foreach ($couples as $k => $val) { |
| 929 | 1042 | $couples[$k] = spip_pg_cite($val, $fields[$k]); |
@@ -941,17 +1054,23 @@ discard block |
||
| 941 | 1054 | $link = $connexion['link']; |
| 942 | 1055 | $db = $connexion['db']; |
| 943 | 1056 | |
| 944 | - if (!$desc) $desc = description_table($table, $serveur); |
|
| 945 | - if (!$desc) die("$table insertion sans description"); |
|
| 1057 | + if (!$desc) { |
|
| 1058 | + $desc = description_table($table, $serveur); |
|
| 1059 | + } |
|
| 1060 | + if (!$desc) { |
|
| 1061 | + die("$table insertion sans description"); |
|
| 1062 | + } |
|
| 946 | 1063 | $prim = $desc['key']['PRIMARY KEY']; |
| 947 | 1064 | $ids = preg_split('/,\s*/', $prim); |
| 948 | 1065 | $noprims = $prims = array(); |
| 949 | 1066 | foreach($values as $k=>$v) { |
| 950 | 1067 | $values[$k] = $v = spip_pg_cite($v, $desc['field'][$k]); |
| 951 | 1068 | |
| 952 | - if (!in_array($k, $ids)) |
|
| 953 | - $noprims[$k]= "$k=$v"; |
|
| 954 | - else $prims[$k]= "$k=$v"; |
|
| 1069 | + if (!in_array($k, $ids)) { |
|
| 1070 | + $noprims[$k]= "$k=$v"; |
|
| 1071 | + } else { |
|
| 1072 | + $prims[$k]= "$k=$v"; |
|
| 1073 | + } |
|
| 955 | 1074 | } |
| 956 | 1075 | |
| 957 | 1076 | // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
@@ -973,7 +1092,9 @@ discard block |
||
| 973 | 1092 | if ($couples) { |
| 974 | 1093 | $couples = spip_pg_query_simple($link, $q); |
| 975 | 1094 | # spip_log($q,'pg.'._LOG_DEBUG); |
| 976 | - if (!$couples) return false; |
|
| 1095 | + if (!$couples) { |
|
| 1096 | + return false; |
|
| 1097 | + } |
|
| 977 | 1098 | $couples = pg_affected_rows($couples); |
| 978 | 1099 | } |
| 979 | 1100 | if (!$couples) { |
@@ -1018,13 +1139,15 @@ discard block |
||
| 1018 | 1139 | { |
| 1019 | 1140 | global $tables_principales; |
| 1020 | 1141 | include_spip('base/serial'); |
| 1021 | - if (!isset($tables_principales[$table])) return false; |
|
| 1142 | + if (!isset($tables_principales[$table])) { |
|
| 1143 | + return false; |
|
| 1144 | + } |
|
| 1022 | 1145 | $desc = $tables_principales[$table]; |
| 1023 | 1146 | $prim = @$desc['key']['PRIMARY KEY']; |
| 1024 | 1147 | if (!preg_match('/^\w+$/', $prim) |
| 1025 | - OR strpos($desc['field'][$prim], 'int') === false) |
|
| 1026 | - return ''; |
|
| 1027 | - else { return $raw?$prim:$table . '_' . $prim . "_seq";} |
|
| 1148 | + OR strpos($desc['field'][$prim], 'int') === false) { |
|
| 1149 | + return ''; |
|
| 1150 | + } else { return $raw?$prim:$table . '_' . $prim . "_seq";} |
|
| 1028 | 1151 | } |
| 1029 | 1152 | |
| 1030 | 1153 | // Explicite les conversions de Mysql d'une valeur $v de type $t |
@@ -1032,26 +1155,30 @@ discard block |
||
| 1032 | 1155 | |
| 1033 | 1156 | // http://doc.spip.org/@spip_pg_cite |
| 1034 | 1157 | function spip_pg_cite($v, $t){ |
| 1035 | - if(is_null($v)) return 'NULL'; // null php se traduit en NULL SQL |
|
| 1158 | + if(is_null($v)) { |
|
| 1159 | + return 'NULL'; |
|
| 1160 | + } |
|
| 1161 | + // null php se traduit en NULL SQL |
|
| 1036 | 1162 | |
| 1037 | 1163 | if (sql_test_date($t)) { |
| 1038 | - if ($v AND (strpos("0123456789", $v[0]) === false)) |
|
| 1039 | - return spip_pg_frommysql($v); |
|
| 1040 | - else { |
|
| 1041 | - if (strncmp($v,'0000',4)==0) |
|
| 1042 | - $v = "0001" . substr($v,4); |
|
| 1043 | - if (strpos($v, "-00-00") === 4) |
|
| 1044 | - $v = substr($v,0,4)."-01-01".substr($v,10); |
|
| 1164 | + if ($v AND (strpos("0123456789", $v[0]) === false)) { |
|
| 1165 | + return spip_pg_frommysql($v); |
|
| 1166 | + } else { |
|
| 1167 | + if (strncmp($v,'0000',4)==0) { |
|
| 1168 | + $v = "0001" . substr($v,4); |
|
| 1169 | + } |
|
| 1170 | + if (strpos($v, "-00-00") === 4) { |
|
| 1171 | + $v = substr($v,0,4)."-01-01".substr($v,10); |
|
| 1172 | + } |
|
| 1045 | 1173 | return "timestamp '$v'"; |
| 1046 | 1174 | } |
| 1047 | - } |
|
| 1048 | - elseif (!sql_test_int($t)) |
|
| 1049 | - return ("'" . pg_escape_string($v) . "'"); |
|
| 1050 | - elseif (is_numeric($v) OR (strpos($v, 'CAST(') === 0)) |
|
| 1051 | - return $v; |
|
| 1052 | - elseif ($v[0]== '0' AND $v[1]!=='x' AND ctype_xdigit(substr($v,1))) |
|
| 1053 | - return substr($v,1); |
|
| 1054 | - else { |
|
| 1175 | + } elseif (!sql_test_int($t)) { |
|
| 1176 | + return ("'" . pg_escape_string($v) . "'"); |
|
| 1177 | + } elseif (is_numeric($v) OR (strpos($v, 'CAST(') === 0)) { |
|
| 1178 | + return $v; |
|
| 1179 | + } elseif ($v[0]== '0' AND $v[1]!=='x' AND ctype_xdigit(substr($v,1))) { |
|
| 1180 | + return substr($v,1); |
|
| 1181 | + } else { |
|
| 1055 | 1182 | spip_log("Warning: '$v' n'est pas de type $t", 'pg.'._LOG_AVERTISSEMENT); |
| 1056 | 1183 | return intval($v); |
| 1057 | 1184 | } |
@@ -1065,11 +1192,13 @@ discard block |
||
| 1065 | 1192 | |
| 1066 | 1193 | function spip_pg_quote($v, $type='') |
| 1067 | 1194 | { |
| 1068 | - if (!is_array($v)) |
|
| 1069 | - return spip_pg_cite($v,$type); |
|
| 1195 | + if (!is_array($v)) { |
|
| 1196 | + return spip_pg_cite($v,$type); |
|
| 1197 | + } |
|
| 1070 | 1198 | // si c'est un tableau, le parcourir en propageant le type |
| 1071 | - foreach($v as $k=>$r) |
|
| 1072 | - $v[$k] = spip_pg_quote($r, $type); |
|
| 1199 | + foreach($v as $k=>$r) { |
|
| 1200 | + $v[$k] = spip_pg_quote($r, $type); |
|
| 1201 | + } |
|
| 1073 | 1202 | return join(",", $v); |
| 1074 | 1203 | } |
| 1075 | 1204 | |
@@ -1094,9 +1223,12 @@ discard block |
||
| 1094 | 1223 | // IN (...) souvent limite a 255 elements, d'ou cette fonction assistante |
| 1095 | 1224 | // |
| 1096 | 1225 | // s'il n'y a pas de valeur, eviter de produire un IN vide: PG rale. |
| 1097 | - if (!$valeurs) return $not ? '0=0' : '0=1'; |
|
| 1098 | - if (strpos($valeurs, "CAST(x'") !== false) |
|
| 1099 | - return "($val=" . join("OR $val=", explode(',',$valeurs)).')'; |
|
| 1226 | + if (!$valeurs) { |
|
| 1227 | + return $not ? '0=0' : '0=1'; |
|
| 1228 | + } |
|
| 1229 | + if (strpos($valeurs, "CAST(x'") !== false) { |
|
| 1230 | + return "($val=" . join("OR $val=", explode(',',$valeurs)).')'; |
|
| 1231 | + } |
|
| 1100 | 1232 | $n = $i = 0; |
| 1101 | 1233 | $in_sql =""; |
| 1102 | 1234 | while ($n = strpos($valeurs, ',', $n+1)) { |
@@ -1135,16 +1267,22 @@ discard block |
||
| 1135 | 1267 | // http://doc.spip.org/@spip_pg_drop_table |
| 1136 | 1268 | function spip_pg_drop_table($table, $exist='', $serveur='',$requeter=true) |
| 1137 | 1269 | { |
| 1138 | - if ($exist) $exist =" IF EXISTS"; |
|
| 1139 | - if (spip_pg_query("DROP TABLE$exist $table", $serveur, $requeter)) |
|
| 1140 | - return true; |
|
| 1141 | - else return false; |
|
| 1142 | -} |
|
| 1270 | + if ($exist) { |
|
| 1271 | + $exist =" IF EXISTS"; |
|
| 1272 | + } |
|
| 1273 | + if (spip_pg_query("DROP TABLE$exist $table", $serveur, $requeter)) { |
|
| 1274 | + return true; |
|
| 1275 | + } else { |
|
| 1276 | + return false; |
|
| 1277 | + } |
|
| 1278 | + } |
|
| 1143 | 1279 | |
| 1144 | 1280 | // supprime une vue |
| 1145 | 1281 | // http://doc.spip.org/@spip_pg_drop_view |
| 1146 | 1282 | function spip_pg_drop_view($view, $exist='', $serveur='',$requeter=true) { |
| 1147 | - if ($exist) $exist =" IF EXISTS"; |
|
| 1283 | + if ($exist) { |
|
| 1284 | + $exist =" IF EXISTS"; |
|
| 1285 | + } |
|
| 1148 | 1286 | return spip_pg_query("DROP VIEW$exist $view", $serveur, $requeter); |
| 1149 | 1287 | } |
| 1150 | 1288 | |
@@ -1177,7 +1315,9 @@ discard block |
||
| 1177 | 1315 | $connexion['last'] = $q = "SELECT column_name, column_default, data_type FROM information_schema.columns WHERE table_name ILIKE " . _q($nom_table); |
| 1178 | 1316 | |
| 1179 | 1317 | $res = spip_pg_query_simple($link, $q); |
| 1180 | - if (!$res) return false; |
|
| 1318 | + if (!$res) { |
|
| 1319 | + return false; |
|
| 1320 | + } |
|
| 1181 | 1321 | |
| 1182 | 1322 | // etrangement, $res peut ne rien contenir, mais arriver ici... |
| 1183 | 1323 | // il faut en tenir compte dans le return |
@@ -1211,41 +1351,47 @@ discard block |
||
| 1211 | 1351 | $prefixe = $connexion['prefixe']; |
| 1212 | 1352 | $link = $connexion['link']; |
| 1213 | 1353 | $db = $connexion['db']; |
| 1214 | - if ($prefixe) $nom = preg_replace('/^spip/', $prefixe, $nom); |
|
| 1354 | + if ($prefixe) { |
|
| 1355 | + $nom = preg_replace('/^spip/', $prefixe, $nom); |
|
| 1356 | + } |
|
| 1215 | 1357 | $query = $prim = $prim_name = $v = $s = $p=''; |
| 1216 | 1358 | $keys = array(); |
| 1217 | 1359 | |
| 1218 | 1360 | // certains plugins declarent les tables (permet leur inclusion dans le dump) |
| 1219 | 1361 | // sans les renseigner (laisse le compilo recuperer la description) |
| 1220 | - if (!is_array($champs) || !is_array($cles)) |
|
| 1221 | - return; |
|
| 1362 | + if (!is_array($champs) || !is_array($cles)) { |
|
| 1363 | + return; |
|
| 1364 | + } |
|
| 1222 | 1365 | |
| 1223 | 1366 | foreach($cles as $k => $v) { |
| 1224 | 1367 | if (strpos($k, "KEY ") === 0) { |
| 1225 | 1368 | $n = str_replace('`','',$k); |
| 1226 | 1369 | $v = str_replace('`','"',$v); |
| 1227 | 1370 | $i = $nom . preg_replace("/KEY +/", '_',$n); |
| 1228 | - if ($k != $n) $i = "\"$i\""; |
|
| 1371 | + if ($k != $n) { |
|
| 1372 | + $i = "\"$i\""; |
|
| 1373 | + } |
|
| 1229 | 1374 | $keys[] = "CREATE INDEX $i ON $nom ($v);"; |
| 1230 | - } |
|
| 1231 | - elseif (strpos($k, "UNIQUE ") === 0) { |
|
| 1375 | + } elseif (strpos($k, "UNIQUE ") === 0) { |
|
| 1232 | 1376 | $k = preg_replace("/^UNIQUE +/", '',$k); |
| 1233 | 1377 | $prim .= "$s\n\t\tCONSTRAINT " . str_replace('`','"',$k) ." UNIQUE ($v)"; |
| 1234 | - } |
|
| 1235 | - else { |
|
| 1378 | + } else { |
|
| 1236 | 1379 | $prim .= "$s\n\t\t" . str_replace('`','"',$k) ." ($v)"; |
| 1237 | 1380 | } |
| 1238 | - if ($k == "PRIMARY KEY") |
|
| 1239 | - $prim_name = $v; |
|
| 1381 | + if ($k == "PRIMARY KEY") { |
|
| 1382 | + $prim_name = $v; |
|
| 1383 | + } |
|
| 1240 | 1384 | $s = ","; |
| 1241 | 1385 | } |
| 1242 | 1386 | $s = ''; |
| 1243 | 1387 | |
| 1244 | 1388 | $character_set = ""; |
| 1245 | - if (@$GLOBALS['meta']['charset_sql_base']) |
|
| 1246 | - $character_set .= " CHARACTER SET ".$GLOBALS['meta']['charset_sql_base']; |
|
| 1247 | - if (@$GLOBALS['meta']['charset_collation_sql_base']) |
|
| 1248 | - $character_set .= " COLLATE ".$GLOBALS['meta']['charset_collation_sql_base']; |
|
| 1389 | + if (@$GLOBALS['meta']['charset_sql_base']) { |
|
| 1390 | + $character_set .= " CHARACTER SET ".$GLOBALS['meta']['charset_sql_base']; |
|
| 1391 | + } |
|
| 1392 | + if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
|
| 1393 | + $character_set .= " COLLATE ".$GLOBALS['meta']['charset_collation_sql_base']; |
|
| 1394 | + } |
|
| 1249 | 1395 | |
| 1250 | 1396 | foreach($champs as $k => $v) { |
| 1251 | 1397 | $k = str_replace('`','"',$k); |
@@ -1270,13 +1416,15 @@ discard block |
||
| 1270 | 1416 | ($character_set?" DEFAULT $character_set":"") |
| 1271 | 1417 | ."\n"; |
| 1272 | 1418 | |
| 1273 | - if (!$requeter) return $q; |
|
| 1419 | + if (!$requeter) { |
|
| 1420 | + return $q; |
|
| 1421 | + } |
|
| 1274 | 1422 | $connexion['last'] = $q; |
| 1275 | 1423 | $r = @pg_query($link, $q); |
| 1276 | 1424 | |
| 1277 | - if (!$r) |
|
| 1278 | - spip_log("Impossible de creer cette table: $q",'pg.'._LOG_ERREUR); |
|
| 1279 | - else { |
|
| 1425 | + if (!$r) { |
|
| 1426 | + spip_log("Impossible de creer cette table: $q",'pg.'._LOG_ERREUR); |
|
| 1427 | + } else { |
|
| 1280 | 1428 | foreach($keys as $index) {pg_query($link, $index);} |
| 1281 | 1429 | } |
| 1282 | 1430 | return $r; |
@@ -1290,10 +1438,14 @@ discard block |
||
| 1290 | 1438 | // Fonction de creation d'une vue SQL nommee $nom |
| 1291 | 1439 | // http://doc.spip.org/@spip_pg_create_view |
| 1292 | 1440 | function spip_pg_create_view($nom, $query_select, $serveur='',$requeter=true) { |
| 1293 | - if (!$query_select) return false; |
|
| 1441 | + if (!$query_select) { |
|
| 1442 | + return false; |
|
| 1443 | + } |
|
| 1294 | 1444 | // vue deja presente |
| 1295 | 1445 | if (sql_showtable($nom, false, $serveur)) { |
| 1296 | - if ($requeter) spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)",'pg.'._LOG_ERREUR); |
|
| 1446 | + if ($requeter) { |
|
| 1447 | + spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)",'pg.'._LOG_ERREUR); |
|
| 1448 | + } |
|
| 1297 | 1449 | return false; |
| 1298 | 1450 | } |
| 1299 | 1451 | |
@@ -29,18 +29,18 @@ discard block |
||
| 29 | 29 | // si ca ne marche toujours pas, echec. |
| 30 | 30 | |
| 31 | 31 | // http://doc.spip.org/@req_pg_dist |
| 32 | -function req_pg_dist($addr, $port, $login, $pass, $db='', $prefixe='') { |
|
| 32 | +function req_pg_dist($addr, $port, $login, $pass, $db = '', $prefixe = '') { |
|
| 33 | 33 | static $last_connect = array(); |
| 34 | 34 | if (!charger_php_extension('pgsql')) return false; |
| 35 | 35 | |
| 36 | 36 | // si provient de selectdb |
| 37 | - if (empty($addr) && empty($port) && empty($login) && empty($pass)){ |
|
| 38 | - foreach (array('addr','port','login','pass','prefixe') as $a){ |
|
| 37 | + if (empty($addr) && empty($port) && empty($login) && empty($pass)) { |
|
| 38 | + foreach (array('addr', 'port', 'login', 'pass', 'prefixe') as $a) { |
|
| 39 | 39 | $$a = $last_connect[$a]; |
| 40 | 40 | } |
| 41 | 41 | } |
| 42 | 42 | @list($host, $p) = explode(';', $addr); |
| 43 | - if ($p >0) $port = " port=$p" ; else $port = ''; |
|
| 43 | + if ($p > 0) $port = " port=$p"; else $port = ''; |
|
| 44 | 44 | $erreurs = array(); |
| 45 | 45 | if ($db) { |
| 46 | 46 | @$link = pg_connect("host=$host$port dbname=$db user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW); |
@@ -56,13 +56,13 @@ discard block |
||
| 56 | 56 | } |
| 57 | 57 | if (!$link) { |
| 58 | 58 | $erreurs[] = pg_last_error(); |
| 59 | - foreach($erreurs as $e) |
|
| 60 | - spip_log('Echec pg_connect. Erreur : ' . $e,'pg.'._LOG_HS); |
|
| 59 | + foreach ($erreurs as $e) |
|
| 60 | + spip_log('Echec pg_connect. Erreur : '.$e, 'pg.'._LOG_HS); |
|
| 61 | 61 | return false; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | if ($link) |
| 65 | - $last_connect = array ( |
|
| 65 | + $last_connect = array( |
|
| 66 | 66 | 'addr' => $addr, |
| 67 | 67 | 'port' => $port, |
| 68 | 68 | 'login' => $login, |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | 'prefixe' => $prefixe, |
| 72 | 72 | ); |
| 73 | 73 | |
| 74 | - spip_log("Connexion vers $host, base $db, prefixe $prefixe " . ($link ? 'operationnelle' : 'impossible'),'pg.'._LOG_DEBUG); |
|
| 74 | + spip_log("Connexion vers $host, base $db, prefixe $prefixe ".($link ? 'operationnelle' : 'impossible'), 'pg.'._LOG_DEBUG); |
|
| 75 | 75 | |
| 76 | 76 | return !$link ? false : array( |
| 77 | 77 | 'db' => $db, |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | |
| 121 | 121 | // Par ou ca passe une fois les traductions faites |
| 122 | 122 | // http://doc.spip.org/@spip_pg_trace_query |
| 123 | -function spip_pg_trace_query($query, $serveur='') |
|
| 123 | +function spip_pg_trace_query($query, $serveur = '') |
|
| 124 | 124 | { |
| 125 | 125 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 126 | 126 | $prefixe = $connexion['prefixe']; |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | if (isset($_GET['var_profile'])) { |
| 131 | 131 | include_spip('public/tracer'); |
| 132 | 132 | $t = trace_query_start(); |
| 133 | - } else $t = 0 ; |
|
| 133 | + } else $t = 0; |
|
| 134 | 134 | |
| 135 | 135 | $connexion['last'] = $query; |
| 136 | 136 | $r = spip_pg_query_simple($link, $query); |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | // Elle change juste le noms des tables ($table_prefix) dans le FROM etc |
| 145 | 145 | |
| 146 | 146 | // http://doc.spip.org/@spip_pg_query |
| 147 | -function spip_pg_query($query, $serveur='',$requeter=true) |
|
| 147 | +function spip_pg_query($query, $serveur = '', $requeter = true) |
|
| 148 | 148 | { |
| 149 | 149 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 150 | 150 | $prefixe = $connexion['prefixe']; |
@@ -154,8 +154,8 @@ discard block |
||
| 154 | 154 | if (preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
| 155 | 155 | $suite = strstr($query, $regs[0]); |
| 156 | 156 | $query = substr($query, 0, -strlen($suite)); |
| 157 | - } else $suite =''; |
|
| 158 | - $query = preg_replace('/([,\s])spip_/', '\1'.$prefixe.'_', $query) . $suite; |
|
| 157 | + } else $suite = ''; |
|
| 158 | + $query = preg_replace('/([,\s])spip_/', '\1'.$prefixe.'_', $query).$suite; |
|
| 159 | 159 | |
| 160 | 160 | // renvoyer la requete inerte si demandee |
| 161 | 161 | if (!$requeter) return $query; |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | return spip_pg_trace_query($query, $serveur); |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | -function spip_pg_query_simple($link, $query){ |
|
| 166 | +function spip_pg_query_simple($link, $query) { |
|
| 167 | 167 | #spip_log(var_export($query,true), 'pg.'._LOG_DEBUG); |
| 168 | 168 | return pg_query($link, $query); |
| 169 | 169 | } |
@@ -176,12 +176,12 @@ discard block |
||
| 176 | 176 | * stocke le resultat pour ne pas faire |
| 177 | 177 | * de requetes showtable intempestives |
| 178 | 178 | */ |
| 179 | -function spip_pg_ajouter_champs_timestamp($table, $couples, $desc='', $serveur=''){ |
|
| 179 | +function spip_pg_ajouter_champs_timestamp($table, $couples, $desc = '', $serveur = '') { |
|
| 180 | 180 | static $tables = array(); |
| 181 | 181 | |
| 182 | - if (!isset($tables[$table])){ |
|
| 182 | + if (!isset($tables[$table])) { |
|
| 183 | 183 | |
| 184 | - if (!$desc){ |
|
| 184 | + if (!$desc) { |
|
| 185 | 185 | $trouver_table = charger_fonction('trouver_table', 'base'); |
| 186 | 186 | $desc = $trouver_table($table, $serveur); |
| 187 | 187 | // si pas de description, on ne fait rien, ou on die() ? |
@@ -193,16 +193,16 @@ discard block |
||
| 193 | 193 | // avec la gestion de DEFAULT et ON UPDATE |
| 194 | 194 | // mais ceux-ci ne sont pas utilises dans le core |
| 195 | 195 | $tables[$table] = array(); |
| 196 | - foreach ($desc['field'] as $k=>$v){ |
|
| 196 | + foreach ($desc['field'] as $k=>$v) { |
|
| 197 | 197 | $v = strtolower(ltrim($v)); |
| 198 | 198 | // ne pas ajouter de timestamp now() si un default est specifie |
| 199 | - if (strpos($v, 'timestamp')===0 AND strpos($v, 'default')===false) |
|
| 199 | + if (strpos($v, 'timestamp') === 0 AND strpos($v, 'default') === false) |
|
| 200 | 200 | $tables[$table][] = $k; |
| 201 | 201 | } |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | // ajout des champs type 'timestamp' absents |
| 205 | - foreach ($tables[$table] as $maj){ |
|
| 205 | + foreach ($tables[$table] as $maj) { |
|
| 206 | 206 | if (!array_key_exists($maj, $couples)) |
| 207 | 207 | $couples[$maj] = "NOW()"; |
| 208 | 208 | } |
@@ -212,12 +212,12 @@ discard block |
||
| 212 | 212 | |
| 213 | 213 | // Alter en PG ne traite pas les index |
| 214 | 214 | // http://doc.spip.org/@spip_pg_alter |
| 215 | -function spip_pg_alter($query, $serveur='',$requeter=true) { |
|
| 215 | +function spip_pg_alter($query, $serveur = '', $requeter = true) { |
|
| 216 | 216 | // il faudrait une regexp pour eviter de spliter ADD PRIMARY KEY (colA, colB) |
| 217 | 217 | // tout en cassant en deux alter distincts "ADD PRIMARY KEY (colA, colB), ADD INDEX (chose)"... |
| 218 | 218 | // ou revoir l'api de sql_alter en creant un |
| 219 | 219 | // sql_alter_table($table,array($actions)); |
| 220 | - if (!preg_match("/\s*((\s*IGNORE)?\s*TABLE\s*([^\s]*))\s*(.*)?/is", $query, $regs)){ |
|
| 220 | + if (!preg_match("/\s*((\s*IGNORE)?\s*TABLE\s*([^\s]*))\s*(.*)?/is", $query, $regs)) { |
|
| 221 | 221 | spip_log("$query mal comprise", 'pg.'._LOG_ERREUR); |
| 222 | 222 | return false; |
| 223 | 223 | } |
@@ -226,53 +226,53 @@ discard block |
||
| 226 | 226 | $suite = $regs[4]; |
| 227 | 227 | $todo = explode(',', $suite); |
| 228 | 228 | // on remet les morceaux dechires ensembles... que c'est laid ! |
| 229 | - $todo2 = array(); $i=0; |
|
| 229 | + $todo2 = array(); $i = 0; |
|
| 230 | 230 | $ouverte = false; |
| 231 | 231 | while ($do = array_shift($todo)) { |
| 232 | - $todo2[$i] = isset($todo2[$i]) ? $todo2[$i] . "," . $do : $do; |
|
| 233 | - $o=(false!==strpos($do,"(")); |
|
| 234 | - $f=(false!==strpos($do,")")); |
|
| 235 | - if ($o AND !$f) $ouverte=true; |
|
| 236 | - elseif ($f) $ouverte=false; |
|
| 232 | + $todo2[$i] = isset($todo2[$i]) ? $todo2[$i].",".$do : $do; |
|
| 233 | + $o = (false !== strpos($do, "(")); |
|
| 234 | + $f = (false !== strpos($do, ")")); |
|
| 235 | + if ($o AND !$f) $ouverte = true; |
|
| 236 | + elseif ($f) $ouverte = false; |
|
| 237 | 237 | if (!$ouverte) $i++; |
| 238 | 238 | } |
| 239 | - $todo=$todo2; |
|
| 239 | + $todo = $todo2; |
|
| 240 | 240 | $query = $debut.' '.array_shift($todo); |
| 241 | 241 | |
| 242 | 242 | if (!preg_match('/^\s*(IGNORE\s*)?TABLE\s+(\w+)\s+(ADD|DROP|CHANGE|MODIFY|RENAME)\s*(.*)$/is', $query, $r)) { |
| 243 | 243 | spip_log("$query incompris", 'pg.'._LOG_ERREUR); |
| 244 | 244 | } else { |
| 245 | 245 | if ($r[1]) spip_log("j'ignore IGNORE dans $query", 'pg.'._LOG_AVERTISSEMENT); |
| 246 | - $f = 'spip_pg_alter_' . strtolower($r[3]); |
|
| 246 | + $f = 'spip_pg_alter_'.strtolower($r[3]); |
|
| 247 | 247 | if (function_exists($f)) |
| 248 | 248 | $f($r[2], $r[4], $serveur, $requeter); |
| 249 | 249 | else spip_log("$query non prevu", 'pg.'._LOG_ERREUR); |
| 250 | 250 | } |
| 251 | 251 | // Alter a plusieurs args. Faudrait optimiser. |
| 252 | 252 | if ($todo) |
| 253 | - spip_pg_alter("TABLE $table " . join(',',$todo)); |
|
| 253 | + spip_pg_alter("TABLE $table ".join(',', $todo)); |
|
| 254 | 254 | |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | // http://doc.spip.org/@spip_pg_alter_change |
| 258 | -function spip_pg_alter_change($table, $arg, $serveur='',$requeter=true) |
|
| 258 | +function spip_pg_alter_change($table, $arg, $serveur = '', $requeter = true) |
|
| 259 | 259 | { |
| 260 | - if (!preg_match('/^`?(\w+)`?\s+`?(\w+)`?\s+(.*?)\s*(DEFAULT .*?)?(NOT\s+NULL)?\s*(DEFAULT .*?)?$/i',$arg, $r)) { |
|
| 260 | + if (!preg_match('/^`?(\w+)`?\s+`?(\w+)`?\s+(.*?)\s*(DEFAULT .*?)?(NOT\s+NULL)?\s*(DEFAULT .*?)?$/i', $arg, $r)) { |
|
| 261 | 261 | spip_log("alter change: $arg incompris", 'pg.'._LOG_ERREUR); |
| 262 | 262 | } else { |
| 263 | 263 | list(,$old, $new, $type, $default, $null, $def2) = $r; |
| 264 | - $actions = array("ALTER $old TYPE " . mysql2pg_type($type)); |
|
| 264 | + $actions = array("ALTER $old TYPE ".mysql2pg_type($type)); |
|
| 265 | 265 | if ($null) |
| 266 | - $actions[]= "ALTER $old SET NOT NULL"; |
|
| 266 | + $actions[] = "ALTER $old SET NOT NULL"; |
|
| 267 | 267 | else |
| 268 | - $actions[]= "ALTER $old DROP NOT NULL"; |
|
| 268 | + $actions[] = "ALTER $old DROP NOT NULL"; |
|
| 269 | 269 | |
| 270 | 270 | if ($d = ($default ? $default : $def2)) |
| 271 | - $actions[]= "ALTER $old SET $d"; |
|
| 271 | + $actions[] = "ALTER $old SET $d"; |
|
| 272 | 272 | else |
| 273 | - $actions[]= "ALTER $old DROP DEFAULT"; |
|
| 273 | + $actions[] = "ALTER $old DROP DEFAULT"; |
|
| 274 | 274 | |
| 275 | - spip_pg_query("ALTER TABLE $table " . join(', ', $actions)); |
|
| 275 | + spip_pg_query("ALTER TABLE $table ".join(', ', $actions)); |
|
| 276 | 276 | |
| 277 | 277 | if ($old != $new) |
| 278 | 278 | spip_pg_query("ALTER TABLE $table RENAME $old TO $new", $serveur); |
@@ -280,38 +280,38 @@ discard block |
||
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | // http://doc.spip.org/@spip_pg_alter_add |
| 283 | -function spip_pg_alter_add($table, $arg, $serveur='',$requeter=true) { |
|
| 283 | +function spip_pg_alter_add($table, $arg, $serveur = '', $requeter = true) { |
|
| 284 | 284 | if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*(.*)$/', $arg, $r)) { |
| 285 | 285 | spip_log("alter add $arg incompris", 'pg.'._LOG_ERREUR); |
| 286 | 286 | return NULL; |
| 287 | 287 | } |
| 288 | - if (!$r[1] OR $r[1]=='COLUMN') { |
|
| 289 | - preg_match('/`?(\w+)`?(.*)/',$r[2], $m); |
|
| 288 | + if (!$r[1] OR $r[1] == 'COLUMN') { |
|
| 289 | + preg_match('/`?(\w+)`?(.*)/', $r[2], $m); |
|
| 290 | 290 | if (preg_match('/^(.*)(BEFORE|AFTER|FIRST)(.*)$/is', $m[2], $n)) { |
| 291 | - $m[2]=$n[1]; |
|
| 291 | + $m[2] = $n[1]; |
|
| 292 | 292 | } |
| 293 | - return spip_pg_query("ALTER TABLE $table ADD " . $m[1] . ' ' . mysql2pg_type($m[2]), $serveur, $requeter); |
|
| 293 | + return spip_pg_query("ALTER TABLE $table ADD ".$m[1].' '.mysql2pg_type($m[2]), $serveur, $requeter); |
|
| 294 | 294 | } elseif ($r[1][0] == 'P') { |
| 295 | 295 | // la primary peut etre sur plusieurs champs |
| 296 | - $r[2] = trim(str_replace('`','',$r[2])); |
|
| 297 | - $m = ($r[2][0]=='(') ? substr($r[2],1,-1) : $r[2]; |
|
| 298 | - return spip_pg_query("ALTER TABLE $table ADD CONSTRAINT $table" .'_pkey PRIMARY KEY (' . $m . ')', $serveur, $requeter); |
|
| 296 | + $r[2] = trim(str_replace('`', '', $r[2])); |
|
| 297 | + $m = ($r[2][0] == '(') ? substr($r[2], 1, -1) : $r[2]; |
|
| 298 | + return spip_pg_query("ALTER TABLE $table ADD CONSTRAINT $table".'_pkey PRIMARY KEY ('.$m.')', $serveur, $requeter); |
|
| 299 | 299 | } else { |
| 300 | - preg_match('/([^\s,]*)\s*(.*)?/',$r[2], $m); |
|
| 300 | + preg_match('/([^\s,]*)\s*(.*)?/', $r[2], $m); |
|
| 301 | 301 | // peut etre "(colonne)" ou "nom_index (colonnes)" |
| 302 | 302 | // bug potentiel si qqn met "(colonne, colonne)" |
| 303 | 303 | // |
| 304 | 304 | // nom_index (colonnes) |
| 305 | 305 | if ($m[2]) { |
| 306 | - $colonnes = substr($m[2],1,-1); |
|
| 306 | + $colonnes = substr($m[2], 1, -1); |
|
| 307 | 307 | $nom_index = $m[1]; |
| 308 | 308 | } |
| 309 | 309 | else { |
| 310 | 310 | // (colonne) |
| 311 | 311 | if ($m[1][0] == "(") { |
| 312 | - $colonnes = substr($m[1],1,-1); |
|
| 313 | - if (false!==strpos(",",$colonnes)) { |
|
| 314 | - spip_log(_LOG_GRAVITE_ERREUR,"PG : Erreur, impossible de creer un index sur plusieurs colonnes" |
|
| 312 | + $colonnes = substr($m[1], 1, -1); |
|
| 313 | + if (false !== strpos(",", $colonnes)) { |
|
| 314 | + spip_log(_LOG_GRAVITE_ERREUR, "PG : Erreur, impossible de creer un index sur plusieurs colonnes" |
|
| 315 | 315 | ." sans qu'il ait de nom ($table, ($colonnes))", 'pg'); |
| 316 | 316 | } else { |
| 317 | 317 | $nom_index = $colonnes; |
@@ -327,25 +327,25 @@ discard block |
||
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | // http://doc.spip.org/@spip_pg_alter_drop |
| 330 | -function spip_pg_alter_drop($table, $arg, $serveur='',$requeter=true) { |
|
| 330 | +function spip_pg_alter_drop($table, $arg, $serveur = '', $requeter = true) { |
|
| 331 | 331 | if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*`?(\w*)`?/', $arg, $r)) |
| 332 | 332 | spip_log("alter drop: $arg incompris", 'pg.'._LOG_ERREUR); |
| 333 | 333 | else { |
| 334 | - if (!$r[1] OR $r[1]=='COLUMN') |
|
| 335 | - return spip_pg_query("ALTER TABLE $table DROP " . $r[2], $serveur); |
|
| 334 | + if (!$r[1] OR $r[1] == 'COLUMN') |
|
| 335 | + return spip_pg_query("ALTER TABLE $table DROP ".$r[2], $serveur); |
|
| 336 | 336 | elseif ($r[1][0] == 'P') |
| 337 | - return spip_pg_query("ALTER TABLE $table DROP CONSTRAINT $table" . '_pkey', $serveur); |
|
| 337 | + return spip_pg_query("ALTER TABLE $table DROP CONSTRAINT $table".'_pkey', $serveur); |
|
| 338 | 338 | else { |
| 339 | - return spip_pg_query("DROP INDEX " . $table . '_' . $r[2], $serveur); |
|
| 339 | + return spip_pg_query("DROP INDEX ".$table.'_'.$r[2], $serveur); |
|
| 340 | 340 | } |
| 341 | 341 | } |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | -function spip_pg_alter_modify($table, $arg, $serveur='',$requeter=true) { |
|
| 345 | - if (!preg_match('/^`?(\w+)`?\s+(.*)$/',$arg, $r)) { |
|
| 344 | +function spip_pg_alter_modify($table, $arg, $serveur = '', $requeter = true) { |
|
| 345 | + if (!preg_match('/^`?(\w+)`?\s+(.*)$/', $arg, $r)) { |
|
| 346 | 346 | spip_log("alter modify: $arg incompris", 'pg.'._LOG_ERREUR); |
| 347 | 347 | } else { |
| 348 | - return spip_pg_alter_change($table, $r[1].' '.$arg, $serveur='',$requeter=true); |
|
| 348 | + return spip_pg_alter_change($table, $r[1].' '.$arg, $serveur = '', $requeter = true); |
|
| 349 | 349 | } |
| 350 | 350 | } |
| 351 | 351 | |
@@ -353,18 +353,18 @@ discard block |
||
| 353 | 353 | // - alter table A rename to X = changer le nom de la table |
| 354 | 354 | // - alter table A rename X to Y = changer le nom de la colonne X en Y |
| 355 | 355 | // pour l'instant, traiter simplement RENAME TO X |
| 356 | -function spip_pg_alter_rename($table, $arg, $serveur='',$requeter=true) { |
|
| 357 | - $rename=""; |
|
| 356 | +function spip_pg_alter_rename($table, $arg, $serveur = '', $requeter = true) { |
|
| 357 | + $rename = ""; |
|
| 358 | 358 | // si TO, mais pas au debut |
| 359 | - if (!stripos($arg,'TO ')){ |
|
| 360 | - $rename=$arg; |
|
| 359 | + if (!stripos($arg, 'TO ')) { |
|
| 360 | + $rename = $arg; |
|
| 361 | 361 | } |
| 362 | 362 | elseif (preg_match('/^(TO)\s*`?(\w*)`?/', $arg, $r)) { |
| 363 | - $rename=$r[2]; |
|
| 363 | + $rename = $r[2]; |
|
| 364 | 364 | } else { |
| 365 | 365 | spip_log("alter rename: $arg incompris", 'pg.'._LOG_ERREUR); |
| 366 | 366 | } |
| 367 | - return $rename?spip_pg_query("ALTER TABLE $table RENAME TO $rename"):false; |
|
| 367 | + return $rename ?spip_pg_query("ALTER TABLE $table RENAME TO $rename") : false; |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | |
@@ -379,24 +379,24 @@ discard block |
||
| 379 | 379 | * |
| 380 | 380 | * @return bool ou requete |
| 381 | 381 | */ |
| 382 | -function spip_pg_create_index($nom, $table, $champs, $serveur='', $requeter=true) { |
|
| 382 | +function spip_pg_create_index($nom, $table, $champs, $serveur = '', $requeter = true) { |
|
| 383 | 383 | if (!($nom OR $table OR $champs)) { |
| 384 | - spip_log("Champ manquant pour creer un index pg ($nom, $table, (".@join(',',$champs)."))",'pg.'._LOG_ERREUR); |
|
| 384 | + spip_log("Champ manquant pour creer un index pg ($nom, $table, (".@join(',', $champs)."))", 'pg.'._LOG_ERREUR); |
|
| 385 | 385 | return false; |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | - $nom = str_replace("`","",$nom); |
|
| 389 | - $champs = str_replace("`","",$champs); |
|
| 388 | + $nom = str_replace("`", "", $nom); |
|
| 389 | + $champs = str_replace("`", "", $champs); |
|
| 390 | 390 | |
| 391 | 391 | // PG ne differentie pas noms des index en fonction des tables |
| 392 | 392 | // il faut donc creer des noms uniques d'index pour une base pg |
| 393 | 393 | $nom = $table.'_'.$nom; |
| 394 | 394 | // enlever d'eventuelles parentheses deja presentes sur champs |
| 395 | - if (!is_array($champs)){ |
|
| 396 | - if ($champs[0]=="(") $champs = substr($champs,1,-1); |
|
| 395 | + if (!is_array($champs)) { |
|
| 396 | + if ($champs[0] == "(") $champs = substr($champs, 1, -1); |
|
| 397 | 397 | $champs = array($champs); |
| 398 | 398 | } |
| 399 | - $query = "CREATE INDEX $nom ON $table (" . join(',',$champs) . ")"; |
|
| 399 | + $query = "CREATE INDEX $nom ON $table (".join(',', $champs).")"; |
|
| 400 | 400 | if (!$requeter) return $query; |
| 401 | 401 | $res = spip_pg_query($query, $serveur, $requeter); |
| 402 | 402 | return $res; |
@@ -404,7 +404,7 @@ discard block |
||
| 404 | 404 | |
| 405 | 405 | |
| 406 | 406 | // http://doc.spip.org/@spip_pg_explain |
| 407 | -function spip_pg_explain($query, $serveur='',$requeter=true){ |
|
| 407 | +function spip_pg_explain($query, $serveur = '', $requeter = true) { |
|
| 408 | 408 | if (strpos(ltrim($query), 'SELECT') !== 0) return array(); |
| 409 | 409 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 410 | 410 | $prefixe = $connexion['prefixe']; |
@@ -412,11 +412,11 @@ discard block |
||
| 412 | 412 | if (preg_match('/\s(SET|VALUES|WHERE)\s/i', $query, $regs)) { |
| 413 | 413 | $suite = strstr($query, $regs[0]); |
| 414 | 414 | $query = substr($query, 0, -strlen($suite)); |
| 415 | - } else $suite =''; |
|
| 416 | - $query = 'EXPLAIN ' . preg_replace('/([,\s])spip_/', '\1'.$prefixe.'_', $query) . $suite; |
|
| 415 | + } else $suite = ''; |
|
| 416 | + $query = 'EXPLAIN '.preg_replace('/([,\s])spip_/', '\1'.$prefixe.'_', $query).$suite; |
|
| 417 | 417 | |
| 418 | 418 | if (!$requeter) return $query; |
| 419 | - $r = spip_pg_query_simple($link,$query); |
|
| 419 | + $r = spip_pg_query_simple($link, $query); |
|
| 420 | 420 | return spip_pg_fetch($r, NULL, $serveur); |
| 421 | 421 | } |
| 422 | 422 | |
@@ -435,13 +435,13 @@ discard block |
||
| 435 | 435 | * Nom de la base en cas de success. |
| 436 | 436 | * False en cas d'erreur. |
| 437 | 437 | **/ |
| 438 | -function spip_pg_selectdb($db, $serveur='',$requeter=true) { |
|
| 438 | +function spip_pg_selectdb($db, $serveur = '', $requeter = true) { |
|
| 439 | 439 | // se connecter a la base indiquee |
| 440 | 440 | // avec les identifiants connus |
| 441 | 441 | $index = $serveur ? strtolower($serveur) : 0; |
| 442 | 442 | |
| 443 | - if ($link = spip_connect_db('', '', '', '', $db, 'pg', '', '')){ |
|
| 444 | - if (($db==$link['db']) && $GLOBALS['connexions'][$index] = $link) |
|
| 443 | + if ($link = spip_connect_db('', '', '', '', $db, 'pg', '', '')) { |
|
| 444 | + if (($db == $link['db']) && $GLOBALS['connexions'][$index] = $link) |
|
| 445 | 445 | return $db; |
| 446 | 446 | } else |
| 447 | 447 | return false; |
@@ -462,16 +462,16 @@ discard block |
||
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | // http://doc.spip.org/@spip_pg_select |
| 465 | -function spip_pg_select($select, $from, $where='', |
|
| 466 | - $groupby=array(), $orderby='', $limit='', |
|
| 467 | - $having='', $serveur='',$requeter=true){ |
|
| 465 | +function spip_pg_select($select, $from, $where = '', |
|
| 466 | + $groupby = array(), $orderby = '', $limit = '', |
|
| 467 | + $having = '', $serveur = '', $requeter = true) { |
|
| 468 | 468 | |
| 469 | 469 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 470 | 470 | $prefixe = $connexion['prefixe']; |
| 471 | 471 | $link = $connexion['link']; |
| 472 | 472 | $db = $connexion['db']; |
| 473 | 473 | |
| 474 | - $limit = preg_match("/^\s*(([0-9]+),)?\s*([0-9]+)\s*$/", $limit,$limatch); |
|
| 474 | + $limit = preg_match("/^\s*(([0-9]+),)?\s*([0-9]+)\s*$/", $limit, $limatch); |
|
| 475 | 475 | if ($limit) { |
| 476 | 476 | $offset = $limatch[2]; |
| 477 | 477 | $count = $limatch[3]; |
@@ -492,20 +492,20 @@ discard block |
||
| 492 | 492 | if (is_array($having)) |
| 493 | 493 | $having = join("\n\tAND ", array_map('calculer_pg_where', $having)); |
| 494 | 494 | } |
| 495 | - $from = spip_pg_from($from, $prefixe); |
|
| 496 | - $query = "SELECT ". $select |
|
| 495 | + $from = spip_pg_from($from, $prefixe); |
|
| 496 | + $query = "SELECT ".$select |
|
| 497 | 497 | . (!$from ? '' : "\nFROM $from") |
| 498 | - . (!$where ? '' : ("\nWHERE " . (!is_array($where) ? calculer_pg_where($where) : (join("\n\tAND ", array_map('calculer_pg_where', $where)))))) |
|
| 498 | + . (!$where ? '' : ("\nWHERE ".(!is_array($where) ? calculer_pg_where($where) : (join("\n\tAND ", array_map('calculer_pg_where', $where)))))) |
|
| 499 | 499 | . spip_pg_groupby($groupby, $from, $select) |
| 500 | 500 | . (!$having ? '' : "\nHAVING $having") |
| 501 | - . ($orderby ? ("\nORDER BY $orderby") :'') |
|
| 502 | - . (!$limit ? '' : (" LIMIT $count" . (!$offset ? '' : " OFFSET $offset"))); |
|
| 501 | + . ($orderby ? ("\nORDER BY $orderby") : '') |
|
| 502 | + . (!$limit ? '' : (" LIMIT $count".(!$offset ? '' : " OFFSET $offset"))); |
|
| 503 | 503 | |
| 504 | 504 | // renvoyer la requete inerte si demandee |
| 505 | 505 | if ($requeter === false) return $query; |
| 506 | 506 | |
| 507 | 507 | $r = spip_pg_trace_query($query, $serveur); |
| 508 | - return $r ? $r : $query;; |
|
| 508 | + return $r ? $r : $query; ; |
|
| 509 | 509 | } |
| 510 | 510 | |
| 511 | 511 | // Le traitement des prefixes de table dans un Select se limite au FROM |
@@ -515,22 +515,22 @@ discard block |
||
| 515 | 515 | function spip_pg_from($from, $prefixe) |
| 516 | 516 | { |
| 517 | 517 | if (is_array($from)) $from = spip_pg_select_as($from); |
| 518 | - return !$prefixe ? $from : preg_replace('/(\b)spip_/','\1'.$prefixe.'_', $from); |
|
| 518 | + return !$prefixe ? $from : preg_replace('/(\b)spip_/', '\1'.$prefixe.'_', $from); |
|
| 519 | 519 | } |
| 520 | 520 | |
| 521 | 521 | // http://doc.spip.org/@spip_pg_orderby |
| 522 | 522 | function spip_pg_orderby($order, $select) |
| 523 | 523 | { |
| 524 | 524 | $res = array(); |
| 525 | - $arg = (is_array($order) ? $order : preg_split('/\s*,\s*/',$order)); |
|
| 525 | + $arg = (is_array($order) ? $order : preg_split('/\s*,\s*/', $order)); |
|
| 526 | 526 | |
| 527 | - foreach($arg as $v) { |
|
| 528 | - if (preg_match('/(case\s+.*?else\s+0\s+end)\s*AS\s+' . $v .'/', $select, $m)) { |
|
| 527 | + foreach ($arg as $v) { |
|
| 528 | + if (preg_match('/(case\s+.*?else\s+0\s+end)\s*AS\s+'.$v.'/', $select, $m)) { |
|
| 529 | 529 | |
| 530 | 530 | $res[] = $m[1]; |
| 531 | - } else $res[]=$v; |
|
| 531 | + } else $res[] = $v; |
|
| 532 | 532 | } |
| 533 | - return spip_pg_frommysql(join(',',$res)); |
|
| 533 | + return spip_pg_frommysql(join(',', $res)); |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | // Conversion a l'arrach' des jointures MySQL en jointures PG |
@@ -544,41 +544,41 @@ discard block |
||
| 544 | 544 | // ismplifier avant de decouper |
| 545 | 545 | if (is_string($select)) |
| 546 | 546 | // fct SQL sur colonne et constante apostrophee ==> la colonne |
| 547 | - $select = preg_replace('/\w+\(\s*([^(),\']*),\s*\'[^\']*\'[^)]*\)/','\\1', $select); |
|
| 547 | + $select = preg_replace('/\w+\(\s*([^(),\']*),\s*\'[^\']*\'[^)]*\)/', '\\1', $select); |
|
| 548 | 548 | |
| 549 | 549 | if ($join OR $groupby) $join = is_array($select) ? $select : explode(", ", $select); |
| 550 | 550 | if ($join) { |
| 551 | 551 | // enlever les 0 as points, '', ... |
| 552 | - foreach($join as $k=>$v){ |
|
| 553 | - $v = str_replace('DISTINCT ','',$v); |
|
| 552 | + foreach ($join as $k=>$v) { |
|
| 553 | + $v = str_replace('DISTINCT ', '', $v); |
|
| 554 | 554 | // fct SQL sur colonne et constante apostrophee ==> la colonne |
| 555 | - $v = preg_replace('/\w+\(\s*([^(),\']*),\s*\'[^\']*\'[^)]*\)/','\\1', $v); |
|
| 556 | - $v = preg_replace('/CAST\(\s*([^(),\' ]*\s+)as\s*\w+\)/','\\1', $v); |
|
| 555 | + $v = preg_replace('/\w+\(\s*([^(),\']*),\s*\'[^\']*\'[^)]*\)/', '\\1', $v); |
|
| 556 | + $v = preg_replace('/CAST\(\s*([^(),\' ]*\s+)as\s*\w+\)/', '\\1', $v); |
|
| 557 | 557 | // resultat d'agregat ne sont pas a mettre dans le groupby |
| 558 | - $v = preg_replace('/(SUM|COUNT|MAX|MIN|UPPER)\([^)]+\)(\s*AS\s+\w+)\s*,?/i','', $v); |
|
| 558 | + $v = preg_replace('/(SUM|COUNT|MAX|MIN|UPPER)\([^)]+\)(\s*AS\s+\w+)\s*,?/i', '', $v); |
|
| 559 | 559 | // idem sans AS (fetch numerique) |
| 560 | - $v = preg_replace('/(SUM|COUNT|MAX|MIN|UPPER)\([^)]+\)\s*,?/i','', $v); |
|
| 560 | + $v = preg_replace('/(SUM|COUNT|MAX|MIN|UPPER)\([^)]+\)\s*,?/i', '', $v); |
|
| 561 | 561 | // des AS simples : on garde le cote droit du AS |
| 562 | - $v = preg_replace('/^.*\sAS\s+(\w+)\s*$/i','\\1', $v); |
|
| 562 | + $v = preg_replace('/^.*\sAS\s+(\w+)\s*$/i', '\\1', $v); |
|
| 563 | 563 | // ne reste plus que les vrais colonnes, ou des constantes a virer |
| 564 | - if (preg_match(',^[\'"],',$v) OR is_numeric($v)) |
|
| 564 | + if (preg_match(',^[\'"],', $v) OR is_numeric($v)) |
|
| 565 | 565 | unset($join[$k]); |
| 566 | 566 | else |
| 567 | 567 | $join[$k] = trim($v); |
| 568 | 568 | } |
| 569 | - $join = array_diff($join,array('')); |
|
| 570 | - $join = implode(',',$join); |
|
| 569 | + $join = array_diff($join, array('')); |
|
| 570 | + $join = implode(',', $join); |
|
| 571 | 571 | } |
| 572 | - if (is_array($groupby)) $groupby = join(',',$groupby); |
|
| 572 | + if (is_array($groupby)) $groupby = join(',', $groupby); |
|
| 573 | 573 | if ($join) $groupby = $groupby ? "$groupby, $join" : $join; |
| 574 | 574 | if (!$groupby) return ''; |
| 575 | 575 | |
| 576 | 576 | $groupby = spip_pg_frommysql($groupby); |
| 577 | 577 | // Ne pas mettre dans le Group-By des valeurs numeriques |
| 578 | 578 | // issue de prepare_recherche |
| 579 | - $groupby = preg_replace('/^\s*\d+\s+AS\s+\w+\s*,?\s*/i','', $groupby); |
|
| 580 | - $groupby = preg_replace('/,\s*\d+\s+AS\s+\w+\s*/i','', $groupby); |
|
| 581 | - $groupby = preg_replace('/\s+AS\s+\w+\s*/i','', $groupby); |
|
| 579 | + $groupby = preg_replace('/^\s*\d+\s+AS\s+\w+\s*,?\s*/i', '', $groupby); |
|
| 580 | + $groupby = preg_replace('/,\s*\d+\s+AS\s+\w+\s*/i', '', $groupby); |
|
| 581 | + $groupby = preg_replace('/\s+AS\s+\w+\s*/i', '', $groupby); |
|
| 582 | 582 | |
| 583 | 583 | return "\nGROUP BY $groupby"; |
| 584 | 584 | } |
@@ -597,7 +597,7 @@ discard block |
||
| 597 | 597 | |
| 598 | 598 | $res = spip_pg_fromfield($arg); |
| 599 | 599 | |
| 600 | - $res = preg_replace('/\brand[(][)]/i','random()', $res); |
|
| 600 | + $res = preg_replace('/\brand[(][)]/i', 'random()', $res); |
|
| 601 | 601 | |
| 602 | 602 | $res = preg_replace('/\b0\.0[+]([a-zA-Z0-9_.]+)\s*/', |
| 603 | 603 | 'CAST(substring(\1, \'^ *[0-9.]+\') as float)', |
@@ -651,8 +651,8 @@ discard block |
||
| 651 | 651 | $res = preg_replace('/([+<>-]=?)\s*(\'\d+-\d+-\d+\')/', '\1 timestamp \2', $res); |
| 652 | 652 | $res = preg_replace('/(\'\d+-\d+-\d+\')\s*([+<>-]=?)/', 'timestamp \1 \2', $res); |
| 653 | 653 | |
| 654 | - $res = preg_replace('/(timestamp .\d+)-00-/','\1-01-', $res); |
|
| 655 | - $res = preg_replace('/(timestamp .\d+-\d+)-00/','\1-01',$res); |
|
| 654 | + $res = preg_replace('/(timestamp .\d+)-00-/', '\1-01-', $res); |
|
| 655 | + $res = preg_replace('/(timestamp .\d+-\d+)-00/', '\1-01', $res); |
|
| 656 | 656 | # correct en theorie mais produit des debordements arithmetiques |
| 657 | 657 | # $res = preg_replace("/(EXTRACT[(][^ ]* FROM *)(timestamp *'[^']*' *[+-] *timestamp *'[^']*') *[)]/", '\2', $res); |
| 658 | 658 | $res = preg_replace("/(EXTRACT[(][^ ]* FROM *)('[^']*')/", '\1 timestamp \2', $res); |
@@ -663,18 +663,18 @@ discard block |
||
| 663 | 663 | // http://doc.spip.org/@spip_pg_fromfield |
| 664 | 664 | function spip_pg_fromfield($arg) |
| 665 | 665 | { |
| 666 | - while(preg_match('/^(.*?)FIELD\s*\(([^,]*)((,[^,)]*)*)\)/', $arg, $m)) { |
|
| 666 | + while (preg_match('/^(.*?)FIELD\s*\(([^,]*)((,[^,)]*)*)\)/', $arg, $m)) { |
|
| 667 | 667 | |
| 668 | 668 | preg_match_all('/,([^,]*)/', $m[3], $r, PREG_PATTERN_ORDER); |
| 669 | 669 | $res = ''; |
| 670 | - $n=0; |
|
| 670 | + $n = 0; |
|
| 671 | 671 | $index = $m[2]; |
| 672 | - foreach($r[1] as $v) { |
|
| 672 | + foreach ($r[1] as $v) { |
|
| 673 | 673 | $n++; |
| 674 | 674 | $res .= "\nwhen $index=$v then $n"; |
| 675 | 675 | } |
| 676 | - $arg = $m[1] . "case $res else 0 end " |
|
| 677 | - . substr($arg,strlen($m[0])); |
|
| 676 | + $arg = $m[1]."case $res else 0 end " |
|
| 677 | + . substr($arg, strlen($m[0])); |
|
| 678 | 678 | } |
| 679 | 679 | return $arg; |
| 680 | 680 | } |
@@ -686,15 +686,15 @@ discard block |
||
| 686 | 686 | return spip_pg_frommysql($v); |
| 687 | 687 | |
| 688 | 688 | $op = str_replace('REGEXP', '~', array_shift($v)); |
| 689 | - if (!($n=count($v))) |
|
| 689 | + if (!($n = count($v))) |
|
| 690 | 690 | return $op; |
| 691 | 691 | else { |
| 692 | 692 | $arg = calculer_pg_where(array_shift($v)); |
| 693 | - if ($n==1) { |
|
| 693 | + if ($n == 1) { |
|
| 694 | 694 | return "$op($arg)"; |
| 695 | 695 | } else { |
| 696 | 696 | $arg2 = calculer_pg_where(array_shift($v)); |
| 697 | - if ($n==2) { |
|
| 697 | + if ($n == 2) { |
|
| 698 | 698 | return "($arg $op $arg2)"; |
| 699 | 699 | } else return "($arg $op ($arg2) : $v[0])"; |
| 700 | 700 | } |
@@ -703,7 +703,7 @@ discard block |
||
| 703 | 703 | |
| 704 | 704 | |
| 705 | 705 | // http://doc.spip.org/@calculer_pg_expression |
| 706 | -function calculer_pg_expression($expression, $v, $join = 'AND'){ |
|
| 706 | +function calculer_pg_expression($expression, $v, $join = 'AND') { |
|
| 707 | 707 | if (empty($v)) |
| 708 | 708 | return ''; |
| 709 | 709 | |
@@ -712,20 +712,20 @@ discard block |
||
| 712 | 712 | if (!is_array($v)) $v = array($v); |
| 713 | 713 | |
| 714 | 714 | if (strtoupper($join) === 'AND') |
| 715 | - return $exp . join("\n\t$join ", array_map('calculer_pg_where', $v)); |
|
| 715 | + return $exp.join("\n\t$join ", array_map('calculer_pg_where', $v)); |
|
| 716 | 716 | else |
| 717 | - return $exp . join($join, $v); |
|
| 717 | + return $exp.join($join, $v); |
|
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | // http://doc.spip.org/@spip_pg_select_as |
| 721 | 721 | function spip_pg_select_as($args) |
| 722 | 722 | { |
| 723 | 723 | $argsas = ""; |
| 724 | - foreach($args as $k => $v) { |
|
| 725 | - if (substr($k,-1)=='@') { |
|
| 724 | + foreach ($args as $k => $v) { |
|
| 725 | + if (substr($k, -1) == '@') { |
|
| 726 | 726 | // c'est une jointure qui se refere au from precedent |
| 727 | 727 | // pas de virgule |
| 728 | - $argsas .= ' ' . $v ; |
|
| 728 | + $argsas .= ' '.$v; |
|
| 729 | 729 | } |
| 730 | 730 | else { |
| 731 | 731 | $as = ''; |
@@ -736,36 +736,36 @@ discard block |
||
| 736 | 736 | elseif ($v != $k) { |
| 737 | 737 | $p = strpos($v, " "); |
| 738 | 738 | if ($p) |
| 739 | - $v = substr($v,0,$p) . " AS $k" . substr($v,$p); |
|
| 739 | + $v = substr($v, 0, $p)." AS $k".substr($v, $p); |
|
| 740 | 740 | else $as = " AS $k"; |
| 741 | 741 | } |
| 742 | 742 | } |
| 743 | 743 | // spip_log("subs $k : $v avec $as", _LOG_DEBUG); |
| 744 | 744 | // if (strpos($v, 'JOIN') === false) $argsas .= ', '; |
| 745 | - $argsas .= ', '. $v . $as; |
|
| 745 | + $argsas .= ', '.$v.$as; |
|
| 746 | 746 | } |
| 747 | 747 | } |
| 748 | - return substr($argsas,2); |
|
| 748 | + return substr($argsas, 2); |
|
| 749 | 749 | } |
| 750 | 750 | |
| 751 | 751 | // http://doc.spip.org/@spip_pg_fetch |
| 752 | -function spip_pg_fetch($res, $t='', $serveur='',$requeter=true) { |
|
| 752 | +function spip_pg_fetch($res, $t = '', $serveur = '', $requeter = true) { |
|
| 753 | 753 | |
| 754 | 754 | if ($res) $res = pg_fetch_array($res, NULL, PGSQL_ASSOC); |
| 755 | 755 | return $res; |
| 756 | 756 | } |
| 757 | 757 | |
| 758 | -function spip_pg_seek($r, $row_number, $serveur='',$requeter=true) { |
|
| 759 | - if ($r) return pg_result_seek($r,$row_number); |
|
| 758 | +function spip_pg_seek($r, $row_number, $serveur = '', $requeter = true) { |
|
| 759 | + if ($r) return pg_result_seek($r, $row_number); |
|
| 760 | 760 | } |
| 761 | 761 | |
| 762 | 762 | |
| 763 | 763 | // http://doc.spip.org/@spip_pg_countsel |
| 764 | -function spip_pg_countsel($from = array(), $where = array(), $groupby=array(), |
|
| 765 | - $having = array(), $serveur='',$requeter=true) |
|
| 764 | +function spip_pg_countsel($from = array(), $where = array(), $groupby = array(), |
|
| 765 | + $having = array(), $serveur = '', $requeter = true) |
|
| 766 | 766 | { |
| 767 | - $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 768 | - $r = spip_pg_select("COUNT($c)", $from, $where,'', '', '', $having, $serveur, $requeter); |
|
| 767 | + $c = !$groupby ? '*' : ('DISTINCT '.(is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 768 | + $r = spip_pg_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
|
| 769 | 769 | if (!$requeter) return $r; |
| 770 | 770 | if (!is_resource($r)) return 0; |
| 771 | 771 | list($c) = pg_fetch_array($r, NULL, PGSQL_NUM); |
@@ -773,17 +773,17 @@ discard block |
||
| 773 | 773 | } |
| 774 | 774 | |
| 775 | 775 | // http://doc.spip.org/@spip_pg_count |
| 776 | -function spip_pg_count($res, $serveur='',$requeter=true) { |
|
| 776 | +function spip_pg_count($res, $serveur = '', $requeter = true) { |
|
| 777 | 777 | return !$res ? 0 : pg_numrows($res); |
| 778 | 778 | } |
| 779 | 779 | |
| 780 | 780 | // http://doc.spip.org/@spip_pg_free |
| 781 | -function spip_pg_free($res, $serveur='',$requeter=true) { |
|
| 781 | +function spip_pg_free($res, $serveur = '', $requeter = true) { |
|
| 782 | 782 | // rien a faire en postgres |
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | // http://doc.spip.org/@spip_pg_delete |
| 786 | -function spip_pg_delete($table, $where='', $serveur='',$requeter=true) { |
|
| 786 | +function spip_pg_delete($table, $where = '', $serveur = '', $requeter = true) { |
|
| 787 | 787 | |
| 788 | 788 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 789 | 789 | $prefixe = $connexion['prefixe']; |
@@ -805,16 +805,16 @@ discard block |
||
| 805 | 805 | } |
| 806 | 806 | |
| 807 | 807 | // http://doc.spip.org/@spip_pg_insert |
| 808 | -function spip_pg_insert($table, $champs, $valeurs, $desc=array(), $serveur='',$requeter=true) { |
|
| 808 | +function spip_pg_insert($table, $champs, $valeurs, $desc = array(), $serveur = '', $requeter = true) { |
|
| 809 | 809 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 810 | 810 | $prefixe = $connexion['prefixe']; |
| 811 | 811 | $link = $connexion['link']; |
| 812 | 812 | $db = $connexion['db']; |
| 813 | 813 | |
| 814 | 814 | if (!$desc) $desc = description_table($table, $serveur); |
| 815 | - $seq = spip_pg_sequence($table,true); |
|
| 815 | + $seq = spip_pg_sequence($table, true); |
|
| 816 | 816 | // si pas de cle primaire dans l'insertion, renvoyer curval |
| 817 | - if (!preg_match(",\b$seq\b,",$champs)){ |
|
| 817 | + if (!preg_match(",\b$seq\b,", $champs)) { |
|
| 818 | 818 | $seq = spip_pg_sequence($table); |
| 819 | 819 | if ($prefixe) |
| 820 | 820 | $seq = preg_replace('/^spip/', $prefixe, $seq); |
@@ -826,10 +826,10 @@ discard block |
||
| 826 | 826 | $table = preg_replace('/^spip/', $prefixe, $table); |
| 827 | 827 | } |
| 828 | 828 | $ret = !$seq ? '' : (" RETURNING $seq"); |
| 829 | - $ins = (strlen($champs)<3) |
|
| 829 | + $ins = (strlen($champs) < 3) |
|
| 830 | 830 | ? " DEFAULT VALUES" |
| 831 | 831 | : "$champs VALUES $valeurs"; |
| 832 | - $q ="INSERT INTO $table $ins $ret"; |
|
| 832 | + $q = "INSERT INTO $table $ins $ret"; |
|
| 833 | 833 | if (!$requeter) return $q; |
| 834 | 834 | $connexion['last'] = $q; |
| 835 | 835 | $r = spip_pg_query_simple($link, $q); |
@@ -843,55 +843,55 @@ discard block |
||
| 843 | 843 | } |
| 844 | 844 | |
| 845 | 845 | // http://doc.spip.org/@spip_pg_insertq |
| 846 | -function spip_pg_insertq($table, $couples=array(), $desc=array(), $serveur='',$requeter=true) { |
|
| 846 | +function spip_pg_insertq($table, $couples = array(), $desc = array(), $serveur = '', $requeter = true) { |
|
| 847 | 847 | |
| 848 | 848 | if (!$desc) $desc = description_table($table, $serveur); |
| 849 | 849 | if (!$desc) die("$table insertion sans description"); |
| 850 | - $fields = $desc['field']; |
|
| 850 | + $fields = $desc['field']; |
|
| 851 | 851 | |
| 852 | 852 | foreach ($couples as $champ => $val) { |
| 853 | - $couples[$champ]= spip_pg_cite($val, $fields[$champ]); |
|
| 853 | + $couples[$champ] = spip_pg_cite($val, $fields[$champ]); |
|
| 854 | 854 | } |
| 855 | 855 | |
| 856 | 856 | // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
| 857 | 857 | $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
| 858 | 858 | |
| 859 | - return spip_pg_insert($table, "(".join(',',array_keys($couples)).")", "(".join(',', $couples).")", $desc, $serveur, $requeter); |
|
| 859 | + return spip_pg_insert($table, "(".join(',', array_keys($couples)).")", "(".join(',', $couples).")", $desc, $serveur, $requeter); |
|
| 860 | 860 | } |
| 861 | 861 | |
| 862 | 862 | |
| 863 | 863 | |
| 864 | 864 | // http://doc.spip.org/@spip_pg_insertq_multi |
| 865 | -function spip_pg_insertq_multi($table, $tab_couples=array(), $desc=array(), $serveur='',$requeter=true) { |
|
| 865 | +function spip_pg_insertq_multi($table, $tab_couples = array(), $desc = array(), $serveur = '', $requeter = true) { |
|
| 866 | 866 | |
| 867 | 867 | if (!$desc) $desc = description_table($table, $serveur); |
| 868 | 868 | if (!$desc) die("$table insertion sans description"); |
| 869 | - $fields = isset($desc['field'])?$desc['field']:array(); |
|
| 869 | + $fields = isset($desc['field']) ? $desc['field'] : array(); |
|
| 870 | 870 | |
| 871 | 871 | // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
| 872 | 872 | // une premiere fois pour ajouter maj dans les cles |
| 873 | 873 | $c = isset($tab_couples[0]) ? $tab_couples[0] : array(); |
| 874 | 874 | $les_cles = spip_pg_ajouter_champs_timestamp($table, $c, $desc, $serveur); |
| 875 | 875 | |
| 876 | - $cles = "(" . join(',',array_keys($les_cles)). ')'; |
|
| 876 | + $cles = "(".join(',', array_keys($les_cles)).')'; |
|
| 877 | 877 | $valeurs = array(); |
| 878 | 878 | foreach ($tab_couples as $couples) { |
| 879 | - foreach ($couples as $champ => $val){ |
|
| 880 | - $couples[$champ]= spip_pg_cite($val, $fields[$champ]); |
|
| 879 | + foreach ($couples as $champ => $val) { |
|
| 880 | + $couples[$champ] = spip_pg_cite($val, $fields[$champ]); |
|
| 881 | 881 | } |
| 882 | 882 | // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
| 883 | 883 | $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
| 884 | 884 | |
| 885 | - $valeurs[] = '(' .join(',', $couples) . ')'; |
|
| 885 | + $valeurs[] = '('.join(',', $couples).')'; |
|
| 886 | 886 | } |
| 887 | - $valeurs = implode(', ',$valeurs); |
|
| 887 | + $valeurs = implode(', ', $valeurs); |
|
| 888 | 888 | |
| 889 | 889 | return spip_pg_insert($table, $cles, $valeurs, $desc, $serveur, $requeter); |
| 890 | 890 | } |
| 891 | 891 | |
| 892 | 892 | |
| 893 | 893 | // http://doc.spip.org/@spip_pg_update |
| 894 | -function spip_pg_update($table, $couples, $where='', $desc='', $serveur='',$requeter=true) { |
|
| 894 | +function spip_pg_update($table, $couples, $where = '', $desc = '', $serveur = '', $requeter = true) { |
|
| 895 | 895 | |
| 896 | 896 | if (!$couples) return; |
| 897 | 897 | $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
@@ -905,7 +905,7 @@ discard block |
||
| 905 | 905 | |
| 906 | 906 | $set = array(); |
| 907 | 907 | foreach ($couples as $champ => $val) { |
| 908 | - $set[] = $champ . '=' . $val; |
|
| 908 | + $set[] = $champ.'='.$val; |
|
| 909 | 909 | } |
| 910 | 910 | |
| 911 | 911 | $query = calculer_pg_expression('UPDATE', $table, ',') |
@@ -921,7 +921,7 @@ discard block |
||
| 921 | 921 | // idem, mais les valeurs sont des constantes a mettre entre apostrophes |
| 922 | 922 | // sauf les expressions de date lorsqu'il s'agit de fonctions SQL (NOW etc) |
| 923 | 923 | // http://doc.spip.org/@spip_pg_updateq |
| 924 | -function spip_pg_updateq($table, $couples, $where='', $desc=array(), $serveur='',$requeter=true) { |
|
| 924 | +function spip_pg_updateq($table, $couples, $where = '', $desc = array(), $serveur = '', $requeter = true) { |
|
| 925 | 925 | if (!$couples) return; |
| 926 | 926 | if (!$desc) $desc = description_table($table, $serveur); |
| 927 | 927 | $fields = $desc['field']; |
@@ -934,8 +934,8 @@ discard block |
||
| 934 | 934 | |
| 935 | 935 | |
| 936 | 936 | // http://doc.spip.org/@spip_pg_replace |
| 937 | -function spip_pg_replace($table, $values, $desc, $serveur='',$requeter=true) { |
|
| 938 | - if (!$values) {spip_log("replace vide $table",'pg.'._LOG_AVERTISSEMENT); return 0;} |
|
| 937 | +function spip_pg_replace($table, $values, $desc, $serveur = '', $requeter = true) { |
|
| 938 | + if (!$values) {spip_log("replace vide $table", 'pg.'._LOG_AVERTISSEMENT); return 0; } |
|
| 939 | 939 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 940 | 940 | $prefixe = $connexion['prefixe']; |
| 941 | 941 | $link = $connexion['link']; |
@@ -946,12 +946,12 @@ discard block |
||
| 946 | 946 | $prim = $desc['key']['PRIMARY KEY']; |
| 947 | 947 | $ids = preg_split('/,\s*/', $prim); |
| 948 | 948 | $noprims = $prims = array(); |
| 949 | - foreach($values as $k=>$v) { |
|
| 949 | + foreach ($values as $k=>$v) { |
|
| 950 | 950 | $values[$k] = $v = spip_pg_cite($v, $desc['field'][$k]); |
| 951 | 951 | |
| 952 | 952 | if (!in_array($k, $ids)) |
| 953 | - $noprims[$k]= "$k=$v"; |
|
| 954 | - else $prims[$k]= "$k=$v"; |
|
| 953 | + $noprims[$k] = "$k=$v"; |
|
| 954 | + else $prims[$k] = "$k=$v"; |
|
| 955 | 955 | } |
| 956 | 956 | |
| 957 | 957 | // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
@@ -959,7 +959,7 @@ discard block |
||
| 959 | 959 | |
| 960 | 960 | $where = join(' AND ', $prims); |
| 961 | 961 | if (!$where) { |
| 962 | - return spip_pg_insert($table, "(".join(',',array_keys($values)).")", "(".join(',', $values).")", $desc, $serveur); |
|
| 962 | + return spip_pg_insert($table, "(".join(',', array_keys($values)).")", "(".join(',', $values).")", $desc, $serveur); |
|
| 963 | 963 | } |
| 964 | 964 | $couples = join(',', $noprims); |
| 965 | 965 | |
@@ -977,9 +977,8 @@ discard block |
||
| 977 | 977 | $couples = pg_affected_rows($couples); |
| 978 | 978 | } |
| 979 | 979 | if (!$couples) { |
| 980 | - $ret = !$seq ? '' : |
|
| 981 | - (" RETURNING nextval('$seq') < $prim"); |
|
| 982 | - $connexion['last'] = $q = "INSERT INTO $table (" . join(',',array_keys($values)) . ') VALUES (' .join(',', $values) . ")$ret"; |
|
| 980 | + $ret = !$seq ? '' : (" RETURNING nextval('$seq') < $prim"); |
|
| 981 | + $connexion['last'] = $q = "INSERT INTO $table (".join(',', array_keys($values)).') VALUES ('.join(',', $values).")$ret"; |
|
| 983 | 982 | $couples = spip_pg_query_simple($link, $q); |
| 984 | 983 | if (!$couples) { |
| 985 | 984 | return false; |
@@ -999,10 +998,10 @@ discard block |
||
| 999 | 998 | |
| 1000 | 999 | |
| 1001 | 1000 | // http://doc.spip.org/@spip_pg_replace_multi |
| 1002 | -function spip_pg_replace_multi($table, $tab_couples, $desc=array(), $serveur='',$requeter=true) { |
|
| 1001 | +function spip_pg_replace_multi($table, $tab_couples, $desc = array(), $serveur = '', $requeter = true) { |
|
| 1003 | 1002 | // boucler pour traiter chaque requete independemment |
| 1004 | - foreach ($tab_couples as $couples){ |
|
| 1005 | - $retour = spip_pg_replace($table, $couples, $desc, $serveur,$requeter); |
|
| 1003 | + foreach ($tab_couples as $couples) { |
|
| 1004 | + $retour = spip_pg_replace($table, $couples, $desc, $serveur, $requeter); |
|
| 1006 | 1005 | } |
| 1007 | 1006 | // renvoie le dernier id |
| 1008 | 1007 | return $retour; |
@@ -1014,7 +1013,7 @@ discard block |
||
| 1014 | 1013 | // Pas extensible pour le moment, |
| 1015 | 1014 | |
| 1016 | 1015 | // http://doc.spip.org/@spip_pg_sequence |
| 1017 | -function spip_pg_sequence($table,$raw=false) |
|
| 1016 | +function spip_pg_sequence($table, $raw = false) |
|
| 1018 | 1017 | { |
| 1019 | 1018 | global $tables_principales; |
| 1020 | 1019 | include_spip('base/serial'); |
@@ -1024,33 +1023,33 @@ discard block |
||
| 1024 | 1023 | if (!preg_match('/^\w+$/', $prim) |
| 1025 | 1024 | OR strpos($desc['field'][$prim], 'int') === false) |
| 1026 | 1025 | return ''; |
| 1027 | - else { return $raw?$prim:$table . '_' . $prim . "_seq";} |
|
| 1026 | + else { return $raw ? $prim : $table.'_'.$prim."_seq"; } |
|
| 1028 | 1027 | } |
| 1029 | 1028 | |
| 1030 | 1029 | // Explicite les conversions de Mysql d'une valeur $v de type $t |
| 1031 | 1030 | // Dans le cas d'un champ date, pas d'apostrophe, c'est une syntaxe ad hoc |
| 1032 | 1031 | |
| 1033 | 1032 | // http://doc.spip.org/@spip_pg_cite |
| 1034 | -function spip_pg_cite($v, $t){ |
|
| 1035 | - if(is_null($v)) return 'NULL'; // null php se traduit en NULL SQL |
|
| 1033 | +function spip_pg_cite($v, $t) { |
|
| 1034 | + if (is_null($v)) return 'NULL'; // null php se traduit en NULL SQL |
|
| 1036 | 1035 | |
| 1037 | 1036 | if (sql_test_date($t)) { |
| 1038 | 1037 | if ($v AND (strpos("0123456789", $v[0]) === false)) |
| 1039 | 1038 | return spip_pg_frommysql($v); |
| 1040 | 1039 | else { |
| 1041 | - if (strncmp($v,'0000',4)==0) |
|
| 1042 | - $v = "0001" . substr($v,4); |
|
| 1040 | + if (strncmp($v, '0000', 4) == 0) |
|
| 1041 | + $v = "0001".substr($v, 4); |
|
| 1043 | 1042 | if (strpos($v, "-00-00") === 4) |
| 1044 | - $v = substr($v,0,4)."-01-01".substr($v,10); |
|
| 1043 | + $v = substr($v, 0, 4)."-01-01".substr($v, 10); |
|
| 1045 | 1044 | return "timestamp '$v'"; |
| 1046 | 1045 | } |
| 1047 | 1046 | } |
| 1048 | 1047 | elseif (!sql_test_int($t)) |
| 1049 | - return ("'" . pg_escape_string($v) . "'"); |
|
| 1048 | + return ("'".pg_escape_string($v)."'"); |
|
| 1050 | 1049 | elseif (is_numeric($v) OR (strpos($v, 'CAST(') === 0)) |
| 1051 | 1050 | return $v; |
| 1052 | - elseif ($v[0]== '0' AND $v[1]!=='x' AND ctype_xdigit(substr($v,1))) |
|
| 1053 | - return substr($v,1); |
|
| 1051 | + elseif ($v[0] == '0' AND $v[1] !== 'x' AND ctype_xdigit(substr($v, 1))) |
|
| 1052 | + return substr($v, 1); |
|
| 1054 | 1053 | else { |
| 1055 | 1054 | spip_log("Warning: '$v' n'est pas de type $t", 'pg.'._LOG_AVERTISSEMENT); |
| 1056 | 1055 | return intval($v); |
@@ -1060,15 +1059,15 @@ discard block |
||
| 1060 | 1059 | // http://doc.spip.org/@spip_pg_hex |
| 1061 | 1060 | function spip_pg_hex($v) |
| 1062 | 1061 | { |
| 1063 | - return "CAST(x'" . $v . "' as bigint)"; |
|
| 1062 | + return "CAST(x'".$v."' as bigint)"; |
|
| 1064 | 1063 | } |
| 1065 | 1064 | |
| 1066 | -function spip_pg_quote($v, $type='') |
|
| 1065 | +function spip_pg_quote($v, $type = '') |
|
| 1067 | 1066 | { |
| 1068 | 1067 | if (!is_array($v)) |
| 1069 | - return spip_pg_cite($v,$type); |
|
| 1068 | + return spip_pg_cite($v, $type); |
|
| 1070 | 1069 | // si c'est un tableau, le parcourir en propageant le type |
| 1071 | - foreach($v as $k=>$r) |
|
| 1070 | + foreach ($v as $k=>$r) |
|
| 1072 | 1071 | $v[$k] = spip_pg_quote($r, $type); |
| 1073 | 1072 | return join(",", $v); |
| 1074 | 1073 | } |
@@ -1082,30 +1081,30 @@ discard block |
||
| 1082 | 1081 | . '(' |
| 1083 | 1082 | . sql_quote(date('Y-m-d H:i:s')) |
| 1084 | 1083 | . ', INTERVAL ' |
| 1085 | - . (($interval > 0) ? $interval : (0-$interval)) |
|
| 1084 | + . (($interval > 0) ? $interval : (0 - $interval)) |
|
| 1086 | 1085 | . ' ' |
| 1087 | 1086 | . $unite |
| 1088 | 1087 | . '))'; |
| 1089 | 1088 | } |
| 1090 | 1089 | |
| 1091 | 1090 | // http://doc.spip.org/@spip_pg_in |
| 1092 | -function spip_pg_in($val, $valeurs, $not='', $serveur) { |
|
| 1091 | +function spip_pg_in($val, $valeurs, $not = '', $serveur) { |
|
| 1093 | 1092 | // |
| 1094 | 1093 | // IN (...) souvent limite a 255 elements, d'ou cette fonction assistante |
| 1095 | 1094 | // |
| 1096 | 1095 | // s'il n'y a pas de valeur, eviter de produire un IN vide: PG rale. |
| 1097 | 1096 | if (!$valeurs) return $not ? '0=0' : '0=1'; |
| 1098 | 1097 | if (strpos($valeurs, "CAST(x'") !== false) |
| 1099 | - return "($val=" . join("OR $val=", explode(',',$valeurs)).')'; |
|
| 1098 | + return "($val=".join("OR $val=", explode(',', $valeurs)).')'; |
|
| 1100 | 1099 | $n = $i = 0; |
| 1101 | - $in_sql =""; |
|
| 1102 | - while ($n = strpos($valeurs, ',', $n+1)) { |
|
| 1100 | + $in_sql = ""; |
|
| 1101 | + while ($n = strpos($valeurs, ',', $n + 1)) { |
|
| 1103 | 1102 | if ((++$i) >= 255) { |
| 1104 | - $in_sql .= "($val $not IN (" . |
|
| 1105 | - substr($valeurs, 0, $n) . |
|
| 1106 | - "))\n" . |
|
| 1103 | + $in_sql .= "($val $not IN (". |
|
| 1104 | + substr($valeurs, 0, $n). |
|
| 1105 | + "))\n". |
|
| 1107 | 1106 | ($not ? "AND\t" : "OR\t"); |
| 1108 | - $valeurs = substr($valeurs, $n+1); |
|
| 1107 | + $valeurs = substr($valeurs, $n + 1); |
|
| 1109 | 1108 | $i = $n = 0; |
| 1110 | 1109 | } |
| 1111 | 1110 | } |
@@ -1115,7 +1114,7 @@ discard block |
||
| 1115 | 1114 | } |
| 1116 | 1115 | |
| 1117 | 1116 | // http://doc.spip.org/@spip_pg_error |
| 1118 | -function spip_pg_error($query='', $serveur, $requeter=true) { |
|
| 1117 | +function spip_pg_error($query = '', $serveur, $requeter = true) { |
|
| 1119 | 1118 | $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
| 1120 | 1119 | $s = $link ? pg_last_error($link) : pg_last_error(); |
| 1121 | 1120 | if ($s) { |
@@ -1126,16 +1125,16 @@ discard block |
||
| 1126 | 1125 | } |
| 1127 | 1126 | |
| 1128 | 1127 | // http://doc.spip.org/@spip_pg_errno |
| 1129 | -function spip_pg_errno($serveur='') { |
|
| 1128 | +function spip_pg_errno($serveur = '') { |
|
| 1130 | 1129 | // il faudrait avoir la derniere ressource retournee et utiliser |
| 1131 | 1130 | // http://fr2.php.net/manual/fr/function.pg-result-error.php |
| 1132 | 1131 | return 0; |
| 1133 | 1132 | } |
| 1134 | 1133 | |
| 1135 | 1134 | // http://doc.spip.org/@spip_pg_drop_table |
| 1136 | -function spip_pg_drop_table($table, $exist='', $serveur='',$requeter=true) |
|
| 1135 | +function spip_pg_drop_table($table, $exist = '', $serveur = '', $requeter = true) |
|
| 1137 | 1136 | { |
| 1138 | - if ($exist) $exist =" IF EXISTS"; |
|
| 1137 | + if ($exist) $exist = " IF EXISTS"; |
|
| 1139 | 1138 | if (spip_pg_query("DROP TABLE$exist $table", $serveur, $requeter)) |
| 1140 | 1139 | return true; |
| 1141 | 1140 | else return false; |
@@ -1143,8 +1142,8 @@ discard block |
||
| 1143 | 1142 | |
| 1144 | 1143 | // supprime une vue |
| 1145 | 1144 | // http://doc.spip.org/@spip_pg_drop_view |
| 1146 | -function spip_pg_drop_view($view, $exist='', $serveur='',$requeter=true) { |
|
| 1147 | - if ($exist) $exist =" IF EXISTS"; |
|
| 1145 | +function spip_pg_drop_view($view, $exist = '', $serveur = '', $requeter = true) { |
|
| 1146 | + if ($exist) $exist = " IF EXISTS"; |
|
| 1148 | 1147 | return spip_pg_query("DROP VIEW$exist $view", $serveur, $requeter); |
| 1149 | 1148 | } |
| 1150 | 1149 | |
@@ -1161,7 +1160,7 @@ discard block |
||
| 1161 | 1160 | * @return ressource |
| 1162 | 1161 | * Ressource à utiliser avec sql_fetch() |
| 1163 | 1162 | **/ |
| 1164 | -function spip_pg_showbase($match, $serveur='',$requeter=true) |
|
| 1163 | +function spip_pg_showbase($match, $serveur = '', $requeter = true) |
|
| 1165 | 1164 | { |
| 1166 | 1165 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 1167 | 1166 | $link = $connexion['link']; |
@@ -1170,11 +1169,11 @@ discard block |
||
| 1170 | 1169 | } |
| 1171 | 1170 | |
| 1172 | 1171 | // http://doc.spip.org/@spip_pg_showtable |
| 1173 | -function spip_pg_showtable($nom_table, $serveur='',$requeter=true) |
|
| 1172 | +function spip_pg_showtable($nom_table, $serveur = '', $requeter = true) |
|
| 1174 | 1173 | { |
| 1175 | 1174 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 1176 | 1175 | $link = $connexion['link']; |
| 1177 | - $connexion['last'] = $q = "SELECT column_name, column_default, data_type FROM information_schema.columns WHERE table_name ILIKE " . _q($nom_table); |
|
| 1176 | + $connexion['last'] = $q = "SELECT column_name, column_default, data_type FROM information_schema.columns WHERE table_name ILIKE "._q($nom_table); |
|
| 1178 | 1177 | |
| 1179 | 1178 | $res = spip_pg_query_simple($link, $q); |
| 1180 | 1179 | if (!$res) return false; |
@@ -1182,16 +1181,16 @@ discard block |
||
| 1182 | 1181 | // etrangement, $res peut ne rien contenir, mais arriver ici... |
| 1183 | 1182 | // il faut en tenir compte dans le return |
| 1184 | 1183 | $fields = array(); |
| 1185 | - while($field = pg_fetch_array($res, NULL, PGSQL_NUM)) { |
|
| 1186 | - $fields[$field[0]] = $field[2] . (!$field[1] ? '' : (" DEFAULT " . $field[1])); |
|
| 1184 | + while ($field = pg_fetch_array($res, NULL, PGSQL_NUM)) { |
|
| 1185 | + $fields[$field[0]] = $field[2].(!$field[1] ? '' : (" DEFAULT ".$field[1])); |
|
| 1187 | 1186 | } |
| 1188 | - $connexion['last'] = $q = "SELECT indexdef FROM pg_indexes WHERE tablename ILIKE " . _q($nom_table); |
|
| 1187 | + $connexion['last'] = $q = "SELECT indexdef FROM pg_indexes WHERE tablename ILIKE "._q($nom_table); |
|
| 1189 | 1188 | $res = spip_pg_query_simple($link, $q); |
| 1190 | 1189 | $keys = array(); |
| 1191 | - while($index = pg_fetch_array($res, NULL, PGSQL_NUM)) { |
|
| 1192 | - if (preg_match('/CREATE\s+(UNIQUE\s+)?INDEX\s([^\s]+).*\((.*)\)$/', $index[0],$r)) { |
|
| 1193 | - $nom = str_replace($nom_table.'_','',$r[2]); |
|
| 1194 | - $keys[($r[1] ? "PRIMARY KEY" : ("KEY " . $nom))] = $r[3]; |
|
| 1190 | + while ($index = pg_fetch_array($res, NULL, PGSQL_NUM)) { |
|
| 1191 | + if (preg_match('/CREATE\s+(UNIQUE\s+)?INDEX\s([^\s]+).*\((.*)\)$/', $index[0], $r)) { |
|
| 1192 | + $nom = str_replace($nom_table.'_', '', $r[2]); |
|
| 1193 | + $keys[($r[1] ? "PRIMARY KEY" : ("KEY ".$nom))] = $r[3]; |
|
| 1195 | 1194 | } |
| 1196 | 1195 | } |
| 1197 | 1196 | |
@@ -1205,14 +1204,14 @@ discard block |
||
| 1205 | 1204 | // si $autoinc, c'est une auto-increment (i.e. serial) sur la Primary Key |
| 1206 | 1205 | // Le nom des index est prefixe par celui de la table pour eviter les conflits |
| 1207 | 1206 | // http://doc.spip.org/@spip_pg_create |
| 1208 | -function spip_pg_create($nom, $champs, $cles, $autoinc=false, $temporary=false, $serveur='',$requeter=true) { |
|
| 1207 | +function spip_pg_create($nom, $champs, $cles, $autoinc = false, $temporary = false, $serveur = '', $requeter = true) { |
|
| 1209 | 1208 | |
| 1210 | 1209 | $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 1211 | 1210 | $prefixe = $connexion['prefixe']; |
| 1212 | 1211 | $link = $connexion['link']; |
| 1213 | 1212 | $db = $connexion['db']; |
| 1214 | 1213 | if ($prefixe) $nom = preg_replace('/^spip/', $prefixe, $nom); |
| 1215 | - $query = $prim = $prim_name = $v = $s = $p=''; |
|
| 1214 | + $query = $prim = $prim_name = $v = $s = $p = ''; |
|
| 1216 | 1215 | $keys = array(); |
| 1217 | 1216 | |
| 1218 | 1217 | // certains plugins declarent les tables (permet leur inclusion dans le dump) |
@@ -1220,20 +1219,20 @@ discard block |
||
| 1220 | 1219 | if (!is_array($champs) || !is_array($cles)) |
| 1221 | 1220 | return; |
| 1222 | 1221 | |
| 1223 | - foreach($cles as $k => $v) { |
|
| 1222 | + foreach ($cles as $k => $v) { |
|
| 1224 | 1223 | if (strpos($k, "KEY ") === 0) { |
| 1225 | - $n = str_replace('`','',$k); |
|
| 1226 | - $v = str_replace('`','"',$v); |
|
| 1227 | - $i = $nom . preg_replace("/KEY +/", '_',$n); |
|
| 1224 | + $n = str_replace('`', '', $k); |
|
| 1225 | + $v = str_replace('`', '"', $v); |
|
| 1226 | + $i = $nom.preg_replace("/KEY +/", '_', $n); |
|
| 1228 | 1227 | if ($k != $n) $i = "\"$i\""; |
| 1229 | 1228 | $keys[] = "CREATE INDEX $i ON $nom ($v);"; |
| 1230 | 1229 | } |
| 1231 | 1230 | elseif (strpos($k, "UNIQUE ") === 0) { |
| 1232 | - $k = preg_replace("/^UNIQUE +/", '',$k); |
|
| 1233 | - $prim .= "$s\n\t\tCONSTRAINT " . str_replace('`','"',$k) ." UNIQUE ($v)"; |
|
| 1231 | + $k = preg_replace("/^UNIQUE +/", '', $k); |
|
| 1232 | + $prim .= "$s\n\t\tCONSTRAINT ".str_replace('`', '"', $k)." UNIQUE ($v)"; |
|
| 1234 | 1233 | } |
| 1235 | 1234 | else { |
| 1236 | - $prim .= "$s\n\t\t" . str_replace('`','"',$k) ." ($v)"; |
|
| 1235 | + $prim .= "$s\n\t\t".str_replace('`', '"', $k)." ($v)"; |
|
| 1237 | 1236 | } |
| 1238 | 1237 | if ($k == "PRIMARY KEY") |
| 1239 | 1238 | $prim_name = $v; |
@@ -1247,11 +1246,11 @@ discard block |
||
| 1247 | 1246 | if (@$GLOBALS['meta']['charset_collation_sql_base']) |
| 1248 | 1247 | $character_set .= " COLLATE ".$GLOBALS['meta']['charset_collation_sql_base']; |
| 1249 | 1248 | |
| 1250 | - foreach($champs as $k => $v) { |
|
| 1251 | - $k = str_replace('`','"',$k); |
|
| 1252 | - if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i',$v,$defs)){ |
|
| 1253 | - if (preg_match(',(char|text),i',$defs[1]) AND !preg_match(',binary,i',$defs[1]) ){ |
|
| 1254 | - $v = $defs[1] . $character_set . ' ' . substr($v,strlen($defs[1])); |
|
| 1249 | + foreach ($champs as $k => $v) { |
|
| 1250 | + $k = str_replace('`', '"', $k); |
|
| 1251 | + if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) { |
|
| 1252 | + if (preg_match(',(char|text),i', $defs[1]) AND !preg_match(',binary,i', $defs[1])) { |
|
| 1253 | + $v = $defs[1].$character_set.' '.substr($v, strlen($defs[1])); |
|
| 1255 | 1254 | } |
| 1256 | 1255 | } |
| 1257 | 1256 | |
@@ -1262,12 +1261,12 @@ discard block |
||
| 1262 | 1261 | ); |
| 1263 | 1262 | $s = ","; |
| 1264 | 1263 | } |
| 1265 | - $temporary = $temporary ? 'TEMPORARY':''; |
|
| 1264 | + $temporary = $temporary ? 'TEMPORARY' : ''; |
|
| 1266 | 1265 | |
| 1267 | 1266 | // En l'absence de "if not exists" en PG, on neutralise les erreurs |
| 1268 | 1267 | |
| 1269 | - $q = "CREATE $temporary TABLE $nom ($query" . ($prim ? ",$prim" : '') . ")". |
|
| 1270 | - ($character_set?" DEFAULT $character_set":"") |
|
| 1268 | + $q = "CREATE $temporary TABLE $nom ($query".($prim ? ",$prim" : '').")". |
|
| 1269 | + ($character_set ? " DEFAULT $character_set" : "") |
|
| 1271 | 1270 | ."\n"; |
| 1272 | 1271 | |
| 1273 | 1272 | if (!$requeter) return $q; |
@@ -1275,36 +1274,36 @@ discard block |
||
| 1275 | 1274 | $r = @pg_query($link, $q); |
| 1276 | 1275 | |
| 1277 | 1276 | if (!$r) |
| 1278 | - spip_log("Impossible de creer cette table: $q",'pg.'._LOG_ERREUR); |
|
| 1277 | + spip_log("Impossible de creer cette table: $q", 'pg.'._LOG_ERREUR); |
|
| 1279 | 1278 | else { |
| 1280 | - foreach($keys as $index) {pg_query($link, $index);} |
|
| 1279 | + foreach ($keys as $index) {pg_query($link, $index); } |
|
| 1281 | 1280 | } |
| 1282 | 1281 | return $r; |
| 1283 | 1282 | } |
| 1284 | 1283 | |
| 1285 | 1284 | |
| 1286 | -function spip_pg_create_base($nom, $serveur='',$requeter=true) { |
|
| 1285 | +function spip_pg_create_base($nom, $serveur = '', $requeter = true) { |
|
| 1287 | 1286 | return spip_pg_query("CREATE DATABASE $nom", $serveur, $requeter); |
| 1288 | 1287 | } |
| 1289 | 1288 | |
| 1290 | 1289 | // Fonction de creation d'une vue SQL nommee $nom |
| 1291 | 1290 | // http://doc.spip.org/@spip_pg_create_view |
| 1292 | -function spip_pg_create_view($nom, $query_select, $serveur='',$requeter=true) { |
|
| 1291 | +function spip_pg_create_view($nom, $query_select, $serveur = '', $requeter = true) { |
|
| 1293 | 1292 | if (!$query_select) return false; |
| 1294 | 1293 | // vue deja presente |
| 1295 | 1294 | if (sql_showtable($nom, false, $serveur)) { |
| 1296 | - if ($requeter) spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)",'pg.'._LOG_ERREUR); |
|
| 1295 | + if ($requeter) spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", 'pg.'._LOG_ERREUR); |
|
| 1297 | 1296 | return false; |
| 1298 | 1297 | } |
| 1299 | 1298 | |
| 1300 | - $query = "CREATE VIEW $nom AS ". $query_select; |
|
| 1299 | + $query = "CREATE VIEW $nom AS ".$query_select; |
|
| 1301 | 1300 | return spip_pg_query($query, $serveur, $requeter); |
| 1302 | 1301 | } |
| 1303 | 1302 | |
| 1304 | 1303 | |
| 1305 | 1304 | // http://doc.spip.org/@spip_pg_set_connect_charset |
| 1306 | -function spip_pg_set_connect_charset($charset, $serveur='',$requeter=true){ |
|
| 1307 | - spip_log("changement de charset sql a ecrire en PG",'pg.'._LOG_ERREUR); |
|
| 1305 | +function spip_pg_set_connect_charset($charset, $serveur = '', $requeter = true) { |
|
| 1306 | + spip_log("changement de charset sql a ecrire en PG", 'pg.'._LOG_ERREUR); |
|
| 1308 | 1307 | } |
| 1309 | 1308 | |
| 1310 | 1309 | |
@@ -1317,15 +1316,15 @@ discard block |
||
| 1317 | 1316 | * @return bool|string true / false / requete |
| 1318 | 1317 | **/ |
| 1319 | 1318 | // http://doc.spip.org/@spip_sqlite_optimize |
| 1320 | -function spip_pg_optimize($table, $serveur='',$requeter=true){ |
|
| 1321 | - return spip_pg_query("VACUUM ". $table, $serveur, $requeter); |
|
| 1319 | +function spip_pg_optimize($table, $serveur = '', $requeter = true) { |
|
| 1320 | + return spip_pg_query("VACUUM ".$table, $serveur, $requeter); |
|
| 1322 | 1321 | } |
| 1323 | 1322 | |
| 1324 | 1323 | // Selectionner la sous-chaine dans $objet |
| 1325 | 1324 | // correspondant a $lang. Cf balise Multi de Spip |
| 1326 | 1325 | |
| 1327 | 1326 | // http://doc.spip.org/@spip_pg_multi |
| 1328 | -function spip_pg_multi ($objet, $lang) { |
|
| 1327 | +function spip_pg_multi($objet, $lang) { |
|
| 1329 | 1328 | $r = "regexp_replace(" |
| 1330 | 1329 | . $objet |
| 1331 | 1330 | . ",'<multi>.*[[]" |
@@ -1338,7 +1337,7 @@ discard block |
||
| 1338 | 1337 | // A completer par les autres, mais essayer de reduire en amont. |
| 1339 | 1338 | |
| 1340 | 1339 | // http://doc.spip.org/@mysql2pg_type |
| 1341 | -function mysql2pg_type($v){ |
|
| 1340 | +function mysql2pg_type($v) { |
|
| 1342 | 1341 | $remplace = array( |
| 1343 | 1342 | '/auto_increment/i' => '', // non reconnu |
| 1344 | 1343 | '/bigint/i' => 'bigint', |
@@ -1359,12 +1358,12 @@ discard block |
||
| 1359 | 1358 | '/(timestamp .* )ON .*$/is' => '\\1', |
| 1360 | 1359 | ); |
| 1361 | 1360 | |
| 1362 | - return preg_replace(array_keys($remplace),array_values($remplace),$v); |
|
| 1361 | + return preg_replace(array_keys($remplace), array_values($remplace), $v); |
|
| 1363 | 1362 | } |
| 1364 | 1363 | |
| 1365 | 1364 | // Renvoie false si on n'a pas les fonctions pg (pour l'install) |
| 1366 | 1365 | // http://doc.spip.org/@spip_versions_pg |
| 1367 | -function spip_versions_pg(){ |
|
| 1366 | +function spip_versions_pg() { |
|
| 1368 | 1367 | charger_php_extension('pgsql'); |
| 1369 | 1368 | return function_exists('pg_connect'); |
| 1370 | 1369 | } |