addLocaleData(); return $success; } /** * Get the name of this plugin. The name must be unique within * its category. * @return String name of plugin */ function getName() { return 'NLMExportPlugin'; } function getDisplayName() { return Locale::translate('plugins.importexport.nlm.displayName'); } function getDescription() { return Locale::translate('plugins.importexport.nlm.description'); } function display(&$args) { $templateMgr = &TemplateManager::getManager(); parent::display($args); $conference = &Request::getConference(); switch (array_shift($args)) { case 'exportPaper': $paperIds = array(array_shift($args)); // $result = array_shift(PaperSearch::formatResults($paperIds)); // $this->exportPaper($conference, $result['track'], $result['section'], $result['publishedPaper']); $result = PaperSearch::formatResults($paperIds); $this->exportPapers($result); break; case 'exportPapers': $paperIds = Request::getUserVar('paperId'); if (!isset($paperIds)) $paperIds = array(); else array_pop($paperIds); $results = &PaperSearch::formatResults($paperIds); $this->exportPapers($results); break; case 'papers': // Display a list of papers for export $this->setBreadcrumbs(array(), true); $publishedPaperDao = &DAORegistry::getDAO('PublishedPaperDAO'); $rangeInfo = Handler::getRangeInfo('papers'); $paperIds = $publishedPaperDao->getPublishedPaperIdsAlphabetizedBySchedConf($conference->getConferenceId()); $totalPapers = count($paperIds); if ($rangeInfo->isValid()) $paperIds = array_slice($paperIds, $rangeInfo->getCount() * ($rangeInfo->getPage()-1), $rangeInfo->getCount()); $iterator = &new VirtualArrayIterator(PaperSearch::formatResults($paperIds), $totalPapers, $rangeInfo->getPage(), $rangeInfo->getCount()); $templateMgr->assign_by_ref('papers', $iterator); $templateMgr->display($this->getTemplatePath() . 'papers.tpl'); break; default: $this->setBreadcrumbs(); $templateMgr->display($this->getTemplatePath() . 'index.tpl'); } } function exportPapers(&$results, $outputFile = null) { $this->import('NLMExportDom'); $doc = &NLMExportDom::generateNLMDom(); $paperSetNode = &NLMExportDom::generatePaperSetDom($doc); foreach ($results as $result) { $conference = &$result['conference']; $track = &$result['track']; $paper = &$result['publishedPaper']; $paperNode = &NLMExportDom::generatePaperDom($doc, $conference, $track, $paper); XMLCustomWriter::appendChild($paperSetNode, $paperNode); } if (!empty($outputFile)) { if (($h = fopen($outputFile, 'w'))===false) return false; fwrite($h, XMLCustomWriter::getXML($doc)); fclose($h); } else { header("Content-Type: application/xml"); header("Cache-Control: private"); header("Content-Disposition: attachment; filename=\"nlm.xml\""); XMLCustomWriter::printXML($doc); //echo '
'.htmlentities(preg_replace('/>', ">\n<", XMLCustomWriter::getXML($doc))).''; } return true; } /** * Execute import/export tasks using the command-line interface. * @param $args Parameters to the plugin */ function executeCLI($scriptName, &$args) { // $command = array_shift($args); $xmlFile = array_shift($args); $conferencePath = array_shift($args); $conferenceDao = &DAORegistry::getDAO('ConferenceDAO'); $userDao = &DAORegistry::getDAO('UserDAO'); $publishedPaperDao = &DAORegistry::getDAO('PublishedPaperDAO'); $conference = &$conferenceDao->getConferenceByPath($conferencePath); if (!$conference) { if ($conferencePath != '') { echo Locale::translate('plugins.importexport.nlm.cliError') . "\n"; echo Locale::translate('plugins.importexport.nlm.export.error.unknownConference', array('conferencePath' => $conferencePath)) . "\n\n"; } $this->usage($scriptName); return; } if ($xmlFile != '') switch (array_shift($args)) { case 'papers': $results = &PaperSearch::formatResults($args); if (!$this->exportPapers($results, $xmlFile)) { echo Locale::translate('plugins.importexport.nlm.cliError') . "\n"; echo Locale::translate('plugins.importexport.nlm.export.error.couldNotWrite', array('fileName' => $xmlFile)) . "\n\n"; } return; } $this->usage($scriptName); } /** * Display the command-line usage information */ function usage($scriptName) { echo Locale::translate('plugins.importexport.nlm.cliUsage', array( 'scriptName' => $scriptName, 'pluginName' => $this->getName() )) . "\n"; } } ?>