From 0df3edb9fd85fb750c47cee19a3a6b66f370cc97 Mon Sep 17 00:00:00 2001 From: x2001corpet Date: Tue, 6 Jun 2006 07:16:33 +0000 Subject: [PATCH] wiki sur xnet git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@296 839d8a87-29fc-0310-9880-83ba4fa771e5 --- ChangeLog | 4 ++ hooks/xnet.inc.php | 5 +- htdocs.net/css/wiki.css | 35 +++++++++++ htdocs.net/wiki.php | 54 ++++++++++++++++ htdocs/wiki.php | 93 ++------------------------- include/wiki.inc.php | 142 ++++++++++++++++++++++++++++++++++++++++++ include/xnet.inc.php | 7 +++ include/xnet/page.inc.php | 2 + include/xorg.inc.php | 4 ++ plugins/pmwiki.config.php | 5 +- plugins/pmwiki.platalAuth.php | 4 +- 11 files changed, 261 insertions(+), 94 deletions(-) create mode 100644 htdocs.net/css/wiki.css create mode 100644 htdocs.net/wiki.php create mode 100644 include/wiki.inc.php diff --git a/ChangeLog b/ChangeLog index bc75823..40ab164 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,10 @@ New : * Geoloc : Dynamic maps using geodesix plugin -Car + * Xnet : + Use wiki from Xnet. -Car + Use wiki for group pages. -Car + Bug/Wish : * Admin : diff --git a/hooks/xnet.inc.php b/hooks/xnet.inc.php index c82ab8c..1694bab 100644 --- a/hooks/xnet.inc.php +++ b/hooks/xnet.inc.php @@ -1,6 +1,6 @@ wiki->wikidir && $globals->xnet->wiki) { + $wikisite = 'xnet'; + function more_wiki_config() { + global $Conditions, $DefaultPasswords; + $Conditions['has_perms'] = has_perms() || may_update(); + $Conditions['is_member'] = is_member(); + $DefaultPasswords['read'] = 'is_member:'; + } + require_once("wiki.inc.php"); + new_page($wiki_template, AUTH_PUBLIC); + wiki_assign_auth(); +} + +$page->setType($globals->asso('cat')); +$page->assign('xorg_extra_header', "\n"); +$page->assign('is_member', is_member()); +$page->assign('has_perms', has_perms() || may_update()); + +$page->addCssLink('css/wiki.css'); +$page->useMenu(); + +$page->run(); +?> diff --git a/htdocs/wiki.php b/htdocs/wiki.php index 26a3342..aa54451 100644 --- a/htdocs/wiki.php +++ b/htdocs/wiki.php @@ -29,99 +29,14 @@ require_once("xorg.inc.php"); // if we arrive here before setting new access we need to try an auth new_skinned_page('wiki.tpl', Env::has('response') ? AUTH_MDP : AUTH_PUBLIC); -function assign_auth() -{ - global $page; - $page->assign('logged', logged()); - $page->assign('identified', identified()); - $page->assign('has_perms', has_perms()); - $page->assign('public', true); - $page->assign('wiki_admin', has_perms() && identified()); -} - if ($globals->wiki->wikidir) { - // the wiki keword is given in the n var - if ($n = Env::get('n', false)) - { - // Get the correcti wiki keywords - $n = str_replace('/', '.', $n); - $keywords = explode('.', $n); - $count = count($keywords); - if ($count == 1) - $n = $keywords[0].".".$keywords[0]; - else - $n = $keywords[$count - 2].".".$keywords[$count - 1]; - if (($urln = str_replace('.', '/', $n)) != Env::get('n') && - $n != Env::get('n')) - { - header("Location: ".$globals->baseurl.'/'.$urln); - die(); - } - $_REQUEST['n'] = $n; - - $dir_wiki_tmp = '../spool/wiki.d/'; - $tpl_name = 'cache_'.$n.'.tpl'; - $short_tpl = $dir_wiki_tmp.$tpl_name; - $dir_tpl = $globals->spoolroot.'templates/'.$dir_wiki_tmp; - $tpl = $globals->spoolroot.'templates/'.$short_tpl; - $tmpfile_exists = file_exists($tpl); - - // don't recreate the tpl if it already exists - if (Env::get('action') || !$tmpfile_exists) - { - if ($tmpfile_exists) { - unlink($tpl); - $templates_cache_dir = '../spool/templates_c/'; - $dh = opendir($templates_cache_dir); - while (false !== ($filename = readdir($dh))) if (strpos($filename, $tpl_name) !== false) - unlink($templates_cache_dir.$filename); - } - - // we leave pmwiki do whatever it wants and store everything - ob_start(); - require_once(dirname(dirname(__FILE__)).'/'.$globals->wiki->wikidir.'/pmwiki.php'); - - $wikiAll = ob_get_clean(); - // the pmwiki skin we are using (almost empty) has these keywords: - $i = strpos($wikiAll, ""); - $j = strpos($wikiAll, "", $i); - - } - if (Env::get('action')) - { - // clean old tmp files (more than one hour) - $dh = opendir($dir_wiki_tmp); - $time = time(); - while (($file = readdir($dh)) !== false) - { - if (strpos($file, 'temp_') === 0) - { - $created = filectime($dir_wiki_tmp.$file); - if ($time-$created > 60 * 60) - unlink($dir_wiki_tmp.$file); - } - } - - $page->assign('xorg_extra_header', substr($wikiAll, 0, $i)); - $tmp_tpl = tempnam($dir_tpl, "temp_"); - $f = fopen($tmp_tpl, 'w'); - fputs($f, substr($wikiAll, $j)); - fclose($f); - new_skinned_page($tmp_tpl, AUTH_PUBLIC); - } else { - if (!$tmpfile_exists) - { - $f = fopen($tpl, 'w'); - fputs($f, substr($wikiAll, $j)); - fclose($f); - } - new_skinned_page($short_tpl, AUTH_PUBLIC); - } - } + $wikisite = 'xorg'; + require_once("wiki.inc.php"); + new_skinned_page($wiki_template, AUTH_PUBLIC); } $page->assign('xorg_extra_header', "\n"); -assign_auth(); +wiki_assign_auth(); $page->addCssLink('css/wiki.css'); $page->run(); diff --git a/include/wiki.inc.php b/include/wiki.inc.php new file mode 100644 index 0000000..b4aefca --- /dev/null +++ b/include/wiki.inc.php @@ -0,0 +1,142 @@ +relurl.'/'.$urln); + $_REQUEST['n'] = $n; + return $n; +} + +function wiki_work_dir() { + global $globals; + return realpath($globals->spoolroot.'htdocs/'.$globals->wiki->workdir); +} + +function wiki_template($n) { + global $wikisite; + return $tpl = wiki_work_dir().'/cache_'.$wikisite.'_'.$n.'.tpl'; +} + +// several files are used for wiki : +// - spool/wiki.d/PageName : the wiki page +// - spool/wiki.d/cache_PageName.tpl : the template cache +// - spool/templates_c/%%...%%cache_PageName.tpl.php : the PHP from Smarty +function wiki_clear_cache($n) { + global $page, $wikisite, $wikisites; + $oldwikisite = $wikisite; + foreach ($wikisites as $s) { + $wikisite = $s; + $tpl = wiki_template($n); + @unlink($tpl); + $page->clear_compiled_tpl($tpl); + } + $wikisite = $oldwikisite; +} + +// editing pages are not static but used templates too, so we used +// temp template files containing result from wiki +function wiki_create_tmp($content) { + $tmpfile = tempnam(wiki_work_dir(), "temp_"); + $f = fopen($tmpfile, 'w'); + fputs($f, $content); + fclose($f); + return $tmpfile; +} + +function wiki_clean_tmp() { + // clean old tmp files (more than one hour) + $wiki_work_dir = wiki_work_dir(); + $dh = opendir(wiki_work_dir()); + $time = time(); + while (($file = readdir($dh)) !== false) { + if (strpos($file, 'temp_') === 0) { + $created = filectime($wiki_work_dir.'/'.$file); + if ($time-$created > 60 * 60) + @unlink($wiki_work_dir.'/'.$file); + } + } +} + +function wiki_assign_auth() { + global $page, $wiki_auths; + $page->assign('logged', logged()); + $page->assign('identified', identified()); + $page->assign('has_perms', has_perms()); + $page->assign('public', true); + $page->assign('wiki_admin', has_perms() && identified()); +} + +// cannot be in a function because pmwiki use all vars as if it was globals +//function new_wiki_page() { + global $page, $globals; + // the wiki keword is given in the n var + if ( $n = wiki_pagename() ) + { + + $wiki_template = wiki_template($n); + $tmpfile_exists = file_exists($wiki_template); + + // don't recreate the tpl if it already exists + if (Env::get('action') || !$tmpfile_exists) + { + if ($tmpfile_exists) { + wiki_clear_cache($n); + } + + // we leave pmwiki do whatever it wants and store everything + ob_start(); + require_once($globals->spoolroot.'/'.$globals->wiki->wikidir.'/pmwiki.php'); + + $wikiAll = ob_get_clean(); + // the pmwiki skin we are using (almost empty) has these keywords: + $i = strpos($wikiAll, ""); + $j = strpos($wikiAll, "", $i); + + } + if (Env::get('action')) + { + // clean old tmp files + wiki_clean_tmp(); + $page->assign('xorg_extra_header', substr($wikiAll, 0, $i)); + // create new tmp files with editing page from wiki engine + $wiki_template = wiki_create_tmp(substr($wikiAll, $j)); + } else { + if (!$tmpfile_exists) + { + $f = fopen($wiki_template, 'w'); + fputs($f, substr($wikiAll, $j)); + fclose($f); + } + } + } + //return $wiki_template; +//} +?> diff --git a/include/xnet.inc.php b/include/xnet.inc.php index e41b5f8..ce3bf43 100644 --- a/include/xnet.inc.php +++ b/include/xnet.inc.php @@ -44,6 +44,13 @@ function new_page($tpl_name, $min_auth) } // }}} +function new_identification_page() +{ + new_page('', AUTH_MDP); + global $page; + $page->useMenu(); +} + // {{{ function new_group_page() function new_group_page($tpl_name) diff --git a/include/xnet/page.inc.php b/include/xnet/page.inc.php index 39ac9fc..6fd7c7a 100644 --- a/include/xnet/page.inc.php +++ b/include/xnet/page.inc.php @@ -90,6 +90,8 @@ class XnetPage extends PlatalPage if (logged() && may_update()) { $sub = array(); $sub['modifier l\'accueil'] = "$dim/edit.php"; + if ($globals->wiki->wikidir && $globals->xnet->wiki) + $sub['wiki'] = "$dim/Accueil"; if ($globals->asso('mail_domain')) { $sub['envoyer un mail'] = "$dim/mail.php"; $sub['créer une liste'] = "$dim/listes-create.php"; diff --git a/include/xorg.inc.php b/include/xorg.inc.php index 43dc4f6..276cc8b 100644 --- a/include/xorg.inc.php +++ b/include/xorg.inc.php @@ -50,6 +50,10 @@ function _new_page($type, $tpl_name, $min_auth, $admin=false) } // }}} +function new_identification_page() +{ + _new_page(SKINNED, '', AUTH_MDP); +} // {{{ function new_skinned_page() function new_skinned_page($tpl_name, $min_auth) diff --git a/plugins/pmwiki.config.php b/plugins/pmwiki.config.php index 3f561c6..915524b 100644 --- a/plugins/pmwiki.config.php +++ b/plugins/pmwiki.config.php @@ -1,6 +1,6 @@ baseurl; +$ScriptUrl = $globals->relurl; $UploadUrlFmt = $ScriptUrl."/uploads"; $WorkDir = $globals->wiki->workdir; $WikiDir = new PageStore('$FarmD/'.$WorkDir.'/$FullName'); @@ -52,4 +52,7 @@ $GUIButtons['hr'] = array(540, '\\n----\\n', '', '', $GUIButtons['table'] = array(600, '||border=1 width=80%\\n||!Hdr ||!Hdr ||!Hdr ||\\n|| || || ||\\n|| || || ||\\n', '', '', '$GUIButtonDirUrlFmt/table.gif"$[Table]"'); + +if (function_exists('more_wiki_config')) + more_wiki_config(); ?> diff --git a/plugins/pmwiki.platalAuth.php b/plugins/pmwiki.platalAuth.php index 2e13c24..d674b36 100644 --- a/plugins/pmwiki.platalAuth.php +++ b/plugins/pmwiki.platalAuth.php @@ -160,11 +160,11 @@ function AuthPlatal($pagename, $level, $authprompt, $since) // maybe it is because he is not identified if ($authprompt && !identified()) { - new_skinned_page('wiki.tpl', AUTH_MDP); + new_identification_page(); } global $page; - new_skinned_page('', AUTH_MDP); + new_identification_page(); if (has_perms()) { $page->trig('Erreur : page Wiki inutilisable sur plat/al'); } else { -- 2.1.4