PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/baser/views/helpers/bc_page.php

https://github.com/hashing/basercms
PHP | 295 lines | 144 code | 34 blank | 117 comment | 32 complexity | f76268ed0dbb12771cce1dcd5aee8c9d 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.view.helpers
  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. * ページヘルパー
  22. *
  23. * @packa ge baser.views.helpers
  24. */
  25. class BcPageHelper extends Helper {
  26. /**
  27. * ページモデル
  28. *
  29. * @var Page
  30. * @access public
  31. */
  32. var $Page = null;
  33. /**
  34. * data
  35. * @var array
  36. * @access public
  37. */
  38. var $data = array();
  39. /**
  40. * ヘルパー
  41. *
  42. * @var array
  43. * @access public
  44. */
  45. var $helpers = array(BC_BASER_HELPER);
  46. /**
  47. * construct
  48. *
  49. * @return void
  50. * @access public
  51. */
  52. function __construct() {
  53. if(ClassRegistry::isKeySet('Page')) {
  54. $this->Page = ClassRegistry::getObject('Page');
  55. }else {
  56. $this->Page =& ClassRegistry::init('Page','Model');
  57. }
  58. }
  59. /**
  60. * beforeRender
  61. *
  62. * @return void
  63. * @access public
  64. */
  65. function beforeRender() {
  66. if(isset($this->params['pass'][0])) {
  67. // TODO ページ機能が.html拡張子なしに統合できたらコメントアウトされたものに切り替える
  68. //$this->data = $this->Page->findByUrl('/'.impload('/',$this->params['pass'][0]));
  69. $param = Configure::read('BcRequest.pureUrl');
  70. if($param && preg_match('/\/$/is',$param)){
  71. $param .= 'index';
  72. }
  73. if(Configure::read('BcRequest.agent')) {
  74. $param = Configure::read('BcRequest.agentPrefix').'/'.$param;
  75. }
  76. $this->data = $this->Page->findByUrl('/'.$param);
  77. }
  78. }
  79. /**
  80. * ページ機能用URLを取得する
  81. *
  82. * @param array $page
  83. * @return string
  84. */
  85. function url($page) {
  86. return $this->Page->getPageUrl($page);
  87. }
  88. /**
  89. * 現在のページが所属するカテゴリデータを取得する
  90. *
  91. * @return array
  92. * @access public
  93. */
  94. function getCategory() {
  95. if(!empty($this->data['PageCategory']['id'])) {
  96. return $this->data['PageCategory'];
  97. }else {
  98. return false;
  99. }
  100. }
  101. /**
  102. * 現在のページが所属する親のカテゴリを取得する
  103. *
  104. * @param boolean $top
  105. * @return array
  106. * @access public
  107. */
  108. function getParentCategory($top = false) {
  109. $category = $this->getCategory();
  110. if(empty($category['id'])) {
  111. return false;
  112. }
  113. if($top) {
  114. $path = $this->Page->PageCategory->getpath($category['id']);
  115. if($path) {
  116. $parent = $path[0];
  117. } else {
  118. return false;
  119. }
  120. } else {
  121. $parent = $this->Page->PageCategory->getparentnode($category['id']);
  122. }
  123. return $parent;
  124. }
  125. /**
  126. * ページリストを取得する
  127. *
  128. * @param int $pageCategoryId
  129. * @param int $recursive
  130. * @return array
  131. * @access public
  132. */
  133. function getPageList($pageCategoryId, $recursive = null) {
  134. return $this->requestAction('/contents/get_page_list_recursive', array('pass' => array($pageCategoryId, $recursive)));
  135. }
  136. /**
  137. * カテゴリ名を取得する
  138. *
  139. * @return mixed string / false
  140. * @access public
  141. */
  142. function getCategoryName(){
  143. $category = $this->getCategory();
  144. if($category['name']) {
  145. return $category['name'];
  146. } else {
  147. return false;
  148. }
  149. }
  150. /**
  151. * 公開状態を取得する
  152. *
  153. * @param array データリスト
  154. * @return boolean 公開状態
  155. * @access public
  156. */
  157. function allowPublish($data){
  158. if(isset($data['Page'])){
  159. $data = $data['Page'];
  160. }
  161. $allowPublish = (int)$data['status'];
  162. // 期限を設定している場合に条件に該当しない場合は強制的に非公開とする
  163. if(($data['publish_begin'] != 0 && $data['publish_begin'] >= date('Y-m-d H:i:s')) ||
  164. ($data['publish_end'] != 0 && $data['publish_end'] <= date('Y-m-d H:i:s'))){
  165. $allowPublish = false;
  166. }
  167. return $allowPublish;
  168. }
  169. /**
  170. * ページカテゴリ間の次の記事へのリンクを取得する
  171. *
  172. * @param array $post
  173. * @param string $title
  174. * @param array $attributes
  175. */
  176. function nextLink($title='', $attributes = array()) {
  177. if(!$this->contensNaviAvailable()) {
  178. return '';
  179. }
  180. if(ClassRegistry::isKeySet('Page')) {
  181. $PageClass =& ClassRegistry::getObject('Page');
  182. } else {
  183. $PageClass =& ClassRegistry::init('Page');
  184. }
  185. $_attributes = array('class'=>'next-link','arrow'=>' ≫');
  186. $attributes = am($_attributes,$attributes);
  187. $arrow = $attributes['arrow'];
  188. unset($attributes['arrow']);
  189. $conditions = am(array(
  190. 'Page.sort >' => $this->data['Page']['sort'],
  191. 'Page.page_category_id' => $this->data['Page']['page_category_id']
  192. ), $PageClass->getConditionAllowPublish());
  193. $nextPost = $PageClass->find('first', array(
  194. 'conditions'=> $conditions,
  195. 'fields' => array('title', 'url'),
  196. 'order' => 'sort',
  197. 'recursive' => -1,
  198. 'cache' => false
  199. ));
  200. if($nextPost) {
  201. if(!$title) {
  202. $title = $nextPost['Page']['title'].$arrow;
  203. }
  204. $this->BcBaser->link($title, preg_replace('/^\/mobile/', '/m', $nextPost['Page']['url']), $attributes);
  205. }
  206. }
  207. /**
  208. * ページカテゴリ間の前の記事へのリンクを取得する
  209. *
  210. * @param array $post
  211. * @param string $title
  212. * @param array $attributes
  213. * @return void
  214. * @access public
  215. */
  216. function prevLink($title='', $attributes = array()) {
  217. if(!$this->contensNaviAvailable()) {
  218. return '';
  219. }
  220. if(ClassRegistry::isKeySet('Page')) {
  221. $PageClass =& ClassRegistry::getObject('Page');
  222. } else {
  223. $PageClass =& ClassRegistry::init('Page');
  224. }
  225. $_attributes = array('class'=>'prev-link','arrow'=>'≪ ');
  226. $attributes = am($_attributes,$attributes);
  227. $arrow = $attributes['arrow'];
  228. unset($attributes['arrow']);
  229. $conditions = am(array(
  230. 'Page.sort <' => $this->data['Page']['sort'],
  231. 'Page.page_category_id' => $this->data['Page']['page_category_id']
  232. ), $PageClass->getConditionAllowPublish());
  233. $nextPost = $PageClass->find('first', array(
  234. 'conditions'=> $conditions,
  235. 'fields' => array('title', 'url'),
  236. 'order' => 'sort DESC',
  237. 'recursive' => -1,
  238. 'cache' => false
  239. ));
  240. if($nextPost) {
  241. if(!$title) {
  242. $title = $arrow.$nextPost['Page']['title'];
  243. }
  244. $this->BcBaser->link($title, preg_replace('/^\/mobile/', '/m', $nextPost['Page']['url']), $attributes);
  245. }
  246. }
  247. /**
  248. * コンテンツナビ有効チェック
  249. *
  250. * @return boolean
  251. * @access public
  252. */
  253. function contensNaviAvailable() {
  254. if(empty($this->data['Page']['page_category_id']) || empty($this->data['PageCategory']['contents_navi'])) {
  255. return false;
  256. } else {
  257. return true;
  258. }
  259. }
  260. }
  261. ?>