From 50aa60436f06aa751325bcc687ef1908c2c36253 Mon Sep 17 00:00:00 2001 From: Simon DELAGE Date: Sun, 4 Oct 2015 11:21:48 +0200 Subject: [PATCH] Added private namespace skeleton feature --- action.php | 33 +++++++++++++++++++++++++++++++-- plugin.info.txt | 2 +- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/action.php b/action.php index ad568e3..8fd254f 100644 --- a/action.php +++ b/action.php @@ -95,10 +95,37 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{ saveWikiText($this->private_page,$this->applyTemplate('private'),'Automatically created'); unlock($this->private_page); // Announce private namespace was created - msg($this->getLang('createdprivatens').' ('.$this->private_page.')', 0); + msg($this->getLang('createdprivatens').' ('.$this->private_page.')', 1); // Note that we created private page $created['private'] = page_exists($this->private_page); } + // If private ns is managed by plugin, check for any template from skeleton that doesn't exist yet + 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){ + $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? // 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()) { @@ -109,7 +136,7 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{ saveWikiText($this->public_page,$this->applyTemplate('public'),'Automatically created'); unlock($this->public_page); // Announce plubic page was created - msg($this->getLang('createdpublicpage').' ('.$this->public_page.')', 0); + msg($this->getLang('createdpublicpage').' ('.$this->public_page.')', 1); // Note that we created public page $created['public'] = page_exists($this->public_page); } @@ -310,6 +337,8 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{ $content = io_readFile($this->private_page_template, false); } elseif ($type == 'public') { $content = io_readFile($this->public_page_template, false); + } else { + $content = io_readFile($type, false); } $content = str_replace('@TARGETPRIVATEPAGE@', $this->private_page, $content); $content = str_replace('@TARGETPRIVATENS@', $this->private_ns, $content); diff --git a/plugin.info.txt b/plugin.info.txt index dbaf5e8..409f73c 100644 --- a/plugin.info.txt +++ b/plugin.info.txt @@ -1,7 +1,7 @@ base userhomepage author Simon Delage email simon.geekitude@gmail.com -date 2015-10-03 +date 2015-10-04 name User Homepage desc Automatically create user's private namespace and/or public page and redirects users to private namespace on login. url https://www.dokuwiki.org/plugin:userhomepage