Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
BlockPlugin.inc.php
1 <?php
2 
16 define('BLOCK_CONTEXT_LEFT_SIDEBAR', 0x00000001);
17 define('BLOCK_CONTEXT_RIGHT_SIDEBAR', 0x00000002);
18 define('BLOCK_CONTEXT_HOMEPAGE', 0x00000003);
19 
20 import('lib.pkp.classes.plugins.LazyLoadPlugin');
21 
22 class BlockPlugin extends LazyLoadPlugin {
26  function BlockPlugin() {
27  parent::LazyLoadPlugin();
28  }
29 
30  /*
31  * Override public methods from Plugin
32  */
36  function register($category, $path) {
37  $success = parent::register($category, $path);
38  if ($success && $this->getEnabled()) {
39  $contextMap = $this->getContextMap();
40  $blockContext = $this->getBlockContext();
41  if (isset($contextMap[$blockContext])) {
42  $hookName = $contextMap[$blockContext];
43  HookRegistry::register($hookName, array($this, 'callback'));
44  }
45  }
46  return $success;
47  }
48 
58  function getSeq() {
59  return $this->getContextSpecificSetting($this->getSettingMainContext(), 'seq');
60  }
61 
62  /*
63  * Block Plugin specific methods
64  */
73  function setSeq($seq) {
74  return $this->updateContextSpecificSetting($this->getSettingMainContext(), 'seq', $seq, 'int');
75  }
76 
82  function getBlockContext() {
83  return $this->getContextSpecificSetting($this->getSettingMainContext(), 'context');
84  }
85 
91  function setBlockContext($context) {
92  return $this->updateContextSpecificSetting($this->getSettingMainContext(), 'context', $context, 'int');
93  }
94 
95 
101  function getSupportedContexts() {
102  // Will return left and right process as this is the
103  // most frequent use case.
104  return array(BLOCK_CONTEXT_LEFT_SIDEBAR, BLOCK_CONTEXT_RIGHT_SIDEBAR);
105  }
106 
112  function &getContextMap() {
113  static $contextMap = array(
114  BLOCK_CONTEXT_LEFT_SIDEBAR => 'Templates::Common::LeftSidebar',
115  BLOCK_CONTEXT_RIGHT_SIDEBAR => 'Templates::Common::RightSidebar',
116  );
117 
118  $homepageHook = $this->_getContextSpecificHomepageHook();
119  if ($homepageHook) $contextMap[BLOCK_CONTEXT_HOMEPAGE] = $homepageHook;
120 
121  HookRegistry::call('BlockPlugin::getContextMap', array($this, &$contextMap));
122  return $contextMap;
123  }
124 
134  return 'block.tpl';
135  }
136 
144  function getContents(&$templateMgr, $request = null) {
145  $blockTemplateFilename = $this->getBlockTemplateFilename();
146  if ($blockTemplateFilename === null) return '';
147  return $templateMgr->fetch($this->getTemplatePath() . $blockTemplateFilename);
148  }
149 
157  function callback($hookName, $args) {
158  $params =& $args[0];
159  $smarty =& $args[1];
160  $output =& $args[2];
161  $output .= $this->getContents($smarty, $this->getRequest());
162  return false;
163  }
164 
165  /*
166  * Private helper methods
167  */
174  $application = PKPApplication::getApplication();
175 
176  if ($application->getContextDepth() == 0) return null;
177 
178  $contextList = $application->getContextList();
179  return 'Templates::Index::'.array_shift($contextList);
180  }
181 }
182 ?>
& getRequest()
Definition: Plugin.inc.php:755
setBlockContext($context)
static call($hookName, $args=null)
getSettingMainContext()
Definition: Plugin.inc.php:452
getContextSpecificSetting($context, $name)
Definition: Plugin.inc.php:387
_getContextSpecificHomepageHook()
Abstract class for block plugins.
static register($hookName, $callback)
callback($hookName, $args)
updateContextSpecificSetting($context, $name, $value, $type=null)
Definition: Plugin.inc.php:410
getContents(&$templateMgr, $request=null)
getTemplatePath($inCore=false)
Definition: Plugin.inc.php:333