websiteWebsite
codingteam CodingTeam
A free forge, lightweight and extensible.

 

Browse the code

Revision log Information on the revision
Revision: 93 (differences)
Author: xbright
Log message: * Some work on the Template class and the .tpl
* Added an .htaccess option
Change revision:
<?php
# ***** BEGIN LICENSE BLOCK *****
#
#    This file is a part of CodingTeam. See <http://www.codingteam.net>.
#    Copyright (C) 2007 CodingTeam Team (See AUTHORS and THANKS for details)
#
#    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 3 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, see <http://www.gnu.org/licenses/>.
#
# ***** END LICENSE BLOCK *****
 
class Template {
    private $tpl, $page, $ct_session, $ct_db, $basedir;
 
    function __construct ($tpl, $page, $ct_session, $ct_db, $basedir)
    {
        if ($ct_session->isLogged($ct_db)) // WARNING: add a '!' before test for the true return
        {
            $cachename = ereg_replace('/', '-', $page);
            $cachenamefile = $basedir.'/public/cache/'.md5($cachename).'.ctcache';
            if (@filemtime($cachenamefile) < time() - ( 3600 * 24 * 360 ))
            {
                ob_start();
                
                $this->parse($tpl, $page, $ct_session, $ct_bd, $basedir);
    
                $cachecontent = ob_get_contents();
                ob_end_flush();
                $filec = fopen($cachenamefile, 'w');
                fwrite($filec, $cachecontent);
                fclose($filec);
            }
            else
                include ($cachenamefile);
        }
        else
            $this->parse($tpl, $page, $ct_session, $ct_bd, $basedir);     
    }
    
    function parse ($tpl, $page, $ct_session, $ct_db, $basedir)
    {
        // Load user authentification module and requested module
        require($basedir.'/inc/modules/head_member/head_member.php');
        $head_member = new head_member();
        $head_member->treatForms($ct_db);    
    
        $pagetag = explode('/', $page);
        foreach ($pagetag as $tag_ => $value)
            $req[$i++] = $value;
            
        $temp['tpl:lang'] = $req[1];
        $temp['tpl:requesturi'] = substr($page, 4);
 
        require($basedir.'/inc/modules/'.$req[2].'/'.$req[2].'.php');
        $view_loaded = new Module();
        $view_loaded->treatForms($ct_db);       
    
        // Import the .tpl file
        $this->tpl_file = file_get_contents($tpl);
        $temp['tpl:cssdir'] = '/inc/templates/';
        $temp['tpl:images'] = '/public/images/';
    
        // Set global values
        $temp['slogan'] = _('Create. Participate. Evolve. Free Software.');
        $temp['button_search'] = _('Search');
        $temp['link_freesoftwareprojects'] = _('Free software projects');
        $temp['link_forum'] = _('Forum');
        $temp['link_jabberserver'] = _('Jabber Server');
        $temp['link_notepad'] = _('Notepad');
        $temp['link_addproject'] = _('Add your project');
        $poweredby = _('Powered by CodingTeam <strong>%s</strong>');
        $temp['poweredby'] = str_replace('%s', file_get_contents($basedir.'/VERSION'), $poweredby);
        $temp['link_about'] = _('About CodingTeam');
        $temp['link_donation'] = _('Make a donation');
        
        // Set global views
        ob_start();
        $head_member->getPageContent($ct_session, $ct_db);
        $temp['view:head_member'] = ob_get_clean();
 
        // Set page data
        $view_loaded->getPageData();
        $temp['title'] = $view_loaded->title;
        $temp['htmlmeta'] = $view_loaded->meta;
 
        // Set page menu
        ob_start();
        $view_loaded->getPageMenu();
        $temp['view:pagemenu'] = ob_get_clean(); 
 
        // Set page content
        ob_start();
        $view_loaded->getPageContent();
        $temp['view:pagecontent'] = ob_get_clean();
 
        // Edit the template
        foreach ($temp as $key => $value)
        {
            $search[] = '{'.$key.'}';
            $replace[] = $value;
        }
        $this->tpl_show = str_replace($search, $replace, $this->tpl_file);
        
        // Show the result
        echo $this->tpl_show;
    }
 
}
?>