irm-1.6-b3/lib/Savant2/Savant2_Compiler_basic.php
/**
	* 
	* Compiles a template source into PHP code for Savant.
	* 
	* @access public
	* 
	* @var string $tpl The source template file.
	* 
	*/
Compiles a template source into PHP code for Savant.

@access public

@var string $tpl The source template file.
Compiles a template source into PHP code for Savant . @access public @var string $tpl The source template file .
function compile($tpl)
	{
		$end = '?' . '>';
		if ($this->forceCompile || $this->changed($tpl)) {
			$php = file_get_contents($tpl);
			$php = str_replace('<?php', '&lt;?php', $php);
			if (ini_get('short_open_tag')) {
				$php = str_replace('<?', '&lt;?', $php);
				$php = str_replace('<?=', '&lt;?=', $php);
			}
			$php = str_replace($end, '?&gt;', $php);
			foreach ($this->convert as $find => $replace) {
				$find = preg_quote($this->prefix) . '\s*' . $find .
					'\s*' . preg_quote($this->suffix);
				$php = preg_replace(
					"/$find/U",
					"<?php $replace $end",
					$php
				);
			}
						if ($this->strict) {
				$report = $this->analyze($php);
				if (count($report) > 0) {
					return new Savant2_Error(
						array(
							'code' => SAVANT2_ERROR_COMPILE_FAIL,
							'text' => $GLOBALS['_SAVANT2']['error'][SAVANT2_ERROR_COMPILE_FAIL],
							'info' => $report
						)
					);
				}
			}
			$this->saveCompiled($tpl, $php);
		}
		return $this->getPath($tpl);
	}
function compile ( $ tpl ) { $ end = '?' . '>' ; if ( $ this -> forceCompile || $ this -> changed ( $ tpl ) ) { $ php = file_get_contents ( $ tpl ) ; $ php = str_replace ( '<?php' , '&lt;?php' , $ php ) ; if ( ini_get ( 'short_open_tag' ) ) { $ php = str_replace ( '<?' , '&lt;?' , $ php ) ; $ php = str_replace ( '<?=' , '&lt;?=' , $ php ) ; } $ php = str_replace ( $ end , '?&gt;' , $ php ) ; foreach ( $ this -> convert as $ find => $ replace ) { $ find = preg_quote ( $ this -> prefix ) . '\s*' . $ find . '\s*' . preg_quote ( $ this -> suffix ) ; $ php = preg_replace ( " / $ find /U " , " <?php  $ replace $ end " , $ php ) ; } if ( $ this -> strict ) { $ report = $ this -> analyze ( $ php ) ; if ( count ( $ report ) > 0 ) { return new Savant2_Error ( array ( 'code' => SAVANT2_ERROR_COMPILE_FAIL , 'text' => $ GLOBALS [ '_SAVANT2' ] [ 'error' ] [ SAVANT2_ERROR_COMPILE_FAIL ] , 'info' => $ report ) ) ; } } $ this -> saveCompiled ( $ tpl , $ php ) ; } return $ this -> getPath ( $ tpl ) ; }
Compiles a template source into PHP code for Savant.
Compiles a template source into PHP code for Savant .
// create a end-tag so that text editors don't // stop colorizing text // recompile only if we are forcing compiled, or // if the template source has changed. // get the template source text /**
			* @todo Do we really care about PHP tags?  The code analyzer
			* will disallow any offending PHP regardless.
			*/ // disallow PHP long tags // disallow PHP short tags (if turned on) // disallow closing tags // convert each template command // allow whitespace around the command // actually do the find-and-replace // +++ DEBUG // $this->saveCompiled($tpl, $php); // --- DEBUG // are we doing strict checking?
 // analyze the code for restriction violations. // there were violations, report them as a generic // Savant error and return.  Savant will wrap this // generic rror with another error that will report // properly to the customized error handler (if any). // otherwise, save the compiled template // return the path to the compiled PHP script