00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 class aliroMenuCreator {
00047 private static $instance = __CLASS__;
00048 private $config = null;
00049 private $handler = null;
00050 private $currlink = '';
00051
00052 private function __construct () {
00053 $this->config = aliroCore::getInstance();
00054 $this->handler = aliroMenuHandler::getInstance();
00055 $itemid = aliroRequest::getInstance()->getItemid();
00056 if ($itemid) {
00057 $currmenu = $this->handler->getMenuByID($itemid);
00058 if ($currmenu) $this->currlink = $currmenu->link;
00059 }
00060 }
00061
00062 private function __clone () {
00063
00064 }
00065
00066 public static function getInstance () {
00067 return is_object(self::$instance) ? self::$instance : (self::$instance = new self::$instance());
00068 }
00069
00070 private function makeMenuLink($mitem, $params, $maxindent, $subactive) {
00071 $newlink = new aliroMenuLink ();
00072 $newlink->id = $mitem->id;
00073 $newlink->name = $mitem->name;
00074 $newlink->level = min($mitem->level,$maxindent);
00075 $newlink->link = aliroSEF::getInstance()->sefRelToAbs($mitem->link);
00076
00077 $newlink->active = ($this->currlink == $mitem->link);
00078 $newlink->subactive = $subactive;
00079
00080 $newlink->opener = $mitem->browserNav;
00081 if ( $params->get('menu_images', 0)) {
00082 $menu_params = new aliroParameters($mitem->params);
00083 $menu_image = $menu_params->def( 'menu_image', -1 );
00084 if ($menu_image AND $menu_image <> '-1') {
00085 $newlink->image = aliroCore::get('mosConfig_live_site').'/images/stories/'.$menu_image;
00086 $newlink->image_last = $params->get('menu_images_align', 0);
00087 }
00088 }
00089 return $newlink;
00090 }
00091
00095 public function getIndents( $params ) {
00096 $base = aliroCore::getInstance()->getCfg('live_site');
00097 $imgpath = $base.'/templates/'. aliroRequest::getInstance()->getTemplate() .'/images';
00098
00099 for ( $i = 1; $i < 7; $i++ ) {
00100 switch ($params->get( 'indent_image', 0 )) {
00101
00102 case '1':
00103
00104 $img[$i] = array("$base/images/M_images/indent$i.png", "Indent $i");
00105 break;
00106
00107 case '2':
00108
00109 $img[$i] = ('-1' == $params->get('indent_image'.$i, 0)) ? array (NULL, NULL) : array("$base/images/M_images/$parm", "Indent $i");
00110 break;
00111
00112 case '3':
00113
00114 $img[$i] = array(NULL,NULL);
00115 break;
00116
00117 default:
00118
00119 $img[$i] = array("$imgpath/indent$i.png", "Indent $i");
00120 break;
00121 }
00122 }
00123 return $img;
00124 }
00125
00129 public function getMenuData ($params, $maxindent) {
00130 $menutype = $params->get('menutype', 'mainmenu');
00131 $rows = $this->handler->getByParentOrder($menutype, true);
00132 $entries = $subactive = array();
00133 if (empty($rows)) return $entries;
00134 foreach ($rows as $i=>$row) $links[$row->id] = $i;
00135 $show = array(0);
00136 foreach ($rows as $row) {
00137 if (!in_array($row->parent, $show)) array_unshift($show, $row->parent);
00138 elseif (!$row->parent == $show[0]) array_shift($show);
00139 if ($this->currlink == $row->link) {
00140 array_push($show, $row->id);
00141 $parent = $row->parent;
00142 while ($parent) {
00143 $subactive[$parent] = 1;
00144 $parent = $rows[$links[$parent]]->parent;
00145 }
00146 break;
00147 }
00148 }
00149 foreach ($rows as $row) if (in_array($row->parent, $show)) {
00150 $entries[] = $this->makeMenuLink($row, $params, $maxindent, isset($subactive[$row->id]));
00151 }
00152 return $entries;
00153 }
00154
00155 }