Making sure Public NS doesn't conflict with Private one
This commit is contained in:
parent
cb5f4827d7
commit
76ec613777
588
action.php
588
action.php
|
@ -25,269 +25,278 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
|
||||||
|
|
||||||
function init(&$event, $param) {
|
function init(&$event, $param) {
|
||||||
global $conf;
|
global $conf;
|
||||||
$this->helper = plugin_load('helper','userhomepage');
|
|
||||||
// If templates_path option starts with 'data/pages' it can automatically be adapted but should be changed
|
|
||||||
if (substr($this->getConf('templates_path'),0,10) == 'data/pages') {
|
|
||||||
$dest = str_replace("data/pages", "./pages", $this->getConf('templates_path'));
|
|
||||||
msg("Userhomepage option [<code>templates_path</code>] should be changed to a path relative to data folder (as set by Dokuwiki's [<code>savedir</code>] setting). Current value is based on former default (i.e. <code>data/pages/...</code>) and will still work but this message will keep appearing until the value is corrected, check <a href='https://www.dokuwiki.org/plugin:userhomepage'>this page</a> for details.",2);
|
|
||||||
} else {
|
|
||||||
$dest = $this->getConf('templates_path');
|
|
||||||
}
|
|
||||||
$this->dataDir = $conf['savedir'];
|
|
||||||
// CREATE PRIVATE NAMESPACE START PAGE TEMPLATES IF NEEDED (is required by options, doesn't exist yet and a known user is logged in)
|
|
||||||
if (($this->getConf('create_private_ns')) && (!is_file($this->dataDir.'/'.$this->getConf('templates_path').'/userhomepage_private.txt')) && ($_SERVER['REMOTE_USER'] != null)) {
|
|
||||||
// If a template exists in path as builded before 2015/05/14 version, use it as source to create userhomepage_private.txt in new templates_path
|
|
||||||
if ((is_file(DOKU_CONF.'../'.$this->getConf('templates_path').'/userhomepage_private.txt')) && ($this->getConf('templatepath') != null)) {
|
|
||||||
$source = DOKU_CONF.'../'.$this->getConf('templates_path').'/userhomepage_private.txt';
|
|
||||||
// If a template from version 3.0.4 exists, use it as source to create userhomepage_private.txt in templates_path
|
|
||||||
} elseif ((is_file(DOKU_INC.$this->getConf('templatepath'))) && ($this->getConf('templatepath') != null)) {
|
|
||||||
$source = $this->getConf('templatepath');
|
|
||||||
// Otherwise, we're on a fresh install
|
|
||||||
} else {
|
|
||||||
$source = 'lib/plugins/userhomepage/lang/'.$conf['lang'].'/userhomepage_private.default';
|
|
||||||
}
|
|
||||||
$this->copyFile($source, $dest, 'userhomepage_private.txt');
|
|
||||||
}
|
|
||||||
// CREATE PUBLIC PAGE TEMPLATES IF NEEDED (is required by options, doesn't exist yet and a known user is logged in)
|
|
||||||
if (($this->getConf('create_public_page')) && (!is_file($this->dataDir.'/'.$this->getConf('templates_path').'/userhomepage_public.txt')) && ($_SERVER['REMOTE_USER'] != null)) {
|
|
||||||
// If a template exists in path as builded before 2015/05/14 version, use it as source to create userhomepage_private.txt in new templates_path
|
|
||||||
if ((is_file(DOKU_CONF.'../'.$this->getConf('templates_path').'/userhomepage_public.txt')) && ($this->getConf('templatepath') != null)) {
|
|
||||||
$source = DOKU_CONF.'../'.$this->getConf('templates_path').'/userhomepage_public.txt';
|
|
||||||
} else {
|
|
||||||
$source = 'lib/plugins/userhomepage/lang/'.$conf['lang'].'/userhomepage_public.default';
|
|
||||||
}
|
|
||||||
$this->copyFile($source, $dest, 'userhomepage_public.txt');
|
|
||||||
}
|
|
||||||
// TARGETS
|
|
||||||
// ...:start.txt or ...:simon_delage.txt
|
|
||||||
$this->private_page = $this->helper->getPrivateID();
|
|
||||||
// user:simon.txt
|
|
||||||
$this->public_page = $this->helper->getPublicID();
|
|
||||||
|
|
||||||
// If a user is logged in, store timestamp (if it wasn't stored yet)
|
if ($this->settingsCheck(true)) {
|
||||||
if (($_SERVER['REMOTE_USER']!=null) && (!isset($_SESSION['uhptimestamp']))) {
|
$this->helper = plugin_load('helper','userhomepage');
|
||||||
$_SESSION['uhptimestamp'] = time();
|
// If templates_path option starts with 'data/pages' it can automatically be adapted but should be changed
|
||||||
// If no user is logged in and a timestamp exists, set timestamp to null (ensures that redirection will work if user just logged out and comes back before closing browser)
|
if (substr($this->getConf('templates_path'),0,10) == 'data/pages') {
|
||||||
} elseif (($_SERVER['REMOTE_USER']==null) && (isset($_SESSION['uhptimestamp']))) {
|
$dest = str_replace("data/pages", "./pages", $this->getConf('templates_path'));
|
||||||
$_SESSION['uhptimestamp'] = null;
|
msg("Userhomepage option [<code>templates_path</code>] should be changed to a path relative to data folder (as set by Dokuwiki's [<code>savedir</code>] setting). Current value is based on former default (i.e. <code>data/pages/...</code>) and will still work but this message will keep appearing until the value is corrected, check <a href='https://www.dokuwiki.org/plugin:userhomepage'>this page</a> for details.",2);
|
||||||
|
} else {
|
||||||
|
$dest = $this->getConf('templates_path');
|
||||||
|
}
|
||||||
|
$this->dataDir = $conf['savedir'];
|
||||||
|
// CREATE PRIVATE NAMESPACE START PAGE TEMPLATES IF NEEDED (is required by options, doesn't exist yet and a known user is logged in)
|
||||||
|
if (($this->getConf('create_private_ns')) && (!is_file($this->dataDir.'/'.$this->getConf('templates_path').'/userhomepage_private.txt')) && ($_SERVER['REMOTE_USER'] != null)) {
|
||||||
|
// If a template exists in path as builded before 2015/05/14 version, use it as source to create userhomepage_private.txt in new templates_path
|
||||||
|
if ((is_file(DOKU_CONF.'../'.$this->getConf('templates_path').'/userhomepage_private.txt')) && ($this->getConf('templatepath') != null)) {
|
||||||
|
$source = DOKU_CONF.'../'.$this->getConf('templates_path').'/userhomepage_private.txt';
|
||||||
|
// If a template from version 3.0.4 exists, use it as source to create userhomepage_private.txt in templates_path
|
||||||
|
} elseif ((is_file(DOKU_INC.$this->getConf('templatepath'))) && ($this->getConf('templatepath') != null)) {
|
||||||
|
$source = $this->getConf('templatepath');
|
||||||
|
// Otherwise, we're on a fresh install
|
||||||
|
} else {
|
||||||
|
$source = 'lib/plugins/userhomepage/lang/'.$conf['lang'].'/userhomepage_private.default';
|
||||||
|
}
|
||||||
|
$this->copyFile($source, $dest, 'userhomepage_private.txt');
|
||||||
|
}
|
||||||
|
// CREATE PUBLIC PAGE TEMPLATES IF NEEDED (is required by options, doesn't exist yet and a known user is logged in)
|
||||||
|
if (($this->getConf('create_public_page')) && (!is_file($this->dataDir.'/'.$this->getConf('templates_path').'/userhomepage_public.txt')) && ($_SERVER['REMOTE_USER'] != null)) {
|
||||||
|
// If a template exists in path as builded before 2015/05/14 version, use it as source to create userhomepage_private.txt in new templates_path
|
||||||
|
if ((is_file(DOKU_CONF.'../'.$this->getConf('templates_path').'/userhomepage_public.txt')) && ($this->getConf('templatepath') != null)) {
|
||||||
|
$source = DOKU_CONF.'../'.$this->getConf('templates_path').'/userhomepage_public.txt';
|
||||||
|
} else {
|
||||||
|
$source = 'lib/plugins/userhomepage/lang/'.$conf['lang'].'/userhomepage_public.default';
|
||||||
|
}
|
||||||
|
$this->copyFile($source, $dest, 'userhomepage_public.txt');
|
||||||
|
}
|
||||||
|
// TARGETS
|
||||||
|
// ...:start.txt or ...:simon_delage.txt
|
||||||
|
$this->private_page = $this->helper->getPrivateID();
|
||||||
|
// user:simon.txt
|
||||||
|
$this->public_page = $this->helper->getPublicID();
|
||||||
|
// If a user is logged in, store timestamp (if it wasn't stored yet)
|
||||||
|
if (($_SERVER['REMOTE_USER']!=null) && (!isset($_SESSION['uhptimestamp']))) {
|
||||||
|
$_SESSION['uhptimestamp'] = time();
|
||||||
|
// If no user is logged in and a timestamp exists, set timestamp to null (ensures that redirection will work if user just logged out and comes back before closing browser)
|
||||||
|
} elseif (($_SERVER['REMOTE_USER']==null) && (isset($_SESSION['uhptimestamp']))) {
|
||||||
|
$_SESSION['uhptimestamp'] = null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return flase;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function redirect(&$event, $param) {
|
function redirect(&$event, $param) {
|
||||||
global $conf;
|
global $conf;
|
||||||
global $lang;
|
global $lang;
|
||||||
$created = array();
|
|
||||||
// If a user is logged in and not allready requesting his private namespace start page
|
if ($this->settingsCheck()) {
|
||||||
if (($_SERVER['REMOTE_USER']!=null)&&($_REQUEST['id']!=$this->private_page)) {
|
$created = array();
|
||||||
// if private page doesn't exists, create it (from template)
|
// If a user is logged in and not allready requesting his private namespace start page
|
||||||
if ($this->getConf('create_private_ns') && is_file($this->dataDir.'/'.$this->getConf('templates_path').'/userhomepage_private.txt') && !page_exists($this->private_page) && !checklock($this->private_page) && !checkwordblock()) {
|
if (($_SERVER['REMOTE_USER']!=null)&&($_REQUEST['id']!=$this->private_page)) {
|
||||||
// Target private start page template
|
// if private page doesn't exists, create it (from template)
|
||||||
$this->private_page_template = $this->dataDir.'/'.$this->getConf('templates_path').'/userhomepage_private.txt';
|
if ($this->getConf('create_private_ns') && is_file($this->dataDir.'/'.$this->getConf('templates_path').'/userhomepage_private.txt') && !page_exists($this->private_page) && !checklock($this->private_page) && !checkwordblock()) {
|
||||||
// Create private page
|
// Target private start page template
|
||||||
lock($this->private_page);
|
$this->private_page_template = $this->dataDir.'/'.$this->getConf('templates_path').'/userhomepage_private.txt';
|
||||||
saveWikiText($this->private_page,$this->applyTemplate('private'),'Automatically created');
|
// Create private page
|
||||||
unlock($this->private_page);
|
lock($this->private_page);
|
||||||
// Announce private namespace was created
|
saveWikiText($this->private_page,$this->applyTemplate('private'),'Automatically created');
|
||||||
msg($this->getLang('createdprivatens').' ('.$this->private_page.')', 1);
|
unlock($this->private_page);
|
||||||
// Note that we created private page
|
// Announce private namespace was created
|
||||||
$created['private'] = page_exists($this->private_page);
|
msg($this->getLang('createdprivatens').' ('.$this->private_page.')', 1);
|
||||||
}
|
// Note that we created private page
|
||||||
// If private ns is managed by plugin, check for any template from skeleton that doesn't exist yet
|
$created['private'] = page_exists($this->private_page);
|
||||||
if ($this->getConf('create_private_ns') && (is_dir($this->dataDir.'/'.$this->getConf('templates_path').'/uhp_private_skeleton'))) {
|
|
||||||
//$files = scandir($this->dataDir.'/'.$this->getConf('templates_path').'/uhp_private_skeleton/');
|
|
||||||
$path = realpath($this->dataDir.'/'.$this->getConf('templates_path').'/uhp_private_skeleton/');
|
|
||||||
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
|
|
||||||
if ($this->getConf('group_by_name')) {
|
|
||||||
// private:s:simon or private:s:simon_delage
|
|
||||||
$this->private_ns = cleanID($this->getConf('users_namespace').':'.substr($this->privateNamespace(), 0, 1).':'. $this->privateNamespace());
|
|
||||||
} else {
|
|
||||||
// private:simon or private:simon_delage
|
|
||||||
$this->private_ns = cleanID($this->getConf('users_namespace').':'. $this->privateNamespace());
|
|
||||||
}
|
}
|
||||||
foreach($objects as $objectName => $object){
|
// If private ns is managed by plugin, check for any template from skeleton that doesn't exist yet
|
||||||
$file = str_replace($path, '', $objectName);
|
if ($this->getConf('create_private_ns') && (is_dir($this->dataDir.'/'.$this->getConf('templates_path').'/uhp_private_skeleton'))) {
|
||||||
if ((is_file($this->dataDir.'/'.$this->getConf('templates_path').'/uhp_private_skeleton'.$file)) and (strpos($file, '.txt') !== false)) {
|
//$files = scandir($this->dataDir.'/'.$this->getConf('templates_path').'/uhp_private_skeleton/');
|
||||||
$custom_page_id = cleanID(str_replace('.txt', '', str_replace('/', ':', str_replace('\\', ':', $file))));
|
$path = realpath($this->dataDir.'/'.$this->getConf('templates_path').'/uhp_private_skeleton/');
|
||||||
$this->custom_target = $this->private_ns.':'.$custom_page_id;
|
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
|
||||||
if (!page_exists($this->custom_target)) {
|
if ($this->getConf('group_by_name')) {
|
||||||
$this->custom_page_template = $this->dataDir.'/'.$this->getConf('templates_path').'/uhp_private_skeleton'.$file;
|
// private:s:simon or private:s:simon_delage
|
||||||
lock($this->custom_target);
|
$this->private_ns = cleanID($this->getConf('users_namespace').':'.substr($this->privateNamespace(), 0, 1).':'. $this->privateNamespace());
|
||||||
saveWikiText($this->custom_target,$this->applyTemplate($this->custom_page_template),'Automatically created');
|
} else {
|
||||||
msg("Added '".$this->custom_target."' page from user namespace skeleton to your private namespace.",0);
|
// private:simon or private:simon_delage
|
||||||
unlock($this->custom_target);
|
$this->private_ns = cleanID($this->getConf('users_namespace').':'. $this->privateNamespace());
|
||||||
|
}
|
||||||
|
foreach($objects as $objectName => $object){
|
||||||
|
$file = str_replace($path, '', $objectName);
|
||||||
|
if ((is_file($this->dataDir.'/'.$this->getConf('templates_path').'/uhp_private_skeleton'.$file)) and (strpos($file, '.txt') !== false)) {
|
||||||
|
$custom_page_id = cleanID(str_replace('.txt', '', str_replace('/', ':', str_replace('\\', ':', $file))));
|
||||||
|
$this->custom_target = $this->private_ns.':'.$custom_page_id;
|
||||||
|
if (!page_exists($this->custom_target)) {
|
||||||
|
$this->custom_page_template = $this->dataDir.'/'.$this->getConf('templates_path').'/uhp_private_skeleton'.$file;
|
||||||
|
lock($this->custom_target);
|
||||||
|
saveWikiText($this->custom_target,$this->applyTemplate($this->custom_page_template),'Automatically created');
|
||||||
|
msg("Added '".$this->custom_target."' page from user namespace skeleton to your private namespace.",0);
|
||||||
|
unlock($this->custom_target);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
// Public page?
|
||||||
// Public page?
|
// If public page doesn't exists, create it (from template)
|
||||||
// If public page doesn't exists, create it (from template)
|
if ($this->getConf('create_public_page') && is_file($this->dataDir.'/'.$this->getConf('templates_path').'/userhomepage_public.txt') && !page_exists($this->public_page) && !checklock($this->public_page) && !checkwordblock()) {
|
||||||
if ($this->getConf('create_public_page') && is_file($this->dataDir.'/'.$this->getConf('templates_path').'/userhomepage_public.txt') && !page_exists($this->public_page) && !checklock($this->public_page) && !checkwordblock()) {
|
// Target public page template
|
||||||
// Target public page template
|
$this->public_page_template = $this->dataDir.'/'.$this->getConf('templates_path').'/userhomepage_public.txt';
|
||||||
$this->public_page_template = $this->dataDir.'/'.$this->getConf('templates_path').'/userhomepage_public.txt';
|
// Create public page
|
||||||
// Create public page
|
lock($this->public_page);
|
||||||
lock($this->public_page);
|
saveWikiText($this->public_page,$this->applyTemplate('public'),'Automatically created');
|
||||||
saveWikiText($this->public_page,$this->applyTemplate('public'),'Automatically created');
|
unlock($this->public_page);
|
||||||
unlock($this->public_page);
|
// Announce plubic page was created
|
||||||
// Announce plubic page was created
|
msg($this->getLang('createdpublicpage').' ('.$this->public_page.')', 1);
|
||||||
msg($this->getLang('createdpublicpage').' ('.$this->public_page.')', 1);
|
// Note that we created public page
|
||||||
// Note that we created public page
|
$created['public'] = page_exists($this->public_page);
|
||||||
$created['public'] = page_exists($this->public_page);
|
}
|
||||||
}
|
// List IDs that can match wiki start
|
||||||
// List IDs that can match wiki start
|
$wikistart = array($conf['start'], ':'.$conf['start']);
|
||||||
$wikistart = array($conf['start'], ':'.$conf['start']);
|
// If Translation plugin is active, wiki start page can also be '??:start'
|
||||||
// If Translation plugin is active, wiki start page can also be '??:start'
|
if (!plugin_isdisabled('translation')) {
|
||||||
if (!plugin_isdisabled('translation')) {
|
// For each language in Translation settings
|
||||||
// For each language in Translation settings
|
foreach (explode(' ',$conf['plugin']['translation']['translations']) as $language){
|
||||||
foreach (explode(' ',$conf['plugin']['translation']['translations']) as $language){
|
array_push($wikistart, $language.':'.$conf['start'], ':'.$language.':'.$conf['start']);
|
||||||
array_push($wikistart, $language.':'.$conf['start'], ':'.$language.':'.$conf['start']);
|
}
|
||||||
|
}
|
||||||
|
// If Public page was just created, redirect to it and edit (or show)
|
||||||
|
if (($created['public']) && (page_exists($this->public_page))) {
|
||||||
|
send_redirect(wl($this->public_page, array('do='.$this->getConf('action')), true));
|
||||||
|
// Else if private start page was just created and edit option is set, redirect to it and edit
|
||||||
|
} elseif (($created['private']) && (page_exists($this->private_page)) && ($this->getConf('edit_before_create'))) {
|
||||||
|
send_redirect(wl($this->private_page, array('do='.$this->getConf('action')), true));
|
||||||
|
// Else if redirection is enabled and user's private page exists AND [(user isn't requesting a specific page OR he's requesting wiki start page) AND logged in 2sec ago max]
|
||||||
|
} elseif (($this->getConf('redirection')) && (page_exists($this->private_page)) && (((!isset($_GET['id'])) or (in_array($_GET['id'], $wikistart))) && (time()-$_SESSION["uhptimestamp"] <= 2))) {
|
||||||
|
send_redirect(wl($this->private_page, '', true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If Public page was just created, redirect to it and edit (or show)
|
} else {
|
||||||
if (($created['public']) && (page_exists($this->public_page))) {
|
return flase;
|
||||||
// send_redirect(wl($this->public_page, 'do='.$this->getConf('action'), false, '&'));
|
|
||||||
send_redirect(wl($this->public_page, array('do='.$this->getConf('action')), true));
|
|
||||||
// Else if private start page was just created and edit option is set, redirect to it and edit
|
|
||||||
} elseif (($created['private']) && (page_exists($this->private_page)) && ($this->getConf('edit_before_create'))) {
|
|
||||||
// send_redirect(wl($this->private_page, 'do='.$this->getConf('action'), false, '&'));
|
|
||||||
send_redirect(wl($this->private_page, array('do='.$this->getConf('action')), true));
|
|
||||||
// Else if redirection is enabled and user's private page exists AND [(user isn't requesting a specific page OR he's requesting wiki start page) AND logged in 2sec ago max]
|
|
||||||
} elseif (($this->getConf('redirection')) && (page_exists($this->private_page)) && (((!isset($_GET['id'])) or (in_array($_GET['id'], $wikistart))) && (time()-$_SESSION["uhptimestamp"] <= 2))) {
|
|
||||||
// send_redirect(wl($this->private_page));
|
|
||||||
send_redirect(wl($this->private_page, '', true));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function acl(&$event, $param) {
|
function acl(&$event, $param) {
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
// if ((!$this->getConf('no_acl')) && ($conf['useacl'])) {
|
if ($this->settingsCheck()) {
|
||||||
if ((!$this->getConf('no_acl')) && ($conf['useacl']) && (isset($_SERVER['REMOTE_USER']))) {
|
if ((!$this->getConf('no_acl')) && ($conf['useacl']) && (isset($_SERVER['REMOTE_USER']))) {
|
||||||
$existingLines = file(DOKU_CONF.'acl.auth.php');
|
$existingLines = file(DOKU_CONF.'acl.auth.php');
|
||||||
$newLines = array();
|
$newLines = array();
|
||||||
// ACL
|
// ACL
|
||||||
$acl = new admin_plugin_acl();
|
$acl = new admin_plugin_acl();
|
||||||
// On private namespace
|
// On private namespace
|
||||||
if ($this->getConf('create_private_ns')) {
|
if ($this->getConf('create_private_ns')) {
|
||||||
// For known users
|
// For known users
|
||||||
// If use_name_string or group_by_name is enabled, we can't use ACL wildcards so let's create ACL for current user on his private ns
|
// If use_name_string or group_by_name is enabled, we can't use ACL wildcards so let's create ACL for current user on his private ns
|
||||||
if (($this->getConf('use_name_string')) or ($this->getConf('group_by_name'))) {
|
if (($this->getConf('use_name_string')) or ($this->getConf('group_by_name'))) {
|
||||||
$where = $this->private_ns.':*';
|
$where = $this->private_ns.':*';
|
||||||
$who = strtolower($_SERVER['REMOTE_USER']);
|
$who = strtolower($_SERVER['REMOTE_USER']);
|
||||||
// Otherwise we can set ACL for all known users at once
|
// Otherwise we can set ACL for all known users at once
|
||||||
} else {
|
} else {
|
||||||
$where = cleanID($this->getConf('users_namespace')).':%USER%:*';
|
$where = cleanID($this->getConf('users_namespace')).':%USER%:*';
|
||||||
|
$who = '%USER%';
|
||||||
|
}
|
||||||
|
$perm = AUTH_DELETE;
|
||||||
|
if (!in_array("$where\t$who\t$perm\n", $existingLines)) { $newLines[] = array('where' => $where, 'who' => $who, 'perm' => $perm); }
|
||||||
|
// For @ALL
|
||||||
|
if ($this->getConf('acl_all_private') != 'noacl') {
|
||||||
|
$where = cleanID($this->getConf('users_namespace')).':*';
|
||||||
|
$who = '@ALL';
|
||||||
|
$perm = (int)$this->getConf('acl_all_private');
|
||||||
|
if (!in_array("$where\t$who\t$perm\n", $existingLines)) { $newLines[] = array('where' => $where, 'who' => $who, 'perm' => $perm); }
|
||||||
|
}
|
||||||
|
// For @user
|
||||||
|
if (($this->getConf('acl_user_private') != 'noacl') && ($this->getConf('acl_user_private') !== $this->getConf('acl_all_private'))) {
|
||||||
|
$where = cleanID($this->getConf('users_namespace')).':*';
|
||||||
|
$who = '@user';
|
||||||
|
$perm = (int)$this->getConf('acl_user_private');
|
||||||
|
if (!in_array("$where\t$who\t$perm\n", $existingLines)) { $newLines[] = array('where' => $where, 'who' => $who, 'perm' => $perm); }
|
||||||
|
}
|
||||||
|
} // end of private namespaces acl
|
||||||
|
// On public user pages
|
||||||
|
if ($this->getConf('create_public_page')) {
|
||||||
|
// For known users
|
||||||
|
if (strpos($this->getConf('public_pages_ns'),':%NAME%:%START%') !== false) {
|
||||||
|
$where = cleanID(str_replace(':%NAME%:%START%', '', $this->getConf('public_pages_ns'))).':*';
|
||||||
|
} else {
|
||||||
|
$where = cleanID($this->getConf('public_pages_ns')).':%USER%';
|
||||||
|
}
|
||||||
$who = '%USER%';
|
$who = '%USER%';
|
||||||
}
|
$perm = AUTH_EDIT;
|
||||||
$perm = AUTH_DELETE;
|
|
||||||
if (!in_array("$where\t$who\t$perm\n", $existingLines)) { $newLines[] = array('where' => $where, 'who' => $who, 'perm' => $perm); }
|
|
||||||
// For @ALL
|
|
||||||
if ($this->getConf('acl_all_private') != 'noacl') {
|
|
||||||
$where = cleanID($this->getConf('users_namespace')).':*';
|
|
||||||
$who = '@ALL';
|
|
||||||
$perm = (int)$this->getConf('acl_all_private');
|
|
||||||
if (!in_array("$where\t$who\t$perm\n", $existingLines)) { $newLines[] = array('where' => $where, 'who' => $who, 'perm' => $perm); }
|
if (!in_array("$where\t$who\t$perm\n", $existingLines)) { $newLines[] = array('where' => $where, 'who' => $who, 'perm' => $perm); }
|
||||||
}
|
// For others
|
||||||
// For @user
|
if ($this->getConf('acl_all_public') != 'noacl') {
|
||||||
if (($this->getConf('acl_user_private') != 'noacl') && ($this->getConf('acl_user_private') !== $this->getConf('acl_all_private'))) {
|
// If both private and public namespaces are identical, we need to force rights for @ALL and/or @user on each public page
|
||||||
$where = cleanID($this->getConf('users_namespace')).':*';
|
if ($this->getConf('users_namespace') == $this->getConf('public_pages_ns')) {
|
||||||
$who = '@user';
|
$files = scandir($this->dataDir.'/pages/'.$this->getConf('public_pages_ns'));
|
||||||
$perm = (int)$this->getConf('acl_user_private');
|
foreach($files as $file) {
|
||||||
if (!in_array("$where\t$who\t$perm\n", $existingLines)) { $newLines[] = array('where' => $where, 'who' => $who, 'perm' => $perm); }
|
if (is_file($this->dataDir.'/pages/'.$this->getConf('public_pages_ns').'/'.$file)) {
|
||||||
}
|
// ACL on templates will be managed another way
|
||||||
} // end of private namespaces acl
|
if (strpos($file, 'userhomepage_p') !== 0) {
|
||||||
// On public user pages
|
// @ALL
|
||||||
if ($this->getConf('create_public_page')) {
|
if ($this->getConf('acl_all_public') != 'noacl') {
|
||||||
// For known users
|
$where = $this->getConf('public_pages_ns').':'.substr($file, 0, -4);
|
||||||
if (strpos($this->getConf('public_pages_ns'),':%NAME%:%START%') !== false) {
|
$who = '@ALL';
|
||||||
$where = cleanID(str_replace(':%NAME%:%START%', '', $this->getConf('public_pages_ns'))).':*';
|
$perm = $this->getConf('acl_all_public');
|
||||||
} else {
|
if (!in_array("$where\t$who\t$perm\n", $existingLines)) { $newLines[] = array('where' => $where, 'who' => $who, 'perm' => $perm); }
|
||||||
$where = cleanID($this->getConf('public_pages_ns')).':%USER%';
|
}
|
||||||
}
|
// @user
|
||||||
$who = '%USER%';
|
if ($this->getConf('acl_user_public') != 'noacl') {
|
||||||
$perm = AUTH_EDIT;
|
$where = $this->getConf('public_pages_ns').':'.substr($file, 0, -4);
|
||||||
if (!in_array("$where\t$who\t$perm\n", $existingLines)) { $newLines[] = array('where' => $where, 'who' => $who, 'perm' => $perm); }
|
$who = '@user';
|
||||||
// For others
|
$perm = $this->getConf('acl_user_public');
|
||||||
if ($this->getConf('acl_all_public') != 'noacl') {
|
if (!in_array("$where\t$who\t$perm\n", $existingLines)) { $newLines[] = array('where' => $where, 'who' => $who, 'perm' => $perm); }
|
||||||
// If both private and public namespaces are identical, we need to force rights for @ALL and/or @user on each public page
|
}
|
||||||
if ($this->getConf('users_namespace') == $this->getConf('public_pages_ns')) {
|
|
||||||
$files = scandir($this->dataDir.'/pages/'.$this->getConf('public_pages_ns'));
|
|
||||||
foreach($files as $file) {
|
|
||||||
if (is_file($this->dataDir.'/pages/'.$this->getConf('public_pages_ns').'/'.$file)) {
|
|
||||||
// ACL on templates will be managed another way
|
|
||||||
if (strpos($file, 'userhomepage_p') !== 0) {
|
|
||||||
// @ALL
|
|
||||||
if ($this->getConf('acl_all_public') != 'noacl') {
|
|
||||||
$where = $this->getConf('public_pages_ns').':'.substr($file, 0, -4);
|
|
||||||
$who = '@ALL';
|
|
||||||
$perm = $this->getConf('acl_all_public');
|
|
||||||
if (!in_array("$where\t$who\t$perm\n", $existingLines)) { $newLines[] = array('where' => $where, 'who' => $who, 'perm' => $perm); }
|
|
||||||
}
|
|
||||||
// @user
|
|
||||||
if ($this->getConf('acl_user_public') != 'noacl') {
|
|
||||||
$where = $this->getConf('public_pages_ns').':'.substr($file, 0, -4);
|
|
||||||
$who = '@user';
|
|
||||||
$perm = $this->getConf('acl_user_public');
|
|
||||||
if (!in_array("$where\t$who\t$perm\n", $existingLines)) { $newLines[] = array('where' => $where, 'who' => $who, 'perm' => $perm); }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
// Otherwise we just need to give the right permission to each group on public pages namespace
|
||||||
// Otherwise we just need to give the right permission to each group on public pages namespace
|
} else {
|
||||||
} else {
|
// @ALL
|
||||||
// @ALL
|
if ($this->getConf('acl_all_public') != 'noacl') {
|
||||||
if ($this->getConf('acl_all_public') != 'noacl') {
|
$where = cleanID(str_replace(':%NAME%:%START%', '', $this->getConf('public_pages_ns'))).':*';
|
||||||
$where = cleanID(str_replace(':%NAME%:%START%', '', $this->getConf('public_pages_ns'))).':*';
|
$who = '@ALL';
|
||||||
$who = '@ALL';
|
$perm = $this->getConf('acl_all_public');
|
||||||
$perm = $this->getConf('acl_all_public');
|
if (!in_array("$where\t$who\t$perm\n", $existingLines)) { $newLines[] = array('where' => $where, 'who' => $who, 'perm' => $perm); }
|
||||||
if (!in_array("$where\t$who\t$perm\n", $existingLines)) { $newLines[] = array('where' => $where, 'who' => $who, 'perm' => $perm); }
|
}
|
||||||
}
|
// @user
|
||||||
// @user
|
if ($this->getConf('acl_user_public') != 'noacl') {
|
||||||
if ($this->getConf('acl_user_public') != 'noacl') {
|
$where = cleanID(str_replace(':%NAME%:%START%', '', $this->getConf('public_pages_ns'))).':*';
|
||||||
$where = cleanID(str_replace(':%NAME%:%START%', '', $this->getConf('public_pages_ns'))).':*';
|
$who = '@user';
|
||||||
$who = '@user';
|
$perm = $this->getConf('acl_user_public');
|
||||||
$perm = $this->getConf('acl_user_public');
|
if (!in_array("$where\t$who\t$perm\n", $existingLines)) { $newLines[] = array('where' => $where, 'who' => $who, 'perm' => $perm); }
|
||||||
if (!in_array("$where\t$who\t$perm\n", $existingLines)) { $newLines[] = array('where' => $where, 'who' => $who, 'perm' => $perm); }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} // end for public pages acl
|
||||||
} // end for public pages acl
|
// On templates if they're in data/pages
|
||||||
// On templates if they're in data/pages
|
if (strpos($this->getConf('templates_path'),'/pages') !== false) {
|
||||||
if (strpos($this->getConf('templates_path'),'/pages') !== false) {
|
// For @ALL
|
||||||
// For @ALL
|
if (($this->getConf('acl_all_templates') != 'noacl') && (($this->getConf('create_private_ns')) or ($this->getConf('create_public_page')))) {
|
||||||
if (($this->getConf('acl_all_templates') != 'noacl') && (($this->getConf('create_private_ns')) or ($this->getConf('create_public_page')))) {
|
$where = end(explode('/',$this->getConf('templates_path'))).':userhomepage_private';
|
||||||
$where = end(explode('/',$this->getConf('templates_path'))).':userhomepage_private';
|
$who = '@ALL';
|
||||||
$who = '@ALL';
|
$perm = (int)$this->getConf('acl_all_templates');
|
||||||
$perm = (int)$this->getConf('acl_all_templates');
|
if (!in_array("$where\t$who\t$perm\n", $existingLines)) { $newLines[] = array('where' => $where, 'who' => $who, 'perm' => $perm); }
|
||||||
if (!in_array("$where\t$who\t$perm\n", $existingLines)) { $newLines[] = array('where' => $where, 'who' => $who, 'perm' => $perm); }
|
$where = end(explode('/',$this->getConf('templates_path'))).':userhomepage_public';
|
||||||
$where = end(explode('/',$this->getConf('templates_path'))).':userhomepage_public';
|
$who = '@ALL';
|
||||||
$who = '@ALL';
|
$perm = (int)$this->getConf('acl_all_templates');
|
||||||
$perm = (int)$this->getConf('acl_all_templates');
|
if (!in_array("$where\t$who\t$perm\n", $existingLines)) { $newLines[] = array('where' => $where, 'who' => $who, 'perm' => $perm); }
|
||||||
if (!in_array("$where\t$who\t$perm\n", $existingLines)) { $newLines[] = array('where' => $where, 'who' => $who, 'perm' => $perm); }
|
}
|
||||||
}
|
// For @user
|
||||||
// For @user
|
if (($this->getConf('acl_user_templates') != 'noacl') && ($this->getConf('acl_user_templates') !== $this->getConf('acl_all_templates')) && (($this->getConf('create_private_ns')) or ($this->getConf('create_public_page')))) {
|
||||||
if (($this->getConf('acl_user_templates') != 'noacl') && ($this->getConf('acl_user_templates') !== $this->getConf('acl_all_templates')) && (($this->getConf('create_private_ns')) or ($this->getConf('create_public_page')))) {
|
$where = end(explode('/',$this->getConf('templates_path'))).':userhomepage_private';
|
||||||
$where = end(explode('/',$this->getConf('templates_path'))).':userhomepage_private';
|
$who = '@user';
|
||||||
$who = '@user';
|
$perm = (int)$this->getConf('acl_user_templates');
|
||||||
$perm = (int)$this->getConf('acl_user_templates');
|
if (!in_array("$where\t$who\t$perm\n", $existingLines)) { $newLines[] = array('where' => $where, 'who' => $who, 'perm' => $perm); }
|
||||||
if (!in_array("$where\t$who\t$perm\n", $existingLines)) { $newLines[] = array('where' => $where, 'who' => $who, 'perm' => $perm); }
|
$where = end(explode('/',$this->getConf('templates_path'))).':userhomepage_public';
|
||||||
$where = end(explode('/',$this->getConf('templates_path'))).':userhomepage_public';
|
$who = '@user';
|
||||||
$who = '@user';
|
$perm = (int)$this->getConf('acl_user_templates');
|
||||||
$perm = (int)$this->getConf('acl_user_templates');
|
if (!in_array("$where\t$who\t$perm\n", $existingLines)) { $newLines[] = array('where' => $where, 'who' => $who, 'perm' => $perm); }
|
||||||
if (!in_array("$where\t$who\t$perm\n", $existingLines)) { $newLines[] = array('where' => $where, 'who' => $who, 'perm' => $perm); }
|
}
|
||||||
}
|
} // end of templates acl
|
||||||
} // end of templates acl
|
$i = count($newLines);
|
||||||
$i = count($newLines);
|
if ($i > 0) {
|
||||||
if ($i > 0) {
|
msg("Userhomepage: adding or updating ".$i." ACL rules.",1);
|
||||||
msg("Userhomepage: adding or updating ".$i." ACL rules.",1);
|
foreach($newLines as $line) {
|
||||||
foreach($newLines as $line) {
|
if (($line['where'] != null) && ($line['who'] != null)) {
|
||||||
if (($line['where'] != null) && ($line['who'] != null)) {
|
// delete potential ACL rule with same scope (aka 'where') and same user (aka 'who')
|
||||||
// delete potential ACL rule with same scope (aka 'where') and same user (aka 'who')
|
$acl->_acl_del($line['where'], $line['who']);
|
||||||
$acl->_acl_del($line['where'], $line['who']);
|
$acl->_acl_add($line['where'], $line['who'], $line['perm']);
|
||||||
$acl->_acl_add($line['where'], $line['who'], $line['perm']);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return flase;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,56 +362,81 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
|
||||||
global $INFO;
|
global $INFO;
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
if (($conf['showuseras'] == "username_link") and ($this->getConf('userlink_replace'))) {
|
if ($this->settingsCheck()) {
|
||||||
$classes = $this->getConf('userlink_classes');
|
if (($conf['showuseras'] == "username_link") and ($this->getConf('userlink_replace'))) {
|
||||||
$classes = str_replace(',', ' ', $classes);
|
$classes = $this->getConf('userlink_classes');
|
||||||
if ($this->getConf('userlink_fa')) {
|
$classes = str_replace(',', ' ', $classes);
|
||||||
$classes = str_replace('interwiki', '', $classes);
|
if ($this->getConf('userlink_fa')) {
|
||||||
}
|
$classes = str_replace('interwiki', '', $classes);
|
||||||
$this->username = $event->data['username'];
|
}
|
||||||
$this->name = $event->data['name'];
|
$this->username = $event->data['username'];
|
||||||
$this->link = $event->data['link'];
|
$this->name = $event->data['name'];
|
||||||
$this->userlink = $event->data['userlink'];
|
$this->link = $event->data['link'];
|
||||||
$this->textonly = $event->data['textonly'];
|
$this->userlink = $event->data['userlink'];
|
||||||
// Logged in as...
|
$this->textonly = $event->data['textonly'];
|
||||||
if (strpos($this->name, '<bdi>') !== false) {
|
// Logged in as...
|
||||||
$privateId = $this->helper->getPrivateID();
|
if (strpos($this->name, '<bdi>') !== false) {
|
||||||
$publicId = $this->helper->getPublicID();
|
$privateId = $this->helper->getPrivateID();
|
||||||
if ((page_exists($privateId)) && (page_exists($publicId))) {
|
$publicId = $this->helper->getPublicID();
|
||||||
if ($this->getConf('userlink_fa')) {
|
if ((page_exists($privateId)) && (page_exists($publicId))) {
|
||||||
$return = '<a href="'.wl($privateId).'" class="'.$classes.' uhp_fa" rel="nofollow" title="'.$this->getLang('privatenamespace').' ('.$privateId.')'.'"><bdi><i class="fa fa-user-secret"></i>'.$INFO['userinfo']['name'].'</bdi></a> (<a href="'.wl($publicId).'" class="'.$classes.' uhp_fa" rel="nofollow" title="'.$this->getLang('publicpage').' ('.$publicId.')'.'"><bdi><i class="fa fa-user"></i>'.$_SERVER['REMOTE_USER'].'</bdi></a>)';
|
if ($this->getConf('userlink_fa')) {
|
||||||
|
$return = '<a href="'.wl($privateId).'" class="'.$classes.' uhp_fa" rel="nofollow" title="'.$this->getLang('privatenamespace').' ('.$privateId.')'.'"><bdi><i class="fa fa-user-secret"></i>'.$INFO['userinfo']['name'].'</bdi></a> (<a href="'.wl($publicId).'" class="'.$classes.' uhp_fa" rel="nofollow" title="'.$this->getLang('publicpage').' ('.$publicId.')'.'"><bdi><i class="fa fa-user"></i>'.$_SERVER['REMOTE_USER'].'</bdi></a>)';
|
||||||
|
} else {
|
||||||
|
$return = '<a href="'.wl($privateId).'" class="'.$classes.' uhp_private" rel="nofollow" title="'.$this->getLang('privatenamespace').' ('.$privateId.')'.'"><bdi>'.$INFO['userinfo']['name'].'</bdi></a> (<a href="'.wl($publicId).'" class="'.$classes.' uhp_public" rel="nofollow" title="'.$this->getLang('publicpage').' ('.$publicId.')'.'"><bdi>'.$_SERVER['REMOTE_USER'].'</bdi></a>)';
|
||||||
|
}
|
||||||
|
} elseif (page_exists($publicId)) {
|
||||||
|
if ($this->getConf('userlink_fa')) {
|
||||||
|
$return = '</a> (<a href="'.wl($publicId).'" class="'.$classes.' uhp_fa" rel="nofollow" title="'.$this->getLang('publicpage').'('.$publicId.')'.'"><bdi><i class="fa fa-user"></i>'.$_SERVER['REMOTE_USER'].'</bdi></a>)';
|
||||||
|
} else {
|
||||||
|
$return = '<bdi>'.$INFO['userinfo']['name'].'</bdi> (<a href="'.wl($publicId).'" class="'.$classes.' uhp_public" rel="nofollow" title="'.$this->getLang('publicpage').' ('.$publicId.')'.'"><bdi>'.$_SERVER['REMOTE_USER'].'</bdi></a>)';
|
||||||
|
}
|
||||||
|
} elseif (page_exists($privateId)) {
|
||||||
|
if ($this->getConf('userlink_fa')) {
|
||||||
|
$return = '<a href="'.wl($privateId).'" class="'.$classes.' uhp_fa" rel="nofollow" title="'.$this->getLang('privatenamespace').' ('.$privateId.')'.'"><bdi><i class="fa fa-user-secret"></i>'.$INFO['userinfo']['name'].'</bdi></a>';
|
||||||
|
} else {
|
||||||
|
$return = '<a href="'.wl($privateId).'" class="'.$classes.' uhp_private" rel="nofollow" title="'.$this->getLang('privatenamespace').' ('.$privateId.')'.'"><bdi>'.$INFO['userinfo']['name'].'</bdi></a> (<bdi>'.$_SERVER['REMOTE_USER'].'</bdi>)';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$return = '<a href="'.wl($privateId).'" class="'.$classes.' uhp_private" rel="nofollow" title="'.$this->getLang('privatenamespace').' ('.$privateId.')'.'"><bdi>'.$INFO['userinfo']['name'].'</bdi></a> (<a href="'.wl($publicId).'" class="'.$classes.' uhp_public" rel="nofollow" title="'.$this->getLang('publicpage').' ('.$publicId.')'.'"><bdi>'.$_SERVER['REMOTE_USER'].'</bdi></a>)';
|
$return = null;
|
||||||
}
|
|
||||||
} elseif (page_exists($publicId)) {
|
|
||||||
if ($this->getConf('userlink_fa')) {
|
|
||||||
$return = '</a> (<a href="'.wl($publicId).'" class="'.$classes.' uhp_fa" rel="nofollow" title="'.$this->getLang('publicpage').'('.$publicId.')'.'"><bdi><i class="fa fa-user"></i>'.$_SERVER['REMOTE_USER'].'</bdi></a>)';
|
|
||||||
} else {
|
|
||||||
$return = '<bdi>'.$INFO['userinfo']['name'].'</bdi> (<a href="'.wl($publicId).'" class="'.$classes.' uhp_public" rel="nofollow" title="'.$this->getLang('publicpage').' ('.$publicId.')'.'"><bdi>'.$_SERVER['REMOTE_USER'].'</bdi></a>)';
|
|
||||||
}
|
|
||||||
} elseif (page_exists($privateId)) {
|
|
||||||
if ($this->getConf('userlink_fa')) {
|
|
||||||
$return = '<a href="'.wl($privateId).'" class="'.$classes.' uhp_fa" rel="nofollow" title="'.$this->getLang('privatenamespace').' ('.$privateId.')'.'"><bdi><i class="fa fa-user-secret"></i>'.$INFO['userinfo']['name'].'</bdi></a>';
|
|
||||||
} else {
|
|
||||||
$return = '<a href="'.wl($privateId).'" class="'.$classes.' uhp_private" rel="nofollow" title="'.$this->getLang('privatenamespace').' ('.$privateId.')'.'"><bdi>'.$INFO['userinfo']['name'].'</bdi></a> (<bdi>'.$_SERVER['REMOTE_USER'].'</bdi>)';
|
|
||||||
}
|
}
|
||||||
|
// ... or Last modified...
|
||||||
} else {
|
} else {
|
||||||
|
// No change for this right now
|
||||||
$return = null;
|
$return = null;
|
||||||
}
|
}
|
||||||
// ... or Last modified...
|
if ($return != null) {
|
||||||
|
$event->data = array(
|
||||||
|
'username' => $this->username,
|
||||||
|
'name' => $this->name,
|
||||||
|
'link' => $this->link,
|
||||||
|
'userlink' => $return,
|
||||||
|
'textonly' => $this->textonly
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return flase;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function settingsCheck($msg=false) {
|
||||||
|
global $conf;
|
||||||
|
|
||||||
|
// Error #1: Public page switched to namespace and is in conflict with Private namespace
|
||||||
|
if (strpos($this->getConf('public_pages_ns'),':%NAME%:%START%') !== false) {
|
||||||
|
$PublicNS = str_replace(':%NAME%:%START%', '', $this->getConf('public_pages_ns'));
|
||||||
|
$PublicNS = str_replace(':', '', $PublicNS);
|
||||||
|
$PrivateNS = str_replace(':', '', $this->getConf('users_namespace'));
|
||||||
|
if ($PublicNS == $PublicNS) {
|
||||||
|
if ($msg) {
|
||||||
|
msg("UserHomePage error #1 ! Make sure Private and Public namespaces are different. Plugin will have no effect untill this is corrected.", -1);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
} else {
|
} else {
|
||||||
// No change for this right now
|
return true;
|
||||||
$return = null;
|
|
||||||
}
|
|
||||||
if ($return != null) {
|
|
||||||
$event->data = array(
|
|
||||||
'username' => $this->username,
|
|
||||||
'name' => $this->name,
|
|
||||||
'link' => $this->link,
|
|
||||||
'userlink' => $return,
|
|
||||||
'textonly' => $this->textonly
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue