plugins/generic/phpMyVisites/PhpMyVisitesPlugin.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00017 import('classes.plugins.GenericPlugin');
00018 
00019 class PhpMyVisitesPlugin extends GenericPlugin {
00020 
00027    function register($category, $path) {
00028       $success = parent::register($category, $path);
00029       if (!Config::getVar('general', 'installed')) return false;
00030       $this->addLocaleData();
00031       if ($success) {
00032          // Insert phpmv page tag to common footer  
00033          HookRegistry::register('Templates::Common::Footer::PageFooter', array($this, 'insertFooter'));
00034 
00035          // Insert phpmv page tag to paper footer
00036          HookRegistry::register('Templates::Paper::Footer::PageFooter', array($this, 'insertFooter'));
00037 
00038          // Insert phpmv page tag to paper interstitial footer
00039          HookRegistry::register('Templates::Paper::Interstitial::PageFooter', array($this, 'insertFooter'));
00040 
00041          // Insert phpmv page tag to paper pdf interstitial footer
00042          HookRegistry::register('Templates::Paper::PdfInterstitial::PageFooter', array($this, 'insertFooter'));
00043 
00044          // Insert phpmv page tag to reading tools pages footer
00045          HookRegistry::register('Templates::Rt::Footer::PageFooter', array($this, 'insertFooter'));
00046 
00047          // Insert phpmv page tag to help footer
00048          HookRegistry::register('Templates::Help::Footer::PageFooter', array($this, 'insertFooter'));
00049       }
00050       return $success;
00051    }
00052 
00059    function getName() {
00060       return 'PhpMyVisitesPlugin';
00061    }
00062 
00063    function getDisplayName() {
00064       return __('plugins.generic.phpmv.displayName');
00065    }
00066 
00067    function getDescription() {
00068       return __('plugins.generic.phpmv.description');
00069    }
00070 
00074    function smartyPluginUrl($params, &$smarty) {
00075       $path = array($this->getCategory(), $this->getName());
00076       if (is_array($params['path'])) {
00077          $params['path'] = array_merge($path, $params['path']);
00078       } elseif (!empty($params['path'])) {
00079          $params['path'] = array_merge($path, array($params['path']));
00080       } else {
00081          $params['path'] = $path;
00082       }
00083 
00084       if (!empty($params['id'])) {
00085          $params['path'] = array_merge($params['path'], array($params['id']));
00086          unset($params['id']);
00087       }
00088       return $smarty->smartyUrl($params, $smarty);
00089    }
00090 
00096    function setBreadcrumbs($isSubclass = false) {
00097       $templateMgr =& TemplateManager::getManager();
00098       $pageCrumbs = array(
00099          array(
00100             Request::url(null, null, 'user'),
00101             'navigation.user'
00102          ),
00103          array(
00104             Request::url(null, null, 'manager'),
00105             'user.role.manager'
00106          )
00107       );
00108       if ($isSubclass) $pageCrumbs[] = array(
00109          Request::url(null, null, 'manager', 'plugins'),
00110          'manager.plugins'
00111       );
00112 
00113       $templateMgr->assign('pageHierarchy', $pageCrumbs);
00114    }
00115 
00119    function getManagementVerbs() {
00120       $verbs = array();
00121       if ($this->getEnabled()) {
00122          $verbs[] = array(
00123             'disable',
00124             __('manager.plugins.disable')
00125          );
00126          $verbs[] = array(
00127             'settings',
00128             __('plugins.generic.phpmv.manager.settings')
00129          );
00130       } else {
00131          $verbs[] = array(
00132             'enable',
00133             __('manager.plugins.enable')
00134          );
00135       }
00136       return $verbs;
00137    }
00138 
00142    function getEnabled() {
00143       $conference =& Request::getConference();
00144       if (!$conference) return false;
00145       return $this->getSetting($conference->getId(), 0, 'enabled');
00146    }
00147 
00151    function setEnabled($enabled) {
00152       $conference =& Request::getConference();
00153       if ($conference) {
00154          $this->updateSetting($conference->getId(), 0, 'enabled', $enabled ? true : false);
00155          return true;
00156       }
00157       return false;
00158    }
00159 
00163    function insertFooter($hookName, $params) {
00164       if ($this->getEnabled()) {
00165          $smarty =& $params[1];
00166          $output =& $params[2];
00167          $templateMgr =& TemplateManager::getManager();
00168          $currentConference = $templateMgr->get_template_vars('currentConference');
00169 
00170          if (!empty($currentConference)) {
00171             $conference =& Request::getConference();
00172             $conferenceId = $conference->getId();
00173             $phpmvSiteId = $this->getSetting($conferenceId, 0, 'phpmvSiteId');
00174             $phpmvUrl = $this->getSetting($conferenceId, 0, 'phpmvUrl');
00175 
00176             if (!empty($phpmvSiteId) && !empty($phpmvUrl)) {
00177                $templateMgr->assign('phpmvSiteId', $phpmvSiteId);
00178                $templateMgr->assign('phpmvUrl', $phpmvUrl);
00179                $output .= $templateMgr->fetch($this->getTemplatePath() . 'pageTag.tpl'); 
00180             }
00181          }
00182       }
00183       return false;
00184    }
00185 
00186    /*
00187     * Execute a management verb on this plugin
00188     * @param $verb string
00189     * @param $args array
00190     * @param $message string Location for the plugin to put a result msg
00191     * @return boolean
00192     */
00193    function manage($verb, $args, &$message) {
00194       $templateMgr =& TemplateManager::getManager();
00195       $templateMgr->register_function('plugin_url', array(&$this, 'smartyPluginUrl'));
00196       $conference =& Request::getConference();
00197       $returner = true;
00198 
00199       switch ($verb) {
00200          case 'enable':
00201             $this->setEnabled(true);
00202             $returner = false;
00203             $message = __('plugins.generic.phpmv.enabled');
00204             break;
00205          case 'disable':
00206             $this->setEnabled(false);
00207             $returner = false;
00208             $message = __('plugins.generic.phpmv.disabled');
00209             break;
00210          case 'settings':
00211             if ($this->getEnabled()) {
00212                $this->import('PhpMyVisitesSettingsForm');
00213                $form = new PhpMyVisitesSettingsForm($this, $conference->getId());
00214                if (Request::getUserVar('save')) {
00215                   $form->readInputData();
00216                   if ($form->validate()) {
00217                      $form->execute();
00218                      Request::redirect(null, null, 'manager', 'plugin');
00219                   } else {
00220                      $this->setBreadCrumbs(true);
00221                      $form->display();
00222                   }
00223                } else {
00224                   $this->setBreadCrumbs(true);
00225                   $form->initData();
00226                   $form->display();
00227                }
00228             } else {
00229                Request::redirect(null, null, 'manager');
00230             }
00231             break;
00232          default:
00233             Request::redirect(null, null, 'manager');
00234       }
00235       return $returner;
00236    }
00237 }
00238 ?>

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