Reindent action.php
Also removed useless functions
This commit is contained in:
parent
11eb488530
commit
887df19155
265
action.php
265
action.php
|
@ -6,170 +6,125 @@
|
||||||
* @license: CC Attribution-Share Alike 3.0 Unported <http://creativecommons.org/licenses/by-sa/3.0/>
|
* @license: CC Attribution-Share Alike 3.0 Unported <http://creativecommons.org/licenses/by-sa/3.0/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// must be run within Dokuwiki
|
||||||
if (!defined('DOKU_INC')) die();
|
if (!defined('DOKU_INC')) die();
|
||||||
if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
|
if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
|
||||||
|
|
||||||
require_once (DOKU_PLUGIN . 'action.php');
|
require_once (DOKU_PLUGIN . 'action.php');
|
||||||
require_once (DOKU_PLUGIN . '/acl/admin.php');
|
require_once (DOKU_PLUGIN . '/acl/admin.php');
|
||||||
|
|
||||||
class action_plugin_userhomepage extends DokuWiki_Action_Plugin
|
class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
|
||||||
{
|
function register(&$controller) {
|
||||||
private $userHomePagePath = '';
|
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'redirect',array());
|
||||||
private $userHomePageTemplate = '';
|
$controller->register_hook('HTML_PAGE_FROMTEMPLATE', 'BEFORE', $this, 'page_template',array());
|
||||||
private $home_wiki_page = '';
|
}
|
||||||
private $home_wiki_ns = '';
|
function redirect(&$event, $param) {
|
||||||
private $doku_page_path = '';
|
global $conf;
|
||||||
private $home_page_template = '';
|
global $INFO;
|
||||||
|
if (($_SERVER['REMOTE_USER']!=null)&&($_REQUEST['do']=='login')) {
|
||||||
function init()
|
|
||||||
{
|
|
||||||
global $conf;
|
|
||||||
require_once (DOKU_INC.'inc/search.php');
|
|
||||||
if($_SERVER['REMOTE_USER']!=null)
|
|
||||||
{
|
|
||||||
//$this->doku_page_path = DOKU_INC . 'data/pages';
|
|
||||||
$this->doku_page_path = $conf['datadir'];
|
|
||||||
$this->home_page_template = DOKU_INC . $this->getConf('templatepath');
|
|
||||||
if ($this->getConf('group_by_name'))
|
|
||||||
{
|
|
||||||
// people:g:gme']li8600
|
|
||||||
$this->home_wiki_ns = cleanID($this->getConf('users_namespace').':'.strtolower(substr($this->homeNamespace(), 0, 1)).':'. $this->homeNamespace());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// people:gli8600
|
|
||||||
$this->home_wiki_ns = cleanID($this->getConf('users_namespace').':'. $this->homeNamespace());
|
|
||||||
}
|
|
||||||
// people:gli8600:start.txt
|
|
||||||
$this->home_wiki_page= cleanID($this->home_wiki_ns . ':' . $this->homePage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//draws a home link, used by calls from main.php in template folder
|
|
||||||
function homeButton()
|
|
||||||
{
|
|
||||||
$this->init();
|
|
||||||
if ($_SERVER['REMOTE_USER']!=null)
|
|
||||||
{
|
|
||||||
echo '<form class="button btn_show" method="post" action="doku.php?id='.$this->home_wiki_page.'"><input class="button" type="submit" value="Home"/></form>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//draws a home button, used by calls from main.php in template folder
|
|
||||||
function homeLink()
|
|
||||||
{
|
|
||||||
$this->init();
|
|
||||||
if ($_SERVER['REMOTE_USER']!=null)
|
|
||||||
{
|
|
||||||
echo '<a href="doku.php?id='.$this->home_wiki_page.'">Home</a>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function homeNamespace() {
|
|
||||||
if ( $this->getConf('use_name_string')) {
|
|
||||||
global $INFO;
|
|
||||||
$raw_string = $INFO['userinfo']['name'];
|
|
||||||
//james_lin
|
|
||||||
return $raw_string;
|
|
||||||
} else {
|
|
||||||
//gli8600
|
|
||||||
return strtolower($_SERVER['REMOTE_USER']);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function homePage() {
|
|
||||||
if ( $this->getConf('use_start_page')) {
|
|
||||||
global $conf;
|
|
||||||
return $conf['start'];
|
|
||||||
} else {
|
|
||||||
return $this->homeNamespace();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function _template() {
|
|
||||||
global $INFO;
|
|
||||||
$content = io_readFile($this->home_page_template, false);
|
|
||||||
$name = $INFO['userinfo']['name'];
|
|
||||||
$user = strtolower($_SERVER['REMOTE_USER']);
|
|
||||||
$content = str_replace('@NAME@',$name,$content);
|
|
||||||
$content = str_replace('@USER@',$user,$content);
|
|
||||||
return $content;
|
|
||||||
}
|
|
||||||
|
|
||||||
function page_template(&$event, $param)
|
|
||||||
{
|
|
||||||
$this->init();
|
$this->init();
|
||||||
if($this->home_wiki_page && $this->home_wiki_page == $event->data[0]) {
|
$id = $this->home_wiki_page;
|
||||||
if(!$event->result) // FIXME: another template applied?
|
// if page doesn't exists, create it
|
||||||
$event->result = $this->_template();
|
if (!page_exists($id) && !checklock($id) && !checkwordblock()) {
|
||||||
$event->preventDefault();
|
// set acl's if requested
|
||||||
}
|
if ( $this->getConf('set_permissions') == 1 ) {
|
||||||
}
|
$acl = new admin_plugin_acl();
|
||||||
|
// Old user-page ACL (version 3.0.4):
|
||||||
function redirect(&$event, $param)
|
// $ns = cleanID($this->home_wiki_ns.':'.$this->homePage());
|
||||||
{
|
// New user-namespace ACL:
|
||||||
global $conf;
|
$ns = cleanID($this->home_wiki_ns).':*';
|
||||||
global $INFO;
|
$acl->_acl_add($this->getConf('users_namespace').':*', '@ALL', (int)$this->getConf('set_permissions_others'));
|
||||||
|
$acl->_acl_add($this->getConf('users_namespace').':*', '@user', (int)$this->getConf('set_permissions_others'));
|
||||||
if (($_SERVER['REMOTE_USER']!=null)&&($_REQUEST['do']=='login'))
|
$acl->_acl_add($ns, strtolower($_SERVER['REMOTE_USER']), AUTH_DELETE);
|
||||||
{
|
|
||||||
$this->init();
|
|
||||||
$id = $this->home_wiki_page;
|
|
||||||
|
|
||||||
//check if page not exists, create it
|
|
||||||
if (!page_exists($id) && !checklock($id) && !checkwordblock())
|
|
||||||
{
|
|
||||||
// set acl's if requested
|
|
||||||
if ( $this->getConf('set_permissions') == 1 )
|
|
||||||
{
|
|
||||||
$acl = new admin_plugin_acl();
|
|
||||||
// Old user-page ACL:
|
|
||||||
// $ns = cleanID($this->home_wiki_ns.':'.$this->homePage());
|
|
||||||
// New user-namespace ACL:
|
|
||||||
$ns = cleanID($this->home_wiki_ns).':*';
|
|
||||||
$acl->_acl_add($this->getConf('users_namespace').':*', '@ALL', (int)$this->getConf('set_permissions_others'));
|
|
||||||
$acl->_acl_add($this->getConf('users_namespace').':*', '@user', (int)$this->getConf('set_permissions_others'));
|
|
||||||
$acl->_acl_add($ns, strtolower($_SERVER['REMOTE_USER']), AUTH_DELETE); }
|
|
||||||
// If the 2 lines concerning set_permissions_others above allready existed in conf/acl.auth.php file they've been duplicated so let's read the file
|
|
||||||
$lines = file(DOKU_INC.'conf/acl.auth.php');
|
|
||||||
// Only keep unique lines (OK, we loose an empty comment line...)
|
|
||||||
$lines = array_unique($lines);
|
|
||||||
// Write things back to conf/acl.auth.php
|
|
||||||
file_put_contents(DOKU_INC.'conf/acl.auth.php', implode($lines));;
|
|
||||||
if (!$this->getConf('edit_before_create'))
|
|
||||||
{
|
|
||||||
//writes the user info to page
|
|
||||||
lock($id);
|
|
||||||
saveWikiText($id,$this->_template(),$lang['created']);
|
|
||||||
unlock($id);
|
|
||||||
}
|
|
||||||
// redirect to edit home page
|
|
||||||
send_redirect(wl($id, array("do" => ($this->getConf('edit_before_create'))?"edit":"show"), false, "&"));
|
|
||||||
}
|
}
|
||||||
// if the user was at a specific page, then don't redirect to personal page.
|
// If the 2 lines concerning set_permissions_others above allready existed in conf/acl.auth.php file they've been duplicated so let's read the file
|
||||||
if (($_REQUEST['id']==$conf['start'])||(!isset($_REQUEST['id'])))
|
$lines = file(DOKU_INC.'conf/acl.auth.php');
|
||||||
{
|
// Only keep unique lines (OK, we loose an empty comment line...)
|
||||||
send_redirect(wl($id));
|
$lines = array_unique($lines);
|
||||||
}
|
// Write things back to conf/acl.auth.php
|
||||||
|
file_put_contents(DOKU_INC.'conf/acl.auth.php', implode($lines));
|
||||||
|
if (!$this->getConf('edit_before_create')) {
|
||||||
|
//writes the user info to page
|
||||||
|
lock($id);
|
||||||
|
saveWikiText($id,$this->_template(),$lang['created']);
|
||||||
|
unlock($id);
|
||||||
|
}
|
||||||
|
// redirect to edit home page
|
||||||
|
send_redirect(wl($id, array("do" => ($this->getConf('edit_before_create'))?"edit":"show"), false, "&"));
|
||||||
|
}
|
||||||
|
// if the user was at a specific page, then don't redirect to personal page.
|
||||||
|
if (($_REQUEST['id']==$conf['start'])||(!isset($_REQUEST['id']))) {
|
||||||
|
send_redirect(wl($id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
function getInfo()
|
function init() {
|
||||||
{
|
global $conf;
|
||||||
return array
|
require_once (DOKU_INC.'inc/search.php');
|
||||||
(
|
if($_SERVER['REMOTE_USER']!=null) {
|
||||||
'name' => 'User Home Page',
|
$this->doku_page_path = $conf['datadir'];
|
||||||
'email' => 'simon.geekitude@gmail.com',
|
$this->home_page_template = DOKU_INC . $this->getConf('templatepath');
|
||||||
'date' => '2009-05-28',
|
if ($this->getConf('group_by_name')) {
|
||||||
'author' => 'Simon Delage (previously James GuanFeng Lin, Mikhail I. Izmestev & Daniel Stonier)',
|
// private:s:simon
|
||||||
'desc' => 'auto redirects users to <create> their homepage',
|
$this->home_wiki_ns = cleanID($this->getConf('users_namespace').':'.strtolower(substr($this->homeNamespace(), 0, 1)).':'. $this->homeNamespace());
|
||||||
'url' => 'https://www.dokuwiki.org/plugin:userhomepage'
|
} else {
|
||||||
);
|
// private:simon
|
||||||
|
$this->home_wiki_ns = cleanID($this->getConf('users_namespace').':'. $this->homeNamespace());
|
||||||
|
}
|
||||||
|
// private:simon:start.txt
|
||||||
|
$this->home_wiki_page= cleanID($this->home_wiki_ns . ':' . $this->homePage());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
function register(&$controller)
|
function homeNamespace() {
|
||||||
{
|
if ( $this->getConf('use_name_string')) {
|
||||||
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'redirect',array());
|
global $INFO;
|
||||||
$controller->register_hook('HTML_PAGE_FROMTEMPLATE', 'BEFORE', $this, 'page_template',array());
|
$raw_string = $INFO['userinfo']['name'];
|
||||||
|
// simon_delage
|
||||||
|
return $raw_string;
|
||||||
|
} else {
|
||||||
|
// simon
|
||||||
|
return strtolower($_SERVER['REMOTE_USER']);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
function homePage() {
|
||||||
|
if ( $this->getConf('use_start_page')) {
|
||||||
|
global $conf;
|
||||||
|
return $conf['start'];
|
||||||
|
} else {
|
||||||
|
return $this->homeNamespace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function _template() {
|
||||||
|
global $INFO;
|
||||||
|
$content = io_readFile($this->home_page_template, false);
|
||||||
|
$name = $INFO['userinfo']['name'];
|
||||||
|
$user = strtolower($_SERVER['REMOTE_USER']);
|
||||||
|
$content = str_replace('@NAME@',$name,$content);
|
||||||
|
$content = str_replace('@USER@',$user,$content);
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
// function page_template(&$event, $param) {
|
||||||
|
// $this->init();
|
||||||
|
// if($this->home_wiki_page && $this->home_wiki_page == $event->data[0]) {
|
||||||
|
// if(!$event->result) {
|
||||||
|
// // FIXME: another template applied?
|
||||||
|
// $event->result = $this->_template();
|
||||||
|
// $event->preventDefault();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//draws a home link, used by calls from main.php in template folder
|
||||||
|
function homeButton() {
|
||||||
|
$this->init();
|
||||||
|
if ($_SERVER['REMOTE_USER']!=null) {
|
||||||
|
echo '<form class="button btn_show" method="post" action="doku.php?id='.$this->home_wiki_page.'"><input class="button" type="submit" value="Home"/></form>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//draws a home button, used by calls from main.php in template folder
|
||||||
|
function homeLink() {
|
||||||
|
$this->init();
|
||||||
|
if ($_SERVER['REMOTE_USER']!=null) {
|
||||||
|
echo '<a href="doku.php?id='.$this->home_wiki_page.'">Home</a>';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue