2 /***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21 $wikisites = array('xorg','xnet');
23 function wiki_pagename() {
24 $n = str_replace('/', '.', Env
::get('n', false
));
25 $keywords = explode('.', $n);
26 $count = count($keywords);
28 $n = $keywords[0].".".$keywords[0];
30 $n = $keywords[$count - 2].".".$keywords[$count - 1];
32 if ($wikiurl && ($urln = str_replace('.', '/', $n)) != Env
::get('n') && $n != Env
::get('n'))
33 redirect($globals->relurl
.'/'.$urln);
38 function wiki_work_dir() {
40 return realpath($globals->spoolroot
.'htdocs/'.$globals->wiki
->workdir
);
43 function wiki_template($n) {
45 return $tpl = wiki_work_dir().'/cache_'.$wikisite.'_'.$n.'.tpl';
48 // several files are used for wiki :
49 // - spool/wiki.d/PageName : the wiki page
50 // - spool/wiki.d/cache_PageName.tpl : the template cache
51 // - spool/templates_c/%%...%%cache_PageName.tpl.php : the PHP from Smarty
52 function wiki_clear_cache($n) {
53 global $page, $wikisite, $wikisites;
54 $oldwikisite = $wikisite;
55 foreach ($wikisites as $s) {
57 $tpl = wiki_template($n);
59 $page->clear_compiled_tpl($tpl);
61 $wikisite = $oldwikisite;
64 // editing pages are not static but used templates too, so we used
65 // temp template files containing result from wiki
66 function wiki_create_tmp($content) {
67 $tmpfile = tempnam(wiki_work_dir(), "temp_");
68 $f = fopen($tmpfile, 'w');
74 function wiki_clean_tmp() {
75 // clean old tmp files (more than one hour)
76 $wiki_work_dir = wiki_work_dir();
77 $dh = opendir(wiki_work_dir());
79 while (($file = readdir($dh)) !== false
) {
80 if (strpos($file, 'temp_') === 0) {
81 $created = filectime($wiki_work_dir.'/'.$file);
82 if ($time-$created > 60 * 60)
83 @unlink
($wiki_work_dir.'/'.$file);
88 function wiki_assign_auth() {
89 global $page, $wiki_auths;
90 $page->assign('logged', logged());
91 $page->assign('identified', identified());
92 $page->assign('has_perms', has_perms());
93 $page->assign('public', true
);
94 $page->assign('wiki_admin', has_perms() && identified());
97 // cannot be in a function because pmwiki use all vars as if it was globals
98 //function new_wiki_page() {
99 global $page, $globals;
100 // the wiki keword is given in the n var
101 if ( $n = wiki_pagename() )
104 $wiki_template = wiki_template($n);
105 $tmpfile_exists = file_exists($wiki_template);
107 // don't recreate the tpl if it already exists
108 if (Env
::get('action') ||
!$tmpfile_exists)
110 if ($tmpfile_exists) {
111 wiki_clear_cache($n);
114 // we leave pmwiki do whatever it wants and store everything
116 require_once($globals->spoolroot
.'/'.$globals->wiki
->wikidir
.'/pmwiki.php');
118 $wikiAll = ob_get_clean();
119 // the pmwiki skin we are using (almost empty) has these keywords:
120 $i = strpos($wikiAll, "<!--/HeaderText-->");
121 $j = strpos($wikiAll, "<!--/PageLeftFmt-->", $i);
124 if (Env
::get('action'))
126 // clean old tmp files
128 $page->assign('xorg_extra_header', substr($wikiAll, 0, $i));
129 // create new tmp files with editing page from wiki engine
130 $wiki_template = wiki_create_tmp(substr($wikiAll, $j));
132 if (!$tmpfile_exists)
134 $f = fopen($wiki_template, 'w');
135 fputs($f, substr($wikiAll, $j));
140 //return $wiki_template;