source: branches/camp/camp-2_5-E/data/class/SC_Display.php @ 19024

Revision 19024, 2.3 KB checked in by miningbrownie, 16 years ago (diff)
Line 
1<?php
2class SC_Display{
3
4    var $response;
5
6    var $device;
7
8    var $autoSet;
9
10    // TODO php4を捨てたときに ここのコメントアウトを外してね。
11    /*
12    * const('MOBILE',1);
13    * const('SMARTPHONE',2);
14    * const('PC',4);
15    */
16
17    function SC_Display($autoGenerateHttpHeaders = true){
18        require_once(CLASS_EX_PATH."/SC_Response_Ex.php");
19        $this->response = new SC_Response_Ex();
20        $this->autoSet = $autoGenerateHttpHeaders;
21    }
22
23
24    // TODO このメソッドは、レスポンスを返すためのメソッドです。名前を絶対に変えましょう。
25    /**
26    *
27    * @param $page LC_Page
28    */
29    function hoge(LC_Page $page){
30        $this->assign($page);
31
32    }
33
34    /**
35     * デバイス毎の出力方法を自動で変更する、ファサード
36     * Enter description here ...
37     */
38    function setDevice(int $device = 4){
39      switch ($device){
40         
41      }
42    }
43
44    /**
45     * 機種を判別する。
46     * SC_Display::MOBILE = ガラケー = 1
47     * SC_Display::SMARTPHONE = スマホ = 2
48     * SC_Display::PC = PC = 4
49     * ※PHP4の為にconstは使っていません。 1がガラケーで、2がスマホで4がPCです。
50     * @return
51     */
52    function detectDevice(){
53        $nu = new Net_UserAgent_Mobile();
54        $retDevice = 0;
55        if($nu->isMobile()){
56            $retDevice = 1;
57        }elseif ($this->isSmartphone()){
58            $retDevice = 2;
59        }else{
60            $retDevice = 4;
61        }
62
63        if($this->autoSet){
64            $this->setDevice($retDevice);
65        }
66        return $retDevice;
67    }
68
69    function isSmartphone(){
70        $useragents = array(
71            'iPhone',         // Apple iPhone
72    'iPod',           // Apple iPod touch
73    'Android',        // 1.5+ Android
74    'dream',          // Pre 1.5 Android
75    'CUPCAKE',        // 1.5+ Android
76    'blackberry9500', // Storm
77    'blackberry9530', // Storm
78    'blackberry9520', // Storm v2
79    'blackberry9550', // Storm v2
80    'blackberry9800', // Torch
81    'webOS',          // Palm Pre Experimental
82    'incognito',      // Other iPhone browser
83    'webmate'         // Other iPhone browser
84        );
85
86        $pattern = implode("|", $useragents);
87        return preg_match('/['.$pattern.']/', $_SERVER['HTTP_USER_AGENT']);
88
89    }
90
91
92    function assign(LC_Page $page){
93
94    }
95
96
97}
Note: See TracBrowser for help on using the repository browser.