plugins/generic/announcementFeed/AnnouncementFeedPlugin.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00017 import('classes.plugins.GenericPlugin');
00018 
00019 class AnnouncementFeedPlugin extends GenericPlugin {
00020    function register($category, $path) {
00021       if (parent::register($category, $path)) {
00022          if ($this->getEnabled()) {
00023             HookRegistry::register('TemplateManager::display',array(&$this, 'callbackAddLinks'));
00024             HookRegistry::register('PluginRegistry::loadCategory', array(&$this, 'callbackLoadCategory'));
00025          }
00026          $this->addLocaleData();
00027          return true;
00028       }
00029       return false;
00030    }
00031 
00036    function getName() {
00037       return 'AnnouncementFeedPlugin';
00038    }
00039 
00044    function getDisplayName() {
00045       return __('plugins.generic.announcementfeed.displayName');
00046    }
00047 
00052    function getDescription() {
00053       return __('plugins.generic.announcementfeed.description');
00054    }   
00055 
00060    function getEnabled() {
00061       $conference =& Request::getConference();
00062       $conferenceId = $conference?$conference->getId():0;
00063       return $this->getSetting($conferenceId, 0, 'enabled');
00064    }
00065 
00072    function callbackLoadCategory($hookName, $args) {
00073       $category =& $args[0];
00074       $plugins =& $args[1];
00075       switch ($category) {
00076          case 'blocks':
00077             $this->import('AnnouncementFeedBlockPlugin');
00078             $blockPlugin = new AnnouncementFeedBlockPlugin();
00079             $plugins[$blockPlugin->getSeq()][$blockPlugin->getPluginPath()] =& $blockPlugin;
00080             break;
00081          case 'gateways':
00082             $this->import('AnnouncementFeedGatewayPlugin');
00083             $gatewayPlugin = new AnnouncementFeedGatewayPlugin();
00084             $plugins[$gatewayPlugin->getSeq()][$gatewayPlugin->getPluginPath()] =& $gatewayPlugin;
00085             break;
00086       }
00087       return false;
00088    }
00089 
00090    function callbackAddLinks($hookName, $args) {
00091       if ($this->getEnabled()) {
00092          $templateManager =& $args[0];
00093          $currentConference =& $templateManager->get_template_vars('currentConference');
00094          $announcementsEnabled = $currentConference ? $currentConference->getSetting('enableAnnouncements') : false;
00095          $displayPage = $currentConference ? $this->getSetting($currentConference->getId(), 0, 'displayPage') : null;
00096          $requestedPage = Request::getRequestedPage();
00097 
00098          if ( $announcementsEnabled && (($displayPage == 'all') || ($displayPage == 'homepage' && (empty($requestedPage) || $requestedPage == 'index' || $requestedPage == 'announcement')) || ($displayPage == $requestedPage)) ) { 
00099 
00100             // if we have a conference selected, append feed meta-links into the header
00101             $additionalHeadData = $templateManager->get_template_vars('additionalHeadData');
00102 
00103             $feedUrl1 = '<link rel="alternate" type="application/atom+xml" href="' . Request::url(null, null, 'gateway', 'plugin', array('AnnouncementFeedGatewayPlugin', 'atom')) . '" />';
00104             $feedUrl2 = '<link rel="alternate" type="application/rdf+xml" href="'. Request::url(null, null, 'gateway', 'plugin', array('AnnouncementFeedGatewayPlugin', 'rss')) . '" />';
00105             $feedUrl3 = '<link rel="alternate" type="application/rss+xml" href="' . Request::url(null, null, 'gateway', 'plugin', array('AnnouncementFeedGatewayPlugin', 'rss2')) . '" />';
00106 
00107             $templateManager->assign('additionalHeadData', $additionalHeadData."\n\t".$feedUrl1."\n\t".$feedUrl2."\n\t".$feedUrl3);
00108          }
00109       }
00110 
00111       return false;
00112    }
00113 
00117    function getManagementVerbs() {
00118       $verbs = array();
00119       if ($this->getEnabled()) {
00120          $verbs[] = array(
00121             'disable',
00122             __('manager.plugins.disable')
00123          );
00124          $verbs[] = array(
00125             'settings',
00126             __('plugins.generic.announcementfeed.settings')
00127          );
00128       } else {
00129          $verbs[] = array(
00130             'enable',
00131             __('manager.plugins.enable')
00132          );
00133       }
00134       return $verbs;
00135    }
00136 
00137    /*
00138     * Execute a management verb on this plugin
00139     * @param $verb string
00140     * @param $args array
00141     * @param $message string Location for the plugin to put a result msg
00142     * @return boolean
00143     */
00144    function manage($verb, $args, &$message) {
00145       $returner = true;
00146       $conference =& Request::getConference();
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, $conference->getId());
00155 
00156             if (Request::getUserVar('save')) {
00157                $form->readInputData();
00158                if ($form->validate()) {
00159                   $form->execute();
00160                   $returner = false;
00161                } else {
00162                   $form->display();
00163                }
00164             } else {
00165                $form->initData();
00166                $form->display();
00167             }
00168             break;
00169          case 'enable':
00170             $this->updateSetting($conference->getId(), 0, 'enabled', true);
00171             $message = __('plugins.generic.announcementfeed.enabled');
00172             $returner = false;
00173             break;
00174          case 'disable':
00175             $this->updateSetting($conference->getId(), 0, 'enabled', false);
00176             $message = __('plugins.generic.announcementfeed.enabled');
00177             $returner = false;
00178             break;   
00179       }
00180       return $returner;    
00181    }
00182 }
00183 
00184 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7