more simplifications
[platal.git] / include / wiki.inc.php
index 000690e..cb05c88 100644 (file)
  ***************************************************************************/
 
 function wiki_pagename() {
-    if (!Get::get('n')) {
+    if (!Get::v('n')) {
         return null;
     }
 
-    $words = explode('/', trim(Get::get('n'), '/'));
+    $words = explode('/', trim(Get::v('n'), '/'));
     if (count($words) == 2) {
         return join('.', $words);
     }
@@ -46,10 +46,15 @@ function wiki_clear_all_cache()
     system('rm -f '.wiki_work_dir().'/cache_*');
 }
 
-function get_perms($n)
+function wiki_perms_options() {
+    return array('public' => 'Public', 'logged' => 'Connecté',
+                  'mdp' => 'Authentifié', 'admin' => 'Admin');
+}
+
+function wiki_get_perms($n)
 {
     $file  = wiki_work_dir().'/'.str_replace('/', '.', $n);
-    $lines = explode("\n", file_get_contents($file));
+    $lines = explode("\n", @file_get_contents($file));
     foreach ($lines as $line) {
         list($k, $v) = explode('=', $line, 2);
         if ($k == 'platal_perms') {
@@ -59,6 +64,45 @@ function get_perms($n)
     return array('logged', 'admin');
 }
 
+function wiki_putfile($f, $s)
+{
+    $fp = fopen($f, 'w');
+    fputs($fp, $s);
+    fclose($fp);
+}
+
+function wiki_set_perms($n, $pr, $pw)
+{
+    $file  = wiki_work_dir().'/'.str_replace('/', '.', $n);
+    if (!file_exists($file))
+        return false;
+
+    $p = $pr . ':' . $pw;
+
+    $lines = explode("\n", file_get_contents($file));
+    foreach ($lines as $i => $line) {
+        list($k, $v) = explode('=', $line, 2);
+        if ($k == 'platal_perms') {
+            $lines[$i] = 'platal_perms='.$p;
+            wiki_putfile($file, join("\n", $lines));
+            return true;
+        }
+    }
+
+    array_splice($lines, 1, 0, array('platal_perms='.$p));
+    wiki_putfile($file, join("\n", $lines));
+    return true;
+}
+
+function wiki_may_have_perms($perm) {
+    switch ($perm) {
+      case 'public': return true;
+      case 'logged': return S::logged();
+      case 'mdp':    return S::logged();
+      default:       return S::has_perms();
+    }
+}
+
 function wiki_apply_perms($perm) {
     global $page, $platal;
 
@@ -67,15 +111,19 @@ function wiki_apply_perms($perm) {
         return;
 
       case 'logged':
-        if (!XorgSession::doAuthCookie()) {
+        if (empty($GLOBALS['IS_XNET_SITE']) && !XorgSession::doAuthCookie()) {
             $platal = new Platal();
             $platal->force_login($page);
         }
+        if ($GLOBALS['IS_XNET_SITE'] && !$_SESSION['session']->doAuth()) {
+            $platal = new Xnet();
+            $platal->force_login($page);
+        }
         return;
 
       default:
-        if (!XorgSession::doAuth()) {
-            $platal = new Platal();
+        if (!$_SESSION['session']->doAuth()) {
+            $platal = empty($GLOBALS['IS_XNET_SITE']) ? new Platal() : new Xnet();
             $platal->force_login($page);
         }
         if ($perm == 'admin') {