| 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"); |
| 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 |
| 30 | new_skinned_page('wiki.tpl', Env::has('response') ? AUTH_MDP : AUTH_PUBLIC); |
| 31 | |
| 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 | |
| 42 | if ($globals->wiki->wikidir) { |
| 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/'; |
| 63 | $short_tpl = $dir_wiki_tmp.'cache_'.$n.'.tpl'; |
| 64 | $dir_tpl = $globals->spoolroot.'templates/'.$dir_wiki_tmp; |
| 65 | $tpl = $globals->spoolroot.'templates/'.$short_tpl; |
| 66 | $tmpfile_exists = file_exists($tpl); |
| 67 | |
| 68 | // don't recreate the tpl if it already exists |
| 69 | if (Env::get('action') || !$tmpfile_exists) |
| 70 | { |
| 71 | // we leave pmwiki do whatever it wants and store everything |
| 72 | ob_start(); |
| 73 | require_once(dirname(dirname(__FILE__)).'/'.$globals->wiki->wikidir.'/pmwiki.php'); |
| 74 | |
| 75 | $wikiAll = ob_get_clean(); |
| 76 | // the pmwiki skin we are using (almost empty) has these keywords: |
| 77 | $i = strpos($wikiAll, "<!--/HeaderText-->"); |
| 78 | $j = strpos($wikiAll, "<!--/PageLeftFmt-->", $i); |
| 79 | |
| 80 | } |
| 81 | if (Env::get('action')) |
| 82 | { |
| 83 | // clean old tmp files (more than one hour) |
| 84 | $dh = opendir($dir_wiki_tmp); |
| 85 | $time = time(); |
| 86 | while (($file = readdir($dh)) !== false) |
| 87 | { |
| 88 | if (strpos($file, 'temp_') === 0) |
| 89 | { |
| 90 | $created = filectime($dir_wiki_tmp.$file); |
| 91 | if ($time-$created > 60 * 60) |
| 92 | unlink($dir_wiki_tmp.$file); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | $page->assign('xorg_extra_header', substr($wikiAll, 0, $i)); |
| 97 | $tmp_tpl = tempnam($dir_tpl, "temp_"); |
| 98 | $f = fopen($tmp_tpl, 'w'); |
| 99 | fputs($f, substr($wikiAll, $j)); |
| 100 | fclose($f); |
| 101 | new_skinned_page($tmp_tpl, AUTH_PUBLIC); |
| 102 | if ($tmpfile_exists) |
| 103 | unlink($tpl); |
| 104 | } else { |
| 105 | if (!$tmpfile_exists) |
| 106 | { |
| 107 | $f = fopen($tpl, 'w'); |
| 108 | fputs($f, substr($wikiAll, $j)); |
| 109 | fclose($f); |
| 110 | } |
| 111 | new_skinned_page($short_tpl, AUTH_PUBLIC); |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | $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"); |
| 117 | assign_auth(); |
| 118 | $page->addCssLink('css/wiki.css'); |
| 119 | |
| 120 | $page->run(); |
| 121 | ?> |