示例#1
0
文件: Config.php 项目: kevinwan/xf
 /**
  * 获取当前配置文件类实例
  * @access public
  * @return XF_Config
  */
 public static function getInstance()
 {
     if (self::$_instance === null) {
         self::$_instance = new self();
         self::$_instance->_load();
     }
     return self::$_instance;
 }
示例#2
0
文件: Bootstrap.php 项目: kevinwan/xf
 /**
  * 当前请求域名是否合法
  * @access private
  * @return void
  */
 private function checkDomain()
 {
     $domain = XF_Config::getInstance()->getDomain();
     if (empty($domain)) {
         return;
     }
     if (strpos($_SERVER['HTTP_HOST'], $domain) === FALSE) {
         throw new XF_Application_Exception('当前请求的域名不正确');
     }
 }
示例#3
0
文件: Exception.php 项目: kevinwan/xf
 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
 protected function _init()
 {
     $this->nowCity = $this->getView()->nowCity;
     $this->assign('domain', XF_Config::getInstance()->getDomain());
     $this->assign('nowCity', $this->nowCity);
     //$this->assign('referer', $_SERVER['HTTP_REFERER']);
     $this->assign('referer', $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
     $a = $this->getRequest()->getAction();
     $c = $this->getRequest()->getController();
     $m = $this->getRequest()->getModule();
 }
示例#5
0
文件: Rewrite.php 项目: kevinwan/xf
 /**
  * 分析匹配结果
  * @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;
                 }
             }
         }
     }
 }
示例#6
0
 public function postRender(&$html)
 {
     $static_url = 'http://static.' . XF_Config::getInstance()->getDomain();
     $html = str_replace('$static', $static_url, $html);
     $html = str_replace('src="/upload', 'src="' . $static_url . '/upload', $html);
     $html = str_replace('src="/images', 'src="' . $static_url . '/img', $html);
     //来源页面是地区切换页
     if ($_SERVER['HTTP_REFERER'] == 'http://www.' . XF_Config::getInstance()->getDomain() . '/') {
         $html = str_replace('$cityReferer', 'true', $html);
     } else {
         $html = str_replace('$cityReferer', 'false', $html);
     }
 }
示例#7
0
文件: Cookie.php 项目: kevinwan/xf
 /**
  * 写入内容
  * @param mixed $content
  * @param int $expire 过期时间 默认为一周7天 单位:秒
  * @param string $path 有效路径 默认为 "/"
  * @param string $domain 域,默认为配置文件中的 “domain”
  * @return XF_Cookie
  */
 public function write($content, $expire = 604800, $path = '/', $domain = NULL)
 {
     if ($this->_lock == FALSE) {
         $this->_lock = TRUE;
         if ($domain == NULL) {
             $domain = '.' . XF_Config::getInstance()->getDomain();
         }
         if ($content == null) {
             setcookie($this->_namespace, '1', time() - 1, $path, $domain);
         } else {
             setcookie($this->_namespace, XF_Functions::authCode($content), time() + $expire, $path, $domain);
         }
         $this->_lock = FALSE;
     }
     return $this;
 }
 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>');
     }
 }
示例#9
0
文件: Memcache.php 项目: kevinwan/xf
 /**
  * 获取当前缓存对象实例
  * @access public
  * @return XF_Cache_Memcache
  */
 public static function getInstance()
 {
     if (self::$_instance == null) {
         //是否存在memcache缓存服务器配置
         $servers = XF_Config::getInstance()->getMemcaches();
         if (!isset($servers[0])) {
             throw new XF_Cache_Exception('Memcache server config is empty');
         }
         $server = explode(':', $servers[0]);
         //检测是否安装memcache PHP扩展
         if (!class_exists('Memcache', FALSE)) {
             throw new XF_Cache_Exception('Memcache PECL expands has not installed or has begun using');
         }
         self::$_instance = new self();
         self::$_instance->_memcache = new Memcache();
         $status = self::$_instance->_memcache->connect($server[0], $server[1]);
         if ($status == FALSE) {
             throw new XF_Cache_Exception('Memcache connect failure');
         }
     }
     return self::$_instance;
 }
示例#10
0
 public function uploadfileAction()
 {
     $gpj_session = new XF_Session("gpj_session");
     if (!$gpj_session->hasContent("userId")) {
         throw new XF_Exception('上传商品图片:用户没有登录');
     }
     if (!$gpj_session->hasContent("sellInfoId")) {
         throw new XF_Exception('上传商品图片:没有数据来源');
     }
     $attDes = $this->getParam('attdes');
     $attrType = $this->getParam('attrtype');
     header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
     header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
     header("Cache-Control: no-store, no-cache, must-revalidate");
     header("Cache-Control: post-check=0, pre-check=0", false);
     header("Pragma: no-cache");
     @set_time_limit(5 * 60);
     $timestamp = gmdate("Ymd");
     // usleep(5000);
     $targetDir = $this->uploadPath . $timestamp . "/";
     // $targetDir = 'uploads';
     $cleanupTargetDir = true;
     $maxFileAge = 5 * 3600;
     if (!file_exists($targetDir)) {
         @mkdir($targetDir);
     }
     if (isset($_REQUEST["name"])) {
         $fileName = $_REQUEST["name"];
     } elseif (!empty($_FILES)) {
         $fileName = $_FILES["file"]["name"];
     } else {
         $fileName = uniqid("file_");
     }
     $filePath = $targetDir . DIRECTORY_SEPARATOR . $fileName;
     $chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;
     $chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0;
     if ($cleanupTargetDir) {
         if (!is_dir($targetDir) || !($dir = opendir($targetDir))) {
             die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}');
         }
         while (($file = readdir($dir)) !== false) {
             $tmpfilePath = $targetDir . DIRECTORY_SEPARATOR . $file;
             if ($tmpfilePath == "{$filePath}.part") {
                 continue;
             }
             if (preg_match('/\\.part$/', $file) && filemtime($tmpfilePath) < time() - $maxFileAge) {
                 @unlink($tmpfilePath);
             }
         }
         closedir($dir);
     }
     if (!($out = @fopen("{$filePath}.part", $chunks ? "ab" : "wb"))) {
         die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
     }
     if (!empty($_FILES)) {
         if ($_FILES["file"]["error"] || !is_uploaded_file($_FILES["file"]["tmp_name"])) {
             die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}');
         }
         if (!($in = @fopen($_FILES["file"]["tmp_name"], "rb"))) {
             die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
         }
     } else {
         if (!($in = @fopen("php://input", "rb"))) {
             die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
         }
     }
     while ($buff = fread($in, 4096)) {
         fwrite($out, $buff);
     }
     @fclose($out);
     @fclose($in);
     if (!$chunks || $chunk == $chunks - 1) {
         rename("{$filePath}.part", $filePath);
     }
     $sessionAry = $gpj_session->read();
     $attrObj = new Sell_Model_Attr();
     $last_id = $attrObj->addAttr($sessionAry["userId"], $sessionAry["sellInfoId"], $attrType, "/" . $timestamp . "/" . $fileName, $attDes);
     die('{"jsonrpc" : "2.0", "result" : "http://static.' . XF_Config::getInstance()->getDomain() . "/uploads/car/" . $timestamp . "/" . $fileName . '", "id" : "' . $last_id . '"}');
 }
示例#11
0
文件: Router.php 项目: kevinwan/xf
 /**
  * 验证路由重写规则
  * @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;
 }
示例#12
0
 /**
  * 向View中添加相关的资料
  */
 protected function initAddDataToView()
 {
     //当前配置文件中的主域名
     XF_View::getInstance()->assign('domain', $this->_config->getDomain());
 }
示例#13
0
文件: View.php 项目: kevinwan/xf
 /**
  * 获取模板起始位置目录
  * @access public
  * @return string
  */
 public function getTemplateStartLocation()
 {
     $this->_template_folder = XF_Controller_Front::getInstance()->getModuleDir() . '/views/' . XF_Config::getInstance()->getViewStyle();
     return $this->_template_folder;
 }
示例#14
0
文件: Tool.php 项目: kevinwan/xf
 /**
  * 获取配置文件中的数据库名称
  * @access public
  * @param string $var db_list 键名称
  * @return string 返回一个数据库名称
  */
 public static function getDBName($var)
 {
     $dbs = XF_Config::getInstance()->getDBNames();
     if (!is_array($dbs)) {
         throw new XF_Application_Exception('缺少dbnames配置资料!', 1000);
     }
     //如果没有预期的数据库名称,则回返当前key名称
     return isset($dbs[$var]) ? $dbs[$var] : $var;
 }
示例#15
0
文件: Abstract.php 项目: kevinwan/xf
 /**
  * 获取数据库服务器配置资料
  * @access protected
  * @return void
  */
 protected function _selectDatabaseServer()
 {
     $config = XF_Config::getInstance();
     $this->_open_slave = $config->getDBOpenSlave();
     //如果开启主从模式
     if ($this->_open_slave) {
         $dbs = $config->getDBServerSlaves();
         //随机获取一个从数据库连接
         $this->_slave_db_count = count($dbs);
         $slave = $dbs[rand(0, $this->_slave_db_count - 1)];
         $this->_slave_db_config = new XF_Db_Config();
         $this->_slave_db_config->setHost($slave['host'])->setHostPort($slave['port'])->setAccount($slave['user'])->setPassword($slave['pass'])->setChar('utf8');
     }
     //设置主数据库(可写)
     $dbs = $config->getDBServerMasters();
     if (is_array($dbs)) {
         $master = $dbs[rand(0, count($dbs) - 1)];
         $this->_db_config = new XF_Db_Config();
         $this->_db_config->setHost($master['host'])->setHostPort($master['port'])->setAccount($master['user'])->setPassword($master['pass'])->setChar('utf8');
     }
 }
示例#16
0
 public function postRender(&$html)
 {
     $html = str_replace('$static', 'http://static.' . XF_Config::getInstance()->getDomain(), $html);
     $html = str_replace('$cityReferer', 'false', $html);
 }
示例#17
0
 /**
  * 普通错误,警告
  * @param int $errno
  * @param string $errstr
  * @param string $errfile
  * @param int $errline
  * @throws XF_Exception
  */
 public static function appError($errno, $errstr, $errfile, $errline)
 {
     $env = XF_Config::getInstance()->getEnvironmental();
     $req = XF_Controller_Request_Http::getInstance();
     $url = $req->getMethod() . ' "' . $req->getRequestUrl() . '"';
     switch ($errno) {
         case E_ERROR:
         case E_PARSE:
         case E_CORE_ERROR:
         case E_COMPILE_ERROR:
         case E_USER_ERROR:
             $message = $url . "\n" . 'ERROR: ' . $errstr . ' in ' . $errfile . ' on line ' . $errline;
             if ($env == 'development') {
                 exit($message);
             } else {
                 XF_Functions::writeErrLog($message);
                 XF_Controller_Plugin_Manage::getInstance()->exception(XF_Controller_Request_Http::getInstance(), new XF_Exception($e['message']));
             }
             break;
             /*case E_STRICT:
                 case E_USER_WARNING:
                 case E_USER_NOTICE:
                 default:
             	    $message = 'ERROR: ['.$errno.']'.$errstr. ' in '.$errfile.' on line '.$errline;
             		XF_Functions::writeErrLog($message);
                     if ($env == 'development')
                     {
                       echo '<br/>'.$message;
                     }
             	    break;*/
     }
 }
示例#18
0
文件: Service.php 项目: kevinwan/xf
 /**
  * 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");
 }
示例#19
0
 /**
  * 发送邮箱
  * @param string $email 邮箱地址
  * @param string $title 标题
  * @param string $content html内容
  * @param string $text 文内容
  * @return bool 是否成功
  */
 public function sendEmail($email, $title, $content, $text = NULL)
 {
     require_once XF_PATH . "/Custom/PHPMailer/class.phpmailer.php";
     $config = XF_Config::getInstance()->load('common');
     $config = $config->common->smtp;
     //下面是几个不常用到的变量
     $charset = empty($config["charset"]) ? 'UTF-8' : $config["charset"];
     $encode = empty($config["encoding"]) ? 'base64' : $config["encoding"];
     $debug = empty($config["debug"]) ? false : $config["debug"];
     //初始化邮件类
     $mail = new PHPMailer();
     $mail->IsSMTP();
     // send via SMTP
     $mail->Host = $config["server"];
     // SMTP servers
     $mail->SMTPAuth = true;
     // turn on SMTP authentication 开启验证
     $mail->Username = $config["username"];
     // SMTP username  注意:普通邮件认证不需要加 @域名
     $mail->Password = $config["password"];
     // SMTP password
     $mail->From = $config["fromUserEmail"];
     // 发件人邮箱
     $mail->FromName = $config["fromUserName"];
     // 发件人
     $mail->CharSet = $charset;
     // 这里指定字符集!
     $mail->Encoding = $encode;
     // 编码方式
     $mail->SMTPDebug = $debug;
     // 调试用的开关
     $mail->AddReplyTo($config["username"], $config["fromUserName"]);
     if (!empty($config["gmail"])) {
         $mail->SMTPSecure = empty($config["secure"]) ? 'ssl' : $config["secure"];
         $mail->Port = empty($config["port"]) ? 465 : $config["port"];
     }
     $mail->Subject = $title;
     if ($content == null && $text != null) {
         $mail->IsHTML(false);
         $mail->Body = $text;
     } else {
         $mail->IsHTML(true);
         $mail->AltBody = $text;
         //不支持html格式时,显示的文本
         $mail->Body = $content;
         //html信体
     }
     $mail->AddAddress($email, $user);
     return $mail->Send();
 }
示例#20
0
文件: Mysql.php 项目: kevinwan/xf
 /**
  * 执行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;
 }
示例#21
0
 /**
  * 绑定当前域名到api模块
  */
 protected function initBindModule()
 {
     $this->_front->getRouter()->bindDomain('api', 'webapi.' . $this->_config->getDomain());
 }
示例#22
0
 /**
  * 获取文件位置
  * @access public
  * @param string $class
  * @return mixed
  */
 protected function _getFileName($class)
 {
     $class = $this->_validateFolderName($class);
     $filename = NULL;
     $tmp = explode('_', $class);
     //当前加载的类,类型 Application_Model_Test  Application_Model_Table_Test
     $classType = 'xf';
     switch ($tmp[0]) {
         case 'XF':
             unset($tmp[0]);
             $filename = XF_PATH . '/' . implode($tmp, '/') . '.php';
             break;
         case 'Application':
             $classType = 'application';
             $php = strtolower(end($tmp));
             $filename = APPLICATION_PATH . '/../' . str_replace($php . '.php', end($tmp) . '.php', strtolower(implode($tmp, '/')) . '.php');
             break;
         case 'Layout':
             $classType = 'layout';
             $filename = APPLICATION_PATH . '/layouts/' . $tmp[1] . '.php';
             break;
     }
     if ($filename == null) {
         if (count($tmp) > 1 && strpos($tmp[1], 'Controller')) {
             $appName = strtolower(substr($tmp[0], 0, 1));
             $appName = $appName . substr($tmp[0], 1);
             $classType = 'controller';
             $filename = APPLICATION_PATH . '/modules/' . $appName . '/controllers/' . $tmp[1] . '.php';
         } elseif (count($tmp) == 1 && strpos($tmp[0], 'Controller')) {
             $classType = 'controller';
             $filename = APPLICATION_PATH . '/controllers/' . $tmp[0] . '.php';
         } else {
             $classType = 'other';
             $php = strtolower(end($tmp));
             $appName = strtolower(substr($tmp[0], 0, 1));
             $appName = substr($tmp[0], 1);
             $filename = str_replace($php . '.php', end($tmp) . '.php', strtolower(implode($tmp, '/')) . '.php');
             $filename = str_replace(strtolower($appName . '/models'), $appName . '/models', $filename);
             $filename = APPLICATION_PATH . '/modules/' . $filename;
         }
     }
     //如果不是加载的框架文件,且当前应用程序中不存在指定的类文件时,尝试加载其它应用程序中的类文件 2012-11-07
     //配置文件中配置:include_application_paths
     if ($classType != 'xf' && !is_file($filename)) {
         $applicationPaths = XF_Config::getInstance()->getIncludeApplicationPaths();
         if (is_array($applicationPaths)) {
             foreach ($applicationPaths as $appPath) {
                 $filename = str_replace(APPLICATION_PATH, realpath($appPath) . '/application', $filename);
                 if (is_file($filename)) {
                     break;
                 }
             }
         }
     }
     //如果都没有发现需要加载的文件,则尝试在当前application中的libs目录中加载自定义的第三方类库
     if (!is_file($filename)) {
         $filename = APPLICATION_PATH . '/libs/' . str_replace('\\', '/', $class) . '.php';
     }
     return $filename;
 }