Example #1
0
 public function start()
 {
     if ($this->isStarted()) {
         return;
     }
     $id = $this->request->getCookie(self::SESSION_NAME);
     if (!$this->storage->hasSession($id)) {
         $id = $this->storage->createSession();
         $this->response->setCookie(self::SESSION_NAME, $id, array('Path' => '/'));
     }
     $this->id = $id;
 }
Example #2
0
 /**
  * Parses a raw response string, including headers and body, and returns a Response object.
  *
  * @param string $response
  *
  * @return \Brick\Http\Response
  *
  * @throws \RuntimeException
  */
 public static function parse($response)
 {
     $responseObject = new Response();
     if (preg_match('/^HTTP\\/([0-9]\\.[0-9]) ([0-9]{3}) .*\\r\\n/', $response, $matches) == 0) {
         throw new \RuntimeException('Could not parse response (error 1).');
     }
     list($line, $protocolVersion, $statusCode) = $matches;
     $responseObject->setProtocolVersion($protocolVersion);
     $responseObject->setStatusCode($statusCode);
     $response = substr($response, strlen($line));
     for (;;) {
         $pos = strpos($response, Message::CRLF);
         if ($pos === false) {
             throw new \RuntimeException('Could not parse response (error 2).');
         }
         if ($pos == 0) {
             break;
         }
         $header = substr($response, 0, $pos);
         if (preg_match('/^(\\S+):\\s*(.*)$/', $header, $matches) == 0) {
             throw new \RuntimeException('Could not parse response (error 3).');
         }
         list($line, $name, $value) = $matches;
         if (strtolower($name) == 'set-cookie') {
             $responseObject->setCookie(Cookie::parse($value));
         } else {
             $responseObject->addHeader($name, $value);
         }
         $response = substr($response, strlen($line) + 2);
     }
     $body = substr($response, 2);
     $responseObject->setContent($body);
     return $responseObject;
 }
 /**
  * @brief mobileDo 进行电脑版与手机版的切换
  *
  * @return void
  */
 private function mobileDo()
 {
     if (Request::C('isMobile', 'string') == 'TRUE') {
         Response::setCookie('isMobile', 'FALSE', time() + 3600 * 24 * 365);
     } else {
         Response::setCookie('isMobile', 'TRUE', time() + 3600 * 24 * 365);
     }
     Response::back();
 }
 /**
  * @brief logout 用户退出
  *
  * @return void
  */
 public function logout()
 {
     Response::setCookie('userid', NULL, 0);
     Response::setCookie('password', NULL, 0);
     Response::back();
 }
 /**
  * @brief postComment 发表评论
  *
  * @return void
  */
 public function postComment()
 {
     $c = array();
     // 如果用户已登录,则可以不填写基本信息
     if (Widget::getWidget('User')->isLogin()) {
         $user = Widget::getWidget('User')->getUser();
         $c['uid'] = $user['uid'];
         $c['author'] = $user['username'];
         $c['email'] = $user['email'];
         $c['website'] = $user['website'];
     } else {
         $c['uid'] = 0;
         $c['author'] = Request::P('author', 'string');
         $c['email'] = Request::P('email', 'string');
         $c['website'] = Request::P('website', 'string');
     }
     $c['pid'] = Request::P('postId');
     $c['content'] = Request::P('content', 'string');
     $error = '';
     if (!$c['pid'] || !$c['author'] || !$c['email'] || !$c['content']) {
         // 检查信息完整性
         $error = _t('Author, Email and Content can not be null.');
     } else {
         // 检查文章是否存在、是否允许评论
         Widget::initWidget('Post');
         $post = new PostLibrary();
         $p = $post->getPost($c['pid']);
         if ($p) {
             Widget::getWidget('Post')->setPID($c['pid']);
         } else {
             $p = $post->getPage($c['pid'], FALSE);
             Widget::getWidget('Post')->setAlias($p['alias']);
         }
         if (!Widget::getWidget('Post')->query() || !Widget::getWidget('Post')->postAllowReply()) {
             $error = _t('Comment closed.');
         } else {
             // TODO 敏感词过滤
             // TODO 内容处理
             $c['content'] = str_replace(array("\r\n", "\n", "\r"), '<br />', htmlspecialchars($c['content']));
             $c = Plugin::call('postComment', $c);
             // 写入评论
             $comment = new CommentLibrary();
             $comment->postComment($c);
             // 评论计数加一
             $post->incReply($c['pid']);
             // 保存用户信息
             Response::setCookie('author', $c['author'], time() + 24 * 3600 * 365);
             Response::setCookie('email', $c['email'], time() + 24 * 3600 * 365);
             Response::setCookie('website', $c['website'], time() + 24 * 3600 * 365);
         }
     }
     if ($error) {
         $r = array('success' => FALSE, 'message' => $error);
     } else {
         $r = array('success' => TRUE, 'message' => _t('Post comment success.'));
     }
     if (Request::isAjax()) {
         Response::ajaxReturn($r);
     } else {
         if ($error) {
             Response::error(_t('Post failed'), $error);
         } else {
             Response::back();
         }
     }
 }
 /**
  * @brief isMobile 判断是否为手机等便携式设备访问
  *
  * @return bool
  */
 public static function isMobile()
 {
     if (self::$_isMobile === TRUE || Request::C('isMobile', 'string') == 'TRUE') {
         return TRUE;
     } elseif (self::$_isMobile === FALSE || Request::C('isMobile', 'string') == 'FALSE') {
         return FALSE;
     }
     $user_agent = $_SERVER['HTTP_USER_AGENT'];
     $mobile_agents = array("240x320", "acer", "acoon", "acs-", "abacho", "ahong", "airness", "alcatel", "amoi", "android", "anywhereyougo.com", "applewebkit/525", "applewebkit/532", "asus", "audio", "au-mic", "avantogo", "becker", "benq", "bilbo", "bird", "blackberry", "blazer", "bleu", "cdm-", "compal", "coolpad", "danger", "dbtel", "dopod", "elaine", "eric", "etouch", "fly ", "fly_", "fly-", "go.web", "goodaccess", "gradiente", "grundig", "haier", "hedy", "hitachi", "htc", "huawei", "hutchison", "inno", "ipad", "ipaq", "ipod", "jbrowser", "kddi", "kgt", "kwc", "lenovo", "lg ", "lg2", "lg3", "lg4", "lg5", "lg7", "lg8", "lg9", "lg-", "lge-", "lge9", "longcos", "maemo", "mercator", "meridian", "micromax", "midp", "mini", "mitsu", "mmm", "mmp", "mobi", "mot-", "moto", "nec-", "netfront", "newgen", "nexian", "nf-browser", "nintendo", "nitro", "nokia", "nook", "novarra", "obigo", "palm", "panasonic", "pantech", "philips", "phone", "pg-", "playstation", "pocket", "pt-", "qc-", "qtek", "rover", "sagem", "sama", "samu", "sanyo", "samsung", "sch-", "scooter", "sec-", "sendo", "sgh-", "sharp", "siemens", "sie-", "softbank", "sony", "spice", "sprint", "spv", "symbian", "tablet", "talkabout", "tcl-", "teleca", "telit", "tianyu", "tim-", "toshiba", "tsm", "up.browser", "utec", "utstar", "verykool", "virgin", "vk-", "voda", "voxtel", "vx", "wap", "wellco", "wig browser", "wii", "windows ce", "wireless", "xda", "xde", "zte");
     self::$_isMobile = FALSE;
     foreach ($mobile_agents as $device) {
         if (stristr($user_agent, $device)) {
             self::$_isMobile = TRUE;
             break;
         }
     }
     if (self::$_isMobile) {
         Response::setCookie('isMobile', 'TRUE', time() + 3600 * 24 * 365);
     } else {
         Response::setCookie('isMobile', 'FALSE', time() + 3600 * 24 * 365);
     }
     return self::$_isMobile;
 }
Example #7
0
 /**
  * Description: 评分
  */
 public function score()
 {
     $articleId = Request::getRequest('article_id', 'int', 58);
     $score = Request::getRequest('score', 'int', 1);
     //判断参数
     if ($score != 1 && $score != 2) {
         View::showErrorMessage(GAME_URL, '非法操作');
     }
     //返回
     $data = array();
     //判断是否24小时内已经投过了。cookie判断,伪验证。
     $addScore = Request::getCookie('add_score');
     if (!empty($addScore) && $addScore - time() <= 86400) {
         $data['status'] = -2;
         $data['msg'] = '<p class="text-center">说你呢-.-</p><p class="text-center">不要贪得无厌哦</p><p class="text-center">24小时内只能顶一次';
         return json_encode($data);
     }
     Response::setCookie('add_score', time(), time() + 86400);
     //更新数据库
     if ($score == 1) {
         $result = ArticleBusiness::goodNum($articleId);
     } else {
         if ($score == 2) {
             $result = ArticleBusiness::badNum($articleId);
         }
     }
     //整理返回值
     if ($result) {
         $data['status'] = 0;
         $data['msg'] = 1;
     } else {
         $data['status'] = -1;
         $data['msg'] = '不明所以的失败了,请重新。';
     }
     return json_encode($data);
 }
 public function testSetCookie_InvalidStringExpire()
 {
     $this->setExpectedException('InvalidArgumentException');
     $this->object->setCookie('user', 'john doe', 'some invalid string');
 }