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

245 lines
6.2 KiB
PHP

<?php
/** PHP Page
* Includes dynamic PHP scripts.
* The PHP file must be in PHP_SCRIPT_DIR.
* The entry point for the PHP script is the function doPhpScript(), which must return the page content.
*
* @version 2.0.2
* @date 2007-05-01
* @author martin lenzelbauer
*
* @change 2007-06-15
* fixed PHP4 bug in show()
*
* @change 2007-12-16
* added template sorting
*/
class PhpPage extends Page{
var $phpfile; //the php file that will be inserted in the template
var $template; //html template file
/** C'tor
*/
//------------------------------------------------
function PhpPage($id, $parent){
//------------------------------------------------
parent::Page($id, $parent);
$this->name = "[unbenannte PHP-Seite]";
$this->phpfile = "";
$this->template = "";
$this->dynamic = true;
$this->editable = USER_ADMIN;
$this->buttonPublish = true;
$this->buttonPreview = true;
}
/** @see CmsObject::load()
*/
//-----------------------------------------------
function load($path=array()){
//-----------------------------------------------
parent::load($path);
if(!$this->classId){
return;
}
$query = sprintf("SELECT * FROM bruckm_phppage WHERE id = %d", $this->classId);
$result = dbQuery($query);
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
$this->template = $line['template'];
$this->phpfile = $line['phpfile'];
}
/** @see Page::doSave()
*/
//----------------------------------------------
function doSave(){
//----------------------------------------------
$query = sprintf("UPDATE bruckm_phppage SET template = %s, phpfile = %s WHERE id = %d",
sqlstring($this->template),
sqlstring($this->phpfile),
sqlnum($this->classId));
dbQuery($query);
parent::doSave();
}
/** @see Page::doCreate()
*/
//----------------------------------------------
function doCreate(){
//----------------------------------------------
$query = sprintf("INSERT INTO bruckm_phppage (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_phppage WHERE id = %d LIMIT 1", $this->classId);
dbQuery($query);
}
/** @see Page::install()
*/
//-----------------------------------------------
function install(){
//-----------------------------------------------
$query = sprintf("CREATE TABLE IF NOT EXISTS bruckm_phppage (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
template VARCHAR(100) NOT NULL DEFAULT '',
phpfile VARCHAR(100) NULL DEFAULT '',
PRIMARY KEY (id)
)");
dbQuery($query);
}
/** @see CmsObject::update()
*/
//-----------------------------------------------
function update(){
//-----------------------------------------------
parent::update();
if(isset($_POST['template'])){
$this->template = $_POST['template'];
}
if(isset($_POST['phpfile'])){
$this->phpfile = $_POST['phpfile'];
}
}
/** @see CmsObject::doPrintClassContent()
*/
//-----------------------------------------------
function doPrintClassContent(){
//-----------------------------------------------
$t = new Template(CMS_TEMPLATE_DIR."phppage.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);
//php scripts
$phpfiles;
$dir = opendir(PHP_SCRIPT_DIR);
while($file = readdir($dir)){
if(is_file(PHP_SCRIPT_DIR.$file)){
if($file == $this->phpfile){
$phpfiles .= "<option value=\"$file\" selected=\"selected\">$file</option>";
}
else{
$phpfiles .= "<option value=\"$file\">$file</option>\n";
}
}
}
$t->setVar("PHP_SCRIPTS", $phpfiles);
if($this->isEditable()){
$t->setVar("TEMPLATE_DISABLED", "");
$t->setVar("PHP_SCRIPT_DISABLED", "");
}
else{
$t->setVar("TEMPLATES_DISABLED", "disabled=\"disabled\"");
$t->setVar("PHP_SCRIPT_DISABLED", "disabled=\"disabled\"");
}
return $t->toString();
}
/** @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;
}
if(empty($this->phpfile)){
logError(3, "No PHP script selected", __FILE__, __LINE__);
$this->addError("Bitte wählen Sie ein PHP-Script aus!");
return false;
}
return true;
}
/** @see CmsObject::doPublish()
*/
//----------------------------------------------
function doPublish(){
//----------------------------------------------
return "";
}
/** @see CmsObject:show()
*/
//----------------------------------------------
function show(){
//----------------------------------------------
require_once(PHP_SCRIPT_DIR.$this->phpfile);
$t = new Template(TEMPLATE_DIR.$this->template);
$t->setVar("CONTENT", doPhpScript($this));
if(!$this->parentObj){
$this->parentObj = FlexiconFactory::instanceById($this->parentId);
}
$parent = clone($this->parentObj);
$parent->load();
$t = $parent->printMenu($t);
$t->setVar("TITLE", $this->toString());
return $t->toString();
}
/** @see CmsObject::preview()
*/
//---------------------------------------------
function preview(){
//---------------------------------------------
return $this->show();
}
/** @see CmsObject::getCssClass()
*/
//------------------------------------------------
function getCssClass(){
//------------------------------------------------
return "itemPhpPage";
}
};
?>