1 | <?php |
---|
2 | |
---|
3 | // module inclu dans la description de l'outil en page de configuration |
---|
4 | |
---|
5 | if (!defined("_ECRIRE_INC_VERSION")) return; // securiser |
---|
6 | //include_spip('inc/actions'); |
---|
7 | //include_spip('inc/actions_compat'); |
---|
8 | include_spip('inc/distant'); |
---|
9 | include_spip('inc/presentation'); |
---|
10 | if(version_compare(PHP_VERSION, '5.0.0', '>=')) |
---|
11 | include_spip('outils/maj_auto_php5'); else { function cs_svn17($dir) { return false; } } |
---|
12 | |
---|
13 | define('_MAJ_SVN_FILE', 'file:///home/svn/repository/spip-zone/'); |
---|
14 | define('_MAJ_SVN_DEBUT', 'svn://zone.spip.org/spip-zone/'); |
---|
15 | define('_MAJ_SVN_TRAC', 'svn://trac.rezo.net/spip-zone/'); // ancienne URL |
---|
16 | define('_MAJ_ZONE', 'http://zone.spip.org/trac/spip-zone/'); |
---|
17 | define('_MAJ_LOG_DEBUT', _MAJ_ZONE.'log/'); |
---|
18 | define('_MAJ_LOG_FIN', '?format=changelog'); |
---|
19 | define('_MAJ_ZIP', 'http://files.spip.org/spip-zone/'); |
---|
20 | define('_MAJ_ZIP_SPIP', 'http://files.spip.org/spip/archives/SPIP-v'); |
---|
21 | define('_MAJ_ECRAN_SECU', _MAJ_ZONE.'browser/_core_/securite/ecran_securite.php?format=txt'); |
---|
22 | |
---|
23 | // Pour SPIP = 2.0.X |
---|
24 | if(!function_exists('info_maj_spip')) { |
---|
25 | include_spip('inc/plugin'); |
---|
26 | if(!function_exists('spip_version_compare')) { |
---|
27 | function spip_version_compare($v1,$v2,$op) { return version_compare($v1,$v2,$op); } |
---|
28 | } |
---|
29 | function info_maj_spip(){ |
---|
30 | if (!autoriser('webmestre')) return ""; |
---|
31 | // derniere version de SPIP |
---|
32 | $maj = $GLOBALS['meta']['info_maj_spip']; |
---|
33 | if (!$maj) return ""; |
---|
34 | list(,$maj) = explode('|',$maj,2); |
---|
35 | if (strncmp($maj,"<a",2)==0) $maj = extraire_attribut ($maj, 'title'); |
---|
36 | $lien = "http://www.spip.net/".$GLOBALS['spip_lang']."_download"; |
---|
37 | $res = _T('couteau:maj_rev_ok',array('revision'=>$maj, 'url'=>$lien, 'zip'=>'')); |
---|
38 | include_spip('lib/maj_auto/distant_mise_a_jour'); |
---|
39 | return $res; |
---|
40 | } |
---|
41 | function compat_maj_spip($forcer=false) { |
---|
42 | include_spip('lib/maj_auto/distant_mise_a_jour'); |
---|
43 | if(function_exists('genie_mise_a_jour_dist') && $forcer) return genie_mise_a_jour_dist(0); |
---|
44 | } |
---|
45 | } |
---|
46 | |
---|
47 | function maj_auto_js() { |
---|
48 | return http_script(" |
---|
49 | jQuery(document).ready(function() { |
---|
50 | var ch = jQuery('#maj_auto_div .maj_checked'); |
---|
51 | var re = jQuery('.cs_relancer a'); |
---|
52 | if(ch.length) ch[0].checked = true; |
---|
53 | else if(!re.length){ |
---|
54 | jQuery('#maj_auto_div :submit').parent().remove(); |
---|
55 | jQuery('#maj_auto_div :radio').attr('disabled','disabled'); |
---|
56 | } |
---|
57 | if(!jQuery('#maj_auto_div :radio:checked').length && jQuery('#maj_auto_div :radio').length) |
---|
58 | jQuery('#maj_auto_div :radio:first')[0].checked = true; |
---|
59 | var ch = jQuery('#maj_auto_div :checkbox'); |
---|
60 | if(ch.length==1) ch.hide(); |
---|
61 | re.click(function() { |
---|
62 | cs_href_click(jQuery('#maj_auto')[0], true); |
---|
63 | return false; |
---|
64 | }); |
---|
65 | jQuery('#maj_auto_div thead').click( function() { |
---|
66 | var span = jQuery('span', this); |
---|
67 | if(!span.length) return true; |
---|
68 | jQuery(this).next().toggleClass('cs_hidden'); |
---|
69 | cs_EcrireCookie(span[0].id, '+'+span[0].className, dixans); |
---|
70 | span.toggleClass('cs_hidden'); |
---|
71 | // annulation du clic |
---|
72 | return false; |
---|
73 | }).each(maj_lire_cookie); |
---|
74 | jQuery('.select_plugin').click( function() { |
---|
75 | var checks = jQuery('#maj_auto_div :checkbox:checked').length; |
---|
76 | var radios = jQuery('#maj_auto_div :radio'); |
---|
77 | if(checks) radios.hide(); else radios.show(); |
---|
78 | }); |
---|
79 | |
---|
80 | function maj_lire_cookie(i,e){ |
---|
81 | var span = jQuery('span', this); |
---|
82 | if(!span.length) return; |
---|
83 | jQuery(this).attr('style', 'cursor:pointer;') |
---|
84 | var c = cs_LireCookie(span[0].id); |
---|
85 | if(c!==null && c.match('cs_hidden')) { |
---|
86 | jQuery(this).next().addClass('cs_hidden'); |
---|
87 | span.removeClass('cs_hidden'); |
---|
88 | } |
---|
89 | } |
---|
90 | });"); } |
---|
91 | |
---|
92 | function info_maj_spip2(){ |
---|
93 | if (!autoriser('webmestre')) return ""; |
---|
94 | include_spip('inc/presentation'); |
---|
95 | // Plus grosse version de SPIP dispo (API d'origine) |
---|
96 | $res = info_maj_spip(); |
---|
97 | $maj = $GLOBALS['meta']['info_maj_spip']; |
---|
98 | list(,$maj) = explode('|',$maj,2); |
---|
99 | // Complement d'info : toutes les autres versions dispos |
---|
100 | list($m1, $m2, $m3) = preg_split('/\D+/', $GLOBALS['spip_version_branche']); |
---|
101 | if($m = info_maj_spip_ext($m1, $m2, $m3)) { if($maj & $res) $m[$maj] = $res; $res = join('<br />', $m); } |
---|
102 | if(!strlen($res)) return $res; |
---|
103 | // liens morts |
---|
104 | $res = preg_replace(',\[([^[]+)->\],', '$1', $res); |
---|
105 | return "<fieldset><legend $style>"._T('couteauprive:help2', array('version'=>'SPIP '.$GLOBALS['spip_version_branche'])).'</legend>' |
---|
106 | . propre("\n|{{{$res}}}|") |
---|
107 | . (preg_match(",$m1\.$m2\.\d+,",$res)?'<p>'._T('couteau:maj_spip').'</p>':'').'</fieldset>'; |
---|
108 | } |
---|
109 | |
---|
110 | // Liste de toutes les versions de SPIP [234].[01].? les plus elevees |
---|
111 | function info_maj_spip_ext($ver_min, $rev_min, $min3){ |
---|
112 | $res = array(); |
---|
113 | include_spip('genie/mise_a_jour'); |
---|
114 | if(!function_exists('info_maj_cache')) return $res; |
---|
115 | $nom = _DIR_CACHE_XML . _VERSIONS_LISTE; |
---|
116 | $page = info_maj_cache($nom, 'spip', !file_exists($nom) ? '' : file_get_contents($nom)); |
---|
117 | preg_match_all(',/SPIP\D+((\d)\D+(\d)(\D+(\d+))?.*?[.]zip)",i', $page, $m, PREG_SET_ORDER); |
---|
118 | $v_min = "$ver_min.$rev_min.$min3"; |
---|
119 | for($ver=$ver_min;$ver<=4;$ver++) for($rev=($ver==$ver_min?$rev_min:0);$rev<=1;$rev++) { |
---|
120 | $max = -1; |
---|
121 | foreach ($m as $v) if ($v[2]=="$ver" && $v[3]=="$rev" && $v[5]>$max) |
---|
122 | list($max, $fich) = array($v[5], $v[1]); |
---|
123 | if($max>=0 && ($v="$ver.$rev.$max")!=$v_min) |
---|
124 | $res[$v] = _T('couteau:maj_rev_ok',array('revision'=>$v, 'url'=>_MAJ_ZIP_SPIP.$fich, 'zip'=>'')); |
---|
125 | } |
---|
126 | ksort($res); |
---|
127 | return $res; |
---|
128 | } |
---|
129 | |
---|
130 | |
---|
131 | function maj_auto_action_rapide() { |
---|
132 | $arg_chargeur = $GLOBALS['spip_version_base']>=15828?'url_zip_plugin2':'url_zip_plugin'; // eq. SPIP >= 2.1.2 |
---|
133 | $tiers = array_map(create_function('$v','return _T("couteau:2pts", array("objet"=>$v));'), explode('/', _T('couteau:maj_tiers'))); |
---|
134 | $tiers = array('necessite'=> $tiers[0], 'utilise'=> $tiers[1], 'procure'=> $tiers[2]); |
---|
135 | $time = time(); |
---|
136 | $timeout = ini_get('max_execution_time'); |
---|
137 | $timeout = $timeout?min(30,floor($timeout/2)):10; |
---|
138 | $style = 'style="padding:0.4em;"'; |
---|
139 | // verification des mises a jour de SPIP >= 2.0 |
---|
140 | $html1 = info_maj_spip2(); |
---|
141 | // verification de l'ecran de securite |
---|
142 | if(defined('_ECRAN_SECURITE')) { |
---|
143 | $maj = maj_auto_rev_distante(_MAJ_ECRAN_SECU,false,",(\d+\.\d+(\.\d+)?),",0,true); |
---|
144 | if($maj{0}!="-" && _ECRAN_SECURITE!=$maj) { |
---|
145 | include_spip('inc/description_outil'); |
---|
146 | $html1 .= "\n<fieldset><legend $style>"._T('couteauprive:help2', array('version'=>_T('couteauprive:ecran_securite:nom').' '._ECRAN_SECURITE)).'</legend>' |
---|
147 | . description_outil_liens(_T("couteauprive:ecran_maj_ko2", array("n"=>"<span style=\"color:red; font-weight:bold;\">$maj</span>"))).'</fieldset>'; |
---|
148 | } |
---|
149 | } |
---|
150 | // verification des plugins |
---|
151 | include_spip('inc/plugin'); |
---|
152 | $plugins_actifs = array_values(liste_chemin_plugin_actifs()); |
---|
153 | // liste des extensions dispo sous SPIP >= 2.1 |
---|
154 | if(defined('_DIR_EXTENSIONS')) define('_DIR_PLUGINS_DIST', _DIR_EXTENSIONS); // compat pour SPIP 2.1 |
---|
155 | $plugins_extensions = defined('_SPIP20100')?array_values(liste_chemin_plugin_actifs(_DIR_PLUGINS_DIST)):array(); |
---|
156 | // tous, mais les actifs d'abord... |
---|
157 | $plugins = array_unique(array_merge($plugins_actifs, $plugins_extensions, liste_plugin_files())); |
---|
158 | $html_actifs = $html_inactifs = $html_extensions = array(); |
---|
159 | echo maj_auto_svp_presenter_messages(); |
---|
160 | foreach ($plugins as $p) { |
---|
161 | $actif = in_array($p, $plugins_actifs, true); |
---|
162 | $extension = in_array($p, $plugins_extensions, true); |
---|
163 | $auto = strncmp($p, 'auto/', 5)==0; |
---|
164 | $infos = plugin_get_infos_maj($p, $stop=time()-$time>$timeout, $extension?_DIR_PLUGINS_DIST:_DIR_PLUGINS); |
---|
165 | if(!defined('_SPIP30000') && strtoupper($infos['necessite'][0]['id'])=='SPIP') array_shift($infos['necessite']); |
---|
166 | $maj_lib = $checked = ''; |
---|
167 | if($stop) |
---|
168 | $maj_lib = '<span class="cs_relancer">'.'Temps serveur écoulé : [poursuivre->#].'.'</span>'; |
---|
169 | elseif($infos['maj_dispo']) { |
---|
170 | $maj_lib = _T('couteau:maj_rev_ok', |
---|
171 | array('revision' => $infos['rev_rss'], 'url'=>$infos['url_origine'], 'zip'=>$infos['zip_trac'])); |
---|
172 | $checked = " class='maj_checked'"; } |
---|
173 | elseif($infos['rev_rss']>0 && $infos['rev_local']) |
---|
174 | $maj_lib = _T('couteau:maj'.($infos['svn']?'_svn':'_ok'), |
---|
175 | array('zip'=>$infos['zip_trac'], 'url'=>$infos['url_origine'])); |
---|
176 | elseif($auto) { |
---|
177 | $maj_lib = _T('couteau:maj_rev_ko', array('url'=>$infos['url_origine'])); |
---|
178 | $checked = " class='maj_checked'"; } |
---|
179 | elseif($infos['rev_local'] && $infos['rev_rss']<=0) |
---|
180 | $maj_lib = _T('couteau:maj_rev_ko', array('url'=>$infos['url_origine'])); |
---|
181 | // eventuels liens morts |
---|
182 | $maj_lib = preg_replace(',\[([^[]+)->\],', '$1', $maj_lib); |
---|
183 | $nom = preg_replace(",[\n\r]+,",' ',$infos['nom']). ' (v' .$infos['version'] . ')' . ($maj_lib?"\n_ {{".$maj_lib.'}}':''); |
---|
184 | $rev = $infos['rev_local']?_T('couteau:maj_rev', array('revision' => $infos['rev_local'])):''; |
---|
185 | if(strlen($infos['commit'])) $rev .= (strlen($rev)?'<br/>':'') . cs_date_court($infos['commit']); |
---|
186 | if($infos['svn']) $rev .= '<br/><span style="font-variant:small-caps;">svn</span>'; |
---|
187 | if($infos['id_paquet']>0) $rev .= '<span style="font-variant:small-caps;"> svp</span>'; |
---|
188 | elseif($infos['id_paquet']<0) $rev .= '<span style="font-variant:small-caps;"> old</span>'; |
---|
189 | $id_paquet = abs($infos['id_paquet']); |
---|
190 | if(!strlen($rev)) $rev = ' '; |
---|
191 | $zip_log = (strlen($infos['zip_log']) && $infos['zip_log']!=$infos['zip_trac']) |
---|
192 | ?"<label><input type='radio' value='$infos[zip_log]'$checked name='$arg_chargeur'/>[->$infos[zip_log]]</label>":''; |
---|
193 | $bouton = ' '; |
---|
194 | if(!$stop) { |
---|
195 | if(/*$infos['maj_dispo'] &&*/ $id_paquet) { |
---|
196 | // format des donnees en sortie |
---|
197 | $bouton = $id_paquet.':'.$infos['id_depot'].':'.$p.':'.$infos['zip_trac']; |
---|
198 | // 1 radio (MAJ unique) et 1 checkbox (MAJ multiple) pour SVP |
---|
199 | $bouton = "<input type='radio' value=\"$bouton\"$checked name='$arg_chargeur'/><br/><input type='checkbox' class='checkbox select_plugin' name='ids_paquet[]' value=\"$bouton\">"; |
---|
200 | } elseif($auto) $bouton = strlen($infos['zip_trac']) |
---|
201 | ?"<input type='radio' value='$infos[zip_trac]'$checked name='$arg_chargeur'/>" |
---|
202 | :'<center style="margin-top:0.6em;font-weight:bold;"><acronym title="'._T('couteau:maj_zip_ko').'">?</acronym></center>'; |
---|
203 | } |
---|
204 | if(strlen($zip_log)) { |
---|
205 | if (!$stop) |
---|
206 | $nom .= "<br/>" . _T('couteau:maj_verif') . "<br/>$zip_log<br/>{$bouton}[->$infos[zip_trac]]<label>"; |
---|
207 | $bouton = ' '; |
---|
208 | } |
---|
209 | // relations exterieures |
---|
210 | foreach($tiers as $k=>$v) if(isset($infos[$k]) && count($infos[$k])) |
---|
211 | $nom .= "<br/>$v {".join('}, {', array_map('array_shift', $infos[$k])).'}'; |
---|
212 | ${$actif?'html_actifs':($extension?'html_extensions':'html_inactifs')}[] = "|$bouton|$nom|$rev|"; |
---|
213 | } |
---|
214 | |
---|
215 | $sep = " class='cs_hidden'> (...)</span>}}|<|<|\n"; |
---|
216 | $html1 = "\n<div $style id='maj_auto_div'>$html1<fieldset><legend $style>" |
---|
217 | . _T('couteau:maj_liste').'</legend>' |
---|
218 | . propre( |
---|
219 | (count($html_actifs)? "\n|{{" . _T('couteau:plug_actifs') . "<span id='maj_1'" . $sep . join("\n",$html_actifs) . "\n" : '') |
---|
220 | . (count($html_extensions)? "\n|{{" . _T(defined('_SPIP30000')?'plugins_liste_dist':'plugins_liste_extensions') . "<span id='maj_2'". $sep . join("\n",$html_extensions) . "\n" : '') |
---|
221 | . (count($html_inactifs)? "\n|{{" . _T('couteau:plug_inactifs') . "<span id='maj_3'". $sep . join("\n",$html_inactifs) . "\n" : '') |
---|
222 | ) |
---|
223 | . "<div style='text-align: right;'><input class='fondo' type='submit' value=\"" |
---|
224 | . attribut_html(_T('couteau:maj_maj')) |
---|
225 | . '" /><p><i>'._T('couteau:maj_verif2').'</i></p></div></fieldset></div>' |
---|
226 | . maj_auto_js(); |
---|
227 | $html2 = "\n<div class='cs_sobre'><input class='cs_sobre' type='submit' value=\"[" |
---|
228 | . attribut_html(_T('couteau:maj_actu')) . ']" /></div>'; |
---|
229 | |
---|
230 | // premier formulaire non ajax, lancant directement charger_plugin |
---|
231 | return redirige_action_post('charger_plugin', '', 'admin_couteau_suisse', "cmd=descrip&outil=maj_auto#cs_infos", $html1) |
---|
232 | // second formulaire ajax : lien d'actualisation forcee |
---|
233 | . ajax_action_auteur('action_rapide', 'maj_auto_forcer', 'admin_couteau_suisse', "arg=maj_auto|description_outil&cmd=descrip#cs_action_rapide", $html2); |
---|
234 | } |
---|
235 | |
---|
236 | function maj_auto_svp_presenter_messages() { |
---|
237 | if(!defined('_SPIP30000')) return; |
---|
238 | // presenter d'abord les messages de SVP |
---|
239 | include_spip('exec/admin_plugin'); |
---|
240 | $res = svp_presenter_actions_realisees(); |
---|
241 | // puis ceux du CS s'il y en a |
---|
242 | if(!@file_exists($f=_DIR_TMP.'cs_messages.txt')) return $res; |
---|
243 | lire_fichier($f, $messages); |
---|
244 | $messages = unserialize($messages); |
---|
245 | include_spip('inc/filtres_boites'); |
---|
246 | foreach(array('ok'=>array('svp:actions_realises','success'), |
---|
247 | 'fail'=>array('svp:actions_en_erreur','error'), |
---|
248 | 'notice'=>array('info_avertissement','notice')) as $k=>$v) |
---|
249 | if($messages[$k]) { |
---|
250 | $tmp = '<ul>'; |
---|
251 | foreach($messages[$k] as $i) $tmp .= "<li>$i</li>"; |
---|
252 | $res .= boite_ouvrir(_T($v[0]), $v[1]) . $tmp. '</ul>' . boite_fermer(); |
---|
253 | } |
---|
254 | spip_unlink($f); |
---|
255 | return $res; |
---|
256 | } |
---|
257 | |
---|
258 | // renvoie le pattern present dans la page distante |
---|
259 | // si le pattern est NULL, renvoie un simple 'is_file_exists' |
---|
260 | function maj_auto_rev_distante($url, $timeout=false, $pattern=NULL, $lastmodified=0, $force=false) { |
---|
261 | $force |= in_array(_request('var_mode'), array('calcul', 'recalcul')); |
---|
262 | // pour la version distante, on regarde toutes les 24h00 (meme en cas d'echec) |
---|
263 | $maj_ = isset($GLOBALS['meta']['tweaks_maj_auto'])?unserialize($GLOBALS['meta']['tweaks_maj_auto']):array(); |
---|
264 | if(!isset($maj_[$url_=md5($url)])) $maj_[$url_] = array(0, false); |
---|
265 | $maj = &$maj_[$url_]; |
---|
266 | // prendre le cache si svn.revision n'est pas modifie recemment, si les 24h ne sont pas ecoulee, et si on ne force pas |
---|
267 | if (!$force && $maj[1]!==false && ($lastmodified<$maj[0]) && (time()-$maj[0] < 24*3600)) |
---|
268 | $distant = $maj[1]; |
---|
269 | elseif($timeout) |
---|
270 | return '-1'; |
---|
271 | else { |
---|
272 | $distant = $maj[1] = ($pattern!==NULL) |
---|
273 | ?(($distant = recuperer_page($url)) |
---|
274 | ?(preg_match($pattern, $distant, $regs)?$regs[1]:'-2') |
---|
275 | :'-1') |
---|
276 | :strlen(recuperer_page($url, false, true, 0)); |
---|
277 | $maj[0] = time(); |
---|
278 | ecrire_meta('tweaks_maj_auto', serialize($maj_)); |
---|
279 | ecrire_metas(); |
---|
280 | } |
---|
281 | return $distant; |
---|
282 | } |
---|
283 | |
---|
284 | function plugin_get_infos_maj($p, $timeout=false, $DIR_PLUGINS=_DIR_PLUGINS) { |
---|
285 | if(defined('_SPIP20100')) { |
---|
286 | $get_infos = charger_fonction('get_infos','plugins'); |
---|
287 | $infos = $get_infos($p, false, $DIR_PLUGINS); |
---|
288 | } else $infos = plugin_get_infos($p); |
---|
289 | // fichier svn.revision fourni par SPIP |
---|
290 | $ok = lire_fichier($svn_rev = $DIR_PLUGINS.$p.'/svn.revision', $svn); |
---|
291 | $lastmodified = @file_exists($svn_rev)?@filemtime($svn_rev):0; |
---|
292 | if($ok && preg_match(',<origine>(.+)</origine>,', $svn, $regs)) { |
---|
293 | $url_origine = str_replace(array(_MAJ_SVN_FILE, _MAJ_SVN_DEBUT), _MAJ_LOG_DEBUT, $regs[1]); |
---|
294 | // prise en compte du recent demenagement de la Zone... |
---|
295 | $url_origine = preg_replace(',/_plugins_/_(?:stable|dev|test)_/,','/_plugins_/', $url_origine); |
---|
296 | } else $url_origine = ''; |
---|
297 | $infos['commit'] = ($ok && preg_match(',<commit>(.+)</commit>,', $svn, $regs))?$regs[1]:''; |
---|
298 | $rev_local = (strlen($svn) && preg_match(',<revision>(.+)</revision>,', $svn, $regs)) |
---|
299 | ?intval($regs[1]):version_svn_courante2($DIR_PLUGINS.$p); |
---|
300 | if($infos['svn'] = is_array($rev_local) || $rev_local<0) { |
---|
301 | // systeme SVN en place |
---|
302 | if (is_array($rev_local)) // version SVN >= 1.7 ? |
---|
303 | list($rev_local, $url_origine) = $rev_local; |
---|
304 | // version SVN anterieure |
---|
305 | elseif (lire_fichier($DIR_PLUGINS.$p.'/.svn/entries', $svn) |
---|
306 | && preg_match(',(?:'.preg_quote(_MAJ_SVN_TRAC).'|'.preg_quote(_MAJ_SVN_DEBUT).')[^\n\r]+,ms', $svn, $regs)) |
---|
307 | $url_origine = $regs[0]; |
---|
308 | $url_origine = str_replace(array(_MAJ_SVN_TRAC,_MAJ_SVN_DEBUT), _MAJ_LOG_DEBUT, $url_origine); |
---|
309 | // prise en compte du recent demenagement de la Zone... |
---|
310 | $url_origine = preg_replace(',/_plugins_/_(?:stable|dev|test)_/,','/_plugins_/', $url_origine); |
---|
311 | } |
---|
312 | // URL http:// inattendu |
---|
313 | if(strncmp($url_origine, 'http://', 7)!==0) $url_origine=''; |
---|
314 | $infos['id_paquet'] = 0; // SVP |
---|
315 | $infos['url_origine'] = strlen($url_origine)?$url_origine._MAJ_LOG_FIN:''; |
---|
316 | $infos['rev_local'] = abs($rev_local); |
---|
317 | $infos['rev_rss'] = intval(maj_auto_rev_distante($infos['url_origine'], $timeout, ', \[(\d+)\],', $lastmodified)); |
---|
318 | $infos['maj_dispo'] = $infos['rev_rss']>0 && $infos['rev_local']>0 && $infos['rev_rss']>$infos['rev_local']; |
---|
319 | // fichiers zip |
---|
320 | $infos['zip_log'] = $infos['zip_trac'] = ''; |
---|
321 | $p2 = preg_match(',^auto/(.*)$,', $p, $regs)?$regs[1]:''; |
---|
322 | if(strlen($p2)) { |
---|
323 | //echo "<hr/>$p -> $infos[prefix]<br/>"; |
---|
324 | if(defined('_SPIP30000')) { |
---|
325 | // supposition du passage par SVP ? |
---|
326 | maj_auto_svp_query($p, $infos); |
---|
327 | // ce plugin passe en negatif s'il n'a pas ete installe par SVP |
---|
328 | if(strpos($p2,$infos['prefix'].'/v')===false) $infos['id_paquet'] *= -1; |
---|
329 | } |
---|
330 | // supposition du nom d'archive sur files.spip.org |
---|
331 | if(!$infos['zip_trac'] && intval(maj_auto_rev_distante($f = _MAJ_ZIP.$p2.'.zip', $timeout))) |
---|
332 | $infos['zip_trac'] = $f; |
---|
333 | // nom de l'archive recemment installee par chargeur |
---|
334 | if(lire_fichier(sous_repertoire(_DIR_CACHE, 'chargeur').$p2.'/install.log', $log) |
---|
335 | && preg_match(',[\n\r]source: *([^\n\r]+),msi', $log, $regs) |
---|
336 | && intval(maj_auto_rev_distante($regs[1], $timeout))) |
---|
337 | $infos['zip_log'] = $regs[1]; |
---|
338 | // au final on prend le bon |
---|
339 | if(!$infos['zip_trac']) $infos['zip_trac'] = $infos['zip_log']; |
---|
340 | } |
---|
341 | return $infos; |
---|
342 | } |
---|
343 | |
---|
344 | // fonction cherchant un fichier zip valide dans les paquets de SVP |
---|
345 | // retourne array($id_paquet, $url_zips, $nom_zip) |
---|
346 | function maj_auto_svp_query($dir, &$infos) { |
---|
347 | // Recherche en base du plugin local, puis du paquet distant |
---|
348 | if($x=sql_fetsel('id_paquet,id_plugin,version,nom_archive','spip_paquets','src_archive='._q($dir))) |
---|
349 | if($y=sql_fetsel('id_paquet,p.id_depot,p.version,nom_archive,src_archive,url_archives,url_brouteur', |
---|
350 | array('spip_paquets AS p', 'spip_depots AS d'), array('p.id_plugin='.$x['id_plugin'], 'p.id_depot>0'))) { |
---|
351 | $infos['id_paquet'] = $x['id_paquet']; |
---|
352 | $infos['id_depot'] = $y['id_depot']; |
---|
353 | // info : si $x['version']<>$y['version'] alors SVP propose une mise a jour disponible |
---|
354 | // construction du paquet zip |
---|
355 | if(strlen($y['nom_archive']) && intval(maj_auto_rev_distante($f = $y['url_archives'].'/'.$y['nom_archive'], $timeout))) |
---|
356 | $infos['zip_trac'] = $f; |
---|
357 | //echo "<hr>$dir -> $infos[prefix]<br>SQL LOCAL = "; print_r($x); echo "<br>SQL DISTANT = "; print_r($y); |
---|
358 | } |
---|
359 | } |
---|
360 | |
---|
361 | // fonction manipulant les fonctions CVT de SVP (cf. svp/formulaires/admin_plugin.php) |
---|
362 | function maj_auto_svp_maj_plugin($ids_paquet=array()) { |
---|
363 | if(!count($ids_paquet)) return; |
---|
364 | $actions = $depots = $messages = $retour = $requests = $cs_messages = array(); |
---|
365 | // donnees du formulaire recues sous la forme id_paquet:id_depot:plugin:archive |
---|
366 | foreach ($ids_paquet as $i) { |
---|
367 | $p = explode(':', $i, 4); |
---|
368 | $requests[$p[0]] = $p; |
---|
369 | $actions[$p[0]] = 'up'; |
---|
370 | $depots[$p[1]] = 1; |
---|
371 | } |
---|
372 | // actualiser la liste des paquets distants |
---|
373 | // ici une demande manuelle de mise a jour est demandee, autant etre sur... |
---|
374 | include_spip('inc/svp_depoter_distant'); |
---|
375 | foreach($depots as $k=>$v) svp_actualiser_depot($k); |
---|
376 | // lancer les verifications |
---|
377 | if(count($actions0 = $actions)) { |
---|
378 | // faire appel au decideur pour determiner la liste exacte des commandes apres |
---|
379 | // verification des dependances |
---|
380 | include_spip('inc/svp_decider'); |
---|
381 | svp_decider_verifier_actions_demandees($actions, $messages); |
---|
382 | } else |
---|
383 | $cs_messages['notice'][] = _T('svp:message_erreur_aucun_plugin_selectionne'); |
---|
384 | if(!count($messages['decideur_erreurs'])) { |
---|
385 | // recuperer les actions validees par le decideur |
---|
386 | $actions = unserialize(_request('_todo')); |
---|
387 | if(count($rejets = array_diff(array_keys($actions0), array_keys($actions)))) { |
---|
388 | // probablement une action de reparation ou de MAJ de release sans changement de version |
---|
389 | // dans ce cas, on remplace simplement les anciens fichiers du plugin (methode SPIP2) |
---|
390 | if(include_spip('lib/maj_auto/distant_action_charger_plugin') && include_spip('lib/maj_auto/distant_inc_charger_plugin')) |
---|
391 | foreach($rejets as $p) if($requests[$p][3]) { |
---|
392 | set_request('url_zip_plugin2', $requests[$p][3]); |
---|
393 | set_request('cs_retour', 'oui'); |
---|
394 | $retour = action_charger_plugin_dist(); |
---|
395 | if($retour['suite'] && is_dir($retour['tmp'])) { |
---|
396 | // deplacement de l'archive dezipee a son emplacement definitif |
---|
397 | $dest = _DIR_PLUGINS . $requests[$p][2]; |
---|
398 | if(is_dir($old = dirname($dest).'/.'.basename($dest).'.old')) supprimer_repertoire($old); |
---|
399 | rename($dest, $old); |
---|
400 | rename($retour['tmp'], $dest); |
---|
401 | spip_unlink($retour['fichier']); |
---|
402 | $cs_messages['ok'][] = ("Le plugin « $retour[nom] » n'a pas changé de version, mais ses fichiers ont quand même été actualisés."); |
---|
403 | } else |
---|
404 | $cs_messages['fail'][] = ('Le fichier « '.$requests[$p][3].' » est introuvable !'); |
---|
405 | } else |
---|
406 | $cs_messages['fail'][] = ('Librairies introuvables !'); |
---|
407 | } else |
---|
408 | $cs_messages['fail'] = array_merge($messages['decideur_erreurs'], $cs_messages['fail']); |
---|
409 | // sauvegarde des messages |
---|
410 | if(count($cs_messages)) |
---|
411 | ecrire_fichier(_DIR_TMP . 'cs_messages.txt', serialize($cs_messages)); |
---|
412 | // envoyer les actions validees a l'actionneur |
---|
413 | include_spip('inc/svp_actionner'); |
---|
414 | svp_actionner_traiter_actions_demandees($actions, $retour, $redirect); |
---|
415 | $action = charger_fonction('actionner', 'action'); |
---|
416 | $action(); // et hop, action et redirection ! |
---|
417 | } |
---|
418 | include_spip('inc/headers'); |
---|
419 | redirige_par_entete(_request('redirect')); |
---|
420 | } |
---|
421 | |
---|
422 | // fonction {$outil}_{$arg}_action() appelee par action/action_rapide.php |
---|
423 | function maj_auto_maj_auto_forcer_action() { |
---|
424 | // forcer la lecture de la derniere version de SPIP |
---|
425 | if(function_exists('compat_maj_spip')) compat_maj_spip(true); // pour SPIP < 2.1 |
---|
426 | elseif($cron = charger_fonction('mise_a_jour', 'genie')) $cron(0); |
---|
427 | // forcer la lecture des revisions distantes de plugins |
---|
428 | ecrire_meta('tweaks_maj_auto', serialize(array())); |
---|
429 | ecrire_metas(); |
---|
430 | } |
---|
431 | |
---|
432 | function version_svn_courante2($dir) { |
---|
433 | // recherche de la base de donnee |
---|
434 | if(!$db = @file_exists($dir2 = realpath($dir . '/.svn/wc.db'))) { |
---|
435 | // version <1.7 de Subversion (reconnue par SPIP) |
---|
436 | if(@file_exists($dir.'/.svn/entries')) return version_svn_courante($dir); |
---|
437 | // trunk et extensions |
---|
438 | $db = @file_exists($dir2 = realpath($dir . '/../.svn/wc.db')); |
---|
439 | if(!$db) { |
---|
440 | // branches |
---|
441 | $db = @file_exists($dir2 = realpath($dir . '/../../.svn/wc.db')); |
---|
442 | if($db) $b = basename(dirname($dir)).'/'.basename($dir); |
---|
443 | } else $b = basename($dir); |
---|
444 | } else $b = ''; |
---|
445 | // version 1.7 de Subversion |
---|
446 | return cs_svn17($dir2); |
---|
447 | } |
---|
448 | |
---|
449 | ?> |
---|