diff --git a/CustomHeaderPlugin.php b/CustomHeaderPlugin.php index 45d493f..91a859c 100644 --- a/CustomHeaderPlugin.php +++ b/CustomHeaderPlugin.php @@ -115,6 +115,7 @@ function displayTemplateHook($hookName, $params) { $request = Application::get()->getRequest(); $context = $request->getContext(); $templateMgr->addHeader('custom', $this->getSetting($context?$context->getId():CONTEXT_ID_NONE, 'content')); + $templateMgr->addHeader('custombackend', $this->getSetting($context?$context->getId():CONTEXT_ID_NONE, 'backendContent'), ['contexts' => ['backend']]); } return false; } diff --git a/CustomHeaderSettingsForm.php b/CustomHeaderSettingsForm.php index 198bc37..1a0bba1 100644 --- a/CustomHeaderSettingsForm.php +++ b/CustomHeaderSettingsForm.php @@ -36,6 +36,7 @@ function __construct($plugin, $contextId) { parent::__construct($plugin->getTemplateResource('settingsForm.tpl')); + $this->addCheck(new \PKP\form\validation\FormValidatorCustom($this, 'backendContent', FORM_VALIDATOR_OPTIONAL_VALUE, 'plugins.generic.customHeader.backendContent.error', function ($backendContent) { return $this->validateWellFormed($backendContent); })); $this->addCheck(new \PKP\form\validation\FormValidatorPost($this)); $this->addCheck(new \PKP\form\validation\FormValidatorCSRF($this)); } @@ -46,6 +47,7 @@ function __construct($plugin, $contextId) { function initData() { $this->_data = array( 'content' => $this->_plugin->getSetting($this->_contextId, 'content'), + 'backendContent' => $this->_plugin->getSetting($this->_contextId, 'backendContent'), 'footerContent' => $this->_plugin->getSetting($this->_contextId, 'footerContent') ); } @@ -54,7 +56,7 @@ function initData() { * Assign form data to user-submitted data. */ function readInputData() { - $this->readUserVars(array('content', 'footerContent')); + $this->readUserVars(array('content', 'backendContent', 'footerContent')); } /** @@ -75,8 +77,26 @@ function execute(...$functionArgs) { $request = Application::get()->getRequest(); $this->_plugin->updateSetting($this->_contextId, 'content', $this->getData('content'), 'string'); + $this->_plugin->updateSetting($this->_contextId, 'backendContent', $this->getData('backendContent'), 'string'); $this->_plugin->updateSetting($this->_contextId, 'footerContent', $this->getData('footerContent'), 'string'); $notificationManager = new NotificationManager(); $notificationManager->createTrivialNotification($request->getUser()->getId(), NOTIFICATION_TYPE_SUCCESS); } + + /** + * Validate that the input is well-formed XML + * We want to avoid breaking the whole HTML page with an unclosed HTML attribute quote or tag + * @param $input string + * @return boolean + */ + function validateWellFormed($input) { + $libxml_errors_setting = libxml_use_internal_errors(); + libxml_use_internal_errors(true); + libxml_clear_errors(); + $dom = new DOMDocument(); + $dom->loadHTML($input); + $isWellFormed = count(libxml_get_errors())==0; + libxml_use_internal_errors($libxml_errors_setting); + return $isWellFormed; + } } diff --git a/locale/en/locale.po b/locale/en/locale.po index d3f3cbd..c762243 100644 --- a/locale/en/locale.po +++ b/locale/en/locale.po @@ -25,3 +25,9 @@ msgstr "Header Content" msgid "plugins.generic.customHeader.footerContent" msgstr "Footer Content" + +msgid "plugins.generic.customHeader.backendContent" +msgstr "Editorial Backend Header Content" + +msgid "plugins.generic.customHeader.backendContent.error" +msgstr "Editorial Backend Header Content must be valid XHTML." diff --git a/templates/settingsForm.tpl b/templates/settingsForm.tpl index f74f477..572bb62 100644 --- a/templates/settingsForm.tpl +++ b/templates/settingsForm.tpl @@ -8,12 +8,6 @@ * Plugin settings * *} -
{translate key="common.requiredField"}
-