<?php
class Menu{
private $module;
private $mod;
private $xml;
private $headmenu;
protected $href;
protected $title;
protected $link;
protected $values;
protected $to;
protected $chref;
public function link_to($href, $title, $values = 0){
$this->href = $href;
$this->title = $title;
$this->values = $values;
if (isset($_SERVER['HTTP_MOD_REWRITE']) && $_SERVER['HTTP_MOD_REWRITE'] == 'On' && SEO_URL == 'yes') {
$this->href = preg_replace("/^index\.php\?controller=([^\/]*)&action=([^\/]*)&v1=([^\/]*)&v2=([^\/]*)&v3=([^\/]*)$/", "$1/$2/$3/$4/$5.html", $this->href);
$this->href = preg_replace("/^index\.php\?controller=([^\/]*)&action=([^\/]*)&v1=([^\/]*)&v2=([^\/]*)$/", "$1/$2/$3/$4.html", $this->href); $this->href = preg_replace("/^index\.php\?controller=([^\/]*)&action=([^\/]*)&v1=([^\/]*)$/", "$1/$2/$3.html", $this->href); $this->href = preg_replace("/^index\.php\?controller=([^\/]*)&action=([^\/]*)$/", "$1/$2.html", $this->href);
$this->href = preg_replace("/^main\/index\.html$/", "index.html", $this->href);
$this->link = "<a ".$this->values." href='".ROOT_URL.$this->href."'>".$this->title."</a>";
return $this->link;
} else {
$this->href = preg_replace("/^index\.php\?controller=main&action=index$/", "index.php", $this->href);
$this->link = "<a ".$this->values." href='".ROOT_URL.$this->href."'>".$this->title."</a>";
return $this->link;
}
}
public function url_to($to){
$this->to = $to;
if (isset($_SERVER['HTTP_MOD_REWRITE']) && $_SERVER['HTTP_MOD_REWRITE'] == 'On' && SEO_URL == 'yes') {
$this->to = preg_replace("/^index\.php\?controller=([^\/]*)&action=([^\/]*)&v1=([^\/]*)&v2=([^\/]*)&v3=([^\/]*)$/", "$1/$2/$3/$4/$5.html", $this->to);
$this->to = preg_replace("/^index\.php\?controller=([^\/]*)&action=([^\/]*)&v1=([^\/]*)&v2=([^\/]*)$/", "$1/$2/$3/$4.html", $this->to); $this->to = preg_replace("/^index\.php\?controller=([^\/]*)&action=([^\/]*)&v1=([^\/]*)$/", "$1/$2/$3.html", $this->to); $this->to = preg_replace("/^index\.php\?controller=([^\/]*)&action=([^\/]*)$/", "$1/$2.html", $this->to);
$this->to = preg_replace("/index.php/","index.html",$this->to);
$this->to = ROOT_URL.$this->to;
return $this->to;
} else {
return $this->to;
}
}
public function headMenu(){
$m = MODULES;
$this->module = explode(',', $m);
foreach($this->module as $this->mod){
$this->mod = trim($this->mod);
$this->xml = simplexml_load_file(ROOT_DIR."modules/".$this->mod."/".$this->mod.".xml") or die("".$this->mod.".xml not exists!");
foreach($this->xml->module as $this->mod){
if($this->mod->menu == "headmenu"){
if($this->mod->enabled == "yes"){
if($this->mod->frontend == "yes" && $this->mod->backend == "yes"){
$this->headmenu .= $this->link_to("index.php?controller=".$this->mod->controllerinmenu."&action=".$this->mod->actioninmenu."", $this->mod->titleinmenu);
}
if(isset($_SESSION["admin"]) && $this->mod->frontend == "no"){
$this->headmenu .= $this->link_to("index.php?controller=".$this->mod->controllerinmenu."&action=".$this->mod->actioninmenu."", $this->mod->titleinmenu);
}
if(isset($_SESSION["admin"]) && $this->mod->frontend == "yes" && $this->mod->backend == "no"){
$this->headmenu .= "";
}
if(!isset($_SESSION["admin"]) && $this->mod->frontend == "yes" && $this->mod->backend == "no"){
$this->headmenu .= $this->link_to("index.php?controller=".$this->mod->controllerinmenu."&action=".$this->mod->actioninmenu."", $this->mod->titleinmenu);
}
}
}
}
}
return $this->headmenu;
}
}
?>