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

864 lines
27 KiB
PHP

<?php
/** Index Page
*
* @version 2.1.0
* @date 2007-05-01
* @author martin lenzelbauer
*
* @change 2007-06-15
* changed preview()
* fixed bug in doSave()
* fixed bug in doPublish()
*
* @change 2007-07-02
* changed findClosest()
*
* @change 2007-08-08
* added alternating image block
*
* @change 2007-12-16
* added template sorting
*
* @change 2008-02-04
* added two quicklinks for the left navigation
*
* @change 2008-09-23
* updated loading & publishing routines to keep memory low in PHP5
*/
class IndexPage extends StdPage{
var $eventList; //flexicon id of the target event list for event detail views
var $headerEvent1;
var $headerEvent2;
var $headerEvent3;
var $headerImage1;
var $headerImage2;
var $headerImage3;
var $headerTitle1;
var $headerTitle2;
var $headerTitle3;
var $headerSubtitle1;
var $headerSubtitle2;
var $headerSubtitle3;
var $includeEvents;
var $excludeEvents;
var $thumbWidth = 910;
var $thumbHeight = 280;
var $thumbStretch = false;
/** C'tor
*/
//------------------------------------------------
function IndexPage($id, $parent){
//------------------------------------------------
parent::StdPage($id, $parent);
$this->dynamic = false;
$this->name = "[Startseite]";
$this->eventList = 0;
$this->includeEvents = "";
$this->excludeEvents = "";
$this->headerEvent1 = 0;
$this->headerEvent2 = 0;
$this->headerEvent3 = 0;
$this->headerImage1 = "";
$this->headerImage2 = "";
$this->headerImage3 = "";
$this->headerTitle1 = "";
$this->headerTitle2 = "";
$this->headerTitle3 = "";
$this->headerSubtitle1 = "";
$this->headerSubtitle2 = "";
$this->headerSubtitle3 = "";
}
/** @see CmsObject::load()
*/
//-----------------------------------------------
function load($path=array()){
//-----------------------------------------------
parent::load($path);
if(!$this->classId){
return;
}
$query = sprintf("SELECT * FROM bruckm_indexpage WHERE id = %d", $this->classId);
$result = dbQuery($query);
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
$this->template = $line['template'];
$this->eventList = $line['eventList'];
$this->headerEvent1 = $line['headerEvent1'];
$this->headerEvent2 = $line['headerEvent2'];
$this->headerEvent3 = $line['headerEvent3'];
$this->headerImage1 = $line['headerImage1'];
$this->headerImage2 = $line['headerImage2'];
$this->headerImage3 = $line['headerImage2'];
$this->headerTitle1 = $line['headerTitle1'];
$this->headerTitle2 = $line['headerTitle2'];
$this->headerTitle3 = $line['headerTitle3'];
$this->headerSubtitle1 = $line['headerSubtitle1'];
$this->headerSubtitle2 = $line['headerSubtitle2'];
$this->headerSubtitle3 = $line['headerSubtitle3'];
$this->includeEvents = $line['includeEvents'];
$this->excludeEvents = $line['excludeEvents'];
$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 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_indexpage SET template = %s, eventList = %d,
headerEvent1 = %d, headerImage1 = %s, headerTitle1 = %s, headerSubtitle1 = %s,
headerEvent2 = %d, headerImage2 = %s, headerTitle2 = %s, headerSubtitle2 = %s,
headerEvent3 = %d, headerImage3 = %s, headerTitle3 = %s, headerSubtitle3 = %s,
includeEvents = %s, excludeEvents = %s, buildingBlocks = %s WHERE id = %d",
sqlstring($this->template),
sqlnum($this->eventList),
sqlnum($this->headerEvent1),
sqlstring($this->headerImage1),
sqlstring($this->headerTitle1),
sqlstring($this->headerSubtitle1),
sqlnum($this->headerEvent2),
sqlstring($this->headerImage2),
sqlstring($this->headerTitle2),
sqlstring($this->headerSubtitle2),
sqlnum($this->headerEvent3),
sqlstring($this->headerImage3),
sqlstring($this->headerTitle3),
sqlstring($this->headerSubtitle3),
sqlstring($this->includeEvents),
sqlstring($this->excludeEvents),
sqlstring(implode("\t", $buildingBlocks)),
sqlnum($this->classId));
dbQuery($query);
Page::doSave();
}
/** @see Page::doCreate()
*/
//----------------------------------------------
function doCreate(){
//----------------------------------------------
$query = sprintf("INSERT INTO bruckm_indexpage (template) VALUES (%s)",
sqlstring($this->template));
dbQuery($query);
$this->classId = mysql_insert_id();
parent::doCreate();
}
/** @see Page::install()
*/
//-----------------------------------------------
function install(){
//-----------------------------------------------
$query = sprintf("CREATE TABLE IF NOT EXISTS bruckm_indexpage (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
template VARCHAR(100) NOT NULL,
buildingBlocks TEXT NOT NULL DEFAULT '',
eventList INT UNSIGNED NOT NULL DEFAULT 0,
cache TEXT NOT NULL DEFAULT '',
enabled TINYINT NOT NULL DEFAULT 0,
quickImage1 VARCHAR(100) NOT NULL,
quickImage2 VARCHAR(100) NOT NULL,
quickLink1 VARCHAR(100) NOT NULL,
quickLink2 VARCHAR(100) NOT NULL,
quickText1 VARCHAR(100) NOT NULL,
quickText2 VARCHAR(100) NOT NULL,
includeEvents VARCHAR(100) NOT NULL,
excludeEvents VARCHAR(100) NOT NULL,
PRIMARY KEY (id),
KEY (enabled)
)");
dbQuery($query);
TextBlock::install();
HeadingBlock::install();
HtmlBlock::install();
FileBlock::install();
ImageBlock::install();
GalleryBlock::install();
AlternatingImageBlock::install();
}
/** @see CmsObject::update()
*/
//-----------------------------------------------
function update(){
//-----------------------------------------------
parent::update();
if(isset($_POST['eventList'])){
$this->eventList = $_POST['eventList'];
}
$this->headerEvent1 = $_POST['headerEvent1'];
$this->headerTitle1 = $_POST['headerTitle1'];
$this->headerSubtitle1 = $_POST['headerSubtitle1'];
$this->headerEvent2 = $_POST['headerEvent2'];
$this->headerTitle2 = $_POST['headerTitle2'];
$this->headerSubtitle2 = $_POST['headerSubtitle2'];
$this->headerEvent3 = $_POST['headerEvent3'];
$this->headerTitle3 = $_POST['headerTitle3'];
$this->headerSubtitle3 = $_POST['headerSubtitle3'];
if(isset($_FILES['headerImage1']) && $_FILES['headerImage1']['error'] == UPLOAD_ERR_OK){
$this->headerImage1 = $this->uploadImage($_FILES['headerImage1'], $this->headerImage1, 1);
} else if ($_POST['headerImageDelete1']) {
$this->headerImage1 = "";
}
if(isset($_FILES['headerImage2']) && $_FILES['headerImage2']['error'] == UPLOAD_ERR_OK){
$this->headerImage2 = $this->uploadImage($_FILES['headerImage2'], $this->headerImage2, 2);
} else if ($_POST['headerImageDelete2']) {
$this->headerImage2 = "";
}
if(isset($_FILES['headerImage3']) && $_FILES['headerImage3']['error'] == UPLOAD_ERR_OK){
$this->headerImage3 = $this->uploadImage($_FILES['headerImage3'], $this->headerImage3, 3);
} else if ($_POST['headerImageDelete3']) {
$this->headerImage3 = "";
}
if(isset($_POST['includeEvents'])){
$this->includeEvents = $_POST['includeEvents'];
}
if(isset($_POST['excludeEvents'])){
$this->excludeEvents = $_POST['excludeEvents'];
}
}
/** @see CmsObject::doPrintClassContent()
*/
//-----------------------------------------------
function doPrintClassContent(){
//-----------------------------------------------
$t = new Template(CMS_TEMPLATE_DIR."indexpage.html");
// templates
$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);
// event list
$lists = "";
$query = sprintf("SELECT id,name FROM bruckm_index WHERE class = 'EventList' ORDER BY name ASC");
$result = dbQuery($query);
while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){
if($line['id'] == $this->eventList){
$lists .= "<option value=\"$line[id]\" selected=\"selected\">";
}
else{
$lists .= "<option value=\"$line[id]\">";
}
$lists .= htmlspecialchars($line['name'])." (ID: $line[id])</option>";
}
$t->setVar("EVENT_LISTS", $lists);
if($_SESSION['userlevel'] == USER_ADMIN){
$t->setVar("TEMPLATE_DISABLED", "");
$t->setVar("EVENT_LIST_DISABLED", "");
}
else{
$t->setVar("TEMPLATE_DISABLED", "disabled=\"disabled\"");
$t->setVar("EVENT_LIST_DISABLED", "disabled=\"disabled\"");
}
// include/exclude events
if($_SESSION['userlevel'] == USER_ADMIN){
$t->setVar("INCLUDEEVENTS", $this->includeEvents);
$t->setVar("EXCLUDEEVENTS", $this->excludeEvents);
}
else{
$t->removeBlock("ADMIN");
}
// load events for header slider
$headerEventIds = array(0);
if ($this->headerEvent1) {
$headerEventIds[] = $this->headerEvent1;
}
if ($this->headerEvent2) {
$headerEventIds[] = $this->headerEvent2;
}
if ($this->headerEvent3) {
$headerEventIds[] = $this->headerEvent3;
}
$query = sprintf(
"SELECT flexiconId,name FROM bruckm_ticketevent WHERE (endDate >= '%s' AND (houseId = 1 OR houseId = 0)) OR flexiconId IN (%s) ORDER BY startDate ASC",
date("Y-m-d"),
implode(",", $headerEventIds)
);
$result = dbQuery($query);
$events = array();
while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$events[$line['flexiconId']] = $line['name'];
}
// header slider 1
if(!empty($this->headerImage1) && file_exists(IMG_DIR.$this->headerImage1)){
$t->setVar("HEADERIMAGE1", IMG_DIR.$this->headerImage1);
}
else{
$t->removeBlock("HEADERIMAGE1");
}
$t->setVar("HEADERTITLE1", htmlspecialchars($this->headerTitle1));
$t->setVar("HEADERSUBTITLE1", htmlspecialchars($this->headerSubtitle1));
$options1 = '<option value="0">(bitte wählen)</option>';
foreach ($events as $id=>$title) {
$options1 .= sprintf('<option value="%d" %s>%s</option>',
$id,
$id == $this->headerEvent1 ? 'selected' : '',
$title
);
}
$t->setVar("HEADEREVENT1", $options1);
// header slider 2
if(!empty($this->headerImage2) && file_exists(IMG_DIR.$this->headerImage2)){
$t->setVar("HEADERIMAGE2", IMG_DIR.$this->headerImage2);
}
else{
$t->removeBlock("HEADERIMAGE2");
}
$t->setVar("HEADERTITLE2", htmlspecialchars($this->headerTitle2));
$t->setVar("HEADERSUBTITLE2", htmlspecialchars($this->headerSubtitle2));
$options2 = '<option value="0">(bitte wählen)</option>';
foreach ($events as $id=>$title) {
$options2 .= sprintf('<option value="%d" %s>%s</option>',
$id,
$id == $this->headerEvent2 ? 'selected' : '',
$title
);
}
$t->setVar("HEADEREVENT2", $options2);
// header slider 3
if(!empty($this->headerImage3) && file_exists(IMG_DIR.$this->headerImage3)){
$t->setVar("HEADERIMAGE3", IMG_DIR.$this->headerImage3);
}
else{
$t->removeBlock("HEADERIMAGE3");
}
$t->setVar("HEADERTITLE3", htmlspecialchars($this->headerTitle3));
$t->setVar("HEADERSUBTITLE3", htmlspecialchars($this->headerSubtitle3));
$options3 = '<option value="0">(bitte wählen)</option>';
foreach ($events as $id=>$title) {
$options3 .= sprintf('<option value="%d" %s>%s</option>',
$id,
$id == $this->headerEvent3 ? 'selected' : '',
$title
);
}
$t->setVar("HEADEREVENT3", $options3);
$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::publish()
*/
//---------------------------------------------
function publish(){
//---------------------------------------------
if($this->canBePublished()){
$out = $this->doPublish();
$query = sprintf("UPDATE bruckm_index SET cache = %s WHERE id = %d",
sqlstring($out),
sqlnum($this->id));
dbQuery($query);
$query = sprintf("UPDATE bruckm_indexpage SET cache = %s, enabled = 1 WHERE id = %d",
sqlstring($out),
sqlnum($this->classId));
dbQuery($query);
$query = sprintf("UPDATE bruckm_indexpage SET enabled = 0 WHERE id != %d",
sqlnum($this->classId));
dbQuery($query);
return true;
}
return false;
}
/** @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 = FlexiconFactory::instanceById($this->parentId);
}
if(!$this->parentObj->isLoaded()){
$this->parentObj->load();
}
$t = $this->parentObj->printMenu($t);
$t->setVar("TITLE", $this->toString());
$t->setVar("EVENTS", $this->printEvents());
$t->setVar("SLIDER", $this->printHeaderSlider());
return $t->toString();
}
/** @see CmsObject::preview()
*/
//---------------------------------------------
function preview(){
//---------------------------------------------
return $this->doPublish();
}
/** @see CmsObject::canBeDeleted()
*/
//--------------------------------------------
function canBeDeleted(){
//--------------------------------------------
$this->addError("Die Startseite darf nicht gelöscht werden!");
return false;
}
// === ADDIDTIONAL METHODS ====================================== //
/** 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, "T&auml;glich wechselndes Bild", $index, "alternatingimageblock", "alternatingimageblock", "T&auml;glich wechselndes 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);
return $t->toString();
}
/** prints a list of the 3 most recent events and 2 quicklinks
* @return string
*
//-------------------------------------------
function printEventsAndQuicklinks(){
//-------------------------------------------
$events = array();
$include = explode(",", $this->includeEvents);
$exclude = explode(",", $this->excludeEvents);
$maxEvents = 3;
$count = 0;
$out = "";
//load all current events
$query = sprintf("SELECT flexiconId FROM bruckm_ticketevent WHERE endDate >= '%s' AND (houseId = 1 OR houseId = 0) ORDER BY startDate ASC", date("Y-m-d"));
$result = dbQuery($query);
while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){
if (!in_array($line['flexiconId'], $exclude) && !in_array($line['flexiconId'], $include)) {
$event = FlexiconFactory::instanceById($line['flexiconId'], $this);
$event->load();
$events[] = $event;
}
}
//add featured events
if(sizeof($include) > 0){
foreach($include as $id){
if (!empty($id)){
$event = FlexiconFactory::instanceById($id, $this);
$event->load();
if ($event->isInFuture()){
$out .= $event->publishForIndexPage($this->eventList);
$count++;
}
}
}
}
//add up to [count] events
while($count < $maxEvents && sizeof($events) > 0){
$index = $this->findClosest($events);
$out .= $events[$index]->publishForIndexPage($this->eventList);
$events = array_remove($events, $index);
$count++;
}
// add quicklinks
if(!empty($this->quickText1) || !empty($this->quickText2)){
//$out .= "<h1 class=\"subMenuTitle\"> </h1>";
}
if(!empty($this->quickText1)){
$ql = new Template(TEMPLATE_DIR."subparts/quicklink-index.html");
$ql->setVar("TEXT", htmlspecialchars($this->quickText1));
$ql->setVar("LINK", $this->quickLink1);
$ql->setVar("IMAGE", $this->quickImage1);
$out .= $ql->toString();
}
if(!empty($this->quickText2)){
$ql = new Template(TEMPLATE_DIR."subparts/quicklink-index.html");
$ql->setVar("TEXT", htmlspecialchars($this->quickText2));
$ql->setVar("LINK", $this->quickLink2);
$ql->setVar("IMAGE", $this->quickImage2);
$out .= $ql->toString();
}
return $out;
}*/
/** prints the header slider
* @return string
*/
//-------------------------------------------
function printHeaderSlider(){
//-------------------------------------------
// set slide count
$slides = 0;
if ($this->headerEvent1) {
$slides++;
}
if ($this->headerEvent2) {
$slides++;
}
if ($this->headerEvent3) {
$slides++;
}
if ($slides == 0) {
return "";
}
$out = sprintf('<ul class="slider" style="width:%d%%">', $slides * 100);
if ($this->headerEvent1) {
$event = FlexiconFactory::instanceById($this->headerEvent1, $this);
$event->load();
$date = $event->getStartDate();
$t = new Template(TEMPLATE_DIR."subparts/slide.html");
$t->setVar("TITLE", htmlspecialchars($this->headerTitle1));
$t->setVar("SUBTITLE", htmlspecialchars($this->headerSubtitle1));
$t->setVar("IMAGE", $this->headerImage1 ? 'images/'.$this->headerImage1 : 'bg/slider-default.jpg');
$t->setVar("DAY", dateGet($date, 'd'));
$t->setVar("MONTH", dateGet($date, 'm'));
$t->setVar("MONTHNAME", dateGet($date, 'F'));
$t->setVar("YEAR", dateGet($date, 'Y'));
$t->setVar("EVENTLISTID", $this->eventList);
$t->setVar("EVENTID", $this->headerEvent1);
$t->setVar("WIDTH", sprintf('%.2f', 100.0 / $slides));
$out .= $t->toString();
}
if ($this->headerEvent2) {
$event = FlexiconFactory::instanceById($this->headerEvent2, $this);
$event->load();
$date = $event->getStartDate();
$t = new Template(TEMPLATE_DIR."subparts/slide.html");
$t->setVar("TITLE", htmlspecialchars($this->headerTitle2));
$t->setVar("SUBTITLE", htmlspecialchars($this->headerSubtitle2));
$t->setVar("IMAGE", $this->headerImage2 ? 'images/'.$this->headerImage2 : 'bg/slider-default.jpg');
$t->setVar("DAY", dateGet($date, 'd'));
$t->setVar("MONTH", dateGet($date, 'm'));
$t->setVar("MONTHNAME", dateGet($date, 'F'));
$t->setVar("YEAR", dateGet($date, 'Y'));
$t->setVar("EVENTLISTID", $this->eventList);
$t->setVar("EVENTID", $this->headerEvent2);
$t->setVar("WIDTH", sprintf('%.2f', 100.0 / $slides));
$out .= $t->toString();
}
if ($this->headerEvent3) {
$event = FlexiconFactory::instanceById($this->headerEvent3, $this);
$event->load();
$date = $event->getStartDate();
$t = new Template(TEMPLATE_DIR."subparts/slide.html");
$t->setVar("TITLE", htmlspecialchars($this->headerTitle3));
$t->setVar("SUBTITLE", htmlspecialchars($this->headerSubtitle3));
$t->setVar("IMAGE", $this->headerImage3 ? 'images/'.$this->headerImage3 : 'bg/slider-default.jpg');
$t->setVar("DAY", dateGet($date, 'd'));
$t->setVar("MONTH", dateGet($date, 'm'));
$t->setVar("MONTHNAME", dateGet($date, 'F'));
$t->setVar("YEAR", dateGet($date, 'Y'));
$t->setVar("EVENTLISTID", $this->eventList);
$t->setVar("EVENTID", $this->headerEvent3);
$t->setVar("WIDTH", sprintf('%.2f', 100.0 / $slides));
$out .= $t->toString();
}
$out .= '</ul>';
return $out;
}
/** prints a list of the most recent events
* @return string
*/
//-------------------------------------------
function printEvents(){
//-------------------------------------------
global $IGNORED_EVENTS; // see include/events.inc.php
$events = array();
//$include = explode(",", $this->includeEvents);
//$exclude = explode(",", $this->excludeEvents);
$maxEvents = 100;
$count = 0;
$out = "";
//load all current events
$query = sprintf("SELECT flexiconId FROM bruckm_ticketevent WHERE endDate >= '%s' AND (houseId = 1 OR houseId = 0) ORDER BY startDate ASC, endDate DESC", date("Y-m-d"));
$result = dbQuery($query);
while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){
if (!in_array($line['flexiconId'], $IGNORED_EVENTS)) {
$event = FlexiconFactory::instanceById($line['flexiconId'], $this);
$event->load();
$events[] = $event;
$out .= $event->publishForIndexPage($this->eventList);
}
}
// //add up to [count] events
// while($count < $maxEvents && sizeof($events) > 0){
// $index = $this->findClosest($events);
// $out .= $events[$index]->publishForIndexPage($this->eventList);
// $events = array_remove($events, $index);
// $count++;
// }
if (sizeof($events) > $maxEvents) {
$out .= '<a href="http://bruckmuehle.at/?id=82" class="moreEvents">Alle Veranstaltungen anzeigen</a>';
}
return $out;
}
/** finds the event closest to the current date
* @return index in the events array
*/
//-------------------------------------
function findClosest($events){
//-------------------------------------
$closest = 0;
$minDifference = 1000;
$now = intval(date("Ymd"));
foreach($events as $i=>$event){
//one day event
if($event->getStartDate() == $event->getEndDate()){
$difference = date2int($event->getStartDate()) - $now;
if($difference < $minDifference){
$minDifference = $difference;
$closest = $i;
}
}
//long range event
else{
$difference = date2int($event->getStartDate()) - $now;
if($difference >= 0 && $difference < $minDifference){
$minDifference = $difference;
$closest = $i;
}
else{
$difference = date2int($event->getEndDate()) - $now;
if($difference <= $minDifference){
$minDifference = abs($difference);
$closest = $i;
}
}
}
}
return $closest;
}
/** views the index page directly
* @static
* @return string
*/
//-------------------------------------
static function view(){
//-------------------------------------
$query = sprintf("SELECT cache FROM bruckm_indexpage WHERE enabled = 1 LIMIT 1");
$result = dbQuery($query);
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
return $line['cache'];
}
/** builds the index page
* @static
*/
//------------------------------------
function build(){
//------------------------------------
$query = sprintf("SELECT id FROM bruckm_index WHERE class = 'IndexPage' AND visible = 1 LIMIT 1");
$result = dbQuery($query);
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
$index = FlexiconFactory::instanceById($line['id']);
$index->load();
$index->publish();
}
/** uploads a header image
* @param file $_FILES file date
* @param quickImage the filename of the current quick image
* @param index the index of the quick image
*/
//------------------------------------------------
function uploadImage($file, $headerImage, $index){
//------------------------------------------------
//remove old image
if(!empty($headerImage) && file_exists(IMG_DIR.$headerImage)){
@unlink(IMG_DIR.$headerImage);
}
//create target path
$imgSize = getImageSize($file['tmp_name']);
switch($imgSize[2]){
case 1: //gif
$path = "slider".time().".gif";
break;
case 2: //jpg
$path = "slider".time().".jpg";
break;
case 3: //png
$path = "slider".time().".png";
break;
default:
logError(3, "Unsupported mime type: $file[name] ($imgSize[2])", __FILE__, __LINE__);
$this->addError("Das Bild verwendet ein nicht unterstütztes Dateiformat oder es ist beschädigt!");
return "";
}
//resize image
if($imgSize[0] > $this->thumbWidth || $imgSize[1] > $this->thumbHeight){
switch($imgSize[2]){
case 1: //gif
$original = imageCreateFromGif($file['tmp_name']);
break;
case 2: //jpg
$original = imageCreateFromJpeg($file['tmp_name']);
break;
case 3: //png
$original = imageCreateFromPng($file['tmp_name']);
break;
}
$origWidth = $imgSize[0];
$origHeight = $imgSize[1];
$width = $this->thumbWidth;
$height = $this->thumbHeight;
$origX = 0;
$origY = 0;
//clip image
if(!$this->thumbStretch){
if($origWidth > $origHeight){
$origX = ($origWidth - $origHeight)/2;
$origWidth = $origHeight;
}
else{
$origY = ($origHeight - $origWidth)/2;
$origHeight = $origWidth;
}
}
$small = imageCreateTrueColor($width, $height);
imageCopyResampled($small, $original, 0, 0, $origX, $origY, $width, $height, $origWidth, $origHeight);
switch($imgSize[2]){
case 1:
if(!@imageGif($small, IMG_DIR.$path)){
logError(4, "Could not create gif image: $path", __FILE__, __LINE__);
$this->addError("Das Bild konnte nicht erzeugt werden!");
return "";
}
break;
case 2:
if(!@imageJpeg($small, IMG_DIR.$path, 100)){
logError(4, "Could not create jpg image: $path", __FILE__, __LINE__);
$this->addError("Das Bild konnte nicht erzeugt werden!");
return "";
}
break;
case 3:
if(!@imagePng($small, IMG_DIR.$path)){
logError(4, "Could not create png image: $path", __FILE__, __LINE__);
$this->addError("Das Bild konnte nicht erzeugt werden!");
return "";
}
break;
}
imageDestroy($small);
imageDestroy($original);
@chmod(IMG_DIR.$path, 0777);
}
//copy image in original size
else{
if(@move_uploaded_file($file['tmp_name'], IMG_DIR.$path)){
@chmod(IMG_DIR.$path, 0777);
}
else{
logError(4, "Could not copy image: $file[tmp_name] => $path)", __FILE__, __LINE__);
$this->addError("Das Bild konnte nicht erzeugt werden!");
return "";
}
}
return $path;
}
};
?>