UTF-8 fixes
[platal.git] / include / wiki.inc.php
index 750df72..1a5717e 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2006 Polytechnique.org                              *
+ *  Copyright (C) 2003-2007 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -19,7 +19,8 @@
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
-function wiki_pagename() {
+function wiki_pagename()
+{
     if (!Get::v('n')) {
         return null;
     }
@@ -36,7 +37,16 @@ function wiki_pagename() {
     pl_redirect($a.'/'.$b);
 }
 
-function wiki_work_dir() {
+function wiki_filename($s)
+{
+    if (@iconv('utf-8', 'utf-8', $s) == $s) {
+        return utf8_decode($s);
+    }
+    return $s;
+}
+
+function wiki_work_dir()
+{
     global $globals;
     return $globals->spoolroot.'/spool/wiki.d';
 }
@@ -47,16 +57,16 @@ function wiki_clear_all_cache()
 }
 
 function wiki_perms_options() {
-    return array('public' => 'Public', 'logged' => 'Connecté',
-                  'mdp' => 'Authentifié', 'admin' => 'Admin');
+    return array('public' => 'Public', 'logged' => 'Connecté',
+                  'mdp' => 'Authentifié', 'admin' => 'Admin');
 }
 
 function wiki_get_perms($n)
 {
-    $file  = wiki_work_dir().'/'.str_replace('/', '.', $n);
+    $file  = wiki_work_dir().'/'.wiki_filename(str_replace('/', '.', $n));
     $lines = explode("\n", @file_get_contents($file));
     foreach ($lines as $line) {
-        list($k, $v) = explode('=', $line, 2);
+        @list($k, $v) = explode('=', $line, 2);
         if ($k == 'platal_perms') {
             return explode(':', $v);
         }
@@ -73,9 +83,10 @@ function wiki_putfile($f, $s)
 
 function wiki_set_perms($n, $pr, $pw)
 {
-    $file  = wiki_work_dir().'/'.str_replace('/', '.', $n);
-    if (!file_exists($file))
+    $file  = wiki_work_dir().'/'.wiki_filename(str_replace('/', '.', $n));
+    if (!file_exists($file)) {
         return false;
+    }
 
     $p = $pr . ':' . $pw;
 
@@ -104,23 +115,22 @@ function wiki_may_have_perms($perm) {
 }
 
 function wiki_apply_perms($perm) {
-    global $page, $platal;
+    global $page, $platal, $globals;
 
     switch ($perm) {
       case 'public':
         return;
 
       case 'logged':
-        if ((empty($GLOBALS['IS_XNET_SITE']) && !XorgSession::doAuthCookie()) ||
-          ($GLOBALS['IS_XNET_SITE'] && !$_SESSION['session']->doAuth())) {
-            $platal = new Platal();
+        if (!call_user_func(array($globals->session, 'doAuthCookie'))) {
+            $platal =  empty($GLOBALS['IS_XNET_SITE']) ? new Platal() : new Xnet();
             $platal->force_login($page);
         }
         return;
 
       default:
-        if (!$_SESSION['session']->doAuth()) {
-            $platal = new Platal();
+        if (!call_user_func(array($globals->session, 'doAuth'))) {
+            $platal = empty($GLOBALS['IS_XNET_SITE']) ? new Platal() : new Xnet();
             $platal->force_login($page);
         }
         if ($perm == 'admin') {
@@ -130,4 +140,14 @@ function wiki_apply_perms($perm) {
     }
 }
 
+function wiki_require_page($pagename)
+{
+    global $globals;
+    $pagename_slashes = str_replace('.','/',$pagename);
+    $pagename_dots = str_replace('/','.',$pagename);
+    if (is_file(wiki_work_dir().'/cache_'.$pagename_dots.'.tpl')) return;
+    system('wget '.$globals->baseurl.'/'.$pagename_slashes.' -O /dev/null');
+}
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>