00001 <?php
00002
00015
00016
00017
00018 import('classes.plugins.GenericPlugin');
00019
00020 class ThesisFeedPlugin extends GenericPlugin {
00021 function register($category, $path) {
00022 if (parent::register($category, $path)) {
00023 if ($this->getEnabled()) {
00024 HookRegistry::register('TemplateManager::display',array(&$this, 'callbackAddLinks'));
00025 HookRegistry::register('PluginRegistry::loadCategory', array(&$this, 'callbackLoadCategory'));
00026 }
00027 $this->addLocaleData();
00028 return true;
00029 }
00030 return false;
00031 }
00032
00037 function getName() {
00038 return 'ThesisFeedPlugin';
00039 }
00040
00045 function getDisplayName() {
00046 return Locale::translate('plugins.generic.thesisfeed.displayName');
00047 }
00048
00053 function getDescription() {
00054 return Locale::translate('plugins.generic.thesisfeed.description');
00055 }
00056
00061 function getEnabled() {
00062 $journal =& Request::getJournal();
00063 $journalId = $journal?$journal->getJournalId():0;
00064 return $this->getSetting($journalId, 'enabled');
00065 }
00066
00073 function callbackLoadCategory($hookName, $args) {
00074 $category =& $args[0];
00075 $plugins =& $args[1];
00076 switch ($category) {
00077 case 'blocks':
00078 $this->import('ThesisFeedBlockPlugin');
00079 $blockPlugin =& new ThesisFeedBlockPlugin();
00080 $plugins[$blockPlugin->getSeq()][$blockPlugin->getPluginPath()] =& $blockPlugin;
00081 break;
00082 case 'gateways':
00083 $this->import('ThesisFeedGatewayPlugin');
00084 $gatewayPlugin =& new ThesisFeedGatewayPlugin();
00085 $plugins[$gatewayPlugin->getSeq()][$gatewayPlugin->getPluginPath()] =& $gatewayPlugin;
00086 break;
00087 }
00088 return false;
00089 }
00090
00091 function callbackAddLinks($hookName, $args) {
00092 if ($this->getEnabled()) {
00093 $templateManager =& $args[0];
00094 $currentJournal =& $templateManager->get_template_vars('currentJournal');
00095
00096 $thesisPlugin =& PluginRegistry::getPlugin('generic', 'ThesisPlugin');
00097 $thesisEnabled = $thesisPlugin->getEnabled();
00098
00099 $displayPage = $currentJournal ? $this->getSetting($currentJournal->getJournalId(), 'displayPage') : null;
00100 $requestedPage = Request::getRequestedPage();
00101
00102 if ( $thesisEnabled && (($displayPage == 'all') || ($displayPage == 'homepage' && (empty($requestedPage) || $requestedPage == 'index' || $requestedPage == 'thesis')) || ($displayPage == $requestedPage)) ) {
00103
00104
00105 $additionalHeadData = $templateManager->get_template_vars('additionalHeadData');
00106
00107 $feedUrl1 = '<link rel="alternate" type="application/atom+xml" href="'.$currentJournal->getUrl().'/gateway/plugin/ThesisFeedGatewayPlugin/atom" />';
00108 $feedUrl2 = '<link rel="alternate" type="application/rdf+xml" href="'.$currentJournal->getUrl().'/gateway/plugin/ThesisFeedGatewayPlugin/rss" />';
00109 $feedUrl3 = '<link rel="alternate" type="application/rss+xml" href="'.$currentJournal->getUrl().'/gateway/plugin/ThesisFeedGatewayPlugin/rss2" />';
00110
00111 $templateManager->assign('additionalHeadData', $additionalHeadData."\n\t".$feedUrl1."\n\t".$feedUrl2."\n\t".$feedUrl3);
00112 }
00113 }
00114
00115 return false;
00116 }
00117
00121 function getManagementVerbs() {
00122 $verbs = array();
00123 if ($this->getEnabled()) {
00124 $verbs[] = array(
00125 'disable',
00126 Locale::translate('manager.plugins.disable')
00127 );
00128 $verbs[] = array(
00129 'settings',
00130 Locale::translate('plugins.generic.thesisfeed.settings')
00131 );
00132 } else {
00133 $verbs[] = array(
00134 'enable',
00135 Locale::translate('manager.plugins.enable')
00136 );
00137 }
00138 return $verbs;
00139 }
00140
00144 function manage($verb, $args) {
00145 $returner = true;
00146 $journal =& Request::getJournal();
00147
00148 switch ($verb) {
00149 case 'settings':
00150 $templateMgr = &TemplateManager::getManager();
00151 $templateMgr->register_function('plugin_url', array(&$this, 'smartyPluginUrl'));
00152
00153 $this->import('SettingsForm');
00154 $form =& new SettingsForm($this, $journal->getJournalId());
00155
00156 if (Request::getUserVar('save')) {
00157 $form->readInputData();
00158 if ($form->validate()) {
00159 $form->execute();
00160 Request::redirect(null, null, 'plugins');
00161 } else {
00162 $form->display();
00163 }
00164 } else {
00165 $form->initData();
00166 $form->display();
00167 }
00168 break;
00169 case 'enable':
00170 $this->updateSetting($journal->getJournalId(), 'enabled', true);
00171 $returner = false;
00172 break;
00173 case 'disable':
00174 $this->updateSetting($journal->getJournalId(), 'enabled', false);
00175 $returner = false;
00176 break;
00177 }
00178
00179 return $returner;
00180 }
00181 }
00182
00183 ?>