From 96781dbd83b8bc69fabc7516c86b7737037093e3 Mon Sep 17 00:00:00 2001 From: Simon DELAGE Date: Wed, 3 Sep 2014 01:45:56 +0200 Subject: [PATCH] Added more flexibility for templates --- action.php | 21 +++++++++++++++++-- conf/default.php | 3 +-- conf/metadata.php | 3 +-- lang/en/settings.php | 11 +++++----- ...e.txt => userhomepage_private_template.txt | 0 ...ic.txt => userhomepage_public_template.txt | 0 6 files changed, 26 insertions(+), 12 deletions(-) rename _template_private.txt => userhomepage_private_template.txt (100%) rename _template_public.txt => userhomepage_public_template.txt (100%) diff --git a/action.php b/action.php index 98d4771..c04ca6a 100644 --- a/action.php +++ b/action.php @@ -16,6 +16,23 @@ require_once (DOKU_PLUGIN . '/acl/admin.php'); class action_plugin_userhomepage extends DokuWiki_Action_Plugin{ function register(&$controller) { $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'redirect',array()); + $controller->register_hook('AUTH_LOGIN_CHECK', 'AFTER', $this, 'templates',array()); + } + function templates(&$event, $param) { + if (!file_exists(DOKU_INC.$this->getConf('templates_path').'/userhomepage_private_template.txt')) { + if (!copy(DOKU_INC.'lib/plugins/userhomepage/userhomepage_private_template.txt', DOKU_INC.$this->getConf('templates_path').'/userhomepage_private_template.txt')) { + echo ' An error occured while attempting to copy private template.'; + } else { + echo ' Successfully copied private template.'; + } + } + if (!file_exists(DOKU_INC.$this->getConf('templates_path').'/userhomepage_public_template.txt')) { + if (!copy(DOKU_INC.'lib/plugins/userhomepage/userhomepage_public_template.txt', DOKU_INC.$this->getConf('templates_path').'/userhomepage_public_template.txt')) { + echo ' An error occured while attempting to copy public template.'; + } else { + echo ' Successfully copied public template.'; + } + } } function redirect(&$event, $param) { global $conf; @@ -55,7 +72,7 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{ // Write things back to conf/acl.auth.php file_put_contents(DOKU_INC.'conf/acl.auth.php', implode($lines)); // Read private start page template - $this->private_page_template = DOKU_INC . $this->getConf('templatepath'); + $this->private_page_template = DOKU_INC.$this->getConf('templates_path').'/userhomepage_private_template.txt'; // Create private page lock($this->private_page); saveWikiText($this->private_page,$this->_template_private(),$lang['created']); @@ -67,7 +84,7 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{ // If public page doesn't exists, create it (from template) if ($this->getConf('create_public_page') && !page_exists($this->public_page) && !checklock($this->public_page) && !checkwordblock()) { // Read public page template - $this->public_page_template = DOKU_INC . $this->getConf('templatepathpublic'); + $this->public_page_template = DOKU_INC.$this->getConf('templates_path').'/userhomepage_public_template.txt'; // Create public page lock($this->public_page); saveWikiText($this->public_page,$this->_template_public(),$lang['created']); diff --git a/conf/default.php b/conf/default.php index 0fa6069..7dfb07f 100644 --- a/conf/default.php +++ b/conf/default.php @@ -13,8 +13,7 @@ $conf['users_namespace'] = 'private'; $conf['set_permissions'] = 1; $conf['set_permissions_others'] = '0'; $conf['group_by_name'] = 1; -$conf['templatepath'] = 'lib/plugins/userhomepage/_template_private.txt'; $conf['edit_before_create'] = 0; $conf['create_public_page'] = 0; $conf['public_pages_ns'] = 'user'; -$conf['templatepathpublic'] = 'lib/plugins/userhomepage/_template_public.txt'; +$conf['templates_path'] = 'data/pages/wiki'; diff --git a/conf/metadata.php b/conf/metadata.php index 204440d..4d08963 100644 --- a/conf/metadata.php +++ b/conf/metadata.php @@ -13,8 +13,7 @@ $meta['users_namespace'] = array('string','_pattern' => '/^(|[a-zA-Z\-:]+)$/'); $meta['set_permissions'] = array('onoff'); $meta['set_permissions_others'] = array('multichoice','_choices'=>array('0','1','2','4','8','16')); $meta['group_by_name'] = array('onoff'); -$meta['templatepath'] = array('string'); $meta['edit_before_create'] = array('onoff'); $meta['create_public_page'] = array('onoff'); $meta['public_pages_ns'] = array('string','_pattern' => '/^(|[a-zA-Z\-:]+)$/','_caution' => 'warning'); -$meta['templatepathpublic'] = array('string'); +$meta['templates_path'] = array('string'); diff --git a/lang/en/settings.php b/lang/en/settings.php index 8cdff3b..844d736 100644 --- a/lang/en/settings.php +++ b/lang/en/settings.php @@ -7,7 +7,7 @@ */ $lang['create_private_ns'] = 'Create user\'s private namespace'; -$lang['use_name_string'] = 'Use user\'s full name instead of login for his namespace and homepage (will break %USER% wildcard in ACL for that namespace).'; +$lang['use_name_string'] = 'Use user\'s full name instead of login for his namespace (will break %USER% wildcard in ACL for that namespace).'; $lang['use_start_page'] = 'Use the wiki\'s start page string instead of the user\'s namespace string set above for the start page of his namespace.'; $lang['users_namespace'] = 'Namespace under which user namespaces are created (can be anything but user without messing up with Dokuwiki default behaviour).'; $lang['set_permissions'] = 'Automatically configure acl for the namespace set above and give full rights to users on their own namespace.'; @@ -18,9 +18,8 @@ $lang['set_permissions_others_o_2'] = 'Edit'; $lang['set_permissions_others_o_4'] = 'Create'; $lang['set_permissions_others_o_8'] = 'Upload'; $lang['set_permissions_others_o_16'] = 'Delete'; -$lang['group_by_name'] = 'Group users\' namespaces by the first character of user name ?'; -$lang['templatepath'] = 'Doku relative path to the template file for user\'s namespace start page.'; -$lang['edit_before_create'] = 'Allow users to edit their namespace start page before create.'; +$lang['group_by_name'] = 'Group users\' namespaces by the first character of user name?'; +$lang['edit_before_create'] = 'Allow users to edit their namespace start page before create (this will only work if you disable [create_public_page]).'; $lang['create_public_page'] = 'Create a public page for user'; -$lang['public_pages_ns'] = 'Namespace under wich public pages ar created. If a value other than \'user\' is used, ?????????????????'; -$lang['templatepathpublic'] = 'lib/plugins/userhomepage/_template_public.txt'; +$lang['public_pages_ns'] = 'Namespace under wich public pages are created. If a value other than user is used, you will have to manually handle interwiki user link used by showuseras option (in Display settings).'; +$lang['templates_path'] = 'Path from DokuWiki root to store templates (userhomepage_private_template.txt and userhomepage_public_template.txt). Examples: data/pages/wiki (wich will make templates editable within DokuWiki) or lib/plugins/userhomepage (usefull in a farm setup to centralize templates).'; diff --git a/_template_private.txt b/userhomepage_private_template.txt similarity index 100% rename from _template_private.txt rename to userhomepage_private_template.txt diff --git a/_template_public.txt b/userhomepage_public_template.txt similarity index 100% rename from _template_public.txt rename to userhomepage_public_template.txt