- Timestamp:
- Dec 1, 2013, 4:03:38 PM (10 years ago)
- Location:
- trunk/include
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/block.class.php
r19703 r25762 20 20 // +-----------------------------------------------------------------------+ 21 21 22 /** 23 * @package functions\menubar 24 */ 25 26 27 /** 28 * Manages a set of RegisteredBlock and DisplayBlock. 29 */ 22 30 class BlockManager 23 31 { 32 /** @var string */ 24 33 protected $id; 25 protected $registered_blocks=array(); 34 /** @var RegisteredBlock[] */ 35 protected $registered_blocks = array(); 36 /** @var DisplayBlock[] */ 26 37 protected $display_blocks = array(); 27 38 28 public function BlockManager($id) 39 /** 40 * @param string $id 41 */ 42 public function __construct($id) 29 43 { 30 44 $this->id = $id; 31 45 } 32 46 33 /** triggers an action that allows implementors of menu blocks to register the blocks*/ 47 /** 48 * Triggers a notice that allows plugins of menu blocks to register the blocks. 49 */ 34 50 public function load_registered_blocks() 35 51 { 36 trigger_action('blockmanager_register_blocks', array(&$this) ); 37 } 38 52 trigger_action('blockmanager_register_blocks', array(&$this)); 53 } 54 55 /** 56 * @return string 57 */ 39 58 public function get_id() 40 59 { … … 42 61 } 43 62 63 /** 64 * @return RegisteredBlock[] 65 */ 44 66 public function get_registered_blocks() 45 67 { … … 47 69 } 48 70 49 /** registers a block with this menu. usually called as a result of menubar_register_blocks action 50 * @param MenuBlock block 51 */ 71 /** 72 * Add a block with the menu. Usually called in 'blockmanager_register_blocks' event. 73 * 74 * @param RegisteredBlock &$block 75 */ 52 76 public function register_block(&$block) 53 77 { 54 if ( isset($this->registered_blocks[$block->get_id()] ))78 if (isset($this->registered_blocks[$block->get_id()])) 55 79 { 56 80 trigger_error("Block '".$block->get_id()."' is already registered", E_USER_WARNING); … … 61 85 } 62 86 63 /** performs one time preparation of registered blocks for display; 64 * triggers the action menubar_prepare_display where implementors can 87 /** 88 * Performs one time preparation of registered blocks for display. 89 * Triggers 'blockmanager_prepare_display' event where plugins can 65 90 * reposition or hide blocks 66 */91 */ 67 92 public function prepare_display() 68 93 { … … 70 95 $conf_id = 'blk_'.$this->id; 71 96 $mb_conf = isset($conf[$conf_id]) ? $conf[$conf_id] : array(); 72 if ( !is_array($mb_conf) ) 97 if (!is_array($mb_conf)) 98 { 73 99 $mb_conf = @unserialize($mb_conf); 100 } 74 101 75 102 $idx = 1; 76 foreach ( $this->registered_blocks as $id => $block)77 { 78 $pos = isset( $mb_conf[$id]) ? $mb_conf[$id] : $idx*50;79 if ( $pos>0)103 foreach ($this->registered_blocks as $id => $block) 104 { 105 $pos = isset($mb_conf[$id]) ? $mb_conf[$id] : $idx*50; 106 if ($pos>0) 80 107 { 81 108 $this->display_blocks[$id] = new DisplayBlock($block); … … 85 112 } 86 113 $this->sort_blocks(); 87 trigger_action( 'blockmanager_prepare_display', array(&$this));114 trigger_action('blockmanager_prepare_display', array(&$this)); 88 115 $this->sort_blocks(); 89 116 } 90 117 91 /** returns true if the block whose id is hidden 92 * @param string block_id 93 */ 118 /** 119 * Returns true if the block is hidden. 120 * 121 * @param string $block_id 122 * @return bool 123 */ 94 124 public function is_hidden($block_id) 95 125 { 96 return isset($this->display_blocks[$block_id]) ? false : true; 97 } 98 126 return !isset($this->display_blocks[$block_id]); 127 } 128 129 /** 130 * Remove a block from the displayed blocks. 131 * 132 * @param string $block_id 133 */ 99 134 public function hide_block($block_id) 100 135 { 101 unset( $this->display_blocks[$block_id] ); 102 } 103 136 unset($this->display_blocks[$block_id]); 137 } 138 139 /** 140 * Returns a visible block. 141 * 142 * @param string $block_id 143 * @return &DisplayBlock|null 144 */ 104 145 public function &get_block($block_id) 105 146 { 106 147 $tmp = null; 107 if ( isset($this->display_blocks[$block_id]))148 if (isset($this->display_blocks[$block_id])) 108 149 { 109 150 return $this->display_blocks[$block_id]; … … 112 153 } 113 154 155 /** 156 * Changes the position of a block. 157 * 158 * @param string $block_id 159 * @param int $position 160 */ 114 161 public function set_block_position($block_id, $position) 115 162 { 116 if ( isset($this->display_blocks[$block_id]))163 if (isset($this->display_blocks[$block_id])) 117 164 { 118 165 $this->display_blocks[$block_id]->set_position($position); … … 120 167 } 121 168 169 /** 170 * Sorts the blocks. 171 */ 122 172 protected function sort_blocks() 123 173 { 124 uasort( $this->display_blocks, array('BlockManager', 'cmp_by_position') ); 125 } 126 174 uasort($this->display_blocks, array('BlockManager', 'cmp_by_position')); 175 } 176 177 /** 178 * Callback for blocks sorting. 179 */ 127 180 static protected function cmp_by_position($a, $b) 128 181 { … … 130 183 } 131 184 185 /** 186 * Parse the menu and assign the result in a template variable. 187 * 188 * @param string $var 189 * @param string $file 190 */ 132 191 public function apply($var, $file) 133 192 { … … 137 196 trigger_action('blockmanager_apply', array(&$this) ); 138 197 139 foreach ($this->display_blocks as $id=>$block)140 { 141 if (empty($block->raw_content) and empty($block->template) 198 foreach ($this->display_blocks as $id=>$block) 199 { 200 if (empty($block->raw_content) and empty($block->template)) 142 201 { 143 202 $this->hide_block($id); … … 150 209 } 151 210 211 152 212 /** 153 * Represents a menu block registered in a Menuobject.213 * Represents a menu block registered in a BlockManager object. 154 214 */ 155 215 class RegisteredBlock 156 216 { 217 /** @var string */ 157 218 protected $id; 219 /** @var string */ 158 220 protected $name; 221 /** @var string */ 159 222 protected $owner; 160 223 161 public function RegisteredBlock($id, $name, $owner) 224 /** 225 * @param string $id 226 * @param string $name 227 * @param string $owner 228 */ 229 public function __construct($id, $name, $owner) 162 230 { 163 231 $this->id = $id; … … 166 234 } 167 235 168 public function get_id() { return $this->id; } 169 public function get_name() { return $this->name; } 170 public function get_owner() { return $this->owner; } 236 /** 237 * @return string 238 */ 239 public function get_id() 240 { 241 return $this->id; 242 } 243 244 /** 245 * @return string 246 */ 247 public function get_name() 248 { 249 return $this->name; 250 } 251 252 /** 253 * @return string 254 */ 255 public function get_owner() 256 { 257 return $this->owner; 258 } 171 259 } 172 260 261 173 262 /** 174 * Represents a menu block ready for display in the Menuobject.263 * Represents a menu block ready for display in the BlockManager object. 175 264 */ 176 265 class DisplayBlock 177 266 { 267 /** @var RegisteredBlock */ 178 268 protected $_registeredBlock; 269 /** @var int */ 179 270 protected $_position; 180 271 /** @var string */ 181 272 protected $_title; 182 273 274 /** @var mixed */ 183 275 public $data; 276 /** @var string */ 184 277 public $template; 278 /** @var string */ 185 279 public $raw_content; 186 280 187 public function DisplayBlock($registeredBlock) 188 { 189 $this->_registeredBlock = &$registeredBlock; 190 } 191 192 public function &get_block() { return $this->_registeredBlock; } 193 194 public function get_position() { return $this->_position; } 281 /** 282 * @param RegisteredBlock &$block 283 */ 284 public function __construct($block) 285 { 286 $this->_registeredBlock = &$block; 287 } 288 289 /** 290 * @return &RegisteredBlock 291 */ 292 public function &get_block() 293 { 294 return $this->_registeredBlock; 295 } 296 297 /** 298 * @return int 299 */ 300 public function get_position() 301 { 302 return $this->_position; 303 } 304 305 /** 306 * @param int $position 307 */ 195 308 public function set_position($position) 196 309 { … … 198 311 } 199 312 313 /** 314 * @return string 315 */ 200 316 public function get_title() 201 317 { 202 318 if (isset($this->_title)) 319 { 203 320 return $this->_title; 321 } 204 322 else 323 { 205 324 return $this->_registeredBlock->get_name(); 206 } 207 325 } 326 } 327 328 /** 329 * @param string 330 */ 208 331 public function set_title($title) 209 332 { -
trunk/include/menubar.inc.php
r21817 r25762 23 23 24 24 /** 25 * This file is included by the main page to show the menu bar 26 * 25 * @package functions\menubar 27 26 */ 28 27 … … 31 30 initialize_menu(); 32 31 32 /** 33 * Setups each block the main menubar. 34 */ 33 35 function initialize_menu() 34 36 { … … 330 332 $menu->apply('MENUBAR', 'menubar.tpl' ); 331 333 } 334 332 335 ?>
Note: See TracChangeset
for help on using the changeset viewer.