00001 <?php
00002
00016
00017
00018
00019 import('classes.plugins.GatewayPlugin');
00020
00021 class ThesisFeedGatewayPlugin extends GatewayPlugin {
00027 function getName() {
00028 return 'ThesisFeedGatewayPlugin';
00029 }
00030
00031 function getDisplayName() {
00032 return Locale::translate('plugins.generic.thesisfeed.displayName');
00033 }
00034
00035 function getDescription() {
00036 return Locale::translate('plugins.generic.thesisfeed.description');
00037 }
00038
00043 function &getThesisFeedPlugin() {
00044 $plugin =& PluginRegistry::getPlugin('generic', 'ThesisFeedPlugin');
00045 return $plugin;
00046 }
00047
00052 function &getThesisPlugin() {
00053 $plugin =& PluginRegistry::getPlugin('generic', 'ThesisPlugin');
00054 return $plugin;
00055 }
00056
00060 function getPluginPath() {
00061 $plugin =& $this->getThesisFeedPlugin();
00062 return $plugin->getPluginPath();
00063 }
00064
00069 function getTemplatePath() {
00070 $plugin =& $this->getThesisFeedPlugin();
00071 return $plugin->getTemplatePath() . 'templates/';
00072 }
00073
00077 function fetch($args) {
00078
00079 $journal =& Request::getJournal();
00080 if (!$journal) return false;
00081
00082
00083 $thesisPlugin =& $this->getThesisPlugin();
00084 $thesisEnabled = $thesisPlugin->getEnabled();
00085 $thesisFeedPlugin =& $this->getThesisFeedPlugin();
00086 $thesisFeedPluginEnabled = $thesisFeedPlugin->getEnabled();
00087
00088 if (!$thesisEnabled || !$thesisFeedPluginEnabled) return false;
00089
00090
00091 $type = array_shift($args);
00092 $typeMap = array(
00093 'rss' => 'rss.tpl',
00094 'rss2' => 'rss2.tpl',
00095 'atom' => 'atom.tpl'
00096 );
00097 $mimeTypeMap = array(
00098 'rss' => 'application/rdf+xml',
00099 'rss2' => 'application/rss+xml',
00100 'atom' => 'application/atom+xml'
00101 );
00102 if (!isset($typeMap[$type])) return false;
00103
00104
00105 $limitRecentItems = $thesisFeedPlugin->getSetting($journal->getJournalId(), 'limitRecentItems');
00106 $recentItems = (int) $thesisFeedPlugin->getSetting($journal->getJournalId(), 'recentItems');
00107
00108 $thesisDao =& DAORegistry::getDAO('ThesisDAO');
00109 $journalId = $journal->getJournalId();
00110 if ($limitRecentItems && $recentItems > 0) {
00111 import('db.DBResultRange');
00112 $rangeInfo =& new DBResultRange($recentItems, 1);
00113 $theses =& $thesisDao->getActiveThesesByJournalId($journalId, null, null, null, null, null, null, $rangeInfo);
00114 } else {
00115 $theses =& $thesisDao->getActiveThesesByJournalId($journalId);
00116 }
00117
00118
00119 $lastDateUpdated = $thesisFeedPlugin->getSetting($journal->getJournalId(), 'dateUpdated');
00120 if ($theses->wasEmpty()) {
00121 if (empty($lastDateUpdated)) {
00122 $dateUpdated = Core::getCurrentDate();
00123 $thesisFeedPlugin->updateSetting($journal->getJournalId(), 'dateUpdated', $dateUpdated, 'string');
00124 } else {
00125 $dateUpdated = $lastDateUpdated;
00126 }
00127 } else {
00128 $mostRecentThesis =& $thesisDao->getMostRecentActiveThesisByJournalId($journalId);
00129 $dateUpdated = $mostRecentThesis->getDateSubmitted();
00130 if (empty($lastDateUpdated) || (strtotime($dateUpdated) > strtotime($lastDateUpdated))) {
00131 $thesisFeedPlugin->updateSetting($journal->getJournalId(), 'dateUpdated', $dateUpdated, 'string');
00132 }
00133 }
00134
00135 $versionDao =& DAORegistry::getDAO('VersionDAO');
00136 $version =& $versionDao->getCurrentVersion();
00137
00138 $templateMgr = &TemplateManager::getManager();
00139 $templateMgr->assign('ojsVersion', $version->getVersionString());
00140 $templateMgr->assign('selfUrl', Request::getCompleteUrl());
00141 $templateMgr->assign('dateUpdated', $dateUpdated);
00142 $templateMgr->assign_by_ref('theses', $theses->toArray());
00143 $templateMgr->assign_by_ref('journal', $journal);
00144
00145 $templateMgr->display($this->getTemplatePath() . $typeMap[$type], $mimeTypeMap[$type]);
00146
00147 return true;
00148 }
00149 }
00150
00151 ?>