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