Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

template.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  This program is free software; you can redistribute it and/or
00004  modify it under the terms of the GNU General Public License
00005  as published by the Free Software Foundation; either version 2
00006  of the License, or (at your option) any later version.
00007 
00008  This program is distributed in the hope that it will be useful,
00009  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  GNU General Public License for more details.
00012 
00013  You should have received a copy of the GNU General Public License
00014  along with this program; if not, write to the Free Software
00015  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00016  ***************************************************************************/
00017 
00022 class Template
00023 {
00024     var $strPath;                   
00025     var $strTmpl;                   
00026     var $strHtml;                   
00027     var $aArea         = array();   
00028     var $aReplacements = array();   
00029     var $strAreaPre;
00030     var $strAreaStart;
00031     var $strAreaEnd;
00032 
00036     function Template ( $strPath )
00037     {
00038         // replace windows backslash with forward slash
00039         $strPath = str_replace('\\', '/', $strPath);
00040 
00041         // remove '/' from string end
00042         $strPath = preg_replace("-/*$-", '', $strPath);
00043 
00044         // add '/'
00045         $strPath .= '/';
00046         if ( !is_dir ( $strPath ) )
00047         {
00048             // template dir does not exist -> set default dir
00049             $strPath = './templates/default/';
00050         }
00051         $this->strPath = $strPath;
00052 
00053         $this->strAreaPre   = '<!--';
00054         $this->strAreaStart = 'Start-->';
00055         $this->strAreaEnd   = 'End-->';
00056     }
00057 
00061     function getPath()
00062     {
00063         return $this->strPath;
00064     }
00065 
00069     function setTemplate($strFile)
00070     {
00071         // check default templates, if an other template set is used
00072         $strPath = ( !file_exists( $this->strPath.$strFile ) ) ? './templates/default/' : $this->strPath;
00073 
00074         if( ( $this->strTmpl = @file_get_contents($strPath.$strFile, true) ) === false )
00075             die("<b>Das Template: $strFile <br> Im Skript: $_SERVER[PHP_SELF] <br> wurde nicht gefunden!</b>");
00076         $this->strHtml = $this->strTmpl;
00077         return true;
00078     }
00079 
00084     function get_area( $strAreaName )
00085     {
00086         if ( !isset ( $this->aArea[$strAreaName] ) )
00087         {
00088             $this->split_area ( $strAreaName );
00089             // check if area exists now
00090             if ( !isset ( $this->aArea[$strAreaName] ) )
00091             {
00092                 die ( 'Template Fehler: '.$strAreaName.' wurde nicht gefunden.' );
00093             }
00094         }
00095 
00096         // copy area contents
00097         $strArea = $this->aArea[$strAreaName];
00098 
00099         $aKeys = array_keys($this->aReplacements);
00100         for ($i = 0; $i < count($aKeys); $i++)
00101         {
00102             $strArea = str_replace( '%_'.$aKeys[$i].'_%', $this->aReplacements[$aKeys[$i]], $strArea );
00103         }
00104 
00105         return rtrim( preg_replace( '/%_(\w*)_%/Ui', '', $this->myrecode( $strArea ) ) );
00106     }
00107 
00111     function get_html()
00112     {
00113         return $this->strHtml;
00114     }
00115 
00119     function get_tmpl()
00120     {
00121         return $this->strTmpl;
00122     }
00123 
00132     function split_area ( $strAreaName, $booDelete=false )
00133     {
00134         $intNameLen   = strlen ( $strAreaName );
00135         $intEndLen    = strlen ( $this->strAreaPre ) + strlen ( $this->strAreaEnd );
00136         $intPosStart  = strpos ( $this->strHtml, $this->strAreaPre . $strAreaName . $this->strAreaStart );
00137         $intPosEnd    = strpos ( $this->strHtml, $this->strAreaPre . $strAreaName . $this->strAreaEnd ) + $intNameLen + $intEndLen;
00138 
00139         if ( $intPosStart === false || $intPosEnd === false )
00140         {
00141             // area cannot be found
00142             return false;
00143         }
00144 
00145         $intAreaStart = $intPosStart + $intNameLen + strlen ( $this->strAreaPre ) + strlen ( $this->strAreaStart );
00146         $intAreaLen   = $intPosEnd - $intAreaStart - $intNameLen - $intEndLen;
00147 
00148         $strAreaVar   = (!$booDelete) ? '%_' . strtoupper ( $strAreaName ) . '_%' : '';
00149 
00150         $this->aArea[$strAreaName] = substr ( $this->strHtml, $intAreaStart, $intAreaLen );
00151         $this->strHtml = substr ( $this->strHtml, 0, $intPosStart ) . $strAreaName . substr ( $this->strHtml, $intPosEnd );
00152 
00153         return true;
00154     }
00155 
00162     function addReplacements( $aNewReplacements )
00163     {
00164         $this->aReplacements = array_merge ( $this->aReplacements, $aNewReplacements );
00165     }
00166 
00170     function getReplacements()
00171     {
00172         return array_keys ( $this->aReplacements );
00173     }
00174 
00175     function myrecode( $strString )
00176     {
00177        $strString = str_replace( "Ä", "&Auml;", $strString );
00178        $strString = str_replace( "Ö", "&Ouml;", $strString );
00179        $strString = str_replace( "Ü", "&Uuml;", $strString );
00180        $strString = str_replace( "ä", "&auml;", $strString );
00181        $strString = str_replace( "ö", "&ouml;", $strString );
00182        $strString = str_replace( "ü", "&uuml;", $strString );
00183        $strString = str_replace( "ß", "&szlig;", $strString );
00184 
00185        return( $strString );
00186     }
00187 
00188 }

Generated on Sun May 8 19:29:45 2005 for PhpMap by  doxygen 1.4.2