getLang $this->setupLocale(); } /** * Handle Sqlite instantiation here and not in the constructor * to not make sqlite mandatory everywhere */ private function initiatePageRuleManager() { if (!isset($this->pageRuleManager)) { $this->pageRuleManager = new PageRules(); } } /** * Access for managers allowed */ function forAdminOnly(): bool { return false; } /** * return sort order for position in admin menu */ function getMenuSort(): int { return 140; } /** * return prompt for admin menu * @param string $language * @return string */ function getMenuText($language): string { return ucfirst(PluginUtility::$PLUGIN_NAME) . " - " . $this->lang['PageRules']; } public function getMenuIcon() { return DirectoryLayout::getComboImagesDirectory()->resolve('page-next.svg')->toAbsoluteId(); } /** * handle user request */ function handle() { $this->initiatePageRuleManager(); /** * If one of the form submit has the add key */ if (($_POST[self::SAVE_ACTION] ?? null) && checkSecurityToken()) { $id = $_POST[PageRules::ID_NAME] ?? null; $matcher = $_POST[PageRules::MATCHER_NAME] ?? null; $target = $_POST[PageRules::TARGET_NAME] ?? null; $priority = $_POST[PageRules::PRIORITY_NAME] ?? null; 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[self::DELETE_ACTION] ?? null) && 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('