[SPIP Zone] r3752 - in /_dev_/spip_loader: spip_loader.php spip_loader.php3

Author: cedric@yterium.com
Date: Sat Jul 1 02:20:25 2006
New Revision: 3752

Log:
soyons in'

Added:
    _dev_/spip_loader/spip_loader.php
      - copied unchanged from r3751, _dev_/spip_loader/spip_loader.php3
Removed:
    _dev_/spip_loader/spip_loader.php3

Removed: _dev_/spip_loader/spip_loader.php3

--- _dev_/spip_loader/spip_loader.php3 (original)
+++ _dev_/spip_loader/spip_loader.php3 (removed)
@@ -1,514 +0,0 @@
-<?php
-
- define('_PAQUET_ZIP','SPIP-v1-9pr1-6750.zip');
- define('_URL_BASE_DL',"http://www.spip.net/spip-dev/DISTRIB/");
- //
- // Gestion des droits d'acces
- //
- function tester_repertoire() {
- global $chmod;
-
- $ok = false;
- $self = basename($_SERVER['PHP_SELF']);
- $uid = @fileowner('.');
- $uid2 = @fileowner($self);
- $gid = @filegroup('.');
- $gid2 = @filegroup($self);
- $perms = @fileperms($self);
-
- // Comparer l'appartenance d'un fichier cree par PHP
- // avec celle du script et du repertoire courant
- @rmdir('test');
- @unlink('test'); // effacer au cas ou
- @touch('test');
- if ($uid > 0 && $uid == $uid2 && @fileowner('test') == $uid)
- $chmod = 0700;
- else if ($gid > 0 && $gid == $gid2 && @filegroup('test') == $gid)
- $chmod = 0770;
- else
- $chmod = 0777;
- // Appliquer de plus les droits d'acces du script
- if ($perms > 0) {
- $perms = ($perms & 0777) | (($perms & 0444) >> 2);
- $chmod |= $perms;
- }
- @unlink('test');
-
- // Verifier que les valeurs sont correctes
-
- @mkdir('test', $chmod);
- @chmod('test', $chmod);
- $f = @fopen('test/test.php', 'w');
- if ($f) {
- @fputs($f, '<'.'?php $ok = true; ?'.'>');
- @fclose($f);
- @chmod('test/test.php', $chmod);
- include('test/test.php');
- }
- @unlink('test/test.php');
- @rmdir('test');
-
- return $ok;
- }
-
- //
- // Demarre une transaction HTTP (s'arrete a la fin des entetes)
- // retourne un descripteur de fichier
- //
- function init_http($get, $url, $refuse_gz=false) {
- global $http_proxy;
- $fopen = false;
- if (!eregi("^http://", $http_proxy))
- $http_proxy = '';
-
- $t = @parse_url($url);
- $host = $t['host'];
- if ($t['scheme'] == 'http') {
- $scheme = 'http'; $scheme_fsock='';
- } else {
- $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 ($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;
- $f = @fsockopen($proxy_host, $proxy_port);
- } 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
- 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) {
- fputs($f, "Proxy-Authorization: Basic "
- . base64_encode($proxy_user . ":" . $proxy_pass) . "\r\n");
- }
-
- }
- // fallback : fopen
- else if (!$http_proxy) {
- $f = @fopen($url, "rb");
- $fopen = true;
- }
- // echec total
- else {
- $f = false;
- }
-
- return array($f, $fopen);
- }
-
- //
- // Recupere une page sur le net
- // et au besoin l'encode dans le charset local
- //
- // options : get_headers si on veut recuperer les entetes
- 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;
-
- for ($i=0;$i<10;$i++) { // dix tentatives maximum en cas d'entetes 301...
- list($f, $fopen) = init_http('GET', $url);
-
- // si on a utilise fopen() - passer a la suite
- if ($fopen) {
- break;
- } else {
- // Fin des entetes envoyees par SPIP
- fputs($f,"\r\n");
-
- // Reponse du serveur distant
- $s = trim(fgets($f, 16384));
- if (ereg('^HTTP/[0-9]+\.[0-9]+ ([0-9]+)', $s, $r)) {
- $status = $r[1];
- }
- else return;
-
- // Entetes HTTP de la page
- $headers = '';
- while ($s = trim(fgets($f, 16384))) {
- $headers .= $s."\n";
- if (eregi('^Location: (.*)', $s, $r)) {
- $location = $r[1];
- }
- if (preg_match(",^Content-Encoding: .*gzip,i", $s))
- $gz = true;
- }
- if ($status >= 300 AND $status < 400 AND $location)
- $url = $location;
- else if ($status != 200)
- return;
- else
- break; # ici on est content
- fclose($f);
- $f = false;
- }
- }
-
- // Contenu de la page
- if (!$f) {
- return false;
- }
-
- $result = '';
- while (!feof($f))
- $result .= fread($f, 16384);
- fclose($f);
-
- // Decompresser le flux
- if (isset($gz) AND $gz)
- $result = gzinflate(substr($result,10));
-
- return $result;
- }
-
- //
- // Ecrire un fichier de maniere un peu sure
- //
- function ecrire_fichier ($fichier, $contenu) {
-
- $fp = @fopen($fichier, 'wb');
- $s = @fputs($fp, $contenu, $a = strlen($contenu));
-
- $ok = ($s == $a);
-
- @fclose($fp);
-
- if (!$ok) {
- @unlink($fichier);
- }
-
- return $ok;
- }
-
- //
- // Traduction des textes de SPIP
- //
- function _T($code, $args=array()) {
- global $lang;
- $text = $GLOBALS['i18n_spiploader_'.$lang][$code];
- while (list($name, $value) = @each($args))
- $text = str_replace ("@$name@", $value, $text);
- return $text;
- }
-
- function telecharger_langue($lang, $droits) {
- global $base;
- global $dir_base;
- $fichier = 'spiploader_'.$lang.'.php';
- if(!file_exists($dir_base.$fichier)) {
- $contenu = recuperer_page($base.$fichier);
- if ($contenu AND $droits) {
- ecrire_fichier($dir_base.$fichier, $contenu);
- include($dir_base.$fichier);
- } elseif($contenu AND !$droits) {
- $contenu = preg_replace('/<\?php/', '', $contenu);
- $contenu = preg_replace('/\?>/', '', $contenu);
- eval($contenu);
- } else {
- return false;
- }
- }
- include($dir_base.$fichier);
- return true;
- }
-
- function selectionner_langue($droits) {
- $accept_langs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
- if (is_array($accept_langs)) {
- while(list(, $s) = each($accept_langs)) {
- if (eregi('^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$', trim($s), $r)) {
- $lang = strtolower($r[1]);
- if (telecharger_langue($lang,$droits)) return $lang;
- }
- }
- }
- //si on a trouve aucune langue, on tente le francais (langue par defaut) une derniere fois
- if (telecharger_langue('fr',$droits)) return 'fr';
- return false;
- }
-
- function debut_html() {
- ?>
- <HTML>
-
- <HTML>
- <HEAD>
- <TITLE><?php echo _T('titre'); ?></TITLE>
- <META HTTP-EQUIV="Expires" CONTENT="0">
- <META HTTP-EQUIV="cache-control" CONTENT="no-cache,no-store">
- <META HTTP-EQUIV="pragma" CONTENT="no-cache">
- <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
-
-
- <style>
- <!--
- a {text-decoration: none; }
- A:Hover {color:#FF9900; text-decoration: underline;}
- .forml {width: 100%; background-color: #FFCC66; background-position: center bottom; float: none; color: #000000}
- .formo {width: 100%; background-color: #970038; background-position: center bottom; float: none; color: #FFFFFF}
- .fondl {background-color: #FFCC66; background-position: center bottom; float: none; color: #000000}
- .fondo {background-color: #970038; background-position: center bottom; float: none; color: #FFFFFF}
- .fondf {background-color: #FFFFFF; border-style: solid ; border-width: 1; border-color: #E86519; color: #E86519}
- -->
- </style>
- </HEAD>
-
- <body bgcolor="#FFFFFF" text="#000000" link="#E86519" vlink="#6E003A" alink="#FF9900" TOPMARGIN="0" LEFTMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0">
-
- <BR><BR><BR>
- <CENTER>
- <TABLE WIDTH=450>
- <TR><TD WIDTH=450>
- <FONT FACE="Verdana,Arial,Helvetica,sans-serif" SIZE=4 COLOR="#970038"><B><?php
- echo _T('titre');
- ?></B></FONT>
- <FONT FACE="Georgia,Garamond,Times,serif" SIZE=3>
- <?php
- }
-
-
- function fin_html() {
- ?>
- </FONT>
- </TD></TR></TABLE>
- </CENTER>
- </BODY>
-
- </HTML>
- <?php
- }
-
- function feed_globals($table) {
- if (is_array($GLOBALS[$table])) {
- reset($GLOBALS[$table]);
- while (list($key, $val) = each($GLOBALS[$table])) {
- $GLOBALS[$key] = $val;
- }
- }
- }
-
- function lire_short($f) {
- global $_fread;
- $bin = $_fread($f, 2);
- $res = unpack('na', $bin);
- return $res['a'];
- }
-
- function lire_long($f) {
- global $_fread;
- $bin = $_fread($f, 4);
- $res = unpack('Na', $bin);
- return $res['a'];
- }
-
- function lire_chaine($f) {
- global $_fread;
- $n = lire_long($f);
- if (!$n) return '';
- return $_fread($f, $n);
- }
-
- // Tester si le fichier est un fichier de configuration
- // modifiable par le webmestre (squelettes, etc)
-
- function test_fichier_config($fichier) {
- // Fichiers graphiques modifiables (racine du site)
- if (ereg("^[^/]*\.(gif|jpe?g|png)$", $fichier)) return true;
-
- // Fichiers .php3 dans le repertoire de base
- if (ereg("^([^/]*)\.php3$", $fichier, $regs)) {
- $racine = $regs[1];
- if ($racine == 'inc-urls') return true;
- if (ereg("^(spip_|inc-)", $racine)) return false;
- return true;
- }
-
- return false;
- }
-
- function unpacker_fichier($f) {
- global $dir_base;
- global $_fread;
- global $chmod;
-
- $chaine = $_fread($f, 4);
- if ($chaine != 'spip') {
- return false;
- }
- $chmod_dir = $chmod;
- $chmod_file = $chmod & ~0111;

[... 159 lines stripped ...]