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) {
00071 $newlink = new aliroMenuLink ();
00072 $newlink->name = $mitem->name;
00073 $newlink->level = min($mitem->level,$maxindent);
00074 $newlink->link = aliroSEF::getInstance()->sefRelToAbs($mitem->link);
00075
00076 $newlink->active = ($this->currlink == $mitem->link);
00077
00078 $newlink->opener = $mitem->browserNav;
00079 if ( $params->get('menu_images', 0)) {
00080 $menu_params = new aliroParameters($mitem->params);
00081 $menu_image = $menu_params->def( 'menu_image', -1 );
00082 if ($menu_image AND $menu_image <> '-1') {
00083 $newlink->image = aliroCore::get('mosConfig_live_site').'/images/stories/'.$menu_image;
00084 $newlink->image_last = $params->get('menu_images_align', 0);
00085 }
00086 }
00087 return $newlink;
00088 }
00089
00093 public function getIndents( $params ) {
00094 $base = aliroCore::getInstance()->getCfg('live_site');
00095 $imgpath = $base.'/templates/'. aliroRequest::getInstance()->getTemplate() .'/images';
00096
00097 for ( $i = 1; $i < 7; $i++ ) {
00098 switch ($params->get( 'indent_image', 0 )) {
00099
00100 case '1':
00101
00102 $img[$i] = array("$base/images/M_images/indent$i.png", "Indent $i");
00103 break;
00104
00105 case '2':
00106
00107 $img[$i] = ('-1' == $params->get('indent_image'.$i, 0)) ? array (NULL, NULL) : array("$base/images/M_images/$parm", "Indent $i");
00108 break;
00109
00110 case '3':
00111
00112 $img[$i] = array(NULL,NULL);
00113 break;
00114
00115 default:
00116
00117 $img[$i] = array("$imgpath/indent$i.png", "Indent $i");
00118 break;
00119 }
00120 }
00121 return $img;
00122 }
00123
00127 public function getMenuData ($params, $maxindent ) {
00128 $menutype = $params->get('menutype', 'mainmenu');
00129 $rows = $this->handler->getByParentOrder($menutype, true);
00130 $entries = array();
00131 $show = array(0);
00132 foreach ($rows as $row) {
00133 if (!in_array($row->parent, $show)) array_unshift($show, $row->parent);
00134 elseif (!$row->parent == $show[0]) array_shift($show);
00135 if ($this->currlink == $row->link) {
00136 array_push($show, $row->id);
00137 break;
00138 }
00139 }
00140 foreach ($rows as $row) if (in_array($row->parent, $show)) {
00141 $entries[] = $this->makeMenuLink($row, $params, $maxindent);
00142 }
00143 return $entries;
00144 }
00145
00146 }