PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/baser/controllers/site_configs_controller.php

https://github.com/hashing/basercms
PHP | 288 lines | 158 code | 34 blank | 96 comment | 32 complexity | ef97f17415e90dbdc7841f69edff04a9 MD5 | raw file
Possible License(s): MIT
  1. <?php
  2. /* SVN FILE: $Id$ */
  3. /**
  4. * サイト設定コントローラー
  5. *
  6. * PHP versions 5
  7. *
  8. * baserCMS : Based Website Development Project <http://basercms.net>
  9. * Copyright 2008 - 2012, baserCMS Users Community <http://sites.google.com/site/baserusers/>
  10. *
  11. * @copyright Copyright 2008 - 2012, baserCMS Users Community
  12. * @link http://basercms.net baserCMS Project
  13. * @package baser.controllers
  14. * @since baserCMS v 0.1.0
  15. * @version $Revision$
  16. * @modifiedby $LastChangedBy$
  17. * @lastmodified $Date$
  18. * @license http://basercms.net/license/index.html
  19. */
  20. /**
  21. * Include files
  22. */
  23. /**
  24. * サイト設定コントローラー
  25. *
  26. * @package baser.controllers
  27. */
  28. class SiteConfigsController extends AppController {
  29. /**
  30. * クラス名
  31. *
  32. * @var string
  33. * @access public
  34. */
  35. var $name = 'SiteConfigs';
  36. /**
  37. * モデル
  38. *
  39. * @var array
  40. * @access public
  41. */
  42. var $uses = array('SiteConfig','GlobalMenu','Page');
  43. /**
  44. * コンポーネント
  45. *
  46. * @var array
  47. * @access public
  48. */
  49. var $components = array('BcAuth','Cookie','BcAuthConfigure');
  50. /**
  51. * サブメニューエレメント
  52. *
  53. * @var array
  54. * @access public
  55. */
  56. var $subMenuElements = array();
  57. /**
  58. * ヘルパー
  59. * @var array
  60. * @access public
  61. */
  62. var $helpers = array(BC_FORM_HELPER);
  63. /**
  64. * ぱんくずナビ
  65. *
  66. * @var array
  67. * @access public
  68. */
  69. var $crumbs = array(array('name' => 'システム設定', 'url' => array('controller' => 'site_configs', 'action' => 'form')));
  70. /**
  71. * [ADMIN] サイト基本設定
  72. *
  73. * @return void
  74. * @access public
  75. */
  76. function admin_form() {
  77. if(empty($this->data)) {
  78. $this->data = $this->_getSiteConfigData();
  79. }else {
  80. $this->SiteConfig->set($this->data);
  81. if(!$this->SiteConfig->validates()) {
  82. $this->Session->setFlash('入力エラーです。内容を修正してください。');
  83. }else {
  84. $mode = 0;
  85. $smartUrl = false;
  86. $siteUrl = $sslUrl = '';
  87. if(isset($this->data['SiteConfig']['mode'])) {
  88. $mode = $this->data['SiteConfig']['mode'];
  89. }
  90. if(isset($this->data['SiteConfig']['smart_url'])) {
  91. $smartUrl = $this->data['SiteConfig']['smart_url'];
  92. }
  93. if(isset($this->data['SiteConfig']['ssl_url'])) {
  94. $siteUrl = $this->data['SiteConfig']['site_url'];
  95. if(!preg_match('/\/$/', $siteUrl)) {
  96. $siteUrl .= '/';
  97. }
  98. }
  99. if(isset($this->data['SiteConfig']['ssl_url'])) {
  100. $sslUrl = $this->data['SiteConfig']['ssl_url'];
  101. if($sslUrl && !preg_match('/\/$/', $sslUrl)) {
  102. $sslUrl .= '/';
  103. }
  104. }
  105. $adminSsl = $this->data['SiteConfig']['admin_ssl'];
  106. $mobile = $this->data['SiteConfig']['mobile'];
  107. $smartphone = $this->data['SiteConfig']['smartphone'];
  108. unset($this->data['SiteConfig']['id']);
  109. unset($this->data['SiteConfig']['mode']);
  110. unset($this->data['SiteConfig']['smart_url']);
  111. unset($this->data['SiteConfig']['site_url']);
  112. unset($this->data['SiteConfig']['ssl_url']);
  113. unset($this->data['SiteConfig']['admin_ssl']);
  114. unset($this->data['SiteConfig']['mobile']);
  115. unset($this->data['SiteConfig']['smartphone']);
  116. // DBに保存
  117. if($this->SiteConfig->saveKeyValue($this->data)) {
  118. $this->Session->setFlash('システム設定を保存しました。');
  119. // 環境設定を保存
  120. $this->writeInstallSetting('debug', $mode);
  121. $this->writeInstallSetting('BcEnv.siteUrl', "'".$siteUrl."'");
  122. $this->writeInstallSetting('BcEnv.sslUrl', "'".$sslUrl."'");
  123. $this->writeInstallSetting('BcApp.adminSsl', ($adminSsl)? 'true' : 'false');
  124. $this->writeInstallSetting('BcApp.mobile', ($mobile)? 'true' : 'false');
  125. $this->writeInstallSetting('BcApp.smartphone', ($smartphone)? 'true' : 'false');
  126. if($this->readSmartUrl() != $smartUrl) {
  127. $this->writeSmartUrl($smartUrl);
  128. }
  129. // キャッシュをクリア
  130. if($this->siteConfigs['maintenance'] ||
  131. ($this->siteConfigs['google_analytics_id'] != $this->data['SiteConfig']['google_analytics_id'])){
  132. clearViewCache();
  133. }
  134. // リダイレクト
  135. if($this->readSmartUrl() != $smartUrl) {
  136. $adminPrefix = Configure::read('Routing.admin');
  137. if($smartUrl){
  138. $redirectUrl = $this->getRewriteBase('/'.$adminPrefix.'/site_configs/form');
  139. }else{
  140. $redirectUrl = $this->getRewriteBase('/index.php/'.$adminPrefix.'/site_configs/form');
  141. }
  142. header('Location: '.FULL_BASE_URL.$redirectUrl);
  143. exit();
  144. }else{
  145. $this->redirect(array('action' => 'form'));
  146. }
  147. }
  148. }
  149. }
  150. /* スマートURL関連 */
  151. $apachegetmodules = function_exists('apache_get_modules');
  152. if($apachegetmodules) {
  153. $rewriteInstalled = in_array('mod_rewrite',apache_get_modules());
  154. }else {
  155. $rewriteInstalled = -1;
  156. }
  157. $writableInstall = is_writable(CONFIGS.'install.php');
  158. if(BC_DEPLOY_PATTERN != 3) {
  159. $htaccess1 = ROOT.DS.'.htaccess';
  160. } else {
  161. $htaccess1 = docRoot().DS.'.htaccess';
  162. }
  163. $htaccess2 = WWW_ROOT.'.htaccess';
  164. $writableHtaccess = is_writable($htaccess1);
  165. if($htaccess1 != $htaccess2) {
  166. $writableHtaccess2 = is_writable($htaccess2);
  167. } else{
  168. $writableHtaccess2 = true;
  169. }
  170. $baseUrl = str_replace('/index.php', '', BC_BASE_URL);
  171. if($writableInstall && $writableHtaccess && $writableHtaccess2 && $rewriteInstalled !== false){
  172. $smartUrlChangeable = true;
  173. } else {
  174. $smartUrlChangeable = false;
  175. }
  176. $UserGroup = ClassRegistry::init('UserGroup');
  177. $userGroups = $UserGroup->find('list', array('fields' => array('UserGroup.id', 'UserGroup.title')));
  178. $this->set('userGroups', $userGroups);
  179. $this->set('rewriteInstalled', $rewriteInstalled);
  180. $this->set('writableInstall', $writableInstall);
  181. $this->set('writableHtaccess', $writableHtaccess);
  182. $this->set('writableHtaccess2', $writableHtaccess2);
  183. $this->set('baseUrl', $baseUrl);
  184. $this->set('smartUrlChangeable', $smartUrlChangeable);
  185. $this->subMenuElements = array('site_configs');
  186. $this->pageTitle = 'サイト基本設定';
  187. $this->help = 'site_configs_form';
  188. }
  189. /**
  190. * キャッシュファイルを全て削除する
  191. *
  192. * @return void
  193. * @access public
  194. */
  195. function admin_del_cache() {
  196. clearAllCache();
  197. $this->Session->setFlash('サーバーキャッシュを削除しました。');
  198. $this->redirect(array('action' => 'form'));
  199. }
  200. /**
  201. * [ADMIN] PHPINFOを表示する
  202. *
  203. * @return void
  204. * @access public
  205. */
  206. function admin_info() {
  207. if(!empty($this->siteConfigs['demo_on'])) {
  208. $this->notFound();
  209. }
  210. $this->pageTitle = '環境情報';
  211. $drivers = array('csv'=>'CSV','sqlite3'=>'SQLite3','mysql'=>'MySQL','postgres'=>'PostgreSQL');
  212. $smartUrl = 'ON';
  213. $db =& ConnectionManager::getDataSource('baser');
  214. if(Configure::read('App.baseUrl')){
  215. $smartUrl = 'OFF';
  216. }
  217. $driver = preg_replace('/^bc_/', '', $db->config['driver']);
  218. $this->set('driver',$drivers[$driver]);
  219. $this->set('smartUrl',$smartUrl);
  220. $this->set('baserVersion',$this->siteConfigs['version']);
  221. $this->set('cakeVersion',$this->getCakeVersion());
  222. $this->subMenuElements = array('site_configs');
  223. }
  224. /**
  225. * [ADMIN] PHP INFO
  226. *
  227. * @return void
  228. * @access public
  229. */
  230. function admin_phpinfo() {
  231. $this->layout = 'empty';
  232. }
  233. /**
  234. * サイト基本設定データを取得する
  235. *
  236. * @return void
  237. * @access protected
  238. */
  239. function _getSiteConfigData() {
  240. $data['SiteConfig'] = $this->siteConfigs;
  241. $data['SiteConfig']['mode'] = Configure::read('debug');
  242. $data['SiteConfig']['smart_url'] = $this->readSmartUrl();
  243. $data['SiteConfig']['site_url'] = Configure::read('BcEnv.siteUrl');
  244. $data['SiteConfig']['ssl_url'] = Configure::read('BcEnv.sslUrl');
  245. $data['SiteConfig']['admin_ssl'] = Configure::read('BcApp.adminSsl');
  246. $data['SiteConfig']['mobile'] = Configure::read('BcApp.mobile');
  247. $data['SiteConfig']['smartphone'] = Configure::read('BcApp.smartphone');
  248. if(is_null($data['SiteConfig']['mobile'])) {
  249. $data['SiteConfig']['mobile'] = false;
  250. }
  251. return $data;
  252. }
  253. }
  254. ?>