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

Revision 19022, 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
40    }
41
42    /**
43     * 機種を判別する。
44     * SC_Display::MOBILE = ガラケー = 1
45     * SC_Display::SMARTPHONE = スマホ = 2
46     * SC_Display::PC = PC = 4
47     * ※PHP4の為にconstは使っていません。 1がガラケーで、2がスマホで4がPCです。
48     * @return
49     */
50    function detectDevice(){
51        $nu = new Net_UserAgent_Mobile();
52        $retDevice = 0;
53        if($nu->isMobile()){
54            $retDevice = 1;
55        }elseif ($this->isSmartphone()){
56            $retDevice = 2;
57        }else{
58            $retDevice = 4;
59        }
60       
61        if($this->autoSet){
62            $this->setDevice($retDevice);
63        }
64        return $retDevice;
65    }
66
67    function isSmartphone(){
68        $useragents = array(
69            'iPhone',         // Apple iPhone
70    'iPod',           // Apple iPod touch
71    'Android',        // 1.5+ Android
72    'dream',          // Pre 1.5 Android
73    'CUPCAKE',        // 1.5+ Android
74    'blackberry9500', // Storm
75    'blackberry9530', // Storm
76    'blackberry9520', // Storm v2
77    'blackberry9550', // Storm v2
78    'blackberry9800', // Torch
79    'webOS',          // Palm Pre Experimental
80    'incognito',      // Other iPhone browser
81    'webmate'         // Other iPhone browser
82        );
83
84        $pattern = implode("|", $useragents);
85        return preg_match('/['.$pattern.']/', $_SERVER['HTTP_USER_AGENT']);
86
87    }
88
89}
90
91function assign(LC_Page $page){
92
93}
94
95
96}
Note: See TracBrowser for help on using the repository browser.