- 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_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);
+ 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_feed_perms($perm)
+{
+ if ($perm == 'public') {
+ return;
+ }
+
+ require_once 'rss.inc.php';
+ $uid = init_rss(null, Env::v('user'), Env::v('hash'));
+ $res = XDB::query('SELECT user_id AS uid, IF (nom_usage <> \'\', nom_usage, nom) AS nom, prenom, perms
+ FROM auth_user_md5
+ WHERE user_id = {?}', $uid);
+ if (!$res->numRows()) {
+ exit;
+ }
+ $table = $res->fetchOneAssoc();
+ $_SESSION = array_merge($_SESSION, $table, array('forlife' => Env::v('user')));
+ require_once 'xorg/session.inc.php';
+ $_SESSION['perms'] =& XorgSession::make_perms($_SESSION['perms']);
+ if ($perm == 'logged' || $_SESSION['perms']->hasFlag('admin')) {
+ return;
+ }
+ exit;
+}
+
+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);