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) {
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         // Active Menu highlighting
00076         $newlink->active = ($this->currlink == $mitem->link);
00077         // Set menu link class
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                 // Default images
00102                 $img[$i] = array("$base/images/M_images/indent$i.png", "Indent $i");
00103                 break;
00104 
00105                 case '2':
00106                 // Use Params
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                 // None
00112                 $img[$i] = array(NULL,NULL);
00113                 break;
00114 
00115                 default:
00116                 // Template
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 }

Generated on Thu Apr 17 13:03:26 2008 for ALIRO by  doxygen 1.5.5