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

309 lines
8.2 KiB
PHP

<?php
require_once(ROOT."include/config.inc.php");
require_once(CMS_DIR."modules/_buildingblockfactory.class.php");
/** Gallery
*
* @version 1.9.0
* @date 2007-03-27
* @author martin lenzelbauer
*
*/
class Gallery extends Page{
var $images; //array of images
//image settings
var $thumbWidth = 50;
var $thumbHeight = 50;
var $thumbStretch = false;
/** C'tor
*/
//------------------------------------------------
function Gallery($id, $parent){
//------------------------------------------------
parent::Page($id, $parent);
$this->name = "[unbenannte Galerie]";
$this->buttonPreview = true;
$this->buttonPublish = true;
$this->images = array();
$this->visible = 1;
}
/** @see CmsObject::load()
*/
//-----------------------------------------------
function load($path=array()){
//-----------------------------------------------
parent::load($path);
if(!$this->classId){
return;
}
$query = sprintf("SELECT * FROM bruckm_gallery WHERE id = %d", $this->classId);
$result = dbQuery($query);
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
$this->images = array();
if(strlen($line['images']) > 0){
$images = explode("\t", $line['images']);
foreach($images as $i){
$img = BuildingBlockFactory::instance($i);
$img->load();
$img->setDirectories(GALLERY_DIR, GALLERY_THUMB_DIR);
$img->useThumbs();
$this->images[] = $img;
}
}
}
/** @see Page::doSave()
*/
//----------------------------------------------
function doSave(){
//----------------------------------------------
$images = array();
foreach($this->images as $i=>$img){
$this->images[$i]->save();
$images[] = $this->images[$i]->getReference();
}
$query = sprintf("UPDATE bruckm_gallery SET images = %s WHERE id = %d",
sqlstring(implode("\t", $images)),
sqlnum($this->classId));
dbQuery($query);
parent::doSave();
}
/** @see Page::doCreate()
*/
//----------------------------------------------
function doCreate(){
//----------------------------------------------
$query = sprintf("INSERT INTO bruckm_gallery (images) VALUES (%s)",
sqlstring(""));
dbQuery($query);
$this->classId = mysql_insert_id();
parent::doCreate();
}
/** @see Page::doDelete()
*/
//-----------------------------------------------
function doDelete(){
//-----------------------------------------------
parent::doDelete();
$query = sprintf("DELETE FROM bruckm_gallery WHERE id = %d LIMIT 1", $this->classId);
dbQuery($query);
foreach($this->images as $i=>$img){
$this->images[$i]->delete();
}
}
/** @see Page::install()
*/
//-----------------------------------------------
function install(){
//-----------------------------------------------
$query = sprintf("CREATE TABLE IF NOT EXISTS bruckm_gallery (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
images TEXT NOT NULL DEFAULT '',
PRIMARY KEY (id)
)");
dbQuery($query);
ImageBlock::install();
}
/** @see CmsObject::update()
*/
//-----------------------------------------------
function update(){
//-----------------------------------------------
parent::update();
if(isset($_POST['galleryname']) && $_POST['galleryname'] != "[unbenannte Galerie]"){
$this->name = $_POST['galleryname'];
}
foreach($this->images as $i=>$img){
$this->images[$i]->update();
}
}
/** @see CmsObject::doPrintClassContent()
*/
//-----------------------------------------------
function doPrintClassContent(){
//-----------------------------------------------
$t = new Template(CMS_TEMPLATE_DIR."gallery.html");
$t->setVar("NAME", $this->name);
$out = $t->toString();
$out .= $this->doPrintBuildingBlockInsertBar(0);
foreach($this->images as $i=>$img){
$out .= $this->images[$i]->printContent($i);
$out .= $this->doPrintBuildingBlockInsertBar($i+1);
}
return $out;
}
/** @see CmsObject::printChildContent()
*/
//-----------------------------------------------
function printChildContent(){
//-----------------------------------------------
$t = new Template(CMS_TEMPLATE_DIR."gallerychild.html");
$t->setVar("TITLE", FlexiconFactory::nameOfClass(get_class($this)));
$t->setVar("NAME", $this->name);
$t->setVar("CLASS", strtolower(get_class($this)));
$t->setVar("PATH", $this->printPath());
$t->setVar("ID", $this->id);
$images = "";
for($i = 0; $i<sizeof($this->images) && $i<9; $i++){
$images .= $this->images[$i]->printThumb();
}
$t->setVar("IMAGES", $images);
return $t->toString();
}
/** @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::doPublish()
*/
//----------------------------------------------
function doPublish(){
//----------------------------------------------
$t = new Template(TEMPLATE_DIR."gallery.html");
$t->setVar("TITLE", htmlspecialchars($this->name));
$t->setVar("ID", $this->id);
return $t->toString();
}
/** @see CmsObject::canBePublished()
*/
//---------------------------------------------
function canBePublished(){
//---------------------------------------------
if(sizeof($this->images) == 0){
$this->addError("Die Galerie beinhaltet keine Bilder!");
return false;
}
return true;
}
/** @see Element::getCssClass()
*/
//------------------------------------------------
function getCssClass(){
//------------------------------------------------
return "itemGallery";
}
// === ADDITIONAL METHODS ============================================================ //
/** inserts a building block
* @param class building block class
* @param index position
*/
//-----------------------------------------------
function doInsertBuildingBlock($index, $class){
//-----------------------------------------------
$this->images = array_insert($this->images, $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->images = array_swap($this->images, $index, $index-1);
}
if($direction == "down" && $index < sizeof($this->buildingBlocks)-1){
$this->images = array_swap($this->images, $index, $index+1);
}
$this->save();
}
/** deletes a building block object
* @param index position
*/
//-----------------------------------------------
function doDeleteBuildingBlock($index){
//-----------------------------------------------
$this->images[$index]->delete();
$this->images = array_remove($this->images, $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, "Bild", $index, "imageblock", "imageblock", "Bild");
$t->setVar("CLASSES", $out);
return $t->toString();
}
/** returns an xml for the gallery flash component
* @return xml string
*/
//-----------------------------------------
function toXml(){
//-----------------------------------------
$xml = "<gallery>";
foreach($this->images as $i=>$img){
$xml .= $this->images[$i]->toXml();
}
$xml .= "</gallery>";
return $xml;
}
};
?>