-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathXMLGalleySettingsForm.inc.php
123 lines (98 loc) · 3.97 KB
/
XMLGalleySettingsForm.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
/**
* @file XMLGalleySettingsForm.inc.php
*
* Copyright (c) 2012 Martin Paul Eve
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* Portions copyright (c) 2003-2011 John Willinsky
*
* @class XMLGalleySettingsForm
* @ingroup plugins_generic_xmlGalley
*
* @brief Form for journal managers to modify Article XML Galley plugin settings
*/
// $Id$
import('lib.pkp.classes.form.Form');
class XMLGalleySettingsForm extends Form {
/** @var $journalId int */
var $journalId;
/** @var $plugin object */
var $plugin;
/**
* Constructor
* @param $plugin object
* @param $journalId int
*/
function XMLGalleySettingsForm(&$plugin, $journalId) {
$templateMgr =& TemplateManager::getManager();
parent::Form($plugin->getTemplatePath() . 'settingsForm.tpl');
$this->journalId = $journalId;
$this->plugin =& $plugin;
$this->addCheck(new FormValidatorPost($this));
}
/**
* Initialize form data.
*/
function initData() {
$journalId = $this->journalId;
$plugin =& $this->plugin;
$templateMgr =& TemplateManager::getManager();
// set form variables for available XSLT renderers
$xsltPHP5 = ( version_compare(PHP_VERSION,'5','>=') && extension_loaded('xsl') && extension_loaded('dom') );
$xsltPHP4 = ( version_compare(PHP_VERSION,'5','<') && extension_loaded('xslt') );
// populate form variables with saved plugin settings
$this->setData('xsltPHP5', $xsltPHP5);
$this->setData('xsltPHP4', $xsltPHP4);
if ( !Request::getUserVar('save') ) {
$this->setData('XSLTrenderer', $plugin->getSetting($journalId, 'XSLTrenderer'));
$this->setData('externalXSLT', $plugin->getSetting($journalId, 'externalXSLT'));
$this->setData('XSLstylesheet', $plugin->getSetting($journalId, 'XSLstylesheet'));
$this->setData('nlmPDF', $plugin->getSetting($journalId, 'nlmPDF'));
$this->setData('externalFOP', $plugin->getSetting($journalId, 'externalFOP'));
}
$this->setData('customXSL', $plugin->getSetting($journalId, 'customXSL'));
}
/**
* Assign form data to user-submitted data.
*/
function readInputData() {
$this->readUserVars(array('XSLTrenderer', 'XSLstylesheet', 'externalXSLT', 'customXSL', 'nlmPDF', 'externalFOP', 'saxon9Location'));
// ensure that external XSLT or XSL are not blank
if ($this->getData('XSLTrenderer') == "external") {
$this->addCheck(new FormValidator($this, 'externalXSLT', 'required', 'plugins.generic.meXmlGalley.settings.externalXSLTRequired'));
}
// if PDF rendering is enabled, then check that an external FO processor is set
if ($this->getData('nlmPDF') == "1") {
$this->addCheck(new FormValidator($this, 'externalFOP', 'required', 'plugins.generic.meXmlGalley.settings.xslFOPRequired'));
}
// if the custom stylesheet button is enabled, then check that an XSL is uploaded
if ($this->getData('XSLstylesheet') == "custom") {
$this->addCheck(new FormValidator($this, 'customXSL', 'required', 'plugins.generic.meXmlGalley.settings.customXSLRequired'));
}
}
/**
* Save settings.
*/
function execute() {
$plugin =& $this->plugin;
$journalId = $this->journalId;
// get existing settings to see if any are changing that will affect the cache
$flushCache = false;
foreach ($this->_data as $setting => $value) {
if ($plugin->getSetting($journalId, $setting) != $value) $flushCache = true;
}
// if there are changes, flush the XSLT cache
if ($flushCache == true) {
$cacheManager =& CacheManager::getManager();
$cacheManager->flush('xsltGalley', CACHE_TYPE_FILE);
}
$plugin->updateSetting($journalId, 'nlmPDF', $this->getData('nlmPDF'));
$plugin->updateSetting($journalId, 'externalFOP', $this->getData('externalFOP'));
$plugin->updateSetting($journalId, 'XSLTrenderer', $this->getData('XSLTrenderer'));
$plugin->updateSetting($journalId, 'XSLstylesheet', $this->getData('XSLstylesheet'));
$plugin->updateSetting($journalId, 'externalXSLT', $this->getData('externalXSLT'));
$plugin->updateSetting($journalId, 'customXSL', $this->getData('customXSL'));
}
}
?>