[SPIP] v3.0.22-->v3.0.24
[lhc/web/www.git] / www / ecrire / inc / utils.php
index 01ed0c1..80ff11d 100644 (file)
@@ -45,7 +45,9 @@ function charger_fonction($nom, $dossier='exec', $continue=false) {
 
        if (!preg_match(',^\w+$,', $f)){
                if ($continue) return false; //appel interne, on passe
-               die(spip_htmlspecialchars($nom)." pas autorise");
+               include_spip('inc/minipres');
+               echo minipres();
+               exit;
        }
 
        // passer en minuscules (cf les balises de formulaires)
@@ -66,7 +68,8 @@ function charger_fonction($nom, $dossier='exec', $continue=false) {
 
        include_spip('inc/minipres');
        echo minipres(_T('forum_titre_erreur'),
-                _T('fichier_introuvable', array('fichier'=> '<b>'.spip_htmlentities($d).'</b>')));
+                _T('fichier_introuvable', array('fichier'=> '<b>'.spip_htmlentities($d).'</b>')),
+               array('all_inline'=>true,'status'=>404));
        exit;
 }
 
@@ -271,12 +274,27 @@ function set_request($var, $val = NULL, $c=false) {
 
 
 /**
- * Tester si une url est absolue
- * @param  $url
+ * Tester si une URL est absolue
+ * 
+ * On est sur le web, on exclut certains protocoles, 
+ * notamment 'file://', 'php://' et d'autres…
+
+ * @param string $url
  * @return bool
  */
-function tester_url_absolue($url){
-       return preg_match(";^([a-z]+:)?//;Uims",trim($url))?true:false;
+function tester_url_absolue($url) {
+       $url = trim($url);
+       if (preg_match(";^([a-z]{3,7}:)?//;Uims", $url, $m)) {
+               if (
+                       isset($m[1])
+                       and $p = strtolower(rtrim($m[1], ':'))
+                       and in_array($p, array('file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'))
+                 ) {
+                       return false;
+               }
+               return true;
+       }
+       return false;
 }
 
 /**
@@ -872,7 +890,7 @@ function lister_themes_prives(){
                $themes = array(_SPIP_THEME_PRIVE);
                // lors d'une installation neuve, prefs n'est pas definie.
                if (isset($GLOBALS['visiteur_session']['prefs'])) {
-                       $prefs = isset($GLOBALS['visiteur_session']['prefs']);
+                       $prefs = $GLOBALS['visiteur_session']['prefs'];
                } else {
                        $prefs = array();
                }
@@ -1296,6 +1314,16 @@ function url_de_($http,$host,$request,$prof=0){
        $prof = max($prof,0);
 
        $myself = ltrim($request,'/');
+       // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
+       // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
+       if (strpos($myself,'://') !== false) {
+               $myself = explode('://',$myself);
+               array_shift($myself);
+               $myself = implode('://',$myself);
+               $myself = explode('/',$myself);
+               array_shift($myself);
+               $myself = implode('/',$myself);
+       }
        # supprimer la chaine de GET
        list($myself) = explode('?', $myself);
        $url = join('/', array_slice(explode('/', $myself), 0, -1-$prof)).'/';
@@ -1583,6 +1611,9 @@ function spip_initialisation_core($pi=NULL, $pa=NULL, $ti=NULL, $ta=NULL) {
                #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
        }
 
+       // Langue par defaut
+       if (!defined('_LANGUE_PAR_DEFAUT')) define('_LANGUE_PAR_DEFAUT','fr');
+
        // PHP_VERSION_ID dispo depuis PHP 5.2.7
        if (!defined('PHP_VERSION_ID')) {
           $version = explode('.',PHP_VERSION);