ここの情報は古いです。ご理解頂いた上でお取り扱いください。

source: OpenPNE3/trunk/lib/request/sfOpenPNEWebRequest.class.php @ 10121

Last change on this file since 10121 was 10121, checked in by ebihara, 11 years ago

#3439:fixed sfOpenPNEWebRequest for the mobile UIDs are now a MD5 hash, not a plain text

File size: 2.6 KB
Line 
1<?php
2
3/**
4 * This file is part of the OpenPNE package.
5 * (c) OpenPNE Project (http://www.openpne.jp/)
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file and the NOTICE file that were distributed with this source code.
9 */
10
11/**
12 * sfOpenPNEWebRequest class manages web requests.
13 *
14 * @package    OpenPNE
15 * @subpackage request
16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
17 */
18class sfOpenPNEWebRequest extends sfWebRequest
19{
20  protected $userAgentMobileInstance = null;
21
22 /**
23  * @see sfWebRequest
24  */
25  public function initialize(sfEventDispatcher $dispatcher, $parameters = array(), $attributes = array())
26  {
27    parent::initialize($dispatcher, $parameters, $attributes);
28
29    require_once 'Net/UserAgent/Mobile.php';
30  }
31
32  public function getMobile()
33  {
34    if (!$this->userAgentMobileInstance) {
35      $this->userAgentMobileInstance = Net_UserAgent_Mobile::factory();
36    }
37
38    return $this->userAgentMobileInstance;
39  }
40
41  public function isMobile()
42  {
43    return !($this->getMobile()->isNonMobile());
44  }
45
46 /**
47  * Returns the mobile UID.
48  *
49  * @return string  mobile UID
50  */
51  public function getMobileUID()
52  {
53    if (!$this->isMobile()) {
54      return false;
55    }
56
57    $uid = $this->getMobile()->getUID();
58    if (!$uid)
59    {
60      if ($this->getMobile()->isSoftBank())
61      {
62        $uid = $this->getMobile()->getSerialNumber();
63      }
64      elseif ($this->getMobile()->isDoCoMo())
65      {
66        $uid = $this->getMobile()->getCardID();
67      }
68    }
69
70    // OpenPNE doesn't need to know a plain mobile UID
71    return md5($uid);
72  }
73
74 /**
75  * Checks whether the mobile UID is a valid or not.
76  *
77  * This method consideres the older versions of OpenPNE(-2.14).
78  *
79  * @params  string $hashedUid
80  *
81  * @return  bool
82  */
83  public function isValidMobileUID($hashedUid)
84  {
85    if (!$this->isMobile())
86    {
87      return false;
88    }
89
90    if ($hashedUid === md5($this->getMobile()->getUID()))
91    {
92      return true;
93    }
94
95    if ($this->getMobile()->isSoftBank())
96    {
97      return ($hashedUid === md5($this->getMobile()->getSerialNumber()));
98    }
99
100    if ($this->getMobile()->isDoCoMo())
101    {
102      return ($hashedUid === md5($this->getMobile()->getCardID()));
103    }
104
105    return false;
106  }
107
108  public function isCookie()
109  {
110    if ($this->getMobile()->isDoCoMo())
111    {
112      return false;
113    }
114    elseif ($this->getMobile()->isSoftBank())
115    {
116      if (!$this->getMobile()->isType3GC() && !$this->getMobile()->isTypeW())
117      {
118        return false;
119      }
120    }
121
122    return true;
123  }
124
125  public function getCurrentQueryString()
126  {
127    return http_build_query($this->getGetParameters());
128  }
129}
Note: See TracBrowser for help on using the repository browser.