function build_runtime() { // 加载常量定义文件 require CORE_PATH . '/sociax/defines.php'; // 加载路径定义文件 require CORE_PATH . '/sociax/paths.php'; // 定义核心编译的文件 $runtime[] = CORE_PATH . '/sociax/functions.php'; // 系统函数 $runtime[] = CORE_PATH . '/sociax/extend.php'; // 扩展函数库 if (version_compare(PHP_VERSION, '5.2.0', '<')) { // 加载兼容函数 $runtime[] = THINK_PATH . '/Common/compat.php'; } // 核心基类必须加载 $runtime[] = THINK_PATH . '/Core/Think.class.php'; // 读取核心编译文件列表 if (is_file(CONFIG_PATH . 'core.php')) { // 加载项目自定义的核心编译文件列表 $list = (include CONFIG_PATH . 'core.php'); } else { // 加载核心编译文件 $list = (include CORE_PATH . '/sociax/core.php'); } $runtime = array_merge($runtime, $list); // 加载核心编译文件列表 foreach ($runtime as $key => $file) { if (is_file($file)) { require $file; } } // 检查项目目录结构 如果不存在则自动创建 if (!is_dir(RUNTIME_PATH)) { // 创建项目目录结构 build_app_dir(); } else { // 检查缓存目录 check_runtime(); } // 生成核心编译缓存 去掉文件空白以减少大小 // ALL_IN_ONE模式时, NO_CACHE_RUNTIME无效 if (!defined('NO_CACHE_RUNTIME')) { define('NO_CACHE_RUNTIME', false); } if (RUNTIME_ALLINONE || !NO_CACHE_RUNTIME) { $compile = RUNTIME_ALLINONE; $content = compile(CORE_PATH . '/sociax/defines.php', $compile); $content .= compile(CORE_PATH . '/sociax/paths.php', $compile); foreach ($runtime as $file) { $content .= compile($file, $compile); } if (defined('STRIP_RUNTIME_SPACE') && STRIP_RUNTIME_SPACE == false) { file_put_contents(RUNTIME_PATH . '/~runtime.php', '<?php' . $content); } else { file_put_contents(RUNTIME_PATH . '/~runtime.php', strip_whitespace('<?php' . $content)); } unset($content); } }
function build_runtime() { // 加载常量定义文件 require THINK_PATH . '/Common/defines.php'; // 加载路径定义文件 require defined('PATH_DEFINE_FILE') ? PATH_DEFINE_FILE : THINK_PATH . '/Common/paths.php'; // 定义核心编译的文件 $runtime[] = THINK_PATH . '/Common/functions.php'; // 系统函数 if (version_compare(PHP_VERSION, '5.2.0', '<')) { // 加载兼容函数 $runtime[] = THINK_PATH . '/Common/compat.php'; } // 核心基类必须加载 $runtime[] = THINK_PATH . '/Lib/Think/Core/Think.class.php'; // 读取核心编译文件列表 if (is_file(CONFIG_PATH . 'core.php')) { // 加载项目自定义的核心编译文件列表 $list = (include CONFIG_PATH . 'core.php'); } else { if (defined('THINK_MODE')) { // 根据设置的运行模式加载不同的核心编译文件 $list = (include THINK_PATH . '/Mode/' . strtolower(THINK_MODE) . '.php'); } else { // 默认核心 $list = (include THINK_PATH . '/Common/core.php'); } } $runtime = array_merge($runtime, $list); // 加载核心编译文件列表 foreach ($runtime as $key => $file) { if (is_file($file)) { require $file; } } // 检查项目目录结构 如果不存在则自动创建 if (!is_dir(RUNTIME_PATH)) { // 创建项目目录结构 build_app_dir(); } else { // 检查缓存目录 check_runtime(); } // 生成核心编译缓存 去掉文件空白以减少大小 if (!defined('NO_CACHE_RUNTIME')) { echo "gggggg"; $compile = defined('RUNTIME_ALLINONE'); $content = compile(THINK_PATH . '/Common/defines.php', $compile); $content .= compile(defined('PATH_DEFINE_FILE') ? PATH_DEFINE_FILE : THINK_PATH . '/Common/paths.php', $compile); foreach ($runtime as $file) { $content .= compile($file, $compile); } if (defined('STRIP_RUNTIME_SPACE') && STRIP_RUNTIME_SPACE == false) { file_put_contents(RUNTIME_PATH . '~runtime.php', '<?php' . $content); } else { file_put_contents(RUNTIME_PATH . '~runtime.php', strip_whitespace('<?php' . $content)); } unset($content); } }
public function run(&$params) { if (!defined('BUILD_LITE_FILE')) { return; } $litefile = C('RUNTIME_LITE_FILE', null, RUNTIME_PATH . 'lite.php'); if (is_file($litefile)) { return; } $defs = get_defined_constants(true); $content = 'namespace {$GLOBALS[\'_beginTime\'] = microtime(TRUE);'; if (MEMORY_LIMIT_ON) { $content .= '$GLOBALS[\'_startUseMems\'] = memory_get_usage();'; } // 生成数组定义 unset($defs['user']['BUILD_LITE_FILE']); $content .= $this->buildArrayDefine($defs['user']) . '}'; // 读取编译列表文件 $filelist = is_file(CONF_PATH . 'lite.php') ? include CONF_PATH . 'lite.php' : array(THINK_PATH . 'Common/functions.php', COMMON_PATH . 'Common/function.php', CORE_PATH . 'Think' . EXT, CORE_PATH . 'Hook' . EXT, CORE_PATH . 'App' . EXT, CORE_PATH . 'Dispatcher' . EXT, CORE_PATH . 'Log' . EXT, CORE_PATH . 'Log/Driver/File' . EXT, CORE_PATH . 'Route' . EXT, CORE_PATH . 'Controller' . EXT, CORE_PATH . 'View' . EXT, CORE_PATH . 'Storage' . EXT, CORE_PATH . 'Storage/Driver/File' . EXT, CORE_PATH . 'Exception' . EXT, BEHAVIOR_PATH . 'ParseTemplateBehavior' . EXT, BEHAVIOR_PATH . 'ContentReplaceBehavior' . EXT); // 编译文件 foreach ($filelist as $file) { if (is_file($file)) { $content .= compile($file); } } // 处理Think类的start方法 $content = preg_replace('/\\$runtimefile = RUNTIME_PATH(.+?)(if\\(APP_STATUS)/', '\\2', $content, 1); $content .= "\nnamespace { Think\\Think::addMap(" . var_export(\Think\Think::getMap(), true) . ");"; $content .= "\nL(" . var_export(L(), true) . ");\nC(" . var_export(C(), true) . ');Think\\Hook::import(' . var_export(\Think\Hook::get(), true) . ');Think\\Think::start();}'; // 生成运行Lite文件 file_put_contents($litefile, strip_whitespace('<?php ' . $content)); }
/** * 静态方法 启用框架的入口方法 */ public static function run() { self::debug(); //启用Debug模块 self::pathinfo(); //启用pathinfo self::initfile(); //检测并初始化系统 $controler_src = C('APP_PATH') . '/Action/' . $_GET['m'] . 'Action.class.php'; $runfile = C('RUN_PATH') . '/Action/' . $_GET['m'] . 'Action.class.php'; if (file_exists($controler_src)) { self::touch($runfile, strip_whitespace(file_get_contents($controler_src)), C('DEBUG')); $m = $_GET['m'] . 'Action'; $tmp = new $m(); Debug::addmsg("当前访问的控制器类: {$controler_src}"); method_exists($tmp, 'init') ? $tmp->init() : ''; method_exists($tmp, $_GET['a']) ? $tmp->{$_GET}['a']() : Debug::addmsg('<font color="red">当前访问的控制器类: ' . $controler_src . ' 不存在 ' . $_GET['a'] . ' 操作</font>'); } else { Debug::addmsg("<font color='red'>当前访问的控制器类: {$controler_src} 不存在!</font>"); } if (C('DEBUG')) { //DEBGU检测输出 Debug::message(); } }
/** * 设置缓存 * @param str $filename * @param mix $data * @return mix */ public function set($filename, $data) { $file = $this->dir . $filename . '.php'; $dir = dirname($filename); if (!is_dir($dir)) { mkdir($dir, 0755, true); } return file_put_contents($file, strip_whitespace("<?php\treturn " . var_export($data, true) . ";?>")); }
function test_paramsToSparql() { $params = queryStringToParams("foo.bar={school}"); $expected = " ?item gc:testPropWithApiLabel ?foo . ?foo gc:testPropWithRdfsLabel <http://education.data.gov.uk/id/school/12345> . "; $actual = $this->SW->paramsToSparql($params); $this->assertEquals(strip_whitespace($expected), strip_whitespace($actual), " Failed translating foo.bar={school}"); $params = queryStringToParams("bar.foo.age={school}"); $expected = "\n ?item gc:testPropWithRdfsLabel ?bar .\n ?bar gc:testPropWithApiLabel ?bar_foo . \n ?bar_foo gc:age <http://education.data.gov.uk/id/school/12345> . "; $actual = $this->SW->paramsToSparql($params); $this->assertEquals(strip_whitespace($expected), strip_whitespace($actual), " Failed translating bar.foo.age={school}"); }
public function test_css() { $this->_reset(); $test = trim($this->CI->asset->css('test')); $expected = '<link href="' . WEB_PATH . 'assets/css/test.css" media="all" rel="stylesheet"/>'; $this->run($test, $expected, 'Asset css() test 1'); // strip tabs to make it easier to test $test = strip_whitespace($this->CI->asset->css('test1, test2')); $expected = "<link href=\"" . WEB_PATH . "assets/css/test1.css\" media=\"all\" rel=\"stylesheet\"/>"; $expected .= "<link href=\"" . WEB_PATH . "assets/css/test2.css\" media=\"all\" rel=\"stylesheet\"/>"; $this->run($test, $expected, 'Asset css() test 2'); }
public function testfunc() { $start_time = microtime(true); $code = "//\$a='b';\n\$b='c';"; for ($i = 0; $i < 10; $i++) { $code .= "//\$a='b';\n\$b='c';"; } $start_time = microtime(true); $res = strip_whitespace($code); var_dump($res); var_dump(microtime(true) - $start_time); }
public static function set($name, $value) { $filename = static::parse_name($name); // 缓存数据 $dir = dirname($filename); // 目录不存在则创建 if (!is_dir($dir)) { mkdir($dir, 0755, true); } // 放入内存缓存 $_cache[$name] = $value; return file_put_contents($filename, strip_whitespace("<?php\treturn " . var_export($value, true) . ";?>")); }
function build_runtime_cache($append = '') { // 生成编译文件 $defs = get_defined_constants(TRUE); $content = '$GLOBALS[\'_beginTime\'] = microtime(TRUE);'; //[sae]编译SaeMC核心 $content .= compile(SAE_PATH . 'Lib/Core/SaeMC.class.php'); if (defined('RUNTIME_DEF_FILE')) { //[sae] 编译后的常量文件外部引入 //SaeMC::set(RUNTIME_DEF_FILE, '<?php '.array_define($defs['user'])); //[saebuilder] 生成常量文件 $defs['user']['APP_DEBUG'] = false; //[saebuilder] APP_DEBUG固定为false unset($defs['user']['SAE_CACHE_BUILDER']); //[saebuilder]去掉SAE_CACHE_BUILDER常量 file_put_contents(RUNTIME_DEF_FILE, '<?php ' . array_define($defs['user'])); echo 'build runtime_def_file:' . RUNTIME_DEF_FILE . PHP_EOL; $content .= 'SaeMC::include_file(\'' . RUNTIME_DEF_FILE . '\');'; } else { $content .= array_define($defs['user']); } $content .= 'set_include_path(get_include_path() . PATH_SEPARATOR . VENDOR_PATH);'; //[sae] 读取核心编译文件列表 $list = array(SAE_PATH . 'Common/common.php', SAE_PATH . 'Lib/Core/Think.class.php', CORE_PATH . 'Core/ThinkException.class.php', CORE_PATH . 'Core/Behavior.class.php'); foreach ($list as $file) { $content .= compile($file); } // 系统行为扩展文件统一编译 if (C('APP_TAGS_ON')) { $content .= build_tags_cache(); } //[sae] 编译SAE的alias $alias = (include SAE_PATH . 'Conf/alias.php'); $content .= 'alias_import(' . var_export($alias, true) . ');'; // 编译框架默认语言包和配置参数 //[saebuilder] 处理配置项,将SAE常量原样输出 $content .= $append . "\nL(" . var_export(L(), true) . ");C(" . preg_replace(array('/\'SAE_(.*?)\'/e', '/\'~([a-zA-Z_][a-zA-Z0-9_]*)\\((.*?)\\)\'/'), array('parse_sae_define("\\1")', '\\1(\\2)'), var_export(C(), true)) . ');G(\'loadTime\');Think::Start();'; //[saebuilder] 生成缓存文件 //SaeMC::set(RUNTIME_FILE, strip_whitespace('<?php '.$content)); file_put_contents(RUNTIME_FILE, strip_whitespace('<?php ' . $content)); echo 'build core file:' . RUNTIME_FILE . PHP_EOL; }
private static function build() { C(include THINK_PATH . '/Common/convention.php'); if (is_file(CONFIG_PATH . 'config.php')) { C(include CONFIG_PATH . 'config.php'); } $runtime = defined('RUNTIME_ALLINONE'); $common = ''; $debug = C('APP_DEBUG') && !$runtime; if (is_file(COMMON_PATH . 'common.php')) { include COMMON_PATH . 'common.php'; if (!$debug) { $common .= compile(COMMON_PATH . 'common.php', $runtime); } } if (is_file(CONFIG_PATH . 'app.php')) { $list = (include CONFIG_PATH . 'app.php'); foreach ($list as $file) { require $file; if (!$debug) { $common .= compile($file, $runtime); } } } $list = C('APP_CONFIG_LIST'); foreach ($list as $val) { if (is_file(CONFIG_PATH . $val . '.php')) { C('_' . $val . '_', array_change_key_case(include CONFIG_PATH . $val . '.php')); } } if ($debug) { C(include THINK_PATH . '/Common/debug.php'); if (is_file(CONFIG_PATH . 'debug.php')) { C(include CONFIG_PATH . 'debug.php'); } } else { if (defined('RUNTIME_ALLINONE')) { $defs = get_defined_constants(TRUE); $content = array_define($defs['user']); $content .= substr(file_get_contents(RUNTIME_PATH . '~runtime.php'), 5); $content .= $common . "\nreturn " . var_export(C(), true) . ';'; file_put_contents(RUNTIME_PATH . '~allinone.php', strip_whitespace('<?php ' . $content)); } else { $content = "<?php " . $common . "\nreturn " . var_export(C(), true) . ";\n?>"; file_put_contents(RUNTIME_PATH . '~app.php', strip_whitespace($content)); } } return; }
/** * Gets all defined includes * * @param array $seetags (reference) * @param string $content * @param string $file */ function find_includes(&$seetags, &$content, $file) { $tokens = get_tokens($content); foreach ($tokens as $key => &$token) { if (is_string($token)) { continue; } if (!in_array($token[0], array(T_REQUIRE, T_REQUIRE_ONCE, T_INCLUDE, T_INCLUDE_ONCE))) { continue; } $t = get_argument_tokens($tokens, $key); strip_whitespace($t); // Strip round brackets if ($t[0] === "(" and $t[count($t) - 1] === ")") { $t = array_splice($t, 1, -1); } if (!$t) { possible_syntax_error($tokens, $key, "Missing argument"); continue; } if (!is_array($t[0])) { continue; } // Strip leading docroot variable or constant if (($t[0][0] === T_VARIABLE or $t[0][0] === T_STRING) and in_array($t[0][1], $GLOBALS['docrootvars']) and $t[1] === ".") { $t = array_splice($t, 2); } if (count($t) == 1 and $t[0][0] === T_CONSTANT_ENCAPSED_STRING) { $includedfile = substr($t[0][1], 1, -1); $seetags[$includedfile][] = array($file); continue; } if (!$t) { possible_syntax_error($tokens, $key, "String concatenator without following string"); } } }
/** * 文件缓存与文件读取 * @param $name 文件名 * @param $value 文件内容,为空则获取缓存 * @param $path 文件所在目录,默认是当前应用的DATA目录 * @param $cached 是否缓存结果,默认缓存 * @return 返回缓存内容 */ function cache($name, $value = '', $path = DATA_PATH, $cached = true) { static $_cache = array(); $filename = $path . $name . '.php'; if ('' !== $value) { if (is_null($value)) { // 删除缓存 return false !== strpos($name, '*') ? array_map("unlink", glob($filename)) : unlink($filename); } else { // 缓存数据 $dir = dirname($filename); // 目录不存在则创建 if (!is_dir($dir)) { mkdir($dir, 0755, true); } $_cache[$name] = $value; return file_put_contents($filename, strip_whitespace("<?php\treturn " . var_export($value, true) . ";?>")); } } if (isset($_cache[$name]) && $cached == true) { return $_cache[$name]; } // 获取缓存数据 if (is_file($filename)) { $value = (include $filename); $_cache[$name] = $value; } else { $value = false; } return $value; }
/** * 应用程序初始化 * @access public * @return void */ public static function start() { // 注册AUTOLOAD方法 spl_autoload_register('Think\\Think::autoload'); // 设定错误和异常处理 register_shutdown_function('Think\\Think::fatalError'); set_error_handler('Think\\Think::appError'); set_exception_handler('Think\\Think::appException'); // 初始化文件存储方式 Storage::connect(STORAGE_TYPE); $runtimefile = RUNTIME_PATH . APP_MODE . '~runtime.php'; if (!APP_DEBUG && Storage::has($runtimefile)) { Storage::load($runtimefile); } else { if (Storage::has($runtimefile)) { Storage::unlink($runtimefile); } $content = ''; // 读取应用模式 $mode = (include is_file(CONF_PATH . 'core.php') ? CONF_PATH . 'core.php' : MODE_PATH . APP_MODE . '.php'); // 加载核心文件 foreach ($mode['core'] as $file) { if (is_file($file)) { include $file; if (!APP_DEBUG) { $content .= compile($file); } } } // 加载应用模式配置文件 foreach ($mode['config'] as $key => $file) { is_numeric($key) ? C(include $file) : C($key, include $file); } // 读取当前应用模式对应的配置文件 if ('common' != APP_MODE && is_file(CONF_PATH . 'config_' . APP_MODE . '.php')) { C(include CONF_PATH . 'config_' . APP_MODE . '.php'); } // 加载模式别名定义 if (isset($mode['alias'])) { self::addMap(is_array($mode['alias']) ? $mode['alias'] : (include $mode['alias'])); } // 加载应用别名定义文件 if (is_file(CONF_PATH . 'alias.php')) { self::addMap(include CONF_PATH . 'alias.php'); } // 加载模式行为定义 if (isset($mode['tags'])) { Hook::import(is_array($mode['tags']) ? $mode['tags'] : (include $mode['tags'])); } // 加载应用行为定义 if (is_file(CONF_PATH . 'tags.php')) { // 允许应用增加开发模式配置定义 Hook::import(include CONF_PATH . 'tags.php'); } // 加载框架底层语言包 L(include THINK_PATH . 'Lang/' . strtolower(C('DEFAULT_LANG')) . '.php'); if (!APP_DEBUG) { $content .= "\nnamespace { Think\\Think::addMap(" . var_export(self::$_map, true) . ");"; $content .= "\nL(" . var_export(L(), true) . ");\nC(" . var_export(C(), true) . ');Think\\Hook::import(' . var_export(Hook::get(), true) . ');}'; Storage::put($runtimefile, strip_whitespace('<?php ' . $content)); } else { // 调试模式加载系统默认的配置文件 C(include THINK_PATH . 'Conf/debug.php'); // 读取应用调试配置文件 if (is_file(CONF_PATH . 'debug.php')) { C(include CONF_PATH . 'debug.php'); } } } // 读取当前应用状态对应的配置文件 if (APP_STATUS && is_file(CONF_PATH . APP_STATUS . '.php')) { C(include CONF_PATH . APP_STATUS . '.php'); } // 设置系统时区 date_default_timezone_set(C('DEFAULT_TIMEZONE')); // 检查应用目录结构 如果不存在则自动创建 if (C('CHECK_APP_DIR') && !is_dir(LOG_PATH)) { // 创建应用目录结构 require THINK_PATH . 'Common/build.php'; } // 记录加载文件时间 G('loadTime'); // 运行应用 App::run(); }
function get_xpub_list($params, $empty_ok = false) { $list = array(); if (@$params['xpub']) { $list = explode(',', strip_whitespace($params['xpub'])); } if (@$params['xpubfile']) { $csv = implode(',', file($params['xpubfile'])); $list = explode(',', strip_whitespace($csv)); } foreach ($list as $idx => $xpub) { if (!$xpub) { unset($list[$idx]); continue; } // todo: validate length/form. if (!is_valid_xpub($xpub)) { // code 2 means an input validation exception. throw new Exception("xpub is invalid: {$xpub}", 2); } } if (!count($list) && !$empty_ok) { // code 2 means an input validation exception. throw new Exception("No valid xpub keys to process.", 2); } return $list; }
/** * Get Page Meta Description * * @since 2.0 * @uses $metad * @uses strip_decode * * @param bool $echo Optional, default is true. False will 'return' value * @return string Echos or returns based on param $echo */ function get_page_meta_desc($echo = true) { $metad = getPageGlobal('metad'); $desc = ''; if ($metad != '') { $desc = encode_quotes(strip_decode($metad)); } else { if (getDef('GSAUTOMETAD', true)) { // use content excerpt, NOT filtered $desc = strip_decode($content); if (getDef('GSCONTENTSTRIP', true)) { $desc = strip_content($desc); } $desc = cleanHtml($desc, array('style', 'script')); // remove unwanted elements that strip_tags fails to remove $desc = getExcerpt($desc, 160); // grab 160 chars $desc = strip_whitespace($desc); // remove newlines, tab chars $desc = encode_quotes($desc); $desc = trim($desc); } } $str = exec_filter('metad', $desc); // @filter metad (str) meta description in get_page_meta_desc return echoReturn($str, $echo); }
function jiamiFile() { // 取当前用户的网站信息 $map['uid'] = $this->mid; $info = M('web_info')->where($map)->find(); // 第一步:取文件内容 $file = SITE_PATH . '/test.php'; $get = trim(wp_file_get_contents($file)); if ('<?php' == strtolower(substr($get, 0, 5))) { $get = substr($get, 5); } else { $get = substr($get, 2); } if ('?>' == substr($get, -2)) { $get = substr($get, 0, -2); } // 第二步:取加密的KEY $key = substr($info['web_key'], 0, 5); $license = substr($info['web_key'], 5); // 代码里插入判断授权的代码段 $pre_code = <<<str \t\t\$ip = gethostbyname ( SITE_DOMAIN ); \t\t\$fip = strtok ( \$ip, '.' ); \t\t\$is_free = \$fip == '10' || \$fip == '127' || \$fip == '168' || \$fip == '192'; \t\tif (! \$is_free) { \t\t\t\$license = C ( 'WEIPHP_STORE_LICENSE' ); \t\t\t\$key = substr ( \$license, 0, 5 ); \t\t\t\$license = substr ( \$license, 5 );\t\t\t \t\t\t \t\t\t\$domain_str = md5 ( think_encrypt ( SITE_DOMAIN, \$key ) ); \t\t\t\$ip_str = md5 ( think_encrypt ( \$ip, \$key ) ); \t\t\tif (\$license != \$domain_str && \$license != \$ip_str) { \t\t\t\theader("Content-Type: text/html;charset=utf-8"); \t\t\t\techo '禁止访问未授权的应用'; \t\t\t\texit (); \t\t\t} \t\t} str; $content = strip_whitespace($pre_code . $get); $content = think_encrypt($content, $key); $content = "<?php eval(code_decode('{$content}'));"; dump($content); file_put_contents(SITE_PATH . '/test2.php', $content); }
/** * Compile the template file contents * @access protected * @param mixed $tmplContent Template content * @return string */ protected function compiler($tmplContent) { //Template parsing $tmplContent = $this->parse($tmplContent); // Restore is replaced Literal tags $tmplContent = preg_replace('/<!--###literal(\\d+)###-->/eis', "\$this->restoreLiteral('\\1')", $tmplContent); // Add Security Code $tmplContent = '<?php if (!defined(\'SEN_PATH\')) exit();?>' . $tmplContent; if (C('TMPL_STRIP_SPACE')) { /* Strip html whitespace and newline */ $find = array('~>\\s+<~', '~>(\\s+\\n|\\r)~'); $replace = array('><', '>'); $tmplContent = preg_replace($find, $replace, $tmplContent); } // Optimize the generated php code $tmplContent = str_replace('?><?php', '', $tmplContent); return strip_whitespace($tmplContent); }
function build_runtime_cache($append = '') { // 生成编译文件 $defs = get_defined_constants(TRUE); $content = '$GLOBALS[\'_beginTime\'] = microtime(TRUE);'; if (defined('RUNTIME_DEF_FILE')) { // 编译后的常量文件外部引入 file_put_contents(RUNTIME_DEF_FILE, '<?php ' . array_define($defs['user'])); $content .= 'require \'' . RUNTIME_DEF_FILE . '\';'; } else { $content .= array_define($defs['user']); } $content .= 'set_include_path(get_include_path() . PATH_SEPARATOR . VENDOR_PATH);'; // 读取核心编译文件列表 $list = array(THINK_PATH . 'Common/common.php', CLUSTER_PATH . 'Lib/Core/Think.class.php', CORE_PATH . 'Core/ThinkException.class.php', CORE_PATH . 'Core/Behavior.class.php'); //[cluster] 判断加载IO.php文件 $content .= 'if(!function_exists(\'runtime_set\')){' . compile(IO_PATH) . '}'; //[cluster] 判断加载ThinkFS文件 $content .= 'if(!class_exists(\'ThinkFS\')){' . compile(CLUSTER_PATH . 'Lib/Core/ThinkFS.class.php') . '}'; foreach ($list as $file) { $content .= compile($file); } // 系统行为扩展文件统一编译 $content .= build_tags_cache(); $alias = (include CLUSTER_PATH . 'Conf/alias.php'); $content .= 'alias_import(' . var_export($alias, true) . ');'; // 编译框架默认语言包和配置参数 $content .= $append . "\nL(" . var_export(L(), true) . ");C(" . var_export(C(), true) . ');G(\'loadTime\');Think::Start();'; //[cluster] 生成核心缓存 ThinkFS::set(RUNTIME_FILE, strip_whitespace('<?php ' . str_replace("defined('THINK_PATH') or exit();", ' ', $content))); }
protected function checkCompile() { $tplfile = ltrim(str_replace(array(PT_ROOT, '/application/', '/template/'), '/', $this->tplFile), '/'); $compiledFile = CACHE_PATH . '/template/' . substr(str_replace('/', ',', $tplfile), 0, -5) . '.php'; $compile = true; if (APP_MODE == 'sae') { $timekey = md5($compiledFile . '_time'); $compiledFile = 'saekv://' . md5($compiledFile); if (!APP_DEBUG && Cache::get($timekey) > filemtime($this->tplFile)) { $compile = false; } } else { if (!APP_DEBUG && is_file($compiledFile) && filemtime($compiledFile) > filemtime($this->tplFile)) { $compile = false; } } if ($compile) { $content = file_get_contents($this->tplFile); plugin::call('template_compile_start', $content); $content = $this->compile($content); if (!APP_DEBUG) { $content = preg_replace_callback('/<style[^>]*>([^<]*)<\\/style>/isU', array('self', 'compressCss'), $content); $content = preg_replace_callback('/<script[^>]*>([^<]+?)<\\/script>/isU', array('self', 'compressJs'), $content); $content = preg_replace(array("/>\\s+</"), array('> <'), $content); $content = preg_replace('/\\?>\\s*<\\?php/', '', $content); $content = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' '), ' ', $content); $content = strip_whitespace($content); } //判断是否开启layout if (C('LAYOUT', null, false)) { $includeFile = $this->getTplFile(C('LAYOUT_NAME', null, 'layout')); $truereturn = realpath($includeFile); if ($truereturn) { $layout = $this->compile(file_get_contents($truereturn)); $content = str_replace('__CONTENT__', $content, $layout); } else { halt("无法找到对应的layout模版:{$truereturn}"); } } $content = '<?php defined(\'PT_ROOT\') || exit(\'Permission denied\');?>' . $this->replace($content); if (APP_MODE == 'sae') { Cache::set($timekey, NOW_TIME); } plugin::call('template_compile_end', $content); F($compiledFile, $content); } return $compiledFile; }
function F($name, $value = '', $path = DATA_PATH) { static $_cache = array(); $filename = $path . $name . '.php'; if ('' !== $value) { if (is_null($value)) { // 删除缓存 return unlink($filename); } else { // 缓存数据 $dir = dirname($filename); // 目录不存在则创建 if (!is_dir($dir)) { mkdir($dir); } $_cache[$name] = $value; return file_put_contents($filename, strip_whitespace("<?php\nreturn " . var_export($value, true) . ";\n?>")); } } if (isset($_cache[$name])) { return $_cache[$name]; } // 获取缓存数据 if (is_file($filename)) { $value = (include $filename); $_cache[$name] = $value; } else { $value = false; } return $value; }
for ($k = $i + 1; $k < $j; $k++) { if (is_string($tokens[$k]) && $tokens[$k] == ';') { $i = $k; break; } else { if ($tokens[$k][0] == T_CLOSE_TAG) { break; } } } break; default: $last_space = false; $stripStr .= $tokens[$i][1]; } } } return $stripStr; } if (!isset($_GET["f"])) { exit; } $f_list = explode(",", $_GET["f"]); $js_content = ""; $base_path = dirname(__FILE__) . DIRECTORY_SEPARATOR; foreach ($f_list as $file) { if (is_file($base_path . $file . ".js")) { $js_content .= strip_whitespace(file_get_contents($base_path . $file . ".js")); } } echo $js_content;
/** +---------------------------------------------------------- * 读取配置信息 编译项目 +---------------------------------------------------------- * @access private +---------------------------------------------------------- * @return string +---------------------------------------------------------- */ private static function build() { // 加载惯例配置文件 C(include THINK_PATH . '/Common/convention.php'); // 加载项目配置文件 if (is_file(CONFIG_PATH . 'config.php')) { C(include CONFIG_PATH . 'config.php'); } $common = ''; $debug = C('APP_DEBUG'); // 是否调试模式 // 加载项目公共文件 if (is_file(COMMON_PATH . 'common.php')) { include COMMON_PATH . 'common.php'; if (!$debug) { // 编译文件 $common .= compile(COMMON_PATH . 'common.php'); } } // 加载项目编译文件列表 if (is_file(CONFIG_PATH . 'app.php')) { $list = (include CONFIG_PATH . 'app.php'); foreach ($list as $key => $file) { // 加载并编译文件 require $file; if (!$debug) { $common .= compile($file); } } } // 如果是调试模式加载调试模式配置文件 if ($debug) { // 加载系统默认的开发模式配置文件 C(include THINK_PATH . '/Common/debug.php'); if (is_file(CONFIG_PATH . 'debug.php')) { // 允许项目增加开发模式配置定义 C(include CONFIG_PATH . 'debug.php'); } } else { // 部署模式下面生成编译文件 // 下次直接加载项目编译文件 if (defined('RUNTIME_ALLINONE')) { // 获取用户自定义变量 $defs = get_defined_constants(TRUE); $content = array_define($defs['user']); $content .= substr(file_get_contents(RUNTIME_PATH . '~runtime.php'), 5); $content .= $common . "\nreturn " . var_export(C(), true) . ';'; file_put_contents(RUNTIME_PATH . '~allinone.php', strip_whitespace('<?php ' . $content)); } else { $content = "<?php " . $common . "\nreturn " . var_export(C(), true) . ";\n?>"; file_put_contents(RUNTIME_PATH . '~app.php', strip_whitespace($content)); } } return; }
function build_runtime_cache($append = '') { // 生成编译文件 $defs = get_defined_constants(TRUE); $content = '$GLOBALS[\'_beginTime\'] = microtime(TRUE);'; //[sae]编译SaeMC核心 $content .= compile(SAE_PATH . 'Lib/Core/SaeMC.class.php'); if (defined('RUNTIME_DEF_FILE')) { //[sae] 编译后的常量文件外部引入 SaeMC::set(RUNTIME_DEF_FILE, '<?php ' . array_define($defs['user'])); $content .= 'SaeMC::include_file(\'' . RUNTIME_DEF_FILE . '\');'; } else { $content .= array_define($defs['user']); } $content .= 'set_include_path(get_include_path() . PATH_SEPARATOR . VENDOR_PATH);'; //[sae] 读取核心编译文件列表 $list = array(SAE_PATH . 'Common/common.php', SAE_PATH . 'Common/sae_common.php', SAE_PATH . 'Lib/Core/Think.class.php', CORE_PATH . 'Core/ThinkException.class.php', CORE_PATH . 'Core/Behavior.class.php'); foreach ($list as $file) { $content .= compile($file); } // 系统行为扩展文件统一编译 $content .= build_tags_cache(); //[sae] 编译SAE的alias $alias = (include SAE_PATH . 'Conf/alias.php'); $content .= 'alias_import(' . var_export($alias, true) . ');'; // 编译框架默认语言包和配置参数 $content .= $append . "\nL(" . var_export(L(), true) . ");C(" . var_export(C(), true) . ');G(\'loadTime\');Think::Start();'; //[sae] 生成编译缓存文件 SaeMC::set(RUNTIME_FILE, strip_whitespace('<?php ' . str_replace("defined('THINK_PATH') or exit();", ' ', $content))); }
function build_runtime_cache($append = '') { // 生成编译文件 $defs = get_defined_constants(TRUE); $content = '$GLOBALS[\'_beginTime\'] = microtime(TRUE);'; if (defined('RUNTIME_DEF_FILE')) { // 编译后的常量文件外部引入 file_put_contents(RUNTIME_DEF_FILE, '<?php ' . array_define($defs['user'])); $content .= 'require \'' . RUNTIME_DEF_FILE . '\';'; } else { $content .= array_define($defs['user']); } $content .= 'set_include_path(get_include_path() . PATH_SEPARATOR . VENDOR_PATH);'; // 读取核心编译文件列表 $list = array(THINK_PATH . 'Common/common.php', CORE_PATH . 'Core/Think.class.php', CORE_PATH . 'Core/ThinkException.class.php', CORE_PATH . 'Core/Behavior.class.php'); foreach ($list as $file) { $content .= compile($file); } // 系统行为扩展文件统一编译 if (C('APP_TAGS_ON')) { $content .= build_tags_cache(); } $alias = (include THINK_PATH . 'Conf/alias.php'); $content .= 'alias_import(' . var_export($alias, true) . ');'; // 编译框架默认语言包和配置参数 $content .= $append . "\nL(" . var_export(L(), true) . ");C(" . var_export(C(), true) . ');G(\'loadTime\');Think::Start();'; file_put_contents(RUNTIME_FILE, strip_whitespace('<?php ' . $content)); }
/** +---------------------------------------------------------- * 读取配置信息 编译项目 +---------------------------------------------------------- * @access private +---------------------------------------------------------- * @return string +---------------------------------------------------------- */ private static function build() { // 加载惯例配置文件 C(include THINK_PATH . '/Common/convention.php'); // 加载项目配置文件 if (is_file(CONFIG_PATH . 'config.php')) { C(include CONFIG_PATH . 'config.php'); } $runtime = defined('RUNTIME_ALLINONE'); $common = ''; //是否调试模式 ALL_IN_ONE模式下面调试模式无效 $debug = C('APP_DEBUG') && !$runtime; // 加载项目公共文件 if (is_file(COMMON_PATH . 'common.php')) { include COMMON_PATH . 'common.php'; // 编译文件 if (!$debug) { $common .= compile(COMMON_PATH . 'common.php', $runtime); } } // 加载项目编译文件列表 if (is_file(CONFIG_PATH . 'app.php')) { $list = (include CONFIG_PATH . 'app.php'); foreach ($list as $file) { // 加载并编译文件 require $file; if (!$debug) { $common .= compile($file, $runtime); } } } // 读取扩展配置文件 $list = C('APP_CONFIG_LIST'); foreach ($list as $val) { if (is_file(CONFIG_PATH . $val . '.php')) { C('_' . $val . '_', array_change_key_case(include CONFIG_PATH . $val . '.php')); } } // 如果是调试模式加载调试模式配置文件 if ($debug) { // 加载系统默认的开发模式配置文件 C(include THINK_PATH . '/Common/debug.php'); if (is_file(CONFIG_PATH . 'debug.php')) { // 允许项目增加开发模式配置定义 C(include CONFIG_PATH . 'debug.php'); } } else { // 部署模式下面生成编译文件 // 下次直接加载项目编译文件 if ($runtime) { // 获取用户自定义变量 $defs = get_defined_constants(TRUE); $content = array_define($defs['user']); $runtimefile = defined('THINK_MODE') ? '~' . strtolower(THINK_MODE) . '_runtime.php' : '~runtime.php'; $content .= substr(file_get_contents(RUNTIME_PATH . $runtimefile), 5); $content .= $common . "\nreturn " . var_export(C(), true) . ';'; file_put_contents(RUNTIME_PATH . '~allinone.php', strip_whitespace('<?php ' . $content)); } else { $content = "<?php " . $common . "\nreturn " . var_export(C(), true) . ";\n?>"; file_put_contents(RUNTIME_PATH . '~' . APP_CACHE_NAME . '.php', strip_whitespace($content)); } } return; }
/** * 编译模板文件内容 * @access protected * @param mixed $tmplContent 模板内容 * @return string */ protected function compiler($tmplContent) { //模板解析 $tmplContent = $this->parse($tmplContent); // 还原被替换的Literal标签 $tmplContent = preg_replace_callback('/<!--###literal(\\d+)###-->/is', array($this, 'restoreLiteral'), $tmplContent); // 添加安全代码 $tmplContent = '<?php if (!defined(\'THINK_PATH\')) exit();?>' . $tmplContent; // 优化生成的php代码 $tmplContent = str_replace('?><?php', '', $tmplContent); // 模版编译过滤标签 Hook::listen('template_filter', $tmplContent); return strip_whitespace($tmplContent); }
function test_hidden_items() { $this->nav['about'] = 'About'; $this->nav['about/history']['hidden'] = TRUE; $this->nav['about/contact']['hidden'] = TRUE; $this->nav['products'] = 'Products'; $this->nav['products/X3000']['hidden'] = TRUE; $this->CI->menu->reset(); $menu = $this->CI->menu->render($this->nav); $test = strip_whitespace($menu); $str = ' <ul> <li class="first"><a href="' . site_url('about') . '" title="About">About</a></li> <li class="last"><a href="' . site_url('products') . '" title="Products">Products</a></li> </ul>'; $expected = strip_whitespace($str); $this->run($test, $expected, 'Test hidden items'); }
/** * 编译模板文件内容 * @access protected * @param mixed $tmplContent 模板内容 * @return string */ protected function compiler($tmplContent) { //模板解析 $tmplContent = $this->parse($tmplContent); // 还原被替换的Literal标签 $tmplContent = preg_replace('/<!--###literal(\\d+)###-->/eis', "\$this->restoreLiteral('\\1')", $tmplContent); // 添加安全代码 $tmplContent = '<?php if (!defined(\'THINK_PATH\')) exit();?>' . $tmplContent; if (C('TMPL_STRIP_SPACE')) { /* 去除html空格与换行 */ $find = array('~>\\s+<~', '~>(\\s+\\n|\\r)~'); $replace = array('><', '>'); $tmplContent = preg_replace($find, $replace, $tmplContent); } // 优化生成的php代码 $tmplContent = str_replace('?><?php', '', $tmplContent); return strip_whitespace($tmplContent); }
/** * 快速文件数据读取和保存 针对简单类型数据 字符串、数组 * @param string $name 缓存名称 * @param mixed $value 缓存值 * @param string $path 缓存路径 * @return mixed */ function F($name, $value = '', $path = DATA_PATH) { static $_cache = array(); $filename = $path . $name . '.php'; if ('' !== $value) { if (is_null($value)) { // 删除缓存 return false !== strpos($name, '*') ? array_map("unlink", glob($filename)) : unlink($filename); } else { // 缓存数据 $dir = dirname($filename); // 目录不存在则创建 if (!is_dir($dir)) { mkdir($dir, 0755, true); } $_cache[$name] = $value; return file_put_contents($filename, strip_whitespace("<?php\treturn " . var_export($value, true) . ";?>")); } } if (isset($_cache[$name])) { return $_cache[$name]; } // 获取缓存数据 if (is_file($filename)) { $value = (include $filename); $_cache[$name] = $value; } else { $value = false; //核心缓存处理 switch ($name) { case 'App': D("Module")->module_cache(); $value = F('App'); break; case 'Behavior': D('Behavior')->behavior_cache(); $value = F('Behavior'); break; case 'Model': D("Model")->model_cache(); $value = F('Model'); break; case 'Category': D("Category")->category_cache(); D("Content_cache")->model_content_cache(); D("Position")->position_cache(); $value = F('Category'); break; case 'Config': D("Config")->config_cache(); $value = F('Config'); break; } } return $value; }