PageRenderTime 33ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/baser/views/helpers/bc_app_helper.php

https://github.com/hashing/basercms
PHP | 252 lines | 171 code | 7 blank | 74 comment | 15 complexity | 37144655412021038f28c4cb53955772 MD5 | raw file
Possible License(s): MIT
  1. <?php
  2. /* SVN FILE: $Id: baser_app_helper.php 143 2011-08-26 06:11:39Z ryuring $ */
  3. /**
  4. * Helper 拡張クラス
  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.view.helpers
  14. * @since baserCMS v 0.1.0
  15. * @version $Revision: 143 $
  16. * @modifiedby $LastChangedBy: ryuring $
  17. * @lastmodified $Date: 2011-08-26 15:11:39 +0900 (金, 26 8 2011) $
  18. * @license http://basercms.net/license/index.html
  19. */
  20. /**
  21. * Helper 拡張クラス
  22. *
  23. * @package baser.view.helpers
  24. */
  25. class BcAppHelper extends Helper {
  26. /**
  27. * view
  28. * キャッシュ用
  29. * @var View
  30. */
  31. var $_view = null;
  32. /**
  33. * html tags used by this helper.
  34. *
  35. * @var array
  36. * @access public
  37. */
  38. var $tags = array(
  39. 'meta' => '<meta%s/>',
  40. 'metalink' => '<link href="%s"%s/>',
  41. 'link' => '<a href="%s"%s>%s</a>',
  42. 'mailto' => '<a href="mailto:%s" %s>%s</a>',
  43. 'form' => '<form %s>',
  44. 'formend' => '</form>',
  45. 'input' => '<input name="%s" %s/>',
  46. 'textarea' => '<textarea name="%s" %s>%s</textarea>',
  47. 'hidden' => '<input type="hidden" name="%s" %s/>',
  48. 'checkbox' => '<input type="checkbox" name="%s" %s/>',
  49. 'checkboxmultiple' => '<input type="checkbox" name="%s[]"%s />',
  50. 'radio' => '<input type="radio" name="%s" id="%s" %s />%s',
  51. 'selectstart' => '<select name="%s"%s>',
  52. 'selectmultiplestart' => '<select name="%s[]"%s>',
  53. 'selectempty' => '<option value=""%s>&nbsp;</option>',
  54. 'selectoption' => '<option value="%s"%s>%s</option>',
  55. 'selectend' => '</select>',
  56. 'optiongroup' => '<optgroup label="%s"%s>',
  57. 'optiongroupend' => '</optgroup>',
  58. 'checkboxmultiplestart' => '',
  59. 'checkboxmultipleend' => '',
  60. 'password' => '<input type="password" name="%s" %s/>',
  61. 'file' => '<input type="file" name="%s" %s/>',
  62. 'file_no_model' => '<input type="file" name="%s" %s/>',
  63. 'submit' => '<input type="submit" %s/>',
  64. 'submitimage' => '<input type="image" src="%s" %s/>',
  65. 'button' => '<input type="%s" %s/>',
  66. 'image' => '<img src="%s" %s/>',
  67. 'tableheader' => '<th%s>%s</th>',
  68. 'tableheaderrow' => '<tr%s>%s</tr>',
  69. 'tablecell' => '<td%s>%s</td>',
  70. 'tablerow' => '<tr%s>%s</tr>',
  71. 'block' => '<div%s>%s</div>',
  72. 'blockstart' => '<div%s>',
  73. 'blockend' => '</div>',
  74. 'tag' => '<%s%s>%s</%s>',
  75. 'tagstart' => '<%s%s>',
  76. 'tagend' => '</%s>',
  77. 'para' => '<p%s>%s</p>',
  78. 'parastart' => '<p%s>',
  79. 'label' => '<label for="%s"%s>%s</label>',
  80. 'fieldset' => '<fieldset%s>%s</fieldset>',
  81. 'fieldsetstart' => '<fieldset><legend>%s</legend>',
  82. 'fieldsetend' => '</fieldset>',
  83. 'legend' => '<legend>%s</legend>',
  84. 'css' => '<link rel="%s" type="text/css" href="%s" %s/>',
  85. 'style' => '<style type="text/css"%s>%s</style>',
  86. 'charset' => '<meta http-equiv="Content-Type" content="text/html; charset=%s" />',
  87. 'ul' => '<ul%s>%s</ul>',
  88. 'ol' => '<ol%s>%s</ol>',
  89. 'li' => '<li%s>%s</li>',
  90. 'error' => '<div%s>%s</div>'
  91. );
  92. /**
  93. * Constructor.
  94. *
  95. * @return void
  96. * @access private
  97. */
  98. function __construct() {
  99. parent::__construct();
  100. $this->tags['checkboxmultiple'] = '<input type="checkbox" name="%s[]"%s />&nbsp;';
  101. $this->tags['hiddenmultiple'] = '<input type="hidden" name="%s[]" %s />';
  102. }
  103. /**
  104. * Checks if a file exists when theme is used, if no file is found default location is returned
  105. *
  106. * PENDING Core Hack
  107. *
  108. * @param string $file
  109. * @return string $webPath web path to file.
  110. */
  111. function webroot($file) {
  112. // CUSTOMIZE ADD 2010/05/19 ryuring
  113. // CakePHP1.2.6以降、Rewriteモジュールを利用せず、App.baseUrlを利用した場合、
  114. // Dispatcherでwebrootが正常に取得できなくなってしまったので、ここで再設定する
  115. // CUSTOMIZE MODIFY 2011/03/17 ryuring
  116. // BC_DEPLOY_PATTERN 2 について対応
  117. // >>>
  118. $dir = Configure::read('App.dir');
  119. $webroot = Configure::read('App.webroot');
  120. $baseUrl = Configure::read('App.baseUrl');
  121. if($baseUrl) {
  122. switch (BC_DEPLOY_PATTERN) {
  123. case 1:
  124. if (strpos($this->webroot, $dir) === false) {
  125. $this->webroot .= $dir . '/' ;
  126. }
  127. if (strpos($this->webroot, $webroot) === false) {
  128. $this->webroot .= $webroot . '/';
  129. }
  130. break;
  131. case 2:
  132. $baseDir = str_replace('index.php', '', $baseUrl);
  133. $this->webroot = $baseDir;
  134. break;
  135. }
  136. }
  137. //<<<
  138. // CUSTOMIZE MODIFY 2009/10/6 ryuring
  139. // Rewriteモジュールが利用できない場合、$html->css / $javascript->link では、
  140. // app/webroot/を付加してURLを生成してしまう為、vendors 内のパス解決ができない。
  141. // URLの取得方法をRouterに変更
  142. // Dispatcherクラスのハックが必須
  143. //
  144. // CUSTOMIZE MODIFY 2010/02/12 ryuring
  145. // ファイルの存在チェックを行い存在しない場合のみRouterを利用するように変更した。
  146. //
  147. // CUSTOMIZE MODIFY 2011/04/11 ryuring
  148. // Rewriteモジュールが利用できない場合、画像等で出力されるURL形式(/app/webroot/img/...)が
  149. // $file に設定された場合でもパス解決ができるようにした。
  150. //
  151. // >>>
  152. // $webPath = "{$this->webroot}" . $file;
  153. // ---
  154. $filePath = str_replace('/', DS, $file);
  155. $docRoot = docRoot();
  156. if(file_exists(WWW_ROOT . $filePath)) {
  157. $webPath = $this->webroot.$file;
  158. } elseif(file_exists($docRoot.DS.$filePath) && strpos($docRoot.DS.$filePath, ROOT.DS) !== false) {
  159. // ※ ファイルのパスが ROOT 配下にある事が前提
  160. $webPath = $file;
  161. } else {
  162. $webPath = Router::url('/'.$file);
  163. }
  164. // <<<
  165. if (!empty($this->themeWeb)) {
  166. $os = env('OS');
  167. if (!empty($os) && strpos($os, 'Windows') !== false) {
  168. if (strpos(WWW_ROOT . $this->themeWeb . $filePath, '\\') !== false) {
  169. $path = str_replace('/', '\\', WWW_ROOT . $this->themeWeb . $filePath);
  170. }
  171. } else {
  172. $path = WWW_ROOT . $this->themeWeb . $filePath;
  173. }
  174. if (file_exists($path)) {
  175. $webPath = "{$this->webroot}" . $this->themeWeb . $file;
  176. }
  177. }
  178. if (strpos($webPath, '//') !== false) {
  179. return str_replace('//', '/', $webPath);
  180. }
  181. // >>> CUSTOMIZE ADD 2010/02/12 ryuring
  182. if (strpos($webPath, '\\') !== false) {
  183. $webPath = str_replace("\\",'/',$webPath);
  184. }
  185. // <<<
  186. return $webPath;
  187. }
  188. /**
  189. * フック処理を実行する
  190. *
  191. * @param string $hook
  192. * @return mixed
  193. */
  194. function executeHook($hook) {
  195. if(!$this->_view){
  196. $this->_view =& ClassRegistry::getObject('View');
  197. }
  198. $args = func_get_args();
  199. $args[0] =& $this;
  200. return call_user_func_array(array(&$this->_view->loaded['bcPluginHook'], $hook), $args);
  201. }
  202. /**
  203. * Finds URL for specified action.
  204. *
  205. * Returns an URL pointing to a combination of controller and action. Param
  206. * $url can be:
  207. * + Empty - the method will find adress to actuall controller/action.
  208. * + '/' - the method will find base URL of application.
  209. * + A combination of controller/action - the method will find url for it.
  210. *
  211. * @param mixed $url Cake-relative URL, like "/products/edit/92" or "/presidents/elect/4"
  212. * or an array specifying any of the following: 'controller', 'action',
  213. * and/or 'plugin', in addition to named arguments (keyed array elements),
  214. * and standard URL arguments (indexed array elements)
  215. * @param boolean $full If true, the full base URL will be prepended to the result
  216. * @return string Full translated URL with base path.
  217. */
  218. function url($url = null, $full = false) {
  219. $url = addSessionId($url);
  220. //======================================================================
  221. // FormHelper::createで id をキーとして使うので、ルーターでマッチしない場合がある。
  222. // id というキー名を除外する事で対応。
  223. //======================================================================
  224. if(is_array($url) && isset($url['id'])) {
  225. array_push($url, $url['id']);
  226. unset($url['id']);
  227. }
  228. if (!isset($url['admin']) && !empty($this->params['admin'])) {
  229. $url['admin'] = true;
  230. } elseif (isset($url['admin']) && !$url['admin']) {
  231. unset($url['admin']);
  232. }
  233. return parent::url($url, $full);
  234. }
  235. }
  236. ?>