2 /***************************************************************************
3 * Copyright (C) 2003-2004 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 ***************************************************************************/
22 require_once("xorg.inc.php");
24 // this page is to create a smarty template page from a wiki file
25 // the wiki engine used is pmwiki.
26 // the templates created are stored in wiki.d/cache_wikiword.tpl
28 // some page can be seen by everybody (public), but to validate a password
29 // if we arrive here before setting new access we need to try an auth
30 new_skinned_page('wiki.tpl', Env
::has('response') ? AUTH_MDP
: AUTH_PUBLIC
);
32 function assign_auth()
35 $page->assign('logged', logged());
36 $page->assign('identified', identified());
37 $page->assign('has_perms', has_perms());
38 $page->assign('public', true
);
39 $page->assign('wiki_admin', has_perms() && identified());
42 if ($globals->wiki
->wikidir
) {
43 // the wiki keword is given in the n var
44 if ($n = Env
::get('n', false
))
46 // Get the correcti wiki keywords
47 $n = str_replace('/', '.', $n);
48 $keywords = explode('.', $n);
49 $count = count($keywords);
51 $n = $keywords[0].".".$keywords[0];
53 $n = $keywords[$count - 2].".".$keywords[$count - 1];
54 if (($urln = str_replace('.', '/', $n)) != Env
::get('n') &&
57 header("Location: ".$globals->baseurl
.'/'.$urln);
62 $dir_wiki_tmp = '../spool/wiki.d/';
63 $tpl_name = 'cache_'.$n.'.tpl';
64 $short_tpl = $dir_wiki_tmp.$tpl_name;
65 $dir_tpl = $globals->spoolroot
.'templates/'.$dir_wiki_tmp;
66 $tpl = $globals->spoolroot
.'templates/'.$short_tpl;
67 $tmpfile_exists = file_exists($tpl);
69 // don't recreate the tpl if it already exists
70 if (Env
::get('action') ||
!$tmpfile_exists)
72 if ($tmpfile_exists) {
74 $templates_cache_dir = '../spool/templates_c/';
75 $dh = opendir($templates_cache_dir);
76 while (false
!== ($filename = readdir($dh))) if (strpos($filename, $tpl_name) !== false
)
77 unlink($templates_cache_dir.$filename);
80 // we leave pmwiki do whatever it wants and store everything
82 require_once(dirname(dirname(__FILE__
)).'/'.$globals->wiki
->wikidir
.'/pmwiki.php');
84 $wikiAll = ob_get_clean();
85 // the pmwiki skin we are using (almost empty) has these keywords:
86 $i = strpos($wikiAll, "<!--/HeaderText-->");
87 $j = strpos($wikiAll, "<!--/PageLeftFmt-->", $i);
90 if (Env
::get('action'))
92 // clean old tmp files (more than one hour)
93 $dh = opendir($dir_wiki_tmp);
95 while (($file = readdir($dh)) !== false
)
97 if (strpos($file, 'temp_') === 0)
99 $created = filectime($dir_wiki_tmp.$file);
100 if ($time-$created > 60 * 60)
101 unlink($dir_wiki_tmp.$file);
105 $page->assign('xorg_extra_header', substr($wikiAll, 0, $i));
106 $tmp_tpl = tempnam($dir_tpl, "temp_");
107 $f = fopen($tmp_tpl, 'w');
108 fputs($f, substr($wikiAll, $j));
110 new_skinned_page($tmp_tpl, AUTH_PUBLIC
);
112 if (!$tmpfile_exists)
114 $f = fopen($tpl, 'w');
115 fputs($f, substr($wikiAll, $j));
118 new_skinned_page($short_tpl, AUTH_PUBLIC
);
123 $page->assign('xorg_extra_header', "<script type='text/JavaScript'>\n<!--\nNix={map:null,convert:function(a){Nix.init();var s='';for(i=0;i<a.length;i++){var b=a.charAt(i);s+=((b>='A'&&b<='Z')||(b>='a'&&b<='z')?Nix.map[b]:b);}return s;},init:function(){if(Nix.map!=null)return;var map=new Array();var s='abcdefghijklmnopqrstuvwxyz';for(i=0;i<s.length;i++)map[s.charAt(i)]=s.charAt((i+13)%26);for(i=0;i<s.length;i++)map[s.charAt(i).toUpperCase()]=s.charAt((i+13)%26).toUpperCase();Nix.map=map;},decode:function(a){document.write(Nix.convert(a));}}\n//-->\n</script>\n");
125 $page->addCssLink('css/wiki.css');