X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fwiki.inc.php;h=110ad3f585cf47e330b299916421da409ad4c8ff;hb=67d7487d7667a7f518b4bc067ef250b9738c2570;hp=6f9c83c022459cbef1624c75b3a46418540789ad;hpb=d7a8b04cfd6812be3c0deb9418f373331f9805f7;p=platal.git diff --git a/include/wiki.inc.php b/include/wiki.inc.php index 6f9c83c..110ad3f 100644 --- a/include/wiki.inc.php +++ b/include/wiki.inc.php @@ -1,6 +1,6 @@ spoolroot.'/spool/wiki.d'; } @@ -46,4 +56,98 @@ function wiki_clear_all_cache() system('rm -f '.wiki_work_dir().'/cache_*'); } +function wiki_perms_options() { + return array('public' => 'Public', 'logged' => 'Connecté', + 'mdp' => 'Authentifié', 'admin' => 'Admin'); +} + +function wiki_get_perms($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); + if ($k == 'platal_perms') { + return explode(':', $v); + } + } + 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().'/'.wiki_filename(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, $globals; + + switch ($perm) { + case 'public': + return; + + case 'logged': + 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 (!call_user_func(array($globals->session, 'doAuth'))) { + $platal = empty($GLOBALS['IS_XNET_SITE']) ? new Platal() : new Xnet(); + $platal->force_login($page); + } + if ($perm == 'admin') { + check_perms(); + } + return; + } +} + +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: ?>