<?php
/**
* Klasse zum Verwalten von Base Template Modulen
*
* Methoden für Modulanmeldung und das parsen
*
* @package BTPL_module
* @access public
* @author Jörg Stöber <hide@address.com>
* @version 0.1 ($Id: BTPL_module.class.php,v 1.6 2004/05/06 14:56:44 cb_fog Exp $)
*/
class BTPL_module {
var $parsed = false;
var $modules = array();
var $modOrder = array();
var $loadOrder = array();
var $arrayList = array();
var $metaData = array();
function BTPL_module() { }
function setRelPath($value) {
$this->rel = $value;
}
function setTemplate(&$value) {
$this->template = $value;
}
function setCBPath($value) {
$this->CB_path = $value;
}
function setVariable($key, $value) {
$this->{$key} = $value;
}
/**
* Setzen der MetaDaten
*
* @access public
* @param array $metaData Array mit den Metadaten wie title etc.
* @return boolean true/false Erfolg des Vorgangs
*/
function setMetaData($metaData) {
if(is_array($metaData)) {
$this->metaData = $metaData;
return true;
} else {
return false;
}
}
/**
* Abrufen der MetaDaten
*
* @access public
* @return array $metaData Array mit Meta Informationen
*/
function getMetaData() {
return $this->metaData;
}
/**
* Anmelden eines Moduls
*
* @access public
* @param array $args Array mit den Infos zum Modul
*/
function setModule($args) {
if(is_array($args)) {
if($args[name] != "") {
// Erzeugung eines Modul Behälters
$newModule =& new BTPL_moduleContainer();
// Eintragung der wichtigsten Daten in den Container
$newModule->setName($args[name]);
$newModule->setPosition($args[position]);
$newModule->setDir($args[directory]);
$newModule->setStartFile($args[file]);
// Wenn Flag main gesetzt ist, dieses auch kenntlich machen
if($args[main]) {
$newModule->setMainStatus(1);
}
// Wenn ein Fehlerhafter loadModule Eintrag vorlag (leerer Name,
// leere Verzeichnisangabe), wird das Modul nicht übernommen
if(!$newModule->getErrorStatus()) {
$this->loadOrder[] = $newModule->getName();
$this->modules[$newModule->getName()] = &$newModule;
}
}
}
}
/**
* Setzen der Ausgabereihenfolge
*
* @access public
* @param string $name Name des Moduls
*/
function displayModule($name) {
if(is_object($this->modules[$name])) {
$this->modOrder[] = $name;
}
}
/**
* Laden aller globalen Variablen. Danach laden aller Module. Die Ergebnisse
* werden in dem ContainerObjekt eingetragen. Die Container aktualisieren sich
* von selbst, da diese per Referenz geladen wurden.
*
* @access public
*/
function parseModules() {
// alle globalen Variablen verfügbar machen
extract($_REQUEST);
extract($GLOBALS);
global $tpl;
$CB_path = $this->CB_path;
$path['cb'] = $CB_path;
$tpl->assign("RELPATH", $rel);
foreach($this->loadOrder as $key => $value) {
// Ableitung per Referenz, alle Änderungen werden sofort übernommen
$currentModule = &$this->modules[$value];
// Abfrage der grundlegenden Modulinfos
$displayName = $currentModule->getName();
$displayPos = $currentModule->getPosition();
$directory = $currentModule->getDir();
$startFile = $currentModule->getStartFile();
/*
* Falls zusätzliche Werte gesetzt wurden -> abfragen
*/
if(is_array($currentModule->values)) {
extract($currentModule->values);
}
$location = $rel."modules/".$directory."/";
$tpl->assign("LOCATION", $location);
$tplImgLocation = $location."templates/images/";
$tplLocation = $location."templates/";
if(is_dir($rel."templates/".$BTPL_skinSelected."/modules/".$directory)) {
$tplImgLocation = $rel."templates/".$BTPL_skinSelected."/modules/".$directory."/images/";
$tplLocation = $rel."templates/".$BTPL_skinSelected."/modules/".$directory;
}
$tpl->assign("MODULE_IMAGE_DIR", $tplImgLocation);
$tpl->template_dir = $tplLocation;
/* aktuelle MetaDaten abrufen */
$BTPL_metaData = $this->getMetaData();
// Wenn für das Modul das flag 'main' aktiviert ist,
// wird es anders eingebunden, da Hauptmodule auch SubModule besitzen
if(!$currentModule->getMainStatus()) {
ob_start();
include($location.$startFile);
$thisContent = ob_get_contents();
ob_end_clean();
} else {
ob_start();
require($location."module.config.php");
if(!empty($sub) && ereg("([a-zA-Z0-9]*)", $sub)) {
require($location.$loadConf[$sub]);
} else {
if($loadConf['default'] != "") {
require($location.$loadConf['default']);
}
}
$thisContent = ob_get_contents();
ob_end_clean();
}
/* MetaDaten wieder einschreiben, ob geändert oder nicht */
$this->setMetaData($BTPL_metaData);
$currentModule->setContent($thisContent);
}
$tpl->template_dir = $t_basedir;
$this->parsed = true;
}
/**
* Nachträgliches Laden eines Moduls
* Diese Methode ruft nachträglich nach einem anderen Modul. (zB Comment System)
*
* @access public
* @param string $module Verzeichnis des Moduls
* @param string $startFile Modul Datei
* @param string $tplLocation Ort der Templates
* @param array $options Übergebene Optionen die das Modul evtl. braucht
* @return object $currentModule Objekt mit Modulinformationen und Output
*/
function callModule($module, $startFile, $tplLocation, $options = array()) {
// alle globalen Variablen verfügbar machen
foreach($_REQUEST as $k => $v) $$k = $v;
foreach($GLOBALS as $k => $v) $$k = $v;
foreach($options as $k => $v) $$k = $v;
$tpl = &$GLOBALS[tpl];
$tpl->addGlobalVar("RELPATH", $rel);
$currentModule = new BTPL_moduleContainer();
// Eintragung der wichtigsten Daten in den Container
$currentModule->setName("custom");
$currentModule->setPosition("custom");
$currentModule->setDir($module);
$currentModule->setStartFile($startFile);
$location = $rel."modules/".$module."/";
$tpl->addGlobalVar("LOCATION", $location);
$tplImgLocation = $tplLocation."images/";
$tpl->addGlobalVar("MODULE_IMAGE_DIR", $tplImgLocation);
$tpl->setBaseDir($tplLocation);
ob_start();
include($location.$startFile);
$thisContent = ob_get_contents();
ob_end_clean();
$currentModule->setContent($thisContent);
$tpl->setBaseDir($t_basedir);
return $currentModule;
}
/**
* Die Module werden entsprechend der Reihenfolge in globale Arrays überführt.
* Diese haben die Form $side.ModuleContent.
*
* @access public
*/
function displayParsedModules() {
if(!$this->parsed == true) {
// Falls noch nicht geparst wurde, wird das jetzt nachgeholt
$this->parseModules();
}
$content = array();
foreach($this->modOrder as $key => $value) {
$currentModule = &$this->modules[$value];
$displayName = $currentModule->getName();
$displayPos = $currentModule->getPosition();
$displayContent = $currentModule->getContent();
// Festlegung des Arraynamens, setzt sich aus der
// Positionsangabe vom loadModules Befehl aus der
// modules.php zusammen
$arrayName = $displayPos."ModuleContent";
// Arraynamen ablegen
$this->arrayList[] = $arrayName;
// Forsorglich das Array global bekannt machen
global ${$arrayName};
// Erzeugung des Array's per dynamischer Variable
${$arrayName}[] = $displayContent;
$content[$displayPos][] = $displayContent;
}
return $content;
}
/**
* Rückgabe der ArrayListe
*
* @access public
*/
function getArrayList() {
return $this->arrayList;
}
}
/**
* Container Klasse zur Aufnahme der einzelnen Module
*
* Methoden zur Verwaltung der Modulinformationen und SpeicherObjekt
* für einzelne Module
*
* @package BTPL_module
* @access public
* @author Jörg Stöber <hide@address.com>
* @version 0.1 ($Id: BTPL_module.class.php,v 1.6 2004/05/06 14:56:44 cb_fog Exp $)
*/
class BTPL_moduleContainer {
var $name, $position, $content;
var $error = false;
function BTPL_moduleContainer() { }
/**
* Setzen des Modulnamens
*
* @access public
* @param string $value Name des Moduls
*/
function setName($value) {
if(empty($value)) {
$this->error = true;
}
$this->name = $value;
}
/**
* Rückgabe des Modulnamens
*
* @access public
*/
function getName() {
return $this->name;
}
/**
* Setzen der Modulposition
*
* @access public
* @param string $value Position des Moduls
*/
function setPosition($value) {
if(empty($value)) {
$this->error = true;
}
$this->position = $value;
}
/**
* Rückgabe der Modulposition im Layout
*
* @access public
*/
function getPosition() {
return $this->position;
}
/**
* Setzen des Verzeichnisses, wo das Modul liegt
*
* @access public
* @param string $value Verzeichnis des Moduls
*/
function setDir($value) {
if(empty($value)) {
$this->error = true;
}
$this->directory = $value;
}
/**
* Rückgabe des Modulverzeichnisses
*
* @access public
*/
function getDir() {
return $this->directory;
}
/**
* Setzen der Startdatei
* Diese datei wird bei Ausführung der Module eingebunden
*
* @access public
* @param string $value Startdatei des Moduls
*/
function setStartFile($value) {
if(empty($value)) {
$this->error = true;
}
$this->startFile = $value;
}
/**
* Rückgabe des Namens der Startdatei
*
* @access public
*/
function getStartFile() {
return $this->startFile;
}
/**
* Speicherung des erzeugten Contents
*
* @access public
* @param string $value Content des Moduls
*/
function setContent($value) {
$this->content = $value;
}
/**
* Rückgabe des Modulcontents
*
* @access public
*/
function getContent() {
return $this->content;
}
/**
* Ist Module ein Hauptmodul oder nicht?
*
* @access public
* @param string $value Content des Moduls
*/
function setMainStatus($value) {
$this->mainStatus = $value;
}
/**
* Rückgabe, ob Modul Hauptmodul ist oder nicht
*
* @access public
*/
function getMainStatus() {
return $this->mainStatus;
}
/**
* Rückgabe des Fehlerstatus
*
* @access public
*/
function getErrorStatus() {
return $this->error;
}
}
?>