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
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
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('&', '&', str_replace('&', '&', $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 }