Esempio n. 1
0
 public static function load($ac)
 {
     if (empty($ac) || !isset(self::$_Instance->array[self::$_Instance->domain][$ac])) {
         return false;
     }
     $ac_array = self::$_Instance->array[self::$_Instance->domain][$ac];
     if (empty($ac_array) || $ac_array[0] == 'self') {
         $info = self::$_Instance->{$ac}();
     } elseif ($ac_array[0] == 'module') {
         $function = $ac_array[2];
         $class = XG::M($ac_array[1]);
         if (empty($ac_array[3])) {
             $info = $class->{$function}();
         } else {
             $eval_string = implode(',', $ac_array[3]);
             eval('$info = $class->$function(' . $eval_string . ');');
         }
         $ac_array[4] = empty($ac_array[4]) ? '' : $ac_array[4];
         switch ($ac_array[4]) {
             case 'boole':
                 $info = $info ? 1 : 0;
                 break;
             case 'int':
                 $info = intval($info);
                 break;
             case 'callback':
                 $info = self::$_Instance->{$ac}($info);
                 break;
             case 'string':
             case 'array':
             default:
         }
     }
     self::returnInfo($info);
 }
Esempio n. 2
0
 public function getValue($key)
 {
     $sql = 'select value from `user_value` where `uid`="' . $this->getUid() . '" and key="' . $key . '"';
     $db = XG::getMysql();
     $row = $db->getOne($sql);
     return unserialize($row);
 }
Esempio n. 3
0
 public static function combine()
 {
     // 线上未找到的文件
     $unfound = array();
     //文件类型
     $type = '';
     //原始请求文件完整路径数组
     $files = array();
     //过滤后的文件完整路径数组,即待抓取的文件列表
     $a_files = array();
     //文件的最后修改时间
     $last_modified_time = 0;
     // request headers
     $request_headers = getallheaders();
     // 输出结果使用的数组
     $R_files = array();
     //得到文件夹路径
     $prefix = realpath(dirname(__FILE__)) . '/';
     // 处理请求中附带的文件列表,得到原始数据
     $pos = strpos("??", $_SERVER['REQUEST_URI']);
     if ($pos !== false) {
         $file_string = substr($_SERVER['REQUEST_URI'], $pos + 2);
         $_tmp = explode(',', $file_string);
         foreach ($_tmp as $v) {
             $files[] = $prefix . $v;
         }
     }
     // 得到需要读取的文件列表
     foreach ($files as $k) {
         //将开头的/和?去掉,和上级目录
         $k = preg_replace(array('/^\\//', '/\\?.+$/', '\\.\\.\\/'), array('', '', ''), $k);
         if (!preg_match('/(\\.js|\\.css)$/', $k)) {
             continue;
         }
         $a_files[] = $k;
     }
     // 得到拼接文件的Last-Modified时间
     foreach ($a_files as $k) {
         if (file_exists($k)) {
             $filemtime = filemtime($k);
             if ($filemtime && $filemtime > $last_modified_time) {
                 $last_modified_time = $filemtime;
             }
         }
     }
     // 检查请求头的if-modified-since,判断是否304
     if (isset($request_headers['If-Modified-Since']) && strtotime($request_headers['If-Modified-Since']) == $last_modified_time) {
         // 如果客户端带有缓存
         header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $last_modified_time . ' GMT'), true, 304);
         exit;
     }
     if (self::$_Minify) {
         $class = XG::T('optimize.combine.' . $type);
     }
     // 拼接文件,并应用通用规则
     foreach ($a_files as $k) {
         if (empty($type)) {
             $type = self::getExtend($k);
         }
         $in_str = file_get_contents($k);
         if ($in_str === false) {
             $unfound[] = $k;
         } elseif (self::$_Minify) {
             //$R_files[] = $class::minify($in_str);
             $R_files[] = call_user_func_array(array($class, 'minify'), array($in_str));
         } else {
             $R_files[] = $in_str;
         }
     }
     //添加过期头,过期时间1年
     header("Expires: " . date("D, j M Y H:i:s", strtotime("now + 10 years")) . " GMT");
     header("Cache-Control: max-age=315360000");
     header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $last_modified_time) . ' GMT');
     //输出文件类型
     header(self::$_Header[$type]);
     //拼装文件
     $result = join("\n", $R_files);
     //输出文件
     echo $result;
     echo "/* non published files:\n";
     echo join("\n", $unfound);
     echo "\n*/";
 }