Valider 18030521 rédigé par james@rezo.net's avatar james@rezo.net
Parcourir les fichiers

Version 2.5.8 et règles de codage

parent 1cd43a8d
Chargement en cours
Chargement en cours
Chargement en cours
Chargement en cours
+195 −147
Numéro de ligne d'origine Numéro de ligne de diff Ligne de diff
@@ -42,7 +42,7 @@ define('_CHEMIN_FICHIER_ZIP', 'spip/stable/spip-3.1.zip');

# Adresse des librairies necessaires a spip_loader
# (pclzip et fichiers de langue)
define('_URL_LOADER_DL',"http://www.spip.net/spip-dev/INSTALL/");
define('_URL_LOADER_DL', 'http://www.spip.net/spip-dev/INSTALL/');
# telecharger a travers un proxy
define('_URL_LOADER_PROXY', '');

@@ -51,8 +51,8 @@ define('_NOM_PAQUET_ZIP','spip');
// par defaut le morceau de path a enlever est le nom : spip
define('_REMOVE_PATH_ZIP', _NOM_PAQUET_ZIP);

define('_SPIP_LOADER_PLUGIN_RETOUR', "ecrire/?exec=admin_plugin&voir=tous");
define('_SPIP_LOADER_SCRIPT', "spip_loader.php");
define('_SPIP_LOADER_PLUGIN_RETOUR', 'ecrire/?exec=admin_plugin&voir=tous');
define('_SPIP_LOADER_SCRIPT', 'spip_loader.php');

// "habillage" optionnel
// liste separee par virgules de fichiers inclus dans spip_loader
@@ -72,7 +72,7 @@ define('_PCL_ZIP_RANGE', 200);
// v 2.5 : affichage de la version à installer, de la version déjà installée (si elle existe),
//		   compatibilite PHP, loader obsolete
// v 2.7 : on télécharge maintenant SPIP 3.1 
define('_SPIP_LOADER_VERSION', '2.5.7');
define('_SPIP_LOADER_VERSION', '2.5.8');
#
#######################################################################

@@ -200,8 +200,9 @@ function _TT($code, $args=array()) {
	global $lang;
	$code = str_replace('tradloader:', '', $code);
	$text = $GLOBALS['i18n_tradloader_'.$lang][$code];
	while (list($name, $value) = @each($args))
	while (list($name, $value) = @each($args)) {
		$text = str_replace("@$name@", $value, $text);
	}
	return $text;
}

@@ -229,9 +230,10 @@ function mkdir_recursif($chemin,$chmod){
	$d = array_shift($dirs);
	foreach ($dirs as $dir) {
		$d = "$d/$dir";
		if (!is_dir($d))
		if (!is_dir($d)) {
			mkdir($d, $chmod);
		}
	}
	return is_dir($chemin);
}

@@ -241,13 +243,17 @@ function move_all($src,$dest) {

	if ($dh = opendir($src)) {
		while (($file = readdir($dh)) !== false) {
			if (in_array($file, array('.', '..'))) continue;
			if (in_array($file, array('.', '..'))) {
				continue;
			}
			$s = "$src/$file";
			$d = "$dest/$file";
			if (is_dir($s)) {
				if (!is_dir($d))
					if (!mkdir_recursif($d, $chmod))
				if (!is_dir($d)) {
					if (!mkdir_recursif($d, $chmod)) {
						die("impossible de creer $d");
					}
				}
				move_all($s, $d);
				rmdir($s);
				// verifier qu'on en a pas oublie (arrive parfois il semblerait ...)
@@ -257,9 +263,11 @@ function move_all($src,$dest) {
					move_all($s, $d);
					rmdir($s);
				}
			} else {
				if (is_file($s)) {
					rename($s, $d);
				}
			}
			else
				if (is_file($s))	rename ($s, $d);
		}
		// liberer le pointeur sinon windows ne permet pas le rmdir eventuel
		closedir($dh);
@@ -272,7 +280,9 @@ function regler_langue_navigateurT() {
		foreach ($accept_langs as $s) {
			if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) {
				$lang = strtolower($r[1]);
				if (isset($GLOBALS['langues'][$lang])) return $lang;
				if (isset($GLOBALS['langues'][$lang])) {
					return $lang;
				}
			}
		}
	}
@@ -280,24 +290,26 @@ function regler_langue_navigateurT() {
}

function menu_languesT($lang, $script = '', $hidden = array()) {

	$r = '';
	if (preg_match(',action=([a-z_]+),', $script, $m)) {
		$r .= "<input type='hidden' name='action' value='".$m[1]."' />";
		$script .= '&amp;';
	}
	else
	} else {
		$script .= '?';
	}

	foreach ($hidden as $k => $v)
		if ($v AND $k!='etape') $script .= "$k=$v&amp;";

	foreach ($hidden as $k => $v) {
		if ($v and $k!='etape') {
			$script .= "$k=$v&amp;";
		}
	}
	$r .= '<select name="lang"
		onchange="window.location=\''.$script.'lang=\'+this.value;">';

	foreach ($GLOBALS['langues'] as $l => $nom)
	foreach ($GLOBALS['langues'] as $l => $nom) {
		$r .= '<option value="'.$l.'"' . ($l == $lang ? ' selected="selected"' : '')
			. '>'.$nom."</option>\n";
	}
	$r .= '</select> <noscript><div><input type="submit" name="ok" value="ok" /></div></noscript>';
	return $r;
}
@@ -322,12 +334,15 @@ function tester_repertoire() {
	@rmdir('test');
	@unlink('test'); // effacer au cas ou
	@touch('test');
	if ($uid > 0 && $uid == $uid2 && @fileowner('test') == $uid)
	if ($uid > 0 && $uid == $uid2 && @fileowner('test') == $uid) {
		$chmod = 0700;
	else if ($gid > 0 && $gid == $gid2 && @filegroup('test') == $gid)
	} else {
		if ($gid > 0 && $gid == $gid2 && @filegroup('test') == $gid) {
			$chmod = 0770;
	else
		} else {
			$chmod = 0777;
		}
	}
	// Appliquer de plus les droits d'acces du script
	if ($perms > 0) {
		$perms = ($perms & 0777) | (($perms & 0444) >> 2);
@@ -352,56 +367,67 @@ function tester_repertoire() {
function init_http($get, $url, $refuse_gz = false) {
	//global $http_proxy;
	$fopen = false;
	if (!preg_match(",^http://,i", _URL_LOADER_PROXY))
	if (!preg_match(",^http://,i", _URL_LOADER_PROXY)) {
		$http_proxy = '';
	else
	} else {
		$http_proxy = _URL_LOADER_PROXY;
	}

	$t = @parse_url($url);
	$host = $t['host'];
	if ($t['scheme'] == 'http') {
		$scheme = 'http'; $scheme_fsock='';
		$scheme = 'http';
		$scheme_fsock = '';
	} else {
		$scheme = $t['scheme']; $scheme_fsock=$scheme.'://';
		$scheme = $t['scheme'];
		$scheme_fsock = $scheme.'://';
	}
	if (!isset($t['port']) or !($port = $t['port'])) {
		$port = 80;
	}
	$query = isset($t['query']) ? $t['query'] : '';
	if (!isset($t['path']) or !($path = $t['path'])) {
		$path = "/";
	}
	if (!isset($t['port']) OR !($port = $t['port'])) $port = 80;
	$query = isset($t['query'])?$t['query']:"";
	if (!isset($t['path']) OR !($path = $t['path'])) $path = "/";

	if ($http_proxy) {
		$t2 = @parse_url($http_proxy);
		$proxy_host = $t2['host'];
		$proxy_user = $t2['user'];
		$proxy_pass = $t2['pass'];
		if (!($proxy_port = $t2['port'])) $proxy_port = 80;
		if (!($proxy_port = $t2['port'])) {
			$proxy_port = 80;
		}
		$f = @fsockopen($proxy_host, $proxy_port);
	} else
	} else {
		$f = @fsockopen($scheme_fsock.$host, $port);
	}

	if ($f) {
		if ($http_proxy)
			fputs($f, "$get $scheme://$host" . (($port != 80) ? ":$port" : "") . $path . ($query ? "?$query" : "") . " HTTP/1.0\r\n");
		else
		if ($http_proxy) {
			fputs(
				$f,
				"$get $scheme://$host" . (($port != 80) ? ":$port" : "") .
				$path . ($query ? "?$query" : "") . " HTTP/1.0\r\n"
			);
		} else {
			fputs($f, "$get $path" . ($query ? "?$query" : "") . " HTTP/1.0\r\n");

		}
		$version_affichee = isset($GLOBALS['spip_version_affichee'])?$GLOBALS['spip_version_affichee']:"xx";
		fputs($f, "Host: $host\r\n");
		fputs($f, "User-Agent: SPIP-$version_affichee (http://www.spip.net/)\r\n");

		// Proxy authentifiant
		if (isset($proxy_user) AND $proxy_user) {
		if (isset($proxy_user) and $proxy_user) {
			fputs($f, "Proxy-Authorization: Basic "
			. base64_encode($proxy_user . ":" . $proxy_pass) . "\r\n");
		}

	}
	} elseif (!$http_proxy) {
		// fallback : fopen
	else if (!$http_proxy) {
		$f = @fopen($url, "rb");
		$fopen = true;
	}
	} else {
		// echec total
	else {
		$f = false;
	}

@@ -417,9 +443,12 @@ function recuperer_page($url) {

	// Accepter les URLs au format feed:// ou qui ont oublie le http://
	$url = preg_replace(',^feed://,i', 'http://', $url);
	if (!preg_match(',^[a-z]+://,i', $url)) $url = 'http://'.$url;
	if (!preg_match(',^[a-z]+://,i', $url)) {
		$url = 'http://'.$url;
	}

	for ($i=0;$i<10;$i++) {	// dix tentatives maximum en cas d'entetes 301...
	// dix tentatives maximum en cas d'entetes 301...
	for ($i = 0; $i < 10; $i++) {
		list($f, $fopen) = init_http('GET', $url);

		// si on a utilise fopen() - passer a la suite
@@ -433,8 +462,9 @@ function recuperer_page($url) {
			$s = trim(fgets($f, 16384));
			if (preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) {
				$status = $r[1];
			} else {
				return;
			}
			else return;

			// Entetes HTTP de la page
			$headers = '';
@@ -443,15 +473,17 @@ function recuperer_page($url) {
				if (preg_match(',^Location: (.*),i', $s, $r)) {
					$location = $r[1];
				}
				if (preg_match(",^Content-Encoding: .*gzip,i", $s))
				if (preg_match(",^Content-Encoding: .*gzip,i", $s)) {
					$gz = true;
				}
			if ($status >= 300 AND $status < 400 AND $location)
			}
			if ($status >= 300 and $status < 400 and $location) {
				$url = $location;
			else if ($status != 200)
			} elseif ($status != 200) {
				return;
			else
			} else {
				break; # ici on est content
			}
			fclose($f);
			$f = false;
		}
@@ -463,8 +495,9 @@ function recuperer_page($url) {
	}

	$result = '';
	while (!feof($f))
	while (!feof($f)) {
		$result .= fread($f, 16384);
	}
	fclose($f);

	// Decompresser le flux
@@ -481,11 +514,11 @@ function telecharger_langue($lang, $droits) {
	$GLOBALS['idx_lang'] = 'i18n_tradloader_'.$lang;
	if (!file_exists(_DIR_BASE.$fichier)) {
		$contenu = recuperer_page(_URL_LOADER_DL.$fichier.".txt");
		if ($contenu AND $droits) {
		if ($contenu and $droits) {
			ecrire_fichierT(_DIR_BASE.$fichier, $contenu);
			include(_DIR_BASE.$fichier);
			return true;
		} elseif($contenu AND !$droits) {
		} elseif ($contenu and !$droits) {
			eval('?'.'>'.$contenu);
			return true;
		} else {
@@ -511,7 +544,7 @@ function selectionner_langue($droits) {
	}

	# reglage par defaut selon les preferences du brouteur
	if (!$lang OR !isset($langues[$lang])) {
	if (!$lang or !isset($langues[$lang])) {
		$lang = regler_langue_navigateurT();
	}

@@ -524,7 +557,7 @@ function selectionner_langue($droits) {
	setcookie('spip_lang_ecrire', $lang);

	# RTL
	if ($lang == 'ar' OR $lang == 'he' OR $lang == 'fa') {
	if ($lang == 'ar' or $lang == 'he' or $lang == 'fa') {
		$GLOBALS['spip_lang_right']='left';
		$GLOBALS['spip_lang_dir']='rtl';
	} else {
@@ -541,11 +574,11 @@ function debut_html($corps='', $hidden=array()) {

	global $lang, $spip_lang_dir, $spip_lang_right, $version_installee;

  if ($version_installee)
	if ($version_installee) {
		$titre = _TT('tradloader:titre_maj', array('paquet'=>strtoupper(_NOM_PAQUET_ZIP)));
		else
	} else {
		$titre = _TT('tradloader:titre', array('paquet'=>strtoupper(_NOM_PAQUET_ZIP)));

	}
	$css = $js = '';
	foreach (explode(',', _SPIP_LOADER_EXTRA) as $fil) {
		switch (strrchr($fil, '.')) {
@@ -563,9 +596,9 @@ function debut_html($corps='', $hidden=array()) {
	}

	$hid = '';
	foreach ($hidden as $k => $v)
	foreach ($hidden as $k => $v) {
		$hid .= "<input type='hidden' name='$k' value='$v' />\n";

	}
	$script = _DIR_BASE . _SPIP_LOADER_SCRIPT;
	echo
	"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
@@ -664,7 +697,9 @@ function nettoyer_racine($fichier) {
	@unlink(_DIR_BASE.'pclzip.php');
	$d = opendir(_DIR_BASE);
	while (false !== ($f = readdir($d))) {
		if(preg_match('/^tradloader_(.+).php$/', $f)) @unlink(_DIR_BASE.$f);
		if (preg_match('/^tradloader_(.+).php$/', $f)) {
			@unlink(_DIR_BASE.$f);
		}
	}
	closedir($d);
	return true;
@@ -688,7 +723,9 @@ function microtime_float()
function verifie_zlib_ok()
{
	global $taux;
	if (!function_exists("gzopen") && !function_exists("gzopen64")) return false;
	if (!function_exists("gzopen") and !function_exists("gzopen64")) {
		return false;
	}

	if (!file_exists($f = _DIR_BASE . 'pclzip.php')) {
		$taux = microtime_float();
@@ -721,10 +758,9 @@ function spip_loader_reinstalle() {
	if (!defined('_SPIP_LOADER_UPDATE_AUTEURS')) {
		define('_SPIP_LOADER_UPDATE_AUTEURS', '1');
	}
	if (!isset($GLOBALS['auteur_session']['statut'])
	OR $GLOBALS['auteur_session']['statut'] != '0minirezo'
	OR !in_array($GLOBALS['auteur_session']['id_auteur'],
	explode(':', _SPIP_LOADER_UPDATE_AUTEURS))) {
	if (!isset($GLOBALS['auteur_session']['statut']) or
		$GLOBALS['auteur_session']['statut'] != '0minirezo' or
		!in_array($GLOBALS['auteur_session']['id_auteur'], explode(':', _SPIP_LOADER_UPDATE_AUTEURS))) {
		include_spip('inc/headers');
		include_spip('inc/minipres');
		http_status('403');
@@ -735,8 +771,7 @@ function spip_loader_reinstalle() {
	}
}

function spip_deballe_paquet($paquet, $fichier, $dest, $range)
{
function spip_deballe_paquet($paquet, $fichier, $dest, $range) {
	global $chmod;

	// le repertoire temporaire est invariant pour permettre la reprise
@@ -749,22 +784,27 @@ function spip_deballe_paquet($paquet, $fichier, $dest, $range)
	$start_index = isset($_REQUEST['start']) ? intval($_REQUEST['start']) : 0;

	if ($start_index < $max_index) {
		if (!$range) $range = _PCL_ZIP_RANGE;
		if (!$range) {
			$range = _PCL_ZIP_RANGE;
		}
		$end_index = min($start_index + $range, $max_index);
		$ok &= $zip->extractByIndex("$start_index-$end_index",
					PCLZIP_OPT_PATH, $tmp,
					PCLZIP_OPT_SET_CHMOD, $chmod,
		$ok &= $zip->extractByIndex(
			"$start_index-$end_index",
			PCLZIP_OPT_PATH,
			$tmp,
			PCLZIP_OPT_SET_CHMOD,
			$chmod,
			PCLZIP_OPT_REPLACE_NEWER,
					PCLZIP_OPT_REMOVE_PATH, _REMOVE_PATH_ZIP."/",
					PCLZIP_CB_POST_EXTRACT, 'touchCallBack'
			PCLZIP_OPT_REMOVE_PATH,
			_REMOVE_PATH_ZIP."/",
			PCLZIP_CB_POST_EXTRACT,
			'touchCallBack'
		);
	}

	if (!$ok OR $zip->error_code<0) {
	if (!$ok or $zip->error_code < 0) {
		debut_html();

		echo _TT('tradloader:donnees_incorrectes',
					array('erreur' => $zip->errorInfo()));
		echo _TT('tradloader:donnees_incorrectes', array('erreur' => $zip->errorInfo()));
		fin_html();
	} else {
		// si l'extraction n'est pas finie, relancer
@@ -781,8 +821,7 @@ function spip_deballe_paquet($paquet, $fichier, $dest, $range)
			@mkdir(_DIR_PLUGINS, $chmod);
			$dir = _DIR_PLUGINS . $dest;
			$url = _DIR_BASE._SPIP_LOADER_PLUGIN_RETOUR;
		}
		else {
		} else {
			$dir =  _DIR_BASE;
			$url = _DIR_BASE._SPIP_LOADER_URL_RETOUR;
		}
@@ -793,10 +832,10 @@ function spip_deballe_paquet($paquet, $fichier, $dest, $range)
	}
}

function spip_redirige_boucle($url, $progres = ""){
function spip_redirige_boucle($url, $progres = ''){
	//@apache_setenv('no-gzip', 1); // provoque page blanche chez certains hebergeurs donc ne pas utiliser
	@ini_set("zlib.output_compression","0"); // pour permettre l'affichage au fur et a mesure
	@ini_set("output_buffering","off");
	@ini_set('zlib.output_compression', '0'); // pour permettre l'affichage au fur et a mesure
	@ini_set('output_buffering', 'off');
	@ini_set('implicit_flush', 1);
	@ob_implicit_flush(1);
	$corps = '<meta http-equiv="refresh" content="0;'.$url.'">';
@@ -855,8 +894,7 @@ function spip_presente_deballe($fichier, $paquet, $dest, $range) {
			'<div class="erreur">'
			. _TT('tradloader:echec_php', array('php1' => $version_php_installee, 'php2' => $version_php_spip))
			. '</div>';
	}
	else {
	} else {
		$bouton =
			"<div style='text-align:".$GLOBALS['spip_lang_right']."'>"
			. '<input type="submit" value="' . $bouton . '" />'
@@ -890,7 +928,7 @@ function spip_recupere_paquet($paquet, $fichier, $dest, $range)
{
	$contenu = recuperer_page(_URL_SPIP_DEPOT . $paquet);

	if(!($contenu AND ecrire_fichierT($fichier, $contenu))) {
	if (!($contenu and ecrire_fichierT($fichier, $contenu))) {
		debut_html();
		echo _TT('tradloader:echec_chargement'), "$paquet, $fichier, $range" ;
		fin_html();
@@ -905,7 +943,7 @@ function spip_deballe($paquet, $etape, $dest, $range)
{
	$fichier = _DIR_BASE . basename($paquet);

	if ($etape == 'fichier'	AND file_exists($fichier)) {
	if ($etape == 'fichier'	and file_exists($fichier)) {
		// etape finale: deploiement de l'archive
		spip_deballe_paquet($paquet, $fichier, $dest, $range);

@@ -928,9 +966,9 @@ error_reporting(E_ALL ^ E_NOTICE);

// PHP >= 5.3 rale si cette init est absente du php.ini et consorts
// On force a defaut de savoir anticiper l'erreur (il doit y avoir mieux)
if (function_exists('date_default_timezone_set'))
if (function_exists('date_default_timezone_set')) {
	date_default_timezone_set('Europe/Paris');

}
$GLOBALS['taux'] = 0; // calcul eventuel du taux de transfert+dezippage

// En cas de reinstallation, verifier que le demandeur a les droits avant tout
@@ -940,10 +978,10 @@ if (@file_exists('ecrire/inc_version.php')) {
	define('_SPIP_LOADER_URL_RETOUR', "ecrire/?exec=accueil");
	include_once 'ecrire/inc_version.php';
	$version_installee = $GLOBALS['spip_version_branche'];
	if (
	  (defined('_FILE_CONNECT') AND _FILE_CONNECT AND strpos(_FILE_CONNECT, '.php'))
	  OR defined('_SITES_ADMIN_MUTUALISATION')
	) {
	if ((defined('_FILE_CONNECT') and
		_FILE_CONNECT and
		strpos(_FILE_CONNECT, '.php')) or
		defined('_SITES_ADMIN_MUTUALISATION')) {
		spip_loader_reinstalle();
	}
} else {
@@ -958,7 +996,8 @@ if (!$GLOBALS['lang']) {
	//on ne peut pas telecharger
	$GLOBALS['lang'] = 'fr'; //francais par defaut
	$GLOBALS['i18n_tradloader_fr']['titre'] = 'T&eacute;l&eacute;chargement de SPIP';
	$GLOBALS['i18n_tradloader_fr']['echec_chargement'] = '<h4>Le chargement a &eacute;chou&eacute;. Veuillez r&eacute;essayer, ou utiliser l\'installation manuelle.</h4>';
	$GLOBALS['i18n_tradloader_fr']['echec_chargement'] = '<h4>Le chargement a &eacute;chou&eacute;.'.
	' Veuillez r&eacute;essayer, ou utiliser l\'installation manuelle.</h4>';
	debut_html();
	echo _TT('tradloader:echec_chargement');
	fin_html();
@@ -966,10 +1005,14 @@ if (!$GLOBALS['lang']) {
	//on ne peut pas ecrire
	debut_html();
	$q = $_SERVER['QUERY_STRING'];
	echo _TT('tradloader:texte_preliminaire',
			array('paquet'=>strtoupper(_NOM_PAQUET_ZIP),
	echo _TT(
		'tradloader:texte_preliminaire',
		array(
			'paquet' => strtoupper(_NOM_PAQUET_ZIP),
			'href'   => ('spip_loader.php' . ($q ? "?$q" : '')),
					'chmod'=>sprintf('%04o',$chmod)));
			'chmod'  => sprintf('%04o', $chmod)
		)
	);
	fin_html();
} elseif (!verifie_zlib_ok()) {
	// on ne peut pas decompresser
@@ -986,9 +1029,14 @@ if (!$GLOBALS['lang']) {
		$paquet = urldecode($_REQUEST['chemin']);
	}

	if ((strpos($paquet, '../') !== false) OR (substr($paquet,-4,4) != '.zip')) {
	if ((strpos($paquet, '../') !== false) or (substr($paquet, -4, 4) != '.zip')) {
		die("chemin incorrect $paquet");
	} else {
		spip_deballe($paquet, (isset($_REQUEST['etape']) ? $_REQUEST['etape'] : ''), $dest, intval(isset($_REQUEST['range']) ? $_REQUEST['range'] : 0));
		spip_deballe(
			$paquet,
			(isset($_REQUEST['etape']) ? $_REQUEST['etape'] : ''),
			$dest,
			intval(isset($_REQUEST['range']) ? $_REQUEST['range'] : 0)
		);
	}
}