Seite 3 von 3

Verfasst: 07.11.2006 17:40
von Sgt. Absolom
@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

Verfasst: 07.11.2006 17:46
von Olli Oberhausen
Sgt. Absolom hat geschrieben:Aber ich denke für das, was ich machen will, ist die aktuelle Lösung ausreichend.

Gruß
Thorsten
Wenn das deine denkweise ist - ok....

Du wirst aber immer wieder probleme bekommen wenn du sagst:
Wie gesagt, ich möchte ein eigenes kleines CMS programmieren
Nur ein tipp von mir, wenn du nacher nicht alles umstellen wilst.

Olli

Verfasst: 07.11.2006 17:54
von Sgt. Absolom
Wie gesagt ich schaue es mir mal an und im Moment bin ich sowieso noch in der Planungsphase.

Gruß
Thorsten

Verfasst: 07.11.2006 22:17
von Ambience
hab (bin noch dabei) eine neue template classe erstellt...

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;
  }
}
?>
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.

Verfasst: 08.11.2006 17:27
von Sgt. Absolom
Danke. Ich werds mir die Tage auch mal anschauen.

Gruß
Thorsten