Annonce

#1 2006-05-12 22:02:36

GoldenEye
Membre
Inscription : 2006-03-24
Messages : 7

Re : Une class template

Voici ma class de template sous license GNU GPL avec 309 l. qui contient encore quelques bugs (vous pourrez voir l.:62 Recodage total (en beta):

<?php
/****************************************************************************
|    
|    #    Nom: sql_pusher.class.php
|    #    Auteur : Groupe Active Board
|    #    Commencé : Le 28 Mars 2006
|    #    Description : Cette classe permet de gérer MySQL simplement
|    #    Version: 4.0.0
|
****************************************************************************/

/***************************************************************************
*
*  Ce programme est un programme libre; vous pouvez le reditribuer et/ou le modifier
*  sous les termes de la GNU (License au grand public) publié par
*  la Free Software Foudation (FSF); vers la version 2 de la license, ou (selon le choix)
*  une version supérieur.
*
*
****************************************************************************/

/***************************************************************************
 *
 *  This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *
 ***************************************************************************/
/**************************************************************************
##################################################
#
#---------------------[ HISTORIQUE ]---------------------------------------------------------------------------------------
#
----------------------------------------------------------------------------

{ VERSION 1 } ------------------- { PEU COMPLETE} 
#_-~~~ 28/03/2006  ~~~-_// Version 1.0.0: 1ère version (bug)
#_-~~~ 01/04/2006  ~~~-_// Version 1.1.0: Plusieurs modification (bug)
{ VERSION 2 } ------------------- { GROS RECODAGE BUG PRESENT} 
#_-~~~ 05/04/2006  ~~~-_// Version 2.0.0: Recodage complet (bug)
#_-~~~ 08/04/2006  ~~~-_// Version 2.0.1: Quelques debogage (bug)
#_-~~~ 09/04/2006  ~~~-_// Version 2.0.2: Correction de tout les bugs trouvés (fonctionnel)
#_-~~~ 09/04/2006  ~~~-_// Version 2.1.0: Modification d'une fonction (fonctionnel)
#_-~~~ 11/04/2006 ~~~-_// Version 2.1.1: Ajout des commentaires de modification + modification de certaines fonction + modification de l'indentation (fonctionnel)
#_-~~~ 12/04/2006 ~~~-_// Version 2.1.2: Ajout d'une erreur. (fonctionnel)
#_-~~~ 15/04/2006 ~~~-_// Version 2.1.3: Quelques modifications. (fonctionnel)
#_-~~~ 21/04/2006 ~~~-_// Version 2.2.0: Ajout du multi tpl + petit nétoyage~(bug)
{ VERSION 3 } ------------------- { PETIT RECODAGE} 
#_-~~~ 29/04/2006 ~~~-_// Version 3.0.0: Petit recodage (bug)
{ VERSION 4 } ------------------- { ENORME RECODAGE} 
#_-~~~ 30/04/2006 ~~~-_// Version 4.0.0: Recodage total (en beta)
------------------------------------------------------------------------------
##################################################
//--------------------------------[ DEBUT CORRECTION ]----------------------------------------------------
// V 2.1.1 : Ligne 205 (cf: ligne 202) [ ERRONE )
// V 4.0.0 : Tout
//--------------------------------[ FIN CORRECTION ]--------------------------------------------------------
***************************************************************************/
/*
** Classe Template,  codée par GoldenEye (par rapport à la class OpB), 
** vous permettra de passer facilement d'un design
** à un autre. Ce moteur de template à été
** codée simplement pour que la plupart 
** puisse la comprendre.
*/

class Template
{
    //--------------------------
    // Déclaration variable
    // template.
    //--------------------------
    var $path_theme        =    'themes';
    var $theme            =    'dAcB';
    
    var $file            =    array();
    var $vars            =     array();
    var $block            =     array();
    var $block_vars        =     array();
    
    var $glob_content    =     array();
    
    //--------------------------
    // Déclaration variable
    // erreur.
    //--------------------------
    
    var $error700        =    'Error général: Aucun array déclaré à la fonction ';
    var $error700_1        =    'Error général: Aucun root déclaré';
    var $error700_2        =    'Error général: Aucun fichier template ouvert';
    var $error701         =     'put_root(): Répertoire introuvable.';
    var $error701_1     =     'put_root(): Impossible d\'ouvrir le répertoire.';
    var $error702        =    'put_filename(): Fichier introuvable.';
    var $error702_1        =    'put_filename): Impossible d\'ouvrir le fichier.';
    var $error703        =    'put_var(): Un des deux paramètre est vide.';
    var $error703_1        =    'put_var(): Impossible de mettre une valeur.';
    var $error704        =    'put_vars(): Un des deux paramètre est vide.';
    var $error704_1        =    'put_vars(): Impossible de mettre des valeurs.';
    var $error705        =    'put_block_vars(): Un des deux paramètre est vide.';
    var $error705_1        =    'put_block_vars(): Impossible de mettre des blocks.';    
    var $error706        =    'modify_theme(): Un des deux paramètre est vide.';
    var $error706_1        =    'modify_theme(): Impossible de changer de thème.';
    
    
    
    function put_root()
    {
        $path_theme = $this->path_theme;
        $theme = $this->theme;
        if(!file_exists($path_theme.'/'.$theme.'/'))
        {
            $root = $path_theme.'/'.$theme.'/';
            die($this->error701);
            return FALSE;
        }
        else
        {
            $root = $path_theme.'/'.$theme.'/';
            $this->root = $path_theme.'/'.$theme.'/';
            return TRUE;
        }
        die($this->error701_1);
        return FALSE;
    }
    
    
    
    function put_filename($file_array)
    {
        if(!empty($file_array))
        {
            if($this->root !== FALSE)
            {
                $this->put_root();
                foreach($file_array as $handle => $filename)
                {
                    if(!file_exists($this->root.$filename))
                    {
                        die($this->error702.' : '.$this->root.$filename);
                        return FALSE;
                    }
                    else
                    {
                        $this->handle = $handle;
                        $this->filename[$this->handle] = $filename;
                        $this->glob_content[$handle] = $this->filename[$this->handle];
                        $tpl = @file($this->root.$filename);
                        $this->glob_content[$handle] = @implode("\n", $tpl);
                        return TRUE;
                    }
                }
            }
            else
            {
                die($this->error700_1);
                return FALSE;
            }
        }
        else
        {
            die($this->error702);
        }
    }
    
    
    
    function put_var($handle, $key, $value)
    {
        if($this->filename !== FALSE)
        {
            if(!empty($handle) AND !empty($value))
            {
                $this->vars[$key] = $value;
                $this->glob_content[$handle] = str_replace('{'.$key.'}', $value, $this->glob_content[$handle]);
                return TRUE;
            }
            else
            {
                die($this->error703);
                return FALSE;
            }
        }
        else
        {
            die($this->error700_2);
        }
        die($this->error703_1);
    }
    
    
    
    function put_vars($handle, $array_vars)
    {
        if($this->filename !== FALSE)
        {
            if(!is_array($array_vars))
            {
                die($this->error700.'put_vars');
                return FALSE;
            }
            else
            {
                if(!empty($array_vars))
                {
                    foreach($array_vars as $key => $value)
                    {
                        $this->vars[$handle] = $value;
                        $this->glob_content[$handle] = $this->vars[$handle];
                        $this->glob_content[$handle] = str_replace('{'.$key.'}', $value, $this->glob_content[$handle]);
                        return TRUE;
                    }
                }
                else
                {
                    die($this->error704);
                    return FALSE;
                }
            }
        }
        else
        {
            die($this->error700_2);
            return FALSE;
        }
        die($this->error704_1);
        return FALSE;
    }
    
    
    
    function put_block_vars($block_name, $values)
    {
        if($this->filename !== FALSE)
        {
            $this->block_vars[$block_name][] = $values;
            return TRUE;
        }
        else
        {
            die($this->error700_2);
            return FALSE;
        }
        die($this->error705_1);
        return FALSE;
    }
    
    
    
    function get_block_vars($block_name)
    {
        $this->block_name[$values] = $block_name;
        $this->block_vars[$this->block_name][] = $this->block_vars[$block_name];
        if(array_key_exists($this->block_name, $this->block))
        {
            return $this->block[$this->block_name];
        }
        else
        {
            die($error700.'get_block_vars');
            return FALSE;
        }
    }
    
    
    
    function modify_theme($path_theme, $theme)
    {
        if(!empty($path_theme) AND !empty($theme))
        {
            $this->theme = $theme;
            $this->path_theme = $path_theme;
            return TRUE;
        }
        else
        {
            die($error706);
            return FALSE;
        }
        die($error706_1);
        return FALSE;
    }
    
    
    
    function reset_template($handle)
    {
        unset($this->glob_content[$handle]);
    }
    
    
    
    function printer($handle)
    {
        echo $this->glob_content[$handle];
        $this->reset_template($handle);
    }
}
?>

Hors ligne

Pied de page des forums