bf98922c |
1 | <?php |
2 | /*************************************************************************** |
3 | * Copyright (C) 2003-2004 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 | ***************************************************************************/ |
21 | |
22 | require_once("xorg.inc.php"); |
2907d401 |
23 | |
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 |
27 | |
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 |
d575b75c |
30 | new_skinned_page('wiki.tpl', Env::has('response') ? AUTH_MDP : AUTH_PUBLIC); |
31 | |
2907d401 |
32 | function assign_auth() |
33 | { |
34 | global $page; |
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()); |
40 | } |
41 | |
d575b75c |
42 | if ($globals->wiki->wikidir) { |
2907d401 |
43 | // the wiki keword is given in the n var |
44 | if ($n = Env::get('n', false)) |
45 | { |
46 | // Get the correcti wiki keywords |
47 | $n = str_replace('/', '.', $n); |
48 | $keywords = explode('.', $n); |
49 | $count = count($keywords); |
50 | if ($count == 1) |
51 | $n = $keywords[0].".".$keywords[0]; |
52 | else |
53 | $n = $keywords[$count - 2].".".$keywords[$count - 1]; |
54 | if (($urln = str_replace('.', '/', $n)) != Env::get('n') && |
55 | $n != Env::get('n')) |
56 | { |
57 | header("Location: ".$globals->baseurl.'/'.$urln); |
58 | die(); |
59 | } |
60 | $_REQUEST['n'] = $n; |
61 | |
62 | $dir_wiki_tmp = '../spool/wiki.d/'; |
1f334cf2 |
63 | $tpl_name = 'cache_'.$n.'.tpl'; |
64 | $short_tpl = $dir_wiki_tmp.$tpl_name; |
2907d401 |
65 | $dir_tpl = $globals->spoolroot.'templates/'.$dir_wiki_tmp; |
66 | $tpl = $globals->spoolroot.'templates/'.$short_tpl; |
67 | $tmpfile_exists = file_exists($tpl); |
d575b75c |
68 | |
2907d401 |
69 | // don't recreate the tpl if it already exists |
70 | if (Env::get('action') || !$tmpfile_exists) |
71 | { |
1f334cf2 |
72 | if ($tmpfile_exists) { |
73 | unlink($tpl); |
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); |
78 | } |
79 | |
2907d401 |
80 | // we leave pmwiki do whatever it wants and store everything |
81 | ob_start(); |
82 | require_once(dirname(dirname(__FILE__)).'/'.$globals->wiki->wikidir.'/pmwiki.php'); |
d575b75c |
83 | |
2907d401 |
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); |
88 | |
89 | } |
90 | if (Env::get('action')) |
91 | { |
92 | // clean old tmp files (more than one hour) |
93 | $dh = opendir($dir_wiki_tmp); |
94 | $time = time(); |
95 | while (($file = readdir($dh)) !== false) |
96 | { |
97 | if (strpos($file, 'temp_') === 0) |
98 | { |
99 | $created = filectime($dir_wiki_tmp.$file); |
100 | if ($time-$created > 60 * 60) |
101 | unlink($dir_wiki_tmp.$file); |
102 | } |
103 | } |
104 | |
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)); |
109 | fclose($f); |
110 | new_skinned_page($tmp_tpl, AUTH_PUBLIC); |
2907d401 |
111 | } else { |
112 | if (!$tmpfile_exists) |
113 | { |
114 | $f = fopen($tpl, 'w'); |
1f334cf2 |
115 | fputs($f, substr($wikiAll, $j)); |
116 | fclose($f); |
2907d401 |
117 | } |
118 | new_skinned_page($short_tpl, AUTH_PUBLIC); |
119 | } |
120 | } |
d575b75c |
121 | } |
bf98922c |
122 | |
2907d401 |
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"); |
124 | assign_auth(); |
52165f0e |
125 | $page->addCssLink('css/wiki.css'); |
bf98922c |
126 | |
127 | $page->run(); |
128 | ?> |