Example #1
0
File: View.php Project: kevinwan/xf
 /**
  * 获取当前实例
  * @return XF_View
  */
 public static function getInstance()
 {
     if (self::$_instance === null) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Example #2
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);
 }
Example #3
0
 /**
  * 在Scripts开头追加内容
  * @access public
  * @param string $str
  * @return XF_View_Helper_Header_Script
  */
 public function prependFile($str)
 {
     //防止与缓存中的路径重复
     $path = XF_View::getInstance()->getResourcePath();
     $str = str_replace($path, '', $str);
     array_unshift($this->_scripts, XF_String::text($path . $str));
     return $this;
 }
Example #4
0
 /**
  * 检测缓存的标题等资料
  * @access private
  * @param string $content
  * @return void
  */
 private function _checkCacheHtmlTag(&$content)
 {
     //title
     preg_match('/<\\!--Title:(.*?)-->/', $content, $matchs);
     if (isset($matchs[1])) {
         $this->_view->headTitle($matchs[1]);
         $content = str_replace($matchs[0], '', $content);
     }
     //metas
     preg_match('/<\\!--Metas:(.*?)-->/', $content, $matchs);
     if (isset($matchs[1])) {
         $tmp = unserialize($matchs[1]);
         if (is_array($tmp)) {
             foreach ($tmp as $val) {
                 $this->_view->headMeta($val);
             }
         }
         $content = str_replace($matchs[0], '', $content);
     }
     //scripts
     preg_match('/<\\!--Scripts:(.*?)-->/', $content, $matchs);
     if (isset($matchs[1])) {
         $tmp = unserialize($matchs[1]);
         if (is_array($tmp)) {
             foreach ($tmp as $val) {
                 $this->_view->headScript($val);
             }
         }
         $content = str_replace($matchs[0], '', $content);
     }
     //stylesheets
     preg_match('/<\\!--Stylesheets:(.*?)-->/', $content, $matchs);
     if (isset($matchs[1])) {
         $tmp = unserialize($matchs[1]);
         if (is_array($tmp)) {
             foreach ($tmp as $val) {
                 $this->_view->headStylesheet($val);
             }
         }
         $content = str_replace($matchs[0], '', $content);
     }
     //links
     preg_match('/<\\!--Links:(.*?)-->/', $content, $matchs);
     if (isset($matchs[1])) {
         $tmp = unserialize($matchs[1]);
         if (is_array($tmp)) {
             foreach ($tmp as $val) {
                 $this->_view->headLink($val);
             }
         }
         $content = str_replace($matchs[0], '', $content);
     }
 }
 public function goodinfoAction()
 {
     $submit_statue = $this->getParam('statue');
     $gpj_session = new XF_Session("gpj_session");
     $session_ary = $gpj_session->read();
     if (!$gpj_session->hasContent("userId")) {
         throw new XF_Exception('补充商品信息:用户没有登录');
     }
     if (isset($submit_statue) && !XF_Functions::isEmpty($submit_statue)) {
         if ($submit_statue == "submit") {
             $car_parts = $this->getParam("car_parts");
             $car_color = $this->getParam("car_color");
             $period_insurance = $this->getParam("period_insurance");
             $car_maintain = $this->getParam("car_maintain");
             $max_cost = $this->getParam("max_cost");
             $transfer_num = $this->getParam("transfer_num");
             $sellObj = new Sell_Model_Sellinfo();
             $last_id = $sellObj->addSellInfo($session_ary["userId"], $session_ary["modelId"], $session_ary["changeId"], $session_ary["dataFrom"], $session_ary["infoId"], implode(",", $car_parts), $car_color, $period_insurance, $car_maintain, $max_cost, $transfer_num, $this->nowCity->id);
             if ($last_id) {
                 $session_ary["sellInfoId"] = $last_id;
                 $gpj_session->write($session_ary);
                 XF_Functions::go("/sell/index/upload/");
             }
         }
     } else {
         $submit_statue = "submit";
     }
     $this->setLayout(new Layout_Default());
     $this->_view->headStylesheet('/css/sell/goodinfo.css');
     $this->_view->headStylesheet('/css/common.css');
     $this->_view->headScript('/js/pagejs/goodinfo.js');
     XF_View::getInstance()->assign('statue', $submit_statue);
     $this->_view->detailModel = $session_ary["detail_model"];
     $this->_view->detailYear = $session_ary["detail_year"];
     $this->_view->detailMile = $session_ary["detail_mile"];
     $this->_view->detailPrice = $session_ary["detail_price"];
 }
Example #6
0
 /**
  * 向View中添加相关的资料
  */
 protected function initAddDataToView()
 {
     //当前配置文件中的主域名
     XF_View::getInstance()->assign('domain', $this->_config->getDomain());
 }
Example #7
0
 /**
  * 获取分页所必要的资料,用户可以根据该资料自定议的分页样式
  * @access private
  */
 private function _getDiyResultByArray()
 {
     $plus = ceil($this->_now_bar_count / 2);
     if ($this->_now_bar_count - $plus + $this->_page > $this->_page_count) {
         $plus = $this->_now_bar_count - $this->_page_count + $this->_page;
     }
     $begin = $this->_page - $plus + 1;
     $begin = $begin >= 1 ? $begin : 1;
     $return = array();
     $return['no_page_current_url'] = $this->_getUrl();
     $return['html']['first'] = $this->_getUrl(1, 1);
     $return['data']['first'] = 1;
     $return['html']['last'] = $this->_getUrl($this->_page_count, $this->_page_count);
     $return['data']['last'] = $this->_page_count;
     $params = $this->_params;
     $return['html']['nonce'] = $this->_page;
     $return['data']['nonce'] = $this->_page;
     //上一页
     $ps = $this->_page == 1 ? 1 : $this->_page - 1;
     $return['html']['previous'] = $this->_getUrl($ps, $ps);
     $return['data']['previous'] = $ps;
     //下一页
     $ps = $this->_page == $this->_page_count ? $this->_page_count : $this->_page + 1;
     $return['html']['next'] = $this->_getUrl($ps, $ps);
     $return['data']['next'] = $ps;
     $return['url'] = $this->_custom_url;
     //总页
     $return['data_count'] = $this->_data_count;
     $return['page_count'] = $this->_page_count;
     for ($i = $begin; $i < $begin + $this->_now_bar_count; $i++) {
         if ($i <= $this->_page_count) {
             $return['html']['item'][] = array('html' => $this->_getUrl($i, $i), 'number' => $i);
             $return['data']['item'][] = $i;
         } else {
             break;
         }
     }
     //生成额外的参数连接
     $string = '';
     $values = array_values($params);
     $keys = array_keys($params);
     for ($i = 0; $i < count($params); $i++) {
         if ($keys[$i] != $this->_paginator_param) {
             $string .= '/' . $keys[$i] . '=' . $values[$i];
         }
     }
     $return['args_string'] = $string;
     $return['args'] = $params;
     $this->_custom_params = $return;
     XF_View::getInstance()->assign($this->_paginator_param . '_Paginator_Data', $return);
     return $return;
 }
Example #8
0
 /**
  * 获取视图
  * @return XF_View
  */
 protected function getView()
 {
     return XF_View::getInstance();
 }