00001 <?php
00002
00015
00016
00017
00018 define('BLOCK_CONTEXT_LEFT_SIDEBAR', 0x00000001);
00019 define('BLOCK_CONTEXT_RIGHT_SIDEBAR', 0x00000002);
00020 define('BLOCK_CONTEXT_HOMEPAGE', 0x00000003);
00021
00022 class BlockPlugin extends Plugin {
00023 function register($category, $path) {
00024 $success = parent::register($category, $path);
00025 if ($success && $this->getEnabled()) {
00026 $contextMap =& $this->getContextMap();
00027 $blockContext = $this->getBlockContext();
00028 if (isset($contextMap[$blockContext])) {
00029 $hookName = $contextMap[$blockContext];
00030 HookRegistry::register($hookName, array(&$this, 'callback'));
00031 }
00032 }
00033 return $success;
00034 }
00035
00040 function getBlockContext() {
00041 $journal =& Request::getJournal();
00042 $journalId = ($journal?$journal->getJournalId():0);
00043 return $this->getSetting($journalId, 'context');
00044 }
00045
00050 function setBlockContext($context) {
00051 $journal =& Request::getJournal();
00052 $journalId = ($journal?$journal->getJournalId():0);
00053 return $this->updateSetting($journalId, 'context', $context, 'int');
00054 }
00055
00060 function getSupportedContexts() {
00061 fatalError('ABSTRACT METHOD');
00062 }
00063
00068 function getEnabled() {
00069 $journal =& Request::getJournal();
00070 $journalId = ($journal?$journal->getJournalId():0);
00071 return $this->getSetting($journalId, 'enabled');
00072 }
00073
00078 function setEnabled($enabled) {
00079 $journal =& Request::getJournal();
00080 $journalId = ($journal?$journal->getJournalId():0);
00081 return $this->updateSetting($journalId, 'enabled', $enabled, 'bool');
00082 }
00083
00089 function getSeq() {
00090 $journal =& Request::getJournal();
00091 $journalId = ($journal?$journal->getJournalId():0);
00092 return $this->getSetting($journalId, 'seq');
00093 }
00094
00100 function setSeq($i) {
00101 $journal =& Request::getJournal();
00102 $journalId = ($journal?$journal->getJournalId():0);
00103 return $this->updateSetting($journalId, 'seq', $i, 'int');
00104 }
00105
00110 function &getContextMap() {
00111 static $contextMap = array(
00112 BLOCK_CONTEXT_LEFT_SIDEBAR => 'Templates::Common::LeftSidebar',
00113 BLOCK_CONTEXT_RIGHT_SIDEBAR => 'Templates::Common::RightSidebar',
00114 BLOCK_CONTEXT_HOMEPAGE => 'Templates::Index::journal'
00115 );
00116 HookRegistry::call('BlockPlugin::getContextMap', array(&$this, &$contextMap));
00117 return $contextMap;
00118 }
00119
00125 function getName() {
00126
00127 return 'BlockPlugin';
00128 }
00129
00134 function getDisplayName() {
00135
00136
00137 return 'Abstract Block Plugin';
00138 }
00139
00143 function getDescription() {
00144 return 'This is the BlockPlugin base class. Its functions can be overridden by subclasses to provide support for UI blocks.';
00145 }
00146
00154 function getBlockTemplateFilename() {
00155 return 'block.tpl';
00156 }
00157
00163 function getContents(&$templateMgr) {
00164 $blockTemplateFilename = $this->getBlockTemplateFilename();
00165 if ($blockTemplateFilename === null) return '';
00166 return $templateMgr->fetch($this->getTemplatePath() . '/' . $blockTemplateFilename);
00167 }
00168
00169 function callback($hookName, &$args) {
00170 $params =& $args[0];
00171 $smarty =& $args[1];
00172 $output =& $args[2];
00173 $output .= $this->getContents($smarty);
00174 }
00175 }
00176
00177 ?>