From 54a71b3d92d0830fe590dbcdfdcb34a6e39142b3 Mon Sep 17 00:00:00 2001
From: Cerdic <cedric@yterium.com>
Date: Sat, 13 Mar 2010 10:29:21 +0000
Subject: [PATCH] Report de [15440] [15441] [15442]

---
 .gitattributes                   |  1 +
 ecrire/genie/mise_a_jour.php     | 92 ++++++++++++++++++++++++++++++++
 ecrire/inc/genie.php             |  5 +-
 ecrire/inc/log.php               |  2 +-
 ecrire/inc/presentation_mini.php | 59 ++++++++------------
 5 files changed, 119 insertions(+), 40 deletions(-)
 create mode 100644 ecrire/genie/mise_a_jour.php

diff --git a/.gitattributes b/.gitattributes
index a26b836e16..094d8b3315 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -199,6 +199,7 @@ ecrire/exec/upgrade.php -text
 ecrire/exec/valider_xml.php -text
 ecrire/exec/virtualiser.php -text
 ecrire/genie/maintenance.php -text
+ecrire/genie/mise_a_jour.php -text
 ecrire/genie/syndic.php -text
 ecrire/inc/actions.php -text
 ecrire/inc/afficher_objets.php -text
diff --git a/ecrire/genie/mise_a_jour.php b/ecrire/genie/mise_a_jour.php
new file mode 100644
index 0000000000..6d82c767e8
--- /dev/null
+++ b/ecrire/genie/mise_a_jour.php
@@ -0,0 +1,92 @@
+<?php
+
+/***************************************************************************\
+ *  SPIP, Systeme de publication pour l'internet                           *
+ *                                                                         *
+ *  Copyright (c) 2001-2010                                                *
+ *  Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James  *
+ *                                                                         *
+ *  Ce programme est un logiciel libre distribue sous licence GNU/GPL.     *
+ *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
+\***************************************************************************/
+
+if (!defined("_ECRIRE_INC_VERSION")) return;
+
+/**
+ * Verifier si une mise a jour est disponible
+ *
+ * @param int $t
+ * @return int
+ */
+function genie_mise_a_jour_dist($t) {
+	include_spip('inc/meta');
+	$maj = info_maj ('spip', 'SPIP', $GLOBALS['spip_version_branche']);
+	ecrire_meta('info_maj_spip',$maj?($GLOBALS['spip_version_branche']."|$maj"):"",'non');
+
+	spip_log("Verification version SPIP : ".($maj?$maj:"version a jour"),"verifie_maj");
+	return 1;
+}
+
+
+// Determiner si une nouvelle version de SPIP est disponible
+// sans demander tout le temps au serveur de versions si leur liste a change'.
+
+define('_VERSIONS_SERVEUR', 'http://files.spip.org/');
+define('_VERSIONS_LISTE', 'archives.xml');
+
+function info_maj ($dir, $file, $version){
+	list($maj,$min,$rev) = preg_split('/\D+/', $version);
+#	list($maj,$min,$rev) = preg_split('/\D+/', '1.9.2i'); # pour test
+#	list($maj,$min,$rev) = preg_split('/\D+/', '2.0.8'); # pour test
+
+	$nom = _DIR_CACHE_XML . _VERSIONS_LISTE;
+	$page = !file_exists($nom) ? '' : file_get_contents($nom);
+	$page = info_maj_cache($nom, $dir, $page);
+
+	// reperer toutes les versions de numero majeur superieur ou egal
+	// (a revoir quand on arrivera a SPIP V10 ...)
+	$p = substr("0123456789", intval($maj));
+	$p = ',/' . $file . '\D+([' . $p . ']+)\D+(\d+)(\D+(\d+))?.*?[.]zip",i';
+	preg_match_all($p, $page, $m,  PREG_SET_ORDER);
+	$page = '';
+	foreach ($m as $v) {
+			list(, $maj2, $min2,, $rev2) = $v;
+			if (($maj2 > $maj)
+			OR (($maj2 == $maj)
+				AND (($min2 > $min)
+					OR (($min2 == $min)
+						AND ($rev2 > $rev))))) {
+			  $page .= $maj2 . '.' . $min2 . '.' . $rev2 . ' ';
+		}
+	}
+
+	if (!$page) return "";
+	return "<a class='info_maj_spip' href='$dir' title='$page'>" .
+	    _T('nouvelles_versions') .
+	    '</a>';
+}
+
+// Verifie que la liste $page des versions dans le fichier $nom est a jour
+// Ce fichier rajoute dans ce fichier l'alea ephemere courant;
+// on teste la nouveaute par If-Modified-Since,
+// et seulement quand celui-ci a change' pour limiter les acces HTTP
+
+function info_maj_cache($nom, $dir, $page='')
+{
+	$re = '<archives id="a' . $GLOBALS['meta']["alea_ephemere"] . '">';
+	if (preg_match("/$re/", $page)) return $page;
+
+	$url = _VERSIONS_SERVEUR . $dir . '/' . _VERSIONS_LISTE;
+	$a = file_exists($nom) ? filemtime($nom) : '';
+	include_spip('inc/distant');
+	$res = recuperer_lapage($url, false, 'GET', _COPIE_LOCALE_MAX_SIZE, '',false, $a);
+	// Si rien de neuf (ou inaccessible), garder l'ancienne
+	if ($res) list(, $page) = $res;
+	// Placer l'indicateur de fraicheur
+	$page = preg_replace('/^<archives.*?>/', $re, $page);
+	sous_repertoire(_DIR_CACHE_XML);
+	ecrire_fichier($nom, $page);
+	return $page;
+}
+
+?>
\ No newline at end of file
diff --git a/ecrire/inc/genie.php b/ecrire/inc/genie.php
index 178d2987c0..266d07b240 100644
--- a/ecrire/inc/genie.php
+++ b/ecrire/inc/genie.php
@@ -121,7 +121,10 @@ function taches_generales($taches_generales = array()) {
 		$taches_generales['syndic'] = 90;
 
 	// maintenance (ajax, verifications diverses)
-		$taches_generales['maintenance'] = 3600 * 2;
+	$taches_generales['maintenance'] = 3600 * 2;
+
+	// verifier si une mise a jour de spip est disponible (2 fois par semaine suffit largement)
+	$taches_generales['mise_a_jour'] = 3*24*3600;
 
 	return pipeline('taches_generales_cron',$taches_generales);
 }
diff --git a/ecrire/inc/log.php b/ecrire/inc/log.php
index 4ae2b50abf..ccf4b25530 100644
--- a/ecrire/inc/log.php
+++ b/ecrire/inc/log.php
@@ -17,7 +17,7 @@ function inc_log_dist($message, $logname=NULL, $logdir=NULL, $logsuf=NULL) {
 	static $compteur = array();
 	global $nombre_de_logs, $taille_des_logs;
 
-	if (is_null($logname))
+	if (is_null($logname) OR !is_string($logname))
 		$logname = defined('_FILE_LOG') ? _FILE_LOG : 'spip';
 	if (!isset($compteur[$logname])) $compteur[$logname] = 0;
 	if ($logname != 'maj'
diff --git a/ecrire/inc/presentation_mini.php b/ecrire/inc/presentation_mini.php
index ed50b5d7d6..bf55969186 100644
--- a/ecrire/inc/presentation_mini.php
+++ b/ecrire/inc/presentation_mini.php
@@ -338,7 +338,7 @@ function fin_page()
 			. "</a></div>")
 		: ("<div id='copyright'>"
 
-			. info_maj ('spip', 'SPIP', $GLOBALS['spip_version_branche'])
+			. info_maj_spip()
 			. info_copyright()
 			. "<br />"
 		 	. _T('info_copyright_doc',
@@ -358,6 +358,26 @@ function fin_page()
 	. "</body></html>\n";
 }
 
+function info_maj_spip(){
+
+	$maj = $GLOBALS['meta']['info_maj_spip'];
+	if (!$maj)
+		return "";
+
+	$maj = explode('|',$maj);
+	// c'est une ancienne notif, on a fait la maj depuis !
+	if ($GLOBALS['spip_version_branche']!==reset($maj))
+		return "";
+
+	if (!autoriser('webmestre'))
+		return "";
+
+	array_shift($maj);
+	$maj = implode('|',$maj);
+
+	return "<br />$maj</br>";
+}
+
 // http://doc.spip.org/@info_copyright
 function info_copyright() {
 	global $spip_version_affichee, $spip_lang;
@@ -387,43 +407,6 @@ function info_copyright() {
 
 }
 
-define('_VERSIONS_SERVEUR', 'http://files.spip.org/');
-define('_VERSIONS_LISTE', 'archives.xml');
-
-function info_maj ($dir, $file, $version)
-{
-	if (!autoriser('webmestre')) return '';
-	list($maj,$min,$rev) = preg_split('/\D+/', $version);
-#	list($maj,$min,$rev) = preg_split('/\D+/', '1.9.2i'); # pour test
-	include_spip('inc/distant');
-	$dir = _VERSIONS_SERVEUR . $dir . '/';
-	$liste = $dir . _VERSIONS_LISTE;
-	if (!$page = copie_locale($liste, 'modif')) return '';
-	$page = file_get_contents(_DIR_RACINE . $page);
-	// reperer toutes les versions de numero majeur superieur ou egal
-	// (a revoir quand on arrivera a SPIP V10 ...)
-	$p = substr("0123456789", intval($maj));
-	$re = ',/' . $file . '\D+([' . $p . ']+)\D+(\d+)(\D+(\d+))?.*?[.]zip",i';
-	preg_match_all($re, $page, $m,  PREG_SET_ORDER);
-	$new = '';
-	foreach ($m as $v) {
-			list(, $maj2, $min2,, $rev2) = $v;
-			if (($maj2 > $maj)
-			OR (($maj2 == $maj)
-				AND (($min2 > $min)
-					OR (($min2 == $min)
-						AND ($rev2 > $rev))))) {
-				$new = $v[0];
-				break;
-		}
-	}
-
-	if (!$new) return "";
-	return "<br /><a style='color: red' href='$dir'>" . 
-	    _L('De nouvelles_versions_de_SPIP_sont_disponibles') .
-	    '</a><br />';
-}
-
 // http://doc.spip.org/@debloquer_article
 function debloquer_article($arg, $texte) {
 
-- 
GitLab