175 lines
4.7 KiB
PHP
175 lines
4.7 KiB
PHP
<?php
|
|
require_once(ROOT."include/bbcode.inc.php");
|
|
|
|
/** Heading Block
|
|
*
|
|
* @version 2.0.0
|
|
* @since 2007-04-16
|
|
* @author martin lenzelbauer
|
|
*
|
|
*/
|
|
class HeadingBlock extends BuildingBlock{
|
|
|
|
var $content; //text content
|
|
var $level; //analag to <h1> - <h7>
|
|
var $levels; //array of available levels
|
|
|
|
|
|
/** C'tor
|
|
*/
|
|
//------------------------------------------------
|
|
function HeadingBlock($id=0){
|
|
//------------------------------------------------
|
|
parent::BuildingBlock($id);
|
|
$this->content = "";
|
|
$this->level = 1;
|
|
$this->levels = array(1);
|
|
}
|
|
|
|
|
|
/** @see BuildingBlock::install()
|
|
*/
|
|
//-----------------------------------------------
|
|
function install(){
|
|
//-----------------------------------------------
|
|
$query = sprintf("CREATE TABLE IF NOT EXISTS bruckm_headingblock (
|
|
id INT NOT NULL AUTO_INCREMENT,
|
|
content TEXT NOT NULL,
|
|
level TINYINT NOT NULL DEFAULT 1,
|
|
PRIMARY KEY(id)
|
|
)");
|
|
dbQuery($query);
|
|
}
|
|
|
|
|
|
/** @see BuildingBlock::load()
|
|
*/
|
|
//-------------------------------------------------
|
|
function load(){
|
|
//-------------------------------------------------
|
|
$query = sprintf("SELECT * FROM bruckm_headingblock WHERE id = %d", $this->id);
|
|
$result = dbQuery($query);
|
|
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
|
$this->content = $line['content'];
|
|
$this->level = $line['level'];
|
|
}
|
|
|
|
|
|
/** @see BuildingBlock::doSave()
|
|
*/
|
|
//-----------------------------------------------
|
|
function doSave(){
|
|
//-----------------------------------------------
|
|
$query = sprintf("UPDATE bruckm_headingblock SET content = %s, level = %d WHERE id = %d",
|
|
sqlstring($this->content),
|
|
sqlnum($this->level),
|
|
$this->id);
|
|
dbQuery($query);
|
|
}
|
|
|
|
|
|
/** @see BuildingBlock::doCreate()
|
|
*/
|
|
//-----------------------------------------------
|
|
function doCreate(){
|
|
//-----------------------------------------------
|
|
$query = sprintf("INSERT INTO bruckm_headingblock (content) VALUES (%s)",
|
|
sqlstring($this->content));
|
|
dbQuery($query);
|
|
return mysql_insert_id();
|
|
}
|
|
|
|
|
|
/** @see BuildingBlock::delete()
|
|
*/
|
|
//-------------------------------------------------
|
|
function delete(){
|
|
//-------------------------------------------------
|
|
$query = sprintf("DELETE FROM bruckm_headingblock WHERE id = %d", $this->id);
|
|
dbQuery($query);
|
|
}
|
|
|
|
|
|
|
|
/** @see BuildingBlock::update()
|
|
*/
|
|
//-----------------------------------------------
|
|
function update(){
|
|
//-----------------------------------------------
|
|
$this->content = html_entity_decode($_POST["headingblock_content".$this->id]);
|
|
$this->level = $_POST["headingblock_level".$this->id];
|
|
}
|
|
|
|
|
|
/** @see BuildingBlock::printContent()
|
|
*/
|
|
//-----------------------------------------------
|
|
function printContent($position){
|
|
//-----------------------------------------------
|
|
$t = new Template(CMS_TEMPLATE_DIR."headingblock.html");
|
|
$c = htmlspecialchars($this->content);
|
|
$c = str_replace("&#", "&#", $c);
|
|
$t->setVar("CONTENT", $c);
|
|
$t->setVar("ID", $this->id);
|
|
$t->setVar("POSITION", $position);
|
|
$levels = "";
|
|
foreach($this->levels as $i){
|
|
if($i == $this->level){
|
|
$levels .= '<option value="'.$i.'" selected="selected">'.$i.'</option>';
|
|
}
|
|
else{
|
|
$levels .= '<option value="'.$i.'">'.$i.'</option>';
|
|
}
|
|
}
|
|
$t->setVar("LEVELS", $levels);
|
|
return $t->toString();
|
|
}
|
|
|
|
|
|
/** @see BuildingBlock::publish()
|
|
*/
|
|
//----------------------------------------------
|
|
function publish(){
|
|
//----------------------------------------------
|
|
if($this->level < 1 || $this->level > 7){
|
|
logError(3, "Illegal heading level (".$this->level.") - ID: ".$this->id, __FILE__, __LINE__);
|
|
$this->level = 1;
|
|
}
|
|
return "<h".$this->level.">".htmlspecialchars($this->content)."</h".$this->level.">";
|
|
}
|
|
|
|
|
|
/** @see BuildingBlock::publishAsPlainText()
|
|
*/
|
|
//----------------------------------------------
|
|
function publishAsPlainText(){
|
|
//----------------------------------------------
|
|
return $this->content . "\r\n\r\n";
|
|
}
|
|
|
|
|
|
/** @see BuildingBlock::publishForNewsletter()
|
|
*/
|
|
//----------------------------------------------
|
|
function publishForNewsletter(){
|
|
//----------------------------------------------
|
|
$p = new Template(NEWSLETTER_DIR . "subparts/heading.html");
|
|
$p->setVar("CONTENT", htmlspecialchars($this->content));
|
|
return $p->toString();
|
|
}
|
|
|
|
|
|
/** @see BuildingBlock::publishForPdf()
|
|
*/
|
|
//----------------------------------------------
|
|
function publishForPdf($pdf){
|
|
//----------------------------------------------
|
|
$pdf->SetFont("Arial", "B", 16);
|
|
$pdf->SetTextColor(0, 0, 0);
|
|
$pdf->Write(5, $this->content . "\n\n");
|
|
}
|
|
|
|
|
|
};
|
|
|
|
?>
|