getLang $this->setupLocale(); $this->currentDate = date("c"); $this->infoPlugin = $this->getInfo(); } /** * Handle Sqlite instantiation here and not in the constructor * to not make sqlite mandatory everywhere */ private function initiatePageRuleManager() { if ($this->pageRuleManager == null) { $sqlite = Sqlite::getSqlite(); if ($sqlite == null) { // A message should have already been send by the getSqlite function return; } $this->pageRuleManager = new PageRules($sqlite); } } /** * Access for managers allowed */ function forAdminOnly() { return false; } /** * return sort order for position in admin menu */ function getMenuSort() { return 140; } /** * return prompt for admin menu * @param string $language * @return string */ function getMenuText($language) { return ucfirst(PluginUtility::$PLUGIN_NAME) . " - " . $this->lang['PageRules']; } public function getMenuIcon() { return DOKU_PLUGIN . $this->getPluginName() . '/images/page-next.svg'; } /** * handle user request */ function handle() { $this->initiatePageRuleManager(); /** * If one of the form submit has the add key */ if ($_POST['save'] && checkSecurityToken()) { $id = $_POST[PageRules::ID_NAME]; $matcher = $_POST[PageRules::MATCHER_NAME]; $target = $_POST[PageRules::TARGET_NAME]; $priority = $_POST[PageRules::PRIORITY_NAME]; if ($matcher == null) { msg('Matcher can not be null', LogUtility::LVL_MSG_ERROR); return; } if ($target == null) { msg('Target can not be null', LogUtility::LVL_MSG_ERROR); return; } if ($matcher == $target) { msg($this->lang['SameSourceAndTargetAndPage'] . ': ' . $matcher . '', LogUtility::LVL_MSG_ERROR); return; } if ($id == null) { if (!$this->pageRuleManager->patternExists($matcher)) { $this->pageRuleManager->addRule($matcher, $target, $priority); msg($this->lang['Saved'], LogUtility::LVL_MSG_INFO); } else { msg("The matcher pattern ($matcher) already exists. The page rule was not inserted.", LogUtility::LVL_MSG_ERROR); } } else { $this->pageRuleManager->updateRule($id, $matcher, $target, $priority); msg($this->lang['Saved'], LogUtility::LVL_MSG_INFO); } } if ($_POST['Delete'] && checkSecurityToken()) { $ruleId = $_POST[PageRules::ID_NAME]; $this->pageRuleManager->deleteRule($ruleId); msg($this->lang['Deleted'], LogUtility::LVL_MSG_INFO); } } /** * output appropriate html * TODO: Add variable parsing where the key is the key of the lang object ?? */ function html() { $this->initiatePageRuleManager(); ptln('
No Rules found
'); } else { ptln(''); ptln(' | ' . $this->getLangOrDefault('Priority', 'Priority') . ' | '); ptln('' . $this->getLangOrDefault('Matcher', 'Matcher') . ' | '); ptln('' . $this->getLangOrDefault('Target', 'Target') . ' | '); ptln('' . $this->getLangOrDefault('NDate', 'Date') . ' | '); ptln('
---|---|---|---|---|
'); ptln(' '); ptln(' '); ptln(' | '); ptln('' . $priority . ' | '); ptln('' . $matcher . ' | '); ptln('' . $target . ' | '); ptln('' . $timestamp . ' | '); ptln('