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

204 lines
5.4 KiB
PHP

<?php
require_once(ROOT."include/bbcode.inc.php");
/** Text Block
*
* @version 1.9.0
* @since 2007-04-16
* @author martin lenzelbauer
*
* @todo implement 'print version'
*/
class TextBlock extends BuildingBlock{
var $content; //text content
/** C'tor
*/
//------------------------------------------------
function TextBlock($id=0){
//------------------------------------------------
parent::BuildingBlock($id);
$this->content = "";
}
/** @see BuildingBlock::install()
*/
//-----------------------------------------------
function install(){
//-----------------------------------------------
$query = sprintf("CREATE TABLE IF NOT EXISTS bruckm_textblock (
id INT not null AUTO_INCREMENT,
content TEXT not null,
PRIMARY KEY(id)
)");
dbQuery($query);
}
/** @see BuildingBlock::load()
*/
//-------------------------------------------------
function load(){
//-------------------------------------------------
$query = sprintf("SELECT * FROM bruckm_textblock WHERE id = %d", $this->id);
$result = dbQuery($query);
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
$this->content = $line['content'];
}
/** @see BuildingBlock::doSave()
*/
//-----------------------------------------------
function doSave(){
//-----------------------------------------------
$query = sprintf("UPDATE bruckm_textblock SET content = %s WHERE id = %d",
sqlstring($this->content),
$this->id);
dbQuery($query);
}
/** @see BuildingBlock::doCreate()
*/
//-----------------------------------------------
function doCreate(){
//-----------------------------------------------
$query = sprintf("INSERT INTO bruckm_textblock (content) VALUES (%s)",
sqlstring($this->content));
dbQuery($query);
return mysql_insert_id();
}
/** @see BuildingBlock::delete()
*/
//-------------------------------------------------
function delete(){
//-------------------------------------------------
$query = sprintf("DELETE FROM bruckm_textblock WHERE id = %d", $this->id);
dbQuery($query);
}
/** @see BuildingBlock::update()
*/
//-----------------------------------------------
function update(){
//-----------------------------------------------
$this->content = html_entity_decode($_POST["textblock_content".$this->id]);
}
/** @see BuildingBlock::printContent()
*/
//-----------------------------------------------
function printContent($position){
//-----------------------------------------------
$t = new Template(CMS_TEMPLATE_DIR."textblock.html");
$c = htmlspecialchars($this->content);
$c = str_replace("&amp;#", "&#", $c);
$t->setVar("CONTENT", $c);
$t->setVar("ID", $this->id);
$t->setVar("POSITION", $position);
return $t->toString();
}
/** @see BuildingBlock::publish()
*/
//----------------------------------------------
function publish(){
//----------------------------------------------
$content = bbcode2html($this->content);
$p = new Template();
$p->setString('<a href="print.php?id={ID}&amp;type={TYPE}" target="_blank" id="{ID}" '.
'onMouseOver="swapImage(\'print{ID}\',2)" onMouseOut="swapImage(\'print{ID}\',1)">'.
'<img src="bg/print1.png" alt="Druckversion" />'.
'<span style="position:relative; top:-3px;">Druckversion</span></a>');
$p->setVar("ID", $this->id);
$p->setVar("TYPE", "stdpage");
//$content = str_replace("[print]", $p->toString(), $content);
return "<p>$content</p>";
}
/** @see BuildingBlock::publishAsPlainText()
*/
//----------------------------------------------
function publishAsPlainText(){
//----------------------------------------------
return bbcode2plaintext($this->content) . "\r\n\r\n";
}
/** @see BuildingBlock::publishForNewsletter()
*/
//----------------------------------------------
function publishForNewsletter(){
//----------------------------------------------
$p = new Template(NEWSLETTER_DIR . "subparts/text.html");
$p->setVar("CONTENT", bbcode2html($this->content));
return $p->toString();
}
/** @see BuildingBlock::publishForPdf()
*/
//----------------------------------------------
function publishForPdf($pdf){
//----------------------------------------------
$pdf->SetFont("Arial", "", 12);
$pdf->SetTextColor(0, 0, 0);
$content = preg_split("(\[(.+)\])U", $this->content, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
$style = "";
for ($i = 0; $i < sizeof($content); $i++) {
$str = $content[$i];
$tag = strtolower(substr($str, 0, 4));
// bold tag
if ($tag == "f") {
$style .= "B";
$pdf->SetFont("Arial", $style, 12);
}
else if ($tag == "/f") {
$style = ereg_replace("B", "", $style);
$pdf->setFont("Arial", $style, 12);
}
// italic tag
else if ($tag == "k") {
$style .= "I";
$pdf->SetFont("Arial", $style, 12);
}
else if ($tag == "/k") {
$style = ereg_replace("I", "", $style);
$pdf->setFont("Arial", $style, 12);
}
// hyperlink
else if ($tag == "url=") {
$href = substr($str, 4, strpos($str, " ") - 4);
$pdf->SetTextColor(0, 0, 127);
$pdf->SetFont("Arial", "I", 12);
$i++;
$pdf->Write(5, $content[$i], $href);
$i++;
$pdf->setTextColor(0, 0, 0);
$pdf->SetFont("Arial", $style, 12);
}
// just text...
else {
$pdf->Write(5, $str);
}
}
$pdf->Ln();
$pdf->Ln();
}
};
?>