Aikido Sportschule Template($tags); $this->array_registeredParsers = array( new StrAPIFunctionsParser(), new CounterFunctionParser(), new IfFunctionParser() ); if(is_array($parser)) { $this->array_registeredParsers = $parser; } } /** * Generiert das Template und gibt es aus/zurück. * * @param $template string/file Template * @param $return bool Return or print template * @param $note bool Echo "Generated by ... " Comment * * @return string complete Template string */ function generate($template, $return = 0, $note = 1) { $template = parent::generate($template, true, $note); foreach($this->array_registeredParsers as $class) { if(is_string($class)) { $classInstance = new $class; } else if(is_object($class)) { $classInstance = $class; } if(is_object($classInstance)) { if(is_subclass_of($classInstance, "AbstractTemplateParser")) { $template = $classInstance->parse($template); } else { $template = "TemplateParserKlasse " . get_class($classInstance) . " ist nicht von AbstractTemplateParser abgeleitet!"; break; } } } if ($return) { return $template; } echo $template; } } /** * class AbstractTemplateParser * * Abstrakte Superklasse für alle Templateparser * * @author Stefan Welpot * @version 1.0 */ class AbstractTemplateParser { /** * Konstruktor */ function AbstractTemplateParser() {} /** * Parst das übergeben Template * * @param $template string das zu parsende Template * * @return string das geparste Template */ function parse($template) { return $template; } } /** * class IfFunctionParser * * Implemenation des AbstractTemplateParser zum Auswerten von * If-Konstrukten im Template * Als Tags im Template sind vorgesehen: * - {if(Bedigung)} * - {else if(Bedingung)} * - {else} * - {/if} * * Ein If-Konstrukt besteht dabei mindestens aus {if(Bedingung)} und einem abschließenden {/if}. * Das {else if(Bedingung)} kann beliebig oft hintereinander verwendet werden. * Die Konstrukte an sich können beliebig tief geschachtelt werden. * Die Bedinungen der {if()}- und {else if()}-Teile werden durch eval ausgewertet * und können somit auch PHP-Funktionen interpretieren. * * * @author Stefan Welpot * @version 1.0 */ class IfFunctionParser extends AbstractTemplateParser { /** * Regexp-Pattern für {if(Bedingung)} * @var pattern_if */ var $pattern_if = "\{if\040*\((.*?)\)\}"; /** * Regexp-Pattern für {else if(Bedingung)} * @var pattern_elseif */ var $pattern_elseif = "\{else if\040*\((.*?)\)\}"; /** * Regexp-Pattern für {else} * @var pattern_else */ var $pattern_else = "\{else\}"; /** * Regexp-Pattern für {/if} * @var pattern_endif */ var $pattern_endif = "\{\/if\}"; /** * Länge des {if(Bedinung)}-Tags ohne Bedingung * @var patternlength_if */ var $patternlength_if = 6; /** * Länge des {else if(Bedinung)}-Tags ohne Bedingung * @var patternlength_elseif */ var $patternlength_elseif = 11; /** * Länge des {else}-Tags * @var patternlength_else */ var $patternlength_else = 6; /** * Länge des {/if}-Tags * @var patternlength_endif */ var $patternlength_endif = 5; /** * Konstruktor */ function IfFunctionParser() { $this->AbstractTemplateParser(); } /** * @see AbstractTemplateParser#parse(string) */ function parse($template) { $array2_uncompletedConstructs = array(); //geöffnete, aber noch nicht geschlossene funktionen //hilfsvariablen $array_match_all = array(); $array_match_part = array(); $uncompletedConstructsIndex = 0; $elseifIndex = 0; $currentOffset = 0; $oldOffset = -1; $array_construct = array(); $pattern_all = "/(?is)(" . $this->pattern_if . "|" . $this->pattern_elseif . "|" . $this->pattern_else . "|" . $this->pattern_endif . ")/"; //das template solange nach konstruktteilen durchsuchen bis keine mehr gefunden werden while($currentOffset != $oldOffset) { $oldOffset = $currentOffset; //wenn irgendein teil einer if-konstruktion gefunden wird if(preg_match($pattern_all, $template, $array_match_all, PREG_OFFSET_CAPTURE, $currentOffset) > 0) { //herausfinden, welcher teil gefunden wurde //if-teil if(preg_match("/(?is)" . $this->pattern_if . "/", $array_match_all[0][0], $array_match_part) > 0) { $uncompletedConstructsIndex++; //inkrement openFunctionIndex $array2_uncompletedConstructs[$uncompletedConstructsIndex]['if']['condition'] = $array_match_part[1]; $array2_uncompletedConstructs[$uncompletedConstructsIndex]['if']['pos_start'] = $array_match_all[0][1]; $array2_uncompletedConstructs[$uncompletedConstructsIndex]['if']['pos_end'] = $array2_uncompletedConstructs[$uncompletedConstructsIndex]['if']['pos_start'] + $this->patternlength_if + strlen($array_match_part[1]); $currentOffset = $array2_uncompletedConstructs[$uncompletedConstructsIndex]['if']['pos_end']; } //elseif-teil else if(preg_match("/(?is)" . $this->pattern_elseif . "/", $array_match_all[0][0], $array_match_part) > 0) { $elseifIndex = count($array2_uncompletedConstructs[$uncompletedConstructsIndex]['elseif']); $array2_uncompletedConstructs[$uncompletedConstructsIndex]['elseif'][$elseifIndex]['condition'] = $array_match_part[1]; $array2_uncompletedConstructs[$uncompletedConstructsIndex]['elseif'][$elseifIndex]['pos_start'] = $array_match_all[0][1]; $array2_uncompletedConstructs[$uncompletedConstructsIndex]['elseif'][$elseifIndex]['pos_end'] = $array2_uncompletedConstructs[$uncompletedConstructsIndex]['elseif'][$elseifIndex]['pos_start'] + $this->patternlength_elseif + strlen($array_match_part[1]); $currentOffset = $array2_uncompletedConstructs[$uncompletedConstructsIndex]['elseif'][$elseifIndex]['pos_end']; } //else-teil else if(preg_match("/(?is)" . $this->pattern_else . "/", $array_match_all[0][0], $array_match_part) > 0) { $array2_uncompletedConstructs[$uncompletedConstructsIndex]['else']['pos_start'] = $array_match_all[0][1]; $array2_uncompletedConstructs[$uncompletedConstructsIndex]['else']['pos_end'] = $array2_uncompletedConstructs[$uncompletedConstructsIndex]['else']['pos_start'] + $this->patternlength_else; $currentOffset = $array2_uncompletedConstructs[$uncompletedConstructsIndex]['else']['pos_end']; } //endif else if(preg_match("/(?is)" . $this->pattern_endif . "/", $array_match_all[0][0], $array_match_part) > 0) { $array2_uncompletedConstructs[$uncompletedConstructsIndex]['endif']['pos_start'] = $array_match_all[0][1]; $array2_uncompletedConstructs[$uncompletedConstructsIndex]['endif']['pos_end'] = $array2_uncompletedConstructs[$uncompletedConstructsIndex]['endif']['pos_start'] + $this->patternlength_endif; $currentOffset = $array2_uncompletedConstructs[$uncompletedConstructsIndex]['endif']['pos_end']; //gefundene komplette funktion sofort ersetzen $array_construct = array_pop($array2_uncompletedConstructs); $uncompletedConstructsIndex--; $template = $this->replaceConstruct($array_construct, $template); //offset korrigieren = anfang der ersetzten funktion $currentOffset = $array_construct['if']['pos_start']; } } } // end while if($uncompletedConstructsIndex > 0) { // wenn noch offene Funktionen vorhanden sind => Fehler im Template $template = "Fehler in IF-Konstruktionen. Folgende If-Statements sind nicht abgeschlossen:
\n"; foreach($array2_uncompletedConstructs as $array_construct) { $template .= "- {if(" . $array_construct['if']['condition'] . ")}
\n"; } } return $template; } // end function /** * Ersetzt die als Array übergebene Funktion durch * den ersten Teil mit einer wahren Bedingung * * @param $array_construct Array das komplette If-Konstrukt das ausgewertet werden soll * @param $template string das Template in dem das Konstrukt ersetzt werden soll * * @return string das Template mit dem ersetzten Konstrukt */ function replaceConstruct($array_construct, $template) { $array_elseif = array(); $key = 0; $replace_text = ""; $boolConditionTrue = false; //prüfen ob der if-teil wahr ist und $replace_text finden if(eval("return " . $array_construct['if']['condition'] . ";")) { if(array_key_exists('elseif', $array_construct)) { //wenn ein elseif-teil existiert $replace_text = substr($template, $array_construct['if']['pos_end'], $array_construct['elseif'][0]['pos_start'] - $array_construct['if']['pos_end']); } else if(array_key_exists('else', $array_construct)) { //wenn nur ein else-teil existiert $replace_text = substr($template, $array_construct['if']['pos_end'], $array_construct['else']['pos_start'] - $array_construct['if']['pos_end']); } else {//wenn der nächste teil schon endif ist $replace_text = substr($template, $array_construct['if']['pos_end'], $array_construct['endif']['pos_start'] - $array_construct['if']['pos_end']); } } else { //alle elseif-teile prüfen if(is_array($array_construct['elseif'])) { foreach($array_construct['elseif'] as $key => $array_elseif) { if(eval("return " . $array_elseif['condition'] . ";")) { $boolConditionTrue = true; if(array_key_exists(($key + 1), $array_construct['elseif'])) { //wenn ein weiterer elseif-teil existiert $replace_text = substr($template, $array_elseif['pos_end'], $array_construct['elseif'][$key+1]['pos_start'] - $array_elseif['pos_end']); } else if(array_key_exists('else', $array_construct)) { //wenn nächster teil nur ein else-teil ist $replace_text = substr($template, $array_elseif['pos_end'], $array_construct['else']['pos_start'] - $array_elseif['pos_end']); } else {//wenn der nächste teil schon endif ist $replace_text = substr($template, $array_elseif['pos_end'], $array_construct['endif']['pos_start'] - $array_elseif['pos_end']); } break; } } } //wenn bisher noch keine wahre Bedingung gefunden wurde if(!$boolConditionTrue) { if(array_key_exists('else', $array_construct)) { // wenn ein else-teil existiert $replace_text = substr($template, $array_construct['else']['pos_end'], $array_construct['endif']['pos_start'] - $array_construct['else']['pos_end']); } else { // sonst wird das gesamte kontrukt durch einen leeren string ersetzt $replace_text = ""; } } } // end else //if-konstruktion durch wahren teil ersetzen $template = substr_replace($template, $replace_text, $array_construct['if']['pos_start'], $array_construct['endif']['pos_end'] - $array_construct['if']['pos_start']); return $template; } } /** * class CounterFunctionParser * * Implemenation des AbstractTemplateParser zur Verwendung von * Zählern im Template * Als Tag im Template ist vorgesehen: * - {counter PARAMETER} * Die PARAMETER sind: * - name=ZÄHLERNAME * - start=STARTWERT (default: 0) * - step=SCHRITTWEITE (default: 1) * - print=(true|false) (default: true) * Alle Parameter sind optional. * * Über die Name-Eigenschaft können mehrere unschiedliche Zähler verwendet werden. * Bei jedem Vorkommen des {counter}-Tags wird der gleichnamige Zähler um STEP erhöht. * Wird die Eigenschaft print auf true oder gar nicht gesetzt erfolgt eine Ausgabe des * Zählerwerts an der Stelle des {counter}-Tags * * * @author Stefan Welpot * @version 1.0 */ class CounterFunctionParser extends AbstractTemplateParser { /** * Regexp-Pattern für {counter PARAMETER} * @var pattern_countertag */ var $pattern_countertag = "/(?si)\{counter(.*?\})/"; /** * Regexp-Pattern für Parameter name=NAME * @var pattern_countername */ var $pattern_countername = "/(?i)name\040?\=(.+?)(\040|\})/"; /** * Regexp-Pattern für Parameter start=STARTWERT * @var pattern_counterstart */ var $pattern_counterstart = "/(?i)start\040?\=(\d+?)(\040|\})/"; /** * Regexp-Pattern für Parameter step=SCHRITTWEITE * @var pattern_counterstep */ var $pattern_counterstep = "/(?i)step\040?\=(\d+?)(\040|\})/"; /** * Regexp-Pattern für Parameter print=(true|false) * @var pattern_counterprint */ var $pattern_counterprint = "/(?i)print\040?\=(true|false)(\040|\})/"; /** * Defaultwert für Parameter name * @var default_countername */ var $default_countername = "unnamed"; /** * Defaultwert für Parameter start * @var default_counterstart */ var $default_counterstart = 0; /** * Defaultwert für Parameter step * @var default_counterstep */ var $default_counterstep = 1; /** * Defaultwert für Parameter print * @var default_counterprint */ var $default_counterprint = true; /** * Konstruktor */ function CounterFunctionParser() { $this->AbstractTemplateParser(); } /** * @see AbstractTemplateParser#parse(string) */ function parse($template) { $counterParameters = ""; $counterKey = ""; $array_matches = array(); $array_countermatches = array(); $array_initCounters = array(); $boolPrint = $this->default_counterprint; $boolDoNotInkr = false; preg_match_all($this->pattern_countertag, $template, $array_countermatches, PREG_SET_ORDER); for($i = 0; $i < count($array_countermatches); $i++) { $counterKey = ""; $counterParameters = $array_countermatches[$i][1]; //Attribut Countername auslesen, falls vorhanden preg_match($this->pattern_countername, $counterParameters, $array_matches); if(count($array_matches) > 0) { $counterKey = $array_matches[1]; } else { // sonst defaultname $counterKey = $this->default_countername; } if(!array_key_exists($counterKey, $array_initCounters)) { // neuen Counter initialisieren $array_initCounters[$counterKey]['value'] = $this->default_counterstart; $array_initCounters[$counterKey]['step'] = $this->default_counterstep; $boolDoNotInkr = true; } //Attribut step preg_match($this->pattern_counterstep, $counterParameters, $array_matches); if(count($array_matches) > 0) { $array_initCounters[$counterKey]['step'] = $array_matches[1]; } //Attribut start preg_match($this->pattern_counterstart, $counterParameters, $array_matches); if(count($array_matches) > 0) { $array_initCounters[$counterKey]['value'] = $array_matches[1]; $boolDoNotInkr = true; } // value regulär erhöhen if(!$boolDoNotInkr) { $array_initCounters[$counterKey]['value'] = $array_initCounters[$counterKey]['value'] + $array_initCounters[$counterKey]['step']; } else { $boolDoNotInkr = false; } //Attribut print preg_match($this->pattern_counterprint, $counterParameters, $array_matches); if(count($array_matches) > 0) { $boolPrint = (strcasecmp("true", $array_matches[1]) == 0) ? true : false; } else { $boolPrint = $this->default_counterprint; } if($boolPrint) { $template = preg_replace($this->pattern_countertag, $array_initCounters[$counterKey]['value'], $template, 1); } else { $template = preg_replace($this->pattern_countertag, '', $template, 1); } } return $template; } } /** * class StrAPIFunctionsParser * * Implemenation des AbstractTemplateParser zum Auswerten von * ContenidoStrAPIFunktionen. * Als erlaubte Funktionen sind vorgesehen: * - {capiStrTrimHard(STRING, LÄNGE)} * - {capiStrTrimAfterWord(STRING, LÄNGE)} * - {capiStrTrimSentence(STRING, LÄNGE)} * * Die die Funktionen werden ertrahiert, ausgewertet und anschließend durch das Ergebnis ersetzt. * * * @author Stefan Welpot * @version 1.0 */ class StrAPIFunctionsParser extends AbstractTemplateParser { /** * zu ersetzende Funktionen * @var array_strAPIFunctions */ var $array_strAPIFunctions = array( "capiStrTrimHard", "capiStrTrimAfterWord", "capiStrTrimSentence" ); /** * Konstruktor */ function StrAPIFunctionParser() { $this->AbstractTemplateParser(); } /** * @see AbstractTemplateParser#parse(string) */ function parse($template) { $anzahlMatches = 0; $array2_matches = array(); $evaledCode = ""; foreach($this->array_strAPIFunctions as $functionname) { $anzahlMatches = preg_match_all("/(?si)\{" . preg_quote($functionname, "/") . "\(\"?(.*?)\"?,\040?(\d+?)\)\}/", $template, $array2_matches); for($i = ($anzahlMatches - 1); $i >= 0; $i--) { $evaledCode = eval("return " . $functionname . "(\"" . $array2_matches[1][$i] . "\", " . $array2_matches[2][$i] . ");"); $template = preg_replace( "/(?si)\{" . preg_quote($functionname, "/") . "\(\"?" . preg_quote($array2_matches[1][$i], "/") . "\"?,\040?" . preg_quote($array2_matches[2][$i], "/") . "\)\}/", $evaledCode, $template ); } //end for(i) } // end foreach return $template; } } ?> Fatal error: Class 'ExtendedTemplate' not found in /var/www/clients/client24/web118/web/cms/front_content.php(958) : eval()'d code on line 688