312 lines
7.7 KiB
PHP
312 lines
7.7 KiB
PHP
<?php
|
|
|
|
/** Menu
|
|
*
|
|
* @version 2.1.0
|
|
* @since 2007-05-01
|
|
* @author martin lenzelbauer
|
|
*
|
|
* @change 2007-05-15
|
|
* fixed PHP4 bug in printMenu()
|
|
*
|
|
* @change 2008-09-23
|
|
* updated loading & publishing routines to keep memory low in PHP5
|
|
*/
|
|
class Menu extends Page{
|
|
|
|
var $startPage; //flexicon id of the startup page
|
|
var $level; //menu level
|
|
|
|
|
|
/** C'tor
|
|
*/
|
|
//------------------------------------------------
|
|
function Menu($id, $parent){
|
|
//------------------------------------------------
|
|
parent::Page($id, $parent);
|
|
$this->name = "[unbenanntes Menü]";
|
|
$this->buttonPublish = true;
|
|
$this->allowedChildObjects = array("stdpage", "stdpagecopy", "phppage", "menu", "separator", "menulink", "eventlist", "personlist", "presslist", "searchpage");
|
|
$this->startPage = 0;
|
|
$this->level = 1;
|
|
$this->editable = USER_ADMIN;
|
|
|
|
if(strtolower(get_class($this->parentObj)) == "menu" && $this->parentObj != null){
|
|
$this->level = $this->parentObj->getLevel() + 1;
|
|
}
|
|
}
|
|
|
|
|
|
/** @see CmsObject::load()
|
|
*/
|
|
//-----------------------------------------------
|
|
function load($path=array()){
|
|
//-----------------------------------------------
|
|
parent::load($path);
|
|
if(!$this->classId){
|
|
return;
|
|
}
|
|
$query = sprintf("SELECT * FROM bruckm_menu WHERE id = %d", $this->classId);
|
|
$result = dbQuery($query);
|
|
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
|
$this->startPage = $line['startPage'];
|
|
$this->level = $line['level'];
|
|
}
|
|
|
|
|
|
/** @see Page::doSave()
|
|
*/
|
|
//----------------------------------------------
|
|
function doSave(){
|
|
//----------------------------------------------
|
|
$query = sprintf("UPDATE bruckm_menu SET startPage = %d, level = %d WHERE id = %d",
|
|
sqlnum($this->startPage),
|
|
sqlnum($this->level),
|
|
sqlnum($this->classId));
|
|
dbQuery($query);
|
|
parent::doSave();
|
|
}
|
|
|
|
|
|
/** @see Page::doCreate()
|
|
*/
|
|
//----------------------------------------------
|
|
function doCreate(){
|
|
//----------------------------------------------
|
|
$query = sprintf("INSERT INTO bruckm_menu (startPage, level) VALUES (%d, %d)",
|
|
sqlnum($this->startPage),
|
|
sqlnum($this->level));
|
|
dbQuery($query);
|
|
$this->classId = mysql_insert_id();
|
|
parent::doCreate();
|
|
}
|
|
|
|
|
|
/** @see Page::doDelete()
|
|
*/
|
|
//-----------------------------------------------
|
|
function doDelete(){
|
|
//-----------------------------------------------
|
|
parent::doDelete();
|
|
$query = sprintf("DELETE FROM bruckm_menu WHERE id = %d LIMIT 1", $this->classId);
|
|
dbQuery($query);
|
|
}
|
|
|
|
|
|
/** @see Page::install()
|
|
*/
|
|
//-----------------------------------------------
|
|
function install(){
|
|
//-----------------------------------------------
|
|
$query = sprintf("CREATE TABLE IF NOT EXISTS bruckm_menu (
|
|
id INT UNSIGNED not null AUTO_INCREMENT,
|
|
startPage INT UNSIGNED not null,
|
|
level TINYINT not null,
|
|
PRIMARY KEY (id)
|
|
)");
|
|
dbQuery($query);
|
|
}
|
|
|
|
|
|
/** @see CmsObject::update()
|
|
*/
|
|
//-----------------------------------------------
|
|
function update(){
|
|
//-----------------------------------------------
|
|
parent::update();
|
|
$this->startPage = $_POST['startPage'];
|
|
}
|
|
|
|
|
|
/** @see CmsObject::doPrintClassContent()
|
|
*/
|
|
//-----------------------------------------------
|
|
function doPrintClassContent(){
|
|
//-----------------------------------------------
|
|
$t = new Template(CMS_TEMPLATE_DIR."menu.html");
|
|
$out = "";
|
|
for($i = 0; $i < sizeof($this->childObjects); $i++){
|
|
$child = $this->childObjects[$i];
|
|
if($child->getId() == $this->startPage){
|
|
$out .= '<option value="'.$child->getId().'" selected="selected">';
|
|
}
|
|
else{
|
|
$out .= '<option value="'.$child->getId().'">';
|
|
}
|
|
$out .= $child->toString() . '</option>';
|
|
}
|
|
$t->setVar("STARTPAGE", $out);
|
|
return $t->toString();
|
|
}
|
|
|
|
|
|
/** @see CmsObject::doPublish()
|
|
*/
|
|
//----------------------------------------------
|
|
function doPublish(){
|
|
//----------------------------------------------
|
|
for($i = 0; $i < sizeof($this->childObjects); $i++) {
|
|
$child = $this->childObjects[$i];
|
|
$load = !$child->isLoaded();
|
|
if($load){
|
|
$child->load();
|
|
}
|
|
$child->publish();
|
|
if($load){
|
|
$child->unload();
|
|
}
|
|
#println(memory_get_usage() . " [" . $child->getName() . " :: " . get_class($child) . "]");
|
|
}
|
|
}
|
|
|
|
|
|
/** @see CmsObject::canBePublished()
|
|
*/
|
|
//---------------------------------------------
|
|
function canBePublished(){
|
|
//---------------------------------------------
|
|
if(sizeof($this->childObjects) == 0){
|
|
$this->addError("Das Menü muss mindestens eine Seite beinhalten!");
|
|
return false;
|
|
}
|
|
$ok = true;
|
|
for($i = 0; $i < sizeof($this->childObjects); $i++) {
|
|
$child = $this->childObjects[$i];
|
|
$load = !$child->isLoaded();
|
|
if($load){
|
|
$child->load();
|
|
}
|
|
if(!$child->canBePublished()){
|
|
if($ok){
|
|
$ok = false;
|
|
$this->addError("Ein oder mehere Seiten können nicht veröffentlicht werden!");
|
|
}
|
|
$this->addError($child->getErrors());
|
|
}
|
|
if($load){
|
|
$child->unload();
|
|
}
|
|
}
|
|
return $ok;
|
|
}
|
|
|
|
|
|
/** @see Element::getCssClass()
|
|
*/
|
|
//------------------------------------------------
|
|
function getCssClass(){
|
|
//------------------------------------------------
|
|
return "itemMenu";
|
|
}
|
|
|
|
|
|
// === ADDITIONAL METHODS ================================================================ //
|
|
|
|
|
|
/** returns the level
|
|
*/
|
|
function getLevel(){
|
|
return $this->level;
|
|
}
|
|
|
|
|
|
/** prints the menu (called by child element)
|
|
* @param t template to print the menu in (variables "MENUTITLE" and "SUBMENU")
|
|
* @return template
|
|
*/
|
|
//------------------------------------------------
|
|
function printMenu($t){
|
|
//------------------------------------------------
|
|
//this is not a top level menu -> dispatch to parent
|
|
if($this->level > 1){
|
|
$parent = $this->parentObj;
|
|
if(!$parent || $parent->getId() != $this->parentId){
|
|
$parent = FlexiconFactory::instanceById($this->parentId);
|
|
}
|
|
if(!$parent->isLoaded()){
|
|
$parent->load();
|
|
}
|
|
return $parent->printMenu($t);
|
|
}
|
|
|
|
//print menu items
|
|
$t->setVar("MENUTITLE", htmlspecialchars($this->name));
|
|
$items = "";
|
|
for($i = 0; $i < sizeof($this->childObjects); $i++) {
|
|
$child = $this->childObjects[$i];
|
|
$load = !$child->isLoaded();
|
|
if($load){
|
|
$child->load();
|
|
}
|
|
if($child->isVisible()){
|
|
$items .= $child->printAsMenuItem();
|
|
}
|
|
if($load){
|
|
$child->unload();
|
|
}
|
|
}
|
|
$items .= "";
|
|
$t->setVar("SUBMENU", $items);
|
|
if(!$this->parentObj){
|
|
$this->parentObj = FlexiconFactory::instanceById($this->parentId);
|
|
}
|
|
if(!$this->parentObj->isLoaded()){
|
|
$this->parentObj->load();
|
|
}
|
|
|
|
if ($this->level > 1 || $this->parentObj instanceof Website) {
|
|
$t = $this->parentObj->printMenu($t);
|
|
}
|
|
else {
|
|
$website = FlexiconFactory::instanceById($this->parentId);
|
|
$website->load();
|
|
$t = $website->printMenu($t);
|
|
}
|
|
|
|
return $t;
|
|
}
|
|
|
|
|
|
/** prints submenu
|
|
* @return string
|
|
*/
|
|
//----------------------------------------------
|
|
function printAsMenuItem(){
|
|
//----------------------------------------------
|
|
$out = "<li>";
|
|
$out .= "<a href=\"?id=".$this->startPage."\" target=\"_self\">".htmlspecialchars($this->name)."</a>";
|
|
$out .= "<ul>";
|
|
for($i = 0; $i < sizeof($this->childObjects); $i++) {
|
|
$child = $this->childObjects[$i];
|
|
$load = !$child->isLoaded();
|
|
if($load){
|
|
$child->load();
|
|
}
|
|
if($child->isVisible()){
|
|
$out .= $child->printAsMenuItem();
|
|
}
|
|
if($load){
|
|
$child->unload();
|
|
}
|
|
}
|
|
$out .= "</ul>";
|
|
$out .= "</li>";
|
|
return $out;
|
|
}
|
|
|
|
|
|
/** returns the flexicon id of the start page
|
|
* @return id
|
|
*/
|
|
//-----------------------------------------------
|
|
function getStartPage(){
|
|
//-----------------------------------------------
|
|
return $this->startPage;
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
?>
|