merge the two files now that they are smaller.
[platal.git] / include / wiki.inc.php
CommitLineData
0df3edb9 1<?php
2/***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
0df3edb9 21
22function wiki_pagename() {
06a5e65b 23 if (!Env::get('n')) {
ed912c6e 24 return null;
25 }
06a5e65b 26
8929b42e 27 $words = explode('/', trim(Env::get('n'), '/'));
06a5e65b 28 if (count($words) == 2) {
29 return join('.', $words);
30 }
31
32 array_unshift($words, $words[0]);
33 $b = array_pop($words);
34 $a = array_pop($words);
35
0df3edb9 36 global $globals;
06a5e65b 37 redirect($globals->baseurl.'/'.$a.'/'.$b);
0df3edb9 38}
39
40function wiki_work_dir() {
41 global $globals;
06a5e65b 42 return $globals->spoolroot.'/spool/wiki.d';
0df3edb9 43}
44
ed912c6e 45function wiki_clear_all_cache()
46{
47 system("rm -f ".wiki_work_dir()."/cache_*");
48}
49
0df3edb9 50// editing pages are not static but used templates too, so we used
51// temp template files containing result from wiki
52function wiki_create_tmp($content) {
53 $tmpfile = tempnam(wiki_work_dir(), "temp_");
54 $f = fopen($tmpfile, 'w');
55 fputs($f, $content);
56 fclose($f);
57 return $tmpfile;
58}
59
60function wiki_clean_tmp() {
61 // clean old tmp files (more than one hour)
62 $wiki_work_dir = wiki_work_dir();
63 $dh = opendir(wiki_work_dir());
64 $time = time();
65 while (($file = readdir($dh)) !== false) {
66 if (strpos($file, 'temp_') === 0) {
67 $created = filectime($wiki_work_dir.'/'.$file);
68 if ($time-$created > 60 * 60)
69 @unlink($wiki_work_dir.'/'.$file);
70 }
71 }
72}
73
74function wiki_assign_auth() {
6bc327ec 75 global $page;
06a5e65b 76 $page->assign('true', true);
77 $page->assign('public', true);
78 $page->assign('logged', S::logged());
cab08090 79 $page->assign('identified', S::identified());
06a5e65b 80 $page->assign('has_perms', S::has_perms());
0df3edb9 81}
82
0df3edb9 83?>