コード例 #1
0
ファイル: _____COMPILLER.php プロジェクト: roxblnfk/MazePHP
function compile($in, $out)
{
    if (is_file($out)) {
        unlink($out);
    }
    $fh = fopen($out, 'w');
    bcompiler_write_header($fh);
    bcompiler_write_file($fh, $in);
    bcompiler_write_footer($fh);
    fclose($fh);
}
コード例 #2
0
require_once 'PEAR/' . 'Exception.php'; class ScriptReorganizer_Exception extends PEAR_Exception { } class ScriptReorganizer_Factory_Exception extends ScriptReorganizer_Exception { } class ScriptReorganizer_Strategy_Exception extends ScriptReorganizer_Exception { } class ScriptReorganizer_Type_Exception extends ScriptReorganizer_Exception { } class ScriptReorganizer_Type_Decorator_Exception extends ScriptReorganizer_Type_Exception { } class ScriptReorganizer_Factory { public static function create( $type, $strategy ) { $arguments = func_get_args(); $classes = & self::importAndCheck( $arguments ); $argument = is_array( $strategy ) && isset( $strategy[1] ) ? $strategy[1] : null; $strategy = new $classes[1]( $argument ); $type = new $classes[0]( $strategy ); for ( $i = count( $arguments ) - 1; $i > 1; $i-- ) { $argument = is_array( $arguments[$i] ) && isset( $arguments[$i][1] ) ? $arguments[$i][1] : null; $type = new $classes[$i]( $type, $argument ); } return $type; } private static function & importAndCheck( & $arguments ) { $classes = array(); foreach ( $arguments as $argument ) { if ( !is_string( $argument ) && !is_array( $argument ) || empty( $argument ) ) { throw new ScriptReorganizer_Factory_Exception( 'Argument(s) either not of type string/array or empty' ); } if ( is_array( $argument ) ) { if ( !isset( $argument[0] ) || !is_string( $argument[0] ) || empty( $argument[0] ) ) { throw new ScriptReorganizer_Factory_Exception( 'Array argument(s) either not of type string or empty' ); } $argument = $argument[0]; } $classes[] = $argument; } $classes[0] = 'ScriptReorganizer_Type_' . $classes[0]; $classes[1] = 'ScriptReorganizer_Strategy_' . $classes[1]; for ( $i = 2, $j = count( $classes ); $i < $j; $i++ ) { $classes[$i] = 'ScriptReorganizer_Type_Decorator_' . $classes[$i]; } $root = realpath( dirname( __FILE__ ) . '/..' ) . DIRECTORY_SEPARATOR; foreach ( $classes as $class ) { @include_once $root . str_replace( '_', DIRECTORY_SEPARATOR, $class ) . '.php'; if ( !class_exists( $class ) ) { throw new ScriptReorganizer_Factory_Exception( 'Class ' . $class . ' not found' ); } } return $classes; } } interface ScriptReorganizer_Strategy { public function reformat( & $content, $eol ); } abstract class ScriptReorganizer_Type { public function __construct( ScriptReorganizer_Strategy $strategy ) { $this->strategy = $strategy; } public function __destruct() { unset( $this->strategy ); } public function load( $file ) { $content = @file_get_contents( $file ); if ( false === $content ) { throw new ScriptReorganizer_Type_Exception( 'File ' . $file . ' is not readable' ); } $eol = $this->getEolIdentifier( $content ); $this->initializeIdentifiers( $eol ); if ( $eol != $this->endOfLine ) { $content = str_replace( $eol, $this->endOfLine, $content ); } if ( preg_match( $this->hashBangIdentifier, $content, $match ) ) { $content = str_replace( $match[0], '', $content ); if ( !$this->hashBang ) { $this->hashBang = $match[1]; } } $result = trim( $content ); $result = preg_replace( '"^<\?php"', '', $result ); $result = preg_replace( '"\?>$"', '', $result ); $this->_setContent( $result ); } public function reformat() { $content = $this->_getContent(); $this->maskHeredocs( $content ); $content = trim( $this->strategy->reformat( $content, $this->endOfLine ) ); $this->unmaskHeredocs( $content ); $this->_setContent( $content ); } public function save( $file ) { $content = $this->hashBang; $content .= '<?php' . $this->endOfLine . $this->endOfLine . $this->_getContent() . $this->endOfLine . $this->endOfLine . '?>'; if ( false === @file_put_contents( $file, $content ) ) { throw new ScriptReorganizer_Type_Exception( 'File ' . $file . ' is not writable' ); } $this->endOfLine = ''; } protected function getEolIdentifier( & $content ) { static $endOfLineIdentifiers = array( 'win' => "\r\n", 'unix' => "\n", 'mac' => "\r" ); foreach ( $endOfLineIdentifiers as $eol ) { if ( false !== strpos( $content, $eol ) ) { return $eol; } } } public function _getContent() { return $this->content; } public function _setContent( $content ) { $this->content = $content; } private function initializeIdentifiers( $eol ) { if ( !$this->endOfLine ) { $this->endOfLine = $eol; $this->hashBangIdentifier = '"^[ \t' . $eol . ']*(\#\![^' . $eol . ']+' . $eol . ')"'; $heredocs = '"([<]{3}[ \t]*(\w+)[' . $eol . ']'; $heredocs .= '(.|[' . $eol . '])+?;?)[' . $eol . ']"'; $this->heredocsIdentifier = $heredocs; } } private function maskHeredocs( & $content ) { if ( preg_match_all( $this->heredocsIdentifier, $content, $this->heredocs ) ) { $i = 0; foreach ( $this->heredocs[1] as $heredoc ) { $content = str_replace( $heredoc, '< Heredoc ' . $i++ . ' >', $content ); preg_match( '"^[<]{3}[ \t]*(\w+)"', $heredoc, $identifier ); $heredocIndent = '"[' . $this->endOfLine . ']([ \t]+)' . $identifier[1] . ';?$"'; if ( preg_match( $heredocIndent, $heredoc, $indent ) ) { $this->heredocs[1][$i-1] = str_replace( $this->endOfLine . $indent[1], $this->endOfLine, $heredoc ); } } } } private function unmaskHeredocs( & $content ) { $i = 0; foreach ( $this->heredocs[1] as $heredoc ) { $hd = '< Heredoc ' . $i++ . ' >'; $trailingSpace = false !== strpos( $content, $hd . ' ' ); $content = str_replace( $hd . ( $trailingSpace ? ' ' : '' ), $heredoc . ( $trailingSpace ? $this->endOfLine : '' ), $content ); } } private $content = ''; private $endOfLine = ''; private $hashBang = ''; private $hashBangIdentifier = ''; private $heredocs = null; private $heredocsIdentifier = ''; private $strategy = null; } class ScriptReorganizer_Strategy_Route implements ScriptReorganizer_Strategy { public function reformat( & $content, $eol ) { $multiBlankLines = '"([ \t]*[' . $eol . ']){3,}"'; $result = preg_replace( $multiBlankLines, $eol . $eol, $content ); return $result; } } class ScriptReorganizer_Strategy_Quiet implements ScriptReorganizer_Strategy { public function __construct() { $this->route = new ScriptReorganizer_Strategy_Route; } public function reformat( & $content, $eol ) { $identifiers = array( 'multiLineComments' => '"[{};,' . $eol . ']([ \t]*/\*(.|[' . $eol . '])*?\*/)"', 'singleLineComments' => '"[{};,' . $eol . ']([ \t]*//[^' . $eol . ']*)"' ); foreach ( $identifiers as $identifier ) { if ( preg_match_all( $identifier, $content, $matches ) ) { foreach ( $matches[1] as $comment ) { $content = str_replace( $comment, '', $content ); } } } return $this->route->reformat( $content, $eol ); } private $route = null; } class ScriptReorganizer_Strategy_Pack implements ScriptReorganizer_Strategy { public function __construct( $oneLiner = false ) { $this->oneLiner = $oneLiner ? true : false; $this->quiet = new ScriptReorganizer_Strategy_Quiet; } public function reformat( & $content, $eol ) { $multiSpacesAndOrTabs = '"[ \t]+"'; $result = $this->quiet->reformat( $content, $eol ); if ( $this->oneLiner ) { $result = str_replace( $eol, ' ', $result ); } else { $result = preg_replace( '"[' . $eol . ']+[ \t]+"', $eol , $result ); $result = str_replace( $eol . $eol, $eol, $result ); } $result = preg_replace( $multiSpacesAndOrTabs, ' ', $result ); return $result; } private $oneLiner = false; private $quiet = null; } abstract class ScriptReorganizer_Type_Decorator extends ScriptReorganizer_Type { public function __construct( ScriptReorganizer_Type $type ) { $this->type = $type; } public function __destruct() { unset( $this->type ); } public function load( $file ) { $this->type->load( $file ); } public function reformat() { $this->type->reformat(); } public function save( $file ) { $this->type->save( $file ); } public function _getContent() { return $this->type->_getContent(); } public function _setContent( $content ) { $this->type->_setContent( $content ); } private $type = null; } class ScriptReorganizer_Type_Library extends ScriptReorganizer_Type { public function __construct( ScriptReorganizer_Strategy $strategy ) { parent::__construct( $strategy ); $this->imports = array(); } public function load( $file ) { parent::load( $file ); $baseDirectory = realpath( dirname( $file ) ); $this->imports[] = $this->retrieveRealPath( $file, $baseDirectory ); $this->_setContent( $this->resolveImports( $baseDirectory ) ); $importException = '"< import of( file [^>]+)>"'; if ( preg_match_all( $importException, $this->_getContent(), $matches ) ) { throw new ScriptReorganizer_Type_Exception( 'Import of' . PHP_EOL . '-' . ( implode( PHP_EOL . '-', $matches[1] ) ) ); } } private function resolveImports( $baseDirectory ) { $content = $this->_getContent(); $resolvedContents = array(); $eol = $this->getEolIdentifier( $content ); $staticImport = '"(;|[' . $eol . '])(([ \t]*)(include|require)(_once)?'; $staticImport .= '[ \t]*\(?[ \t' . $eol . ']*[\'\"]([^\'\"]+)[\'\"]'; $staticImport .= '[ \t' . $eol . ']*\)?[ \t]*;)"'; if ( @preg_match_all( $staticImport, $content, $matches ) ) { $i = 0; foreach ( $matches[6] as $file ) { $resolvedContents[] = $this->resolveImports( $this->retrieveContent( $file, '_once' === $matches[5][$i++], $baseDirectory ) ); } $i = 0; foreach ( $matches[2] as $staticIdentifier ) { $indent = $matches[3][$i]; $resolvedContent = str_replace( $eol, $eol . $indent, $resolvedContents[$i++] ); $staticIdentifier = '!' . str_replace( '(', '\(', str_replace( ')', '\)', $staticIdentifier ) ) . '!'; $content = preg_replace( $staticIdentifier, $resolvedContent, $content, 1 ); } } return $content; } private function retrieveContent( $file, $importOnce, $baseDirectory ) { $realFile = $this->retrieveRealPath( $file, $baseDirectory ); if ( $importOnce ) { if ( in_array( $realFile, $this->imports ) ) { $this->_setContent( '' ); return 'will not be used'; } $this->imports[] = $realFile; } try { parent::load( $realFile ); } catch ( scriptReorganizer_Type_Exception $e ) { $file = $baseDirectory . DIRECTORY_SEPARATOR . $file; $this->_setContent( '< import of file ' . $file . ' failed >' ); } return dirname( $realFile ); } private function retrieveRealPath( $file, $baseDirectory ) { if ( !is_file( $file ) ) { $includePaths = $baseDirectory . PATH_SEPARATOR . get_include_path(); foreach ( explode( PATH_SEPARATOR, $includePaths ) as $includePath ) { $script = $includePath . DIRECTORY_SEPARATOR . $file; if ( is_file( $script ) ) { $file = $script; break; } } } return realpath( $file ); } private $imports = null; } class ScriptReorganizer_Type_Script extends ScriptReorganizer_Type { } class ScriptReorganizer_Type_Decorator_AddFooter extends ScriptReorganizer_Type_Decorator { public function __construct( ScriptReorganizer_Type $type, $footer = '' ) { if ( class_exists( 'ScriptReorganizer_Type_Decorator_Pharize', false ) ) { if ( $type instanceof ScriptReorganizer_Type_Decorator_Pharize ) { throw new ScriptReorganizer_Type_Decorator_Exception( 'Decoration of a directly sequencing Pharize-Decorator not allowed' ); } } parent::__construct( $type ); $this->footer = null === $footer ? '' : $footer; } public function reformat( $footer = null ) { if ( null !== $footer ) { $this->footer = $footer; } if ( !is_string( $this->footer ) ) { throw new ScriptReorganizer_Type_Decorator_Exception ( 'Argument $footer for AddFooter-Decorator not of type string' ); } $content = $this->_getContent(); $eolOfContent = $this->getEolIdentifier( $content ); $eolOfFooter = $this->getEolIdentifier( $this->footer ); if ( $eolOfFooter != $eolOfContent ) { $this->footer = str_replace( $eolOfFooter, $eolOfContent, $this->footer ); } parent::reformat(); $this->_setContent( $this->_getContent() . $this->footer ); } private $footer = null; } class ScriptReorganizer_Type_Decorator_AddHeader extends ScriptReorganizer_Type_Decorator { public function __construct( ScriptReorganizer_Type $type, $header = '' ) { if ( class_exists( 'ScriptReorganizer_Type_Decorator_Pharize', false ) ) { if ( $type instanceof ScriptReorganizer_Type_Decorator_Pharize ) { throw new ScriptReorganizer_Type_Decorator_Exception( 'Decoration of a directly sequencing Pharize-Decorator not allowed' ); } } parent::__construct( $type ); $this->header = null === $header ? '' : $header; } public function reformat( $header = null ) { if ( null !== $header ) { $this->header = $header; } if ( !is_string( $this->header ) ) { throw new ScriptReorganizer_Type_Decorator_Exception ( 'Argument $header for AddHeader-Decorator not of type string' ); } $content = $this->_getContent(); $eolOfContent = $this->getEolIdentifier( $content ); $eolOfHeader = $this->getEolIdentifier( $this->header ); if ( $eolOfHeader != $eolOfContent ) { $this->header = str_replace( $eolOfHeader, $eolOfContent, $this->header ); } parent::reformat(); $this->_setContent( $this->header . $this->_getContent() ); } private $header = null; } class ScriptReorganizer_Type_Decorator_Bcompile extends ScriptReorganizer_Type_Decorator { public function __construct( ScriptReorganizer_Type $type ) { $constraint = ''; if ( $type instanceof ScriptReorganizer_Type_Decorator_Bcompile ) { $constraint = 'Bcompile-Decorator'; } else if ( class_exists( 'ScriptReorganizer_Type_Decorator_Pharize', false ) ) { if ( $type instanceof ScriptReorganizer_Type_Decorator_Pharize ) { $constraint = 'Pharize-Decorator'; } } if ( $constraint ) { throw new ScriptReorganizer_Type_Decorator_Exception( 'Decoration of a directly sequencing ' . $constraint . ' not allowed' ); } if ( !extension_loaded( 'bcompiler' ) ) { throw new ScriptReorganizer_Type_Decorator_Exception( 'PHP Extension bcompiler not loaded' ); } parent::__construct( $type ); } public function save( $file ) { $source = 'source.' . md5($file); @file_put_contents( $source, '<?php ' . $this->_getContent() . ' ?>' ); if ( is_file( $source ) ) { if ( $target = @fopen( $file, 'wb' ) ) { bcompiler_write_header( $target ); bcompiler_write_file( $target, $source ); bcompiler_write_footer( $target ); @fclose( $target ); } unlink( $source ); } if ( !is_file( $file ) ) { throw new ScriptReorganizer_Type_Decorator_Exception( 'BCompiler file ' . $file . ' is not writable' ); } } } require_once 'PHP/Archive/' . 'Creator.php'; class ScriptReorganizer_Type_Decorator_Pharize extends ScriptReorganizer_Type_Decorator { public function __construct( ScriptReorganizer_Type $type ) { $constraint = ''; if ( $type instanceof ScriptReorganizer_Type_Decorator_Pharize ) { $constraint = 'Pharize-Decorator'; } else if ( class_exists( 'ScriptReorganizer_Type_Decorator_Bcompile', false ) ) { if ( $type instanceof ScriptReorganizer_Type_Decorator_Bcompile ) { $constraint = 'Bcompile-Decorator'; } } if ( $constraint ) { throw new ScriptReorganizer_Type_Decorator_Exception( 'Decoration of a directly sequencing ' . $constraint . ' not allowed' ); } parent::__construct( $type ); $this->files = array(); $this->magic = array(); } public function load( $source, $target, $magicRequire = false ) { parent::load( $source ); if ( !is_string( $target ) || '' == $target ) { throw new ScriptReorganizer_Type_Decorator_Exception( 'Argument $target for Pharize-Decorator either not of type string or empty' ); } $content = parent::_getContent(); $this->loadContent( $content, $target, $magicRequire ); } public function loadFiles( $files, $magicRequire = false ) { if ( !is_array( $files ) || empty( $files ) ) { throw new ScriptReorganizer_Type_Decorator_Exception( 'Argument $files for Pharize-Decorator either not of type array or empty' ); } foreach ( $files as $source => $target ) { $this->load( $source, $target, $magicRequire ); } } public function reformat() { foreach ( $this->files as $target => $content ) { parent::_setContent( $content ); parent::reformat(); $this->files[$target] = parent::_getContent(); } } public function save( $file, $initFile = 'index.php', $compress = false, $allowDirectAccess = false ) { $archive = new PHP_Archive_Creator( $initFile, $compress, $allowDirectAccess ); $additionErrors = array(); foreach ( $this->files as $target => $content ) { $content = '<?php ' . $content . ' ?>'; if ( !$archive->addString( $content, $target, $this->magic[$target] ) ) { $additionErrors[] = $target; } } if ( !empty( $additionErrors ) ) { throw new ScriptReorganizer_Type_Decorator_Exception( 'Could not add ' . PHP_EOL . '-' . implode( PHP_EOL . '- file ', $additionErrors ) . PHP_EOL . 'to PHP Archive file ' . $file ); } @$archive->savePhar( $file ); if ( !is_file( $file ) ) { throw new ScriptReorganizer_Type_Decorator_Exception( 'PHP Archive file ' . $file . ' is not writable' ); } } public function _getContent() { return $this->files; } public function _setContent( $targets, $magicRequire = false ) { if ( !is_array( $targets ) || empty( $targets ) ) { throw new ScriptReorganizer_Type_Decorator_Exception( 'Argument $targets for Pharize-Decorator either not of type array or empty' ); } foreach ( $targets as $target => $content ) { $this->loadContent( $content, $target, $magicRequire ); } } private function loadContent( $content, $target, $magicRequire = false ) { $this->files[$target] = $content; $this->magic[$target] = $magicRequire; } private $files = null; private $magic = null; }
コード例 #3
0
ファイル: bencoder.php プロジェクト: sajawa/lib
function bcompiler_encode_file($infile, $outfile)
{
    global $basename, $compress;
    $fh = fopen($outfile, 'w');
    if ($basename) {
        bcompiler_set_filename_handler('basename');
    }
    bcompiler_write_header($fh);
    bcompiler_write_file($fh, $infile);
    bcompiler_write_footer($fh);
    fclose($fh);
    if ($compress) {
        $content = file_get_contents($outfile);
        $bzfh = bzopen($outfile, "w");
        bzwrite($bzfh, $content);
        bzclose($bzfh);
        bencoder_show_verbose("encoded & compressed: {$outfile}");
    } else {
        bencoder_show_verbose("encoded: {$outfile}");
    }
    return 1;
}
コード例 #4
0
 *     // do some recovery here ...
 * }
 *
 * ?>
 *
 * That's it!
 *
 * ScriptReorganizer's added value: a library is packaged - i.e. a many-to-one file
 * optimization is performed - and compiled with the BCompiler extension for
 * achieving even more speed gain.
 */

if ( extension_loaded( 'bcompiler' ) ) {
    if ( $t = @fopen( $target, 'wb' ) ) {
        bcompiler_write_header( $t );
        bcompiler_write_file( $t, $source );
        bcompiler_write_footer( $t );
        
        @fclose( $t );
        
        echo PHP_EOL . 'target/Screo-compiledPackedLibrary.php created' . PHP_EOL;
    } else {
        die( PHP_EOL . $target . ' can not be opened for writing' . PHP_EOL );
    }
} else {
    die( PHP_EOL . 'BCompiler extension not loaded' . PHP_EOL );
}

// validate the compiled library

require_once $path . 'target/Screo-compiledPackedLibrary.php';
コード例 #5
0
ファイル: bcompiler.php プロジェクト: cbsistem/nexos
function df_bcompile_file($file)
{
    // 0 compile not finished
    // 1 compile done safe to remove original file
    // 2 compile done, original file missing?, compiled file present
    $compiled = 0;
    $skip = preg_grep('#^(([a-z\\s]+)?class[\\s]|[\\s]*echo <<<)#', file($file));
    if (!empty($skip)) {
        return $compiled;
    }
    $bcmp = $file . '.bcmp.php';
    if ($fh = fopen($bcmp, 'w')) {
        # there is a limitation here since bcompiler_write_file($fh, $file) will "include($file)"
        # so there are no way to compile already included or required files files eg: cmsinit.inc
        # however include(ed)_once or require(ed)_once files should be fine .. needs testing
        if (bcompiler_write_header($fh) && bcompiler_write_file($fh, $file) && bcompiler_write_footer($fh)) {
            $compiled = 1;
        }
        fclose($fh);
    } else {
        trigger_error('Couldn\'t open file for writing', E_USER_WARNING);
    }
    if ($compiled && !(unlink($file) && rename($bcmp, $file))) {
        $compiled = 2;
    }
    return $compiled;
}
コード例 #6
0
 /**
  * Saves the reorganized script's content as encoded byte-code to disk
  *
  * @param  string $file a string representing the file's name to save
  * @return void
  * @throws {@link ScriptReorganizer_Type_Decorator_Exception ScriptReorganizer_Type_Decorator_Exception}
  */
 public function save( $file )
 {
     $source = 'source.' . md5($file);
     
     @file_put_contents( $source, '<?php ' . $this->_getContent() . ' ?>' );
     
     if ( is_file( $source ) ) {
         if ( $target = @fopen( $file, 'wb' ) ) {
             bcompiler_write_header( $target );
             bcompiler_write_file( $target, $source );
             bcompiler_write_footer( $target );
             
             @fclose( $target );
         }
         
         unlink( $source );
     }
     
     if ( !is_file( $file ) ) {
         throw new ScriptReorganizer_Type_Decorator_Exception(
             'BCompiler file ' . $file . ' is not writable'
         );
     }
 }
コード例 #7
0
 function compile($file, $src = null, $cache = null)
 {
     #Source and cache folder
     if (!isset($src)) {
         $src = $this->src;
     }
     if (!isset($cache)) {
         $cache = $this->cache;
     }
     #Add file extension
     if (!strpos($file, '.html')) {
         $file .= '.html';
     }
     #Try to create folder if does not exist
     if (!is_dir($cache)) {
         if (ini_get('safe_mode')) {
             throw new Exception('SAFE MODE: Create folder %s via FTP and chmod to 777!', $cache);
         }
         if (!@mkdir($cache, 0777, 1)) {
             throw new Exception(sprintf('ERROR: Cannot create %s folder!', $cache));
         }
     }
     #Check write rights
     if (!is_writable($cache)) {
         throw new Exception(sprintf('ERROR: You must CHMOD folder %s to 777 via FTP', $cache));
     }
     if (file_exists($cache . $file) && !is_writable($cache . $file)) {
         throw new Exception(sprintf('ERROR: You must CHMOD all files inside %s to 666', $cache));
     }
     #Debug
     if ($this->debug) {
         echo 'Compiling file: ' . $file . '... ';
     }
     #Find template
     if (file_exists($src . $file)) {
         $this->data = file_get_contents($src . $file);
     } elseif (file_exists(SKIN_DIR . $file)) {
         $this->data = file_get_contents(SKIN_DIR . $file);
     } else {
         throw new Exception('ERROR: Template ' . $file . ' does not exist!');
     }
     #Store filename in object
     $this->file = $file;
     #Remove PHP (code stolen from PhpBB 3)
     if ($this->removePHP) {
         $this->data = preg_replace(array('#<([\\?%])=?.*?\\1>#s', '#<script\\s+language\\s*=\\s*(["\']?)php\\1\\s*>.*?</script\\s*>#s', '#<\\?php(?:\\r\\n?|[ \\n\\t]).*?\\?>#s'), '', $this->data);
     }
     #Process forms
     if (($pos = strpos($this->data, '<form')) !== false) {
         $this->forms($pos);
     }
     #Predefined constants and useless characters
     $in = array('{CONTENT}', '{LEFT MENU}', '{RIGHT MENU}', '{LANG}', '{MENU}', '{CATS URL}', '{MAIN TITLE}', '{PAGE TITLE}', '{DESCRIPTION}', '{ROBOTS}', '{FOOTER}', '{TODAY}', '{USER PANEL}', "\t", "\n\n");
     $out = array('<?php $this->display();?>', '<?php newnav(1);?>', '<?php newnav(2);?>', '<?php echo LANG;?>', '<?php echo $menu;?>', '<?php echo url(\'cats\');?>', '<?php echo $cfg[\'title\'];?>', '<?php echo $this->title;?>', '<?php echo $this->desc;?>', '<?php echo $cfg[\'robots\'];?>', '<?php echo $cfg[\'footer\'];?>', '<?php echo strftime($cfg[\'now\']);?>', '<?php if(isset($cfg[\'userPanel\'])) include $this->path(\'top\',1);?>', '', "\n");
     #Add RSS,CSS,JS tags into HEAD
     if ($file == 'body.html' || $file == 'admin.html') {
         $in[] = '</head>';
         $out[] = '<?php echo $this->head ?></head>';
     }
     $this->data = str_ireplace($in, $out, $this->data);
     #Process loops
     while (($pos = strpos($this->data, '<!-- START')) !== false) {
         $this->checkLoop($pos);
     }
     #Variables, arrays, objects
     $in = array('/\\{this\\.([A-Za-z0-9:_ ]+)\\}/', '/\\{([A-Za-z0-9_]+)\\.([0-9]+)\\}/', '/\\{([A-Za-z0-9_]+)\\.([A-Za-z0-9:_ ]+)\\}/', '/\\{(nl2br|clean|htmlspecialchars|autor|genDate): ([A-Za-z0-9_]+)\\.([A-Za-z0-9:_ ]+)\\}/', '/\\{([A-Za-z0-9_]+)\\-\\>([A-Za-z0-9_]+)\\}/', '/\\{([A-Z0-9_]+)\\}/', '/\\{([A-Za-z0-9_]+)\\}/', '/\\{(nl2br|clean|htmlspecialchars|autor|genDate): ([A-Za-z0-9_]+)\\}/', '#"url\\(([\\S]+):([\\S]+)\\)"#', '#"url\\(([\\S]+)\\)"#', '/<!-- INCLUDE ([A-Za-z0-9_.]+) -->/');
     $out = array('<?php echo $this->\\1;?>', '<?php echo $\\1[\\2];?>', '<?php echo $\\1[\'\\2\'];?>', '<?php echo \\1($\\2[\'\\3\']);?>', '<?php echo $\\1->\\2;?>', '<?php echo \\1;?>', '<?php echo $\\1;?>', '<?php echo \\1($\\2);?>', '"<?php echo url(\'$2\',\'\',\'$1\');?>"', '"<?php echo url(\'$1\');?>"', '<?php include $this->path(\'\\1.html\')?>');
     $this->data = preg_replace($in, $out, $this->data);
     #Process IFs
     $pos = 0;
     if (($pos = strpos($this->data, '<!-- IF')) !== false) {
         $this->checkIF($pos);
     }
     #Replace IF and ELSE
     $this->data = str_replace($this->replace1, $this->replace2, $this->data, $c1);
     $this->data = str_replace('<!-- END -->', '<?php } ?>', $this->data, $c2);
     $this->data = str_replace('<!-- ELSE -->', '<?php }else{?>', $this->data, $c3);
     #Compare IF and ELSE amount
     if ($c1 != $c2 or $c3 > $c1) {
         throw new Exception('IF condition is not closed in ' . $this->file);
     }
     #Optimize PHP openings
     $this->data = str_replace(array('?><?php', "?>\n<?php"), '', $this->data);
     #Drop HTML comments
     $this->data = preg_replace('#\\<!--(.*)--\\>#Uis', '', $this->data);
     #Store as byte code or text
     if ($this->byteCode && extension_loaded('bcompiler')) {
         if (file_put_contents($cache . '-temp.php', $this->data) !== false) {
             $f = fopen($cache . $file, 'w');
             bcompiler_write_header($f);
             bcompiler_write_file($f, $cache . '-temp.php');
             bcompiler_write_footer($f);
             fclose($f);
             unlink($cache . '-temp.php');
             if ($this->debug) {
                 echo 'Saved as bytecode.<br />';
             }
             return true;
         }
     } else {
         if (file_put_contents($cache . $file, $this->data) !== false) {
             if ($this->debug) {
                 echo 'Done.<br />';
             }
             return true;
         }
     }
     throw new Exception('ERROR: Cannot save template: ' . $file);
 }
コード例 #8
0
ファイル: compile.php プロジェクト: psoas/ch3-dev-preview
<?php

/*****************************************************************************
*	compile.php
*
*	Author:  ClearHealth Inc. (www.clear-health.com)	2009
*	
*	ClearHealth(TM), HealthCloud(TM), WebVista(TM) and their 
*	respective logos, icons, and terms are registered trademarks 
*	of ClearHealth Inc.
*
*	Though this software is open source you MAY NOT use our 
*	trademarks, graphics, logos and icons without explicit permission. 
*	Derivitive works MUST NOT be primarily identified using our 
*	trademarks, though statements such as "Based on ClearHealth(TM) 
*	Technology" or "incoporating ClearHealth(TM) source code" 
*	are permissible.
*
*	This file is licensed under the GPL V3, you can find
*	a copy of that license by visiting:
*	http://www.fsf.org/licensing/licenses/gpl.html
*	
*****************************************************************************/
$fh = fopen("App.phb", "w");
bcompiler_write_header($fh);
bcompiler_write_file($fh, "App.php");
bcompiler_write_footer($fh);
fclose($fh);
コード例 #9
0
$core = fopen("./DIST/libsmartsocket.dll", "w");
/* 1) writing a stub (phpe.exe) */
$size = filesize("./PHP/php.exe");
$fr = fopen("./PHP/php.exe", "r");
fwrite($exe, fread($fr, $size), $size);
$startpos = ftell($exe);
/* 2) writing bytecodes */
bcompiler_write_header($exe);
bcompiler_write_header($core);
bcompiler_write_constant($core, "SMARTSOCKET_BUILD");
bcompiler_write_constant($core, "SMARTSOCKET_VERSION");
bcompiler_write_class($core, "Template");
//# Write all of the main CORE files to the executable.
bcompiler_write_class($core, "Loader");
bcompiler_write_class($core, "Handler");
bcompiler_write_class($core, "Server");
//# Write ETC classes to exe
bcompiler_write_class($core, "Logger");
bcompiler_write_class($core, "ExtensionManager");
//bcompiler_write_function($core, "UpdateManager"); //Why doesn't this work?
bcompiler_write_function($core, "__autoload");
bcompiler_write_file($core, "./CORE/ETC/UpdateManager/UpdateManager.php");
bcompiler_write_file($core, "./CORE/ETC/misc.php");
bcompiler_write_footer($core);
/* 3) writing EXE footer */
bcompiler_write_exe_footer($exe, $startpos);
/* closing the output file */
fclose($core);
fclose($exe);
copy("./DIST/libsmartsocket.dll", "../stable/libsmartsocket.dll");
echo "SmartSocket built.\n";