diff --git a/action.php b/action.php index a4deecf..290b84d 100644 --- a/action.php +++ b/action.php @@ -14,16 +14,18 @@ require_once (DOKU_PLUGIN . 'action.php'); require_once (DOKU_PLUGIN . '/acl/admin.php'); class action_plugin_userhomepage extends DokuWiki_Action_Plugin{ + function register(&$controller) { $controller->register_hook('AUTH_LOGIN_CHECK', 'AFTER', $this, 'init',array()); $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'redirect',array()); } + function init(&$event, $param) { global $conf; global $INFO; - // COPY TEMPLATES IF NEEDED + // COPY TEMPLATES IF NEEDED if (!file_exists(DOKU_INC.$this->getConf('templates_path').'/userhomepage_private.txt')) { - // If version 3.0.4 was installed, 'templatepath' option isn't empty and points to former template + // If version 3.0.4 was installed, 'templatepath' option isn't empty and points to former template if (($this->getConf('templatepath') != null) && (file_exists(DOKU_INC.$this->getConf('templatepath')))) { if (!copy(DOKU_INC.$this->getConf('templatepath'), DOKU_INC.$this->getConf('templates_path').'/userhomepage_private.txt')) { // echo ' An error occured while attempting to copy old template to '.DOKU_INC.$this->getConf('templates_path').'/userhomepage_private.txt'; @@ -51,7 +53,7 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{ // private:simon or private:simon_delage $this->private_ns = cleanID($this->getConf('users_namespace').':'. $this->privateNamespace()); } - // private:simon:start.txt + // ...:start.txt or ...:simon_delage.txt $this->private_page = $this->private_ns . ':' . $this->privatePage(); // user:simon.txt $this->public_page = cleanID($this->getConf('public_pages_ns').':'. $_SERVER['REMOTE_USER']); @@ -61,16 +63,16 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{ if (($this->getConf('create_private_ns')) && ($this->getConf('set_permissions'))) { // If use_name_string is enabled, we can't use ACL wildcard if ($this->getConf('use_name_string')) { - $ns = $this->private_ns.':*'; - $acl->_acl_add($ns, $INFO['userinfo']['name'], AUTH_DELETE); - } else { - $acl->_acl_add(cleanID($this->getConf('users_namespace')).':%USER%:*', '%USER%', AUTH_DELETE); - } + $ns = $this->private_ns.':*'; + $acl->_acl_add($ns, $INFO['userinfo']['name'], AUTH_DELETE); + } else { + $acl->_acl_add(cleanID($this->getConf('users_namespace')).':%USER%:*', '%USER%', AUTH_DELETE); + } $acl->_acl_add(cleanID($this->getConf('users_namespace')).':*', '@ALL', (int)$this->getConf('set_permissions_others')); $acl->_acl_add(cleanID($this->getConf('users_namespace')).':*', '@user', (int)$this->getConf('set_permissions_others')); - } + } // For public user pages - if (($this->getConf('create_public_page')) && ($this->getConf('set_permissions_public'))) { + if (($this->getConf('create_public_page')) && ($this->getConf('set_permissions_public'))) { $acl->_acl_add(cleanID($this->getConf('public_pages_ns')).':%USER%', '%USER%', AUTH_EDIT); $acl->_acl_add(cleanID($this->getConf('public_pages_ns')).':*', '@ALL', AUTH_READ); $acl->_acl_add(cleanID($this->getConf('public_pages_ns')).':*', '@user', AUTH_READ); @@ -82,6 +84,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)); } + function redirect(&$event, $param) { global $conf; global $INFO; @@ -132,6 +135,7 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{ } } } + function privateNamespace() { if ( $this->getConf('use_name_string')) { global $INFO; @@ -143,6 +147,7 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{ return strtolower($_SERVER['REMOTE_USER']); } } + function privatePage() { if ($this->getConf('use_start_page')) { global $conf; @@ -151,47 +156,23 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{ return $this->privateNamespace(); } } -// function _template_private() { -// global $INFO; -// global $lang; -// $content = io_readFile($this->private_page_template, false); -// $content = str_replace('@PRIVATENAMESPACE@',$this->getLang('privatenamespace'),$content); -// // Improved template process to use any replacement patterns from https://www.dokuwiki.org/namespace_templates -// // Code by Christian Nancy -// // Build a fake data structure for the parser -// $data = array('tpl' => $content, 'id' => $this->private_page); -// // Use the built-in parser -// $content = parsePageTemplate($data); -// return $content; -// } -// function _template_public() { -// global $INFO; -// global $lang; -// $content = io_readFile($this->public_page_template, false); -// $content = str_replace('@PUBLICPAGE@',$this->getLang('publicpage'),$content); -// // Improved template process to use any replacement patterns from https://www.dokuwiki.org/namespace_templates -// // Code by Christian Nancy -// // Build a fake data structure for the parser -// $data = array('tpl' => $content, 'id' => $this->private_page); -// // Use the built-in parser -// $content = parsePageTemplate($data); -// return $content; -// } + function apply_template($type) { global $INFO; global $lang; // Improved template process to use any replacement patterns from https://www.dokuwiki.org/namespace_templates based on code proposed by Christian Nancy if ($type == 'private') { - $content = io_readFile($this->private_page_template, false); - $content = str_replace('@PRIVATENAMESPACE@',$this->getLang('privatenamespace'),$content); - $data = array('tpl' => $content, 'id' => $this->private_page); - } elseif ($type == 'public') { - $content = io_readFile($this->public_page_template, false); - $content = str_replace('@PUBLICPAGE@',$this->getLang('publicpage'),$content); - $data = array('tpl' => $content, 'id' => $this->public_page); - } - // Use the built-in parser - $content = parsePageTemplate($data); + $content = io_readFile($this->private_page_template, false); + $content = str_replace('@PRIVATENAMESPACE@',$this->getLang('privatenamespace'),$content); + $data = array('tpl' => $content, 'id' => $this->private_page); + } elseif ($type == 'public') { + $content = io_readFile($this->public_page_template, false); + $content = str_replace('@PUBLICPAGE@',$this->getLang('publicpage'),$content); + $data = array('tpl' => $content, 'id' => $this->public_page); + } + // Use the built-in parser + $content = parsePageTemplate($data); return $content; } + } diff --git a/conf/default.php b/conf/default.php index 318032c..fc31b2c 100644 --- a/conf/default.php +++ b/conf/default.php @@ -6,16 +6,16 @@ * @license: CC Attribution-Share Alike 3.0 Unported */ -$conf['create_private_ns'] = 0; -$conf['use_name_string'] = 0; -$conf['use_start_page'] = 1; -$conf['users_namespace'] = 'private'; -$conf['set_permissions'] = 1; -$conf['set_permissions_others'] = '0'; -$conf['group_by_name'] = 1; -$conf['edit_before_create'] = 0; -$conf['create_public_page'] = 0; -$conf['public_pages_ns'] = 'user'; -$conf['set_permissions_public'] = 1; -$conf['templates_path'] = 'data/pages/wiki'; -$conf['templatepath'] = ''; + $conf['create_private_ns'] = 0; + $conf['use_name_string'] = 0; + $conf['use_start_page'] = 1; + $conf['users_namespace'] = 'private'; + $conf['set_permissions'] = 1; + $conf['set_permissions_others'] = '0'; + $conf['group_by_name'] = 1; + $conf['edit_before_create'] = 0; + $conf['create_public_page'] = 0; + $conf['public_pages_ns'] = 'user'; + $conf['set_permissions_public'] = 1; + $conf['templates_path'] = 'data/pages/wiki'; + $conf['templatepath'] = ''; diff --git a/conf/metadata.php b/conf/metadata.php index 9e6026e..ec08801 100644 --- a/conf/metadata.php +++ b/conf/metadata.php @@ -6,16 +6,16 @@ * @license: CC Attribution-Share Alike 3.0 Unported */ -$meta['create_private_ns'] = array('onoff'); -$meta['use_name_string'] = array('onoff','_caution' => 'warning'); -$meta['use_start_page'] = array('onoff'); -$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['edit_before_create'] = array('onoff'); -$meta['create_public_page'] = array('onoff'); -$meta['public_pages_ns'] = array('string','_pattern' => '/^(|[a-zA-Z\-:]+)$/','_caution' => 'warning'); -$meta['set_permissions_public'] = array('onoff'); -$meta['templates_path'] = array('string'); -$meta['templatepath'] = array('string'); + $meta['create_private_ns'] = array('onoff'); + $meta['use_name_string'] = array('onoff','_caution' => 'warning'); + $meta['use_start_page'] = array('onoff'); + $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['edit_before_create'] = array('onoff'); + $meta['create_public_page'] = array('onoff'); + $meta['public_pages_ns'] = array('string','_pattern' => '/^(|[a-zA-Z\-:]+)$/','_caution' => 'warning'); + $meta['set_permissions_public'] = array('onoff'); + $meta['templates_path'] = array('string'); + $meta['templatepath'] = array('string'); diff --git a/helper.php b/helper.php index 30c02a8..c5cdeb4 100644 --- a/helper.php +++ b/helper.php @@ -21,7 +21,6 @@ class helper_plugin_userhomepage extends DokuWiki_Plugin { } // ...:start.txt return $this->private_page = cleanID($this->private_ns.':'.$this->privateStart()); - } function getPublicID() { @@ -32,24 +31,24 @@ class helper_plugin_userhomepage extends DokuWiki_Plugin { global $INFO; global $lang; if ($param == "loggedinas") { - return '
  • '.$lang['loggedinas'].' : '.$INFO['userinfo']['name'].' ('.$_SERVER['REMOTE_USER'].')
  • '; - } elseif ($param != null) { - return ''.$param.''; - } else { - return ''.$this->getLang('privatenamespace').''; - } + return '
  • '.$lang['loggedinas'].' : '.$INFO['userinfo']['name'].' ('.$_SERVER['REMOTE_USER'].')
  • '; + } elseif ($param != null) { + return ''.$param.''; + } else { + return ''.$this->getLang('privatenamespace').''; + } } function getPublicLink($param=null) { global $INFO; global $lang; if ($param == "loggedinas") { - return '
  • '.$lang['loggedinas'].' : '.$INFO['userinfo']['name'].' ('.$_SERVER['REMOTE_USER'].')
  • '; - } elseif ($param != null) { - return ''.$param.''; - } else { - return ''.$this->getLang('publicpage').''; - } + return '
  • '.$lang['loggedinas'].' : '.$INFO['userinfo']['name'].' ('.$_SERVER['REMOTE_USER'].')
  • '; + } elseif ($param != null) { + return ''.$param.''; + } else { + return ''.$this->getLang('publicpage').''; + } } function privateNamespace() { diff --git a/lang/en/lang.php b/lang/en/lang.php index 93778c1..d4f953c 100644 --- a/lang/en/lang.php +++ b/lang/en/lang.php @@ -5,6 +5,6 @@ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) */ -$lang['created'] = 'Created from template by Userhompage plugin'; -$lang['privatenamespace'] = 'Private Namespace'; -$lang['publicpage'] = 'Public Page'; + $lang['created'] = 'Created from template by Userhompage plugin'; + $lang['privatenamespace'] = 'Private Namespace'; + $lang['publicpage'] = 'Public Page'; diff --git a/lang/en/settings.php b/lang/en/settings.php index 0042d36..cddb96e 100644 --- a/lang/en/settings.php +++ b/lang/en/settings.php @@ -6,22 +6,22 @@ * @license: CC Attribution-Share Alike 3.0 Unported */ -$lang['create_private_ns'] = 'Create user\'s private namespace'; -$lang['use_name_string'] = 'Use user\'s full name instead of login for his private namespace (enabling this option will prevent using %USER% ACL wildcard and make ACL more complex).'; -$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.'; -$lang['set_permissions_others'] = 'If set permission is enabled, what permission for other people (both @ALL and @user groups) ?'; -$lang['set_permissions_others_o_0'] = 'None'; -$lang['set_permissions_others_o_1'] = 'Read'; -$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['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 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['set_permissions_public'] = 'Automatically configure ACL for the namespace set above (read access to anyone and edit rigth for each user on his own public plage).'; -$lang['templates_path'] = 'Path from DokuWiki root to store templates (userhomepage_private.txt and userhomepage_public.txt). Examples: data/pages/wiki (wich will make templates editable within DokuWiki) or lib/plugins/userhomepage (usefull in a farm setup to centralize templates).'; -$lang['templatepath'] = 'Template path from version 3.0.4 if it was installed before. Don\'t change it, it is only there for backward compatibility. If this file exists, it will be used as default for new private namespace start page template.'; + $lang['create_private_ns'] = 'Create user\'s private namespace'; + $lang['use_name_string'] = 'Use user\'s full name instead of login for his private namespace (enabling this option will prevent using %USER% ACL wildcard and make ACL more complex).'; + $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.'; + $lang['set_permissions_others'] = 'If set permission is enabled, what permission for other people (both @ALL and @user groups) ?'; + $lang['set_permissions_others_o_0'] = 'None'; + $lang['set_permissions_others_o_1'] = 'Read'; + $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['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 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['set_permissions_public'] = 'Automatically configure ACL for the namespace set above (read access to anyone and edit rigth for each user on his own public plage).'; + $lang['templates_path'] = 'Path from DokuWiki root to store templates (userhomepage_private.txt and userhomepage_public.txt). Examples: data/pages/wiki (wich will make templates editable within DokuWiki) or lib/plugins/userhomepage (usefull in a farm setup to centralize templates).'; + $lang['templatepath'] = 'Template path from version 3.0.4 if it was installed before. Don\'t change it, it is only there for backward compatibility. If this file exists, it will be used as default for new private namespace start page template.';