| 1 | <?php |
|---|
| 2 | // TODO GPLのあれ |
|---|
| 3 | class SC_Display{ |
|---|
| 4 | |
|---|
| 5 | var $response; |
|---|
| 6 | |
|---|
| 7 | var $device; |
|---|
| 8 | |
|---|
| 9 | var $autoSet; |
|---|
| 10 | |
|---|
| 11 | /** |
|---|
| 12 | * |
|---|
| 13 | * @var SC_View |
|---|
| 14 | */ |
|---|
| 15 | var $view; |
|---|
| 16 | |
|---|
| 17 | var $deviceSeted = false; |
|---|
| 18 | |
|---|
| 19 | // TODO php4を捨てたときに ここのコメントアウトを外してね。 |
|---|
| 20 | /* |
|---|
| 21 | * const('MOBILE',1); |
|---|
| 22 | * const('SMARTPHONE',2); |
|---|
| 23 | * const('PC',4); |
|---|
| 24 | * const('ADMIN',8); |
|---|
| 25 | */ |
|---|
| 26 | function SC_Display($setPrevURL=true,$autoGenerateHttpHeaders = true){ |
|---|
| 27 | require_once(CLASS_EX_PATH."/SC_Response_Ex.php"); |
|---|
| 28 | $this->response = new SC_Response_Ex(); |
|---|
| 29 | $this->autoSet = $autoGenerateHttpHeaders; |
|---|
| 30 | if ($setPrevURL) { |
|---|
| 31 | $this->setPrevURL(); |
|---|
| 32 | } |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | function setPrevURL(){ |
|---|
| 36 | $objCartSess = new SC_CartSession(); |
|---|
| 37 | $objCartSess->setPrevURL($_SERVER['REQUEST_URI']); |
|---|
| 38 | |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | // TODO このメソッドは、レスポンスを返すためのメソッドです。名前を絶対に変えましょう。 |
|---|
| 43 | /** |
|---|
| 44 | * |
|---|
| 45 | * @param $page LC_Page |
|---|
| 46 | */ |
|---|
| 47 | function hoge($page, $is_admin = false){ |
|---|
| 48 | if(!$this->deviceSeted || !is_null($this->view)){ |
|---|
| 49 | $device = ($is_admin) ? 8 : $this->detectDevice(); |
|---|
| 50 | $this->setDevice($device); |
|---|
| 51 | } |
|---|
| 52 | $this->assignobj($page); |
|---|
| 53 | $this->response->setResposeBody($this->view->getResponse($page->getTemplate())); |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | function redirect($location){ |
|---|
| 57 | $this->response->sendRedirect($location); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | function reload($queryString = array(), $removeQueryString = false){ |
|---|
| 61 | $this->response->reload($queryString, $removeQueryString); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | function noAction(){ |
|---|
| 65 | return; |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | function addHeader($name, $value){ |
|---|
| 69 | $this->response->addHeader($name, $value); |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | /** |
|---|
| 73 | * デバイス毎の出力方法を自動で変更する、ファサード |
|---|
| 74 | * Enter description here ... |
|---|
| 75 | */ |
|---|
| 76 | function setDevice($device=4){ |
|---|
| 77 | |
|---|
| 78 | switch ($device){ |
|---|
| 79 | case 1: |
|---|
| 80 | $this->response->setContentType("text/html"); |
|---|
| 81 | $this->setView(new SC_MobileView()); |
|---|
| 82 | break; |
|---|
| 83 | case 2: |
|---|
| 84 | // $this->view = new |
|---|
| 85 | break; |
|---|
| 86 | case 4: |
|---|
| 87 | $this->setView(new SC_SiteView()); |
|---|
| 88 | break; |
|---|
| 89 | case 8: |
|---|
| 90 | $this->setView(new SC_AdminView()); |
|---|
| 91 | } |
|---|
| 92 | $this->deviceSeted = true; |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | function setView($view){ |
|---|
| 96 | |
|---|
| 97 | $this->view = $view; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | /** |
|---|
| 101 | * 機種を判別する。 |
|---|
| 102 | * SC_Display::MOBILE = ガラケー = 1 |
|---|
| 103 | * SC_Display::SMARTPHONE = スマホ = 2 |
|---|
| 104 | * SC_Display::PC = PC = 4 |
|---|
| 105 | * ※PHP4の為にconstは使っていません。 1がガラケーで、2がスマホで4がPCです。 |
|---|
| 106 | * @return |
|---|
| 107 | */ |
|---|
| 108 | function detectDevice(){ |
|---|
| 109 | $nu = new Net_UserAgent_Mobile(); |
|---|
| 110 | $su = new SC_SmartphoneUserAgent(); |
|---|
| 111 | $retDevice = 0; |
|---|
| 112 | if($nu->isMobile()){ |
|---|
| 113 | $retDevice = 1; |
|---|
| 114 | }elseif ($su->isSmartphone()){ |
|---|
| 115 | $retDevice = 2; |
|---|
| 116 | }else{ |
|---|
| 117 | $retDevice = 4; |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | if($this->autoSet){ |
|---|
| 121 | $this->setDevice($retDevice); |
|---|
| 122 | } |
|---|
| 123 | return $retDevice; |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | function assign($val1,$val2){ |
|---|
| 127 | $this->view->assign($val1, $val2); |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | function assignobj($obj){ |
|---|
| 131 | $this->view->assignobj($obj); |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | function assignarray($array){ |
|---|
| 135 | $this->view->assignarray($array); |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | } |
|---|