Пример #1
0
 /**
  * 添加记录
  * @param string $mobile 手机号
  * @param string $message 发送内容
  * @param string $type 类型 code:验证码
  * @param string $source 平台供应商 0:未知 1:畅天游 2:开路者(奇羽)vkpush 默认为0
  */
 public static function add($mobile, $message, $type, $source = '0')
 {
     $tb = new Application_Model_Table_SmsSenderLog();
     $tb->fillDataFromArray(array('mobile' => $mobile, 'message' => $message, 'type' => $type, 'source' => $source, 'ip' => XF_Controller_Request_Http::getInstance()->getClientIp(), 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'created' => date('Y-m-d H:i:s')));
     if (XF_DataPool::getInstance()->get('RequestFromApp') === true) {
         $tb->user_agent = 'cds_app';
     }
     return $tb->insert();
 }
Пример #2
0
 /**
  * 获取当前实例
  * @return XF_Controller_Request_Http
  */
 public static function getInstance()
 {
     if (self::$_instance === null) {
         self::$_instance = new self();
         if (self::$_instance->isPost() && is_array($_POST)) {
             foreach ($_POST as $key => $val) {
                 self::$_instance->setPost($key, $val);
             }
             //unset($_POST);
         }
         if (is_array($_FILES)) {
             foreach ($_FILES as $key => $val) {
                 self::$_instance->setPost($key, $val, false);
             }
         }
         //unset($_GET);
     }
     return self::$_instance;
 }
Пример #3
0
 public function __toString()
 {
     $env = XF_Config::getInstance()->getEnvironmental();
     if ($env == 'development') {
         if ($this->code == 404) {
             header('HTTP/1.1 404 Not Found');
         } else {
             header('HTTP/1.1 500 Internal Server Error');
         }
         echo '<html xmlns="http://www.w3.org/1999/xhtml"><head>';
         echo '<title>Application Error</title>';
         echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
         echo '</head><body>';
         echo '<pre>';
         echo parent::__toString();
         echo "\n\n\nRequest URL: " . XF_Controller_Request_Http::getInstance()->getRequestUrl() . "\n";
         echo "Params:\n";
         print_r(XF_Controller_Request_Http::getInstance()->getParams());
         echo "\nRewrites: \n";
         $debug = XF_DataPool::getInstance()->get('DEBUG');
         print_r($debug['Rewites']);
         $_querys = XF_DataPool::getInstance()->get('Querys', array());
         echo '<br/>Querys(' . count($_querys) . ') Time:' . XF_DataPool::getInstance()->get('QueryTimeCount', 0) . 's<br/>';
         print_r($_querys);
         echo '<br/>ReadCache(' . XF_DataPool::getInstance()->get('CacheTimeCount', 0) . 's)<br/>';
         print_r(XF_DataPool::getInstance()->get('CacheTimeList', array()));
         echo '<br/>RunApplication:' . XF_DataPool::getInstance()->get('RunApplication') . 's';
         echo '<br/>RunBootstrap:' . XF_DataPool::getInstance()->get('RunBootstrap') . 's';
         echo '<br/>LoadFile:' . sprintf("%.5fs", XF_Application::getInstance()->loadFileTime());
         echo '<br/>RunTime:' . sprintf('%.5f', microtime(true) - APP_START_TIME) . 's';
         echo '</pre>';
         echo '</body></html>';
     } else {
         $string = $title = '';
         if ($this->code == 404) {
             header('HTTP/1.1 404 Not Found');
             $title = 'Not Found';
             $string = '<h1 style="font-size:60px;">:( 404</h1>';
             $string .= '<p>您请求的网页不存在或已删除!<br/><br/><a href="/">返回</a></p>';
         } else {
             header('HTTP/1.1 500 Internal Server Error');
             $title = 'Internal Server Error';
             $string = '<h1 style="font-size:60px;">:( 500</h1>';
             $string .= '<p>您请求的网页存在错误,请稍后再访问!<br/><br/><a href="/">返回</a></p>';
         }
         echo '<html xmlns="http://www.w3.org/1999/xhtml"><head>';
         echo '<title>' . $title . '</title>';
         echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
         echo '</head><body style="padding:10px;">';
         echo $string;
         echo '<p style="color:#999;font-size:14px;">URL:' . XF_Controller_Request_Http::getInstance()->getRequestUrl() . '</p>';
         echo '</body></html>';
     }
     return '';
 }
Пример #4
0
 /**
  * 分析传统请求方式的参数
  * @access private 
  * @return void
  */
 private function _readOldRequestParams()
 {
     if ($this->_old_request_params_string != '') {
         $tmp = explode('&', $this->_old_request_params_string);
         foreach ($tmp as $t) {
             $_tmp = explode('=', $t);
             //GET 数组参数
             $_tmp[0] = str_replace('%5B%5D', '[]', $_tmp[0]);
             $_tmp[0] = str_replace('%5b%5d', '[]', $_tmp[0]);
             $this->_request->setParam($_tmp[0], isset($_tmp[1]) ? urldecode($_tmp[1]) : NULL);
         }
     }
 }
Пример #5
0
 private function switchCity()
 {
     $isSpider = false;
     $spiders = array('sogou spider', 'Sosospider', '360Spider', 'googlebot', 'mediapartners-google', 'baiduspider', 'msnbot', 'yodaobot', 'yahoo! slurp;', 'yahoo! slurp china;', 'iaskspider', 'sogou web spider', 'sogou push spider');
     foreach ($spiders as $s) {
         if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), strtolower($s)) !== false) {
             $isSpider = true;
             break;
         }
     }
     //如果来源是本站则不自动跳转
     if ((!isset($_SERVER['HTTP_REFERER']) || strpos($_SERVER['HTTP_REFERER'], XF_Config::getInstance()->getDomain()) == false) && $isSpider == false) {
         $domain_url = XF_Config::getInstance()->getDomain();
         //是否存在cookie
         $cookie = new XF_Cookie('local');
         if ($cookie->isEmpty() == false) {
             $mod = new Application_Model_City();
             $row = $mod->get($cookie->read());
             if ($row != false) {
                 die('<script>window.location.href="http://' . $row->pinyin . '.' . $domain_url . '";</script>');
             }
         }
         /////IP
         $ip = XF_Controller_Request_Http::getInstance()->getClientIp();
         $mod = new Application_Model_IP();
         $row = $mod->getByIP($ip);
         $province_id = 1;
         //如果用户ip不存在则添加到库中
         if ($row == false) {
             $province_id = $mod->add($ip);
         } else {
             $province_id = $row->province_id;
         }
         XF_Config::getInstance()->load('cityDomain');
         $cityDomains = (array) XF_Config::getInstance()->cityDomain;
         foreach ($cityDomains as $domain => $val) {
             if ($val['id'] == $province_id) {
                 die('<script>window.location.href="http://' . $domain . '.' . $domain_url . '";</script>');
             }
         }
         //默认为北京
         die('<script>window.location.href="http://beijing.' . $domain_url . '";</script>');
     }
 }
Пример #6
0
 /**
  * 获取表单提交的数据
  * @access public
  * @param array $data 默认值
  * @param bool $filter_primary_key 是否过滤主键值? 默认true
  * @return mixed
  */
 public function getFormData(array $data = null, $filter_primary_key = true)
 {
     //获取表单数据
     if (empty($data)) {
         $data = XF_Controller_Request_Http::getInstance()->getPost();
     }
     //开始检测字段缓存
     $this->_makeCacheTableFields();
     //过滤表单提交的数据
     $this->_filterDataFromCacheField($data, $filter_primary_key);
     $this->_result_array = array();
     $this->fillDataFromArray($data);
     return $this->toArray();
 }
Пример #7
0
 /**
  * 渲染模板
  * @access public
  * @param string $template_file Action模板文件
  * @param string $cache_sign 缓存标识
  * @param XF_View_Layout_Abstract $layout 
  * @return string
  */
 public function render($template_file = null, $cache_sign = '', XF_View_Layout_Abstract $layout = null)
 {
     $this->getTemplateStartLocation();
     $request = XF_Controller_Request_Http::getInstance();
     $appName = $request->getModule();
     $controllerName = $request->getController();
     $actionName = $request->getAction();
     //如果没有设置模板,则自动获取当前Action名称相关的模板
     if ($template_file == null) {
         $template_file = $this->_template_folder . '/' . $controllerName . '/' . $actionName . '.php';
     }
     if (!is_file($template_file)) {
         throw new XF_View_Exception('Action template not found');
     }
     $content = $this->obGetContents($template_file);
     XF_Controller_Plugin_Manage::getInstance()->postRender($content);
     //是否需要缓存?
     if ($this->_cache_time > 0) {
         $layout_tag = '';
         if ($layout != null) {
             $layout_tag = '<!--Layout:' . get_class($layout) . ',' . $layout->getCacheTime() . ',' . (int) $layout->getCacheType() . '-->';
         }
         $_content = $content . $layout_tag . $this->_makeCacheHeadTitleAndHeadMeta();
         //写入缓存
         if ($this->_cache_instance instanceof XF_Cache_SECache) {
             XF_File::mkdirs(TEMP_PATH . '/Cache');
             $this->_cache_instance->setCacheSaveFile(TEMP_PATH . '/Cache/ActionViewCache');
         }
         $this->_cache_instance->setCacheTime($this->_cache_time);
         $this->_cache_instance->add($cache_sign, $_content);
     }
     //是否启用布局
     if ($layout != null) {
         $layout->assign('$layoutContent', $content);
         $content = $layout->render();
     }
     return $content;
 }
Пример #8
0
 /**
  * 初始化相应必要的对象
  * @access public
  * @return XF_Controller_Front
  */
 public function init()
 {
     if ($this->_router == NULL) {
         $this->_router = new XF_Controller_Router();
         $this->_plugin_manage = XF_Controller_Plugin_Manage::getInstance();
         $this->_request = XF_Controller_Request_Http::getInstance();
     }
     return $this;
 }
Пример #9
0
 /**
  * 验证访问权限,无权限时将会抛出异常
  * @access public
  * @param string $acl 例:default.index.index
  * @throws XF_Acl_Exception
  * @return void
  */
 public function validate($acl = NULL)
 {
     $request = XF_Controller_Request_Http::getInstance();
     $module = $request->getModule();
     $controller = $request->getController();
     $action = $request->getAction();
     if ($acl != null) {
         $tmp = explode('.', $acl);
         $module = $tmp[0];
         $controller = $tmp[1];
         $action = $tmp[2];
     }
     //当前请求的Acl
     $nowAcl = $module . '.' . $controller . '.' . $action;
     $acl = $acl == NULL ? $nowAcl : $acl;
     $acl = md5(strtolower(trim($acl)));
     //是否在忽略列表中
     if (is_array($this->_ignore) && in_array($acl, $this->_ignore)) {
         return true;
     }
     if (!is_array($this->_acl)) {
         throw new XF_Acl_Exception('无效的访问,您当前权限不足');
     }
     if ($this->_acl['acls'][0] == '*') {
         return true;
     }
     //是否拥有该action权限
     if (in_array($acl, $this->_acl['acls'])) {
         return true;
     }
     //是否拥有该控制器所有的权限
     $controller_tmp = strtolower($controller);
     if (strtolower($module) != 'default') {
         $controller_tmp = strtolower($module . '_' . $controller);
     }
     if (in_array(md5($controller_tmp), $this->_acl['acls'])) {
         return true;
     }
     //是否在白名单中
     if (is_array($this->_allows) && in_array($acl, $this->_allows)) {
         return true;
     }
     throw new XF_Acl_Exception('无效的访问,您当前权限不足');
 }
Пример #10
0
 /**
  * 执行分页
  */
 public function run()
 {
     $this->_request = XF_Controller_Request_Http::getInstance();
     $this->_params = $this->_request->getCustomParams(false);
     $page = $this->_request->getParam($this->_paginator_param, FALSE) ? intval($this->_request->getParam($this->_paginator_param)) : 1;
     $this->_page = $page;
     //重置最大页数
     if (is_numeric($this->_max_page_size) && $this->_max_page_size > 0 && $this->_page_count > $this->_max_page_size) {
         $this->_page_count = $this->_max_page_size;
     }
     $this->_getDiyResultByArray();
     $this->nowbar();
     //重置相关设置
     $this->setCustomUrl();
     $this->setPaginatorParamName();
     $this->setNowBarCount();
 }
Пример #11
0
 /**
  * 获取数据缓存唯一名称标识
  * @access protected
  * @param string $appendString 添加的字符串,主要用于区分count(*)查询 
  * @return string
  */
 protected function _getDataCacheFileName($appendString = '')
 {
     $code = $this->_db_name . $this->_db_table->getTableName() . serialize($this->_adv_find) . serialize($this->_adv_where) . serialize($this->_adv_in) . serialize($this->_adv_not_in) . serialize($this->_adv_order) . serialize($this->_adv_limit);
     $path = XF_Controller_Request_Http::getInstance()->getModule() . '/' . XF_Controller_Request_Http::getInstance()->getController() . '/' . md5(serialize($this->_adv_where)) . '/';
     return TEMP_PATH . '/Cache/Data/' . $this->_db_name . '/' . $this->_db_table->getTableName() . '/' . $path . md5($code . $appendString) . '.php';
 }
Пример #12
0
 /**
  * 渲染布局模板文件
  * @access public
  * @return string
  */
 public function render()
 {
     $content = isset($this->_data['$layoutContent']) ? $this->_data['$layoutContent'] : '';
     //布局模板起始路径
     $layoutTemplatePath = APPLICATION_PATH . '/layouts/scripts/';
     if (!is_file($layoutTemplatePath . $this->_tpl)) {
         return $content;
     }
     //检测缓存
     if ($this->_cache_time > 0) {
         $request = XF_Controller_Request_Http::getInstance();
         $file = TEMP_PATH . '/Cache/LayoutScripts/';
         $pathinfo = pathinfo($this->_tpl);
         //检测布局缓存类型,定位正确的路径
         if ($this->_cache_is_private) {
             $file .= 'Private/' . $request->getModule() . '/' . $request->getController() . '/' . $request->getAction() . '/' . $pathinfo['basename'];
         } else {
             $file .= 'Public/' . $pathinfo['basename'];
         }
         XF_File::mkdirs(pathinfo($file, PATHINFO_DIRNAME));
         if (is_file($file)) {
             //布局缓存是否过期
             if (time() > filemtime($file) + $this->_cache_time * 60) {
                 //缓存失效时执行用户的初始化操作init()
                 $this->_init();
                 XF_File::del($file);
                 $this->_flag = false;
                 $content = $this->_getObContent($layoutTemplatePath . $this->_tpl);
                 XF_File::write($file, $content);
             }
             $this->_flag = true;
             return $this->_getObContent($file);
         } else {
             $this->_init();
             $this->_flag = false;
             $content = $this->_getObContent($layoutTemplatePath . $this->_tpl);
             XF_File::write($file, $content);
             $this->_flag = true;
             return $this->_getObContent($file);
         }
     } else {
         //不采用缓存时获取最终输出的HTML内容
         $this->_init();
         $this->_flag = true;
         return $this->_getObContent($layoutTemplatePath . $this->_tpl);
     }
     return $content;
 }
Пример #13
0
/**
 * 程序框加调试信息,主要用于开发测试
 */
function funcGetDebugContent()
{
    //$session = new XF_Session('XF_Role');
    //if ($session->isEmpty() == false && $session->read() == 1 && XF_Controller_Request_Http::getInstance()->getParam('debug') == 'true')
    //{
    echo "<pre>Debug info";
    echo "\n\nRequest URL: " . XF_Controller_Request_Http::getInstance()->getRequestUrl();
    echo "\n\nExceptionMessage: " . XF_DataPool::getInstance()->get('ExceptionMessage') . "\n";
    echo "\nParams:\n";
    print_r(XF_Controller_Request_Http::getInstance()->getParams());
    echo "\nRewrites: \n";
    $debug = XF_DataPool::getInstance()->get('DEBUG');
    print_r($debug['Rewites']);
    $_querys = XF_DataPool::getInstance()->get('ConnectionMysql', array());
    echo '<br/>Connection Mysql(' . count($_querys) . ') Time:' . XF_DataPool::getInstance()->get('ConnectionMysqlTimeCount', '0s') . '<br/>';
    print_r($_querys);
    $_querys = XF_DataPool::getInstance()->get('Querys', array());
    echo '<br/>Querys(' . count($_querys) . ') Time:' . XF_DataPool::getInstance()->get('QueryTimeCount', '0s') . '<br/>';
    print_r($_querys);
    $_solrs = XF_DataPool::getInstance()->get('Solrs', null);
    if (is_array($_solrs)) {
        echo '<br/>Solrs(' . count($_solrs) . ') Time:' . XF_DataPool::getInstance()->get('SolrTimeCount', '0s') . '<br/>';
        print_r($_solrs);
    }
    echo '<br/>ReadCache(' . XF_DataPool::getInstance()->get('CacheTimeCount', 0) . 's)<br/>';
    print_r(XF_DataPool::getInstance()->get('CacheTimeList'));
    echo '<br/>RunApplication:' . XF_DataPool::getInstance()->get('RunApplication') . 's';
    echo '<br/>RunBootstrap:' . XF_DataPool::getInstance()->get('RunBootstrap') . 's';
    echo '<br/>RunBootstraps:';
    print_r(XF_DataPool::getInstance()->get('Bootstrap_Inits'));
    echo '<br/>Load_Interface:';
    print_r(XF_DataPool::getInstance()->get('Load_Interface'));
    echo '<br/>LoadFile:' . sprintf("%.5fs", XF_Application::getInstance()->loadFileTime());
    echo '<br/>RunTime:' . sprintf("%.5fs", microtime(true) - APP_START_TIME);
    echo "</pre>";
    //}
}
Пример #14
0
<?php 
echo $this->getView()->headLink();
echo $this->getView()->headTitle();
echo $this->getView()->headMeta();
?>
<script src="$static/js/jquery/jquery-1.11.1.js"></script>
<script src="$static/js/layer/layer.js"></script>
<script src="$static/js/common.js"></script>
<?php 
echo $this->getView()->headScript();
?>
<link rel="stylesheet" href="$static/css/base.css"  />
<?php 
echo $this->getView()->headStylesheet();
?>
</head>
<body>
<?php 
require_once APPLICATION_PATH . '/layouts/scripts/header.php';
echo $this->{'$layoutContent'};
require_once APPLICATION_PATH . '/layouts/scripts/selectcity.php';
require_once APPLICATION_PATH . '/layouts/scripts/footer.php';
//打印debug信息
if (XF_Controller_Request_Http::getInstance()->getParam('debug') == 'true') {
    echo funcGetDebugContent();
}
?>
</body>
</html>

Пример #15
0
 /**
  * 分析匹配结果
  * @param string $uri 请求的URI
  * @param string $regex 具体规则
  * @param array $tmp 匹配后的结果数组
  * @param int $regexIndex 当前是第几个规则【是指同一个名称里的规则,不是全局】
  * @return void
  */
 private function _matchAnalysis($uri, $regex, $tmp, $regexIndex)
 {
     //是否匹配成功
     if (is_array($tmp) && XF_Functions::isEmpty($tmp) === FALSE || $regex == '/' && $uri == '/') {
         //记录匹配到的规则方便调式用
         if (XF_Config::getInstance()->getSaveDebug()) {
             XF_DataPool::getInstance()->addHash('DEBUG', 'Match_Rewrite', $regex);
         }
         $this->_match_status = TRUE;
         $request = XF_Controller_Request_Http::getInstance();
         $request->setModule($this->_ma_array['module'])->setController($this->_ma_array['controller'])->setAction($this->_ma_array['action']);
         //是否存在自定义的附加参数
         if (isset($this->_ma_array['params']) && is_array($this->_ma_array['params'])) {
             foreach ($this->_ma_array['params'] as $k => $val) {
                 $request->setParam($k, $val);
             }
         }
         //设置匹配到的参数
         if (is_array($this->_params_array)) {
             foreach ($this->_params_array as $key => $val) {
                 //指定的参数是否只匹配指定位置的规则
                 $keyTmp = explode(':', $key);
                 if (!isset($keyTmp[1])) {
                     if (isset($tmp[$keyTmp[0]])) {
                         $request->setParam($val, urldecode($tmp[$keyTmp[0]]));
                     }
                 } else {
                     if ($keyTmp[0] == $regexIndex && isset($tmp[$keyTmp[1]])) {
                         //规则位置从0开始
                         $request->setParam($val, urldecode($tmp[$keyTmp[1]]));
                     }
                 }
             }
         }
         //////重写URL后,尝试获取设置的参数
         $uri = str_replace($tmp[0], '', $uri);
         $tep = explode('/', $uri);
         if (is_array($tep) && count($tep) >= 2) {
             if ($tep[0] == '') {
                 unset($tep[0]);
             }
             $tep = array_values($tep);
             foreach ($tep as $key => $val) {
                 if (isset($tep[$key + 1]) && $tep[$key + 1] != '') {
                     $request->setParam($val, urldecode($tep[$key + 1]));
                 } else {
                     break;
                 }
             }
         }
     }
 }
Пример #16
0
 public function getParams()
 {
     return $this->_request->getParams();
 }
Пример #17
0
 /**
  * 全局异常处理
  * @param Exception $e
  * @throws Exception
  * @throws XF_Exception
  */
 public static function appException(Exception $e)
 {
     $req = XF_Controller_Request_Http::getInstance();
     $message = $req->getMethod() . ' "' . $req->getRequestUrl() . '" ' . $e->getMessage() . "\n";
     XF_Functions::writeErrLog($message . $e->getTraceAsString());
     echo $e;
 }