Execute('SELECT * FROM nav ORDER BY id');
while(!$res->EOF) {
$this->entries[$res->fields[0]] = new NavEntry($res->fields[1], $res->fields[2], $res->fields[3], $res->fields[4]);
$res->MoveNext();
}
foreach($this->entries as $key => $entry)
if($entry->parent == 0)
$this->root_entries[$entry->gid][$entry->text] = &$this->entries[$key];
elseif(isset($this->entries[$entry->parent]))
$this->entries[$entry->parent]->Add(&$this->entries[$key]);
}
function ParseNav($name, $gid = NULL) {
if($gid === NULL) $gid = $GLOBALS['user']->getGid();
$ret = '
';
foreach($this->root_entries[$gid][$name]->children as $entry)
$ret .= $entry->Parse();
$ret .= '
';
return $ret;
}
function ParseInsert($name, $data) {
$res = $GLOBALS['db']->Execute('SELECT code FROM nav_inserts WHERE name = ?', $name);
if(!$res->RecordCount()) return ' ';
ob_start();
eval('?>' . $res->fields[0]);
$ret = ob_get_contents();
ob_end_clean();
return $ret;
}
function ParseLink($text, $link) {
if(!$link) return $text;
switch($link[0]) {
case ':':
$ret = $GLOBALS['links']->GetNeonLink(substr($link, 1));
if($ret)
return '' . $text . '';
return $text;
case '@':
return '' . $text . '';
case '-':
return $this->ParseInsert(substr($link, 1), $text);
case '!':
return '' . $text . '';
}
}
}
class NavEntry {
var $parent, $gid, $text, $link;
var $children = array();
function NavEntry($parent, $gid, $text, $link) {
$this->parent = $parent;
$this->gid = $gid;
$this->text = $text;
$this->link = $link;
}
function Add($entry) {
array_push($this->children, &$entry);
}
function Parse() {
$ccount = 0;
if($this->link) $ret = '';
else $ret = '';
$a = $GLOBALS['nav']->ParseLink($this->text, $this->link);
$ret .= $a;
if(count($this->children) > 0) {
$ret .= '';
foreach($this->children as $child) {
$cret = $child->Parse();
if($cret) {
$ret .= $cret;
$ccount++;
}
}
$ret .= '
';
}
if(!$ccount && $a == $this->text)
return '';
return $ret . '';
}
}
$GLOBALS['nav'] = new Nav;
?>