/** * 编译模板函数 * * @access public * @param string $filename * * @return sring 编译后文件地址 */ function make_compiled($filename) { $name = $this->compile_dir . '/' . basename($filename) . '.php'; if ($this->_expires) { $expires = $this->_expires - $this->cache_lifetime; } else { $filestat = @stat($name); $expires = $filestat['mtime']; } $filestat = @stat($filename); if ($filestat['mtime'] <= $expires && !$this->force_compile) { if (file_exists($name)) { $source = $this->_require($name); if ($source == '') { $expires = 0; } } else { $source = ''; $expires = 0; } } if ($this->force_compile || $filestat['mtime'] > $expires) { $this->_current_file = $filename; $source = $this->fetch_str(file_get_contents($filename)); if (file_put_contents(saemc($name), $source) === false) { trigger_error('can\'t write:' . saemc($name)); } $source = $this->_eval($source); } return $source; }
* and open the template in the editor. */ $flashdb = array(); if (file_exists(saemc(DATA_DIR . '/flash_data.xml'))) { // 兼容v2.7.0及以前版本 if (!preg_match_all('/item_url="([^"]+)"\\slink="([^"]+)"\\stext="([^"]*)"\\ssort="([^"]*)"/', file_get_contents(saemc(DATA_DIR . '/flash_data.xml')), $t, PREG_SET_ORDER)) { preg_match_all('/item_url="([^"]+)"\\slink="([^"]+)"\\stext="([^"]*)"/', file_get_contents(saemc(DATA_DIR . '/flash_data.xml')), $t, PREG_SET_ORDER); } if (!empty($t)) { foreach ($t as $key => $val) { $val[4] = isset($val[4]) ? $val[4] : 0; $flashdb[] = array('src' => $val[1], 'url' => $val[2], 'text' => $val[3], 'sort' => $val[4]); } } } dump(saemc(DATA_DIR . '/flash_data.xml'), 'saemc://data/flash_data.xml'); dump($flashdb, 'flashdb'); $ads = $flashdb; // function saemc($file) { $file = " " . $file; if (stripos($file, SAEMC) > 0) { return @ltrim($file); } else { $file = @ltrim($file); $file = @ltrim($file, "../"); $file = @ltrim($file, "/"); return SAEMC . $file; } }
$ecs_user = $db->getOne('SELECT COUNT(*) FROM ' . $ecs->table('users')); $ecs_template = $db->getOne('SELECT value FROM ' . $ecs->table('shop_config') . ' WHERE code = \'template\''); $style = $db->getOne('SELECT value FROM ' . $ecs->table('shop_config') . ' WHERE code = \'stylename\''); if ($style == '') { $style = '0'; } $ecs_style = $style; $shop_url = urlencode($ecs->url()); $patch_file = file_get_contents(ROOT_PATH . ADMIN_PATH . "/patch_num"); $apiget = "ver= {$ecs_version} &lang= {$ecs_lang} &release= {$ecs_release} &php_ver= {$php_ver} &mysql_ver= {$mysql_ver} &ocount= {$ocount} &oamount= {$oamount} &gcount= {$gcount} &charset= {$ecs_charset} &usecount= {$ecs_user} &template= {$ecs_template} &style= {$ecs_style} &url= {$shop_url} &patch= {$patch_file} "; $t = new transport(); $api_comment = $t->request('http://api.ecshop.com/checkver.php', $apiget); $api_str = $api_comment["body"]; echo $api_str; $f = ROOT_PATH . 'data/config.php'; file_put_contents(saemc($f), str_replace("'API_TIME', '" . API_TIME . "'", "'API_TIME', '" . date('Y-m-d H:i:s', time()) . "'", file_get_contents($f))); write_static_cache('api_str', $api_str); } else { echo $data; } } elseif ($_REQUEST['act'] == 'first') { $smarty->assign('countries', get_regions()); $smarty->assign('provinces', get_regions(1, 1)); $smarty->assign('cities', get_regions(2, 2)); $sql = 'SELECT value from ' . $ecs->table('shop_config') . " WHERE code='shop_name'"; $shop_name = $db->getOne($sql); $smarty->assign('shop_name', $shop_name); $sql = 'SELECT value from ' . $ecs->table('shop_config') . " WHERE code='shop_title'"; $shop_title = $db->getOne($sql); $smarty->assign('shop_title', $shop_title); //获取配送方式
/** * 写结果缓存文件 * * @params string $cache_name * @params string $caches * * @return */ function write_static_cache($cache_name, $caches) { if ((DEBUG_MODE & 2) == 2) { return false; } $cache_file_path = saemc('temp/static_caches/' . $cache_name . '.php'); $content = "<?php\r\n"; $content .= "\$data = " . var_export($caches, true) . ";\r\n"; $content .= "?>"; // dump($cache_file_path,'$cache_file_path lib_base 1024'); file_put_contents($cache_file_path, $content); }
/** * 清除指定后缀的模板缓存或编译文件 * * @access public * @param bool $is_cache 是否清除缓存还是清出编译文件 * @param string $ext 需要删除的文件名,不包含后缀 * * @return int 返回清除的文件个数 */ function clear_tpl_files($is_cache = true, $ext = '') { $mmc = memcache_init(); $mmc->flush(); return TRUE; $dirs = array(); if (isset($GLOBALS['shop_id']) && $GLOBALS['shop_id'] > 0) { $tmp_dir = DATA_DIR; } else { $tmp_dir = 'temp'; } if ($is_cache) { $cache_dir = saemc($tmp_dir . '/caches/'); $dirs[] = saemc($tmp_dir . '/query_caches/'); $dirs[] = saemc($tmp_dir . '/static_caches/'); for ($i = 0; $i < 16; $i++) { $hash_dir = $cache_dir . dechex($i); $dirs[] = $hash_dir . '/'; } } else { $dirs[] = saemc($tmp_dir . '/compiled/'); $dirs[] = saemc($tmp_dir . '/compiled/admin/'); } $str_len = strlen($ext); $count = 0; foreach ($dirs as $dir) { make_dir($dir); $folder = @opendir($dir); if ($folder === false) { continue; } while ($file = readdir($folder)) { if ($file == '.' || $file == '..' || $file == 'index.htm' || $file == 'index.html') { continue; } if (is_file($dir . $file)) { /* 如果有文件名则判断是否匹配 */ $pos = $is_cache ? strrpos($file, '_') : strrpos($file, '.'); if ($str_len > 0 && $pos !== false) { $ext_str = substr($file, 0, $pos); if ($ext_str == $ext) { if (@unlink($dir . $file)) { $count++; } } } else { if (@unlink($dir . $file)) { $count++; } } } } closedir($folder); } return $count; }