00001 <?php
00002
00015
00016
00017
00018 import('classes.plugins.ImportExportPlugin');
00019
00020 import('xml.XMLCustomWriter');
00021
00022 class EruditExportPlugin extends ImportExportPlugin {
00029 function register($category, $path) {
00030 $success = parent::register($category, $path);
00031 $this->addLocaleData();
00032 return $success;
00033 }
00034
00040 function getName() {
00041 return 'EruditExportPlugin';
00042 }
00043
00044 function getDisplayName() {
00045 return Locale::translate('plugins.importexport.erudit.displayName');
00046 }
00047
00048 function getDescription() {
00049 return Locale::translate('plugins.importexport.erudit.description');
00050 }
00051
00052 function display(&$args) {
00053 $templateMgr = &TemplateManager::getManager();
00054 parent::display($args);
00055
00056 $issueDao = &DAORegistry::getDAO('IssueDAO');
00057 $publishedArticleDao = &DAORegistry::getDAO('PublishedArticleDAO');
00058 $articleGalleyDao = &DAORegistry::getDAO('ArticleGalleyDAO');
00059
00060 $journal = &Request::getJournal();
00061 switch (array_shift($args)) {
00062 case 'exportGalley':
00063 $articleId = array_shift($args);
00064 $galleyId = array_shift($args);
00065
00066 $article = &$publishedArticleDao->getPublishedArticleByArticleId($articleId);
00067 $galley = &$articleGalleyDao->getGalley($galleyId, $articleId);
00068 if ($article && $galley && ($issue = &$issueDao->getIssueById($article->getIssueId(), $journal->getJournalId()))) {
00069 $this->exportArticle($journal, $issue, $article, $galley);
00070 break;
00071 }
00072 default:
00073
00074 $this->setBreadcrumbs();
00075 $publishedArticleDao = &DAORegistry::getDAO('PublishedArticleDAO');
00076 $rangeInfo = Handler::getRangeInfo('articles');
00077 $articleIds = $publishedArticleDao->getPublishedArticleIdsAlphabetizedByJournal($journal->getJournalId(), false);
00078 $totalArticles = count($articleIds);
00079 $articleIds = array_slice($articleIds, $rangeInfo->getCount() * ($rangeInfo->getPage()-1), $rangeInfo->getCount());
00080 $iterator = &new VirtualArrayIterator(ArticleSearch::formatResults($articleIds), $totalArticles, $rangeInfo->getPage(), $rangeInfo->getCount());
00081 $templateMgr->assign_by_ref('articles', $iterator);
00082 $templateMgr->display($this->getTemplatePath() . 'index.tpl');
00083 break;
00084 }
00085 }
00086
00087 function exportArticle(&$journal, &$issue, &$article, &$galley, $outputFile = null) {
00088 $this->import('EruditExportDom');
00089 $doc = &XMLCustomWriter::createDocument('article', '-//ERUDIT//Erudit Article DTD 3.0.0//EN', 'http://www.erudit.org/dtd/article/3.0.0/en/eruditarticle.dtd');
00090 $articleNode = &EruditExportDom::generateArticleDom($doc, $journal, $issue, $article, $galley);
00091 XMLCustomWriter::appendChild($doc, $articleNode);
00092
00093 if (!empty($outputFile)) {
00094 if (($h = fopen($outputFile, 'wb'))===false) return false;
00095 fwrite($h, XMLCustomWriter::getXML($doc));
00096 fclose($h);
00097 } else {
00098 header("Content-Type: application/xml");
00099 header("Cache-Control: private");
00100 header("Content-Disposition: attachment; filename=\"erudit.xml\"");
00101 XMLCustomWriter::printXML($doc);
00102 }
00103 return true;
00104 }
00105
00110 function executeCLI($scriptName, &$args) {
00111 $xmlFile = array_shift($args);
00112 $journalPath = array_shift($args);
00113 $articleId = array_shift($args);
00114 $galleyLabel = array_shift($args);
00115
00116 $journalDao = &DAORegistry::getDAO('JournalDAO');
00117 $issueDao = &DAORegistry::getDAO('IssueDAO');
00118 $sectionDao = &DAORegistry::getDAO('SectionDAO');
00119 $userDao = &DAORegistry::getDAO('UserDAO');
00120 $publishedArticleDao = &DAORegistry::getDAO('PublishedArticleDAO');
00121
00122 $journal = &$journalDao->getJournalByPath($journalPath);
00123
00124 if (!$journal) {
00125 if ($journalPath != '') {
00126 echo Locale::translate('plugins.importexport.erudit.cliError') . "\n";
00127 echo Locale::translate('plugins.importexport.erudit.error.unknownJournal', array('journalPath' => $journalPath)) . "\n\n";
00128 }
00129 $this->usage($scriptName);
00130 return;
00131 }
00132
00133 $publishedArticle = &$publishedArticleDao->getPublishedArticleByBestArticleId($journal->getJournalId(), $articleId);
00134 if ($publishedArticle == null) {
00135 echo Locale::translate('plugins.importexport.erudit.cliError') . "\n";
00136 echo Locale::translate('plugins.importexport.erudit.export.error.articleNotFound', array('articleId' => $articleId)) . "\n\n";
00137 return;
00138 }
00139 foreach ($publishedArticle->getGalleys() as $thisGalley) {
00140 if ($thisGalley->getLabel() == $galleyLabel) {
00141 $galley =& $thisGalley;
00142 break;
00143 }
00144 }
00145 if (!isset($galley)) {
00146 echo Locale::translate('plugins.importexport.erudit.export.error.galleyNotFound', array('galleyLabel' => $galleyLabel)) . "\n\n";
00147 return;
00148 }
00149 $issue = &$issueDao->getIssueById($publishedArticle->getIssueId());
00150 if (!$this->exportArticle($journal, $issue, $publishedArticle, $galley, $xmlFile)) {
00151 echo Locale::translate('plugins.importexport.erudit.cliError') . "\n";
00152 echo Locale::translate('plugins.importexport.erudit.export.error.couldNotWrite', array('fileName' => $xmlFile)) . "\n\n";
00153 }
00154 }
00155
00159 function usage($scriptName) {
00160 echo Locale::translate('plugins.importexport.erudit.cliUsage', array(
00161 'scriptName' => $scriptName,
00162 'pluginName' => $this->getName()
00163 )) . "\n";
00164 }
00165 }
00166
00167 ?>