/** * 取得变量的存储文件名 * @param string $name 缓存变量名 * @return string */ private function filename($name) { $name = md5($name); if (C('DATA_CACHE_SUBDIR')) { // 使用子目录 $dir = ''; for ($i = 0; $i < C('DATA_PATH_LEVEL'); $i++) { $dir .= $name[$i] . '/'; } if (!is_dir($this->options['temp'] . $dir)) { \Medz\Component\Filesystem\Filesystem::mkdir($this->options['temp'] . $dir, 0777); } $filename = $dir . $this->options['prefix'] . $name . '.php'; } else { $filename = $this->options['prefix'] . $name . '.php'; } return $this->options['temp'] . $filename; }
/** * 执行App控制器 */ public static function execApp() { //防止CSRF if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST' && stripos($_SERVER['HTTP_REFERER'], SITE_URL) !== 0 && $_SERVER['HTTP_USER_AGENT'] !== 'Shockwave Flash' && strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'adobe flash player') === false && MODULE_NAME != 'Weixin') { exit('illegal request.'); } // 微信自动登陆和绑定 $openid = session('wx_open_id'); $mid = $_SESSION['mid'] ?: $_SESSION['uid']; // var_dump($openid);exit; if ($openid) { $login = Ts\Models\Login::byType('weixin')->byVendorId($openid)->orderBy('login_id', 'desc')->first(); if (!$login && $mid) { $login = new Ts\Model\Login(); $login->uid = $mid; $login->type_uid = $openid; $login->type = 'weixin'; $login->is_sync = 0; $login->save(); // var_dump(123); } // var_dump($openid, $login, $_SESSION);exit; if (!$mid && $login) { $_SESSION['mid'] = $login->uid; } } // 微信 if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false && isset($_REQUEST['w_sign']) && !$openid) { U('h5/sign/weixin', '', true); /* # 跳转移动版首页,以后有时间,可以做兼容跳转 */ } elseif ($_SESSION['wap_to_normal'] != 1 and cookie('wap_to_normal') != 1 and $_REQUEST['wap_to_normal'] != 1 and !isiPad() and json_decode(json_encode(model('Xdata')->get('admin_Mobile:setting')), false)->switch and in_array(APP_NAME, array('public', 'channel', 'weiba', 'square', 'people')) and MODULE_NAME != 'Widget' and !in_array(strtolower(MODULE_NAME), array('message', 'register', 'feed')) and strtolower(ACTION_NAME) != 'message' and isMobile()) { if (\Medz\Component\Filesystem\Filesystem::exists(TS_APPLICATION . '/h5') === true) { Jumper::start(); } } $GLOBALS['time_run_detail']['addons_end'] = microtime(true); //创建Action控制器实例 $className = MODULE_NAME . 'Action'; // tsload(APP_ACTION_PATH.'/'.$className.'.class.php'); $action = ACTION_NAME; // action名称 $appTimer = sprintf('%s/%s/app/%s/timer', TS_ROOT, TS_STORAGE, strtolower(APP_NAME)); if (!file_exists($appTimer) || time() - file_get_contents($appTimer) > 604800 || defined('TS_APP_DEV') && TS_APP_DEV == true) { \Ts\Helper\AppInstall::getInstance(APP_NAME)->moveResources(); \Medz\Component\Filesystem\Filesystem::mkdir(dirname($appTimer), 0777); file_put_contents($appTimer, time()); } $app = new \Ts\Helper\Controller(); $app->setApp(APP_NAME)->setController(MODULE_NAME)->setAction(ACTION_NAME)->run(); //执行计划任务 model('Schedule')->run(); $GLOBALS['time_run_detail']['action_run'] = microtime(true); return; }
public function cleancache() { // 清文件缓存 $dirs = array(TS_ROOT . TS_STORAGE . '/temp/'); // 清理缓存 foreach ($dirs as $value) { $this->_rmdirr($value); echo "<div style='border:2px solid green; background:#f1f1f1; padding:20px;margin:20px;width:800px;font-weight:bold;color:green;text-align:center;'>\"" . $value . '" 文件缓存目录已经删除! </div> <br /><br />'; } \Medz\Component\Filesystem\Filesystem::mkdir(TS_ROOT . TS_STORAGE . '/temp', 0777); //其它缓存清理 model('Cache')->clear(); }
/** * 移动Ts中应用中所有的静态资源 * * @author Seven Du <*****@*****.**> **/ public static function moveAllApplicationResources() { $handle = opendir(TS_APPLICATION); while (($file = readdir($handle)) !== false) { if (in_array($file, array('.', '..'))) { continue; } $manageFile = sprintf('%s/%s/manage.json', TS_APPLICATION, $file); if (!file_exists($manageFile) || !($manageInfo = json_decode(file_get_contents($manageFile), true))) { continue; } elseif (!isset($manageInfo['resource'])) { $manageInfo['resource'] = '_static'; } Filesystem::mirror(sprintf('%s/%s/%s', TS_APPLICATION, $file, $manageInfo['resource']), sprintf('%s/%s/app/%s', TS_ROOT, TS_STORAGE, strtolower($file))); } closedir($handle); }
/** * 运行控制器 */ public static function run() { // 设定错误和异常处理 set_error_handler(array('App', 'appError')); set_exception_handler(array('App', 'appException')); // Session初始化 if (!session_id()) { session_start(); } // 模版检查 $GLOBALS['time_run_detail']['init_end'] = microtime(true); //检查服务器是否开启了zlib拓展 if (C('GZIP_OPEN') && extension_loaded('zlib') && function_exists('ob_gzhandler')) { ob_end_clean(); ob_start('ob_gzhandler'); } $GLOBALS['time_run_detail']['obstart'] = microtime(true); $pharApiFile = sprintf('%s/api/ts-api.phar', TS_ROOT); if (constant('API_VERSION') && API_VERSION == 'sociax' && !\Medz\Component\Filesystem\Filesystem::exists(sprintf('%s/api/sociax', TS_ROOT))) { $class_file = sprintf('phar://%s/%sApi.class.php', $pharApiFile, MODULE_NAME); } elseif (constant('API_VERSION')) { $class_file = SITE_PATH . '/api/' . API_VERSION . '/' . MODULE_NAME . 'Api.class.php'; } else { $class_file = SITE_PATH . '/api/thinksns/' . MODULE_NAME . 'Api.class.php'; } if (!file_exists($class_file)) { $message['msg'] = '接口不存在'; $message['status'] = 404; API::error($message); } //执行当前操作 include $class_file; $className = MODULE_NAME . 'Api'; $module = new $className(); $action = ACTION_NAME; $data = call_user_func(array(&$module, $action)); //格式化输出 if ($_REQUEST['format'] == 'php') { //输出php格式 echo var_export($data); } elseif ($_REQUEST['format'] == 'test') { //测试输出 dump($data); } else { header('Content-Type:application/json'); echo json_encode($data); } //输出buffer中的内容,即压缩后的css文件 if (C('GZIP_OPEN') && extension_loaded('zlib') && function_exists('ob_gzhandler')) { ob_end_flush(); } $GLOBALS['time_run_detail']['obflush'] = microtime(true); if (C('LOG_RECORD')) { Log::save(); } return; }
//默认静态文件、模版文件目录 tsdefine('THEME_PATH', ADDON_PATH . '/theme/' . THEME_NAME); tsdefine('THEME_URL', ADDON_URL . '/theme/' . THEME_NAME); tsdefine('THEME_PUBLIC_PATH', THEME_PATH . '/_static'); tsdefine('THEME_PUBLIC_URL', THEME_URL . '/_static'); tsdefine('APP_PUBLIC_PATH', APP_PATH . '/_static'); // tsdefine('APP_PUBLIC_URL', APP_URL.'/_static'); tsdefine('APP_TPL_PATH', APP_PATH . '/Tpl/default'); tsdefine('APP_TPL_URL', APP_URL . '/Tpl/default'); tsdefine('CANVAS_PATH', SITE_PATH . '/config/canvas/'); /* 临时兼容代码,新方法开发中 */ $timer = sprintf('%s%s/app/timer', TS_ROOT, TS_STORAGE); if (!file_exists($timer) || time() - file_get_contents($timer) > 604800) { \Ts\Helper\AppInstall::moveAllApplicationResources(); // 移动应用所有的资源 \Medz\Component\Filesystem\Filesystem::mkdir(dirname($timer), 0777); file_put_contents($timer, time()); } define('APP_PUBLIC_URL', sprintf('%s%s/app/%s', SITE_URL, TS_STORAGE, strtolower(APP_NAME))); //设置语言包 setLang(); /* * 新应用入口文件 */ if (file_exists(sprintf('%s/bootstrap.php', APP_PATH))) { Ts::import(APP_PATH, 'bootstrap', '.php'); /* * 兼容旧的应用 */ } elseif (file_exists(sprintf('%s/common.php', APP_COMMON_PATH))) { Ts::import(APP_COMMON_PATH, 'common', '.php');
public function testDelete() { $this->assertEquals(true, Filesystem::delete(static::$file)); }
function mk_dir($dir, $mode = 0755) { return \Medz\Component\Filesystem\Filesystem::mkdir($dir, $mode); }