00001 <?php
00002
00015
00016
00017
00018 import('classes.plugins.GenericPlugin');
00019
00020 class XMLGalleyPlugin extends GenericPlugin {
00021
00022 function register($category, $path) {
00023 if (parent::register($category, $path)) {
00024 if ($this->getEnabled()) {
00025 $this->import('ArticleXMLGalleyDAO');
00026 $xmlGalleyDao = &new ArticleXMLGalleyDAO();
00027 DAORegistry::registerDAO('ArticleXMLGalleyDAO', $xmlGalleyDao);
00028
00029
00030 HookRegistry::register('ArticleGalleyDAO::getArticleGalleys', array(&$xmlGalleyDao, 'appendXMLGalleys') );
00031 HookRegistry::register('ArticleGalleyDAO::insertNewGalley', array(&$xmlGalleyDao, 'insertXMLGalleys') );
00032 HookRegistry::register('ArticleGalleyDAO::deleteGalleyById', array(&$xmlGalleyDao, 'deleteXMLGalleys') );
00033 HookRegistry::register('ArticleGalleyDAO::incrementGalleyViews', array(&$xmlGalleyDao, 'incrementXMLViews') );
00034 HookRegistry::register('ArticleGalleyDAO::_returnGalleyFromRow', array(&$this, 'returnXMLGalley') );
00035 HookRegistry::register('ArticleGalleyDAO::getNewGalley', array(&$this, 'getXMLGalley') );
00036
00037
00038 HookRegistry::register( 'ArticleHandler::viewFile', array(&$this, 'viewXMLGalleyFile') );
00039 HookRegistry::register( 'ArticleHandler::downloadFile', array(&$this, 'viewXMLGalleyFile') );
00040 }
00041
00042 $this->addLocaleData();
00043 return true;
00044 }
00045 return false;
00046 }
00047
00048 function getName() {
00049 return 'XMLGalleyPlugin';
00050 }
00051
00052 function getDisplayName() {
00053 return Locale::translate('plugins.generic.xmlGalley.displayName');
00054 }
00055
00056 function getDescription() {
00057 return Locale::translate('plugins.generic.xmlGalley.description');
00058 }
00059
00063 function getInstallSchemaFile() {
00064 return $this->getPluginPath() . '/' . 'schema.xml';
00065 }
00066
00071 function getXMLGalley($hookName, &$args) {
00072 if (!$this->getEnabled()) return false;
00073 $galleyId =& $args[0];
00074 $articleId =& $args[1];
00075 $returner =& $args[2];
00076
00077 $xmlGalleyDao = &new ArticleXMLGalleyDAO();
00078 $xmlGalley = $xmlGalleyDao->_getXMLGalleyFromId($galleyId, $articleId);
00079 if ($xmlGalley) {
00080 $xmlGalley->setGalleyId($galleyId);
00081 $returner = $xmlGalley;
00082 return true;
00083 }
00084 return false;
00085 }
00086
00090 function viewXMLGalleyFile($hookName, $args) {
00091 if (!$this->getEnabled()) return false;
00092 $article =& $args[0];
00093 $galley =& $args[1];
00094 $fileId =& $args[2];
00095
00096 $journal = &Request::getJournal();
00097
00098 if (get_class($galley) == 'ArticleXMLGalley' && $galley->isPdfGalley() &&
00099 $this->getSetting($journal->getJournalId(), 'nlmPDF') == 1) {
00100 return $galley->viewFileContents();
00101 } else return false;
00102 }
00103
00108 function returnXMLGalley($hookName, $args) {
00109 if (!$this->getEnabled()) return false;
00110 $galley =& $args[0];
00111 $row =& $args[1];
00112
00113
00114
00115
00116
00117 if ($galley->getFileType() == "text/xml") {
00118 $galley = $this->_returnXMLGalleyFromArticleGalley($galley);
00119 return true;
00120 }
00121
00122 return false;
00123 }
00124
00130 function _returnXMLGalleyFromArticleGalley(&$galley) {
00131 $this->import('ArticleXMLGalley');
00132 $articleXMLGalley = new ArticleXMLGalley();
00133
00134
00135 $articleXMLGalley->setGalleyId($galley->getGalleyId());
00136 $articleXMLGalley->setArticleId($galley->getArticleId());
00137 $articleXMLGalley->setFileId($galley->getFileId());
00138 $articleXMLGalley->setLabel($galley->getLabel());
00139 $articleXMLGalley->setSequence($galley->getSequence());
00140 $articleXMLGalley->setViews($galley->getViews());
00141 $articleXMLGalley->setFileName($galley->getFileName());
00142 $articleXMLGalley->setOriginalFileName($galley->getOriginalFileName());
00143 $articleXMLGalley->setFileType($galley->getFileType());
00144 $articleXMLGalley->setFileSize($galley->getFileSize());
00145 $articleXMLGalley->setStatus($galley->getStatus());
00146 $articleXMLGalley->setDateModified($galley->getDateModified());
00147 $articleXMLGalley->setDateUploaded($galley->getDateUploaded());
00148 $articleXMLGalley->setLocale($galley->getLocale());
00149
00150 $articleXMLGalley->setType('public');
00151
00152
00153 if ($galley->isHTMLGalley()) {
00154 $articleXMLGalley->setStyleFileId($galley->getStyleFileId());
00155 $articleXMLGalley->setStyleFile($galley->getStyleFile());
00156 $articleXMLGalley->setImageFiles($galley->getImageFiles());
00157 }
00158
00159 return $articleXMLGalley;
00160 }
00161
00165 function getEnabled() {
00166 $journal = &Request::getJournal();
00167 if (!$journal) return false;
00168 return $this->getSetting($journal->getJournalId(), 'enabled');
00169 }
00170
00174 function setEnabled($enabled) {
00175 $journal = &Request::getJournal();
00176 if ($journal) {
00177 $this->updateSetting($journal->getJournalId(), 'enabled', $enabled ? true : false);
00178
00179
00180 if ($this->getSetting($journal->getJournalId(), 'XSLTrenderer') == "") {
00181
00182
00183 if ( version_compare(PHP_VERSION,'5','>=') && extension_loaded('xsl') && extension_loaded('dom') ) {
00184
00185 $this->updateSetting($journal->getJournalId(), 'XSLTrenderer', 'PHP5');
00186
00187 } elseif ( version_compare(PHP_VERSION,'5','<') && extension_loaded('xslt') ) {
00188
00189 $this->updateSetting($journal->getJournalId(), 'XSLTrenderer', 'PHP4');
00190
00191 } else {
00192 $this->updateSetting($journal->getJournalId(), 'XSLTrenderer', 'external');
00193 }
00194 }
00195
00196
00197 if ($this->getSetting($journal->getJournalId(), 'XSLstylesheet') == "") {
00198 $this->updateSetting($journal->getJournalId(), 'XSLstylesheet', 'NLM');
00199 }
00200
00201 return true;
00202 }
00203 return false;
00204 }
00205
00209 function manage($verb, $args) {
00210 $journal =& Request::getJournal();
00211
00212 $templateMgr = &TemplateManager::getManager();
00213 $templateMgr->register_function('plugin_url', array(&$this, 'smartyPluginUrl'));
00214
00215 $this->import('XMLGalleySettingsForm');
00216 $form =& new XMLGalleySettingsForm($this, $journal->getJournalId());
00217
00218 switch ($verb) {
00219 case 'test':
00220
00221 $xsltRenderer = $this->getSetting($journal->getJournalId(), 'XSLTrenderer');
00222
00223 if ($xsltRenderer == "external") {
00224
00225 $xsltCommand = $this->getSetting($journal->getJournalId(), 'externalXSLT');
00226
00227
00228 $xmlFile = dirname($_SERVER['SCRIPT_FILENAME']) . DIRECTORY_SEPARATOR . $this->getPluginPath() . '/transform/test.xml';
00229 $xslFile = $this->getPluginPath() . '/transform/test.xsl';
00230
00231
00232 $this->import('ArticleXMLGalley');
00233 $xmlGalley = new ArticleXMLGalley();
00234
00235
00236 $result = $xmlGalley->transformXSLT($xmlFile, $xslFile, $xsltCommand);
00237
00238
00239 if (trim(preg_replace("/\s+/", " ", $result)) != "Open Journal Systems Success" ) {
00240 $form->addError('content', Locale::translate('plugins.generic.xmlGalley.settings.externalXSLTFailure'));
00241 } else $templateMgr->assign('testSuccess', true);
00242
00243 }
00244
00245 case 'settings':
00246
00247
00248 if (Request::getUserVar('save')) {
00249 $form->readInputData();
00250 $form->initData();
00251 if ($form->validate()) {
00252 $form->execute();
00253 }
00254 $form->display();
00255
00256
00257 } elseif (Request::getUserVar('uploadCustomXSL')) {
00258 $form->readInputData();
00259
00260 import('file.JournalFileManager');
00261
00262
00263 $fileManager = &new JournalFileManager($journal);
00264 if ($fileManager->uploadedFileExists('customXSL')) {
00265
00266
00267 $type = $fileManager->getUploadedFileType('customXSL');
00268 $fileName = $fileManager->getUploadedFileName('customXSL');
00269 $extension = strtolower($fileManager->getExtension($fileName));
00270
00271 if (($type == 'text/xml' || $type == 'text/xml' || $type == 'application/xml' || $type == 'application/xslt+xml')
00272 && $extension == 'xsl') {
00273
00274
00275 $existingFile = $this->getSetting($journal->getJournalId(), 'customXSL');
00276 if (!empty($existingFile) && $fileManager->fileExists($fileManager->filesDir . $existingFile)) {
00277 $fileManager->deleteFile($existingFile);
00278 }
00279
00280
00281 $fileManager->uploadFile('customXSL', $fileName);
00282
00283
00284 $this->updateSetting($journal->getJournalId(), 'XSLstylesheet', 'custom');
00285 $this->updateSetting($journal->getJournalId(), 'customXSL', $fileName);
00286
00287 } else $form->addError('content', Locale::translate('plugins.generic.xmlGalley.settings.customXSLInvalid'));
00288
00289 } else $form->addError('content', Locale::translate('plugins.generic.xmlGalley.settings.customXSLRequired'));
00290
00291
00292 $form->initData();
00293 $form->display();
00294
00295
00296 } elseif (Request::getUserVar('deleteCustomXSL')) {
00297
00298 import('file.JournalFileManager');
00299
00300
00301 $fileManager = &new JournalFileManager($journal);
00302
00303
00304 $fileName = $this->getSetting($journal->getJournalId(), 'customXSL');
00305 if (!empty($fileName)) $fileManager->deleteFile($fileName);
00306
00307
00308 $this->updateSetting($journal->getJournalId(), 'XSLstylesheet', 'NLM');
00309 $this->updateSetting($journal->getJournalId(), 'customXSL', '');
00310
00311
00312 $form->initData();
00313 $form->display();
00314
00315 } else {
00316 $form->initData();
00317 $form->display();
00318 }
00319 return true;
00320 case 'enable':
00321 $this->setEnabled(true);
00322 return false;
00323 case 'disable':
00324 $this->setEnabled(false);
00325 return false;
00326 }
00327 }
00328
00332 function getManagementVerbs() {
00333 $verbs = array();
00334 if ($this->getEnabled()) {
00335 $verbs[] = array(
00336 'disable',
00337 Locale::translate('manager.plugins.disable')
00338 );
00339 $verbs[] = array(
00340 'settings',
00341 Locale::translate('plugins.generic.xmlGalley.manager.settings')
00342 );
00343 } else {
00344 $verbs[] = array(
00345 'enable',
00346 Locale::translate('manager.plugins.enable')
00347 );
00348 }
00349 return $verbs;
00350 }
00351
00352 }
00353 ?>