Location: PHPKode > projects > Entier Studio > entierstudio/framework/viewtemplate.parser.php
<?php
/**
 * Entier Studio
 *
 * LICENSE
 *
 *	Copyright 2006 Entier Studio team.
 *
 *	Licensed under the Apache License, Version 2.0 (the "License");
 *	you may not use this file except in compliance with the License.
 *	You may obtain a copy of the License at
 *
 *		http://www.apache.org/licenses/LICENSE-2.0
 *
 *	Unless required by applicable law or agreed to in writing, software
 *	distributed under the License is distributed on an "AS IS" BASIS,
 *	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *	See the License for the specific language governing permissions and
 *	limitations under the License.
 *
 * @package    entier.framework
 * @copyright  Copyright (c) 2006 Entier Studio team. All rights reserved.
 * @version	   $Id: viewtemplate.parser.php 94 2008-02-03 23:35:48Z yannromefort $
 */
// Comments
//
//    This work is derived from class.FastTemplate.php3 version 1.1.0 as
//    available from http://www.thewebmasters.net/.  That work makes
//    reference to the "GNU General Artistic License".  In correspondence
//    with the author, the intent was to use the GNU General Public License;
//    this work does the same.
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefViewTemplateParser")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefViewTemplateParser", "1");
    //-------------------------------------------------------------------------
    //	Class
    class ViewTemplateParser {
        //---------------------------------------------------------------------
        //	Attributes
        
        /**
         * Template layouts
         * @var	array
         */
        var $m_layouts = array();
        /**
         * Template errors
         * @var	array
         */
        var $m_errors = array();
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
         *
         */
        /**
         * Constructor
         * @access	public
         */
        function ViewTemplateParser() {
        }
        //---------------------------------------------------------------------
        //	Properties
        //
        //	_ErrorSet property
        //
        /*
        * @return	array
        */
        function errorSet() {
            return ($this->m_errors);
        }
        //	_ErrorSet.field_count
        /*
        * @return	integer
        */
        function get_error_count() {
            if (is_array($this->m_errors)) return (count($this->m_errors));
            return (0);
        }
        //---------------------------------------------------------------------
        //	Methods
        
        /**
         * @param	integer	error number
         * @param	string  error message
         */
        function set_error_message($errno, $arg = "") {
            //
            $this->m_errors[$errno] = $arg;
            //
            return (true);
        }
        /**
         * Match layout tag
         * @access	private
         * @param	string	Template source
         * @return	string	Layout name
         */
        function getTemplateTag($source) {
            //	Match first layout tag
            if (@preg_match("(<block:([^()]+)>)sU", $source, $match))            
				return ($match[1]);
			return false;
        }
        /**
         * Check layout end
         * @access	private
         * @param	string	Template source
         * @param	string	Layout name
         * @return	boolean	result flag
         */
        function endTemplateTag($source, $layout) {
            //
            @preg_match("(</block:$layout>)sU", $source, $match);
            return (($match[0] != "</block:$layout>") ? false : true);
        }
        /**
         * Match layout content
         * @access	private
         * @param	string	Template source
         * @param	string	Layout name
         * @param	integer	Layout type
         * @return	string	Layout source
         */
        function getTemplateContent($source, $layout, $type = 0) {
            // Retourne le source de la zone de nom $layout
            @preg_match_all("(<block:$layout>(.*)</block:$layout>)sU", $source, $reg);
            //
            return $reg[$type][0];
        }
        /**
         * Parse template
         * @access	private
         * @param	string	Template source
         * @param	string	Layout name
         * @return	string	Layout parent
         */
        function parseTemplate($source, $layout = ".", $parent = "") {
            // Check defined template
            if (isset($this->m_layouts[$layout])) {
                $this->set_error_message(3, $layout);
                return (false);
            }
            //
            $this->m_layouts[$layout]["parent"] = $parent;
            $this->m_layouts[$layout]["source"] = $source;
            $this->m_layouts[$layout]["insets"] = array();
            // Match inset layouts
            while ($member = $this->getTemplateTag($this->m_layouts[$layout]["source"])) {
                //
                if (!$this->endTemplateTag($source, $member)) {
                    $this->set_error_message(2, $member);
                    return (false);
                }
                //
                $this->parseTemplate($this->getTemplateContent($this->m_layouts[$layout]["source"], $member, 1) , $member, $layout);
                //
                $this->m_layouts[$layout]["insets"][] = $member;
                //
                $this->m_layouts[$layout]["source"] = @str_replace($this->getTemplateContent($this->m_layouts[$layout]["source"], $member, 0) , "|$member|", $this->m_layouts[$layout]["source"]);
                //
                if (count(explode("|$member|", $this->m_layouts[$layout]["source"])) > 2) {
                    $this->set_error_message(3, $member);
                    return (false);
                }
            }
            //
            return (true);
        }
    };
    //	Class
    //-------------------------------------------------------------------------
    
}
//	namespace
//-----------------------------------------------------------------------------
?>
Return current item: Entier Studio