Пример #1
0
 /**
  * 从已加密的cookie中取出值
  *
  * @param string $params cookie的key
  * @param bool $de
  * @return bool|mixed|string
  */
 function get($params, $de = false)
 {
     $de_json = false;
     if (false !== strpos($params, ':')) {
         list($v_key, $c_key) = explode(':', $params);
         $de_json = true;
     } else {
         $v_key = $params;
     }
     if (isset($_COOKIE[$v_key])) {
         $str = $_COOKIE[$v_key];
     } else {
         return false;
     }
     $key = $this->cookieKey($v_key);
     $result = Helper::authCode($str, 'DECODE', $key);
     if (!$result) {
         return false;
     }
     if ($de_json || $de) {
         $result = json_decode($result, true);
         if (!empty($c_key) && !empty($result[$c_key])) {
             return $result[$c_key];
         }
         return $result;
     }
     return $result;
 }
Пример #2
0
 /**
  * 参数加密
  *
  * @param $tex
  * @param string $type
  * @return bool|string
  */
 protected function urlEncrypt($tex, $type = 'encode')
 {
     $key = $this->getUrlEncryptKey();
     return Helper::encodeParams($tex, $key, $type);
 }
Пример #3
0
 /**
  * 输出js/css连接
  *
  * @param $res_link
  * @param bool $make_link
  * @return null|string
  */
 function outputResLink($res_link, $make_link = true)
 {
     $t = Helper::getExt($res_link);
     switch (strtolower($t)) {
         case 'js':
             $tpl = '<script type="text/javascript" src="%s"></script>';
             break;
         case 'css':
             $tpl = '<link rel="stylesheet" type="text/css" href="%s"/>';
             break;
         default:
             $tpl = null;
     }
     if (null !== $tpl) {
         if ($make_link) {
             $res_link = $this->res($res_link);
         }
         return sprintf("{$tpl}\n", $res_link);
     }
     return null;
 }
Пример #4
0
 /**
  * 如果缓存文件不存在则创建
  */
 function init()
 {
     if (!file_exists($this->cache_file)) {
         Helper::mkfile($this->cache_file);
     }
 }
Пример #5
0
 /**
  * 读取指定的单一文件
  *
  * @param string $file Loader::parseFileRealPath()
  * @param bool $require_file 是否返回文件 等于false时,返回文件文本内容
  * @return mixed
  * @throws CoreException
  */
 public static function read($file, $require_file = true)
 {
     if (is_file($file)) {
         $file_path = $file;
     } else {
         $file_path = Loader::getFilePath($file);
     }
     $read_file_flag = (int) $require_file;
     if (isset(self::$loaded[$file_path][$read_file_flag])) {
         return self::$loaded[$file_path][$read_file_flag];
     }
     if (is_readable($file_path)) {
         if (false === $require_file) {
             $file_content = file_get_contents($file_path);
             self::$loaded[$file_path][$read_file_flag] = $file_content;
             return $file_content;
         }
         $ext = Helper::getExt($file_path);
         switch ($ext) {
             case 'php':
                 $data = (require $file_path);
                 self::$loaded[$file_path][$read_file_flag] = $data;
                 break;
             case 'json':
                 $data = json_decode(file_get_contents($file_path), true);
                 self::$loaded[$file_path][$read_file_flag] = $data;
                 break;
             case 'ini':
                 $data = parse_ini_file($file_path, true);
                 self::$loaded[$file_path][$read_file_flag] = $data;
                 break;
             default:
                 throw new CoreException('不支持的解析格式');
         }
         return $data;
     } else {
         throw new CoreException("读取文件失败:{$file}");
     }
 }
Пример #6
0
 /**
  * 参数加密
  *
  * @param $tex
  * @param string $type
  * @return bool|string
  */
 protected function urlEncrypt($tex, $type = 'encode')
 {
     return Helper::encodeParams($tex, $this->getUrlEncryptKey('uri'), $type);
 }
Пример #7
0
 /**
  * 获取要产生的文字
  *
  * @return Array
  * @throws CoreException
  */
 private function getCheckCode()
 {
     if ($this->checkCode) {
         $ret = array();
         $this->num = Helper::strLen($this->checkCode);
         for ($i = 0; $i < $this->num; $i++) {
             $ret[] = mb_substr($this->checkCode, $i, 1, 'UTF-8');
         }
         return $ret;
     } else {
         throw new CoreException('error captcha code!');
     }
 }