@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | include_spip('inc/actions'); |
@@ -31,17 +31,17 @@ discard block |
||
| 31 | 31 | * @uses ajax_retour() |
| 32 | 32 | **/ |
| 33 | 33 | function exec_rechercher_dist() { |
| 34 | - $id = intval(_request('id')); |
|
| 35 | - $exclus = intval(_request('exclus')); |
|
| 36 | - $rac = spip_htmlentities(_request('rac')); |
|
| 37 | - $type = _request('type'); |
|
| 38 | - $do = _request('do'); |
|
| 39 | - if (preg_match('/^\w*$/', $do)) { |
|
| 40 | - $r = exec_rechercher_args($id, $type, $exclus, $rac, $do); |
|
| 41 | - } else { |
|
| 42 | - $r = ''; |
|
| 43 | - } |
|
| 44 | - ajax_retour($r); |
|
| 34 | + $id = intval(_request('id')); |
|
| 35 | + $exclus = intval(_request('exclus')); |
|
| 36 | + $rac = spip_htmlentities(_request('rac')); |
|
| 37 | + $type = _request('type'); |
|
| 38 | + $do = _request('do'); |
|
| 39 | + if (preg_match('/^\w*$/', $do)) { |
|
| 40 | + $r = exec_rechercher_args($id, $type, $exclus, $rac, $do); |
|
| 41 | + } else { |
|
| 42 | + $r = ''; |
|
| 43 | + } |
|
| 44 | + ajax_retour($r); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -58,59 +58,59 @@ discard block |
||
| 58 | 58 | * @return string |
| 59 | 59 | **/ |
| 60 | 60 | function exec_rechercher_args($id, $type, $exclus, $rac, $do) { |
| 61 | - if (!$do) { |
|
| 62 | - $do = 'aff'; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - $points = $rub = array(); |
|
| 66 | - |
|
| 67 | - $where = preg_split(",\s+,", $type); |
|
| 68 | - if ($where) { |
|
| 69 | - foreach ($where as $k => $v) { |
|
| 70 | - $where[$k] = "'%" . substr(str_replace("%", "\%", sql_quote($v, '', 'string')), 1, -1) . "%'"; |
|
| 71 | - } |
|
| 72 | - $where_titre = ("(titre LIKE " . join(" AND titre LIKE ", $where) . ")"); |
|
| 73 | - $where_desc = ("(descriptif LIKE " . join(" AND descriptif LIKE ", $where) . ")"); |
|
| 74 | - $where_id = ("(id_rubrique = " . intval($type) . ")"); |
|
| 75 | - |
|
| 76 | - if ($exclus) { |
|
| 77 | - include_spip('inc/rubriques'); |
|
| 78 | - $where_exclus = " AND " . sql_in('id_rubrique', calcul_branche_in($exclus), 'NOT'); |
|
| 79 | - } else { |
|
| 80 | - $where_exclus = ''; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - foreach (array( |
|
| 84 | - 3 => $where_titre, |
|
| 85 | - 2 => $where_desc, |
|
| 86 | - 1 => $where_id, |
|
| 87 | - ) as $point => $recherche) { |
|
| 88 | - $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$recherche$where_exclus"); |
|
| 89 | - while ($row = sql_fetch($res)) { |
|
| 90 | - $id_rubrique = $row["id_rubrique"]; |
|
| 91 | - if (!isset($rub[$id_rubrique])) { |
|
| 92 | - $rub[$id_rubrique] = array(); |
|
| 93 | - } |
|
| 94 | - $rub[$id_rubrique]["titre"] = typo($row["titre"]); |
|
| 95 | - $rub[$id_rubrique]["id_parent"] = $row["id_parent"]; |
|
| 96 | - if (!isset($points[$id_rubrique])) { |
|
| 97 | - $points[$id_rubrique] = 0; |
|
| 98 | - } |
|
| 99 | - $points[$id_rubrique] = $points[$id_rubrique] + $point; |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - if ($points) { |
|
| 105 | - arsort($points); |
|
| 106 | - $style = " style='background-image: url(" . chemin_image('secteur-12.png') . ")'"; |
|
| 107 | - foreach ($rub as $k => $v) { |
|
| 108 | - $rub[$k]['atts'] = ($v["id_parent"] ? $style : '') |
|
| 109 | - . " class='petite-rubrique'"; |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - return (proposer_item($points, $rub, $rac, $type, $do)); |
|
| 61 | + if (!$do) { |
|
| 62 | + $do = 'aff'; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + $points = $rub = array(); |
|
| 66 | + |
|
| 67 | + $where = preg_split(",\s+,", $type); |
|
| 68 | + if ($where) { |
|
| 69 | + foreach ($where as $k => $v) { |
|
| 70 | + $where[$k] = "'%" . substr(str_replace("%", "\%", sql_quote($v, '', 'string')), 1, -1) . "%'"; |
|
| 71 | + } |
|
| 72 | + $where_titre = ("(titre LIKE " . join(" AND titre LIKE ", $where) . ")"); |
|
| 73 | + $where_desc = ("(descriptif LIKE " . join(" AND descriptif LIKE ", $where) . ")"); |
|
| 74 | + $where_id = ("(id_rubrique = " . intval($type) . ")"); |
|
| 75 | + |
|
| 76 | + if ($exclus) { |
|
| 77 | + include_spip('inc/rubriques'); |
|
| 78 | + $where_exclus = " AND " . sql_in('id_rubrique', calcul_branche_in($exclus), 'NOT'); |
|
| 79 | + } else { |
|
| 80 | + $where_exclus = ''; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + foreach (array( |
|
| 84 | + 3 => $where_titre, |
|
| 85 | + 2 => $where_desc, |
|
| 86 | + 1 => $where_id, |
|
| 87 | + ) as $point => $recherche) { |
|
| 88 | + $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$recherche$where_exclus"); |
|
| 89 | + while ($row = sql_fetch($res)) { |
|
| 90 | + $id_rubrique = $row["id_rubrique"]; |
|
| 91 | + if (!isset($rub[$id_rubrique])) { |
|
| 92 | + $rub[$id_rubrique] = array(); |
|
| 93 | + } |
|
| 94 | + $rub[$id_rubrique]["titre"] = typo($row["titre"]); |
|
| 95 | + $rub[$id_rubrique]["id_parent"] = $row["id_parent"]; |
|
| 96 | + if (!isset($points[$id_rubrique])) { |
|
| 97 | + $points[$id_rubrique] = 0; |
|
| 98 | + } |
|
| 99 | + $points[$id_rubrique] = $points[$id_rubrique] + $point; |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + if ($points) { |
|
| 105 | + arsort($points); |
|
| 106 | + $style = " style='background-image: url(" . chemin_image('secteur-12.png') . ")'"; |
|
| 107 | + foreach ($rub as $k => $v) { |
|
| 108 | + $rub[$k]['atts'] = ($v["id_parent"] ? $style : '') |
|
| 109 | + . " class='petite-rubrique'"; |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + return (proposer_item($points, $rub, $rac, $type, $do)); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | |
@@ -133,35 +133,35 @@ discard block |
||
| 133 | 133 | **/ |
| 134 | 134 | function proposer_item($ids, $titles, $rac, $type, $do) { |
| 135 | 135 | |
| 136 | - if (!$ids) { |
|
| 137 | - return "<br /><br /><div style='padding: 5px; color: red;'><b>" |
|
| 138 | - . spip_htmlentities($type) |
|
| 139 | - . "</b> : " . _T('avis_aucun_resultat') . "</div>"; |
|
| 140 | - } |
|
| 136 | + if (!$ids) { |
|
| 137 | + return "<br /><br /><div style='padding: 5px; color: red;'><b>" |
|
| 138 | + . spip_htmlentities($type) |
|
| 139 | + . "</b> : " . _T('avis_aucun_resultat') . "</div>"; |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - $ret = ''; |
|
| 143 | - $info = generer_url_ecrire('informer', "type=rubrique&rac=$rac&id="); |
|
| 142 | + $ret = ''; |
|
| 143 | + $info = generer_url_ecrire('informer', "type=rubrique&rac=$rac&id="); |
|
| 144 | 144 | |
| 145 | - $onClick = "aff_selection(this.firstChild.title,'$rac" . "_selection','$info', event)"; |
|
| 145 | + $onClick = "aff_selection(this.firstChild.title,'$rac" . "_selection','$info', event)"; |
|
| 146 | 146 | |
| 147 | - $ondbClick = "$do(this.firstChild.firstChild.nodeValue,this.firstChild.title,'selection_rubrique', 'id_parent');"; |
|
| 147 | + $ondbClick = "$do(this.firstChild.firstChild.nodeValue,this.firstChild.title,'selection_rubrique', 'id_parent');"; |
|
| 148 | 148 | |
| 149 | - foreach ($ids as $id => $bof) { |
|
| 149 | + foreach ($ids as $id => $bof) { |
|
| 150 | 150 | |
| 151 | - $titre = strtr(str_replace("'", "’", str_replace('"', """, textebrut($titles[$id]["titre"]))), "\n\r", |
|
| 152 | - " "); |
|
| 151 | + $titre = strtr(str_replace("'", "’", str_replace('"', """, textebrut($titles[$id]["titre"]))), "\n\r", |
|
| 152 | + " "); |
|
| 153 | 153 | |
| 154 | - $ret .= "<div class='highlight off'\nonclick=\"changerhighlight(this); " |
|
| 155 | - . $onClick |
|
| 156 | - . "\"\nondblclick=\"" |
|
| 157 | - . $ondbClick |
|
| 158 | - . $onClick |
|
| 159 | - . " \"><div" |
|
| 160 | - . $titles[$id]["atts"] |
|
| 161 | - . " title='$id'> " |
|
| 162 | - . $titre |
|
| 163 | - . "</div></div>"; |
|
| 164 | - } |
|
| 154 | + $ret .= "<div class='highlight off'\nonclick=\"changerhighlight(this); " |
|
| 155 | + . $onClick |
|
| 156 | + . "\"\nondblclick=\"" |
|
| 157 | + . $ondbClick |
|
| 158 | + . $onClick |
|
| 159 | + . " \"><div" |
|
| 160 | + . $titles[$id]["atts"] |
|
| 161 | + . " title='$id'> " |
|
| 162 | + . $titre |
|
| 163 | + . "</div></div>"; |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - return $ret; |
|
| 166 | + return $ret; |
|
| 167 | 167 | } |
@@ -67,15 +67,15 @@ discard block |
||
| 67 | 67 | $where = preg_split(",\s+,", $type); |
| 68 | 68 | if ($where) { |
| 69 | 69 | foreach ($where as $k => $v) { |
| 70 | - $where[$k] = "'%" . substr(str_replace("%", "\%", sql_quote($v, '', 'string')), 1, -1) . "%'"; |
|
| 70 | + $where[$k] = "'%".substr(str_replace("%", "\%", sql_quote($v, '', 'string')), 1, -1)."%'"; |
|
| 71 | 71 | } |
| 72 | - $where_titre = ("(titre LIKE " . join(" AND titre LIKE ", $where) . ")"); |
|
| 73 | - $where_desc = ("(descriptif LIKE " . join(" AND descriptif LIKE ", $where) . ")"); |
|
| 74 | - $where_id = ("(id_rubrique = " . intval($type) . ")"); |
|
| 72 | + $where_titre = ("(titre LIKE ".join(" AND titre LIKE ", $where).")"); |
|
| 73 | + $where_desc = ("(descriptif LIKE ".join(" AND descriptif LIKE ", $where).")"); |
|
| 74 | + $where_id = ("(id_rubrique = ".intval($type).")"); |
|
| 75 | 75 | |
| 76 | 76 | if ($exclus) { |
| 77 | 77 | include_spip('inc/rubriques'); |
| 78 | - $where_exclus = " AND " . sql_in('id_rubrique', calcul_branche_in($exclus), 'NOT'); |
|
| 78 | + $where_exclus = " AND ".sql_in('id_rubrique', calcul_branche_in($exclus), 'NOT'); |
|
| 79 | 79 | } else { |
| 80 | 80 | $where_exclus = ''; |
| 81 | 81 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | |
| 104 | 104 | if ($points) { |
| 105 | 105 | arsort($points); |
| 106 | - $style = " style='background-image: url(" . chemin_image('secteur-12.png') . ")'"; |
|
| 106 | + $style = " style='background-image: url(".chemin_image('secteur-12.png').")'"; |
|
| 107 | 107 | foreach ($rub as $k => $v) { |
| 108 | 108 | $rub[$k]['atts'] = ($v["id_parent"] ? $style : '') |
| 109 | 109 | . " class='petite-rubrique'"; |
@@ -136,13 +136,13 @@ discard block |
||
| 136 | 136 | if (!$ids) { |
| 137 | 137 | return "<br /><br /><div style='padding: 5px; color: red;'><b>" |
| 138 | 138 | . spip_htmlentities($type) |
| 139 | - . "</b> : " . _T('avis_aucun_resultat') . "</div>"; |
|
| 139 | + . "</b> : "._T('avis_aucun_resultat')."</div>"; |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | $ret = ''; |
| 143 | 143 | $info = generer_url_ecrire('informer', "type=rubrique&rac=$rac&id="); |
| 144 | 144 | |
| 145 | - $onClick = "aff_selection(this.firstChild.title,'$rac" . "_selection','$info', event)"; |
|
| 145 | + $onClick = "aff_selection(this.firstChild.title,'$rac"."_selection','$info', event)"; |
|
| 146 | 146 | |
| 147 | 147 | $ondbClick = "$do(this.firstChild.firstChild.nodeValue,this.firstChild.title,'selection_rubrique', 'id_parent');"; |
| 148 | 148 | |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | |
| 25 | 25 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 26 | - return; |
|
| 26 | + return; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | |
@@ -31,24 +31,24 @@ discard block |
||
| 31 | 31 | * Réparer la base de données |
| 32 | 32 | */ |
| 33 | 33 | function exec_base_repair_dist() { |
| 34 | - $ok = false; |
|
| 35 | - if (!spip_connect()) { |
|
| 36 | - $message = _T('titre_probleme_technique'); |
|
| 37 | - } else { |
|
| 38 | - $version_sql = sql_version(); |
|
| 39 | - if (!$version_sql) { |
|
| 40 | - $message = _T('avis_erreur_connexion_mysql'); |
|
| 41 | - } else { |
|
| 42 | - $message = _T('texte_requetes_echouent'); |
|
| 43 | - $ok = true; |
|
| 44 | - } |
|
| 45 | - $action = _T('texte_tenter_reparation'); |
|
| 46 | - } |
|
| 47 | - if ($ok) { |
|
| 48 | - $admin = charger_fonction('admin', 'inc'); |
|
| 49 | - echo $admin('repair', $action, $message, true); |
|
| 50 | - } else { |
|
| 51 | - include_spip('inc/minipres'); |
|
| 52 | - echo minipres(_T('titre_reparation'), "<p>$message</p>"); |
|
| 53 | - } |
|
| 34 | + $ok = false; |
|
| 35 | + if (!spip_connect()) { |
|
| 36 | + $message = _T('titre_probleme_technique'); |
|
| 37 | + } else { |
|
| 38 | + $version_sql = sql_version(); |
|
| 39 | + if (!$version_sql) { |
|
| 40 | + $message = _T('avis_erreur_connexion_mysql'); |
|
| 41 | + } else { |
|
| 42 | + $message = _T('texte_requetes_echouent'); |
|
| 43 | + $ok = true; |
|
| 44 | + } |
|
| 45 | + $action = _T('texte_tenter_reparation'); |
|
| 46 | + } |
|
| 47 | + if ($ok) { |
|
| 48 | + $admin = charger_fonction('admin', 'inc'); |
|
| 49 | + echo $admin('repair', $action, $message, true); |
|
| 50 | + } else { |
|
| 51 | + include_spip('inc/minipres'); |
|
| 52 | + echo minipres(_T('titre_reparation'), "<p>$message</p>"); |
|
| 53 | + } |
|
| 54 | 54 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | |
| 23 | 23 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 24 | - return; |
|
| 24 | + return; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | |
@@ -29,15 +29,15 @@ discard block |
||
| 29 | 29 | $GLOBALS['delais'] = 0;// pas de cache ! |
| 30 | 30 | // Securite |
| 31 | 31 | if (strstr($fond, '/')) { |
| 32 | - if (!include_spip('inc/autoriser') |
|
| 33 | - or !autoriser('webmestre') |
|
| 34 | - ) { |
|
| 35 | - include_spip('inc/minipres'); |
|
| 36 | - echo minipres(); |
|
| 37 | - exit; |
|
| 38 | - } |
|
| 32 | + if (!include_spip('inc/autoriser') |
|
| 33 | + or !autoriser('webmestre') |
|
| 34 | + ) { |
|
| 35 | + include_spip('inc/minipres'); |
|
| 36 | + echo minipres(); |
|
| 37 | + exit; |
|
| 38 | + } |
|
| 39 | 39 | } else { |
| 40 | - $fond = "prive/squelettes/$fond"; |
|
| 40 | + $fond = "prive/squelettes/$fond"; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | // quelques inclusions et ini prealables |
@@ -49,8 +49,8 @@ discard block |
||
| 49 | 49 | * @todo supprimer cette fonction vide ? |
| 50 | 50 | **/ |
| 51 | 51 | function shutdown_error() { |
| 52 | - // si on arrive ici avec un tampon non ferme : erreur fatale |
|
| 53 | - /* if (ob_get_level()){ |
|
| 52 | + // si on arrive ici avec un tampon non ferme : erreur fatale |
|
| 53 | + /* if (ob_get_level()){ |
|
| 54 | 54 | // envoyer tous les tampons |
| 55 | 55 | while (ob_get_level()) |
| 56 | 56 | ob_end_flush(); |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | |
| 27 | 27 | |
| 28 | 28 | $fond = _request('exec'); |
| 29 | -$GLOBALS['delais'] = 0;// pas de cache ! |
|
| 29 | +$GLOBALS['delais'] = 0; // pas de cache ! |
|
| 30 | 30 | // Securite |
| 31 | 31 | if (strstr($fond, '/')) { |
| 32 | 32 | if (!include_spip('inc/autoriser') |
@@ -139,11 +139,11 @@ discard block |
||
| 139 | 139 | if ($quoi !== 'actifs') { |
| 140 | 140 | $lpf = liste_plugin_files(); |
| 141 | 141 | if ($lpf) { |
| 142 | - echo "<p>" . _T('texte_presente_plugin') . "</p>"; |
|
| 142 | + echo "<p>"._T('texte_presente_plugin')."</p>"; |
|
| 143 | 143 | } else { |
| 144 | 144 | if (!@is_dir(_DIR_PLUGINS)) { |
| 145 | - echo "<p>" . _T('plugin_info_automatique_ftp', array('rep' => joli_repertoire(_DIR_PLUGINS))) |
|
| 146 | - . " — " . _T('plugin_info_automatique_creer') . "</p>"; |
|
| 145 | + echo "<p>"._T('plugin_info_automatique_ftp', array('rep' => joli_repertoire(_DIR_PLUGINS))) |
|
| 146 | + . " — "._T('plugin_info_automatique_creer')."</p>"; |
|
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | $lcpaffiche = $lpf; |
@@ -164,8 +164,8 @@ discard block |
||
| 164 | 164 | if (defined('_DIR_PLUGINS_SUPPL')) { |
| 165 | 165 | $nb += count($lcpas); |
| 166 | 166 | } |
| 167 | - echo "<h3>" . sinon(singulier_ou_pluriel($nb, 'plugins_actif_un', 'plugins_actifs', 'count'), |
|
| 168 | - _T('plugins_actif_aucun')) . "</h3>"; |
|
| 167 | + echo "<h3>".sinon(singulier_ou_pluriel($nb, 'plugins_actif_un', 'plugins_actifs', 'count'), |
|
| 168 | + _T('plugins_actif_aucun'))."</h3>"; |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | if (empty($format)) { |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | |
| 183 | 183 | if ($corps) { |
| 184 | 184 | $corps .= "\n<div class='boutons' style='display:none;'>" |
| 185 | - . "<input type='submit' class='submit save' value='" . _T('bouton_enregistrer') |
|
| 185 | + . "<input type='submit' class='submit save' value='"._T('bouton_enregistrer') |
|
| 186 | 186 | . "' />" |
| 187 | 187 | . "</div>"; |
| 188 | 188 | } |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | . debut_cadre_trait_couleur('', true, '', _T('plugins_liste_dist'), 'liste_plugins_dist') |
| 256 | 256 | . "<p>" |
| 257 | 257 | . _T('plugin_info_plugins_dist_1', array('plugins_dist' => joli_repertoire(_DIR_PLUGINS_DIST))) |
| 258 | - . '<br />' . _T('plugin_info_plugins_dist_2') |
|
| 258 | + . '<br />'._T('plugin_info_plugins_dist_2') |
|
| 259 | 259 | . "</p>" |
| 260 | 260 | . $liste |
| 261 | 261 | . fin_cadre_trait_couleur(true) |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | $res = debut_cadre_enfonce('', true, '', _T('plugin_librairies_installees')); |
| 279 | 279 | $res .= '<dl>'; |
| 280 | 280 | foreach ($libs as $lib => $rep) { |
| 281 | - $res .= "<dt>$lib</dt><dd>" . joli_repertoire($rep) . "</dd>\n"; |
|
| 281 | + $res .= "<dt>$lib</dt><dd>".joli_repertoire($rep)."</dd>\n"; |
|
| 282 | 282 | } |
| 283 | 283 | $res .= '</dl>'; |
| 284 | 284 | $res .= fin_cadre_enfonce(true); |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | function liste_librairies() { |
| 297 | 297 | $libs = array(); |
| 298 | 298 | foreach (array_reverse(creer_chemin()) as $d) { |
| 299 | - if (is_dir($dir = $d . 'lib/') |
|
| 299 | + if (is_dir($dir = $d.'lib/') |
|
| 300 | 300 | and $t = opendir($dir) |
| 301 | 301 | ) { |
| 302 | 302 | while (($f = readdir($t)) !== false) { |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/config'); |
@@ -37,26 +37,26 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | function exec_admin_plugin_dist($retour = '') { |
| 39 | 39 | |
| 40 | - if (!autoriser('configurer', '_plugins')) { |
|
| 41 | - include_spip('inc/minipres'); |
|
| 42 | - echo minipres(); |
|
| 43 | - } else { |
|
| 44 | - // on fait la verif du path avant tout, |
|
| 45 | - // et l'installation des qu'on est dans la colonne principale |
|
| 46 | - // si jamais la liste des plugins actifs change, il faut faire un refresh du hit |
|
| 47 | - // pour etre sur que les bons fichiers seront charges lors de l'install |
|
| 48 | - $new = actualise_plugins_actifs(); |
|
| 49 | - if ($new and _request('actualise') < 2) { |
|
| 50 | - include_spip('inc/headers'); |
|
| 51 | - if (isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 52 | - // attendre eventuellement l'invalidation du cache opcode |
|
| 53 | - spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']); |
|
| 54 | - } |
|
| 55 | - redirige_par_entete(parametre_url(self(), 'actualise', _request('actualise') + 1, '&')); |
|
| 56 | - } else { |
|
| 57 | - admin_plug_args(_request('voir'), _request('erreur'), _request('format')); |
|
| 58 | - } |
|
| 59 | - } |
|
| 40 | + if (!autoriser('configurer', '_plugins')) { |
|
| 41 | + include_spip('inc/minipres'); |
|
| 42 | + echo minipres(); |
|
| 43 | + } else { |
|
| 44 | + // on fait la verif du path avant tout, |
|
| 45 | + // et l'installation des qu'on est dans la colonne principale |
|
| 46 | + // si jamais la liste des plugins actifs change, il faut faire un refresh du hit |
|
| 47 | + // pour etre sur que les bons fichiers seront charges lors de l'install |
|
| 48 | + $new = actualise_plugins_actifs(); |
|
| 49 | + if ($new and _request('actualise') < 2) { |
|
| 50 | + include_spip('inc/headers'); |
|
| 51 | + if (isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 52 | + // attendre eventuellement l'invalidation du cache opcode |
|
| 53 | + spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']); |
|
| 54 | + } |
|
| 55 | + redirige_par_entete(parametre_url(self(), 'actualise', _request('actualise') + 1, '&')); |
|
| 56 | + } else { |
|
| 57 | + admin_plug_args(_request('voir'), _request('erreur'), _request('format')); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -81,126 +81,126 @@ discard block |
||
| 81 | 81 | * Format d'affichage (liste ou arborescence) |
| 82 | 82 | **/ |
| 83 | 83 | function admin_plug_args($quoi, $erreur, $format) { |
| 84 | - if (!$quoi) { |
|
| 85 | - $quoi = 'actifs'; |
|
| 86 | - } |
|
| 87 | - // empecher l'affichage des erreurs dans le bandeau, on le donne ensuite |
|
| 88 | - // format brut par plugin |
|
| 89 | - $GLOBALS['erreurs_activation_raw'] = plugin_donne_erreurs(true, false); |
|
| 90 | - // format resume mis en forme |
|
| 91 | - $erreur_activation = plugin_donne_erreurs(); |
|
| 92 | - $commencer_page = charger_fonction('commencer_page', 'inc'); |
|
| 93 | - echo $commencer_page(_T('icone_admin_plugin'), "configuration", "plugin"); |
|
| 94 | - |
|
| 95 | - echo debut_gauche('plugin', true); |
|
| 96 | - echo recuperer_fond('prive/squelettes/navigation/configurer', array('exec' => 'admin_plugin')); |
|
| 97 | - |
|
| 98 | - echo pipeline('affiche_gauche', |
|
| 99 | - array( |
|
| 100 | - 'args' => array('exec' => 'admin_plugin'), |
|
| 101 | - 'data' => afficher_librairies() |
|
| 102 | - ) |
|
| 103 | - ); |
|
| 104 | - |
|
| 105 | - echo debut_droite('plugin', true); |
|
| 106 | - echo gros_titre(_T('icone_admin_plugin'), '', false); |
|
| 107 | - |
|
| 108 | - // Barre d'onglets de premier niveau |
|
| 109 | - echo barre_onglets("plugins", "plugins_actifs"); |
|
| 110 | - // Barre d'onglets de second niveau |
|
| 111 | - $onglet2 = $quoi == 'actifs' ? 'plugins_actifs' : 'admin_plugin'; |
|
| 112 | - echo debut_onglet('onglets_simple second'); |
|
| 113 | - echo onglet(_T('plugins_tous_liste'), generer_url_ecrire("admin_plugin", "voir=tous"), 'admin_plugin', $onglet2); |
|
| 114 | - echo onglet(_T('plugins_actifs_liste'), generer_url_ecrire("admin_plugin"), 'plugins_actifs', $onglet2); |
|
| 115 | - echo fin_onglet(); |
|
| 116 | - |
|
| 117 | - // message d'erreur au retour d'une operation |
|
| 118 | - if ($erreur) { |
|
| 119 | - echo "<div class='error'>$erreur</div>"; |
|
| 120 | - } |
|
| 121 | - if ($erreur_activation) { |
|
| 122 | - echo "<div class='error'>$erreur_activation</div>"; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - // la mise a jour de cette meta a ete faite par ecrire_plugin_actifs |
|
| 126 | - $actifs = unserialize($GLOBALS['meta']['plugin']); |
|
| 127 | - $lcpa = $actifs + unserialize($GLOBALS['meta']['plugin_attente']); |
|
| 128 | - |
|
| 129 | - // Les affichages se basent sur le repertoire, pas sur le nom |
|
| 130 | - $actifs = liste_chemin_plugin($actifs, ''); |
|
| 131 | - if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 132 | - $lcpas = liste_chemin_plugin($lcpa, _DIR_PLUGINS_SUPPL); |
|
| 133 | - } |
|
| 134 | - $lcpa = liste_chemin_plugin($lcpa); |
|
| 135 | - |
|
| 136 | - // on installe les plugins maintenant, |
|
| 137 | - // cela permet aux scripts d'install de faire des affichages (moches...) |
|
| 138 | - plugin_installes_meta(); |
|
| 139 | - |
|
| 140 | - echo "<div class='liste-plugins formulaire_spip'>"; |
|
| 141 | - echo debut_cadre_trait_couleur('plugin-24.png', true, '', _T('plugins_liste'), 'plugins'); |
|
| 142 | - |
|
| 143 | - if ($quoi !== 'actifs') { |
|
| 144 | - $lpf = liste_plugin_files(); |
|
| 145 | - if ($lpf) { |
|
| 146 | - echo "<p>" . _T('texte_presente_plugin') . "</p>"; |
|
| 147 | - } else { |
|
| 148 | - if (!@is_dir(_DIR_PLUGINS)) { |
|
| 149 | - echo "<p>" . _T('plugin_info_automatique_ftp', array('rep' => joli_repertoire(_DIR_PLUGINS))) |
|
| 150 | - . " — " . _T('plugin_info_automatique_creer') . "</p>"; |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - $lcpaffiche = $lpf; |
|
| 154 | - if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 155 | - $lcpaffichesup = liste_plugin_files(_DIR_PLUGINS_SUPPL); |
|
| 156 | - } |
|
| 157 | - } else { |
|
| 158 | - // la liste |
|
| 159 | - // $quoi=='actifs' |
|
| 160 | - $lcpaffiche = $lcpa; |
|
| 161 | - if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 162 | - $lcpaffichesup = $lcpas; |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - if ($quoi == 'actifs' or $lpf) { |
|
| 167 | - $nb = count($lcpa); |
|
| 168 | - if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 169 | - $nb += count($lcpas); |
|
| 170 | - } |
|
| 171 | - echo "<h3>" . sinon(singulier_ou_pluriel($nb, 'plugins_actif_un', 'plugins_actifs', 'count'), |
|
| 172 | - _T('plugins_actif_aucun')) . "</h3>"; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - if (empty($format)) { |
|
| 176 | - $format = 'liste'; |
|
| 177 | - } elseif (!in_array($format, array('liste', 'repertoires'))) { |
|
| 178 | - $format = 'repertoires'; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - $afficher = charger_fonction("afficher_$format", 'plugins'); |
|
| 182 | - $corps = $afficher(self(), $lcpaffiche, $lcpa, $actifs); |
|
| 183 | - if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 184 | - $corps .= $afficher(self(), $lcpaffichesup, $lcpas, $actifs, _DIR_PLUGINS_SUPPL); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - if ($corps) { |
|
| 188 | - $corps .= "\n<div class='boutons' style='display:none;'>" |
|
| 189 | - . "<input type='submit' class='submit save' value='" . _T('bouton_enregistrer') |
|
| 190 | - . "' />" |
|
| 191 | - . "</div>"; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - echo redirige_action_post('activer_plugins', 'activer', 'admin_plugin', '', $corps); |
|
| 195 | - |
|
| 196 | - echo fin_cadre_trait_couleur(true); |
|
| 197 | - |
|
| 198 | - if ($quoi == 'actifs') { |
|
| 199 | - echo affiche_les_plugins_verrouilles($actifs); |
|
| 200 | - } |
|
| 201 | - echo "</div>"; |
|
| 202 | - |
|
| 203 | - echo http_script(" |
|
| 84 | + if (!$quoi) { |
|
| 85 | + $quoi = 'actifs'; |
|
| 86 | + } |
|
| 87 | + // empecher l'affichage des erreurs dans le bandeau, on le donne ensuite |
|
| 88 | + // format brut par plugin |
|
| 89 | + $GLOBALS['erreurs_activation_raw'] = plugin_donne_erreurs(true, false); |
|
| 90 | + // format resume mis en forme |
|
| 91 | + $erreur_activation = plugin_donne_erreurs(); |
|
| 92 | + $commencer_page = charger_fonction('commencer_page', 'inc'); |
|
| 93 | + echo $commencer_page(_T('icone_admin_plugin'), "configuration", "plugin"); |
|
| 94 | + |
|
| 95 | + echo debut_gauche('plugin', true); |
|
| 96 | + echo recuperer_fond('prive/squelettes/navigation/configurer', array('exec' => 'admin_plugin')); |
|
| 97 | + |
|
| 98 | + echo pipeline('affiche_gauche', |
|
| 99 | + array( |
|
| 100 | + 'args' => array('exec' => 'admin_plugin'), |
|
| 101 | + 'data' => afficher_librairies() |
|
| 102 | + ) |
|
| 103 | + ); |
|
| 104 | + |
|
| 105 | + echo debut_droite('plugin', true); |
|
| 106 | + echo gros_titre(_T('icone_admin_plugin'), '', false); |
|
| 107 | + |
|
| 108 | + // Barre d'onglets de premier niveau |
|
| 109 | + echo barre_onglets("plugins", "plugins_actifs"); |
|
| 110 | + // Barre d'onglets de second niveau |
|
| 111 | + $onglet2 = $quoi == 'actifs' ? 'plugins_actifs' : 'admin_plugin'; |
|
| 112 | + echo debut_onglet('onglets_simple second'); |
|
| 113 | + echo onglet(_T('plugins_tous_liste'), generer_url_ecrire("admin_plugin", "voir=tous"), 'admin_plugin', $onglet2); |
|
| 114 | + echo onglet(_T('plugins_actifs_liste'), generer_url_ecrire("admin_plugin"), 'plugins_actifs', $onglet2); |
|
| 115 | + echo fin_onglet(); |
|
| 116 | + |
|
| 117 | + // message d'erreur au retour d'une operation |
|
| 118 | + if ($erreur) { |
|
| 119 | + echo "<div class='error'>$erreur</div>"; |
|
| 120 | + } |
|
| 121 | + if ($erreur_activation) { |
|
| 122 | + echo "<div class='error'>$erreur_activation</div>"; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + // la mise a jour de cette meta a ete faite par ecrire_plugin_actifs |
|
| 126 | + $actifs = unserialize($GLOBALS['meta']['plugin']); |
|
| 127 | + $lcpa = $actifs + unserialize($GLOBALS['meta']['plugin_attente']); |
|
| 128 | + |
|
| 129 | + // Les affichages se basent sur le repertoire, pas sur le nom |
|
| 130 | + $actifs = liste_chemin_plugin($actifs, ''); |
|
| 131 | + if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 132 | + $lcpas = liste_chemin_plugin($lcpa, _DIR_PLUGINS_SUPPL); |
|
| 133 | + } |
|
| 134 | + $lcpa = liste_chemin_plugin($lcpa); |
|
| 135 | + |
|
| 136 | + // on installe les plugins maintenant, |
|
| 137 | + // cela permet aux scripts d'install de faire des affichages (moches...) |
|
| 138 | + plugin_installes_meta(); |
|
| 139 | + |
|
| 140 | + echo "<div class='liste-plugins formulaire_spip'>"; |
|
| 141 | + echo debut_cadre_trait_couleur('plugin-24.png', true, '', _T('plugins_liste'), 'plugins'); |
|
| 142 | + |
|
| 143 | + if ($quoi !== 'actifs') { |
|
| 144 | + $lpf = liste_plugin_files(); |
|
| 145 | + if ($lpf) { |
|
| 146 | + echo "<p>" . _T('texte_presente_plugin') . "</p>"; |
|
| 147 | + } else { |
|
| 148 | + if (!@is_dir(_DIR_PLUGINS)) { |
|
| 149 | + echo "<p>" . _T('plugin_info_automatique_ftp', array('rep' => joli_repertoire(_DIR_PLUGINS))) |
|
| 150 | + . " — " . _T('plugin_info_automatique_creer') . "</p>"; |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + $lcpaffiche = $lpf; |
|
| 154 | + if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 155 | + $lcpaffichesup = liste_plugin_files(_DIR_PLUGINS_SUPPL); |
|
| 156 | + } |
|
| 157 | + } else { |
|
| 158 | + // la liste |
|
| 159 | + // $quoi=='actifs' |
|
| 160 | + $lcpaffiche = $lcpa; |
|
| 161 | + if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 162 | + $lcpaffichesup = $lcpas; |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + if ($quoi == 'actifs' or $lpf) { |
|
| 167 | + $nb = count($lcpa); |
|
| 168 | + if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 169 | + $nb += count($lcpas); |
|
| 170 | + } |
|
| 171 | + echo "<h3>" . sinon(singulier_ou_pluriel($nb, 'plugins_actif_un', 'plugins_actifs', 'count'), |
|
| 172 | + _T('plugins_actif_aucun')) . "</h3>"; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + if (empty($format)) { |
|
| 176 | + $format = 'liste'; |
|
| 177 | + } elseif (!in_array($format, array('liste', 'repertoires'))) { |
|
| 178 | + $format = 'repertoires'; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + $afficher = charger_fonction("afficher_$format", 'plugins'); |
|
| 182 | + $corps = $afficher(self(), $lcpaffiche, $lcpa, $actifs); |
|
| 183 | + if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 184 | + $corps .= $afficher(self(), $lcpaffichesup, $lcpas, $actifs, _DIR_PLUGINS_SUPPL); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + if ($corps) { |
|
| 188 | + $corps .= "\n<div class='boutons' style='display:none;'>" |
|
| 189 | + . "<input type='submit' class='submit save' value='" . _T('bouton_enregistrer') |
|
| 190 | + . "' />" |
|
| 191 | + . "</div>"; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + echo redirige_action_post('activer_plugins', 'activer', 'admin_plugin', '', $corps); |
|
| 195 | + |
|
| 196 | + echo fin_cadre_trait_couleur(true); |
|
| 197 | + |
|
| 198 | + if ($quoi == 'actifs') { |
|
| 199 | + echo affiche_les_plugins_verrouilles($actifs); |
|
| 200 | + } |
|
| 201 | + echo "</div>"; |
|
| 202 | + |
|
| 203 | + echo http_script(" |
|
| 204 | 204 | jQuery(function(){ |
| 205 | 205 | jQuery('.plugins li.item a[rel=info]').click(function(){ |
| 206 | 206 | var li = jQuery(this).parents('li').eq(0); |
@@ -226,14 +226,14 @@ discard block |
||
| 226 | 226 | }); |
| 227 | 227 | "); |
| 228 | 228 | |
| 229 | - echo pipeline('affiche_milieu', |
|
| 230 | - array( |
|
| 231 | - 'args' => array('exec' => 'admin_plugin'), |
|
| 232 | - 'data' => '' |
|
| 233 | - ) |
|
| 234 | - ); |
|
| 229 | + echo pipeline('affiche_milieu', |
|
| 230 | + array( |
|
| 231 | + 'args' => array('exec' => 'admin_plugin'), |
|
| 232 | + 'data' => '' |
|
| 233 | + ) |
|
| 234 | + ); |
|
| 235 | 235 | |
| 236 | - echo fin_gauche(), fin_page(); |
|
| 236 | + echo fin_gauche(), fin_page(); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -247,23 +247,23 @@ discard block |
||
| 247 | 247 | * Code HTML |
| 248 | 248 | **/ |
| 249 | 249 | function affiche_les_plugins_verrouilles($actifs) { |
| 250 | - if ((!$liste = liste_plugin_files(_DIR_PLUGINS_DIST))) { |
|
| 251 | - return ''; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - $afficher = charger_fonction("afficher_liste", 'plugins'); |
|
| 255 | - $liste = $afficher(self(), $liste, array(), $actifs, _DIR_PLUGINS_DIST); |
|
| 256 | - |
|
| 257 | - return |
|
| 258 | - "<div id='plugins_dist'>" |
|
| 259 | - . debut_cadre_trait_couleur('', true, '', _T('plugins_liste_dist'), 'liste_plugins_dist') |
|
| 260 | - . "<p>" |
|
| 261 | - . _T('plugin_info_plugins_dist_1', array('plugins_dist' => joli_repertoire(_DIR_PLUGINS_DIST))) |
|
| 262 | - . '<br />' . _T('plugin_info_plugins_dist_2') |
|
| 263 | - . "</p>" |
|
| 264 | - . $liste |
|
| 265 | - . fin_cadre_trait_couleur(true) |
|
| 266 | - . "</div>\n"; |
|
| 250 | + if ((!$liste = liste_plugin_files(_DIR_PLUGINS_DIST))) { |
|
| 251 | + return ''; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + $afficher = charger_fonction("afficher_liste", 'plugins'); |
|
| 255 | + $liste = $afficher(self(), $liste, array(), $actifs, _DIR_PLUGINS_DIST); |
|
| 256 | + |
|
| 257 | + return |
|
| 258 | + "<div id='plugins_dist'>" |
|
| 259 | + . debut_cadre_trait_couleur('', true, '', _T('plugins_liste_dist'), 'liste_plugins_dist') |
|
| 260 | + . "<p>" |
|
| 261 | + . _T('plugin_info_plugins_dist_1', array('plugins_dist' => joli_repertoire(_DIR_PLUGINS_DIST))) |
|
| 262 | + . '<br />' . _T('plugin_info_plugins_dist_2') |
|
| 263 | + . "</p>" |
|
| 264 | + . $liste |
|
| 265 | + . fin_cadre_trait_couleur(true) |
|
| 266 | + . "</div>\n"; |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | /** |
@@ -275,19 +275,19 @@ discard block |
||
| 275 | 275 | */ |
| 276 | 276 | function afficher_librairies() { |
| 277 | 277 | |
| 278 | - if (!$libs = liste_librairies()) { |
|
| 279 | - return ''; |
|
| 280 | - } |
|
| 281 | - ksort($libs); |
|
| 282 | - $res = debut_cadre_enfonce('', true, '', _T('plugin_librairies_installees')); |
|
| 283 | - $res .= '<dl>'; |
|
| 284 | - foreach ($libs as $lib => $rep) { |
|
| 285 | - $res .= "<dt>$lib</dt><dd>" . joli_repertoire($rep) . "</dd>\n"; |
|
| 286 | - } |
|
| 287 | - $res .= '</dl>'; |
|
| 288 | - $res .= fin_cadre_enfonce(true); |
|
| 289 | - |
|
| 290 | - return $res; |
|
| 278 | + if (!$libs = liste_librairies()) { |
|
| 279 | + return ''; |
|
| 280 | + } |
|
| 281 | + ksort($libs); |
|
| 282 | + $res = debut_cadre_enfonce('', true, '', _T('plugin_librairies_installees')); |
|
| 283 | + $res .= '<dl>'; |
|
| 284 | + foreach ($libs as $lib => $rep) { |
|
| 285 | + $res .= "<dt>$lib</dt><dd>" . joli_repertoire($rep) . "</dd>\n"; |
|
| 286 | + } |
|
| 287 | + $res .= '</dl>'; |
|
| 288 | + $res .= fin_cadre_enfonce(true); |
|
| 289 | + |
|
| 290 | + return $res; |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | |
@@ -298,20 +298,20 @@ discard block |
||
| 298 | 298 | * Tableau (nom de la lib => repertoire , ...) |
| 299 | 299 | */ |
| 300 | 300 | function liste_librairies() { |
| 301 | - $libs = array(); |
|
| 302 | - foreach (array_reverse(creer_chemin()) as $d) { |
|
| 303 | - if (is_dir($dir = $d . 'lib/') |
|
| 304 | - and $t = opendir($dir) |
|
| 305 | - ) { |
|
| 306 | - while (($f = readdir($t)) !== false) { |
|
| 307 | - if ($f[0] != '.' |
|
| 308 | - and is_dir("$dir/$f") |
|
| 309 | - ) { |
|
| 310 | - $libs[$f] = $dir; |
|
| 311 | - } |
|
| 312 | - } |
|
| 313 | - } |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - return $libs; |
|
| 301 | + $libs = array(); |
|
| 302 | + foreach (array_reverse(creer_chemin()) as $d) { |
|
| 303 | + if (is_dir($dir = $d . 'lib/') |
|
| 304 | + and $t = opendir($dir) |
|
| 305 | + ) { |
|
| 306 | + while (($f = readdir($t)) !== false) { |
|
| 307 | + if ($f[0] != '.' |
|
| 308 | + and is_dir("$dir/$f") |
|
| 309 | + ) { |
|
| 310 | + $libs[$f] = $dir; |
|
| 311 | + } |
|
| 312 | + } |
|
| 313 | + } |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + return $libs; |
|
| 317 | 317 | } |
@@ -92,10 +92,12 @@ |
||
| 92 | 92 | $store = &$_GET; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - foreach ($c as $k => $v) // on ecrase pas si saisi a nouveau ! |
|
| 95 | + foreach ($c as $k => $v) { |
|
| 96 | + // on ecrase pas si saisi a nouveau ! |
|
| 96 | 97 | { |
| 97 | 98 | if (!isset($store[$k])) { |
| 98 | 99 | $_REQUEST[$k] = $store[$k] = $v; |
| 100 | + } |
|
| 99 | 101 | } // mais si tableau des deux cotes, on merge avec priorite a la derniere saisie |
| 100 | 102 | elseif (is_array($store[$k]) |
| 101 | 103 | and is_array($v) |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | $erreurs_etapes = array(); |
| 230 | 230 | $derniere_etape_ok = 0; |
| 231 | 231 | $e = 0; |
| 232 | - while ($e < max($etape, $etape_demandee -1) and $e < $etapes) { |
|
| 232 | + while ($e < max($etape, $etape_demandee - 1) and $e < $etapes) { |
|
| 233 | 233 | $e++; |
| 234 | 234 | $erreurs_etapes[$e] = array(); |
| 235 | 235 | if ($verifier = charger_fonction("verifier_$e", "formulaires/$form/", true)) { |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | // si la derniere etape OK etait la derniere |
| 268 | 268 | // on renvoie le flux inchange et ca declenche traiter |
| 269 | 269 | if ($derniere_etape_ok == $etapes |
| 270 | - and (!$etape_demandee or $etape_demandee>=$etapes)) { |
|
| 270 | + and (!$etape_demandee or $etape_demandee >= $etapes)) { |
|
| 271 | 271 | return $erreurs; |
| 272 | 272 | } else { |
| 273 | 273 | $etape = $derniere_etape_ok + 1; |
@@ -309,9 +309,9 @@ discard block |
||
| 309 | 309 | and ($e = $flux['args']['contexte']['_etape']) > 1 |
| 310 | 310 | and $ext = $flux['args']['ext'] |
| 311 | 311 | and $f = $flux['data'] |
| 312 | - and file_exists($f . "_$e.$ext") |
|
| 312 | + and file_exists($f."_$e.$ext") |
|
| 313 | 313 | ) { |
| 314 | - $flux['data'] = $f . "_$e"; |
|
| 314 | + $flux['data'] = $f."_$e"; |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | return $flux; |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | |
| 68 | 68 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 69 | - return; |
|
| 69 | + return; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -77,45 +77,45 @@ discard block |
||
| 77 | 77 | * @return array |
| 78 | 78 | */ |
| 79 | 79 | function cvtmulti_recuperer_post_precedents($form) { |
| 80 | - include_spip('inc/filtres'); |
|
| 81 | - if ($form |
|
| 82 | - and $c = _request('cvtm_prev_post') |
|
| 83 | - and $c = decoder_contexte_ajax($c, $form) |
|
| 84 | - ) { |
|
| 85 | - #var_dump($c); |
|
| 80 | + include_spip('inc/filtres'); |
|
| 81 | + if ($form |
|
| 82 | + and $c = _request('cvtm_prev_post') |
|
| 83 | + and $c = decoder_contexte_ajax($c, $form) |
|
| 84 | + ) { |
|
| 85 | + #var_dump($c); |
|
| 86 | 86 | |
| 87 | - # reinjecter dans la bonne variable pour permettre de retrouver |
|
| 88 | - # toutes les saisies dans un seul tableau |
|
| 89 | - if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 90 | - $store = &$_POST; |
|
| 91 | - } else { |
|
| 92 | - $store = &$_GET; |
|
| 93 | - } |
|
| 87 | + # reinjecter dans la bonne variable pour permettre de retrouver |
|
| 88 | + # toutes les saisies dans un seul tableau |
|
| 89 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 90 | + $store = &$_POST; |
|
| 91 | + } else { |
|
| 92 | + $store = &$_GET; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - foreach ($c as $k => $v) // on ecrase pas si saisi a nouveau ! |
|
| 96 | - { |
|
| 97 | - if (!isset($store[$k])) { |
|
| 98 | - $_REQUEST[$k] = $store[$k] = $v; |
|
| 99 | - } // mais si tableau des deux cotes, on merge avec priorite a la derniere saisie |
|
| 100 | - elseif (is_array($store[$k]) |
|
| 101 | - and is_array($v) |
|
| 102 | - and $z = array_keys($v) |
|
| 103 | - and !is_numeric(reset($z)) |
|
| 104 | - and $z = array_keys($store[$k]) |
|
| 105 | - and !is_numeric(reset($z)) |
|
| 106 | - ) { |
|
| 107 | - $_REQUEST[$k] = $store[$k] = array_merge($v, $store[$k]); |
|
| 108 | - } |
|
| 109 | - } |
|
| 95 | + foreach ($c as $k => $v) // on ecrase pas si saisi a nouveau ! |
|
| 96 | + { |
|
| 97 | + if (!isset($store[$k])) { |
|
| 98 | + $_REQUEST[$k] = $store[$k] = $v; |
|
| 99 | + } // mais si tableau des deux cotes, on merge avec priorite a la derniere saisie |
|
| 100 | + elseif (is_array($store[$k]) |
|
| 101 | + and is_array($v) |
|
| 102 | + and $z = array_keys($v) |
|
| 103 | + and !is_numeric(reset($z)) |
|
| 104 | + and $z = array_keys($store[$k]) |
|
| 105 | + and !is_numeric(reset($z)) |
|
| 106 | + ) { |
|
| 107 | + $_REQUEST[$k] = $store[$k] = array_merge($v, $store[$k]); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - // vider pour eviter un second appel a verifier_n |
|
| 112 | - // en cas de double implementation (unipotence) |
|
| 113 | - set_request('cvtm_prev_post'); |
|
| 111 | + // vider pour eviter un second appel a verifier_n |
|
| 112 | + // en cas de double implementation (unipotence) |
|
| 113 | + set_request('cvtm_prev_post'); |
|
| 114 | 114 | |
| 115 | - return array($c['_etape'], $c['_etapes']); |
|
| 116 | - } |
|
| 115 | + return array($c['_etape'], $c['_etapes']); |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - return false; |
|
| 118 | + return false; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -128,28 +128,28 @@ discard block |
||
| 128 | 128 | * @return array |
| 129 | 129 | */ |
| 130 | 130 | function cvtmulti_sauver_post($form, $je_suis_poste, &$valeurs) { |
| 131 | - if (!isset($valeurs['_cvtm_prev_post'])) { |
|
| 132 | - $post = array('_etape' => $valeurs['_etape'], '_etapes' => $valeurs['_etapes']); |
|
| 133 | - foreach (array_keys($valeurs) as $champ) { |
|
| 134 | - if (substr($champ, 0, 1) !== '_') { |
|
| 135 | - if ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])) { |
|
| 136 | - if (($v = _request($champ)) !== null) { |
|
| 137 | - $post[$champ] = $v; |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - include_spip('inc/filtres'); |
|
| 143 | - $c = encoder_contexte_ajax($post, $form); |
|
| 144 | - if (!isset($valeurs['_hidden'])) { |
|
| 145 | - $valeurs['_hidden'] = ''; |
|
| 146 | - } |
|
| 147 | - $valeurs['_hidden'] .= "<input type='hidden' name='cvtm_prev_post' value='$c' />"; |
|
| 148 | - // marquer comme fait, pour eviter double encodage (unipotence) |
|
| 149 | - $valeurs['_cvtm_prev_post'] = true; |
|
| 150 | - } |
|
| 131 | + if (!isset($valeurs['_cvtm_prev_post'])) { |
|
| 132 | + $post = array('_etape' => $valeurs['_etape'], '_etapes' => $valeurs['_etapes']); |
|
| 133 | + foreach (array_keys($valeurs) as $champ) { |
|
| 134 | + if (substr($champ, 0, 1) !== '_') { |
|
| 135 | + if ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])) { |
|
| 136 | + if (($v = _request($champ)) !== null) { |
|
| 137 | + $post[$champ] = $v; |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + include_spip('inc/filtres'); |
|
| 143 | + $c = encoder_contexte_ajax($post, $form); |
|
| 144 | + if (!isset($valeurs['_hidden'])) { |
|
| 145 | + $valeurs['_hidden'] = ''; |
|
| 146 | + } |
|
| 147 | + $valeurs['_hidden'] .= "<input type='hidden' name='cvtm_prev_post' value='$c' />"; |
|
| 148 | + // marquer comme fait, pour eviter double encodage (unipotence) |
|
| 149 | + $valeurs['_cvtm_prev_post'] = true; |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - return $valeurs; |
|
| 152 | + return $valeurs; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | |
@@ -162,13 +162,13 @@ discard block |
||
| 162 | 162 | * @return array |
| 163 | 163 | */ |
| 164 | 164 | function cvtmulti_formulaire_charger($flux) { |
| 165 | - if (is_array($flux['data']) |
|
| 166 | - and isset($flux['data']['_etapes']) |
|
| 167 | - ) { |
|
| 168 | - $flux['data'] = cvtmulti_formulaire_charger_etapes($flux['args'], $flux['data']); |
|
| 169 | - } |
|
| 165 | + if (is_array($flux['data']) |
|
| 166 | + and isset($flux['data']['_etapes']) |
|
| 167 | + ) { |
|
| 168 | + $flux['data'] = cvtmulti_formulaire_charger_etapes($flux['args'], $flux['data']); |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - return $flux; |
|
| 171 | + return $flux; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -178,19 +178,19 @@ discard block |
||
| 178 | 178 | * @return array |
| 179 | 179 | */ |
| 180 | 180 | function cvtmulti_formulaire_charger_etapes($args, $valeurs) { |
| 181 | - if (!isset($valeurs['_etape'])) { |
|
| 182 | - $form = $args['form']; |
|
| 183 | - $je_suis_poste = $args['je_suis_poste']; |
|
| 184 | - $nb_etapes = $valeurs['_etapes']; |
|
| 185 | - $etape = _request('_etape'); |
|
| 186 | - $etape = min(max($etape, 1), $nb_etapes); |
|
| 187 | - set_request('_etape', $etape); |
|
| 188 | - $valeurs['_etape'] = $etape; |
|
| 181 | + if (!isset($valeurs['_etape'])) { |
|
| 182 | + $form = $args['form']; |
|
| 183 | + $je_suis_poste = $args['je_suis_poste']; |
|
| 184 | + $nb_etapes = $valeurs['_etapes']; |
|
| 185 | + $etape = _request('_etape'); |
|
| 186 | + $etape = min(max($etape, 1), $nb_etapes); |
|
| 187 | + set_request('_etape', $etape); |
|
| 188 | + $valeurs['_etape'] = $etape; |
|
| 189 | 189 | |
| 190 | - // sauver les posts de cette etape pour les avoir a la prochaine etape |
|
| 191 | - $valeurs = cvtmulti_sauver_post($form, $je_suis_poste, $valeurs); |
|
| 192 | - } |
|
| 193 | - return $valeurs; |
|
| 190 | + // sauver les posts de cette etape pour les avoir a la prochaine etape |
|
| 191 | + $valeurs = cvtmulti_sauver_post($form, $je_suis_poste, $valeurs); |
|
| 192 | + } |
|
| 193 | + return $valeurs; |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | |
@@ -202,8 +202,8 @@ discard block |
||
| 202 | 202 | * @return array |
| 203 | 203 | */ |
| 204 | 204 | function cvtmulti_formulaire_verifier($flux) { |
| 205 | - $flux['data'] = cvtmulti_formulaire_verifier_etapes($flux['args'], $flux['data']); |
|
| 206 | - return $flux; |
|
| 205 | + $flux['data'] = cvtmulti_formulaire_verifier_etapes($flux['args'], $flux['data']); |
|
| 206 | + return $flux; |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | /** |
@@ -214,84 +214,84 @@ discard block |
||
| 214 | 214 | * @return array |
| 215 | 215 | */ |
| 216 | 216 | function cvtmulti_formulaire_verifier_etapes($args, $erreurs) { |
| 217 | - #var_dump('Pipe verifier'); |
|
| 217 | + #var_dump('Pipe verifier'); |
|
| 218 | 218 | |
| 219 | - if ($form = $args['form'] |
|
| 220 | - and ($e = cvtmulti_recuperer_post_precedents($form)) !== false |
|
| 221 | - ) { |
|
| 222 | - // recuperer l'etape saisie et le nombre d'etapes total |
|
| 223 | - list($etape, $etapes) = $e; |
|
| 224 | - $etape_demandee = intval(_request('aller_a_etape')); // possibilite de poster un entier dans aller_a_etape |
|
| 219 | + if ($form = $args['form'] |
|
| 220 | + and ($e = cvtmulti_recuperer_post_precedents($form)) !== false |
|
| 221 | + ) { |
|
| 222 | + // recuperer l'etape saisie et le nombre d'etapes total |
|
| 223 | + list($etape, $etapes) = $e; |
|
| 224 | + $etape_demandee = intval(_request('aller_a_etape')); // possibilite de poster un entier dans aller_a_etape |
|
| 225 | 225 | |
| 226 | - $args['etape_saisie'] = $etape; |
|
| 227 | - $args['etapes'] = $etapes; |
|
| 228 | - // lancer les verifs pour chaque etape deja saisie de 1 a $etape |
|
| 229 | - $erreurs_etapes = array(); |
|
| 230 | - $derniere_etape_ok = 0; |
|
| 231 | - $e = 0; |
|
| 232 | - while ($e < max($etape, $etape_demandee -1) and $e < $etapes) { |
|
| 233 | - $e++; |
|
| 234 | - $erreurs_etapes[$e] = array(); |
|
| 235 | - if ($verifier = charger_fonction("verifier_$e", "formulaires/$form/", true)) { |
|
| 236 | - $erreurs_etapes[$e] = call_user_func_array($verifier, $args['args']); |
|
| 237 | - } elseif ($verifier = charger_fonction("verifier_etape", "formulaires/$form/", true)) { |
|
| 238 | - $a = $args['args']; |
|
| 239 | - array_unshift($a, $e); |
|
| 240 | - $erreurs_etapes[$e] = call_user_func_array($verifier, $a); |
|
| 241 | - } |
|
| 242 | - // et on appelle un pipeline dedie aux etapes, plus easy |
|
| 243 | - $args['etape'] = $e; |
|
| 244 | - $args['etape_demandee'] = $etape_demandee; |
|
| 245 | - $erreurs_etapes[$e] = pipeline( |
|
| 246 | - 'formulaire_verifier_etape', |
|
| 247 | - array( |
|
| 248 | - 'args' => $args, |
|
| 249 | - 'data' => $erreurs_etapes[$e] |
|
| 250 | - ) |
|
| 251 | - ); |
|
| 226 | + $args['etape_saisie'] = $etape; |
|
| 227 | + $args['etapes'] = $etapes; |
|
| 228 | + // lancer les verifs pour chaque etape deja saisie de 1 a $etape |
|
| 229 | + $erreurs_etapes = array(); |
|
| 230 | + $derniere_etape_ok = 0; |
|
| 231 | + $e = 0; |
|
| 232 | + while ($e < max($etape, $etape_demandee -1) and $e < $etapes) { |
|
| 233 | + $e++; |
|
| 234 | + $erreurs_etapes[$e] = array(); |
|
| 235 | + if ($verifier = charger_fonction("verifier_$e", "formulaires/$form/", true)) { |
|
| 236 | + $erreurs_etapes[$e] = call_user_func_array($verifier, $args['args']); |
|
| 237 | + } elseif ($verifier = charger_fonction("verifier_etape", "formulaires/$form/", true)) { |
|
| 238 | + $a = $args['args']; |
|
| 239 | + array_unshift($a, $e); |
|
| 240 | + $erreurs_etapes[$e] = call_user_func_array($verifier, $a); |
|
| 241 | + } |
|
| 242 | + // et on appelle un pipeline dedie aux etapes, plus easy |
|
| 243 | + $args['etape'] = $e; |
|
| 244 | + $args['etape_demandee'] = $etape_demandee; |
|
| 245 | + $erreurs_etapes[$e] = pipeline( |
|
| 246 | + 'formulaire_verifier_etape', |
|
| 247 | + array( |
|
| 248 | + 'args' => $args, |
|
| 249 | + 'data' => $erreurs_etapes[$e] |
|
| 250 | + ) |
|
| 251 | + ); |
|
| 252 | 252 | |
| 253 | - if ($derniere_etape_ok == $e - 1 and !count($erreurs_etapes[$e])) { |
|
| 254 | - $derniere_etape_ok = $e; |
|
| 255 | - } |
|
| 256 | - // possibilite de poster dans _retour_etape_x ou aller_a_etape |
|
| 257 | - if (!is_null(_request("_retour_etape_$e"))) { |
|
| 258 | - $etape_demandee = $e; |
|
| 259 | - } |
|
| 260 | - // Il se peut que les verifications ait décidé de faire sauter des étapes |
|
| 261 | - if ($aller_a_etape = intval(_request('aller_a_etape'))) { |
|
| 262 | - $etape_demandee = $aller_a_etape; // possibilite de poster un entier dans aller_a_etape |
|
| 263 | - } |
|
| 264 | - } |
|
| 253 | + if ($derniere_etape_ok == $e - 1 and !count($erreurs_etapes[$e])) { |
|
| 254 | + $derniere_etape_ok = $e; |
|
| 255 | + } |
|
| 256 | + // possibilite de poster dans _retour_etape_x ou aller_a_etape |
|
| 257 | + if (!is_null(_request("_retour_etape_$e"))) { |
|
| 258 | + $etape_demandee = $e; |
|
| 259 | + } |
|
| 260 | + // Il se peut que les verifications ait décidé de faire sauter des étapes |
|
| 261 | + if ($aller_a_etape = intval(_request('aller_a_etape'))) { |
|
| 262 | + $etape_demandee = $aller_a_etape; // possibilite de poster un entier dans aller_a_etape |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | 266 | |
| 267 | - // si la derniere etape OK etait la derniere |
|
| 268 | - // on renvoie le flux inchange et ca declenche traiter |
|
| 269 | - if ($derniere_etape_ok == $etapes |
|
| 270 | - and (!$etape_demandee or $etape_demandee>=$etapes)) { |
|
| 271 | - return $erreurs; |
|
| 272 | - } else { |
|
| 273 | - $etape = $derniere_etape_ok + 1; |
|
| 274 | - if ($etape_demandee > 0 and $etape_demandee < $etape) { |
|
| 275 | - $etape = $etape_demandee; |
|
| 276 | - } |
|
| 277 | - $etape = min($etape, $etapes); |
|
| 278 | - #var_dump("prochaine etape $etape"); |
|
| 279 | - // retourner les erreurs de l'etape ciblee |
|
| 280 | - $erreurs = isset($erreurs_etapes[$etape]) ? $erreurs_etapes[$etape] : array(); |
|
| 281 | - // Ne pas se tromper dans le texte du message d'erreur : la clé '_etapes' n'est pas une erreur ! |
|
| 282 | - if ($erreurs) { |
|
| 283 | - if (!isset($erreurs['message_erreur'])) { |
|
| 284 | - $erreurs['message_erreur'] = singulier_ou_pluriel(count($erreurs), 'avis_1_erreur_saisie', 'avis_nb_erreurs_saisie'); |
|
| 285 | - } |
|
| 286 | - } else { |
|
| 287 | - $erreurs['message_erreur'] = ''; |
|
| 288 | - } |
|
| 289 | - $erreurs['_etapes'] = "etape suivante $etape"; |
|
| 290 | - set_request('_etape', $etape); |
|
| 291 | - } |
|
| 292 | - } |
|
| 267 | + // si la derniere etape OK etait la derniere |
|
| 268 | + // on renvoie le flux inchange et ca declenche traiter |
|
| 269 | + if ($derniere_etape_ok == $etapes |
|
| 270 | + and (!$etape_demandee or $etape_demandee>=$etapes)) { |
|
| 271 | + return $erreurs; |
|
| 272 | + } else { |
|
| 273 | + $etape = $derniere_etape_ok + 1; |
|
| 274 | + if ($etape_demandee > 0 and $etape_demandee < $etape) { |
|
| 275 | + $etape = $etape_demandee; |
|
| 276 | + } |
|
| 277 | + $etape = min($etape, $etapes); |
|
| 278 | + #var_dump("prochaine etape $etape"); |
|
| 279 | + // retourner les erreurs de l'etape ciblee |
|
| 280 | + $erreurs = isset($erreurs_etapes[$etape]) ? $erreurs_etapes[$etape] : array(); |
|
| 281 | + // Ne pas se tromper dans le texte du message d'erreur : la clé '_etapes' n'est pas une erreur ! |
|
| 282 | + if ($erreurs) { |
|
| 283 | + if (!isset($erreurs['message_erreur'])) { |
|
| 284 | + $erreurs['message_erreur'] = singulier_ou_pluriel(count($erreurs), 'avis_1_erreur_saisie', 'avis_nb_erreurs_saisie'); |
|
| 285 | + } |
|
| 286 | + } else { |
|
| 287 | + $erreurs['message_erreur'] = ''; |
|
| 288 | + } |
|
| 289 | + $erreurs['_etapes'] = "etape suivante $etape"; |
|
| 290 | + set_request('_etape', $etape); |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | 293 | |
| 294 | - return $erreurs; |
|
| 294 | + return $erreurs; |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | /** |
@@ -303,16 +303,16 @@ discard block |
||
| 303 | 303 | * @return array |
| 304 | 304 | */ |
| 305 | 305 | function cvtmulti_styliser($flux) { |
| 306 | - if (strncmp($flux['args']['fond'], 'formulaires/', 12) == 0 |
|
| 307 | - and isset($flux['args']['contexte']['_etapes']) |
|
| 308 | - and isset($flux['args']['contexte']['_etape']) |
|
| 309 | - and ($e = $flux['args']['contexte']['_etape']) > 1 |
|
| 310 | - and $ext = $flux['args']['ext'] |
|
| 311 | - and $f = $flux['data'] |
|
| 312 | - and file_exists($f . "_$e.$ext") |
|
| 313 | - ) { |
|
| 314 | - $flux['data'] = $f . "_$e"; |
|
| 315 | - } |
|
| 306 | + if (strncmp($flux['args']['fond'], 'formulaires/', 12) == 0 |
|
| 307 | + and isset($flux['args']['contexte']['_etapes']) |
|
| 308 | + and isset($flux['args']['contexte']['_etape']) |
|
| 309 | + and ($e = $flux['args']['contexte']['_etape']) > 1 |
|
| 310 | + and $ext = $flux['args']['ext'] |
|
| 311 | + and $f = $flux['data'] |
|
| 312 | + and file_exists($f . "_$e.$ext") |
|
| 313 | + ) { |
|
| 314 | + $flux['data'] = $f . "_$e"; |
|
| 315 | + } |
|
| 316 | 316 | |
| 317 | - return $flux; |
|
| 317 | + return $flux; |
|
| 318 | 318 | } |
@@ -135,7 +135,7 @@ |
||
| 135 | 135 | while ( |
| 136 | 136 | $p !== false |
| 137 | 137 | and ($morceau = substr($txt, $d, $p - $d)) |
| 138 | - and (($nopen += preg_match_all("{<" . preg_quote($closing_tag) . "(\s*>|\s[^>]*[^/>]>)}is", $morceau, |
|
| 138 | + and (($nopen += preg_match_all("{<".preg_quote($closing_tag)."(\s*>|\s[^>]*[^/>]>)}is", $morceau, |
|
| 139 | 139 | $matches, PREG_SET_ORDER)) > $nclose) |
| 140 | 140 | ) { |
| 141 | 141 | $nclose++; |
@@ -154,9 +154,11 @@ |
||
| 154 | 154 | } |
| 155 | 155 | $content = substr($txt, 0, $p); |
| 156 | 156 | $txt = substr($txt, $p + $ncclos); |
| 157 | - if ($profondeur == 0 or strpos($content, "<") === false) // eviter une recursion si pas utile |
|
| 157 | + if ($profondeur == 0 or strpos($content, "<") === false) { |
|
| 158 | + // eviter une recursion si pas utile |
|
| 158 | 159 | { |
| 159 | 160 | $out[$tag][] = importer_charset($content, $charset); |
| 161 | + } |
|
| 160 | 162 | }//$content; |
| 161 | 163 | else { |
| 162 | 164 | $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1); |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -47,24 +47,24 @@ discard block |
||
| 47 | 47 | * - false si l'arbre xml ne peut être créé ou est vide |
| 48 | 48 | **/ |
| 49 | 49 | function spip_xml_load($fichier, $strict = true, $clean = true, $taille_max = 1048576, $datas = '', $profondeur = -1) { |
| 50 | - $contenu = ""; |
|
| 51 | - if (tester_url_absolue($fichier)) { |
|
| 52 | - include_spip('inc/distant'); |
|
| 53 | - $contenu = recuperer_url($fichier, ['taille_max' => $taille_max, 'datas' => $datas]); |
|
| 54 | - $contenu = $contenu['page'] ?? ''; |
|
| 55 | - } else { |
|
| 56 | - lire_fichier($fichier, $contenu); |
|
| 57 | - } |
|
| 58 | - $arbre = array(); |
|
| 59 | - if ($contenu) { |
|
| 60 | - $arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur); |
|
| 61 | - } |
|
| 50 | + $contenu = ""; |
|
| 51 | + if (tester_url_absolue($fichier)) { |
|
| 52 | + include_spip('inc/distant'); |
|
| 53 | + $contenu = recuperer_url($fichier, ['taille_max' => $taille_max, 'datas' => $datas]); |
|
| 54 | + $contenu = $contenu['page'] ?? ''; |
|
| 55 | + } else { |
|
| 56 | + lire_fichier($fichier, $contenu); |
|
| 57 | + } |
|
| 58 | + $arbre = array(); |
|
| 59 | + if ($contenu) { |
|
| 60 | + $arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - return count($arbre) ? $arbre : false; |
|
| 63 | + return count($arbre) ? $arbre : false; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | if (!defined('_SPIP_XML_TAG_SPLIT')) { |
| 67 | - define('_SPIP_XML_TAG_SPLIT', "{<([^:>][^>]*?)>}sS"); |
|
| 67 | + define('_SPIP_XML_TAG_SPLIT', "{<([^:>][^>]*?)>}sS"); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -83,150 +83,150 @@ discard block |
||
| 83 | 83 | * - false si l'arbre xml ne peut être créé ou est vide |
| 84 | 84 | **/ |
| 85 | 85 | function spip_xml_parse(&$texte, $strict = true, $clean = true, $profondeur = -1) { |
| 86 | - $out = array(); |
|
| 87 | - // enlever les commentaires |
|
| 88 | - $charset = 'AUTO'; |
|
| 89 | - if ($clean === true) { |
|
| 90 | - if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) { |
|
| 91 | - $charset = $regs[2]; |
|
| 92 | - } |
|
| 93 | - $texte = preg_replace(',<!--(.*?)-->,is', '', $texte); |
|
| 94 | - $texte = preg_replace(',<\?(.*?)\?>,is', '', $texte); |
|
| 95 | - include_spip('inc/charsets'); |
|
| 96 | - $clean = $charset; |
|
| 97 | - //$texte = importer_charset($texte,$charset); |
|
| 98 | - } |
|
| 99 | - if (is_string($clean)) { |
|
| 100 | - $charset = $clean; |
|
| 101 | - } |
|
| 102 | - $txt = $texte; |
|
| 86 | + $out = array(); |
|
| 87 | + // enlever les commentaires |
|
| 88 | + $charset = 'AUTO'; |
|
| 89 | + if ($clean === true) { |
|
| 90 | + if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) { |
|
| 91 | + $charset = $regs[2]; |
|
| 92 | + } |
|
| 93 | + $texte = preg_replace(',<!--(.*?)-->,is', '', $texte); |
|
| 94 | + $texte = preg_replace(',<\?(.*?)\?>,is', '', $texte); |
|
| 95 | + include_spip('inc/charsets'); |
|
| 96 | + $clean = $charset; |
|
| 97 | + //$texte = importer_charset($texte,$charset); |
|
| 98 | + } |
|
| 99 | + if (is_string($clean)) { |
|
| 100 | + $charset = $clean; |
|
| 101 | + } |
|
| 102 | + $txt = $texte; |
|
| 103 | 103 | |
| 104 | - // tant qu'il y a des tags |
|
| 105 | - $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 106 | - while (count($chars) >= 2) { |
|
| 107 | - // tag ouvrant |
|
| 108 | - //$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE); |
|
| 104 | + // tant qu'il y a des tags |
|
| 105 | + $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 106 | + while (count($chars) >= 2) { |
|
| 107 | + // tag ouvrant |
|
| 108 | + //$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE); |
|
| 109 | 109 | |
| 110 | - // $before doit etre vide ou des espaces uniquements! |
|
| 111 | - $before = trim($chars[0]); |
|
| 110 | + // $before doit etre vide ou des espaces uniquements! |
|
| 111 | + $before = trim($chars[0]); |
|
| 112 | 112 | |
| 113 | - if (strlen($before) > 0) { |
|
| 114 | - return importer_charset($texte, $charset); |
|
| 115 | - }//$texte; // before non vide, donc on est dans du texte |
|
| 113 | + if (strlen($before) > 0) { |
|
| 114 | + return importer_charset($texte, $charset); |
|
| 115 | + }//$texte; // before non vide, donc on est dans du texte |
|
| 116 | 116 | |
| 117 | - $tag = rtrim($chars[1]); |
|
| 118 | - $txt = $chars[2]; |
|
| 117 | + $tag = rtrim($chars[1]); |
|
| 118 | + $txt = $chars[2]; |
|
| 119 | 119 | |
| 120 | - if (strncmp($tag, '![CDATA[', 8) == 0) { |
|
| 121 | - return importer_charset($texte, $charset); |
|
| 122 | - }//$texte; |
|
| 123 | - if (substr($tag, -1) == '/') { // self closing tag |
|
| 124 | - $tag = rtrim(substr($tag, 0, strlen($tag) - 1)); |
|
| 125 | - $out[$tag][] = ""; |
|
| 126 | - } else { |
|
| 127 | - $closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag)); |
|
| 128 | - $closing_tag = reset($closing_tag); |
|
| 129 | - // tag fermant |
|
| 130 | - $ncclos = strlen("</$closing_tag>"); |
|
| 131 | - $p = strpos($txt, "</$closing_tag>"); |
|
| 132 | - if ($p !== false and (strpos($txt, "<") < $p)) { |
|
| 133 | - $nclose = 0; |
|
| 134 | - $nopen = 0; |
|
| 135 | - $d = 0; |
|
| 136 | - while ( |
|
| 137 | - $p !== false |
|
| 138 | - and ($morceau = substr($txt, $d, $p - $d)) |
|
| 139 | - and (($nopen += preg_match_all("{<" . preg_quote($closing_tag) . "(\s*>|\s[^>]*[^/>]>)}is", $morceau, |
|
| 140 | - $matches, PREG_SET_ORDER)) > $nclose) |
|
| 141 | - ) { |
|
| 142 | - $nclose++; |
|
| 143 | - $d = $p + $ncclos; |
|
| 144 | - $p = strpos($txt, "</$closing_tag>", $d); |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - if ($p === false) { |
|
| 148 | - if ($strict) { |
|
| 149 | - $out[$tag][] = "erreur : tag fermant $tag manquant::$txt"; |
|
| 120 | + if (strncmp($tag, '![CDATA[', 8) == 0) { |
|
| 121 | + return importer_charset($texte, $charset); |
|
| 122 | + }//$texte; |
|
| 123 | + if (substr($tag, -1) == '/') { // self closing tag |
|
| 124 | + $tag = rtrim(substr($tag, 0, strlen($tag) - 1)); |
|
| 125 | + $out[$tag][] = ""; |
|
| 126 | + } else { |
|
| 127 | + $closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag)); |
|
| 128 | + $closing_tag = reset($closing_tag); |
|
| 129 | + // tag fermant |
|
| 130 | + $ncclos = strlen("</$closing_tag>"); |
|
| 131 | + $p = strpos($txt, "</$closing_tag>"); |
|
| 132 | + if ($p !== false and (strpos($txt, "<") < $p)) { |
|
| 133 | + $nclose = 0; |
|
| 134 | + $nopen = 0; |
|
| 135 | + $d = 0; |
|
| 136 | + while ( |
|
| 137 | + $p !== false |
|
| 138 | + and ($morceau = substr($txt, $d, $p - $d)) |
|
| 139 | + and (($nopen += preg_match_all("{<" . preg_quote($closing_tag) . "(\s*>|\s[^>]*[^/>]>)}is", $morceau, |
|
| 140 | + $matches, PREG_SET_ORDER)) > $nclose) |
|
| 141 | + ) { |
|
| 142 | + $nclose++; |
|
| 143 | + $d = $p + $ncclos; |
|
| 144 | + $p = strpos($txt, "</$closing_tag>", $d); |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + if ($p === false) { |
|
| 148 | + if ($strict) { |
|
| 149 | + $out[$tag][] = "erreur : tag fermant $tag manquant::$txt"; |
|
| 150 | 150 | |
| 151 | - return $out; |
|
| 152 | - } else { |
|
| 153 | - return importer_charset($texte, $charset); |
|
| 154 | - }//$texte // un tag qui constitue du texte a reporter dans $before |
|
| 155 | - } |
|
| 156 | - $content = substr($txt, 0, $p); |
|
| 157 | - $txt = substr($txt, $p + $ncclos); |
|
| 158 | - if ($profondeur == 0 or strpos($content, "<") === false) // eviter une recursion si pas utile |
|
| 159 | - { |
|
| 160 | - $out[$tag][] = importer_charset($content, $charset); |
|
| 161 | - }//$content; |
|
| 162 | - else { |
|
| 163 | - $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1); |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 167 | - } |
|
| 168 | - if (count($out) && (strlen(trim($txt)) == 0)) { |
|
| 169 | - return $out; |
|
| 170 | - } else { |
|
| 171 | - return importer_charset($texte, $charset); |
|
| 172 | - }//$texte; |
|
| 151 | + return $out; |
|
| 152 | + } else { |
|
| 153 | + return importer_charset($texte, $charset); |
|
| 154 | + }//$texte // un tag qui constitue du texte a reporter dans $before |
|
| 155 | + } |
|
| 156 | + $content = substr($txt, 0, $p); |
|
| 157 | + $txt = substr($txt, $p + $ncclos); |
|
| 158 | + if ($profondeur == 0 or strpos($content, "<") === false) // eviter une recursion si pas utile |
|
| 159 | + { |
|
| 160 | + $out[$tag][] = importer_charset($content, $charset); |
|
| 161 | + }//$content; |
|
| 162 | + else { |
|
| 163 | + $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1); |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 167 | + } |
|
| 168 | + if (count($out) && (strlen(trim($txt)) == 0)) { |
|
| 169 | + return $out; |
|
| 170 | + } else { |
|
| 171 | + return importer_charset($texte, $charset); |
|
| 172 | + }//$texte; |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | // https://code.spip.net/@spip_xml_aplatit |
| 176 | 176 | function spip_xml_aplatit($arbre, $separateur = " ") { |
| 177 | - $s = ""; |
|
| 178 | - if (is_array($arbre)) { |
|
| 179 | - foreach ($arbre as $tag => $feuille) { |
|
| 180 | - if (is_array($feuille)) { |
|
| 181 | - if ($tag !== intval($tag)) { |
|
| 182 | - $f = spip_xml_aplatit($feuille, $separateur); |
|
| 183 | - if (strlen($f)) { |
|
| 184 | - $tagf = explode(" ", $tag); |
|
| 185 | - $tagf = $tagf[0]; |
|
| 186 | - $s .= "<$tag>$f</$tagf>"; |
|
| 187 | - } else { |
|
| 188 | - $s .= "<$tag />"; |
|
| 189 | - } |
|
| 190 | - } else { |
|
| 191 | - $s .= spip_xml_aplatit($feuille); |
|
| 192 | - } |
|
| 193 | - $s .= $separateur; |
|
| 194 | - } else { |
|
| 195 | - $s .= "$feuille$separateur"; |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - } |
|
| 177 | + $s = ""; |
|
| 178 | + if (is_array($arbre)) { |
|
| 179 | + foreach ($arbre as $tag => $feuille) { |
|
| 180 | + if (is_array($feuille)) { |
|
| 181 | + if ($tag !== intval($tag)) { |
|
| 182 | + $f = spip_xml_aplatit($feuille, $separateur); |
|
| 183 | + if (strlen($f)) { |
|
| 184 | + $tagf = explode(" ", $tag); |
|
| 185 | + $tagf = $tagf[0]; |
|
| 186 | + $s .= "<$tag>$f</$tagf>"; |
|
| 187 | + } else { |
|
| 188 | + $s .= "<$tag />"; |
|
| 189 | + } |
|
| 190 | + } else { |
|
| 191 | + $s .= spip_xml_aplatit($feuille); |
|
| 192 | + } |
|
| 193 | + $s .= $separateur; |
|
| 194 | + } else { |
|
| 195 | + $s .= "$feuille$separateur"; |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | - return strlen($separateur) ? substr($s, 0, -strlen($separateur)) : $s; |
|
| 200 | + return strlen($separateur) ? substr($s, 0, -strlen($separateur)) : $s; |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | // https://code.spip.net/@spip_xml_tagname |
| 204 | 204 | function spip_xml_tagname($tag) { |
| 205 | - if (preg_match(',^([a-z][\w:]*),i', $tag, $reg)) { |
|
| 206 | - return $reg[1]; |
|
| 207 | - } |
|
| 205 | + if (preg_match(',^([a-z][\w:]*),i', $tag, $reg)) { |
|
| 206 | + return $reg[1]; |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - return ""; |
|
| 209 | + return ""; |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | // https://code.spip.net/@spip_xml_decompose_tag |
| 213 | 213 | function spip_xml_decompose_tag($tag) { |
| 214 | - $tagname = spip_xml_tagname($tag); |
|
| 215 | - $liste = array(); |
|
| 216 | - $tag = ltrim(strpbrk($tag, " \n\t")); |
|
| 217 | - $p = strpos($tag, '='); |
|
| 218 | - while ($p !== false) { |
|
| 219 | - $attr = trim(substr($tag, 0, $p)); |
|
| 220 | - $tag = ltrim(substr($tag, $p + 1)); |
|
| 221 | - $quote = $tag[0]; |
|
| 222 | - $p = strpos($tag, $quote, 1); |
|
| 223 | - $cont = substr($tag, 1, $p - 1); |
|
| 224 | - $liste[$attr] = $cont; |
|
| 225 | - $tag = substr($tag, $p + 1); |
|
| 226 | - $p = strpos($tag, '='); |
|
| 227 | - } |
|
| 214 | + $tagname = spip_xml_tagname($tag); |
|
| 215 | + $liste = array(); |
|
| 216 | + $tag = ltrim(strpbrk($tag, " \n\t")); |
|
| 217 | + $p = strpos($tag, '='); |
|
| 218 | + while ($p !== false) { |
|
| 219 | + $attr = trim(substr($tag, 0, $p)); |
|
| 220 | + $tag = ltrim(substr($tag, $p + 1)); |
|
| 221 | + $quote = $tag[0]; |
|
| 222 | + $p = strpos($tag, $quote, 1); |
|
| 223 | + $cont = substr($tag, 1, $p - 1); |
|
| 224 | + $liste[$attr] = $cont; |
|
| 225 | + $tag = substr($tag, $p + 1); |
|
| 226 | + $p = strpos($tag, '='); |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - return array($tagname, $liste); |
|
| 229 | + return array($tagname, $liste); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -249,21 +249,21 @@ discard block |
||
| 249 | 249 | * false si aucun élément ne valide l'expression régulière, true sinon. |
| 250 | 250 | **/ |
| 251 | 251 | function spip_xml_match_nodes($regexp, &$arbre, &$matches, $init = true) { |
| 252 | - if ($init) { |
|
| 253 | - $matches = array(); |
|
| 254 | - } |
|
| 255 | - if (is_array($arbre) && count($arbre)) { |
|
| 256 | - foreach (array_keys($arbre) as $tag) { |
|
| 257 | - if (preg_match($regexp, $tag)) { |
|
| 258 | - $matches[$tag] = &$arbre[$tag]; |
|
| 259 | - } |
|
| 260 | - if (is_array($arbre[$tag])) { |
|
| 261 | - foreach (array_keys($arbre[$tag]) as $occurences) { |
|
| 262 | - spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false); |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - } |
|
| 252 | + if ($init) { |
|
| 253 | + $matches = array(); |
|
| 254 | + } |
|
| 255 | + if (is_array($arbre) && count($arbre)) { |
|
| 256 | + foreach (array_keys($arbre) as $tag) { |
|
| 257 | + if (preg_match($regexp, $tag)) { |
|
| 258 | + $matches[$tag] = &$arbre[$tag]; |
|
| 259 | + } |
|
| 260 | + if (is_array($arbre[$tag])) { |
|
| 261 | + foreach (array_keys($arbre[$tag]) as $occurences) { |
|
| 262 | + spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false); |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - return (count($matches)); |
|
| 268 | + return (count($matches)); |
|
| 269 | 269 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | $_id = $e['id_table_objet']; |
| 51 | 51 | if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) { |
| 52 | 52 | $table = $e['table_objet_sql']; |
| 53 | - $row = sql_fetsel('*', $table, "$_id=" . intval($id)); |
|
| 53 | + $row = sql_fetsel('*', $table, "$_id=".intval($id)); |
|
| 54 | 54 | if (isset($row['id_rubrique'])) { |
| 55 | 55 | $contexte['id_rubrique'] = $row['id_rubrique']; |
| 56 | 56 | if (isset($row['id_secteur'])) { |
@@ -111,8 +111,8 @@ discard block |
||
| 111 | 111 | $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
| 112 | 112 | + array( |
| 113 | 113 | $id => new Bouton( |
| 114 | - ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 115 | - $infos['titre'], // titre |
|
| 114 | + ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 115 | + $infos['titre'], // titre |
|
| 116 | 116 | (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
| 117 | 117 | (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
| 118 | 118 | ) |
@@ -128,8 +128,8 @@ discard block |
||
| 128 | 128 | $boutons_admin = array_slice($boutons_admin, 0, $position) |
| 129 | 129 | + array( |
| 130 | 130 | $id => new Bouton( |
| 131 | - ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 132 | - $infos['titre'], // titre |
|
| 131 | + ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 132 | + $infos['titre'], // titre |
|
| 133 | 133 | (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
| 134 | 134 | (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
| 135 | 135 | ) |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | $libelles = $isfavoris = $favoris = array(); |
| 171 | 171 | foreach ($menu->sousmenu as $key => $item) { |
| 172 | 172 | $libelles[$key] = strtolower(translitteration(_T($item->libelle))); |
| 173 | - $isfavoris[$key] = (bool)$item->favori; |
|
| 173 | + $isfavoris[$key] = (bool) $item->favori; |
|
| 174 | 174 | $favoris[$key] = $item->favori; |
| 175 | 175 | } |
| 176 | 176 | if ($avec_favoris) { |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | $url = str_replace('&', '&', $url); |
| 213 | 213 | while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
| 214 | 214 | if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) { |
| 215 | - $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique'])); |
|
| 215 | + $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique='.intval($contexte['id_rubrique'])); |
|
| 216 | 216 | } |
| 217 | 217 | $val = _request($matches[2], $contexte); |
| 218 | 218 | $url = parametre_url($url, $matches[1], $val ? $val : '', '&'); |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/boutons'); |
@@ -37,33 +37,33 @@ discard block |
||
| 37 | 37 | * Contexte |
| 38 | 38 | **/ |
| 39 | 39 | function definir_barre_contexte($contexte = null) { |
| 40 | - if (is_null($contexte)) { |
|
| 41 | - $contexte = $_GET; |
|
| 42 | - } elseif (is_string($contexte)) { |
|
| 43 | - $contexte = unserialize($contexte); |
|
| 44 | - } |
|
| 45 | - if (!isset($contexte['id_rubrique']) and isset($contexte['exec'])) { |
|
| 46 | - if (!function_exists('trouver_objet_exec')) { |
|
| 47 | - include_spip('inc/pipelines_ecrire'); |
|
| 48 | - } |
|
| 49 | - if ($e = trouver_objet_exec($contexte['exec'])) { |
|
| 50 | - $_id = $e['id_table_objet']; |
|
| 51 | - if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) { |
|
| 52 | - $table = $e['table_objet_sql']; |
|
| 53 | - $row = sql_fetsel('*', $table, "$_id=" . intval($id)); |
|
| 54 | - if (isset($row['id_rubrique'])) { |
|
| 55 | - $contexte['id_rubrique'] = $row['id_rubrique']; |
|
| 56 | - if (isset($row['id_secteur'])) { |
|
| 57 | - $contexte['id_secteur'] = $row['id_secteur']; |
|
| 58 | - } |
|
| 59 | - } elseif (isset($row['id_groupe'])) { |
|
| 60 | - // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé |
|
| 61 | - $contexte['id_groupe'] = $row['id_groupe']; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - return $contexte; |
|
| 40 | + if (is_null($contexte)) { |
|
| 41 | + $contexte = $_GET; |
|
| 42 | + } elseif (is_string($contexte)) { |
|
| 43 | + $contexte = unserialize($contexte); |
|
| 44 | + } |
|
| 45 | + if (!isset($contexte['id_rubrique']) and isset($contexte['exec'])) { |
|
| 46 | + if (!function_exists('trouver_objet_exec')) { |
|
| 47 | + include_spip('inc/pipelines_ecrire'); |
|
| 48 | + } |
|
| 49 | + if ($e = trouver_objet_exec($contexte['exec'])) { |
|
| 50 | + $_id = $e['id_table_objet']; |
|
| 51 | + if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) { |
|
| 52 | + $table = $e['table_objet_sql']; |
|
| 53 | + $row = sql_fetsel('*', $table, "$_id=" . intval($id)); |
|
| 54 | + if (isset($row['id_rubrique'])) { |
|
| 55 | + $contexte['id_rubrique'] = $row['id_rubrique']; |
|
| 56 | + if (isset($row['id_secteur'])) { |
|
| 57 | + $contexte['id_secteur'] = $row['id_secteur']; |
|
| 58 | + } |
|
| 59 | + } elseif (isset($row['id_groupe'])) { |
|
| 60 | + // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé |
|
| 61 | + $contexte['id_groupe'] = $row['id_groupe']; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + return $contexte; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -79,88 +79,88 @@ discard block |
||
| 79 | 79 | * @return array |
| 80 | 80 | */ |
| 81 | 81 | function definir_barre_boutons($contexte = array(), $icones = true, $autorise = true) { |
| 82 | - include_spip('inc/autoriser'); |
|
| 83 | - $boutons_admin = array(); |
|
| 82 | + include_spip('inc/autoriser'); |
|
| 83 | + $boutons_admin = array(); |
|
| 84 | 84 | |
| 85 | - // les boutons du core, issus de ecrire/paquet.xml |
|
| 86 | - $liste_boutons = array(); |
|
| 85 | + // les boutons du core, issus de ecrire/paquet.xml |
|
| 86 | + $liste_boutons = array(); |
|
| 87 | 87 | |
| 88 | - // ajouter les boutons issus des plugin via paquet.xml |
|
| 89 | - if (function_exists('boutons_plugins') |
|
| 90 | - and is_array($liste_boutons_plugins = boutons_plugins()) |
|
| 91 | - ) { |
|
| 92 | - $liste_boutons = &$liste_boutons_plugins; |
|
| 93 | - } |
|
| 88 | + // ajouter les boutons issus des plugin via paquet.xml |
|
| 89 | + if (function_exists('boutons_plugins') |
|
| 90 | + and is_array($liste_boutons_plugins = boutons_plugins()) |
|
| 91 | + ) { |
|
| 92 | + $liste_boutons = &$liste_boutons_plugins; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - foreach ($liste_boutons as $id => $infos) { |
|
| 96 | - $parent = ''; |
|
| 97 | - // les boutons principaux ne sont pas soumis a autorisation |
|
| 98 | - if (!isset($infos['parent']) |
|
| 99 | - or !($parent = $infos['parent']) |
|
| 100 | - or !$autorise |
|
| 101 | - or autoriser('menu', "_$id", 0, null, array('contexte' => $contexte)) |
|
| 102 | - ) { |
|
| 103 | - if ($parent |
|
| 104 | - and $parent = preg_replace(',^bando_,', 'menu_', $parent) |
|
| 105 | - and isset($boutons_admin[$parent]) |
|
| 106 | - ) { |
|
| 107 | - if (!is_array($boutons_admin[$parent]->sousmenu)) { |
|
| 108 | - $boutons_admin[$parent]->sousmenu = array(); |
|
| 109 | - } |
|
| 110 | - $position = (isset($infos['position']) and strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu); |
|
| 111 | - if ($position < 0) { |
|
| 112 | - $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position; |
|
| 113 | - } |
|
| 114 | - $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
|
| 115 | - + array( |
|
| 116 | - $id => new Bouton( |
|
| 117 | - ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 118 | - $infos['titre'], // titre |
|
| 119 | - (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 120 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 121 | - ) |
|
| 122 | - ) |
|
| 123 | - + array_slice($boutons_admin[$parent]->sousmenu, $position, 100); |
|
| 124 | - } |
|
| 125 | - if (!$parent |
|
| 126 | - // provisoire, eviter les vieux boutons |
|
| 127 | - and (!in_array($id, array('forum', 'statistiques_visites'))) |
|
| 128 | - and (!$autorise or autoriser('menugrandeentree', "_$id", 0, null, array('contexte' => $contexte))) |
|
| 129 | - ) { |
|
| 130 | - $position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin); |
|
| 131 | - $boutons_admin = array_slice($boutons_admin, 0, $position) |
|
| 132 | - + array( |
|
| 133 | - $id => new Bouton( |
|
| 134 | - ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 135 | - $infos['titre'], // titre |
|
| 136 | - (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 137 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 138 | - ) |
|
| 139 | - ) |
|
| 140 | - + array_slice($boutons_admin, $position, 100); |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - $boutons_admin = pipeline('ajouter_menus', $boutons_admin); |
|
| 95 | + foreach ($liste_boutons as $id => $infos) { |
|
| 96 | + $parent = ''; |
|
| 97 | + // les boutons principaux ne sont pas soumis a autorisation |
|
| 98 | + if (!isset($infos['parent']) |
|
| 99 | + or !($parent = $infos['parent']) |
|
| 100 | + or !$autorise |
|
| 101 | + or autoriser('menu', "_$id", 0, null, array('contexte' => $contexte)) |
|
| 102 | + ) { |
|
| 103 | + if ($parent |
|
| 104 | + and $parent = preg_replace(',^bando_,', 'menu_', $parent) |
|
| 105 | + and isset($boutons_admin[$parent]) |
|
| 106 | + ) { |
|
| 107 | + if (!is_array($boutons_admin[$parent]->sousmenu)) { |
|
| 108 | + $boutons_admin[$parent]->sousmenu = array(); |
|
| 109 | + } |
|
| 110 | + $position = (isset($infos['position']) and strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu); |
|
| 111 | + if ($position < 0) { |
|
| 112 | + $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position; |
|
| 113 | + } |
|
| 114 | + $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
|
| 115 | + + array( |
|
| 116 | + $id => new Bouton( |
|
| 117 | + ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 118 | + $infos['titre'], // titre |
|
| 119 | + (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 120 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 121 | + ) |
|
| 122 | + ) |
|
| 123 | + + array_slice($boutons_admin[$parent]->sousmenu, $position, 100); |
|
| 124 | + } |
|
| 125 | + if (!$parent |
|
| 126 | + // provisoire, eviter les vieux boutons |
|
| 127 | + and (!in_array($id, array('forum', 'statistiques_visites'))) |
|
| 128 | + and (!$autorise or autoriser('menugrandeentree', "_$id", 0, null, array('contexte' => $contexte))) |
|
| 129 | + ) { |
|
| 130 | + $position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin); |
|
| 131 | + $boutons_admin = array_slice($boutons_admin, 0, $position) |
|
| 132 | + + array( |
|
| 133 | + $id => new Bouton( |
|
| 134 | + ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 135 | + $infos['titre'], // titre |
|
| 136 | + (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 137 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 138 | + ) |
|
| 139 | + ) |
|
| 140 | + + array_slice($boutons_admin, $position, 100); |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + $boutons_admin = pipeline('ajouter_menus', $boutons_admin); |
|
| 145 | 145 | |
| 146 | - // définir les favoris et positions d’origine |
|
| 147 | - if ($boutons_admin) { |
|
| 148 | - $menus_favoris = obtenir_menus_favoris(); |
|
| 149 | - $i = 1; |
|
| 150 | - foreach ($boutons_admin as $key => $menu) { |
|
| 151 | - $menu->favori = table_valeur($menus_favoris, $key, false); |
|
| 152 | - $menu->position = $i++; |
|
| 153 | - if ($menu->sousmenu) { |
|
| 154 | - $j = 1; |
|
| 155 | - foreach ($menu->sousmenu as $key => $bouton) { |
|
| 156 | - $bouton->favori = table_valeur($menus_favoris, $key, false); |
|
| 157 | - $bouton->position = $j++; |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - } |
|
| 146 | + // définir les favoris et positions d’origine |
|
| 147 | + if ($boutons_admin) { |
|
| 148 | + $menus_favoris = obtenir_menus_favoris(); |
|
| 149 | + $i = 1; |
|
| 150 | + foreach ($boutons_admin as $key => $menu) { |
|
| 151 | + $menu->favori = table_valeur($menus_favoris, $key, false); |
|
| 152 | + $menu->position = $i++; |
|
| 153 | + if ($menu->sousmenu) { |
|
| 154 | + $j = 1; |
|
| 155 | + foreach ($menu->sousmenu as $key => $bouton) { |
|
| 156 | + $bouton->favori = table_valeur($menus_favoris, $key, false); |
|
| 157 | + $bouton->position = $j++; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | - return $boutons_admin; |
|
| 163 | + return $boutons_admin; |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
@@ -172,22 +172,22 @@ discard block |
||
| 172 | 172 | * @return Bouton[] |
| 173 | 173 | */ |
| 174 | 174 | function trier_boutons_enfants_par_alpha($menus, $avec_favoris = false) { |
| 175 | - foreach ($menus as $menu) { |
|
| 176 | - if ($menu->sousmenu) { |
|
| 177 | - $libelles = $isfavoris = $favoris = array(); |
|
| 178 | - foreach ($menu->sousmenu as $key => $item) { |
|
| 179 | - $libelles[$key] = strtolower(translitteration(_T($item->libelle))); |
|
| 180 | - $isfavoris[$key] = (bool)$item->favori; |
|
| 181 | - $favoris[$key] = $item->favori; |
|
| 182 | - } |
|
| 183 | - if ($avec_favoris) { |
|
| 184 | - array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu); |
|
| 185 | - } else { |
|
| 186 | - array_multisort($libelles, SORT_ASC, $menu->sousmenu); |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - return $menus; |
|
| 175 | + foreach ($menus as $menu) { |
|
| 176 | + if ($menu->sousmenu) { |
|
| 177 | + $libelles = $isfavoris = $favoris = array(); |
|
| 178 | + foreach ($menu->sousmenu as $key => $item) { |
|
| 179 | + $libelles[$key] = strtolower(translitteration(_T($item->libelle))); |
|
| 180 | + $isfavoris[$key] = (bool)$item->favori; |
|
| 181 | + $favoris[$key] = $item->favori; |
|
| 182 | + } |
|
| 183 | + if ($avec_favoris) { |
|
| 184 | + array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu); |
|
| 185 | + } else { |
|
| 186 | + array_multisort($libelles, SORT_ASC, $menu->sousmenu); |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + return $menus; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | * @return Bouton[] |
| 199 | 199 | */ |
| 200 | 200 | function trier_boutons_enfants_par_favoris_alpha($menus) { |
| 201 | - return trier_boutons_enfants_par_alpha($menus, true); |
|
| 201 | + return trier_boutons_enfants_par_alpha($menus, true); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | |
@@ -211,23 +211,23 @@ discard block |
||
| 211 | 211 | * @return string |
| 212 | 212 | */ |
| 213 | 213 | function bandeau_creer_url($url, $args = '', $contexte = null) { |
| 214 | - if (!preg_match(',[\/\?],', $url)) { |
|
| 215 | - $url = generer_url_ecrire($url, $args, true); |
|
| 216 | - // recuperer les parametres du contexte demande par l'url sous la forme |
|
| 217 | - // &truc=@machin@ |
|
| 218 | - // @machin@ etant remplace par _request('machin') |
|
| 219 | - $url = str_replace('&', '&', $url); |
|
| 220 | - while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
|
| 221 | - if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) { |
|
| 222 | - $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique'])); |
|
| 223 | - } |
|
| 224 | - $val = _request($matches[2], $contexte); |
|
| 225 | - $url = parametre_url($url, $matches[1], $val ? $val : '', '&'); |
|
| 226 | - } |
|
| 227 | - $url = str_replace('&', '&', $url); |
|
| 228 | - } |
|
| 214 | + if (!preg_match(',[\/\?],', $url)) { |
|
| 215 | + $url = generer_url_ecrire($url, $args, true); |
|
| 216 | + // recuperer les parametres du contexte demande par l'url sous la forme |
|
| 217 | + // &truc=@machin@ |
|
| 218 | + // @machin@ etant remplace par _request('machin') |
|
| 219 | + $url = str_replace('&', '&', $url); |
|
| 220 | + while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
|
| 221 | + if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) { |
|
| 222 | + $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique'])); |
|
| 223 | + } |
|
| 224 | + $val = _request($matches[2], $contexte); |
|
| 225 | + $url = parametre_url($url, $matches[1], $val ? $val : '', '&'); |
|
| 226 | + } |
|
| 227 | + $url = str_replace('&', '&', $url); |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | - return $url; |
|
| 230 | + return $url; |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | * Code HTML du bandeau |
| 238 | 238 | */ |
| 239 | 239 | function inc_bandeau_dist() { |
| 240 | - return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET); |
|
| 240 | + return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET); |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | |
@@ -246,13 +246,13 @@ discard block |
||
| 246 | 246 | * @return array |
| 247 | 247 | */ |
| 248 | 248 | function obtenir_menus_favoris() { |
| 249 | - if ( |
|
| 250 | - isset($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 251 | - and is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 252 | - and $GLOBALS['visiteur_session']['prefs']['menus_favoris'] |
|
| 253 | - ) { |
|
| 254 | - return $GLOBALS['visiteur_session']['prefs']['menus_favoris']; |
|
| 255 | - } |
|
| 256 | - $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc'); |
|
| 257 | - return $definir_menus_favoris(); |
|
| 249 | + if ( |
|
| 250 | + isset($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 251 | + and is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 252 | + and $GLOBALS['visiteur_session']['prefs']['menus_favoris'] |
|
| 253 | + ) { |
|
| 254 | + return $GLOBALS['visiteur_session']['prefs']['menus_favoris']; |
|
| 255 | + } |
|
| 256 | + $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc'); |
|
| 257 | + return $definir_menus_favoris(); |
|
| 258 | 258 | } |
| 259 | 259 | \ No newline at end of file |
@@ -429,9 +429,11 @@ |
||
| 429 | 429 | if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
| 430 | 430 | // relancer avec les nouveaux arguments de temps |
| 431 | 431 | include_spip('inc/genie'); |
| 432 | - if ($result < 0) // relancer tout de suite, mais en baissant la priorite |
|
| 432 | + if ($result < 0) { |
|
| 433 | + // relancer tout de suite, mais en baissant la priorite |
|
| 433 | 434 | { |
| 434 | 435 | queue_genie_replan_job($row['fonction'], $periode, 0 - $result, null, $row['priorite'] - 1); |
| 436 | + } |
|
| 435 | 437 | } else // relancer avec la periode prevue |
| 436 | 438 | { |
| 437 | 439 | queue_genie_replan_job($row['fonction'], $periode, $time); |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | $md5args = md5($arguments); |
| 71 | 71 | |
| 72 | 72 | // si pas de date programee, des que possible |
| 73 | - $duplicate_where = 'status=' . intval(_JQ_SCHEDULED) . ' AND '; |
|
| 73 | + $duplicate_where = 'status='.intval(_JQ_SCHEDULED).' AND '; |
|
| 74 | 74 | if (!$time) { |
| 75 | 75 | $time = time(); |
| 76 | 76 | $duplicate_where = ""; // ne pas dupliquer si deja le meme job en cours d'execution |
@@ -94,9 +94,8 @@ discard block |
||
| 94 | 94 | and |
| 95 | 95 | $id_job = sql_getfetsel('id_job', 'spip_jobs', |
| 96 | 96 | $duplicate_where = |
| 97 | - $duplicate_where . 'fonction=' . sql_quote($function) |
|
| 98 | - . (($no_duplicate === 'function_only') ? '' : |
|
| 99 | - ' AND md5args=' . sql_quote($md5args) . ' AND inclure=' . sql_quote($file))) |
|
| 97 | + $duplicate_where.'fonction='.sql_quote($function) |
|
| 98 | + . (($no_duplicate === 'function_only') ? '' : ' AND md5args='.sql_quote($md5args).' AND inclure='.sql_quote($file))) |
|
| 100 | 99 | ) { |
| 101 | 100 | return $id_job; |
| 102 | 101 | } |
@@ -108,9 +107,9 @@ discard block |
||
| 108 | 107 | if ( |
| 109 | 108 | $no_duplicate |
| 110 | 109 | and |
| 111 | - $id_prev = sql_getfetsel('id_job', 'spip_jobs', "id_job<" . intval($id_job) . " AND $duplicate_where") |
|
| 110 | + $id_prev = sql_getfetsel('id_job', 'spip_jobs', "id_job<".intval($id_job)." AND $duplicate_where") |
|
| 112 | 111 | ) { |
| 113 | - sql_delete('spip_jobs', 'id_job=' . intval($id_job)); |
|
| 112 | + sql_delete('spip_jobs', 'id_job='.intval($id_job)); |
|
| 114 | 113 | |
| 115 | 114 | return $id_prev; |
| 116 | 115 | } |
@@ -122,9 +121,9 @@ discard block |
||
| 122 | 121 | // ie cas d'un char non acceptables sur certains type de champs |
| 123 | 122 | // qui coupe la valeur |
| 124 | 123 | if (defined('_JQ_INSERT_CHECK_ARGS') and $id_job) { |
| 125 | - $args = sql_getfetsel('args', 'spip_jobs', 'id_job=' . intval($id_job)); |
|
| 124 | + $args = sql_getfetsel('args', 'spip_jobs', 'id_job='.intval($id_job)); |
|
| 126 | 125 | if ($args !== $arguments) { |
| 127 | - spip_log('arguments job errones / longueur ' . strlen($args) . " vs " . strlen($arguments) . ' / valeur : ' . var_export($arguments, |
|
| 126 | + spip_log('arguments job errones / longueur '.strlen($args)." vs ".strlen($arguments).' / valeur : '.var_export($arguments, |
|
| 128 | 127 | true), 'queue'); |
| 129 | 128 | } |
| 130 | 129 | } |
@@ -152,7 +151,7 @@ discard block |
||
| 152 | 151 | function queue_purger() { |
| 153 | 152 | include_spip('base/abstract_sql'); |
| 154 | 153 | sql_delete('spip_jobs'); |
| 155 | - sql_delete("spip_jobs_liens", "id_job NOT IN (" . sql_get_select("id_job", "spip_jobs") . ")"); |
|
| 154 | + sql_delete("spip_jobs_liens", "id_job NOT IN (".sql_get_select("id_job", "spip_jobs").")"); |
|
| 156 | 155 | include_spip('inc/genie'); |
| 157 | 156 | genie_queue_watch_dist(); |
| 158 | 157 | } |
@@ -167,8 +166,8 @@ discard block |
||
| 167 | 166 | function queue_remove_job($id_job) { |
| 168 | 167 | include_spip('base/abstract_sql'); |
| 169 | 168 | |
| 170 | - if ($row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job=' . intval($id_job)) |
|
| 171 | - and $res = sql_delete('spip_jobs', 'id_job=' . intval($id_job)) |
|
| 169 | + if ($row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job='.intval($id_job)) |
|
| 170 | + and $res = sql_delete('spip_jobs', 'id_job='.intval($id_job)) |
|
| 172 | 171 | ) { |
| 173 | 172 | queue_unlink_job($id_job); |
| 174 | 173 | // est-ce une tache cron qu'il faut relancer ? |
@@ -217,7 +216,7 @@ discard block |
||
| 217 | 216 | * resultat du sql_delete |
| 218 | 217 | */ |
| 219 | 218 | function queue_unlink_job($id_job) { |
| 220 | - return sql_delete("spip_jobs_liens", "id_job=" . intval($id_job)); |
|
| 219 | + return sql_delete("spip_jobs_liens", "id_job=".intval($id_job)); |
|
| 221 | 220 | } |
| 222 | 221 | |
| 223 | 222 | /** |
@@ -233,7 +232,7 @@ discard block |
||
| 233 | 232 | // deserialiser les arguments |
| 234 | 233 | $args = unserialize($row['args']); |
| 235 | 234 | if ($args === false) { |
| 236 | - spip_log('arguments job errones ' . var_export($row, true), 'queue'); |
|
| 235 | + spip_log('arguments job errones '.var_export($row, true), 'queue'); |
|
| 237 | 236 | $args = array(); |
| 238 | 237 | } |
| 239 | 238 | |
@@ -250,12 +249,12 @@ discard block |
||
| 250 | 249 | } |
| 251 | 250 | |
| 252 | 251 | if (!function_exists($fonction)) { |
| 253 | - spip_log("fonction $fonction ($inclure) inexistante " . var_export($row, true), 'queue'); |
|
| 252 | + spip_log("fonction $fonction ($inclure) inexistante ".var_export($row, true), 'queue'); |
|
| 254 | 253 | |
| 255 | 254 | return false; |
| 256 | 255 | } |
| 257 | 256 | |
| 258 | - spip_log("queue [" . $row['id_job'] . "]: $fonction() start", 'queue'); |
|
| 257 | + spip_log("queue [".$row['id_job']."]: $fonction() start", 'queue'); |
|
| 259 | 258 | switch (count($args)) { |
| 260 | 259 | case 0: |
| 261 | 260 | $res = $fonction(); |
@@ -295,7 +294,7 @@ discard block |
||
| 295 | 294 | # plus lent mais completement generique |
| 296 | 295 | $res = call_user_func_array($fonction, $args); |
| 297 | 296 | } |
| 298 | - spip_log("queue [" . $row['id_job'] . "]: $fonction() end", 'queue'); |
|
| 297 | + spip_log("queue [".$row['id_job']."]: $fonction() end", 'queue'); |
|
| 299 | 298 | |
| 300 | 299 | return $res; |
| 301 | 300 | |
@@ -327,14 +326,14 @@ discard block |
||
| 327 | 326 | function queue_schedule($force_jobs = null) { |
| 328 | 327 | $time = time(); |
| 329 | 328 | if (defined('_DEBUG_BLOCK_QUEUE')) { |
| 330 | - spip_log("_DEBUG_BLOCK_QUEUE : schedule stop", 'jq' . _LOG_DEBUG); |
|
| 329 | + spip_log("_DEBUG_BLOCK_QUEUE : schedule stop", 'jq'._LOG_DEBUG); |
|
| 331 | 330 | |
| 332 | 331 | return; |
| 333 | 332 | } |
| 334 | 333 | |
| 335 | 334 | // rien a faire si le prochain job est encore dans le futur |
| 336 | 335 | if (queue_sleep_time_to_next_job() > 0 and (!$force_jobs or !count($force_jobs))) { |
| 337 | - spip_log("queue_sleep_time_to_next_job", 'jq' . _LOG_DEBUG); |
|
| 336 | + spip_log("queue_sleep_time_to_next_job", 'jq'._LOG_DEBUG); |
|
| 338 | 337 | |
| 339 | 338 | return; |
| 340 | 339 | } |
@@ -355,7 +354,7 @@ discard block |
||
| 355 | 354 | } |
| 356 | 355 | $end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE; |
| 357 | 356 | |
| 358 | - spip_log("JQ schedule $time / $end_time", 'jq' . _LOG_DEBUG); |
|
| 357 | + spip_log("JQ schedule $time / $end_time", 'jq'._LOG_DEBUG); |
|
| 359 | 358 | |
| 360 | 359 | if (!defined('_JQ_MAX_JOBS_EXECUTE')) { |
| 361 | 360 | define('_JQ_MAX_JOBS_EXECUTE', 200); |
@@ -369,19 +368,19 @@ discard block |
||
| 369 | 368 | // lorsqu'un job cron n'a pas fini, sa priorite est descendue |
| 370 | 369 | // pour qu'il ne bloque pas les autres jobs en attente |
| 371 | 370 | if (is_array($force_jobs) and count($force_jobs)) { |
| 372 | - $cond = "status=" . intval(_JQ_SCHEDULED) . " AND " . sql_in("id_job", $force_jobs); |
|
| 371 | + $cond = "status=".intval(_JQ_SCHEDULED)." AND ".sql_in("id_job", $force_jobs); |
|
| 373 | 372 | } else { |
| 374 | 373 | $now = date('Y-m-d H:i:s', $time); |
| 375 | - $cond = "status=" . intval(_JQ_SCHEDULED) . " AND date<=" . sql_quote($now); |
|
| 374 | + $cond = "status=".intval(_JQ_SCHEDULED)." AND date<=".sql_quote($now); |
|
| 376 | 375 | } |
| 377 | 376 | |
| 378 | 377 | register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible |
| 379 | - $res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,' . (_JQ_MAX_JOBS_EXECUTE + 1)); |
|
| 378 | + $res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,'.(_JQ_MAX_JOBS_EXECUTE + 1)); |
|
| 380 | 379 | do { |
| 381 | 380 | if ($row = array_shift($res)) { |
| 382 | 381 | $nbj++; |
| 383 | 382 | // il faut un verrou, a base de sql_delete |
| 384 | - if (sql_delete('spip_jobs', "id_job=" . intval($row['id_job']) . " AND status=" . intval(_JQ_SCHEDULED))) { |
|
| 383 | + if (sql_delete('spip_jobs', "id_job=".intval($row['id_job'])." AND status=".intval(_JQ_SCHEDULED))) { |
|
| 385 | 384 | #spip_log("JQ schedule job ".$nbj." OK",'jq'); |
| 386 | 385 | // on reinsert dans la base aussitot avec un status=_JQ_PENDING |
| 387 | 386 | $row['status'] = _JQ_PENDING; |
@@ -396,13 +395,13 @@ discard block |
||
| 396 | 395 | queue_close_job($row, $time, $result); |
| 397 | 396 | } |
| 398 | 397 | } |
| 399 | - spip_log("JQ schedule job end time " . $time, 'jq' . _LOG_DEBUG); |
|
| 398 | + spip_log("JQ schedule job end time ".$time, 'jq'._LOG_DEBUG); |
|
| 400 | 399 | } while ($nbj < _JQ_MAX_JOBS_EXECUTE and $row and $time < $end_time); |
| 401 | - spip_log("JQ schedule end time " . time(), 'jq' . _LOG_DEBUG); |
|
| 400 | + spip_log("JQ schedule end time ".time(), 'jq'._LOG_DEBUG); |
|
| 402 | 401 | |
| 403 | 402 | if ($row = array_shift($res)) { |
| 404 | 403 | queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP |
| 405 | - spip_log("JQ encore !", 'jq' . _LOG_DEBUG); |
|
| 404 | + spip_log("JQ encore !", 'jq'._LOG_DEBUG); |
|
| 406 | 405 | } else { |
| 407 | 406 | queue_update_next_job_time(); |
| 408 | 407 | } |
@@ -438,9 +437,9 @@ discard block |
||
| 438 | 437 | } |
| 439 | 438 | } |
| 440 | 439 | // purger ses liens eventuels avec des objets |
| 441 | - sql_delete("spip_jobs_liens", "id_job=" . intval($row['id_job'])); |
|
| 440 | + sql_delete("spip_jobs_liens", "id_job=".intval($row['id_job'])); |
|
| 442 | 441 | // supprimer le job fini |
| 443 | - sql_delete('spip_jobs', 'id_job=' . intval($row['id_job'])); |
|
| 442 | + sql_delete('spip_jobs', 'id_job='.intval($row['id_job'])); |
|
| 444 | 443 | } |
| 445 | 444 | |
| 446 | 445 | /** |
@@ -511,17 +510,17 @@ discard block |
||
| 511 | 510 | // traiter les jobs morts au combat (_JQ_PENDING depuis plus de 180s) |
| 512 | 511 | // pour cause de timeout ou autre erreur fatale |
| 513 | 512 | $res = sql_allfetsel("*", "spip_jobs", |
| 514 | - "status=" . intval(_JQ_PENDING) . " AND date<" . sql_quote(date('Y-m-d H:i:s', $time - 180))); |
|
| 513 | + "status=".intval(_JQ_PENDING)." AND date<".sql_quote(date('Y-m-d H:i:s', $time - 180))); |
|
| 515 | 514 | if (is_array($res)) { |
| 516 | 515 | foreach ($res as $row) { |
| 517 | 516 | queue_close_job($row, $time); |
| 518 | - spip_log ("queue_close_job car _JQ_PENDING depuis +180s : ".print_r($row,1), "job_mort"._LOG_ERREUR); |
|
| 517 | + spip_log("queue_close_job car _JQ_PENDING depuis +180s : ".print_r($row, 1), "job_mort"._LOG_ERREUR); |
|
| 519 | 518 | } |
| 520 | 519 | } |
| 521 | 520 | |
| 522 | 521 | // chercher la date du prochain job si pas connu |
| 523 | 522 | if (is_null($next) or is_null(queue_sleep_time_to_next_job())) { |
| 524 | - $date = sql_getfetsel('date', 'spip_jobs', "status=" . intval(_JQ_SCHEDULED), '', 'date', '0,1'); |
|
| 523 | + $date = sql_getfetsel('date', 'spip_jobs', "status=".intval(_JQ_SCHEDULED), '', 'date', '0,1'); |
|
| 525 | 524 | $next = strtotime($date); |
| 526 | 525 | } |
| 527 | 526 | if (!is_null($next_time)) { |
@@ -533,7 +532,7 @@ discard block |
||
| 533 | 532 | if ($next) { |
| 534 | 533 | if (is_null($nb_jobs_scheduled)) { |
| 535 | 534 | $nb_jobs_scheduled = sql_countsel('spip_jobs', |
| 536 | - "status=" . intval(_JQ_SCHEDULED) . " AND date<" . sql_quote(date('Y-m-d H:i:s', $time))); |
|
| 535 | + "status=".intval(_JQ_SCHEDULED)." AND date<".sql_quote(date('Y-m-d H:i:s', $time))); |
|
| 537 | 536 | } elseif ($next <= $time) { |
| 538 | 537 | $nb_jobs_scheduled++; |
| 539 | 538 | } |
@@ -601,7 +600,7 @@ discard block |
||
| 601 | 600 | } |
| 602 | 601 | |
| 603 | 602 | // ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent |
| 604 | - if (file_exists($lock = _DIR_TMP . "cron.lock") and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) { |
|
| 603 | + if (file_exists($lock = _DIR_TMP."cron.lock") and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) { |
|
| 605 | 604 | return $texte; |
| 606 | 605 | } |
| 607 | 606 | |
@@ -672,20 +671,20 @@ discard block |
||
| 672 | 671 | $scheme = ''; |
| 673 | 672 | $port = 80; |
| 674 | 673 | } |
| 675 | - $fp = @fsockopen($scheme . $parts['host'], |
|
| 674 | + $fp = @fsockopen($scheme.$parts['host'], |
|
| 676 | 675 | isset($parts['port']) ? $parts['port'] : $port, |
| 677 | 676 | $errno, $errstr, 1); |
| 678 | 677 | |
| 679 | 678 | if ($fp) { |
| 680 | 679 | $host_sent = $parts['host']; |
| 681 | 680 | if (isset($parts['port']) and $parts['port'] !== $port) { |
| 682 | - $host_sent .= ':' . $parts['port']; |
|
| 681 | + $host_sent .= ':'.$parts['port']; |
|
| 683 | 682 | } |
| 684 | 683 | $timeout = 200; // ms |
| 685 | 684 | stream_set_timeout($fp, 0, $timeout * 1000); |
| 686 | - $query = $parts['path'] . ($parts['query'] ? "?" . $parts['query'] : ""); |
|
| 687 | - $out = "GET " . $query . " HTTP/1.1\r\n"; |
|
| 688 | - $out .= "Host: " . $host_sent . "\r\n"; |
|
| 685 | + $query = $parts['path'].($parts['query'] ? "?".$parts['query'] : ""); |
|
| 686 | + $out = "GET ".$query." HTTP/1.1\r\n"; |
|
| 687 | + $out .= "Host: ".$host_sent."\r\n"; |
|
| 689 | 688 | $out .= "Connection: Close\r\n\r\n"; |
| 690 | 689 | fwrite($fp, $out); |
| 691 | 690 | spip_timer('read'); |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Queue |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined("_ECRIRE_INC_VERSION")) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | define('_JQ_SCHEDULED', 1); |
@@ -50,98 +50,98 @@ discard block |
||
| 50 | 50 | * id of job |
| 51 | 51 | */ |
| 52 | 52 | function queue_add_job( |
| 53 | - $function, |
|
| 54 | - $description, |
|
| 55 | - $arguments = array(), |
|
| 56 | - $file = '', |
|
| 57 | - $no_duplicate = false, |
|
| 58 | - $time = 0, |
|
| 59 | - $priority = 0 |
|
| 53 | + $function, |
|
| 54 | + $description, |
|
| 55 | + $arguments = array(), |
|
| 56 | + $file = '', |
|
| 57 | + $no_duplicate = false, |
|
| 58 | + $time = 0, |
|
| 59 | + $priority = 0 |
|
| 60 | 60 | ) { |
| 61 | - include_spip('base/abstract_sql'); |
|
| 62 | - |
|
| 63 | - // cas pourri de ecrire/action/editer_site avec l'option reload=oui |
|
| 64 | - if (defined('_GENIE_SYNDIC_NOW')) { |
|
| 65 | - $arguments['id_syndic'] = _GENIE_SYNDIC_NOW; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - // serialiser les arguments |
|
| 69 | - $arguments = serialize($arguments); |
|
| 70 | - $md5args = md5($arguments); |
|
| 71 | - |
|
| 72 | - // si pas de date programee, des que possible |
|
| 73 | - $duplicate_where = 'status=' . intval(_JQ_SCHEDULED) . ' AND '; |
|
| 74 | - if (!$time) { |
|
| 75 | - $time = time(); |
|
| 76 | - $duplicate_where = ""; // ne pas dupliquer si deja le meme job en cours d'execution |
|
| 77 | - } |
|
| 78 | - $date = date('Y-m-d H:i:s', $time); |
|
| 79 | - |
|
| 80 | - $set_job = array( |
|
| 81 | - 'fonction' => $function, |
|
| 82 | - 'descriptif' => $description, |
|
| 83 | - 'args' => $arguments, |
|
| 84 | - 'md5args' => $md5args, |
|
| 85 | - 'inclure' => $file, |
|
| 86 | - 'priorite' => max(-10, min(10, intval($priority))), |
|
| 87 | - 'date' => $date, |
|
| 88 | - 'status' => _JQ_SCHEDULED, |
|
| 89 | - ); |
|
| 90 | - // si option ne pas dupliquer, regarder si la fonction existe deja |
|
| 91 | - // avec les memes args et file |
|
| 92 | - if ( |
|
| 93 | - $no_duplicate |
|
| 94 | - and |
|
| 95 | - $id_job = sql_getfetsel('id_job', 'spip_jobs', |
|
| 96 | - $duplicate_where = |
|
| 97 | - $duplicate_where . 'fonction=' . sql_quote($function) |
|
| 98 | - . (($no_duplicate === 'function_only') ? '' : |
|
| 99 | - ' AND md5args=' . sql_quote($md5args) . ' AND inclure=' . sql_quote($file))) |
|
| 100 | - ) { |
|
| 101 | - return $id_job; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $id_job = sql_insertq('spip_jobs', $set_job); |
|
| 105 | - // en cas de concurrence, deux process peuvent arriver jusqu'ici en parallele |
|
| 106 | - // avec le meme job unique a inserer. Dans ce cas, celui qui a eu l'id le plus grand |
|
| 107 | - // doit s'effacer |
|
| 108 | - if ( |
|
| 109 | - $no_duplicate |
|
| 110 | - and |
|
| 111 | - $id_prev = sql_getfetsel('id_job', 'spip_jobs', "id_job<" . intval($id_job) . " AND $duplicate_where") |
|
| 112 | - ) { |
|
| 113 | - sql_delete('spip_jobs', 'id_job=' . intval($id_job)); |
|
| 114 | - |
|
| 115 | - return $id_prev; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - // verifier la non duplication qui peut etre problematique en cas de concurence |
|
| 119 | - // il faut dans ce cas que seul le dernier ajoute se supprime ! |
|
| 120 | - |
|
| 121 | - // une option de debug pour verifier que les arguments en base sont bons |
|
| 122 | - // ie cas d'un char non acceptables sur certains type de champs |
|
| 123 | - // qui coupe la valeur |
|
| 124 | - if (defined('_JQ_INSERT_CHECK_ARGS') and $id_job) { |
|
| 125 | - $args = sql_getfetsel('args', 'spip_jobs', 'id_job=' . intval($id_job)); |
|
| 126 | - if ($args !== $arguments) { |
|
| 127 | - spip_log('arguments job errones / longueur ' . strlen($args) . " vs " . strlen($arguments) . ' / valeur : ' . var_export($arguments, |
|
| 128 | - true), 'queue'); |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - if ($id_job) { |
|
| 133 | - queue_update_next_job_time($time); |
|
| 134 | - } |
|
| 135 | - // si la mise en file d'attente du job echoue, |
|
| 136 | - // il ne faut pas perdre l'execution de la fonction |
|
| 137 | - // on la lance immediatement, c'est un fallback |
|
| 138 | - // sauf en cas d'upgrade necessaire (table spip_jobs inexistante) |
|
| 139 | - elseif ($GLOBALS['meta']['version_installee'] == $GLOBALS['spip_version_base']) { |
|
| 140 | - $set_job['id_job'] = 0; |
|
| 141 | - queue_start_job($set_job); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - return $id_job; |
|
| 61 | + include_spip('base/abstract_sql'); |
|
| 62 | + |
|
| 63 | + // cas pourri de ecrire/action/editer_site avec l'option reload=oui |
|
| 64 | + if (defined('_GENIE_SYNDIC_NOW')) { |
|
| 65 | + $arguments['id_syndic'] = _GENIE_SYNDIC_NOW; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + // serialiser les arguments |
|
| 69 | + $arguments = serialize($arguments); |
|
| 70 | + $md5args = md5($arguments); |
|
| 71 | + |
|
| 72 | + // si pas de date programee, des que possible |
|
| 73 | + $duplicate_where = 'status=' . intval(_JQ_SCHEDULED) . ' AND '; |
|
| 74 | + if (!$time) { |
|
| 75 | + $time = time(); |
|
| 76 | + $duplicate_where = ""; // ne pas dupliquer si deja le meme job en cours d'execution |
|
| 77 | + } |
|
| 78 | + $date = date('Y-m-d H:i:s', $time); |
|
| 79 | + |
|
| 80 | + $set_job = array( |
|
| 81 | + 'fonction' => $function, |
|
| 82 | + 'descriptif' => $description, |
|
| 83 | + 'args' => $arguments, |
|
| 84 | + 'md5args' => $md5args, |
|
| 85 | + 'inclure' => $file, |
|
| 86 | + 'priorite' => max(-10, min(10, intval($priority))), |
|
| 87 | + 'date' => $date, |
|
| 88 | + 'status' => _JQ_SCHEDULED, |
|
| 89 | + ); |
|
| 90 | + // si option ne pas dupliquer, regarder si la fonction existe deja |
|
| 91 | + // avec les memes args et file |
|
| 92 | + if ( |
|
| 93 | + $no_duplicate |
|
| 94 | + and |
|
| 95 | + $id_job = sql_getfetsel('id_job', 'spip_jobs', |
|
| 96 | + $duplicate_where = |
|
| 97 | + $duplicate_where . 'fonction=' . sql_quote($function) |
|
| 98 | + . (($no_duplicate === 'function_only') ? '' : |
|
| 99 | + ' AND md5args=' . sql_quote($md5args) . ' AND inclure=' . sql_quote($file))) |
|
| 100 | + ) { |
|
| 101 | + return $id_job; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $id_job = sql_insertq('spip_jobs', $set_job); |
|
| 105 | + // en cas de concurrence, deux process peuvent arriver jusqu'ici en parallele |
|
| 106 | + // avec le meme job unique a inserer. Dans ce cas, celui qui a eu l'id le plus grand |
|
| 107 | + // doit s'effacer |
|
| 108 | + if ( |
|
| 109 | + $no_duplicate |
|
| 110 | + and |
|
| 111 | + $id_prev = sql_getfetsel('id_job', 'spip_jobs', "id_job<" . intval($id_job) . " AND $duplicate_where") |
|
| 112 | + ) { |
|
| 113 | + sql_delete('spip_jobs', 'id_job=' . intval($id_job)); |
|
| 114 | + |
|
| 115 | + return $id_prev; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + // verifier la non duplication qui peut etre problematique en cas de concurence |
|
| 119 | + // il faut dans ce cas que seul le dernier ajoute se supprime ! |
|
| 120 | + |
|
| 121 | + // une option de debug pour verifier que les arguments en base sont bons |
|
| 122 | + // ie cas d'un char non acceptables sur certains type de champs |
|
| 123 | + // qui coupe la valeur |
|
| 124 | + if (defined('_JQ_INSERT_CHECK_ARGS') and $id_job) { |
|
| 125 | + $args = sql_getfetsel('args', 'spip_jobs', 'id_job=' . intval($id_job)); |
|
| 126 | + if ($args !== $arguments) { |
|
| 127 | + spip_log('arguments job errones / longueur ' . strlen($args) . " vs " . strlen($arguments) . ' / valeur : ' . var_export($arguments, |
|
| 128 | + true), 'queue'); |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + if ($id_job) { |
|
| 133 | + queue_update_next_job_time($time); |
|
| 134 | + } |
|
| 135 | + // si la mise en file d'attente du job echoue, |
|
| 136 | + // il ne faut pas perdre l'execution de la fonction |
|
| 137 | + // on la lance immediatement, c'est un fallback |
|
| 138 | + // sauf en cas d'upgrade necessaire (table spip_jobs inexistante) |
|
| 139 | + elseif ($GLOBALS['meta']['version_installee'] == $GLOBALS['spip_version_base']) { |
|
| 140 | + $set_job['id_job'] = 0; |
|
| 141 | + queue_start_job($set_job); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + return $id_job; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -150,11 +150,11 @@ discard block |
||
| 150 | 150 | * @return void |
| 151 | 151 | */ |
| 152 | 152 | function queue_purger() { |
| 153 | - include_spip('base/abstract_sql'); |
|
| 154 | - sql_delete('spip_jobs'); |
|
| 155 | - sql_delete("spip_jobs_liens", "id_job NOT IN (" . sql_get_select("id_job", "spip_jobs") . ")"); |
|
| 156 | - include_spip('inc/genie'); |
|
| 157 | - genie_queue_watch_dist(); |
|
| 153 | + include_spip('base/abstract_sql'); |
|
| 154 | + sql_delete('spip_jobs'); |
|
| 155 | + sql_delete("spip_jobs_liens", "id_job NOT IN (" . sql_get_select("id_job", "spip_jobs") . ")"); |
|
| 156 | + include_spip('inc/genie'); |
|
| 157 | + genie_queue_watch_dist(); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -165,23 +165,23 @@ discard block |
||
| 165 | 165 | * @return bool |
| 166 | 166 | */ |
| 167 | 167 | function queue_remove_job($id_job) { |
| 168 | - include_spip('base/abstract_sql'); |
|
| 169 | - |
|
| 170 | - if ($row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job=' . intval($id_job)) |
|
| 171 | - and $res = sql_delete('spip_jobs', 'id_job=' . intval($id_job)) |
|
| 172 | - ) { |
|
| 173 | - queue_unlink_job($id_job); |
|
| 174 | - // est-ce une tache cron qu'il faut relancer ? |
|
| 175 | - if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 176 | - // relancer avec les nouveaux arguments de temps |
|
| 177 | - include_spip('inc/genie'); |
|
| 178 | - // relancer avec la periode prevue |
|
| 179 | - queue_genie_replan_job($row['fonction'], $periode, strtotime($row['date'])); |
|
| 180 | - } |
|
| 181 | - queue_update_next_job_time(); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - return $res; |
|
| 168 | + include_spip('base/abstract_sql'); |
|
| 169 | + |
|
| 170 | + if ($row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job=' . intval($id_job)) |
|
| 171 | + and $res = sql_delete('spip_jobs', 'id_job=' . intval($id_job)) |
|
| 172 | + ) { |
|
| 173 | + queue_unlink_job($id_job); |
|
| 174 | + // est-ce une tache cron qu'il faut relancer ? |
|
| 175 | + if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 176 | + // relancer avec les nouveaux arguments de temps |
|
| 177 | + include_spip('inc/genie'); |
|
| 178 | + // relancer avec la periode prevue |
|
| 179 | + queue_genie_replan_job($row['fonction'], $periode, strtotime($row['date'])); |
|
| 180 | + } |
|
| 181 | + queue_update_next_job_time(); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + return $res; |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -194,18 +194,18 @@ discard block |
||
| 194 | 194 | * ou un tableau composé de tableaux simples pour lieur plusieurs objets en une fois |
| 195 | 195 | */ |
| 196 | 196 | function queue_link_job($id_job, $objets) { |
| 197 | - include_spip('base/abstract_sql'); |
|
| 198 | - |
|
| 199 | - if (is_array($objets) and count($objets)) { |
|
| 200 | - if (is_array(reset($objets))) { |
|
| 201 | - foreach ($objets as $k => $o) { |
|
| 202 | - $objets[$k]['id_job'] = $id_job; |
|
| 203 | - } |
|
| 204 | - sql_insertq_multi('spip_jobs_liens', $objets); |
|
| 205 | - } else { |
|
| 206 | - sql_insertq('spip_jobs_liens', array_merge(array('id_job' => $id_job), $objets)); |
|
| 207 | - } |
|
| 208 | - } |
|
| 197 | + include_spip('base/abstract_sql'); |
|
| 198 | + |
|
| 199 | + if (is_array($objets) and count($objets)) { |
|
| 200 | + if (is_array(reset($objets))) { |
|
| 201 | + foreach ($objets as $k => $o) { |
|
| 202 | + $objets[$k]['id_job'] = $id_job; |
|
| 203 | + } |
|
| 204 | + sql_insertq_multi('spip_jobs_liens', $objets); |
|
| 205 | + } else { |
|
| 206 | + sql_insertq('spip_jobs_liens', array_merge(array('id_job' => $id_job), $objets)); |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | * resultat du sql_delete |
| 218 | 218 | */ |
| 219 | 219 | function queue_unlink_job($id_job) { |
| 220 | - return sql_delete("spip_jobs_liens", "id_job=" . intval($id_job)); |
|
| 220 | + return sql_delete("spip_jobs_liens", "id_job=" . intval($id_job)); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | /** |
@@ -230,74 +230,74 @@ discard block |
||
| 230 | 230 | */ |
| 231 | 231 | function queue_start_job($row) { |
| 232 | 232 | |
| 233 | - // deserialiser les arguments |
|
| 234 | - $args = unserialize($row['args']); |
|
| 235 | - if ($args === false) { |
|
| 236 | - spip_log('arguments job errones ' . var_export($row, true), 'queue'); |
|
| 237 | - $args = array(); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - $fonction = $row['fonction']; |
|
| 241 | - if (strlen($inclure = trim($row['inclure']))) { |
|
| 242 | - if (substr($inclure, -1) == '/') { // c'est un chemin pour charger_fonction |
|
| 243 | - $f = charger_fonction($fonction, rtrim($inclure, '/'), false); |
|
| 244 | - if ($f) { |
|
| 245 | - $fonction = $f; |
|
| 246 | - } |
|
| 247 | - } else { |
|
| 248 | - include_spip($inclure); |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - if (!function_exists($fonction)) { |
|
| 253 | - spip_log("fonction $fonction ($inclure) inexistante " . var_export($row, true), 'queue'); |
|
| 254 | - |
|
| 255 | - return false; |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - spip_log("queue [" . $row['id_job'] . "]: $fonction() start", 'queue'); |
|
| 259 | - switch (count($args)) { |
|
| 260 | - case 0: |
|
| 261 | - $res = $fonction(); |
|
| 262 | - break; |
|
| 263 | - case 1: |
|
| 264 | - $res = $fonction($args[0]); |
|
| 265 | - break; |
|
| 266 | - case 2: |
|
| 267 | - $res = $fonction($args[0], $args[1]); |
|
| 268 | - break; |
|
| 269 | - case 3: |
|
| 270 | - $res = $fonction($args[0], $args[1], $args[2]); |
|
| 271 | - break; |
|
| 272 | - case 4: |
|
| 273 | - $res = $fonction($args[0], $args[1], $args[2], $args[3]); |
|
| 274 | - break; |
|
| 275 | - case 5: |
|
| 276 | - $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4]); |
|
| 277 | - break; |
|
| 278 | - case 6: |
|
| 279 | - $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]); |
|
| 280 | - break; |
|
| 281 | - case 7: |
|
| 282 | - $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6]); |
|
| 283 | - break; |
|
| 284 | - case 8: |
|
| 285 | - $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7]); |
|
| 286 | - break; |
|
| 287 | - case 9: |
|
| 288 | - $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8]); |
|
| 289 | - break; |
|
| 290 | - case 10: |
|
| 291 | - $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8], |
|
| 292 | - $args[9]); |
|
| 293 | - break; |
|
| 294 | - default: |
|
| 295 | - # plus lent mais completement generique |
|
| 296 | - $res = call_user_func_array($fonction, $args); |
|
| 297 | - } |
|
| 298 | - spip_log("queue [" . $row['id_job'] . "]: $fonction() end", 'queue'); |
|
| 299 | - |
|
| 300 | - return $res; |
|
| 233 | + // deserialiser les arguments |
|
| 234 | + $args = unserialize($row['args']); |
|
| 235 | + if ($args === false) { |
|
| 236 | + spip_log('arguments job errones ' . var_export($row, true), 'queue'); |
|
| 237 | + $args = array(); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + $fonction = $row['fonction']; |
|
| 241 | + if (strlen($inclure = trim($row['inclure']))) { |
|
| 242 | + if (substr($inclure, -1) == '/') { // c'est un chemin pour charger_fonction |
|
| 243 | + $f = charger_fonction($fonction, rtrim($inclure, '/'), false); |
|
| 244 | + if ($f) { |
|
| 245 | + $fonction = $f; |
|
| 246 | + } |
|
| 247 | + } else { |
|
| 248 | + include_spip($inclure); |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + if (!function_exists($fonction)) { |
|
| 253 | + spip_log("fonction $fonction ($inclure) inexistante " . var_export($row, true), 'queue'); |
|
| 254 | + |
|
| 255 | + return false; |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + spip_log("queue [" . $row['id_job'] . "]: $fonction() start", 'queue'); |
|
| 259 | + switch (count($args)) { |
|
| 260 | + case 0: |
|
| 261 | + $res = $fonction(); |
|
| 262 | + break; |
|
| 263 | + case 1: |
|
| 264 | + $res = $fonction($args[0]); |
|
| 265 | + break; |
|
| 266 | + case 2: |
|
| 267 | + $res = $fonction($args[0], $args[1]); |
|
| 268 | + break; |
|
| 269 | + case 3: |
|
| 270 | + $res = $fonction($args[0], $args[1], $args[2]); |
|
| 271 | + break; |
|
| 272 | + case 4: |
|
| 273 | + $res = $fonction($args[0], $args[1], $args[2], $args[3]); |
|
| 274 | + break; |
|
| 275 | + case 5: |
|
| 276 | + $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4]); |
|
| 277 | + break; |
|
| 278 | + case 6: |
|
| 279 | + $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]); |
|
| 280 | + break; |
|
| 281 | + case 7: |
|
| 282 | + $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6]); |
|
| 283 | + break; |
|
| 284 | + case 8: |
|
| 285 | + $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7]); |
|
| 286 | + break; |
|
| 287 | + case 9: |
|
| 288 | + $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8]); |
|
| 289 | + break; |
|
| 290 | + case 10: |
|
| 291 | + $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8], |
|
| 292 | + $args[9]); |
|
| 293 | + break; |
|
| 294 | + default: |
|
| 295 | + # plus lent mais completement generique |
|
| 296 | + $res = call_user_func_array($fonction, $args); |
|
| 297 | + } |
|
| 298 | + spip_log("queue [" . $row['id_job'] . "]: $fonction() end", 'queue'); |
|
| 299 | + |
|
| 300 | + return $res; |
|
| 301 | 301 | |
| 302 | 302 | } |
| 303 | 303 | |
@@ -325,89 +325,89 @@ discard block |
||
| 325 | 325 | * - true : une planification a été faite. |
| 326 | 326 | */ |
| 327 | 327 | function queue_schedule($force_jobs = null) { |
| 328 | - $time = time(); |
|
| 329 | - if (defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 330 | - spip_log("_DEBUG_BLOCK_QUEUE : schedule stop", 'jq' . _LOG_DEBUG); |
|
| 331 | - |
|
| 332 | - return; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - // rien a faire si le prochain job est encore dans le futur |
|
| 336 | - if (queue_sleep_time_to_next_job() > 0 and (!$force_jobs or !count($force_jobs))) { |
|
| 337 | - spip_log("queue_sleep_time_to_next_job", 'jq' . _LOG_DEBUG); |
|
| 338 | - |
|
| 339 | - return; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - include_spip('base/abstract_sql'); |
|
| 343 | - // on ne peut rien faire si pas de connexion SQL |
|
| 344 | - if (!spip_connect()) { |
|
| 345 | - return false; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - if (!defined('_JQ_MAX_JOBS_TIME_TO_EXECUTE')) { |
|
| 349 | - $max_time = ini_get('max_execution_time') / 2; |
|
| 350 | - // valeur conservatrice si on a pas reussi a lire le max_execution_time |
|
| 351 | - if (!$max_time) { |
|
| 352 | - $max_time = 5; |
|
| 353 | - } |
|
| 354 | - define('_JQ_MAX_JOBS_TIME_TO_EXECUTE', min($max_time, 15)); // une valeur maxi en temps. |
|
| 355 | - } |
|
| 356 | - $end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE; |
|
| 357 | - |
|
| 358 | - spip_log("JQ schedule $time / $end_time", 'jq' . _LOG_DEBUG); |
|
| 359 | - |
|
| 360 | - if (!defined('_JQ_MAX_JOBS_EXECUTE')) { |
|
| 361 | - define('_JQ_MAX_JOBS_EXECUTE', 200); |
|
| 362 | - } |
|
| 363 | - $nbj = 0; |
|
| 364 | - // attraper les jobs |
|
| 365 | - // dont la date est passee (echus en attente), |
|
| 366 | - // par ordre : |
|
| 367 | - // - de priorite |
|
| 368 | - // - de date |
|
| 369 | - // lorsqu'un job cron n'a pas fini, sa priorite est descendue |
|
| 370 | - // pour qu'il ne bloque pas les autres jobs en attente |
|
| 371 | - if (is_array($force_jobs) and count($force_jobs)) { |
|
| 372 | - $cond = "status=" . intval(_JQ_SCHEDULED) . " AND " . sql_in("id_job", $force_jobs); |
|
| 373 | - } else { |
|
| 374 | - $now = date('Y-m-d H:i:s', $time); |
|
| 375 | - $cond = "status=" . intval(_JQ_SCHEDULED) . " AND date<=" . sql_quote($now); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible |
|
| 379 | - $res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,' . (_JQ_MAX_JOBS_EXECUTE + 1)); |
|
| 380 | - do { |
|
| 381 | - if ($row = array_shift($res)) { |
|
| 382 | - $nbj++; |
|
| 383 | - // il faut un verrou, a base de sql_delete |
|
| 384 | - if (sql_delete('spip_jobs', "id_job=" . intval($row['id_job']) . " AND status=" . intval(_JQ_SCHEDULED))) { |
|
| 385 | - #spip_log("JQ schedule job ".$nbj." OK",'jq'); |
|
| 386 | - // on reinsert dans la base aussitot avec un status=_JQ_PENDING |
|
| 387 | - $row['status'] = _JQ_PENDING; |
|
| 388 | - $row['date'] = date('Y-m-d H:i:s', $time); |
|
| 389 | - sql_insertq('spip_jobs', $row); |
|
| 390 | - |
|
| 391 | - // on a la main sur le job : |
|
| 392 | - // l'executer |
|
| 393 | - $result = queue_start_job($row); |
|
| 394 | - |
|
| 395 | - $time = time(); |
|
| 396 | - queue_close_job($row, $time, $result); |
|
| 397 | - } |
|
| 398 | - } |
|
| 399 | - spip_log("JQ schedule job end time " . $time, 'jq' . _LOG_DEBUG); |
|
| 400 | - } while ($nbj < _JQ_MAX_JOBS_EXECUTE and $row and $time < $end_time); |
|
| 401 | - spip_log("JQ schedule end time " . time(), 'jq' . _LOG_DEBUG); |
|
| 402 | - |
|
| 403 | - if ($row = array_shift($res)) { |
|
| 404 | - queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP |
|
| 405 | - spip_log("JQ encore !", 'jq' . _LOG_DEBUG); |
|
| 406 | - } else { |
|
| 407 | - queue_update_next_job_time(); |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - return true; |
|
| 328 | + $time = time(); |
|
| 329 | + if (defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 330 | + spip_log("_DEBUG_BLOCK_QUEUE : schedule stop", 'jq' . _LOG_DEBUG); |
|
| 331 | + |
|
| 332 | + return; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + // rien a faire si le prochain job est encore dans le futur |
|
| 336 | + if (queue_sleep_time_to_next_job() > 0 and (!$force_jobs or !count($force_jobs))) { |
|
| 337 | + spip_log("queue_sleep_time_to_next_job", 'jq' . _LOG_DEBUG); |
|
| 338 | + |
|
| 339 | + return; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + include_spip('base/abstract_sql'); |
|
| 343 | + // on ne peut rien faire si pas de connexion SQL |
|
| 344 | + if (!spip_connect()) { |
|
| 345 | + return false; |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + if (!defined('_JQ_MAX_JOBS_TIME_TO_EXECUTE')) { |
|
| 349 | + $max_time = ini_get('max_execution_time') / 2; |
|
| 350 | + // valeur conservatrice si on a pas reussi a lire le max_execution_time |
|
| 351 | + if (!$max_time) { |
|
| 352 | + $max_time = 5; |
|
| 353 | + } |
|
| 354 | + define('_JQ_MAX_JOBS_TIME_TO_EXECUTE', min($max_time, 15)); // une valeur maxi en temps. |
|
| 355 | + } |
|
| 356 | + $end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE; |
|
| 357 | + |
|
| 358 | + spip_log("JQ schedule $time / $end_time", 'jq' . _LOG_DEBUG); |
|
| 359 | + |
|
| 360 | + if (!defined('_JQ_MAX_JOBS_EXECUTE')) { |
|
| 361 | + define('_JQ_MAX_JOBS_EXECUTE', 200); |
|
| 362 | + } |
|
| 363 | + $nbj = 0; |
|
| 364 | + // attraper les jobs |
|
| 365 | + // dont la date est passee (echus en attente), |
|
| 366 | + // par ordre : |
|
| 367 | + // - de priorite |
|
| 368 | + // - de date |
|
| 369 | + // lorsqu'un job cron n'a pas fini, sa priorite est descendue |
|
| 370 | + // pour qu'il ne bloque pas les autres jobs en attente |
|
| 371 | + if (is_array($force_jobs) and count($force_jobs)) { |
|
| 372 | + $cond = "status=" . intval(_JQ_SCHEDULED) . " AND " . sql_in("id_job", $force_jobs); |
|
| 373 | + } else { |
|
| 374 | + $now = date('Y-m-d H:i:s', $time); |
|
| 375 | + $cond = "status=" . intval(_JQ_SCHEDULED) . " AND date<=" . sql_quote($now); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible |
|
| 379 | + $res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,' . (_JQ_MAX_JOBS_EXECUTE + 1)); |
|
| 380 | + do { |
|
| 381 | + if ($row = array_shift($res)) { |
|
| 382 | + $nbj++; |
|
| 383 | + // il faut un verrou, a base de sql_delete |
|
| 384 | + if (sql_delete('spip_jobs', "id_job=" . intval($row['id_job']) . " AND status=" . intval(_JQ_SCHEDULED))) { |
|
| 385 | + #spip_log("JQ schedule job ".$nbj." OK",'jq'); |
|
| 386 | + // on reinsert dans la base aussitot avec un status=_JQ_PENDING |
|
| 387 | + $row['status'] = _JQ_PENDING; |
|
| 388 | + $row['date'] = date('Y-m-d H:i:s', $time); |
|
| 389 | + sql_insertq('spip_jobs', $row); |
|
| 390 | + |
|
| 391 | + // on a la main sur le job : |
|
| 392 | + // l'executer |
|
| 393 | + $result = queue_start_job($row); |
|
| 394 | + |
|
| 395 | + $time = time(); |
|
| 396 | + queue_close_job($row, $time, $result); |
|
| 397 | + } |
|
| 398 | + } |
|
| 399 | + spip_log("JQ schedule job end time " . $time, 'jq' . _LOG_DEBUG); |
|
| 400 | + } while ($nbj < _JQ_MAX_JOBS_EXECUTE and $row and $time < $end_time); |
|
| 401 | + spip_log("JQ schedule end time " . time(), 'jq' . _LOG_DEBUG); |
|
| 402 | + |
|
| 403 | + if ($row = array_shift($res)) { |
|
| 404 | + queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP |
|
| 405 | + spip_log("JQ encore !", 'jq' . _LOG_DEBUG); |
|
| 406 | + } else { |
|
| 407 | + queue_update_next_job_time(); |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + return true; |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | /** |
@@ -425,22 +425,22 @@ discard block |
||
| 425 | 425 | * @param int $result |
| 426 | 426 | */ |
| 427 | 427 | function queue_close_job(&$row, $time, $result = 0) { |
| 428 | - // est-ce une tache cron qu'il faut relancer ? |
|
| 429 | - if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 430 | - // relancer avec les nouveaux arguments de temps |
|
| 431 | - include_spip('inc/genie'); |
|
| 432 | - if ($result < 0) // relancer tout de suite, mais en baissant la priorite |
|
| 433 | - { |
|
| 434 | - queue_genie_replan_job($row['fonction'], $periode, 0 - $result, null, $row['priorite'] - 1); |
|
| 435 | - } else // relancer avec la periode prevue |
|
| 436 | - { |
|
| 437 | - queue_genie_replan_job($row['fonction'], $periode, $time); |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - // purger ses liens eventuels avec des objets |
|
| 441 | - sql_delete("spip_jobs_liens", "id_job=" . intval($row['id_job'])); |
|
| 442 | - // supprimer le job fini |
|
| 443 | - sql_delete('spip_jobs', 'id_job=' . intval($row['id_job'])); |
|
| 428 | + // est-ce une tache cron qu'il faut relancer ? |
|
| 429 | + if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 430 | + // relancer avec les nouveaux arguments de temps |
|
| 431 | + include_spip('inc/genie'); |
|
| 432 | + if ($result < 0) // relancer tout de suite, mais en baissant la priorite |
|
| 433 | + { |
|
| 434 | + queue_genie_replan_job($row['fonction'], $periode, 0 - $result, null, $row['priorite'] - 1); |
|
| 435 | + } else // relancer avec la periode prevue |
|
| 436 | + { |
|
| 437 | + queue_genie_replan_job($row['fonction'], $periode, $time); |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + // purger ses liens eventuels avec des objets |
|
| 441 | + sql_delete("spip_jobs_liens", "id_job=" . intval($row['id_job'])); |
|
| 442 | + // supprimer le job fini |
|
| 443 | + sql_delete('spip_jobs', 'id_job=' . intval($row['id_job'])); |
|
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | /** |
@@ -450,10 +450,10 @@ discard block |
||
| 450 | 450 | * @uses queue_update_next_job_time() |
| 451 | 451 | */ |
| 452 | 452 | function queue_error_handler() { |
| 453 | - // se remettre dans le bon dossier, car Apache le change parfois (toujours?) |
|
| 454 | - chdir(_ROOT_CWD); |
|
| 453 | + // se remettre dans le bon dossier, car Apache le change parfois (toujours?) |
|
| 454 | + chdir(_ROOT_CWD); |
|
| 455 | 455 | |
| 456 | - queue_update_next_job_time(); |
|
| 456 | + queue_update_next_job_time(); |
|
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | |
@@ -470,18 +470,18 @@ discard block |
||
| 470 | 470 | * Périodicité de la tâche en secondes, si tâche périodique, sinon false. |
| 471 | 471 | */ |
| 472 | 472 | function queue_is_cron_job($function, $inclure) { |
| 473 | - static $taches = null; |
|
| 474 | - if (strncmp($inclure, 'genie/', 6) == 0) { |
|
| 475 | - if (is_null($taches)) { |
|
| 476 | - include_spip('inc/genie'); |
|
| 477 | - $taches = taches_generales(); |
|
| 478 | - } |
|
| 479 | - if (isset($taches[$function])) { |
|
| 480 | - return $taches[$function]; |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - return false; |
|
| 473 | + static $taches = null; |
|
| 474 | + if (strncmp($inclure, 'genie/', 6) == 0) { |
|
| 475 | + if (is_null($taches)) { |
|
| 476 | + include_spip('inc/genie'); |
|
| 477 | + $taches = taches_generales(); |
|
| 478 | + } |
|
| 479 | + if (isset($taches[$function])) { |
|
| 480 | + return $taches[$function]; |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + return false; |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | /** |
@@ -495,57 +495,57 @@ discard block |
||
| 495 | 495 | * temps de la tache ajoutee ou 0 pour ASAP |
| 496 | 496 | */ |
| 497 | 497 | function queue_update_next_job_time($next_time = null) { |
| 498 | - static $nb_jobs_scheduled = null; |
|
| 499 | - static $deja_la = false; |
|
| 500 | - // prendre le min des $next_time que l'on voit passer ici, en cas de reentrance |
|
| 501 | - static $next = null; |
|
| 502 | - // queue_close_job peut etre reentrant ici |
|
| 503 | - if ($deja_la) { |
|
| 504 | - return; |
|
| 505 | - } |
|
| 506 | - $deja_la = true; |
|
| 507 | - |
|
| 508 | - include_spip('base/abstract_sql'); |
|
| 509 | - $time = time(); |
|
| 510 | - |
|
| 511 | - // traiter les jobs morts au combat (_JQ_PENDING depuis plus de 180s) |
|
| 512 | - // pour cause de timeout ou autre erreur fatale |
|
| 513 | - $res = sql_allfetsel("*", "spip_jobs", |
|
| 514 | - "status=" . intval(_JQ_PENDING) . " AND date<" . sql_quote(date('Y-m-d H:i:s', $time - 180))); |
|
| 515 | - if (is_array($res)) { |
|
| 516 | - foreach ($res as $row) { |
|
| 517 | - queue_close_job($row, $time); |
|
| 518 | - spip_log ("queue_close_job car _JQ_PENDING depuis +180s : ".print_r($row,1), "job_mort"._LOG_ERREUR); |
|
| 519 | - } |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - // chercher la date du prochain job si pas connu |
|
| 523 | - if (is_null($next) or is_null(queue_sleep_time_to_next_job())) { |
|
| 524 | - $date = sql_getfetsel('date', 'spip_jobs', "status=" . intval(_JQ_SCHEDULED), '', 'date', '0,1'); |
|
| 525 | - $next = strtotime($date); |
|
| 526 | - } |
|
| 527 | - if (!is_null($next_time)) { |
|
| 528 | - if (is_null($next) or $next > $next_time) { |
|
| 529 | - $next = $next_time; |
|
| 530 | - } |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - if ($next) { |
|
| 534 | - if (is_null($nb_jobs_scheduled)) { |
|
| 535 | - $nb_jobs_scheduled = sql_countsel('spip_jobs', |
|
| 536 | - "status=" . intval(_JQ_SCHEDULED) . " AND date<" . sql_quote(date('Y-m-d H:i:s', $time))); |
|
| 537 | - } elseif ($next <= $time) { |
|
| 538 | - $nb_jobs_scheduled++; |
|
| 539 | - } |
|
| 540 | - // si trop de jobs en attente, on force la purge en fin de hit |
|
| 541 | - // pour assurer le coup |
|
| 542 | - if ($nb_jobs_scheduled > (defined('_JQ_NB_JOBS_OVERFLOW') ? _JQ_NB_JOBS_OVERFLOW : 10000)) { |
|
| 543 | - define('_DIRECT_CRON_FORCE', true); |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - queue_set_next_job_time($next); |
|
| 548 | - $deja_la = false; |
|
| 498 | + static $nb_jobs_scheduled = null; |
|
| 499 | + static $deja_la = false; |
|
| 500 | + // prendre le min des $next_time que l'on voit passer ici, en cas de reentrance |
|
| 501 | + static $next = null; |
|
| 502 | + // queue_close_job peut etre reentrant ici |
|
| 503 | + if ($deja_la) { |
|
| 504 | + return; |
|
| 505 | + } |
|
| 506 | + $deja_la = true; |
|
| 507 | + |
|
| 508 | + include_spip('base/abstract_sql'); |
|
| 509 | + $time = time(); |
|
| 510 | + |
|
| 511 | + // traiter les jobs morts au combat (_JQ_PENDING depuis plus de 180s) |
|
| 512 | + // pour cause de timeout ou autre erreur fatale |
|
| 513 | + $res = sql_allfetsel("*", "spip_jobs", |
|
| 514 | + "status=" . intval(_JQ_PENDING) . " AND date<" . sql_quote(date('Y-m-d H:i:s', $time - 180))); |
|
| 515 | + if (is_array($res)) { |
|
| 516 | + foreach ($res as $row) { |
|
| 517 | + queue_close_job($row, $time); |
|
| 518 | + spip_log ("queue_close_job car _JQ_PENDING depuis +180s : ".print_r($row,1), "job_mort"._LOG_ERREUR); |
|
| 519 | + } |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + // chercher la date du prochain job si pas connu |
|
| 523 | + if (is_null($next) or is_null(queue_sleep_time_to_next_job())) { |
|
| 524 | + $date = sql_getfetsel('date', 'spip_jobs', "status=" . intval(_JQ_SCHEDULED), '', 'date', '0,1'); |
|
| 525 | + $next = strtotime($date); |
|
| 526 | + } |
|
| 527 | + if (!is_null($next_time)) { |
|
| 528 | + if (is_null($next) or $next > $next_time) { |
|
| 529 | + $next = $next_time; |
|
| 530 | + } |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + if ($next) { |
|
| 534 | + if (is_null($nb_jobs_scheduled)) { |
|
| 535 | + $nb_jobs_scheduled = sql_countsel('spip_jobs', |
|
| 536 | + "status=" . intval(_JQ_SCHEDULED) . " AND date<" . sql_quote(date('Y-m-d H:i:s', $time))); |
|
| 537 | + } elseif ($next <= $time) { |
|
| 538 | + $nb_jobs_scheduled++; |
|
| 539 | + } |
|
| 540 | + // si trop de jobs en attente, on force la purge en fin de hit |
|
| 541 | + // pour assurer le coup |
|
| 542 | + if ($nb_jobs_scheduled > (defined('_JQ_NB_JOBS_OVERFLOW') ? _JQ_NB_JOBS_OVERFLOW : 10000)) { |
|
| 543 | + define('_DIRECT_CRON_FORCE', true); |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + queue_set_next_job_time($next); |
|
| 548 | + $deja_la = false; |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | |
@@ -556,26 +556,26 @@ discard block |
||
| 556 | 556 | */ |
| 557 | 557 | function queue_set_next_job_time($next) { |
| 558 | 558 | |
| 559 | - // utiliser le temps courant reel plutot que temps de la requete ici |
|
| 560 | - $time = time(); |
|
| 561 | - |
|
| 562 | - // toujours relire la valeur pour comparer, pour tenir compte des maj concourrantes |
|
| 563 | - // et ne mettre a jour que si il y a un interet a le faire |
|
| 564 | - // permet ausis d'initialiser le nom de fichier a coup sur |
|
| 565 | - $curr_next = $_SERVER['REQUEST_TIME'] + max(0, queue_sleep_time_to_next_job(true)); |
|
| 566 | - if ( |
|
| 567 | - ($curr_next <= $time and $next > $time) // le prochain job est dans le futur mais pas la date planifiee actuelle |
|
| 568 | - or $curr_next > $next // le prochain job est plus tot que la date planifiee actuelle |
|
| 569 | - ) { |
|
| 570 | - if (function_exists("cache_set") and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) { |
|
| 571 | - cache_set(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 572 | - } else { |
|
| 573 | - ecrire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 574 | - } |
|
| 575 | - queue_sleep_time_to_next_job($next); |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - return queue_sleep_time_to_next_job(); |
|
| 559 | + // utiliser le temps courant reel plutot que temps de la requete ici |
|
| 560 | + $time = time(); |
|
| 561 | + |
|
| 562 | + // toujours relire la valeur pour comparer, pour tenir compte des maj concourrantes |
|
| 563 | + // et ne mettre a jour que si il y a un interet a le faire |
|
| 564 | + // permet ausis d'initialiser le nom de fichier a coup sur |
|
| 565 | + $curr_next = $_SERVER['REQUEST_TIME'] + max(0, queue_sleep_time_to_next_job(true)); |
|
| 566 | + if ( |
|
| 567 | + ($curr_next <= $time and $next > $time) // le prochain job est dans le futur mais pas la date planifiee actuelle |
|
| 568 | + or $curr_next > $next // le prochain job est plus tot que la date planifiee actuelle |
|
| 569 | + ) { |
|
| 570 | + if (function_exists("cache_set") and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) { |
|
| 571 | + cache_set(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 572 | + } else { |
|
| 573 | + ecrire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 574 | + } |
|
| 575 | + queue_sleep_time_to_next_job($next); |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + return queue_sleep_time_to_next_job(); |
|
| 579 | 579 | } |
| 580 | 580 | |
| 581 | 581 | /** |
@@ -592,62 +592,62 @@ discard block |
||
| 592 | 592 | * @return string |
| 593 | 593 | */ |
| 594 | 594 | function queue_affichage_cron() { |
| 595 | - $texte = ""; |
|
| 596 | - |
|
| 597 | - $time_to_next = queue_sleep_time_to_next_job(); |
|
| 598 | - // rien a faire si le prochain job est encore dans le futur |
|
| 599 | - if ($time_to_next > 0 or defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 600 | - return $texte; |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - // ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent |
|
| 604 | - if (file_exists($lock = _DIR_TMP . "cron.lock") and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) { |
|
| 605 | - return $texte; |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - @touch($lock); |
|
| 609 | - |
|
| 610 | - // il y a des taches en attentes |
|
| 611 | - // si depuis plus de 5min, on essaye de lancer le cron par tous les moyens pour rattraper le coup |
|
| 612 | - // on est sans doute sur un site qui n'autorise pas http sortant ou avec peu de trafic |
|
| 613 | - $urgent = false; |
|
| 614 | - if ($time_to_next < -300) { |
|
| 615 | - $urgent = true; |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - $url_cron = generer_url_action('cron', '', false, true); |
|
| 619 | - |
|
| 620 | - if (!defined('_HTML_BG_CRON_FORCE') or !_HTML_BG_CRON_FORCE) { |
|
| 621 | - |
|
| 622 | - if (queue_lancer_url_http_async($url_cron) and !$urgent) { |
|
| 623 | - return $texte; |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - // si deja force, on retourne sans rien |
|
| 629 | - if (defined('_DIRECT_CRON_FORCE')) { |
|
| 630 | - return $texte; |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - // si c'est un bot |
|
| 634 | - // inutile de faire un appel par image background, |
|
| 635 | - // on force un appel direct en fin de hit |
|
| 636 | - if ((defined('_IS_BOT') and _IS_BOT)) { |
|
| 637 | - define('_DIRECT_CRON_FORCE', true); |
|
| 638 | - |
|
| 639 | - return $texte; |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - if (!defined('_HTML_BG_CRON_INHIB') or !_HTML_BG_CRON_INHIB) { |
|
| 643 | - // en derniere solution, on insere un appel xhr non bloquant ou une image background dans la page si pas de JS |
|
| 644 | - $url_cron = generer_url_action('cron'); |
|
| 645 | - $texte = '<!-- SPIP-CRON -->' |
|
| 646 | - . "<script>setTimeout(function(){var xo = new XMLHttpRequest();xo.open('GET', '$url_cron', true);xo.send('');},100);</script>" |
|
| 647 | - . "<noscript><div style=\"background-image: url('$url_cron');\"></div></noscript>"; |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - return $texte; |
|
| 595 | + $texte = ""; |
|
| 596 | + |
|
| 597 | + $time_to_next = queue_sleep_time_to_next_job(); |
|
| 598 | + // rien a faire si le prochain job est encore dans le futur |
|
| 599 | + if ($time_to_next > 0 or defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 600 | + return $texte; |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + // ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent |
|
| 604 | + if (file_exists($lock = _DIR_TMP . "cron.lock") and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) { |
|
| 605 | + return $texte; |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + @touch($lock); |
|
| 609 | + |
|
| 610 | + // il y a des taches en attentes |
|
| 611 | + // si depuis plus de 5min, on essaye de lancer le cron par tous les moyens pour rattraper le coup |
|
| 612 | + // on est sans doute sur un site qui n'autorise pas http sortant ou avec peu de trafic |
|
| 613 | + $urgent = false; |
|
| 614 | + if ($time_to_next < -300) { |
|
| 615 | + $urgent = true; |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + $url_cron = generer_url_action('cron', '', false, true); |
|
| 619 | + |
|
| 620 | + if (!defined('_HTML_BG_CRON_FORCE') or !_HTML_BG_CRON_FORCE) { |
|
| 621 | + |
|
| 622 | + if (queue_lancer_url_http_async($url_cron) and !$urgent) { |
|
| 623 | + return $texte; |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + // si deja force, on retourne sans rien |
|
| 629 | + if (defined('_DIRECT_CRON_FORCE')) { |
|
| 630 | + return $texte; |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + // si c'est un bot |
|
| 634 | + // inutile de faire un appel par image background, |
|
| 635 | + // on force un appel direct en fin de hit |
|
| 636 | + if ((defined('_IS_BOT') and _IS_BOT)) { |
|
| 637 | + define('_DIRECT_CRON_FORCE', true); |
|
| 638 | + |
|
| 639 | + return $texte; |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + if (!defined('_HTML_BG_CRON_INHIB') or !_HTML_BG_CRON_INHIB) { |
|
| 643 | + // en derniere solution, on insere un appel xhr non bloquant ou une image background dans la page si pas de JS |
|
| 644 | + $url_cron = generer_url_action('cron'); |
|
| 645 | + $texte = '<!-- SPIP-CRON -->' |
|
| 646 | + . "<script>setTimeout(function(){var xo = new XMLHttpRequest();xo.open('GET', '$url_cron', true);xo.send('');},100);</script>" |
|
| 647 | + . "<noscript><div style=\"background-image: url('$url_cron');\"></div></noscript>"; |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + return $texte; |
|
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | /** |
@@ -656,69 +656,69 @@ discard block |
||
| 656 | 656 | * @return bool : true si l'url a pu être appelée en asynchrone, false sinon |
| 657 | 657 | */ |
| 658 | 658 | function queue_lancer_url_http_async($url_cron) { |
| 659 | - // methode la plus rapide : |
|
| 660 | - // Si fsockopen est possible, on lance le cron via un socket en asynchrone |
|
| 661 | - // si fsockopen echoue (disponibilite serveur, firewall) on essaye pas cURL |
|
| 662 | - // car on a toutes les chances d'echouer pareil mais sans moyen de le savoir |
|
| 663 | - // mais on renvoie false direct |
|
| 664 | - if (function_exists('fsockopen')) { |
|
| 665 | - $parts = parse_url($url_cron); |
|
| 666 | - |
|
| 667 | - switch ($parts['scheme']) { |
|
| 668 | - case 'https': |
|
| 669 | - $scheme = 'ssl://'; |
|
| 670 | - $port = 443; |
|
| 671 | - break; |
|
| 672 | - case 'http': |
|
| 673 | - default: |
|
| 674 | - $scheme = ''; |
|
| 675 | - $port = 80; |
|
| 676 | - } |
|
| 677 | - $fp = @fsockopen($scheme . $parts['host'], |
|
| 678 | - isset($parts['port']) ? $parts['port'] : $port, |
|
| 679 | - $errno, $errstr, 1); |
|
| 680 | - |
|
| 681 | - if ($fp) { |
|
| 682 | - $host_sent = $parts['host']; |
|
| 683 | - if (isset($parts['port']) and $parts['port'] !== $port) { |
|
| 684 | - $host_sent .= ':' . $parts['port']; |
|
| 685 | - } |
|
| 686 | - $timeout = 200; // ms |
|
| 687 | - stream_set_timeout($fp, 0, $timeout * 1000); |
|
| 688 | - $query = $parts['path'] . ($parts['query'] ? "?" . $parts['query'] : ""); |
|
| 689 | - $out = "GET " . $query . " HTTP/1.1\r\n"; |
|
| 690 | - $out .= "Host: " . $host_sent . "\r\n"; |
|
| 691 | - $out .= "Connection: Close\r\n\r\n"; |
|
| 692 | - fwrite($fp, $out); |
|
| 693 | - spip_timer('read'); |
|
| 694 | - $t = 0; |
|
| 695 | - // on lit la reponse si possible pour fermer proprement la connexion |
|
| 696 | - // avec un timeout total de 200ms pour ne pas se bloquer |
|
| 697 | - while (!feof($fp) and $t < $timeout) { |
|
| 698 | - @fgets($fp, 1024); |
|
| 699 | - $t += spip_timer('read', true); |
|
| 700 | - spip_timer('read'); |
|
| 701 | - } |
|
| 702 | - fclose($fp); |
|
| 703 | - return true; |
|
| 704 | - } |
|
| 705 | - } |
|
| 706 | - // si fsockopen n'est pas dispo on essaye cURL : |
|
| 707 | - // lancer le cron par un cURL asynchrone si cURL est present |
|
| 708 | - elseif (function_exists("curl_init")) { |
|
| 709 | - //setting the curl parameters. |
|
| 710 | - $ch = curl_init($url_cron); |
|
| 711 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 712 | - // cf bug : http://www.php.net/manual/en/function.curl-setopt.php#104597 |
|
| 713 | - curl_setopt($ch, CURLOPT_NOSIGNAL, 1); |
|
| 714 | - // valeur mini pour que la requete soit lancee |
|
| 715 | - curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200); |
|
| 716 | - // lancer |
|
| 717 | - curl_exec($ch); |
|
| 718 | - // fermer |
|
| 719 | - curl_close($ch); |
|
| 720 | - return true; |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - return false; |
|
| 659 | + // methode la plus rapide : |
|
| 660 | + // Si fsockopen est possible, on lance le cron via un socket en asynchrone |
|
| 661 | + // si fsockopen echoue (disponibilite serveur, firewall) on essaye pas cURL |
|
| 662 | + // car on a toutes les chances d'echouer pareil mais sans moyen de le savoir |
|
| 663 | + // mais on renvoie false direct |
|
| 664 | + if (function_exists('fsockopen')) { |
|
| 665 | + $parts = parse_url($url_cron); |
|
| 666 | + |
|
| 667 | + switch ($parts['scheme']) { |
|
| 668 | + case 'https': |
|
| 669 | + $scheme = 'ssl://'; |
|
| 670 | + $port = 443; |
|
| 671 | + break; |
|
| 672 | + case 'http': |
|
| 673 | + default: |
|
| 674 | + $scheme = ''; |
|
| 675 | + $port = 80; |
|
| 676 | + } |
|
| 677 | + $fp = @fsockopen($scheme . $parts['host'], |
|
| 678 | + isset($parts['port']) ? $parts['port'] : $port, |
|
| 679 | + $errno, $errstr, 1); |
|
| 680 | + |
|
| 681 | + if ($fp) { |
|
| 682 | + $host_sent = $parts['host']; |
|
| 683 | + if (isset($parts['port']) and $parts['port'] !== $port) { |
|
| 684 | + $host_sent .= ':' . $parts['port']; |
|
| 685 | + } |
|
| 686 | + $timeout = 200; // ms |
|
| 687 | + stream_set_timeout($fp, 0, $timeout * 1000); |
|
| 688 | + $query = $parts['path'] . ($parts['query'] ? "?" . $parts['query'] : ""); |
|
| 689 | + $out = "GET " . $query . " HTTP/1.1\r\n"; |
|
| 690 | + $out .= "Host: " . $host_sent . "\r\n"; |
|
| 691 | + $out .= "Connection: Close\r\n\r\n"; |
|
| 692 | + fwrite($fp, $out); |
|
| 693 | + spip_timer('read'); |
|
| 694 | + $t = 0; |
|
| 695 | + // on lit la reponse si possible pour fermer proprement la connexion |
|
| 696 | + // avec un timeout total de 200ms pour ne pas se bloquer |
|
| 697 | + while (!feof($fp) and $t < $timeout) { |
|
| 698 | + @fgets($fp, 1024); |
|
| 699 | + $t += spip_timer('read', true); |
|
| 700 | + spip_timer('read'); |
|
| 701 | + } |
|
| 702 | + fclose($fp); |
|
| 703 | + return true; |
|
| 704 | + } |
|
| 705 | + } |
|
| 706 | + // si fsockopen n'est pas dispo on essaye cURL : |
|
| 707 | + // lancer le cron par un cURL asynchrone si cURL est present |
|
| 708 | + elseif (function_exists("curl_init")) { |
|
| 709 | + //setting the curl parameters. |
|
| 710 | + $ch = curl_init($url_cron); |
|
| 711 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 712 | + // cf bug : http://www.php.net/manual/en/function.curl-setopt.php#104597 |
|
| 713 | + curl_setopt($ch, CURLOPT_NOSIGNAL, 1); |
|
| 714 | + // valeur mini pour que la requete soit lancee |
|
| 715 | + curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200); |
|
| 716 | + // lancer |
|
| 717 | + curl_exec($ch); |
|
| 718 | + // fermer |
|
| 719 | + curl_close($ch); |
|
| 720 | + return true; |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + return false; |
|
| 724 | 724 | } |
| 725 | 725 | \ No newline at end of file |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | |
| 114 | 114 | // Appels incomplets (sans $c) |
| 115 | 115 | if (!is_array($c)) { |
| 116 | - spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 116 | + spip_log('erreur appel objet_modifier_champs('.$objet.'), manque $c'); |
|
| 117 | 117 | |
| 118 | 118 | return _T('erreur_technique_enregistrement_impossible'); |
| 119 | 119 | } |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | |
| 182 | 182 | // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
| 183 | 183 | include_spip('inc/editer'); |
| 184 | - if (!isset($options['data']) or is_null($options['data'])){ |
|
| 184 | + if (!isset($options['data']) or is_null($options['data'])) { |
|
| 185 | 185 | $options['data'] = &$_POST; |
| 186 | 186 | } |
| 187 | 187 | $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur); |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | $id_rubrique = 0; |
| 200 | 200 | if (isset($desc['field']['id_rubrique'])) { |
| 201 | 201 | $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
| 202 | - $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet)); |
|
| 202 | + $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=".intval($id_objet)); |
|
| 203 | 203 | } |
| 204 | 204 | $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
| 205 | 205 | $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
@@ -220,10 +220,10 @@ discard block |
||
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | // allez on commit la modif |
| 223 | - sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), $serveur); |
|
| 223 | + sql_updateq($spip_table_objet, $champs, "$id_table_objet=".intval($id_objet), $serveur); |
|
| 224 | 224 | |
| 225 | 225 | // on verifie si elle est bien passee |
| 226 | - $moof = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=" . intval($id_objet), array(), array(), |
|
| 226 | + $moof = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=".intval($id_objet), array(), array(), |
|
| 227 | 227 | '', array(), $serveur); |
| 228 | 228 | // si difference entre les champs, reperer les champs mal enregistres |
| 229 | 229 | if ($moof != $champs) { |
@@ -250,11 +250,11 @@ discard block |
||
| 250 | 250 | // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur |
| 251 | 251 | // c'est un cas exceptionnel |
| 252 | 252 | if (count($liste)) { |
| 253 | - spip_log("Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 254 | - 'modifier.' . _LOG_CRITIQUE); |
|
| 253 | + spip_log("Erreur enregistrement en base $objet/$id_objet champs :".var_export($conflits, true), |
|
| 254 | + 'modifier.'._LOG_CRITIQUE); |
|
| 255 | 255 | |
| 256 | 256 | return _T('erreur_technique_enregistrement_champs', |
| 257 | - array('champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>")); |
|
| 257 | + array('champs' => "<i>'".implode("'</i>,<i>'", $liste)."'</i>")); |
|
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | 260 | |
@@ -291,8 +291,8 @@ discard block |
||
| 291 | 291 | // message a affiner :-) |
| 292 | 292 | include_spip('inc/filtres_mini'); |
| 293 | 293 | $qui = isset($GLOBALS['visiteur_session']['nom']) and $GLOBALS['visiteur_session']['nom'] ? $GLOBALS['visiteur_session']['nom'] : $GLOBALS['ip']; |
| 294 | - journal(_L($qui . ' a édité l’' . $objet . ' ' . $id_objet . ' (' . join('+', |
|
| 295 | - array_diff(array_keys($champs), array('date_modif'))) . ')'), array( |
|
| 294 | + journal(_L($qui.' a édité l’'.$objet.' '.$id_objet.' ('.join('+', |
|
| 295 | + array_diff(array_keys($champs), array('date_modif'))).')'), array( |
|
| 296 | 296 | 'faire' => 'modifier', |
| 297 | 297 | 'quoi' => $objet, |
| 298 | 298 | 'id' => $id_objet |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -39,28 +39,28 @@ discard block |
||
| 39 | 39 | * Tableau des champs et valeurs collectées |
| 40 | 40 | */ |
| 41 | 41 | function collecter_requests($white_list, $black_list = array(), $set = null, $tous = false) { |
| 42 | - $c = $set; |
|
| 43 | - if (!$c) { |
|
| 44 | - $c = array(); |
|
| 45 | - foreach ($white_list as $champ) { |
|
| 46 | - // on ne collecte que les champs reellement envoyes par defaut. |
|
| 47 | - // le cas d'un envoi de valeur NULL peut du coup poser probleme. |
|
| 48 | - $val = _request($champ); |
|
| 49 | - if ($tous or $val !== null) { |
|
| 50 | - $c[$champ] = $val; |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - // on ajoute toujours la lang en saisie possible |
|
| 54 | - // meme si pas prevu au depart pour l'objet concerne |
|
| 55 | - if ($l = _request('changer_lang')) { |
|
| 56 | - $c['lang'] = $l; |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - foreach ($black_list as $champ) { |
|
| 60 | - unset($c[$champ]); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - return $c; |
|
| 42 | + $c = $set; |
|
| 43 | + if (!$c) { |
|
| 44 | + $c = array(); |
|
| 45 | + foreach ($white_list as $champ) { |
|
| 46 | + // on ne collecte que les champs reellement envoyes par defaut. |
|
| 47 | + // le cas d'un envoi de valeur NULL peut du coup poser probleme. |
|
| 48 | + $val = _request($champ); |
|
| 49 | + if ($tous or $val !== null) { |
|
| 50 | + $c[$champ] = $val; |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + // on ajoute toujours la lang en saisie possible |
|
| 54 | + // meme si pas prevu au depart pour l'objet concerne |
|
| 55 | + if ($l = _request('changer_lang')) { |
|
| 56 | + $c['lang'] = $l; |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + foreach ($black_list as $champ) { |
|
| 60 | + unset($c[$champ]); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + return $c; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -97,211 +97,211 @@ discard block |
||
| 97 | 97 | * - chaîne : Texte d'un message d'erreur |
| 98 | 98 | */ |
| 99 | 99 | function objet_modifier_champs($objet, $id_objet, $options, $c = null, $serveur = '') { |
| 100 | - if (!$id_objet = intval($id_objet)) { |
|
| 101 | - spip_log('Erreur $id_objet non defini', 'warn'); |
|
| 102 | - |
|
| 103 | - return _T('erreur_technique_enregistrement_impossible'); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - include_spip('inc/filtres'); |
|
| 107 | - |
|
| 108 | - $table_objet = table_objet($objet, $serveur); |
|
| 109 | - $spip_table_objet = table_objet_sql($objet, $serveur); |
|
| 110 | - $id_table_objet = id_table_objet($objet, $serveur); |
|
| 111 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 112 | - $desc = $trouver_table($spip_table_objet, $serveur); |
|
| 113 | - |
|
| 114 | - // Appels incomplets (sans $c) |
|
| 115 | - if (!is_array($c)) { |
|
| 116 | - spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 117 | - |
|
| 118 | - return _T('erreur_technique_enregistrement_impossible'); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - // Securite : certaines variables ne sont jamais acceptees ici |
|
| 122 | - // car elles ne relevent pas de autoriser(xxx, modifier) ; |
|
| 123 | - // il faut passer par instituer_XX() |
|
| 124 | - // TODO: faut-il passer ces variables interdites |
|
| 125 | - // dans un fichier de description separe ? |
|
| 126 | - unset($c['statut']); |
|
| 127 | - unset($c['id_parent']); |
|
| 128 | - unset($c['id_rubrique']); |
|
| 129 | - unset($c['id_secteur']); |
|
| 130 | - |
|
| 131 | - // Gerer les champs non vides |
|
| 132 | - if (isset($options['nonvide']) and is_array($options['nonvide'])) { |
|
| 133 | - foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 134 | - if (isset($c[$champ]) and $c[$champ] === '') { |
|
| 135 | - $c[$champ] = $sinon; |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - // N'accepter que les champs qui existent |
|
| 142 | - // TODO: ici aussi on peut valider les contenus |
|
| 143 | - // en fonction du type |
|
| 144 | - $champs = array(); |
|
| 145 | - foreach ($desc['field'] as $champ => $ignore) { |
|
| 146 | - if (isset($c[$champ])) { |
|
| 147 | - $champs[$champ] = $c[$champ]; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - // Nettoyer les valeurs |
|
| 152 | - $champs = array_map('corriger_caracteres', $champs); |
|
| 153 | - |
|
| 154 | - // Envoyer aux plugins |
|
| 155 | - $champs = pipeline('pre_edition', |
|
| 156 | - array( |
|
| 157 | - 'args' => array( |
|
| 158 | - 'table' => $spip_table_objet, // compatibilite |
|
| 159 | - 'table_objet' => $table_objet, |
|
| 160 | - 'spip_table_objet' => $spip_table_objet, |
|
| 161 | - 'desc' => $desc, |
|
| 162 | - 'type' => $objet, |
|
| 163 | - 'id_objet' => $id_objet, |
|
| 164 | - 'data' => isset($options['data']) ? $options['data'] : null, |
|
| 165 | - 'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] c'est quoi ? |
|
| 166 | - 'serveur' => $serveur, |
|
| 167 | - 'action' => isset($options['action']) ? $options['action'] : 'modifier' |
|
| 168 | - ), |
|
| 169 | - 'data' => $champs |
|
| 170 | - ) |
|
| 171 | - ); |
|
| 172 | - |
|
| 173 | - if (!$champs) { |
|
| 174 | - return false; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - // marquer le fait que l'objet est travaille par toto a telle date |
|
| 179 | - if ($GLOBALS['meta']['articles_modif'] != 'non') { |
|
| 180 | - include_spip('inc/drapeau_edition'); |
|
| 181 | - signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 185 | - include_spip('inc/editer'); |
|
| 186 | - if (!isset($options['data']) or is_null($options['data'])){ |
|
| 187 | - $options['data'] = &$_POST; |
|
| 188 | - } |
|
| 189 | - $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur); |
|
| 190 | - // cas hypothetique : normalement inc/editer verifie en amont le conflit edition |
|
| 191 | - // et gere l'interface |
|
| 192 | - // ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme |
|
| 193 | - if ($conflits) { |
|
| 194 | - return _T('titre_conflit_edition'); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - if ($champs) { |
|
| 198 | - // cas particulier de la langue : passer par instituer_langue_objet |
|
| 199 | - if (isset($champs['lang'])) { |
|
| 200 | - if ($changer_lang = $champs['lang']) { |
|
| 201 | - $id_rubrique = 0; |
|
| 202 | - if (isset($desc['field']['id_rubrique'])) { |
|
| 203 | - $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
|
| 204 | - $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet)); |
|
| 205 | - } |
|
| 206 | - $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
|
| 207 | - $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
|
| 208 | - } |
|
| 209 | - // on laisse 'lang' dans $champs, |
|
| 210 | - // ca permet de passer dans le pipeline post_edition et de journaliser |
|
| 211 | - // et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir |
|
| 212 | - // deja pris en compte |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - // la modif peut avoir lieu |
|
| 216 | - |
|
| 217 | - // faut-il ajouter date_modif ? |
|
| 218 | - if (isset($options['date_modif']) and $options['date_modif'] |
|
| 219 | - and !isset($champs[$options['date_modif']]) |
|
| 220 | - ) { |
|
| 221 | - $champs[$options['date_modif']] = date('Y-m-d H:i:s'); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - // allez on commit la modif |
|
| 225 | - sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), $serveur); |
|
| 226 | - |
|
| 227 | - // on verifie si elle est bien passee |
|
| 228 | - $moof = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=" . intval($id_objet), array(), array(), |
|
| 229 | - '', array(), $serveur); |
|
| 230 | - // si difference entre les champs, reperer les champs mal enregistres |
|
| 231 | - if ($moof != $champs) { |
|
| 232 | - $liste = array(); |
|
| 233 | - foreach ($moof as $k => $v) { |
|
| 234 | - if ($v !== $champs[$k] |
|
| 235 | - // ne pas alerter si le champ est numerique est que les valeurs sont equivalentes |
|
| 236 | - and (!is_numeric($v) or intval($v) !== intval($champs[$k])) |
|
| 237 | - // ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle |
|
| 238 | - and (strlen($champs[$k]) or !in_array($v, ['0000-00-00 00:00:00', '0000-00-00'])) |
|
| 239 | - ) { |
|
| 240 | - $liste[] = $k; |
|
| 241 | - $conflits[$k]['post'] = $champs[$k]; |
|
| 242 | - $conflits[$k]['save'] = $v; |
|
| 243 | - |
|
| 244 | - // cas specifique MySQL+emoji : si l'un est la |
|
| 245 | - // conversion utf8_noplanes de l'autre alors c'est OK |
|
| 246 | - if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) { |
|
| 247 | - include_spip('inc/charsets'); |
|
| 248 | - if ($v == utf8_noplanes($champs[$k])) { |
|
| 249 | - array_pop($liste); |
|
| 250 | - } |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur |
|
| 255 | - // c'est un cas exceptionnel |
|
| 256 | - if (count($liste)) { |
|
| 257 | - spip_log("Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 258 | - 'modifier.' . _LOG_CRITIQUE); |
|
| 259 | - |
|
| 260 | - return _T('erreur_technique_enregistrement_champs', |
|
| 261 | - array('champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>")); |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - // Invalider les caches |
|
| 266 | - if (isset($options['invalideur']) and $options['invalideur']) { |
|
| 267 | - include_spip('inc/invalideur'); |
|
| 268 | - if (is_array($options['invalideur'])) { |
|
| 269 | - array_map('suivre_invalideur', $options['invalideur']); |
|
| 270 | - } else { |
|
| 271 | - suivre_invalideur($options['invalideur']); |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - // Notifications, gestion des revisions... |
|
| 276 | - // en standard, appelle |nouvelle_revision ci-dessous |
|
| 277 | - pipeline('post_edition', |
|
| 278 | - array( |
|
| 279 | - 'args' => array( |
|
| 280 | - 'table' => $spip_table_objet, |
|
| 281 | - 'table_objet' => $table_objet, |
|
| 282 | - 'spip_table_objet' => $spip_table_objet, |
|
| 283 | - 'desc' => $desc, |
|
| 284 | - 'type' => $objet, |
|
| 285 | - 'id_objet' => $id_objet, |
|
| 286 | - 'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] kesako ? |
|
| 287 | - 'serveur' => $serveur, |
|
| 288 | - 'action' => isset($options['action']) ? $options['action'] : 'modifier' |
|
| 289 | - ), |
|
| 290 | - 'data' => $champs |
|
| 291 | - ) |
|
| 292 | - ); |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - // journaliser l'affaire |
|
| 296 | - // message a affiner :-) |
|
| 297 | - include_spip('inc/filtres_mini'); |
|
| 298 | - $qui = isset($GLOBALS['visiteur_session']['nom']) and $GLOBALS['visiteur_session']['nom'] ? $GLOBALS['visiteur_session']['nom'] : $GLOBALS['ip']; |
|
| 299 | - journal(_L($qui . ' a édité l’' . $objet . ' ' . $id_objet . ' (' . join('+', |
|
| 300 | - array_diff(array_keys($champs), array('date_modif'))) . ')'), array( |
|
| 301 | - 'faire' => 'modifier', |
|
| 302 | - 'quoi' => $objet, |
|
| 303 | - 'id' => $id_objet |
|
| 304 | - )); |
|
| 305 | - |
|
| 306 | - return ''; |
|
| 100 | + if (!$id_objet = intval($id_objet)) { |
|
| 101 | + spip_log('Erreur $id_objet non defini', 'warn'); |
|
| 102 | + |
|
| 103 | + return _T('erreur_technique_enregistrement_impossible'); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + include_spip('inc/filtres'); |
|
| 107 | + |
|
| 108 | + $table_objet = table_objet($objet, $serveur); |
|
| 109 | + $spip_table_objet = table_objet_sql($objet, $serveur); |
|
| 110 | + $id_table_objet = id_table_objet($objet, $serveur); |
|
| 111 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 112 | + $desc = $trouver_table($spip_table_objet, $serveur); |
|
| 113 | + |
|
| 114 | + // Appels incomplets (sans $c) |
|
| 115 | + if (!is_array($c)) { |
|
| 116 | + spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 117 | + |
|
| 118 | + return _T('erreur_technique_enregistrement_impossible'); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + // Securite : certaines variables ne sont jamais acceptees ici |
|
| 122 | + // car elles ne relevent pas de autoriser(xxx, modifier) ; |
|
| 123 | + // il faut passer par instituer_XX() |
|
| 124 | + // TODO: faut-il passer ces variables interdites |
|
| 125 | + // dans un fichier de description separe ? |
|
| 126 | + unset($c['statut']); |
|
| 127 | + unset($c['id_parent']); |
|
| 128 | + unset($c['id_rubrique']); |
|
| 129 | + unset($c['id_secteur']); |
|
| 130 | + |
|
| 131 | + // Gerer les champs non vides |
|
| 132 | + if (isset($options['nonvide']) and is_array($options['nonvide'])) { |
|
| 133 | + foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 134 | + if (isset($c[$champ]) and $c[$champ] === '') { |
|
| 135 | + $c[$champ] = $sinon; |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + // N'accepter que les champs qui existent |
|
| 142 | + // TODO: ici aussi on peut valider les contenus |
|
| 143 | + // en fonction du type |
|
| 144 | + $champs = array(); |
|
| 145 | + foreach ($desc['field'] as $champ => $ignore) { |
|
| 146 | + if (isset($c[$champ])) { |
|
| 147 | + $champs[$champ] = $c[$champ]; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + // Nettoyer les valeurs |
|
| 152 | + $champs = array_map('corriger_caracteres', $champs); |
|
| 153 | + |
|
| 154 | + // Envoyer aux plugins |
|
| 155 | + $champs = pipeline('pre_edition', |
|
| 156 | + array( |
|
| 157 | + 'args' => array( |
|
| 158 | + 'table' => $spip_table_objet, // compatibilite |
|
| 159 | + 'table_objet' => $table_objet, |
|
| 160 | + 'spip_table_objet' => $spip_table_objet, |
|
| 161 | + 'desc' => $desc, |
|
| 162 | + 'type' => $objet, |
|
| 163 | + 'id_objet' => $id_objet, |
|
| 164 | + 'data' => isset($options['data']) ? $options['data'] : null, |
|
| 165 | + 'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] c'est quoi ? |
|
| 166 | + 'serveur' => $serveur, |
|
| 167 | + 'action' => isset($options['action']) ? $options['action'] : 'modifier' |
|
| 168 | + ), |
|
| 169 | + 'data' => $champs |
|
| 170 | + ) |
|
| 171 | + ); |
|
| 172 | + |
|
| 173 | + if (!$champs) { |
|
| 174 | + return false; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + // marquer le fait que l'objet est travaille par toto a telle date |
|
| 179 | + if ($GLOBALS['meta']['articles_modif'] != 'non') { |
|
| 180 | + include_spip('inc/drapeau_edition'); |
|
| 181 | + signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 185 | + include_spip('inc/editer'); |
|
| 186 | + if (!isset($options['data']) or is_null($options['data'])){ |
|
| 187 | + $options['data'] = &$_POST; |
|
| 188 | + } |
|
| 189 | + $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur); |
|
| 190 | + // cas hypothetique : normalement inc/editer verifie en amont le conflit edition |
|
| 191 | + // et gere l'interface |
|
| 192 | + // ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme |
|
| 193 | + if ($conflits) { |
|
| 194 | + return _T('titre_conflit_edition'); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + if ($champs) { |
|
| 198 | + // cas particulier de la langue : passer par instituer_langue_objet |
|
| 199 | + if (isset($champs['lang'])) { |
|
| 200 | + if ($changer_lang = $champs['lang']) { |
|
| 201 | + $id_rubrique = 0; |
|
| 202 | + if (isset($desc['field']['id_rubrique'])) { |
|
| 203 | + $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
|
| 204 | + $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet)); |
|
| 205 | + } |
|
| 206 | + $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
|
| 207 | + $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
|
| 208 | + } |
|
| 209 | + // on laisse 'lang' dans $champs, |
|
| 210 | + // ca permet de passer dans le pipeline post_edition et de journaliser |
|
| 211 | + // et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir |
|
| 212 | + // deja pris en compte |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + // la modif peut avoir lieu |
|
| 216 | + |
|
| 217 | + // faut-il ajouter date_modif ? |
|
| 218 | + if (isset($options['date_modif']) and $options['date_modif'] |
|
| 219 | + and !isset($champs[$options['date_modif']]) |
|
| 220 | + ) { |
|
| 221 | + $champs[$options['date_modif']] = date('Y-m-d H:i:s'); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + // allez on commit la modif |
|
| 225 | + sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), $serveur); |
|
| 226 | + |
|
| 227 | + // on verifie si elle est bien passee |
|
| 228 | + $moof = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=" . intval($id_objet), array(), array(), |
|
| 229 | + '', array(), $serveur); |
|
| 230 | + // si difference entre les champs, reperer les champs mal enregistres |
|
| 231 | + if ($moof != $champs) { |
|
| 232 | + $liste = array(); |
|
| 233 | + foreach ($moof as $k => $v) { |
|
| 234 | + if ($v !== $champs[$k] |
|
| 235 | + // ne pas alerter si le champ est numerique est que les valeurs sont equivalentes |
|
| 236 | + and (!is_numeric($v) or intval($v) !== intval($champs[$k])) |
|
| 237 | + // ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle |
|
| 238 | + and (strlen($champs[$k]) or !in_array($v, ['0000-00-00 00:00:00', '0000-00-00'])) |
|
| 239 | + ) { |
|
| 240 | + $liste[] = $k; |
|
| 241 | + $conflits[$k]['post'] = $champs[$k]; |
|
| 242 | + $conflits[$k]['save'] = $v; |
|
| 243 | + |
|
| 244 | + // cas specifique MySQL+emoji : si l'un est la |
|
| 245 | + // conversion utf8_noplanes de l'autre alors c'est OK |
|
| 246 | + if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) { |
|
| 247 | + include_spip('inc/charsets'); |
|
| 248 | + if ($v == utf8_noplanes($champs[$k])) { |
|
| 249 | + array_pop($liste); |
|
| 250 | + } |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur |
|
| 255 | + // c'est un cas exceptionnel |
|
| 256 | + if (count($liste)) { |
|
| 257 | + spip_log("Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 258 | + 'modifier.' . _LOG_CRITIQUE); |
|
| 259 | + |
|
| 260 | + return _T('erreur_technique_enregistrement_champs', |
|
| 261 | + array('champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>")); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + // Invalider les caches |
|
| 266 | + if (isset($options['invalideur']) and $options['invalideur']) { |
|
| 267 | + include_spip('inc/invalideur'); |
|
| 268 | + if (is_array($options['invalideur'])) { |
|
| 269 | + array_map('suivre_invalideur', $options['invalideur']); |
|
| 270 | + } else { |
|
| 271 | + suivre_invalideur($options['invalideur']); |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + // Notifications, gestion des revisions... |
|
| 276 | + // en standard, appelle |nouvelle_revision ci-dessous |
|
| 277 | + pipeline('post_edition', |
|
| 278 | + array( |
|
| 279 | + 'args' => array( |
|
| 280 | + 'table' => $spip_table_objet, |
|
| 281 | + 'table_objet' => $table_objet, |
|
| 282 | + 'spip_table_objet' => $spip_table_objet, |
|
| 283 | + 'desc' => $desc, |
|
| 284 | + 'type' => $objet, |
|
| 285 | + 'id_objet' => $id_objet, |
|
| 286 | + 'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] kesako ? |
|
| 287 | + 'serveur' => $serveur, |
|
| 288 | + 'action' => isset($options['action']) ? $options['action'] : 'modifier' |
|
| 289 | + ), |
|
| 290 | + 'data' => $champs |
|
| 291 | + ) |
|
| 292 | + ); |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + // journaliser l'affaire |
|
| 296 | + // message a affiner :-) |
|
| 297 | + include_spip('inc/filtres_mini'); |
|
| 298 | + $qui = isset($GLOBALS['visiteur_session']['nom']) and $GLOBALS['visiteur_session']['nom'] ? $GLOBALS['visiteur_session']['nom'] : $GLOBALS['ip']; |
|
| 299 | + journal(_L($qui . ' a édité l’' . $objet . ' ' . $id_objet . ' (' . join('+', |
|
| 300 | + array_diff(array_keys($champs), array('date_modif'))) . ')'), array( |
|
| 301 | + 'faire' => 'modifier', |
|
| 302 | + 'quoi' => $objet, |
|
| 303 | + 'id' => $id_objet |
|
| 304 | + )); |
|
| 305 | + |
|
| 306 | + return ''; |
|
| 307 | 307 | } |