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

404 lines
12 KiB
PHP

<?php
require_once(ROOT."include/config.inc.php");
require_once(CMS_DIR."modules/_buildingblockfactory.class.php");
/** Standard Page
*
* @version 2.1.0
* @date 2007-05-01
* @author martin lenzelbauer
*
* @change 2007-05-15
* fixed PHP4 bug in doPublish()
*
* @change 2007-12-16
* added file sorting when reading template files
*
* @change 2008-09-23
* updated loading & publishing routines to keep memory low in PHP5
*/
class StdPage extends Page{
var $template; //html template file
var $buildingBlocks; //array of building blocks
/** C'tor
*/
//------------------------------------------------
function StdPage($id, $parent){
//------------------------------------------------
parent::Page($id, $parent);
$this->name = "[unbenannte Seite]";
$this->buttonPublish = true;
$this->buttonPreview = true;
$this->template = "";
$this->buildingBlocks = array();
}
/** @see CmsObject::load()
*/
//-----------------------------------------------
function load($path=array()){
//-----------------------------------------------
parent::load($path);
if(!$this->classId){
return;
}
$query = sprintf("SELECT * FROM bruckm_stdpage WHERE id = %d", $this->classId);
$result = dbQuery($query);
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
$this->template = $line['template'];
$this->buildingBlocks = array();
if(strlen($line['buildingBlocks']) > 0){
$buildingBlocks = explode("\t", $line['buildingBlocks']);
foreach($buildingBlocks as $b){
$block = BuildingBlockFactory::instance($b);
$block->load();
$this->buildingBlocks[] = $block;
}
}
}
/** @see::CmsObjcet::unload()
*/
//----------------------------------------------
function unload($depth=1){
//----------------------------------------------
parent::unload($depth);
for($i = 0; $i < sizeof($this->buildingBlocks); $i++){
unset($this->buildingBlocks[$i]);
}
unset($this->buildingBlocks);
$this->buildingBlocks = array();
}
/** @see Page::doSave()
*/
//----------------------------------------------
function doSave(){
//----------------------------------------------
$buildingBlocks = array();
foreach($this->buildingBlocks as $i=>$block){
$this->buildingBlocks[$i]->save();
$buildingBlocks[] = $this->buildingBlocks[$i]->getReference();
}
$query = sprintf("UPDATE bruckm_stdpage SET template = %s, buildingBlocks = %s WHERE id = %d",
sqlstring($this->template),
sqlstring(implode("\t", $buildingBlocks)),
sqlnum($this->classId));
dbQuery($query);
parent::doSave();
}
/** @see Page::doCreate()
*/
//----------------------------------------------
function doCreate(){
//----------------------------------------------
$query = sprintf("INSERT INTO bruckm_stdpage (template) VALUES (%s)",
sqlstring($this->template));
dbQuery($query);
$this->classId = mysql_insert_id();
parent::doCreate();
}
/** @see Page::doDelete()
*/
//-----------------------------------------------
function doDelete(){
//-----------------------------------------------
parent::doDelete();
$query = sprintf("DELETE FROM bruckm_stdpage WHERE id = %d LIMIT 1", $this->classId);
dbQuery($query);
foreach($this->buildingBlocks as $i=>$block){
$this->buildingBlocks[$i]->delete();
}
}
/** @see Page::canBeDeleted()
*/
//----------------------------------------------
function canBeDeleted(){
//----------------------------------------------
if($copies = StdPageCopy::getCopiesOf($this->classId)){
$this->addError("Die Seite kann nicht gelöscht werden, da noch Kopien von Ihr bestehen!");
return false;
}
return true;
}
/** @see Page::install()
*/
//-----------------------------------------------
function install(){
//-----------------------------------------------
$query = sprintf("CREATE TABLE IF NOT EXISTS bruckm_stdpage (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
template VARCHAR(100) NOT NULL,
buildingBlocks TEXT NOT NULL DEFAULT '',
PRIMARY KEY (id)
)");
dbQuery($query);
TextBlock::install();
HeadingBlock::install();
HtmlBlock::install();
FileBlock::install();
ImageBlock::install();
GalleryBlock::install();
}
/** @see CmsObject::update()
*/
//-----------------------------------------------
function update(){
//-----------------------------------------------
parent::update();
if(isset($_POST['template'])){
$this->template = $_POST['template'];
}
foreach($this->buildingBlocks as $i=>$block){
$this->buildingBlocks[$i]->update();
}
}
/** @see CmsObject::doPrintClassContent()
*/
//-----------------------------------------------
function doPrintClassContent(){
//-----------------------------------------------
$t = new Template(CMS_TEMPLATE_DIR."stdpage.html");
$templates = "";
$templateFiles = array();
$dir = opendir(TEMPLATE_DIR);
while($file = readdir($dir)){
if(is_file(TEMPLATE_DIR.$file)){
$templateFiles[] = $file;
}
}
sort($templateFiles);
foreach($templateFiles as $file){
if($file == $this->template){
$templates .= "<option value=\"$file\" selected=\"selected\">$file</option>";
}
else{
$templates .= "<option value=\"$file\">$file</option>\n";
}
}
$t->setVar("TEMPLATES", $templates);
if($_SESSION['userlevel'] == USER_ADMIN){
$t->setVar("TEMPLATE_DISABLED", "");
}
else{
$t->setVar("TEMPLATE_DISABLED", "disabled=\"disabled\"");
}
$out = $t->toString();
$out .= $this->doPrintBuildingBlockInsertBar(0);
foreach($this->buildingBlocks as $i=>$block){
$out .= $this->buildingBlocks[$i]->printContent($i);
$out .= $this->doPrintBuildingBlockInsertBar($i+1);
}
return $out;
}
/** @see CmsObject::handleAction()
*/
//-----------------------------------------------
function handleAction($action, $position, $type){
//-----------------------------------------------
switch($action){
case "insertBuildingBlock":
$this->doInsertBuildingBlock($position, $type);
break;
case "moveBuildingBlock":
$this->doMoveBuildingBlock($position, $type);
break;
case "deleteBuildingBlock":
$this->doDeleteBuildingBlock($position);
break;
}
}
/** @see CmsObject::publish()
*/
//---------------------------------------------
function publish(){
//---------------------------------------------
if($this->canBePublished()){
$out = $this->doPublish();
if(!$this->dynamic){
$query = sprintf("UPDATE bruckm_index SET cache = %s WHERE id = %d",
sqlstring($out),
sqlnum($this->id));
dbQuery($query);
}
$copies = StdPageCopy::getCopiesOf($this->classId);
foreach($copies as $copy){
$copy->load();
$copy->publishCopy();
$copy->unload();
$copy->unloadParent();
}
unset($copies);
return true;
}
return false;
}
/** @see CmsObject::canBePublished()
*/
//----------------------------------------------
function canBePublished(){
//----------------------------------------------
if(empty($this->template)){
logError(3, "No template selected", __FILE__, __LINE__);
$this->addError("Bitte wählen Sie ein Template aus!");
return false;
}
return true;
}
/** @see CmsObject::doPublish()
*/
//----------------------------------------------
function doPublish(){
//----------------------------------------------
$t = new Template(TEMPLATE_DIR.$this->template);
$content = "";
foreach($this->buildingBlocks as $i=>$block){
$content .= $this->buildingBlocks[$i]->publish();
}
$t->setVar("CONTENT", $content);
if(!$this->parentObj || $this->parentObj->getId() != $this->parentId){
$this->parentObj = FlexiconFactory::instanceById($this->parentId);
}
if(!$this->parentObj->isLoaded()){
$this->parentObj->load();
}
$t = $this->parentObj->printMenu($t);
$t->setVar("TITLE", $this->toString());
return $t->toString();
}
/** @see Element::getCssClass()
*/
//------------------------------------------------
function getCssClass(){
//------------------------------------------------
return "itemStdPage";
}
// === IMPLEMENTATION OF PRINTABLE =========================================== //
/** @see Printable::printVersion
*
//----------------------------------------------
function printVersion(){
//----------------------------------------------
$t =& new Template(TEMPLATE_DIR."printversion.html");
$content = "";
foreach($this->childElements as $child){
$content .= $this->childObjects[$i]->doPublish();
}
$t->setVar("CONTENT", $content);
return $t->toString();
}*/
// === ADDITIONAL METHODS ==================================================== //
/** inserts a building block
* @param class building block class
* @param index position
*/
//-----------------------------------------------
function doInsertBuildingBlock($index, $class){
//-----------------------------------------------
$this->buildingBlocks = array_insert($this->buildingBlocks, $index, BuildingBlockFactory::instance("$class,0"));
$this->save();
}
/** moves a building block
* @param direction up or down
* @param index position
*/
//-----------------------------------------------
function doMoveBuildingBlock($index, $direction){
//-----------------------------------------------
if($direction == "up" && $index > 0){
$this->buildingBlocks = array_swap($this->buildingBlocks, $index, $index-1);
}
if($direction == "down" && $index < sizeof($this->buildingBlocks)-1){
$this->buildingBlocks = array_swap($this->buildingBlocks, $index, $index+1);
}
$this->save();
}
/** deletes a building block object
* @param index position
*/
//-----------------------------------------------
function doDeleteBuildingBlock($index){
//-----------------------------------------------
$this->buildingBlocks[$index]->delete();
$this->buildingBlocks = array_remove($this->buildingBlocks, $index);
$this->save();
}
/** prints a bar with buttons for inserting building blocks
* @param index position, where the building block will be inserted
* @return string
*/
//-----------------------------------------------
function doPrintBuildingBlockInsertBar($index){
//-----------------------------------------------
$t = new Template(CMS_TEMPLATE_DIR."insertbar.html");
$button = "<div class=\"insert\" onMouseOver=\"showTooltip('%s einf&uuml;gen')\"".
"onClick=\"setAction('insertBuildingBlock', %d, '%s'); document.forms[0].submit();\">".
"<img src=\"images/%s1.png\" alt=\"%s einf&uuml;gen\" onMouseOver=\"swapImage(this,2)\" onMouseOut=\"swapImage(this,1)\" />".
"</div>";
$out .= sprintf($button, "&Uuml;berschrift", $index, "headingblock", "headingblock", "&Uuml;berschrift");
$out .= sprintf($button, "Text", $index, "textblock", "textblock", "Text");
$out .= sprintf($button, "Bild", $index, "imageblock", "imageblock", "Bild");
$out .= sprintf($button, "Text/Bild", $index, "textimageblock", "textimageblock", "Text/Bild");
$out .= sprintf($button, "Datei", $index, "fileblock", "fileblock", "Datei");
$out .= sprintf($button, "Bildergalerie", $index, "galleryblock", "galleryblock", "Bildergalerie");
$out .= sprintf($button, "Sound", $index, "audioblock", "audioblock", "Sound");
$out .= sprintf($button, "Video", $index, "videoblock", "videoblock", "Video");
$out .= sprintf($button, "HTML Code", $index, "htmlblock", "htmlblock", "HTML Code");
$t->setVar("CLASSES", $out);
$t->removeBlock("PASTE");
return $t->toString();
}
//----------------------------------------------
function setTemplate($template) {
//----------------------------------------------
$this->template = $template;
}
};
?>