Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkp#28: provide backend header support [main] #30

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CustomHeaderPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
22 changes: 21 additions & 1 deletion CustomHeaderSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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')
);
}
Expand All @@ -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'));
}

/**
Expand All @@ -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;
}
}
6 changes: 6 additions & 0 deletions locale/en/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -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."
19 changes: 8 additions & 11 deletions templates/settingsForm.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
* Plugin settings
*
*}
<div id="customHeaderSettings">
<div id="description">{translate key="plugins.generic.customHeader.manager.settings.description"}</div>

<div class="separator"></div>

<br />

<script>
$(function() {ldelim}
Expand All @@ -23,21 +17,24 @@
</script>
<form class="pkp_form" id="customHeaderSettingsForm" method="post" action="{url router=$smarty.const.ROUTE_COMPONENT op="manage" category="generic" plugin=$pluginName verb="settings" save=true}">
{csrf}
<p id="description">{translate key="plugins.generic.customHeader.manager.settings.description"}</p>
{include file="controllers/notification/inPlaceNotification.tpl" notificationId="customHeaderFormNotification"}

{fbvFormArea id="customHeaderSettingsFormArea"}
{fbvFormSection for="headerContent" title="plugins.generic.customHeader.content"}
{fbvElement type="textarea" name="content" id="headerContent" value=$content height=$fbvStyles.height.TALL}
{/fbvFormSection}
{/fbvFormArea}

{fbvFormArea id="customHeaderSettingsFormArea"}
{fbvFormSection for="footerContent" title="plugins.generic.customHeader.footerContent"}
{fbvElement type="textarea" name="footerContent" id="footerContent" value=$footerContent height=$fbvStyles.height.TALL}
{/fbvFormSection}
{/fbvFormArea}

{fbvFormArea id="customHeaderBackendSettingsFormArea"}
{fbvFormSection for="backendContent" title="plugins.generic.customHeader.backendContent"}
{fbvElement type="textarea" name="backendContent" id="backendContent" value=$backendContent height=$fbvStyles.height.TALL}
{/fbvFormSection}
{/fbvFormArea}

{fbvFormButtons}
</form>

<p><span class="formRequired">{translate key="common.requiredField"}</span></p>
</div>