aliroAdminMenu.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  * Everything here is to do with database management.
00038  *
00039  * aliroInstallXML is the class that handles the XML that defines the packaginf
00040  * of any extension.  It is an extension of aliroCommonInstallXML - the base
00041  * class for both install and uninstall XML handling.
00042  *
00043  * aliroInstaller does the real work of installing extensions
00044  *
00045  */
00046 
00047 class aliroAdminMenu extends aliroDatabaseRow {
00048     protected $DBclass = 'aliroCoreDatabase';
00049     protected $tableName = '#__admin_menu';
00050     protected $rowKey = 'id';
00051 
00052     public function store ($updateNulls=false) {
00053         $ret = parent::store($updateNulls);
00054         aliroAdminMenuHandler::getInstance()->clearCache();
00055         return $ret;
00056     }
00057 }
00058 
00059 class aliroAdminMenuHandler extends cachedSingleton  {
00060     protected static $instance = __CLASS__;
00061 
00062     private $all_entries = array();
00063     private $visible = array();
00064     private $byname = array();
00065     private $basepath = '';
00066     private $links = null;
00067     private $componentBase = 0;
00068 
00069     protected function __construct () {
00070         // Making private enforces singleton
00071         $this->basepath = aliroRequest::getInstance()->getCfg('admin_site').'/';
00072         $database = aliroCoreDatabase::getInstance();
00073         $this->all_entries = $database->doSQLget("SELECT * FROM #__admin_menu", 'aliroAdminMenu');
00074         foreach ($this->all_entries as $key=>&$result) {
00075             $result->link = str_replace('&', '&amp;', str_replace('&amp;', '&', $result->link));
00076             $this->byname[$result->component] = $key;
00077             if ('placeholder' == $result->type AND 'components' == $result->component) $this->componentBase = $result->id;
00078             if (!$result->published) continue;
00079             $mcount = 0;
00080             $this->visible[$result->id] = $result;
00081         }
00082     }
00083 
00084     public static function getInstance () {
00085         return is_object(self::$instance) ? self::$instance : (self::$instance = parent::getCachedSingleton(self::$instance));
00086     }
00087 
00088     public function getByName ($name) {
00089         if (isset($this->byname[$name])) return $this->all_entries[$this->byname[$name]];
00090         else return null;
00091     }
00092 
00093     public function baseComponentMenu () {
00094         return $this->componentBase;
00095     }
00096 
00097     public function createChild ($entry) {
00098         $item = new aliroAdminMenu();
00099         $item->name = $entry->name;
00100         $item->link = $entry->link;
00101         $item->type = $entry->type;
00102         $item->parent = $entry->id;
00103         $item->component = $entry->component;
00104         $item->sublevel = $entry->sublevel + 1;
00105         $item->xmlfile = $entry->xmlfile;
00106         return $item;
00107     }
00108 
00109     public function makeMenu () {
00110         $max = $chosen = 0;
00111         foreach ($this->visible as $result) {
00112             $mcount = 0;
00113             $query = substr($result->link, 10);
00114             $elements = explode ('&', $query);
00115             foreach ($elements as $element) {
00116                 $parts = explode ('=', $element);
00117                 if (isset($_REQUEST[$parts[0]]) AND isset($parts[1]) AND $_REQUEST[$parts[0]] == $parts[1]) $mcount++;
00118             }
00119             if ($mcount > $max) {
00120                 $max = $mcount;
00121                 $chosen = $result->id;
00122             }
00123         }
00124         $numbers = array();
00125         while ($chosen) {
00126             $numbers[] = $chosen;
00127             $chosen = $this->visible[$chosen]->parent;
00128         }
00129         $this->showLevel(0, $numbers, "\n<ul id='nav'>");
00130         $html = '';
00131         if ($this->links) {
00132             foreach ($this->links as $link) $html .= $link;
00133         }
00134         return $html;
00135     }
00136 
00137     private function showLevel ($parent, $numbers, $liststart) {
00138         $authoriser = aliroAuthoriser::getInstance();
00139         $trigger = false;
00140         foreach ($this->visible as $entry) {
00141             if ($entry->parent != $parent) continue;
00142             if (!$authoriser->checkUserPermission('see', 'aliroMenu', $entry->id)) continue;
00143             if (!$trigger) {
00144                 $this->links[] = $liststart;
00145                 $trigger = true;
00146             }
00147             if ('placeholder' == $entry->type) $this->links[] = "\n\t<li>$entry->name";
00148             elseif ('url' == $entry->type) $this->links[] = "\n\t<li><a href='{$entry->link}'>$entry->name</a>";
00149             else $this->links[] = "\n\t<li><a href='{$this->basepath}{$entry->link}'>$entry->name</a>";
00150             $this->showLevel($entry->id, $numbers, "\n<ul>");
00151             $this->links[] = "</li>";
00152         }
00153         if ($trigger) $this->links[] = "\n</ul>";
00154     }
00155 
00156 }

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