* @author Alan Knowles * @return boolean (basically true all the time here) */ function compile(&$flexy) { $this->flexy = &$flexy; // read the entire file into one variable $fileContent = file_get_contents($flexy->currentTemplate); // apply pre filter $fileContent = $this->applyFilters( $fileContent , "/^pre_/i" ); $fileContent = $this->applyFilters( $fileContent , "/^(pre_|post_)/i",TRUE); $fileContent = $this->applyFilters( $fileContent , "/^post_/i" ); // write the compiled template into the compiledTemplate-File if( ($cfp = fopen( $flexy->compiledTemplate , 'w' )) ) { fwrite($cfp,$fileContent); fclose($cfp); @chmod($flexy->compiledTemplate,0775); } return true; } /** * actually it will only be used to apply the pre and post filters * * @access public * @version 01/12/10 * @author Alan Knowles * @param string $input the string to filter * @param array $prefix the subset of methods to use. * @return string the filtered string */ function applyFilters( $input , $prefix = "",$negate=FALSE) { $this->flexy->debug("APPLY FILTER $prefix
"); $filters = $this->options['filters']; $this->flexy->debug(serialize($filters)."
"); foreach($filters as $filtername) { $class = "HTML_Template_Flexy_Compiler_Regex_{$filtername}"; require_once("HTML/Template/Flexy/Compiler/Regex/{$filtername}.php"); if (!class_exists($class)) { return HTML_Template_Flexy::raiseError("Failed to load filter $filter",null,HTML_TEMPLATE_FLEXY_ERROR_DIE); } if (!@$this->filter_objects[$class]) { $this->filter_objects[$class] = new $class; $this->filter_objects[$class]->_set_engine($this); } $filter = &$this->filter_objects[$class]; $methods = get_class_methods($class); $this->flexy->debug("METHODS:"); $this->flexy->debug(serialize($methods)."
"); foreach($methods as $method) { if ($method{0} == "_") { continue; // private } if ($method == $class) { continue; // constructor } $this->flexy->debug("TEST: $negate $prefix : $method"); if ($negate && preg_match($prefix,$method)) { continue; } if (!$negate && !preg_match($prefix,$method)) { continue; } $this->flexy->debug("APPLYING $filtername $method
"); $input = $filter->$method($input); } } return $input; } }