@Olli Oberhausen: Danke ich schaue mir das bei Gelegenheit mal an. Aber ich denke für das, was ich machen will, ist die aktuelle Lösung ausreichend.
Gruß
Thorsten
Zusammenspiel Sprachdateien und Templates???
-
- Mitglied
- Beiträge: 103
- Registriert: 27.07.2004 22:24
- Wohnort: Eppelheim
- Kontaktdaten:
- Olli Oberhausen
- Mitglied
- Beiträge: 561
- Registriert: 22.10.2004 01:03
- Wohnort: Oberhausen NRW
- Kontaktdaten:
Wenn das deine denkweise ist - ok....Sgt. Absolom hat geschrieben:Aber ich denke für das, was ich machen will, ist die aktuelle Lösung ausreichend.
Gruß
Thorsten
Du wirst aber immer wieder probleme bekommen wenn du sagst:
Nur ein tipp von mir, wenn du nacher nicht alles umstellen wilst.Wie gesagt, ich möchte ein eigenes kleines CMS programmieren
Olli
Neulich im Zoo: Papa, guck mal, da sind Linuxe...
KB-Suche :: db_update_generator :: phpMyAdmin
Winmerge :: Zend Studio
KB-Suche :: db_update_generator :: phpMyAdmin
Winmerge :: Zend Studio
-
- Mitglied
- Beiträge: 103
- Registriert: 27.07.2004 22:24
- Wohnort: Eppelheim
- Kontaktdaten:
hab (bin noch dabei) eine neue template classe erstellt...
Basiert ein wenig auf phpBB aber habe das alles selbst geschrieben und werde es für meine Bedürfnisse schreiben.. aber dort solltest du schon durchblicken... ist bis jetzt noch nicht ganz funktionsfähig... aber da kannst ja mal gucken wie sowas im großen und ganzen gemacht wird.
Code: Alles auswählen
<?php
class Template
{
//
// private variables
//
private $assigns = array(); // saves the added arrays/strings
private $file = array(); // saves the added file
private $root; // saves the root directory of the templates dir
/**
*
* Constructor and method to set the templates root dir
*
* @access puplic
* @param strin $dir
* @return true/false
*
**/
function Template($dir = '.')
{
if (!dir($dir))
{
die("Template->Template(): Can´t set any root dir for $dir");
}
$this->root = $dir;
return true;
}
/**
*
* function to set handle and file for display
*
* @access puplic
* @param string $handle
* @param string $tpl_file
* @return true
*
**/
function set_filename($handle, $tpl_file)
{
if (empty($handle))
{
die('Template->set_filename(): Can´t set a filename for an empty handle');
}
if (empty($tpl_file))
{
die("Template->set_filename(): Can´t set an empty file for $handle");
}
if (!file_exists($tpl_root . $tpl_file))
{
die("Template->set_filename(): File $file doesn´t exists in $tpl_root$tpl_file");
}
$this->file[$handle] = $tpl_file;
return true;
}
/**
*
* function to assign normaly key´s and values
*
* @access puplic
* @param string $key
* @param string $value
* @return true
*
**/
function assign($key, $value)
{
if (empty($key))
{
die('Template->assign(): Can´t add an empty Key');
}
if (empty($value))
{
die("Template->assign(): Can´t add an empty Value for Key: $key");
}
$this->assigns[$key] = $value; // adds key and value
return true;
}
/**
*
* function to assign arrays
*
* @access puplic
* @param array $vars_array
* @return true
*
**/
function assign_vars($vars_array)
{
if (!is_array($vars_array) OR is_object($vars_array))
{
die('Template->assign_vars(): You have to add an array');
}
while (list($key, $value) = each($vars_array))
{
$this->assigns[$key] = $value; // adds key and value
}
return true;
}
/**
*
* function to compile and display the template which was assigns by set_filename
*
* @access puplic
* @param string $handle
* @return string $code
*
**/
function display($handle)
{
if (empty($handle))
{
die('Template->display(): Can´t display an empty handle');
}
if (!in_array($handle, $this->file))
{
die("Template->display(): You have to add this handle($handle) in the method: set_filename");
}
$code = file($this->root . $this->file[$handle]);
$code = implode('', $code);
$code = str_replace('\\', '\\\\', $code);
$code = str_replace('\'', '\\\'', $code);
$code_lines = explode("\n", $code);
$line_count = sizeof($code_lines);
for ($i = 0; $i < $line_count; $i++)
{
if (preg_match('#\{([a-z0-9\-_])\}#is', $code_lines[$i], $m))
{
$code = str_replace("{$m[1]}", $this->assigns[$m[1]], $code);
}
}
echo $code;
return true;
}
}
?>
-
- Mitglied
- Beiträge: 103
- Registriert: 27.07.2004 22:24
- Wohnort: Eppelheim
- Kontaktdaten: