1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322:
<?php
class LinksMenu extends LinksMenuElement
{
const LINKS_MENU__CLASS = 'LinksMenu';
const AUTOMATIC_MENU = 'automatic';
const VERTICAL_MENU = 'vertical';
const HORIZONTAL_MENU = 'horizontal';
const STATIC_MENU = 'static';
const VERTICAL_SCROLLING_MENU = 'vertical_scrolling';
const HORIZONTAL_SCROLLING_MENU = 'horizontal_scrolling';
public $type;
public $elements = array();
public function __construct($title, $url, $image = '', $type = self::AUTOMATIC_MENU)
{
$this->type = $this->type == self::HORIZONTAL_SCROLLING_MENU ? self::HORIZONTAL_MENU : $this->type;
$this->type = $this->type == self::VERTICAL_SCROLLING_MENU ? self::VERTICAL_MENU : $this->type;
$this->type = in_array($type, self::get_menu_types_list()) ? $type : self::AUTOMATIC_MENU;
parent::__construct($title, $url, $image);
}
public function add_array($menu_elements)
{
foreach ($menu_elements as $element)
{
$this->add($element);
}
}
public function add($element)
{
if ($element instanceof _CLASS_)
{
$element->_parent($this->type);
}
else
{
$element->_parent($this->type);
}
$this->elements[] = $element;
}
public function update_uid()
{
parent::update_uid();
foreach ($this->elements as $element)
{
$element->update_uid();
}
}
public function display($template = false, $mode = LinksMenuElement::LINKS_MENU_ELEMENT__CLASSIC_DISPLAYING)
{
$filters = $this->get_filters();
$is_displayed = empty($filters) || $filters[0]->get_pattern() == '/' || $mode != LinksMenuElement::LINKS_MENU_ELEMENT__CLASSIC_DISPLAYING;
foreach ($filters as $key => $filter)
{
if ($filter->get_pattern() != '/' && $filter->match())
{
$is_displayed = true;
break;
}
}
if ($is_displayed && $this->check_auth())
{
if (!is_object($template) || !($template instanceof Template))
{
$tpl = new FileTemplate('framework/menus/links.tpl');
}
else
{
$tpl = $template;
}
$original_tpl = clone $tpl;
$menu_with_submenu = false;
$elements_number = 0;
foreach ($this->elements as $element)
{
if ($element->check_auth())
{
$tpl->assign_block_vars('elements', array('DISPLAY' => $element->display(clone $original_tpl, $mode)));
$elements_number++;
}
if (get_class($element) == self::LINKS_MENU__CLASS)
{
$menu_with_submenu = true;
}
}
parent::_assign($tpl, $mode);
$tpl->put_all(array(
'C_MENU' => true,
'C_MENU_WITH_SUBMENU' => $menu_with_submenu,
'C_NEXT_MENU' => $this->depth > 0,
'C_FIRST_MENU' => $this->depth == 0,
'C_HAS_CHILD' => $elements_number,
'C_HIDDEN_WITH_SMALL_SCREENS' => $this->hidden_with_small_screens,
'DEPTH' => $this->depth
));
if ($this->type == self::AUTOMATIC_MENU)
{
$tpl->put_all(array(
'C_MENU_CONTAINER' => in_array($this->get_block(), array(Menu::BLOCK_POSITION__LEFT, Menu::BLOCK_POSITION__RIGHT)),
'C_MENU_HORIZONTAL' => in_array($this->get_block(), array(Menu::BLOCK_POSITION__HEADER, Menu::BLOCK_POSITION__SUB_HEADER, Menu::BLOCK_POSITION__TOP_CENTRAL, Menu::BLOCK_POSITION__BOTTOM_CENTRAL)),
'C_MENU_VERTICAL' => in_array($this->get_block(), array(Menu::BLOCK_POSITION__LEFT, Menu::BLOCK_POSITION__RIGHT)),
'C_MENU_STATIC' => in_array($this->get_block(), array(Menu::BLOCK_POSITION__TOP_FOOTER, Menu::BLOCK_POSITION__FOOTER)),
'C_MENU_LEFT' => $this->get_block() == Menu::BLOCK_POSITION__LEFT,
'C_MENU_RIGHT' => $this->get_block() == Menu::BLOCK_POSITION__RIGHT
));
}
else
{
$tpl->put_all(array(
'C_MENU_CONTAINER' => in_array($this->get_block(), array(Menu::BLOCK_POSITION__LEFT, Menu::BLOCK_POSITION__RIGHT)),
'C_MENU_HORIZONTAL' => $this->type == self::HORIZONTAL_MENU,
'C_MENU_VERTICAL' => $this->type == self::VERTICAL_MENU,
'C_MENU_STATIC' => $this->type == self::STATIC_MENU,
'C_MENU_LEFT' => $this->get_block() == Menu::BLOCK_POSITION__LEFT,
'C_MENU_RIGHT' => $this->get_block() == Menu::BLOCK_POSITION__RIGHT
));
}
return $tpl->render();
}
return '';
}
public function cache_export($template = false)
{
if (!is_object($template) || !($template instanceof Template))
{
$tpl = new FileTemplate('framework/menus/links/links.tpl');
}
else
{
$tpl = clone $template;
}
$original_tpl = clone $tpl;
$menu_with_submenu = false;
$elements_number = 0;
foreach ($this->elements as $element)
{
$tpl->assign_block_vars('elements', array('DISPLAY' => $element->cache_export(clone $original_tpl)));
$elements_number++;
if (get_class($element) == self::LINKS_MENU__CLASS)
{
$menu_with_submenu = true;
}
}
parent::_assign($tpl, LinksMenuElement::LINKS_MENU_ELEMENT__CLASSIC_DISPLAYING);
$tpl->put_all(array(
'C_MENU' => true,
'C_MENU_WITH_SUBMENU' => $menu_with_submenu,
'C_NEXT_MENU' => $this->depth > 0,
'C_FIRST_MENU' => $this->depth == 0,
'C_HAS_CHILD' => $elements_number,
'C_HIDDEN_WITH_SMALL_SCREENS' => $this->hidden_with_small_screens,
'DEPTH' => $this->depth,
'ID' => '##.#GET_UID#.##',
'ID_VAR' => '##.#GET_UID_VAR#.##'
));
if ($this->type == self::AUTOMATIC_MENU)
{
$tpl->put_all(array(
'C_MENU_CONTAINER' => in_array($this->get_block(), array(Menu::BLOCK_POSITION__LEFT, Menu::BLOCK_POSITION__RIGHT)),
'C_MENU_HORIZONTAL' => in_array($this->get_block(), array(Menu::BLOCK_POSITION__HEADER, Menu::BLOCK_POSITION__SUB_HEADER, Menu::BLOCK_POSITION__TOP_CENTRAL, Menu::BLOCK_POSITION__BOTTOM_CENTRAL)),
'C_MENU_VERTICAL' => in_array($this->get_block(), array(Menu::BLOCK_POSITION__LEFT, Menu::BLOCK_POSITION__RIGHT)),
'C_MENU_STATIC' => in_array($this->get_block(), array(Menu::BLOCK_POSITION__TOP_FOOTER, Menu::BLOCK_POSITION__FOOTER)),
'C_MENU_LEFT' => $this->get_block() == Menu::BLOCK_POSITION__LEFT,
'C_MENU_RIGHT' => $this->get_block() == Menu::BLOCK_POSITION__RIGHT
));
}
else
{
$tpl->put_all(array(
'C_MENU_CONTAINER' => in_array($this->get_block(), array(Menu::BLOCK_POSITION__LEFT, Menu::BLOCK_POSITION__RIGHT)),
'C_MENU_HORIZONTAL' => $this->type == self::HORIZONTAL_MENU,
'C_MENU_VERTICAL' => $this->type == self::VERTICAL_MENU,
'C_MENU_STATIC' => $this->type == self::STATIC_MENU,
'C_MENU_LEFT' => $this->get_block() == Menu::BLOCK_POSITION__LEFT,
'C_MENU_RIGHT' => $this->get_block() == Menu::BLOCK_POSITION__RIGHT
));
}
if ($this->depth == 0)
{
$cache_str = parent::cache_export_begin() . '\'.' .
var_export($tpl->render(), true) .
'.\'' . parent::cache_export_end();
$cache_str = str_replace(
array('#GET_UID#', '#GET_UID_VAR#', '##'),
array('($__uid = AppContext::get_uid())', '$__uid', '\''),
$cache_str
);
return $cache_str;
}
return parent::cache_export_begin() . $tpl->render() . parent::cache_export_end();
}
public static function get_menu_types_list()
{
return array(self::AUTOMATIC_MENU, self::VERTICAL_MENU, self::HORIZONTAL_MENU, self::STATIC_MENU);
}
protected function _parent($type)
{
parent::_parent($type);
$this->type = $type;
foreach ($this->elements as $element)
{
$element->_parent($type);
}
}
public function get_type() { return $this->type; }
public function set_type($type) { $this->type = $type; }
public function get_children() { return $this->elements; }
}
?>