Esempio n. 1
0
 public function routeShutdown(XF_Controller_Request_Abstract $request)
 {
     //如果存在强制清除缓存命令
     $auth = new XF_Auth_Storage_Session();
     if ($auth->isEmpty() == false && $auth->read()->role_id != '0') {
         if ($request->getParam('clear') == 'cache') {
             XF_DataPool::getInstance()->add('clearCache', TRUE);
         }
         if ($request->getParam('clear') == 'action') {
             XF_DataPool::getInstance()->add('clearActionCache', TRUE);
         }
     }
     //自动清除缓存
     if ($request->getParam('autoclear') == 'true') {
         XF_DataPool::getInstance()->add('clearActionCache', TRUE);
     }
     //获取用户当前真实的地区id
     $data = array('id' => '1', 'name' => '北京', 'pinyin' => 'beijing');
     $ip = new Application_Model_IP();
     $ip->table()->setAssociatedAuto('city');
     $row = $ip->getByIP($request->getClientIp());
     if ($row != false) {
         $data = array('id' => $row->province_id, 'name' => $row->city_province_id->name, 'pinyin' => $row->city_province_id->pinyin);
     }
     XF_View::getInstance()->assign('trueCity', (object) $data);
 }
Esempio n. 2
0
 /**
  * 获取当前数据池实例
  * @return XF_DataPool
  */
 public static function getInstance()
 {
     if (self::$_instance === null) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Esempio n. 3
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();
 }
Esempio n. 4
0
 /**
  * 记录缓存读取时间用于调试
  * @access protected
  * @param int $start_time
  * @param string $by
  * @return void
  */
 protected function _addReadDebug($start_time, $by)
 {
     //
     $end_time = microtime(true);
     $now_time = sprintf("%01.5f", $end_time - $start_time) . 's By ' . $by;
     $count_time = XF_DataPool::getInstance()->get('CacheTimeCount', 0);
     XF_DataPool::getInstance()->add('CacheTimeCount', sprintf("%01.5f", $count_time + ($end_time - $start_time > 0 ? $end_time - $start_time : 0)));
     XF_DataPool::getInstance()->addList('CacheTimeList', $now_time);
 }
Esempio n. 5
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 '';
 }
Esempio n. 6
0
 /**
  * 读取缓存内容
  * @access public
  * @param string $key 缓存KEY
  * @return mixed
  */
 public function read($key)
 {
     $start_time = microtime(true);
     //是否强制清除缓存?
     if (XF_DataPool::getInstance()->get('clearCache') === true) {
         return XF_CACHE_EMPTY;
     }
     $data = XF_CACHE_EMPTY;
     $value = $this->_memcache->get($key);
     if ($value !== false) {
         $data = $value;
     }
     $this->_addReadDebug($start_time, 'Memcache');
     return $data;
 }
Esempio n. 7
0
 public function routeShutdown(XF_Controller_Request_Abstract $request)
 {
     //检测访问权限
     $m = $request->getModule();
     $c = $request->getController();
     if ($m == 'user' && $c != 'front') {
         $auth = new XF_Auth_Storage_Session();
         if ($auth->isEmpty()) {
             XF_Functions::go('/login/?redirect_url=' . urlencode($request->getRequestUrl()));
         }
     }
     //如果存在强制清除缓存命令
     $auth = new XF_Auth_Storage_Session();
     if ($auth->isEmpty() == false && $auth->read()->role_id != '0') {
         if ($request->getParam('clear') == 'cache') {
             XF_DataPool::getInstance()->add('clearCache', TRUE);
         }
         if ($request->getParam('clear') == 'action') {
             XF_DataPool::getInstance()->add('clearActionCache', TRUE);
         }
     }
 }
Esempio n. 8
0
 /**
  * 读取缓存内容
  * @access public
  * @param string $key 缓存KEY
  * @return mixed
  */
 public function read($key)
 {
     $start_time = microtime(true);
     //是否强制清除缓存?
     if (XF_DataPool::getInstance()->get('clearCache') === true) {
         return XF_CACHE_EMPTY;
     }
     if (strlen($key) > 32) {
         $key = md5($key);
     }
     $secache = new secache();
     $secache->workat($this->_cache_file);
     $content = $this->_getData($key);
     if ($content != NULL) {
         return $content;
     }
     if ($secache->fetch($key, $content)) {
         $this->_addReadDebug($start_time, 'SECache');
         //缓存是否过过期
         preg_match('/<cache:(.*)?:cache>/', $content, $tmp);
         if (isset($tmp[1])) {
             $d = explode('_', $tmp[1]);
             if ($d[1] == 0) {
                 $content = str_replace($tmp[0], '', $content);
             }
             if (time() > $d[0] + $d[1] * 60) {
                 return XF_CACHE_EMPTY;
             } else {
                 $content = str_replace($tmp[0], '', $content);
             }
             $content = unserialize($content);
             $this->_pushData($key, $content);
             return $content;
         }
     }
     return XF_CACHE_EMPTY;
 }
Esempio n. 9
0
 /**
  * 运行启动器
  * @access public
  * @return void
  */
 public function run()
 {
     $st = microtime(true);
     $this->checkDomain();
     $this->runStartup();
     XF_DataPool::getInstance()->addList('Bootstrap_Inits', 'runStartup ' . sprintf('%.5fs', microtime(true) - $st));
     if (!empty($_GET['xsessid'])) {
         $session_id = XF_Functions::authCode(urlencode($_GET['xsessid']), 'DECODE');
         if ($session_id != '') {
             session_id($session_id);
         }
     }
     $stt = microtime(true);
     session_start();
     XF_DataPool::getInstance()->addList('Bootstrap_Inits', 'session_start ' . sprintf('%.5fs', microtime(true) - $stt));
     header("Content-type:text/html;charset=utf-8");
     $this->_loadInit();
     XF_DataPool::getInstance()->add('RunBootstrap', sprintf("%.6f", microtime(true) - $st));
     XF_Controller_Front::getInstance()->init()->dispatch();
 }
Esempio n. 10
0
 /**
  * 验证路由重写规则
  * @access private
  * @return bool 是否成功匹配到自定义的路由规则
  */
 private function _validateRewrite()
 {
     $status = FALSE;
     krsort($this->_rewrite_index);
     foreach ($this->_rewrite_index as $name) {
         //记录准备要匹配的规则名称
         if (XF_Config::getInstance()->getSaveDebug()) {
             XF_DataPool::getInstance()->addHash('DEBUG', 'NowMatchRewriteName', $name);
         }
         if (TRUE === $this->_rewrites[$name]->match($this->_final_uri)) {
             $status = TRUE;
             break;
         }
     }
     //记录URL重写规则匹配顺序,debug信息
     if (XF_Config::getInstance()->getSaveDebug()) {
         $tmp = array();
         //匹配到的规则
         $matchRewrite = XF_DataPool::getInstance()->getHash('DEBUG', 'Match_Rewrite');
         foreach ($this->_rewrite_index as $name) {
             $regxArray = $this->_rewrites[$name]->toArray();
             if (count($regxArray) == 1 && $matchRewrite != false) {
                 $regxArray = str_replace($matchRewrite, "<b style=\"color:red\">{$matchRewrite}</b>", $regxArray[0]);
             } elseif ($matchRewrite != false) {
                 foreach ($regxArray as $k => $v) {
                     $regxArray[$k] = str_replace($matchRewrite, "<b style=\"color:red\">{$matchRewrite}</b>", $v);
                 }
             }
             $tmp[$name] = $regxArray;
         }
         XF_DataPool::getInstance()->addHash('DEBUG', 'Rewites', $tmp);
     }
     $this->_request_default_route = !$status;
     return $status;
 }
Esempio n. 11
0
 /**
  * 进行数据验证
  * @param bool $validate 是否验证? 默认为true
  * @param bool $is_insert 当前验证的数据是否准备插入数据库?只有是插入数据库操作,所有的required强制生效
  * @throws XF_Db_Table_Exception
  * @return bool
  */
 protected function _validateAllData($validate = true, $is_insert = true)
 {
     if ($validate !== true) {
         return true;
     }
     if ($this->_field_validate_rule == null) {
         return true;
     }
     //验证
     $data = $this->toArray();
     if ($is_insert == false) {
         //只验证发生改变的字段
         $dbResultArray = $this->getDBResultArray();
         if ($dbResultArray != null && is_array($data)) {
             foreach ($dbResultArray as $key => $val) {
                 if (array_key_exists($key, $data) && $data[$key] === $val) {
                     unset($data[$key]);
                     //同时删除不需要验证的字段规则
                     $this->getFieldValidateRule()->removeFieldRule($key);
                 }
             }
         }
     }
     if (XF_Db_Table_Validate::getInstance()->validateData($data, $this->getFieldValidateRule()->toArray(), true, $this, $is_insert) === false) {
         throw new XF_Db_Table_Exception(XF_DataPool::getInstance()->get('TableFieldDataValidateError'));
     } else {
         $this->_set_var_validate = false;
         foreach ($data as $key => $val) {
             $this->{$key} = $val;
         }
         $this->_set_var_validate = true;
     }
     return true;
 }
Esempio n. 12
0
 /**
  * 执行SQL语句
  * @param string $query
  * @param bool $is_select 是否为查询,如果为true,框架会尝试将查询的结果包装成数组[默认为false]
  * @throws XF_Db_Table_Select_Exception
  */
 public function execute($query, $is_select = false)
 {
     if ($this->_show_query === TRUE) {
         echo $query . '<br/>';
     }
     //多次查询相同的SQL时只执行一次。
     if (XF_DataPool::getInstance()->get('CLOSE_SQL_DATA_CACHE') == false) {
         $data = XF_DataPool::getInstance()->get('SQL_DATA');
         if (is_array($data) && isset($data[md5($query)])) {
             return $data[md5($query)];
         }
     }
     $stime = microtime(true);
     $this->_connection();
     $result = mysql_query($query, $this->_db_connection);
     $etime = microtime(true);
     $use = sprintf('%.5f', $etime - $stime);
     //是否记录debug信息
     if (XF_Config::getInstance()->getSaveDebug()) {
         $str = $query . ' ' . $use . 's';
         if ($use > 0.3) {
             $str = '<font style="color:red">' . $str . '</font>';
         }
         XF_DataPool::getInstance()->addList('Querys', $str);
         $count = XF_DataPool::getInstance()->get('QueryTimeCount', 0);
         XF_DataPool::getInstance()->add('QueryTimeCount', sprintf("%.5f", $count + $use));
     }
     if (mysql_error($this->_db_connection) != '') {
         throw new XF_Db_Table_Select_Exception(mysql_error($this->_db_connection));
     }
     if ($result == false) {
         return false;
     }
     if ($is_select == true && strpos(strtolower(trim($query)), 'select') === 0 || strpos(strtolower(trim($query)), 'show tables') === 0) {
         $result = $this->_getResultArray($result);
         //添加临时缓存
         if (XF_DataPool::getInstance()->get('CLOSE_SQL_DATA_CACHE') == false) {
             $data[md5($query)] = $result;
             XF_DataPool::getInstance()->add('SQL_DATA', $data);
         }
     }
     return $result;
 }
Esempio n. 13
0
 /**
  * 添加相关资料到控制器中,方便Action中直接读取
  */
 protected function initAddDataToController()
 {
     if ($this->_nowCityDomain != NULL) {
         XF_Controller_Front::getInstance()->addHandleData('nowCity', $this->_nowCityDomain);
         XF_View::getInstance()->assign('nowCity', $this->_nowCityDomain);
         XF_DataPool::getInstance()->add('nowCity', $this->_nowCityDomain);
     }
     //添加静态资源URL
     XF_Controller_Front::getInstance()->addHandleData('static_url', 'http://static.' . XF_Config::getInstance()->getDomain());
 }
Esempio n. 14
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>";
    //}
}
Esempio n. 15
0
 /**
  * 验证表单 分析规则 Validate
  * @access private
  * @param array $data 将要验证的数组资料
  * @param string $key	当前需要验证的字段[key]
  * @param string $rules_name	规则名称
  * @param mixed $rules_value	规则值
  * @param array	 $message	自定义错误信息
  * @param XF_Db_Table_Abstract $db_table 主要支持unique的验证,默认为null
  * @param bool $is_insert 是否为添加数据操作?如果不是,则不强制执行required
  * @return bool
  */
 private function _switchValidateFormData($data, $key, $rules_name, $rules_value, $message, XF_Db_Table_Abstract $db_table = NULL, $is_insert = TRUE)
 {
     $this->_validate_count++;
     //判断规则,分析结果
     $validateOk = true;
     switch ($rules_name) {
         //验证 必填
         case 'required':
             if ($rules_value == 'true') {
                 if (isset($data[$key])) {
                     if (XF_Functions::isEmpty($data[$key])) {
                         $validateOk = false;
                     }
                 } elseif ($is_insert == true) {
                     $validateOk = false;
                 }
             }
             break;
             //验证 数字
         //验证 数字
         case 'number':
             if (isset($data[$key])) {
                 if ($rules_value == 'true') {
                     if (!is_numeric($data[$key])) {
                         $validateOk = false;
                     }
                 }
             }
             break;
             //数字小于
         //数字小于
         case 'lt':
             if (isset($data[$key])) {
                 if (!is_numeric($data[$key]) || !is_numeric($rules_value)) {
                     $validateOk = false;
                 } elseif ($data[$key] >= $rules_value) {
                     $validateOk = false;
                 }
             }
             break;
             //数字大于
         //数字大于
         case 'gt':
             if (isset($data[$key])) {
                 if (!is_numeric($data[$key]) || !is_numeric($rules_value)) {
                     $validateOk = false;
                 } elseif ($data[$key] <= $rules_value) {
                     $validateOk = false;
                 }
             }
             break;
             //等于
         //等于
         case 'equal':
             if (isset($data[$key])) {
                 if ($data[$key] !== $rules_value) {
                     $validateOk = false;
                 }
             }
             break;
             //不等于
         //不等于
         case 'unequal':
             if (isset($data[$key])) {
                 if ($data[$key] === $rules_value) {
                     $validateOk = false;
                 }
             }
             break;
             //验证 是否为正确的email
         //验证 是否为正确的email
         case 'email':
             if (!empty($data[$key]) && $rules_value == 'true') {
                 $validateOk = XF_String_Validate_Email::validate($data[$key]);
             }
             break;
             //验证 是否为正确的电话号码
         //验证 是否为正确的电话号码
         case 'tel':
             if (!empty($data[$key]) && $rules_value == 'true') {
                 $validateOk = XF_String_Validate_Phone::validate($data[$key]);
             }
             break;
             //验证 是否为正确的手机号码
         //验证 是否为正确的手机号码
         case 'mobile':
             if (!empty($data[$key]) && $rules_value == 'true') {
                 $validateOk = XF_String_Validate_Mobile::validate($data[$key]);
             }
             break;
             //验证 是否为正确的身份证号码
         //验证 是否为正确的身份证号码
         case 'card':
             if (!empty($data[$key]) && $rules_value == 'true') {
                 $validateOk = XF_String_Validate_Card::validate($data[$key]);
             }
             break;
             //验证 是否为正确邮政编码
         //验证 是否为正确邮政编码
         case 'zip':
             if (!empty($data[$key]) && $rules_value == 'true') {
                 $validateOk = XF_String_Validate_ZipCode::validate($data[$key]);
             }
             break;
             //验证 最小长度
         //验证 最小长度
         case 'minlen':
             if (!empty($data[$key])) {
                 if (mb_strlen($data[$key], 'utf8') < $rules_value) {
                     $validateOk = false;
                 }
             }
             break;
             //验证 最大长度
         //验证 最大长度
         case 'maxlen':
             if (!empty($data[$key])) {
                 if (mb_strlen($data[$key], 'utf8') > $rules_value) {
                     $validateOk = false;
                 }
             }
             break;
             //验证 ip地址
         //验证 ip地址
         case 'ip':
             if (!empty($data[$key]) && $rules_value == 'true') {
                 $validateOk = XF_String_Validate_Ip::validate($data[$key]);
             }
             break;
             /**
              *  验证 取值范围在列表中
              *  例如:in:2|23|9|0
              *
              */
         /**
          *  验证 取值范围在列表中
          *  例如:in:2|23|9|0
          *
          */
         case 'in':
             if (XF_Functions::isEmpty($data[$key]) == FALSE) {
                 if (!in_array($data[$key], explode('|', $rules_value))) {
                     $validateOk = false;
                 }
             }
             break;
             /**
              *  验证 取值范围必需不在列表中
              *  例如:not_in:2|23|9|0
              *
              */
         /**
          *  验证 取值范围必需不在列表中
          *  例如:not_in:2|23|9|0
          *
          */
         case 'not_in':
             if (XF_Functions::isEmpty($data[$key]) == FALSE) {
                 if (!in_array($data[$key], explode('|', $rules_value))) {
                     $validateOk = false;
                 }
             }
             break;
             //验证与指定的字段值是否相同
         //验证与指定的字段值是否相同
         case 'confirm':
             if (isset($data[$key])) {
                 if ($data[$key] != $data[$rules_value]) {
                     $validateOk = false;
                 }
             }
             break;
         case 'date':
             if (isset($data[$key]) && $rules_value == 'true') {
                 if (!XF_String_Validate_Date::validate($data[$key])) {
                     $validateOk = false;
                 }
             }
             break;
         case 'time':
             if (isset($data[$key]) && $rules_value == 'true') {
                 if (!XF_String_Validate_Time::validate($data[$key])) {
                     $validateOk = false;
                 }
             }
             break;
         case 'unique':
             if (isset($data[$key]) && $rules_value == 'true') {
                 if ($db_table == NULL) {
                     $validateOk = false;
                 } elseif (!XF_Db_Table_Validate_Unique::validate($data[$key], $key, $db_table, $is_insert)) {
                     $validateOk = false;
                 }
             }
             break;
     }
     //字段值为 '$NULL' 时直接通过验证 2014-09-3
     if (isset($data[$key]) && $data[$key] == '$NULL') {
         $validateOk = true;
     }
     //没有错误
     if ($validateOk) {
         $this->_validate_success_count++;
         return true;
     } else {
         //记录错误
         $errorMessage = $key . '=>' . $rules_name . ':' . $rules_value;
         if (isset($message[$key]) && is_array($message[$key]) && isset($message[$key][$rules_name])) {
             $errorMessage = $message[$key][$rules_name];
         } elseif (isset($message[$key])) {
             $errorMessage = (string) $message[$key];
         }
         XF_DataPool::getInstance()->replace('TableFieldDataValidateError', $errorMessage);
         return false;
     }
 }
Esempio n. 16
0
 /**
  * 检测是否存在缓存文件
  * @access private
  * @return void
  */
 private function _checkCacheContent()
 {
     $key = $this->getCacheSign();
     if ($key == '') {
         return;
     }
     //如果没有设置缓存类型,则默认为secache
     if ($this->_cache_instance == null) {
         $this->_cache_instance = XF_Cache_SECache::getInstance();
     }
     if ($this->_cache_instance instanceof XF_Cache_SECache) {
         $cache_file = TEMP_PATH . '/Cache/ActionViewCache';
         if (!is_file($cache_file . '.php')) {
             return null;
         }
         $this->_cache_instance->setCacheSaveFile($cache_file);
     }
     //是否存强制清除缓存
     if (XF_DataPool::getInstance()->get('clearActionCache') === true) {
         $this->_cache_instance->remove($key);
         return null;
     }
     $content = $this->_cache_instance->read($key);
     if ($content == XF_CACHE_EMPTY) {
         return null;
     }
     //检测布局
     preg_match('/<!--Layout:(.*?)-->/', $content, $matches);
     if (isset($matches[0])) {
         $tmp = explode(',', $matches[1]);
         $layoutName = $tmp[0];
         $layout = new $layoutName();
         $layout->setCacheTime($tmp[1]);
         $layout->setCacheType($tmp[2]);
         //清除布局标记
         $content = str_replace($matches[0], '', $content);
         //执行布局对象,并渲染布局模板
         if ($layout instanceof XF_View_Layout_Abstract) {
             //获取缓存的标题等信息
             $this->_checkCacheHtmlTag($content);
             $layout->assign('$layoutContent', $content);
             $content = $layout->render();
         }
     }
     return $content;
 }
Esempio n. 17
0
 /**
  * 设置数据缓存
  * @access protected
  * @param mixed $data
  */
 protected function _setDataCache($data, $saveFile = null)
 {
     if ($this->_data_cache_time > 0) {
         if (!$this->_cache_class instanceof XF_Cache_Interface) {
             throw new XF_Db_Table_Select_Exception('缓存器无法识别', 500);
         }
         if ($saveFile == null) {
             $saveFile = $this->_getDataCacheFileName();
         }
         $this->_cache_class->setCacheTime($this->_data_cache_time)->add($saveFile, $data);
     }
     //设置临时缓存
     XF_DataPool::getInstance()->addHash('TEMP_DATA_CACHE', md5($saveFile), $data);
     return true;
 }
Esempio n. 18
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;
                 }
             }
         }
     }
 }
Esempio n. 19
0
 /**
  * 启动框架
  * @return void
  */
 public function run()
 {
     XF_DataPool::getInstance()->add('RunApplication', sprintf("%.6f", microtime(true) - APP_START_TIME));
     //如果是命令行模式则直接返回
     if ($this->_is_command_line === TRUE) {
         return;
     }
     $this->getBootstrap()->run();
 }
Esempio n. 20
0
 /**
  * Simple Search interface
  *
  * @param string $query The raw query string
  * @param int $offset The starting offset for result documents
  * @param int $limit The maximum number of result documents to return
  * @param array $params key / value pairs for other query parameters (see Solr documentation), use arrays for parameter keys used more than once (e.g. facet.field)
  * @param string $method The HTTP method (Apache_Solr_Service::METHOD_GET or Apache_Solr_Service::METHOD::POST)
  * @return Apache_Solr_Response
  *
  * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
  * @throws Apache_Solr_InvalidArgumentException If an invalid HTTP method is used
  */
 public function search($query, $offset = 0, $limit = 10, $params = array(), $method = self::METHOD_GET)
 {
     // ensure params is an array
     if (!is_null($params)) {
         if (!is_array($params)) {
             // params was specified but was not an array - invalid
             throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
         }
     } else {
         $params = array();
     }
     // construct our full parameters
     // common parameters in this interface
     $params['wt'] = self::SOLR_WRITER;
     $params['json.nl'] = $this->_namedListTreatment;
     $params['q'] = $query;
     $params['start'] = $offset;
     $params['rows'] = $limit;
     $queryString = $this->_generateQueryString($params);
     $result = false;
     $stime = microtime(true);
     if ($method == self::METHOD_GET) {
         $result = $this->_sendRawGet($this->_searchUrl . $this->_queryDelimiter . $queryString);
     } else {
         if ($method == self::METHOD_POST) {
             $result = $this->_sendRawPost($this->_searchUrl, $queryString, FALSE, 'application/x-www-form-urlencoded; charset=UTF-8');
         }
     }
     $etime = microtime(true);
     if (XF_Config::getInstance()->getSaveDebug()) {
         $str = $this->_host . ' ' . $this->_path . ' : ' . urldecode($queryString) . ' ' . sprintf("%.5f", $etime - $stime) . 's';
         if ($etime - $stime > 0.5) {
             $str = '<font style="color:red">' . $str . '</font>';
         }
         XF_DataPool::getInstance()->addList('Solrs', $str);
         $count = XF_DataPool::getInstance()->get('SolrTimeCount', 0);
         XF_DataPool::getInstance()->add('SolrTimeCount', sprintf("%.5f", $count + ($etime - $stime > 0 ? $etime - $stime : 0)));
     }
     return $result;
     throw new Apache_Solr_InvalidArgumentException("Unsupported method '{$method}', please use the Apache_Solr_Service::METHOD_* constants");
 }
Esempio n. 21
0
 /**
  * 获取接口数据
  * @access public
  * param string $query 查询条件
  * @return array
  */
 public function pull($query)
 {
     //获取数据缓存
     if ($this->Is_Open_Cache == TRUE) {
         $result = $this->_getDataCache($query);
     }
     if ($result == XF_CACHE_EMPTY || $this->Is_Open_Cache == FALSE) {
         $st = microtime(true);
         //$url = urlencode($query);
         $url = self::_webapi_domain . $query;
         $curl = curl_init();
         curl_setopt($curl, CURLOPT_URL, $url);
         curl_setopt($curl, CURLOPT_HEADER, false);
         curl_setopt($curl, CURLOPT_USERAGENT);
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0);
         curl_setopt($curl, CURLOPT_TIMEOUT, 30);
         $response = curl_exec($curl);
         curl_close($curl);
         $json = json_decode($response);
         if (is_object($json)) {
             if ($this->Is_Open_Cache == TRUE) {
                 $this->_setDataCache($result, $query);
                 //设置数据缓存
             }
             XF_DataPool::getInstance()->addList('Load_Interface', $query . ' ' . sprintf('%.5fs', microtime(true) - $st));
             return $json;
         } else {
             $message = '接口获取数据失败';
             XF_Functions::writeErrLog($message);
         }
     } else {
         return $result;
     }
 }
Esempio n. 22
0
 /**
  * 发送短信息
  * @param int $mobile 接收手机号
  * @param string $message 消息内容
  * @param string $type 发送类型 code:验证码 reg:注册 other:其它
  * @return bool 是否成功
  */
 public function sendSms($mobile, $message, $type = 'other')
 {
     /*$list = array('13502581563','13736913577');
     		if (in_array($mobile, $list))
     		{
     			return false;
     		}*/
     if (XF_DataPool::getInstance()->get('RequestFromApp') !== true) {
         /*if (
         				strpos(XF_Controller_Request_Http::getInstance()->getHeader('Referer'), '.souchela.com') === false &&
         				strpos(XF_Controller_Request_Http::getInstance()->getHeader('Referer'), '.gongpingjia.com') === false 
         				
         		)
         		{
         			throw new XF_Exception('非法的请求');
         		}
         		if (strpos($_SERVER['HTTP_USER_AGENT'], '.NET CLR 3.5.21022'))
         		{
         			throw new XF_Exception('非法的请求');
         		}*/
     }
     $mod = new Application_Model_SmsSenderLog();
     /*if ($type == 'code')
     		{
     			//每个手机号每小时最多10条
     			$where = array(
     				'mobile' => $mobile,
     				'created,>' => date('Y-m-d H').':00:00',
     				'created,<' => date('Y-m-d H', strtotime(date('Y-m-d H').':00:00') + 3600).':00:00'
     			);
     			$c = $mod->select()->setWhere($where)->fetchCount();
     			if ($c >= 10)
     			{
     				throw new XF_Exception('您今日发送短信次数已超出上限');
     			}
     			
     			//每个ip一天多最30条
     			$ip = XF_Controller_Request_Http::getInstance()->getClientIp();
     			if ($ip != '119.161.222.193')
     			{
     				$where = array('ip' => XF_Controller_Request_Http::getInstance()->getClientIp(), 'created,>' => date('Y-m-d 00:00:00'));
     				$c = $mod->select()->setWhere($where)->fetchCount();
     				if ($c >= 10)
     				{
     					throw new XF_Exception('您今日发送短信次数已超出上限');
     				}
     			}
     			
     			//每个手机号一天多最30条
     			$tmp = array(
     				/*'18601021305',
     				'13488790156',
     				'13611216850',
     				'13691334650',
     				'15010156676',
     				'13718187856',
     					
     				'13701242648',
     				'13910250340',
     				'18911697907'
     			);
     			$where = array('mobile' => $mobile, 'created,>' => date('Y-m-d 00:00:00'), 'mobile,notin' => $tmp);
     			$c = $mod->select()->setWhere($where)->fetchCount();
     			if ($c >= 10)
     			{
     				throw new XF_Exception('您今日发送短信次数已超出上限');
     			}
     		}*/
     //每个手机号码2分钟内只能发送一次
     $log = $mod->getByMobile($mobile);
     if ($log != false) {
         $use = time() - strtotime($log->created);
         if ($use < 120 && $type == 'code') {
             throw new XF_Exception(120 - $use . '秒之后才能再次发送');
         }
     }
     //$sms_sender_log_id = Application_Model_SmsSenderLog::add($mobile, $message, $type);
     if ($this->_sender !== NULL) {
         $this->_sender->send($mobile, $message);
         //Application_Model_SmsSenderLog::updateSource($sms_sender_log_id, $this->_sender->getSourceId());
         $status = $this->_sender->isOk();
         //Application_Model_SmsSenderLog::updateSendMessage($sms_sender_log_id, $this->_sender->getMessage());
         if ($status == TRUE) {
             //Application_Model_SmsSenderLog::updateComplete($sms_sender_log_id);
             return TRUE;
         }
         return FALSE;
     }
     ///////依次发送
     $senders = array('Application_Model_SmsSenderSms7');
     try {
         foreach ($senders as $s) {
             $sender = new $s();
             $sender->send($mobile, $message);
             //Application_Model_SmsSenderLog::updateSource($sms_sender_log_id, $sender->getSourceId());
             //Application_Model_SmsSenderLog::updateSendMessage($sms_sender_log_id, $sender->getMessage());
             if ($sender->isOk()) {
                 //Application_Model_SmsSenderLog::updateComplete($sms_sender_log_id);
                 return TRUE;
             }
         }
     } catch (Exception $e) {
         return FALSE;
     }
     return FALSE;
 }