get_site_config(); //$this->assign('site_config',$site_config); } /** * cookie封装 * @param type $cookie */ public function myCookie($cookie, $defalut = null) { $result = I('cookie.'.$cookie, "htmlspecialchars", $defalut); return $result; } /** * get封装 * @param type $get * $defalut默认值 默认null */ public function myGet($get, $defalut = null) { $result = I('get.'.$get, "htmlspecialchars", $defalut); return $result; } /** * post封装 * @param type $post */ public function myPost($post, $defalut = null) { $result = I('post.'.$post, "htmlspecialchars", $defalut); return $result; } /** * $request封装 * @param type $request * @param type $default * @return type */ public function myRequest($request, $default = null) { $result = $_REQUEST[$request]; !empty($result) ? ($result = $result) : ($result = $default); $result = htmlspecialchars($result); return $result; } /** * 301跳转 * @param type $url * @return boolean */ public function header301($url) { if (empty($url)) { return false; } header('HTTP/1.1 301 Moved Permanently'); header('Location:' . $url); exit; } //空操作 public function _empty() { header("HTTP/1.0 404 Not Found"); $this->display('./Application/Common/404/home404.html'); exit; } /** * 自动加载函数库 .php文件 * @param string $path 文件夹 */ public function auto_load_func($path) { $auto_funcs = glob($path . "*.php"); if (!empty($auto_funcs)) { foreach ($auto_funcs as $fileName) { include_once $fileName; } } } /** * 返回并重载上一页 * Transient_1988 */ public function goBack() { echo ''; exit; } /** * 记录来源 -- Transient_1988 */ public function record_source() { $s_host = cookie('SOURCE_HOST'); if (empty($s_host)) { $s_url = $_SERVER['HTTP_REFERER']; $s = explode("/", $s_url); $s_host = $s[2]; cookie('SOURCE_HOST', $s_host); cookie('SOURCE_URL', $s_url); } } /** * 记录ref -- Transient_1988 */ public function record_ref() { $s_ref = $this->myRequest('ref'); if (!empty($s_ref)) { cookie('REF', $s_ref); } } /** * 发送post请求 * @param type $url * @param type $data * @return type */ public function sendPost($url, $data = null) { $post_data = implode('&', $data); $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); ob_start(); curl_exec($ch); $result = ob_get_contents(); ob_end_clean(); return $result; } /** * 发送get请求 * @param type $url * @param type $data * @return type 失败返回false */ public function sendGet($url, $data = null) { $status = false; if (empty($url)) { echo '亲,URL都没有,你要GET到哪去?'; $status = false; return $status; } if (!empty($data)) { $get_data = ''; foreach ($data as $k => $v) { $get_data .= "{$k}={$v}&"; } $get_data = trim($get_data, '&'); } if (!empty($get_data)) { $url .= '?' . $get_data; } $result = file_get_contents($url); if (!empty($result)) { $result = $this->jsonDecode($result); } return $result; } /** * * @param type $json * @return boolean */ public function jsonDecode($json) { if (empty($json)) { echo '亲,json都没有,你想解析个蛋?'; $status = false; return $status; } $json = strval($json); $arr = json_decode(trim($json, chr(239) . chr(187) . chr(191)), true); //删除bom头 return $arr; } /** * 友情链接 */ public function getYqlj(){ $link_mod = new LinksModel(); if(__ACTION__ == '/index/index'){ $where = array('status' => 1,'type'=>1,); }elseif(__ACTION__ != '/index/index'){ $where = array('status' => 1,'type'=>2,); } $res = $link_mod->getList($where,1,7); $this->assign('links', $res); } /** * action错误输出 * @param type 错误信息 */ public function actionError($msg) { $ret['code'] = API_ERROR_CHECK; $ret['msg'] = $msg; return $ret; } /** * action成功输出 * @param type $param * @return type */ public function actionSuccess($param) { $ret['code'] = API_SUCCESS; $ret['data'] = $param; return $ret; } /** * 404操作 */ public function header404() { header("HTTP/1.0 404 Not Found"); $this->display('./Application/Common/404/home404.html'); exit; } /** * 获取标签名称 * @param $name * @param $id * @author: huangch */ public function get_tag_name($name, $id) { foreach ($this->$name as $val) { if ($val['id'] == $id) return $val['name']; } } /** * api返回数据 * @param bool $status * @param array $data * @param string $info * @param string $url */ public function apiReturn($status = true, $data = array(), $info = '操作成功', $url = '') { header('Content-Type:application/json; charset=utf-8'); $return = array( 'status' => $status, 'data' => empty($data) ? new \stdClass() : $data, 'url' => $url, 'info' => $info, ); die(json_encode($return)); } }