00001 <?php
00002
00015
00016
00017
00018 import('classes.plugins.GenericPlugin');
00019
00020 class CmsPlugin extends GenericPlugin {
00021
00022 function getName() {
00023 return 'CmsPlugin';
00024 }
00025
00026 function getDisplayName() {
00027 return Locale::translate('plugins.generic.cms.displayName');
00028 }
00029
00030 function getDescription() {
00031 $description = Locale::translate('plugins.generic.cms.description');
00032 if ( !$this->isTinyMCEInstalled() )
00033 $description .= "<br />".Locale::translate('plugins.generic.cms.requirement.tinymce');
00034 return $description;
00035 }
00036
00037 function isTinyMCEInstalled() {
00038 $tinyMCEPlugin = &PluginRegistry::getPlugin('generic', 'TinyMCEPlugin');
00039
00040 if ( $tinyMCEPlugin )
00041 return $tinyMCEPlugin->getEnabled();
00042
00043 return false;
00044 }
00045
00052 function register($category, $path) {
00053 if (parent::register($category, $path)) {
00054 $this->addLocaleData();
00055 if ($this->getEnabled()) {
00056 HookRegistry::register('LoadHandler', array(&$this, 'callbackHandleContent'));
00057 HookRegistry::register('PluginRegistry::loadCategory', array(&$this, 'callbackLoadCategory'));
00058 }
00059 return true;
00060 }
00061 return false;
00062 }
00063
00071 function callbackLoadCategory($hookName, $args) {
00072 $category =& $args[0];
00073 $plugins =& $args[1];
00074 switch ($category) {
00075 case 'blocks':
00076 $this->import('CmsBlockPlugin');
00077 $blockPlugin =& new CmsBlockPlugin();
00078 $plugins[$category][$blockPlugin->getSeq()] =& $blockPlugin;
00079 break;
00080 }
00081 return false;
00082 }
00083
00084
00085
00086
00087 function callbackHandleContent($hookName, $args) {
00088 $templateMgr = &TemplateManager::getManager();
00089
00090 $page =& $args[0];
00091 $op =& $args[1];
00092
00093 if ( $page == 'cms' ) {
00094 define('HANDLER_CLASS', 'CmsHandler');
00095 $this->import('CmsHandler');
00096 return true;
00097 }
00098 return false;
00099 }
00100
00104 function getEnabled() {
00105 $journal = &Request::getJournal();
00106 if (!$journal) return false;
00107 return $this->getSetting($journal->getJournalId(), 'enabled');
00108 }
00109
00113 function setEnabled($enabled) {
00114 $journal = &Request::getJournal();
00115 if ($journal) {
00116 $this->updateSetting($journal->getJournalId(), 'enabled', $enabled ? true : false);
00117
00118 $layoutManagerPlugin = &PluginRegistry::getPlugin('generic', 'LayoutManager');
00119
00120 if ( $enabled ) {
00121 $this->import('ContentManager');
00122 $contentManager =& new ContentManager();
00123
00124 $h = array();
00125 $c = array();
00126
00127
00128 $contentManager->parseContents( $h, $c );
00129
00130
00131 $this->updateSetting($journal->getJournalId(), 'toc', $h);
00132 }
00133
00134 return true;
00135 }
00136 return false;
00137 }
00138
00142 function getManagementVerbs() {
00143 $verbs = array();
00144 if ($this->getEnabled()) {
00145 $verbs[] = array(
00146 'disable',
00147 Locale::translate('manager.plugins.disable')
00148 );
00149 if ( $this->isTinyMCEInstalled() ) {
00150 $verbs[] = array(
00151 'edit',
00152 Locale::translate('manager.plugins.content')
00153 );
00154 }
00155 } else {
00156 $verbs[] = array(
00157 'enable',
00158 Locale::translate('manager.plugins.enable')
00159 );
00160 }
00161 return $verbs;
00162 }
00163
00167 function manage($verb, $args) {
00168 $returner = true;
00169
00170 $templateMgr = &TemplateManager::getManager();
00171 $templateMgr->register_function('plugin_url', array(&$this, 'smartyPluginUrl'));
00172
00173
00174 switch ($verb) {
00175 case 'edit':
00176 $journal =& Request::getJournal();
00177
00178 $this->import('CmsSettingsForm');
00179 $form =& new CmsSettingsForm($this, $journal->getJournalId());
00180
00181
00182 if ( Request::getUserVar('content') ) {
00183 $form->readInputData();
00184
00185 if ($form->validate()) {
00186
00187 $form->save();
00188 $form->initData( array($form->getData('current')) );
00189 } else {
00190
00191 $form->addTinyMCE();
00192
00193
00194
00195
00196 $templateMgr->assign('currentHeading', '');
00197 $templateMgr->assign('currentContent', Request::getUserVar('content'));
00198
00199 }
00200 $form->display();
00201 } else {
00202 $form->initData($args);
00203 $form->display();
00204 }
00205 $returner = true;
00206 break;
00207 case 'enable':
00208 $this->setEnabled(true);
00209 $returner = false;
00210 break;
00211 case 'disable':
00212 $this->setEnabled(false);
00213 $returner = false;
00214 break;
00215 }
00216
00217 return $returner;
00218 }
00219 }
00220
00221 ?>