Cleaned up files and checked indentation

This commit is contained in:
Simon DELAGE 2014-09-07 11:51:44 +02:00
parent 0bc23734bf
commit 8488c1c86f
6 changed files with 87 additions and 107 deletions

View File

@ -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;
}
}

View File

@ -6,16 +6,16 @@
* @license: CC Attribution-Share Alike 3.0 Unported <http://creativecommons.org/licenses/by-sa/3.0/>
*/
$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'] = '';

View File

@ -6,16 +6,16 @@
* @license: CC Attribution-Share Alike 3.0 Unported <http://creativecommons.org/licenses/by-sa/3.0/>
*/
$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');

View File

@ -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 '<li>'.$lang['loggedinas'].' : <a href="'.wl($this->getPrivateID()).'" class="uhp_private" rel="nofollow" title="'.$this->getLang('privatenamespace').'">'.$INFO['userinfo']['name'].' ('.$_SERVER['REMOTE_USER'].')</a></li>';
} elseif ($param != null) {
return '<a href="'.wl($this->getPrivateID()).'" rel="nofollow" title="'.$this->getLang('privatenamespace').'">'.$param.'</a>';
} else {
return '<a href="'.wl($this->getPrivateID()).'" rel="nofollow" title="'.$this->getLang('privatenamespace').'">'.$this->getLang('privatenamespace').'</a>';
}
return '<li>'.$lang['loggedinas'].' : <a href="'.wl($this->getPrivateID()).'" class="uhp_private" rel="nofollow" title="'.$this->getLang('privatenamespace').'">'.$INFO['userinfo']['name'].' ('.$_SERVER['REMOTE_USER'].')</a></li>';
} elseif ($param != null) {
return '<a href="'.wl($this->getPrivateID()).'" rel="nofollow" title="'.$this->getLang('privatenamespace').'">'.$param.'</a>';
} else {
return '<a href="'.wl($this->getPrivateID()).'" rel="nofollow" title="'.$this->getLang('privatenamespace').'">'.$this->getLang('privatenamespace').'</a>';
}
}
function getPublicLink($param=null) {
global $INFO;
global $lang;
if ($param == "loggedinas") {
return '<li>'.$lang['loggedinas'].' : <a href="'.wl($this->getPublicID()).'" class="uhp_public" rel="nofollow" title="'.$this->getLang('publicpage').'">'.$INFO['userinfo']['name'].' ('.$_SERVER['REMOTE_USER'].')</a></li>';
} elseif ($param != null) {
return '<a href="'.wl($this->getPublicID()).'" rel="nofollow" title="'.$this->getLang('publicpage').'">'.$param.'</a>';
} else {
return '<a href="'.wl($this->getPublicID()).'" rel="nofollow" title="'.$this->getLang('publicpage').'">'.$this->getLang('publicpage').'</a>';
}
return '<li>'.$lang['loggedinas'].' : <a href="'.wl($this->getPublicID()).'" class="uhp_public" rel="nofollow" title="'.$this->getLang('publicpage').'">'.$INFO['userinfo']['name'].' ('.$_SERVER['REMOTE_USER'].')</a></li>';
} elseif ($param != null) {
return '<a href="'.wl($this->getPublicID()).'" rel="nofollow" title="'.$this->getLang('publicpage').'">'.$param.'</a>';
} else {
return '<a href="'.wl($this->getPublicID()).'" rel="nofollow" title="'.$this->getLang('publicpage').'">'.$this->getLang('publicpage').'</a>';
}
}
function privateNamespace() {

View File

@ -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';

View File

@ -6,22 +6,22 @@
* @license: CC Attribution-Share Alike 3.0 Unported <http://creativecommons.org/licenses/by-sa/3.0/>
*/
$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 <code>%USER%</code> 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 <code>user</code> 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 <code>@ALL</code> and <code>@user</code> 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 <code>user</code> is used, you will have to manually handle interwiki user link used by <code>showuseras</code> 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: <code>data/pages/wiki</code> (wich will make templates editable within DokuWiki) or <code>lib/plugins/userhomepage</code> (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 <code>%USER%</code> 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 <code>user</code> 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 <code>@ALL</code> and <code>@user</code> 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 <code>user</code> is used, you will have to manually handle interwiki user link used by <code>showuseras</code> 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: <code>data/pages/wiki</code> (wich will make templates editable within DokuWiki) or <code>lib/plugins/userhomepage</code> (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.';