View Single Post
ישן 01-08-06, 06:47   # 1
Second
חבר חדש
 
מיני פרופיל
תאריך הצטרפות: Jul 2006
מיקום: נתניה
גיל: 35
הודעות: 37
שלח הודעה באמצעות MSN אל Second

Second לא מחובר  

מחלקה של Templates

הי אנשים .
לפני כמה ימים עשיתי מחלקה של Templates ורציתי לשמוע על דעתכם.

PHP קוד:
<?
class Template
{
    var 
$folder;
    var 
$files = array();
    var 
$loops = array();

    function 
Template$tpl_folder "." )
    {
        if( 
is_file($tpl_folder) )
        {
            
$this->folder $tpl_folder;
        }
    }

    function 
loadFile$file_name$tpl_file )
    {
        
$file_path $this->folder $tpl_file;

        if( 
is_file($file_path) && !array_key_exists($file_name$this->files))
        {
            
$this->loops[$file_name] = array();

            
$handle    fopen$file_path"r" );
            
$temp    fread$handlefilesize($file_path) );
            
fclose($handle);

            
$patten "/\A([\s\S]*)<!-- BEGIN (.*?) -->([\s\S]*)<!-- END (.*?) -->([\s\S]*)\z/i";
            
$count preg_match($patten$temp);
            while( 
$count != )
            {
                
$loop_name preg_replace($patten"\\2"$temp1);
                
$this->loops[$file_name][$loop_name] = preg_replace($patten"\\3"$temp1);
                
$temp preg_replace($patten"\\1{loop.\\2}\\5"$temp1);
                
$count preg_match($patten$temp);
            }

            
$this->files[$file_name] = $temp;
        }
    }

    function 
do_loop$file_name$loop_name$info )
    {

        if( 
array_key_exists($file_name$this->files) && array_key_exists($loop_name$this->loops[$file_name]) && is_array($info) )
        {
            
$temp $this->loops[$file_name][$loop_name];
            foreach( 
$info as $key=>$val )
            {
                
$temp str_replace("{".$loop_name.".".$key."}"$val$temp);

            }

            
$this->files[$file_name] = preg_replace("/\A([\s\S]*){loop.$loop_name}([\s\S]*)\z/i""\\1".$temp."{loop.$loop_name}\\2"$this->files[$file_name]);
        }
    }

    function 
block_vars$file_name$info )
    {
        if( 
array_key_exists($file_name$this->files) && is_array($info) )
        {
            foreach( 
$info as $key=>$val )
            {
                
$this->files[$file_name] = str_replace("{".$key."}"$val$this->files[$file_name]);
            }
        }
    }

    function 
out$file_name )
    {
        if( 
array_key_exists($file_name$this->files) )
        {
            
$this->files[$file_name] = preg_replace("/\{\S+\}/i"""$this->files[$file_name]);
            echo 
$this->files[$file_name];
        }
    }
}
?>
תנו הצעות לשיפורים (:
Attached Files כדי לראות קבצים מצורפים, מספר ההודעות שלך חייב להיות גדול מ,.. או שווה ל 10
  Reply With Quote