Example #1
0
 public static function run()
 {
     ZOL_Registry::set('request', new ZOL_Request());
     $request = ZOL_Registry::get('request');
     ZOL_Registry::set('response', new ZOL_Response());
     $response = ZOL_Registry::get('response');
     $controller = $request->getControllerName();
     $action = $request->getActionName();
     $controller = ZOL_String::toValidVariableName($controller);
     $action = ZOL_String::toValidVariableName($action);
     if (empty($controller)) {
         throw new ZOL_Exception("The controller of '{$controller}' is empty in request!");
     }
     if (empty($action)) {
         throw new ZOL_Exception("The action of '{$action}' is empty in request!");
     }
     $controller = APP_NAME . '_Page_' . ucfirst($controller);
     //var_dump($controller);
     $page = new $controller($request, $response);
     self::$_page = $page;
     self::$_url = empty($_SERVER['SCRIPT_URL']) ? '' : $_SERVER['SCRIPT_URL'];
     self::$_cacheKey = self::getCacheKey();
     if ($page->isCache() && ($html = self::getCache())) {
         die($html);
     }
     if ($page->validate($request, $response)) {
         $actionMap = $page->getActionMapping();
         if (empty($actionMap)) {
             $action = 'do' . ucfirst($action);
             if (method_exists($page, $action)) {
                 $page->{$action}($request, $response);
             } else {
                 throw new ZOL_Exception("The function of '{$action}' does not exist in class '{$controller}'!");
             }
         } else {
             foreach ($actionMap[$action] as $methodName) {
                 $methodName = 'do' . ucfirst($methodName);
                 if (method_exists($page, $methodName)) {
                     $page->{$methodName}($request, $response);
                 } else {
                     throw new ZOL_Exception(' the function dose not exist:' . $methodName);
                 }
             }
         }
     }
     self::$_html = $response->display();
     $page->isCache() && self::setCache();
 }
Example #2
0
 public static function handler($exception)
 {
     if ($exception instanceof Exception) {
         $debugging = defined('IS_DEBUGGING') ? IS_DEBUGGING : false;
         $production = defined('IS_PRODUCTION') ? IS_PRODUCTION : false;
         if (true == $debugging) {
             if (true == $production) {
                 ZOL_Log::write(ZOL_String::clean($exception), ZOL_Log::TYPE_EXCEPTION);
             } else {
                 echo ZOL_Request::resolveType() == ZOL_Request::CLI ? ZOL_String::clean($exception) : $exception;
             }
         } else {
             header('location: ' . SYSTEM_HOMEPAGE);
         }
     }
 }
Example #3
0
 /**
  * 存入VBA配置
  */
 public function doSetConfig(ZOL_Request $input, ZOL_Response $output)
 {
     $Arr = $upArr = array();
     $Arr['dbName'] = $input->post('db');
     $Arr['tableName'] = $input->post('tbl');
     $upArr['content'] = $Arr['content'] = $input->post('con', true) ? substr(ZOL_String::u8conv($input->post('con', true)), 1) : '';
     $flag = Helper_Dao::getOne(array('dbName' => 'Db_UserData', 'tblName' => 'vba_config', 'cols' => 'count(*)', 'whereSql' => ' and dbName="' . $Arr['dbName'] . '" and tableName="' . $Arr['tableName'] . '"'));
     if ($flag) {
         $data = Helper_Dao::updateItem(array('editItem' => $upArr, 'dbName' => 'Db_UserData', 'tblName' => 'vba_config', 'where' => ' dbName="' . $Arr['dbName'] . '" and tableName="' . $Arr['tableName'] . '"'));
     } else {
         $data = Helper_Dao::insertItem(array('addItem' => $Arr, 'dbName' => 'Db_UserData', 'tblName' => 'vba_config'));
     }
     if ($data) {
         echo 1;
     }
     exit;
 }
Example #4
0
 public static function handler($level, $errorMsg, $file, $line, $context = null)
 {
     if ('.tpl.php' == substr($file, -8)) {
         return;
     }
     $str = new ZOL_Exception($errorMsg, $level, $file, $line);
     $debugging = IS_DEBUGGING;
     $production = IS_PRODUCTION;
     if ($debugging) {
         $content = "<br />\n<h2>Error Info:</h2>\n" . '<b>MESSAGE:</b> ' . $errorMsg . "<br />\n" . '<b>TYPE:</b> ' . (isset(self::$levels[$level]) ? self::$levels[$level] : $level) . "<br />\n" . '<b>FILE:</b> ' . $file . "<br />\n" . '<b>LINE:</b> ' . $line . "<br />\n" . $str;
         if ($production) {
             ZOL_Log::write(ZOL_String::clean($content), ZOL_Log::TYPE_ERROR);
         } else {
             echo ZOL_Request::resolveType() == ZOL_Request::CLI ? ZOL_String::clean($content) : $content;
         }
     }
 }
Example #5
0
 /**
  * ajax获得指定数据
  */
 public function doAjaxData(ZOL_Request $input, ZOL_Response $output)
 {
     $id = (int) $input->get('id');
     $arr = Helper_Dao::getRows(array('dbName' => "Db_Andyou", 'tblName' => "staffcate", 'cols' => "*", 'whereSql' => ' and id=' . $id));
     $data = ZOL_String::convToU8($arr);
     if (isset($data[0])) {
         echo json_encode($data[0]);
     }
     exit;
 }
Example #6
0
 public function getByMethod($key = '', $method = 'get', $allowTags = false, $safeFilter = true)
 {
     $ret = '';
     if (empty($key)) {
         if (false === $allowTags) {
             $ret = ZOL_String::clean($this->_a[$method]);
         } else {
             $ret = $this->_a[$method];
         }
     } elseif (isset($this->_a[$method][$key])) {
         //  don't operate on reference to avoid segfault :-(
         $ret = $this->_a[$method][$key];
         //  if html not allowed, run an enhanced strip_tags()
         if (false === $allowTags) {
             $ret = ZOL_String::clean($ret);
         }
     }
     if (!empty($ret)) {
         if (self::AJAX == $this->getType() && strcasecmp(SYSTEM_CHARSET, 'utf-8')) {
             if (in_array(strtolower($method), array('get', 'post')) && !empty($ret)) {
                 $ret = ZOL_String::convertEncodingDeep($ret, SYSTEM_CHARSET, 'utf-8');
             }
         }
     }
     if ($safeFilter && defined("IN_ZOL_API")) {
         #如果已经包含私有云
         $methodMap = array("get" => "G", "post" => "P", "cookie" => "C", "request" => "G");
         if (isset($methodMap[$method])) {
             $ret = API_Item_Security_Input::sqlFilter(array('value' => $ret, 'from' => $methodMap[$method], 'recDb' => true));
         }
     }
     return $ret;
 }
Example #7
0
 /**
  * 得到用户所在地区信息
  */
 public static function getUserArea()
 {
     $ip = self::getClientIpMulti();
     $ipArr = explode(",", $ip);
     $ipNum = count($ipArr);
     $ip = $ipArr[0];
     #这个是加了一个广告代理,所以ip变成三个了,取第一个 2010-06-18
     $cacheObj = ZOL_DAL_RefreshCacheLoader::getInstance();
     $tmpProvinceArr = $cacheObj->loadCacheObject('Province', array());
     $provinceArr = array();
     if ($tmpProvinceArr) {
         foreach ($tmpProvinceArr as $key => $value) {
             $provinceName = ZOL_String::substr($value, 4);
             $provinceArr[$provinceName] = $key;
         }
     }
     $ipName = self::ip2location($ip);
     if (strpos($ipName, '省')) {
         $ipName = explode('省', $ipName);
         $cityName = ZOL_String::substr($ipName[1], 4);
         $provinceName = ZOL_String::substr($ipName[0], 4);
     } else {
         $cityName = '';
         $provinceName = ZOL_String::substr($ipName, 4);
     }
     #省份
     $provinceId = 1;
     if ($cityName && array_key_exists($cityName, $provinceArr)) {
         $provinceId = $provinceArr[$cityName];
     } elseif ($provinceName && array_key_exists($provinceName, $provinceArr)) {
         $provinceId = $provinceArr[$provinceName];
     }
     #城市
     $cityId = 0;
     if ($cityName && $provinceId) {
         $tmpCityArr = $cacheObj->loadCacheObject('City', array('provinceId' => $provinceId));
         foreach ($tmpCityArr as $key => $val) {
             $val = ZOL_String::substr($val, 4);
             if ($val == $cityName) {
                 $cityId = $key;
                 break;
             }
         }
     }
     #locationId获得
     $tmpLocationArr = $cacheObj->loadCacheObject('Location', array('type' => 'LOCATION'));
     $locationArr = array();
     if ($tmpLocationArr) {
         foreach ($tmpLocationArr as $key => $value) {
             $locationName = ZOL_String::substr($value['name'], 4);
             $locationArr[$locationName] = $key;
         }
     }
     #根据省的名称和城市的名称,获得LocationId
     $locationId = 1;
     if ($cityName && isset($locationArr[$cityName])) {
         $locationId = $locationArr[$cityName];
     } elseif ($provinceName && isset($locationArr[$provinceName])) {
         $locationId = $locationArr[$provinceName];
         if (isset($tmpLocationArr[$locationId]['defaultId'])) {
             $locationId = $tmpLocationArr[$locationId]['defaultId'];
         }
     }
     setcookie('userProvinceId', $provinceId, SYSTEM_TIME + 86400, '/', '.zol.com.cn');
     setcookie('userCityId', $cityId, SYSTEM_TIME + 86400, '/', '.zol.com.cn');
     setcookie('userLocationId', $locationId, SYSTEM_TIME + 86400, '/', '.zol.com.cn');
     return array('provinceId' => $provinceId, 'cityId' => $cityId, 'userLocationId' => $locationId);
 }
Example #8
0
 /**
  * Query function
  * @param string $sql
  */
 function query($sql)
 {
     if ('' === $sql) {
         throw new ZOL_Exception('$sql should not be empty!');
     }
     if (false == $this->link) {
         $this->connect();
     }
     if (!fwrite($this->link, $sql . "\n")) {
         trigger_error('Send search query failed!', E_USER_WARNING);
         return false;
     }
     $result = '';
     while (($line = fgets($this->link, 4096)) !== false) {
         $result .= $line;
     }
     $doc = simplexml_load_string($result, 'SimpleXMLElement', LIBXML_NOCDATA);
     if (false === $doc) {
         trigger_error('Invalid document format!', E_USER_WARNING);
         return false;
     }
     $this->res = ZOL_String::u8conv($doc, $this->encoding);
     return !$this->res['@attributes']['state'];
 }
Example #9
0
 /**
  * 产品线选择
  */
 public function doSelectSubcate(ZOL_Request $input, ZOL_Response $output)
 {
     $manuId = (int) $input->get('manuId');
     $subcateIdStr = $input->get('subcateIdStr');
     if ($subcateIdStr) {
         $subcateIdArr = explode(',', $subcateIdStr);
     }
     #取得所有品牌数据
     //        $dataArr = ZOL_Api::run("Pro.Cate.getSubcateByDb" , array(
     //            'manuId'  => $manuId, #品牌ID
     //            'noSecond'=> 1
     //        ));
     #数据源数组配置
     $dataArr = Helper_Pro_Pro::getSubcateTemp(array());
     if ($dataArr) {
         foreach ($dataArr as $key => $val) {
             if (isset($subcateIdArr) && in_array($val['subcateId'], $subcateIdArr)) {
                 continue;
             }
             $manuName = ZOL_String::trimWhitespace($val['name']);
             #获得首字母
             $tfl = API_Item_Base_String::getFirstLetter(array('input' => $manuName));
             if (!isset($outArr[$tfl])) {
                 $outArr[$tfl] = array('name' => $tfl, 'cons' => array());
             }
             $outArr[$tfl]['cons'][] = $val;
         }
         sort($outArr);
         $output->outArr = $outArr;
     }
     $output->setTemplate('Ajax/SelectSubcate');
 }
Example #10
0
 /**
  * ajax获得指定数据
  */
 public function doAjaxData(ZOL_Request $input, ZOL_Response $output)
 {
     $id = (int) $input->get('id');
     $arr = Helper_Dao::getRows(array('dbName' => "Db_Andyou", 'tblName' => "membercate", 'cols' => "*", 'whereSql' => ' and id=' . $id));
     //数据补充
     if ($arr) {
         foreach ($arr as $k => $v) {
             if ($v["discountStr"]) {
                 $tmparr = json_decode($v["discountStr"], true);
                 foreach ($tmparr as $i => $iv) {
                     $arr[$k]["disc_" . $i] = $iv;
                 }
             }
         }
     }
     $data = ZOL_String::convToU8($arr);
     if (isset($data[0])) {
         echo json_encode($data[0]);
     }
     exit;
 }
Example #11
0
 /**
  * 推送ios设备消息
  * @param type $paramArr
  */
 public static function pushMessageIos($paramArr)
 {
     $options = array('apiKey' => '', 'secretKey' => '', 'alert' => '', 'pushType' => '', 'userId' => '', 'tagName' => '', 'channelId' => '', 'messageType' => '');
     if (is_array($paramArr)) {
         $options = array_merge($options, $paramArr);
     }
     extract($options);
     $channel = new Channel($apiKey, $secretKey);
     $push_type = $pushType;
     //推送单播消息
     //如果推送单播消息,需要指定user
     if ($userId) {
         $optional[Channel::USER_ID] = $userId;
     }
     //如果推送tag消息,需要指定tag_name
     if ($tagName) {
         $optional[Channel::TAG_NAME] = $tagName;
     }
     //指定发到ios设备
     $optional[Channel::DEVICE_TYPE] = 4;
     //指定消息类型为通知
     $optional[Channel::MESSAGE_TYPE] = $messageType;
     //如果ios应用当前部署状态为开发状态,指定DEPLOY_STATUS为1,默认是生产状态,值为2.
     //旧版本曾采用不同的域名区分部署状态,仍然支持。
     $optional[Channel::DEPLOY_STATUS] = 1;
     //通知类型的内容必须按指定内容发送,示例如下:
     $message = '{ 
         "aps":{
             "alert":"' . ZOL_String::convToU8($alert) . '",
             "sound":"",
             "badge":0
         }
     }';
     $message_key = "msg_key";
     $ret = $channel->pushMessage($push_type, $message, $message_key, $optional);
     return $ret;
 }
Example #12
0
 /**
  * 获取历史列表页链接 
  * @param array 数组参数
  */
 public static function getHistoryListUrl($paramArr)
 {
     $options = array('subcateId' => 0, 'subcateEnName' => 0, 'manuId' => 0, 'priceId' => 1, 'paramVal' => '', 'queryType' => 0, 'keyword' => 0, 'page' => 1, 'rewrite' => 1);
     if (is_array($paramArr)) {
         $options = array_merge($options, $paramArr);
     }
     extract($options);
     if (!$rewrite) {
         $url = '/index.php?c=List&subcateId=' . $subcateId;
         $url .= $manuId ? '&manuId=' . $manuId : '';
         if (is_array($appendParam)) {
             $url .= '&' . http_build_query($appendParam);
         } else {
             if ($appendParam) {
                 $url .= '&' . $appendParam;
             }
         }
         return $url;
     } else {
         $urlParam = $paramVal ? "_" . $paramVal : '_0';
         #复合参数
         #关键字分页替换用,不需转换
         if ($keyword && '{keyword}' != $keyword) {
             $keyword = ZOL_String::escape($keyword);
             $keyword = str_replace('%', '@', $keyword);
         }
         if ($paramVal && $keyword) {
             $urlKeyword = "-k" . $keyword;
             #关键字
         } else {
             if (!$paramVal && $keyword) {
                 $urlKeyword = "_k" . $keyword;
                 #关键字
             } else {
                 $urlKeyword = '';
             }
         }
         $url = '/history/subcate' . $subcateId . '_' . $manuId . '_' . $priceId . $urlParam . $urlKeyword . '_' . $queryType . '_' . $page . ".html";
     }
     return $url;
 }