Files
bm/public_html/public/cms/modules/website.class.php
2025-09-24 13:26:28 +02:00

159 lines
3.5 KiB
PHP

<?php
/** Website
*
* @version 2.1.0
* @since 2007-05-01
* @author martin lenzelbauer
*
*
* @change 2008-09-23
* updated loading & publishing routines to keep memory low in PHP5
*/
class Website extends Page{
/** C'tor
*/
//------------------------------------------------
function Website($line=NULL, $parent){
//------------------------------------------------
parent::Page($line, $parent);
$this->name = "[unbenannte Website]";
$this->buttonPublish = true;
$this->editable = USER_ADMIN;
$this->allowedChildObjects = array("menu", "indexpage");
}
/** @see DBElement::canBeDeleted()
*/
//----------------------------------------------
function canBeDeleted(){
//----------------------------------------------
$this->addError("Die Website darf nicht gelöscht werden!");
return false;
}
/** @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();
}
}
}
/** @see CmsObject::canBePublished()
*/
//---------------------------------------------
function canBePublished(){
//---------------------------------------------
$index = 0;
$menu = 0;
for($i = 0; $i < sizeof($this->childObjects); $i++){
$child = $this->childObjects[$i];
if(strtolower(get_class($child)) == "menu"){
$menu++;
}
else if(strtolower(get_class($child)) == "indexpage"){
$index++;
}
}
if($index != 1){
logError(1, "No index page", __FILE__, __LINE__);
$this->addError("Die Website muss eine Indexseite besitzen!");
return false;
}
/*if($menu != 6){
logError(1, "Wrong menu items count ($menu)", __FILE__, __LINE__);
$this->addError("Die Website muss genau 6 Menüpunkte besitzen!");
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 "itemWebsite";
}
// === ADDITIONAL METHODS =========================================================== //
/** prints the main menu
* @param t template to print the menu in (variable "MENU")
* @return template
*/
//-------------------------------------------
function printMenu($t){
//-------------------------------------------
$menu = "";
$count = 0;
for($i = 0; $i < sizeof($this->childObjects); $i++){
$child = $this->childObjects[$i];
if(strtolower(get_class($child)) == "menu"){
$load = !$child->isLoaded();
if($load){
$child->load();
}
if (!$child->isVisible()) {
continue;
}
$menu .= sprintf(
'<li class="nav-item-%d"><a href="?id=%d">%s</a></li>',
$count + 1,
$child->getStartPage(),
$child->toString()
);
$count++;
if($load){
$child->unload();
}
}
}
$t->setVar("MENU", $menu);
return $t;
}
};
?>