plugins/generic/staticPages/StaticPagesPlugin.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 import('classes.plugins.GenericPlugin');
00017 
00018 class StaticPagesPlugin extends GenericPlugin {
00019 
00020    function getName() {
00021       return 'StaticPagesPlugin';
00022    }
00023 
00024    function getDisplayName() {
00025       return __('plugins.generic.staticPages.displayName');
00026    }
00027 
00028    function getDescription() {
00029       $description = __('plugins.generic.staticPages.description');
00030       if ( !$this->isTinyMCEInstalled() )
00031          $description .= "<br />".__('plugins.generic.staticPages.requirement.tinymce');
00032       return $description;
00033    }
00034 
00035    function isTinyMCEInstalled() {
00036       $tinyMCEPlugin =& PluginRegistry::getPlugin('generic', 'TinyMCEPlugin');
00037 
00038       if ( $tinyMCEPlugin )
00039          return $tinyMCEPlugin->getEnabled();
00040 
00041       return false;
00042    }
00043 
00050    function register($category, $path) {
00051       if (parent::register($category, $path)) {
00052          $this->addLocaleData();
00053          if ($this->getEnabled()) {
00054             $this->import('StaticPagesDAO');
00055             if (checkPhpVersion('5.0.0')) { // WARNING: see http://pkp.sfu.ca/wiki/index.php/Information_for_Developers#Use_of_.24this_in_the_constructur
00056                $staticPagesDAO = new StaticPagesDAO();
00057             } else {
00058                $staticPagesDAO =& new StaticPagesDAO();
00059             }
00060             $returner =& DAORegistry::registerDAO('StaticPagesDAO', $staticPagesDAO);
00061 
00062             HookRegistry::register('LoadHandler', array(&$this, 'callbackHandleContent'));
00063          }
00064          return true;
00065       }
00066       return false;
00067    }
00068 
00072    function callbackHandleContent($hookName, $args) {
00073       $templateMgr =& TemplateManager::getManager();
00074 
00075       $page =& $args[0];
00076       $op =& $args[1];
00077 
00078       if ( $page == 'pages' ) {
00079          define('HANDLER_CLASS', 'StaticPagesHandler');
00080          $this->import('StaticPagesHandler');
00081          return true;
00082       }
00083       return false;
00084    }
00085 
00089    function getEnabled() {
00090       $conference =& Request::getConference();
00091       $conferenceId = $conference?$conference->getId():0;
00092       return $this->getSetting($conferenceId, 0, 'enabled');
00093    }
00094 
00098    function setEnabled($enabled) {
00099       $conference =& Request::getConference();
00100       $conferenceId = $conference?$conference->getId():0;
00101       $this->updateSetting($conferenceId, 0, 'enabled', $enabled);
00102 
00103       return true;
00104    }
00105 
00109    function getManagementVerbs() {
00110       $verbs = array();
00111       if ($this->getEnabled()) {
00112          $verbs[] = array(
00113             'disable',
00114             __('manager.plugins.disable')
00115          );
00116          if ( $this->isTinyMCEInstalled() ) {
00117             $verbs[] = array(
00118                'settings',
00119                __('plugins.generic.staticPages.editAddContent')
00120             );
00121          }
00122       } else {
00123          $verbs[] = array(
00124             'enable',
00125             __('manager.plugins.enable')
00126          );
00127       }
00128       return $verbs;
00129    }
00130 
00134    function manage($verb, $args) {
00135       $returner = true;
00136 
00137       $templateMgr =& TemplateManager::getManager();
00138       $templateMgr->register_function('plugin_url', array(&$this, 'smartyPluginUrl'));
00139       $templateMgr->assign('pagesPath', Request::url(null, null, 'pages', 'view', 'REPLACEME'));
00140 
00141       $pageCrumbs = array(
00142          array(
00143             Request::url(null, null, 'user'),
00144             'navigation.user'
00145          ),
00146          array(
00147             Request::url(null, null, 'manager'),
00148             'user.role.manager'
00149          )
00150       );
00151 
00152       switch ($verb) {
00153          case 'settings':
00154             $conference =& Request::getConference();
00155 
00156             $this->import('StaticPagesSettingsForm');
00157             $form = new StaticPagesSettingsForm($this, $conference->getId());
00158 
00159             $templateMgr->assign('pageHierarchy', $pageCrumbs);
00160             $form->initData();
00161             $form->display();
00162             break;
00163          case 'edit':
00164          case 'add':
00165             $conference =& Request::getConference();
00166 
00167             $this->import('StaticPagesEditForm');
00168 
00169             $staticPageId = isset($args[0])?(int)$args[0]:null;
00170             $form = new StaticPagesEditForm($this, $conference->getId(), $staticPageId);
00171 
00172             if ($form->isLocaleResubmit()) {
00173                $form->readInputData();
00174                $form->addTinyMCE();
00175             } else {
00176                $form->initData();
00177             }
00178 
00179             $pageCrumbs[] = array(
00180                Request::url(null, null,  'manager', 'plugin', array('generic', $this->getName(), 'settings')),
00181                $this->getDisplayName(),
00182                true
00183             );
00184             $templateMgr->assign('pageHierarchy', $pageCrumbs);
00185             $form->display();
00186             $returner = true;
00187             break;
00188          case 'save':
00189             $conference =& Request::getConference();
00190 
00191             $this->import('StaticPagesEditForm');
00192 
00193             $staticPageId = isset($args[0])?(int)$args[0]:null;
00194             $form = new StaticPagesEditForm($this, $conference->getId(), $staticPageId);
00195 
00196             if (Request::getUserVar('edit')) {
00197                $form->readInputData();
00198                if ($form->validate()) {
00199                   $form->save();
00200                   $templateMgr->assign(array(
00201                      'currentUrl' => Request::url(null, null, null, null, array($this->getCategory(), $this->getName(), 'settings')),
00202                      'pageTitle' => 'plugins.generic.staticPages.displayName',
00203                      'pageHierarchy' => $pageCrumbs,
00204                      'message' => 'plugins.generic.staticPages.pageSaved',
00205                      'backLink' => Request::url(null, null, null, null, array($this->getCategory(), $this->getName(), 'settings')),
00206                      'backLinkLabel' => 'common.continue'
00207                   ));
00208                   $templateMgr->display('common/message.tpl');
00209                   exit;
00210                } else {
00211                   $form->addTinyMCE();
00212                   $form->display();
00213                   exit;
00214                }
00215             }
00216             Request::redirect(null, null, null, 'manager', 'plugins');
00217             $returner = true;
00218             break;
00219          case 'delete':
00220             $conference =& Request::getConference();
00221             $staticPageId = isset($args[0])?(int) $args[0]:null;
00222             $staticPagesDAO =& DAORegistry::getDAO('StaticPagesDAO');
00223             $staticPagesDAO->deleteStaticPageById($staticPageId);
00224 
00225             $templateMgr->assign(array(
00226                'currentUrl' => Request::url(null, null, null, null, array($this->getCategory(), $this->getName(), 'settings')),
00227                'pageTitle' => 'plugins.generic.staticPages.displayName',
00228                'message' => 'plugins.generic.staticPages.pageDeleted',
00229                'backLink' => Request::url(null, null, null, null, array($this->getCategory(), $this->getName(), 'settings')),
00230                'backLinkLabel' => 'common.continue'
00231             ));
00232 
00233             $templateMgr->assign('pageHierarchy', $pageCrumbs);
00234             $templateMgr->display('common/message.tpl');
00235             $returner = true;
00236             break;
00237          case 'enable':
00238             $this->setEnabled(true);
00239             $returner = false;
00240             break;
00241          case 'disable':
00242             $this->setEnabled(false);
00243             $returner = false;
00244             break;
00245       }
00246 
00247       return $returner;
00248    }
00249 
00253    function getInstallSchemaFile() {
00254       return $this->getPluginPath() . '/' . 'schema.xml';
00255    }
00256 }
00257 
00258 ?>

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