PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/baser/config/routes.php

https://github.com/hashing/basercms
PHP | 209 lines | 120 code | 4 blank | 85 comment | 33 complexity | 812cf2ca76d37e2ad42a63f371440f5c MD5 | raw file
Possible License(s): MIT
  1. <?php
  2. /* SVN FILE: $Id$ */
  3. /**
  4. * ルーティング定義
  5. *
  6. * PHP versions 4 and 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.config
  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. * vendors内の静的ファイルの読み込みの場合はスキップ
  22. */
  23. if(Configure::read('BcRequest.asset')) {
  24. return;
  25. }
  26. if(BC_INSTALLED && !Configure::read('BcRequest.isUpdater') && !Configure::read('BcRequest.isMaintenance')) {
  27. $parameter = getUrlParamFromEnv();
  28. Configure::write('BcRequest.pureUrl', $parameter); // requestAction の場合、bootstrapが実行されないので、urlParamを書き換える
  29. $agent = Configure::read('BcRequest.agent');
  30. $agentAlias = Configure::read('BcRequest.agentAlias');
  31. $agentPrefix = Configure::read('BcRequest.agentPrefix');
  32. $authPrefixes = Configure::read('BcAuthPrefix');
  33. $pluginMatch = array();
  34. $plugins = Configure::listObjects('plugin');
  35. if($plugins) {
  36. foreach ($plugins as $key => $value) {
  37. $plugins[$key] = Inflector::underscore($value);
  38. }
  39. $pluginMatch = array('plugin' => implode('|', $plugins));
  40. }
  41. /**
  42. * プラグイン判定 & プラグイン名の書き換え
  43. *
  44. * DBに登録したデータを元にURLのプラグイン名部分を書き換える。
  45. * 一つのプラグインで二つのコンテンツを設置した場合に利用する。
  46. * あらかじめ、plugin_contentsテーブルに、URLに使う名前とコンテンツを特定する。
  47. * プラグインごとの一意のキー[content_id]を保存しておく。
  48. *
  49. * content_idをコントローラーで取得するには、$plugins_controllerのcontentIdプロパティを利用する。
  50. * Router::connectの引数として値を与えると、$html->linkなどで、
  51. * Routerを利用する際にマッチしなくなりURLがデフォルトのプラグイン名となるので注意
  52. */
  53. $PluginContent = ClassRegistry::init('PluginContent');
  54. if($PluginContent) {
  55. $pluginContent = $PluginContent->currentPluginContent($parameter);
  56. if($pluginContent) {
  57. $pluginContentName = $pluginContent['PluginContent']['name'];
  58. $pluginName = $pluginContent['PluginContent']['plugin'];
  59. if(!$agent) {
  60. Router::connect("/{$pluginContentName}/:action/*", array('plugin' => $pluginName, 'controller'=> $pluginName));
  61. }else {
  62. Router::connect("/{$agentAlias}/{$pluginContentName}/:action/*", array('prefix' => $agentPrefix, 'plugin' => $pluginName, 'controller'=> $pluginName));
  63. }
  64. }
  65. }
  66. /**
  67. * 認証プレフィックス
  68. */
  69. if($authPrefixes && is_array($authPrefixes)) {
  70. foreach($authPrefixes as $key => $authPrefix) {
  71. if(empty($authPrefix['prefix'])) {
  72. continue;
  73. }
  74. $prefix = $authPrefix['prefix'];
  75. if(!empty($authPrefix['alias'])) {
  76. $alias = $authPrefix['alias'];
  77. } else {
  78. $alias = $prefix;
  79. }
  80. Router::connect("/{$alias}", array('prefix' => $prefix, $prefix => true, 'controller' => 'dashboard', 'action'=> 'index'));
  81. Router::connect("/{$alias}/:plugin/:controller", array('prefix' => $prefix, $prefix => true), $pluginMatch);
  82. Router::connect("/{$alias}/:plugin/:controller/:action/*", array('prefix' => $prefix, $prefix => true), $pluginMatch);
  83. Router::connect("/{$alias}/:plugin/:action/*", array('prefix' => $prefix, $prefix => true), $pluginMatch);
  84. Router::connect("/{$alias}/:controller/:action/*", array('prefix' => $prefix, $prefix => true));
  85. }
  86. }
  87. /**
  88. * ページ機能拡張
  89. * cakephp の ページ機能を利用する際、/pages/xxx とURLである必要があるが
  90. * それを /xxx で呼び出す為のルーティング
  91. */
  92. $adminPrefix = Configure::read('Routing.admin');
  93. if(!preg_match("/^{$adminPrefix}/", $parameter)){
  94. /* 1.5.10 以降 */
  95. $Page = ClassRegistry::init('Page');
  96. if($Page){
  97. if(!$parameter){
  98. $_parameters = array('index');
  99. }elseif(preg_match('/\/$/is', $parameter)) {
  100. $_parameters = array(urldecode($parameter.'index'));
  101. }else{
  102. $_parameters = array(urldecode($parameter),urldecode($parameter).'/index');
  103. }
  104. foreach ($_parameters as $_parameter){
  105. if(!$agent){
  106. $url = "/{$_parameter}";
  107. }else{
  108. $url = "/{$agentPrefix}/{$_parameter}";
  109. }
  110. if($Page->isPageUrl($url) && $Page->checkPublish($url)){
  111. if(!$agent){
  112. Router::connect("/{$parameter}", am(array('controller' => 'pages', 'action' => 'display'),split('/',$_parameter)));
  113. }else{
  114. Router::connect("/{$agentAlias}/{$parameter}", am(array('prefix' => $agentPrefix, 'controller' => 'pages', 'action' => 'display'),split('/',$_parameter)));
  115. }
  116. break;
  117. } else {
  118. if(preg_match('/^(.+?)\.html$/', $url, $matches)) {
  119. $url = $matches[1];
  120. if($Page->isPageUrl($url) && $Page->checkPublish($url)){
  121. $_parameter = str_replace('.html', '', $_parameter);
  122. if(!$agent){
  123. Router::connect("/{$parameter}", am(array('controller' => 'pages', 'action' => 'display'), $_parameter));
  124. }else{
  125. Router::connect("/{$agentAlias}/{$parameter}", am(array('prefix' => $agentPrefix, 'controller' => 'pages', 'action' => 'display'),split('/',$_parameter)));
  126. }
  127. break;
  128. }
  129. }
  130. }
  131. }
  132. }
  133. }
  134. /**
  135. * 携帯標準ルーティング
  136. */
  137. if($agent) {
  138. // プラグイン
  139. Router::connect("/{$agentAlias}/:plugin/:controller/:action/*", array('prefix' => $agentPrefix), $pluginMatch);
  140. Router::connect("/{$agentAlias}/:plugin/:action/*", array('prefix' => $agentPrefix), $pluginMatch);
  141. // 携帯ノーマル
  142. Router::connect("/{$agentAlias}/:controller/:action/*", array('prefix' => $agentPrefix));
  143. }
  144. /**
  145. * ユニットテスト
  146. */
  147. Router::connect('/tests', array('controller' => 'tests', 'action' => 'index'));
  148. /**
  149. * フィード出力
  150. * 拡張子rssの場合は、rssディレクトリ内のビューを利用する
  151. */
  152. Router::parseExtensions('rss');
  153. }
  154. else {
  155. Router::connect('/', array('controller' => 'installations', 'action' => 'index'));
  156. }
  157. /**
  158. * インストーラー用
  159. */
  160. Router::connect('/install', array('controller' => 'installations', 'action' => 'index'));
  161. /**
  162. * エラーハンドラ読み込み
  163. * baserフォルダ内のAppErrorを読みこませる為に定義
  164. * bootstrapに記述するとAppControllerの未定義エラーとなる為仕方なくここに配置
  165. * また、controllerに記述するとAppControllerの重複定義となってしまう
  166. */
  167. if (file_exists(APP . 'error.php')) {
  168. include_once (APP . 'error.php');
  169. } elseif (file_exists(APP . 'app_error.php')) {
  170. include_once (APP . 'app_error.php');
  171. } elseif (file_exists(BASER . 'app_error.php')) {
  172. include_once (BASER . 'app_error.php');
  173. }
  174. if(BC_INSTALLED && !Configure::read('BcRequest.isUpdater') && !Configure::read('BcRequest.isMaintenance')) {
  175. /**
  176. * プラグインの bootstrap を実行する
  177. * bootstrapではプラグインのパスが読み込めない為ここに定義
  178. * TODO CakePHP 1.3にアップしたら、App::buildでのパス設定にし、bootstrapに定義する
  179. */
  180. $enablePlugins = getEnablePlugins();
  181. Configure::write('BcStatus.enablePlugins', $enablePlugins);
  182. $_pluginPaths = array(
  183. APP.'plugins'.DS,
  184. BASER_PLUGINS
  185. );
  186. foreach($enablePlugins as $enablePlugin) {
  187. foreach($_pluginPaths as $_pluginPath) {
  188. $pluginBootstrap = $_pluginPath.$enablePlugin.DS.'config'.DS.'bootstrap.php';
  189. if(file_exists($pluginBootstrap)) {
  190. include $pluginBootstrap;
  191. }
  192. }
  193. }
  194. /**
  195. * テーマの bootstrap を実行する
  196. * bootstrapではプラグインのパスが読み込めない為ここに定義
  197. * TODO CakePHP 1.3にアップしたら、App::buildでのパス設定にし、bootstrapに定義す
  198. */
  199. $themePath = WWW_ROOT.'themed'.DS.Configure::read('BcSite.theme').DS;
  200. $themeBootstrap = $themePath.'config'.DS.'bootstrap.php';
  201. if(file_exists($themeBootstrap)) {
  202. include $themeBootstrap;
  203. }
  204. }
  205. ?>