X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fwiki.inc.php;h=750df7265854f582717875af53b1d532839f9fc2;hb=4f9e482c39da76dd070b517485b79470d5ffc51b;hp=2aa2dd23a09acbc32ef796bfcfccd72d40725a2d;hpb=8b00e0e0c6f303762f6740c853e7065b1471d245;p=platal.git diff --git a/include/wiki.inc.php b/include/wiki.inc.php index 2aa2dd2..750df72 100644 --- a/include/wiki.inc.php +++ b/include/wiki.inc.php @@ -20,11 +20,11 @@ ***************************************************************************/ 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); } @@ -43,40 +43,91 @@ function wiki_work_dir() { function wiki_clear_all_cache() { - system("rm -f ".wiki_work_dir()."/cache_*"); + system('rm -f '.wiki_work_dir().'/cache_*'); } -// editing pages are not static but used templates too, so we used -// temp template files containing result from wiki -function wiki_create_tmp($content) { - $tmpfile = tempnam(wiki_work_dir(), "temp_"); - $f = fopen($tmpfile, 'w'); - fputs($f, $content); - fclose($f); - return $tmpfile; +function wiki_perms_options() { + return array('public' => 'Public', 'logged' => 'Connecté', + 'mdp' => 'Authentifié', 'admin' => 'Admin'); } -function wiki_clean_tmp() { - // clean old tmp files (more than one hour) - $wiki_work_dir = wiki_work_dir(); - $dh = opendir(wiki_work_dir()); - $time = time(); - while (($file = readdir($dh)) !== false) { - if (strpos($file, 'temp_') === 0) { - $created = filectime($wiki_work_dir.'/'.$file); - if ($time-$created > 60 * 60) - @unlink($wiki_work_dir.'/'.$file); +function wiki_get_perms($n) +{ + $file = wiki_work_dir().'/'.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().'/'.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_assign_auth() { - global $page; - $page->assign('true', true); - $page->assign('public', true); - $page->assign('logged', S::logged()); - $page->assign('identified', S::identified()); - $page->assign('has_perms', S::has_perms()); +function wiki_apply_perms($perm) { + global $page, $platal; + + 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(); + $platal->force_login($page); + } + return; + + default: + if (!$_SESSION['session']->doAuth()) { + $platal = new Platal(); + $platal->force_login($page); + } + if ($perm == 'admin') { + check_perms(); + } + return; + } } ?>