aliroMenuCreator.php

Go to the documentation of this file.
00001 <?php
00002 
00003 /*******************************************************************************
00004  * Aliro - the modern, accessible content management system
00005  *
00006  * Aliro is open source software, free to use, and licensed under GPL.
00007  * You can find the full licence at http://www.gnu.org/copyleft/gpl.html GNU/GPL
00008  *
00009  * The author freely draws attention to the fact that Aliro derives from Mambo,
00010  * software that is controlled by the Mambo Foundation.  However, this section
00011  * of code is totally new.  If it should contain any fragments that are similar
00012  * to Mambo, please bear in mind (1) there are only so many ways to do things
00013  * and (2) the author of Aliro is also the author and copyright owner for large
00014  * parts of Mambo 4.6.
00015  *
00016  * Tribute should be paid to all the developers who took Mambo to the stage
00017  * it had reached at the time Aliro was created.  It is a feature rich system
00018  * that contains a good deal of innovation.
00019  *
00020  * Your attention is also drawn to the fact that Aliro relies on other items of
00021  * open source software, which is very much in the spirit of open source.  Aliro
00022  * wishes to give credit to those items of code.  Please refer to
00023  * http://aliro.org/credits for details.  The credits are not included within
00024  * the Aliro package simply to avoid providing a marker that allows hackers to
00025  * identify the system.
00026  *
00027  * Copyright in this code is strictly reserved by its author, Martin Brampton.
00028  * If it seems appropriate, the copyright will be vested in the Aliro Organisation
00029  * at a suitable time.
00030  *
00031  * Copyright (c) 2007 Martin Brampton
00032  *
00033  * http://aliro.org
00034  *
00035  * counterpoint@aliro.org
00036  *
00037  * aliroMenuCreator is a singleton class that handles the logic of menu creation.
00038  * It complements the aliroMenuHandler (cached singleton) class which knows about
00039  * all the menu entries for the system.  It is used by menu modules in conjunction
00040  * with the aliroMenuHandler to obtain the raw material for building a menu.  The
00041  * aim is to provide all the logic for menus in the Aliro core, while leaving the
00042  * construction of XHTML (and maybe CSS) to add-on modules.
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         // Null function - private to enforce singleton
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         // Active Menu highlighting
00077         $newlink->active = ($this->currlink == $mitem->link);
00078     $newlink->subactive = $subactive;
00079         // Set menu link class
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                 // Default images
00104                 $img[$i] = array("$base/images/M_images/indent$i.png", "Indent $i");
00105                 break;
00106 
00107                 case '2':
00108                 // Use Params
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                 // None
00114                 $img[$i] = array(NULL,NULL);
00115                 break;
00116 
00117                 default:
00118                 // Template
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 }

Generated on Wed May 14 13:01:56 2008 for ALIRO by  doxygen 1.5.5