PageRenderTime 47ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/baser/plugins/blog/controllers/blog_controller.php

https://github.com/hashing/basercms
PHP | 914 lines | 531 code | 120 blank | 263 comment | 90 complexity | 976c85d9b99599b94793e41586bd4c96 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.plugins.blog.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.plugins.blog.controllers
  27. */
  28. class BlogController extends BlogAppController {
  29. /**
  30. * クラス名
  31. *
  32. * @var string
  33. * @access public
  34. */
  35. var $name = 'Blog';
  36. /**
  37. * モデル
  38. *
  39. * @var array
  40. * @access public
  41. */
  42. var $uses = array('Blog.BlogCategory', 'Blog.BlogPost', 'Blog.BlogContent');
  43. /**
  44. * ヘルパー
  45. *
  46. * @var array
  47. * @access public
  48. */
  49. var $helpers = array(BC_TEXT_HELPER, BC_TIME_HELPER, BC_FREEZE_HELPER, BC_ARRAY_HELPER, 'Paginator', 'Blog.Blog', 'Cache');
  50. /**
  51. * コンポーネント
  52. *
  53. * @var array
  54. * @access public
  55. */
  56. var $components = array('BcAuth', 'Cookie', 'BcAuthConfigure', 'RequestHandler', 'BcEmail', 'Security');
  57. /**
  58. * ぱんくずナビ
  59. *
  60. * @var array
  61. * @access public
  62. */
  63. var $crumbs = array();
  64. /**
  65. * サブメニューエレメント
  66. *
  67. * @var array
  68. * @access public
  69. */
  70. var $subMenuElements = array();
  71. /**
  72. * ブログデータ
  73. *
  74. * @var array
  75. * @access public
  76. */
  77. var $blogContent = array();
  78. /**
  79. * プレビューフラグ
  80. *
  81. * @var boolean
  82. * @access public
  83. */
  84. var $preview = false;
  85. /**
  86. * beforeFilter
  87. *
  88. * @return void
  89. * @access public
  90. */
  91. function beforeFilter() {
  92. parent::beforeFilter();
  93. /* 認証設定 */
  94. $this->BcAuth->allow(
  95. 'index', 'mobile_index', 'smartphone_index',
  96. 'archives', 'mobile_archives', 'smartphone_archives',
  97. 'posts', 'mobile_posts', 'smartphone_posts',
  98. 'get_calendar', 'get_categories', 'get_posted_months', 'get_posted_years', 'get_recent_entries'
  99. );
  100. $this->BlogContent->recursive = -1;
  101. if($this->contentId) {
  102. $this->blogContent = $this->BlogContent->read(null,$this->contentId);
  103. }else {
  104. $this->blogContent = $this->BlogContent->read(null,$this->params['pass'][0]);
  105. }
  106. $this->subMenuElements = array('default');
  107. $this->crumbs = array(array('name' => $this->blogContent['BlogContent']['title'], 'url' => '/'.$this->blogContent['BlogContent']['name'].'/index'));
  108. // ページネーションのリンク対策
  109. // コンテンツ名を変更している際、以下の設定を行わないとプラグイン名がURLに付加されてしまう
  110. // Viewで $paginator->options = array('url' => $this->passedArgs) を行う事が前提
  111. if(!isset($this->params['admin'])) {
  112. $this->passedArgs['controller'] = $this->blogContent['BlogContent']['name'];
  113. $this->passedArgs['plugin'] = $this->blogContent['BlogContent']['name'];
  114. $this->passedArgs['action'] = $this->action;
  115. }
  116. // コメント送信用のトークンを出力する為にセキュリティコンポーネントを利用しているが、
  117. // 表示用のコントローラーなのでポストデータのチェックは必要ない
  118. $this->Security->enabled = true;
  119. $this->Security->validatePost = false;
  120. }
  121. /**
  122. * beforeRender
  123. *
  124. * @return void
  125. * @access public
  126. */
  127. function beforeRender() {
  128. parent::beforeRender();
  129. $this->set('blogContent',$this->blogContent);
  130. if($this->blogContent['BlogContent']['widget_area']){
  131. $this->set('widgetArea',$this->blogContent['BlogContent']['widget_area']);
  132. }
  133. }
  134. /**
  135. * [PUBLIC] ブログを一覧表示する
  136. *
  137. * @return void
  138. * @access public
  139. */
  140. function index() {
  141. if(!$this->blogContent['BlogContent']['status']) {
  142. $this->notFound();
  143. }
  144. if ($this->RequestHandler->isRss()) {
  145. Configure::write('debug', 0);
  146. $this->set('channel', array(
  147. 'title' => h($this->blogContent['BlogContent']['title'].'|'.$this->siteConfigs['name']),
  148. 'description' => h(strip_tags($this->blogContent['BlogContent']['description']))
  149. ));
  150. $this->layout = 'default';
  151. $template = 'index';
  152. $listCount = $this->blogContent['BlogContent']['feed_count'];
  153. }else {
  154. $this->layout = $this->blogContent['BlogContent']['layout'];
  155. $template = $this->blogContent['BlogContent']['template'].DS.'index';
  156. $listCount = $this->blogContent['BlogContent']['list_count'];
  157. }
  158. $datas = $this->_getBlogPosts(array('listCount' => $listCount));
  159. $this->set('editLink', array('admin' => true, 'controller' => 'blog_contents', 'action' => 'edit', $this->blogContent['BlogContent']['id']));
  160. $this->set('posts', $datas);
  161. $this->set('single', false);
  162. $this->subMenuElements = array_merge($this->subMenuElements, array('blog_calendar', 'blog_recent_entries', 'blog_category_archives', 'blog_monthly_archives'));
  163. $this->pageTitle = $this->blogContent['BlogContent']['title'];
  164. $this->crumbs = array();
  165. $this->render($template);
  166. }
  167. /**
  168. * [MOBILE] ブログ記事を一覧表示する
  169. *
  170. * @return void
  171. * @access public
  172. */
  173. function mobile_index() {
  174. $this->setAction('index');
  175. }
  176. /**
  177. * [SMARTPHONE] ブログ記事を一覧表示する
  178. *
  179. * @return void
  180. * @access public
  181. */
  182. function smartphone_index() {
  183. $this->setAction('index');
  184. }
  185. /**
  186. * [PUBLIC] ブログアーカイブを表示する
  187. *
  188. * @param mixed blog_post_id / type
  189. * @param mixed blog_post_id / ""
  190. * @return void
  191. * @access public
  192. */
  193. function archives() {
  194. if(!$this->blogContent['BlogContent']['status']) {
  195. $this->notFound();
  196. }
  197. // パラメーター処理
  198. $pass = $this->params['pass'];
  199. $type = $year = $month = $day = $id = '';
  200. $crumbs = $posts = array();
  201. $single = false;
  202. $posts = array();
  203. if($pass[0] == 'category') {
  204. $type = 'category';
  205. }elseif($pass[0] == 'tag') {
  206. $type = 'tag';
  207. }elseif($pass[0] == 'date') {
  208. $type='date';
  209. }
  210. switch($type) {
  211. /* カテゴリ一覧 */
  212. case 'category':
  213. $category = $pass[count($pass)-1];
  214. if(empty($category)) {
  215. $this->notFound();
  216. }
  217. // 記事を取得
  218. $posts = $this->_getBlogPosts(array('conditions' => array('category' => $category)));
  219. // ナビゲーションを設定
  220. $categoryId = $this->BlogCategory->field('id', array(
  221. 'BlogCategory.blog_content_id' => $this->contentId,
  222. 'BlogCategory.name' => $category
  223. ));
  224. $blogCategories = $this->BlogCategory->getpath($categoryId,array('name','title'));
  225. if(count($blogCategories) > 1){
  226. foreach($blogCategories as $key => $blogCategory) {
  227. if($key < count($blogCategories) -1 ) {
  228. $crumbs[] = array('name' => $blogCategory['BlogCategory']['title'], 'url' => '/'.$this->blogContent['BlogContent']['name'].'/archives/category/'.$blogCategory['BlogCategory']['name']);
  229. }
  230. }
  231. }
  232. $this->pageTitle = $blogCategories[count($blogCategories)-1]['BlogCategory']['title'];
  233. $template = $this->blogContent['BlogContent']['template'].DS.'archives';
  234. break;
  235. /* タグ別記事一覧 */
  236. case 'tag':
  237. $tag = h($pass[count($pass)-1]);
  238. if(empty($this->blogContent['BlogContent']['tag_use']) || empty($tag)) {
  239. $this->notFound();
  240. }
  241. $posts = $this->_getBlogPosts(array('conditions' => array('tag' => $tag)));
  242. $this->pageTitle = urldecode($tag);
  243. $template = $this->blogContent['BlogContent']['template'].DS.'archives';
  244. break;
  245. /* 月別アーカイブ一覧 */
  246. case 'date':
  247. $year = h($pass[1]);
  248. $month = h(@$pass[2]);
  249. $day = h(@$pass[3]);
  250. if(!$year && !$month && !$day) {
  251. $this->notFound();
  252. }
  253. $posts = $this->_getBlogPosts(array('conditions' => array('year' => $year, 'month' => $month, 'day' => $day)));
  254. $this->pageTitle = $year.'年';
  255. if($month) $this->pageTitle .= $month.'月';
  256. if($day) $this->pageTitle .= $day.'日';
  257. $template = $this->blogContent['BlogContent']['template'].DS.'archives';
  258. break;
  259. /* 単ページ */
  260. default:
  261. // プレビュー
  262. if($this->preview) {
  263. $this->contentId = $pass[0];
  264. if(!empty($pass[1])) {
  265. $id = $pass[1];
  266. } elseif(empty($this->data['BlogPost'])) {
  267. $this->notFound();
  268. }
  269. $post['BlogPost'] = $this->data['BlogPost'];
  270. if($this->data['BlogPost']['blog_category_id']) {
  271. $blogCategory = $this->BlogPost->BlogCategory->find('first', array(
  272. 'conditions'=> array('BlogCategory.id' => $this->data['BlogPost']['blog_category_id']),
  273. 'recursive' => -1
  274. ));
  275. $post['BlogCategory'] = $blogCategory['BlogCategory'];
  276. }
  277. if($this->data['BlogPost']['user_id']) {
  278. $author = $this->BlogPost->User->find('first', array(
  279. 'conditions' => array('User.id' => $this->data['BlogPost']['user_id']),
  280. 'recursive' => -1
  281. ));
  282. $post['User'] = $author['User'];
  283. }
  284. if(isset($this->data['BlogTag'])) {
  285. $tags = $this->BlogPost->BlogTag->find('all', array('conditions' => $this->data['BlogTag']['BlogTag']));
  286. if($tags) {
  287. $tags = Set::extract('/BlogTag/.', $tags);
  288. $post['BlogTag'] = $tags;
  289. }
  290. }
  291. } else {
  292. if(!empty($pass[0])) {
  293. $id = $pass[0];
  294. } else {
  295. $this->notFound();
  296. }
  297. // コメント送信
  298. if(isset($this->data['BlogComment'])) {
  299. $this->add_comment($id);
  300. }
  301. $_posts = $this->_getBlogPosts(array('conditions' => array('id' => $id)));
  302. if(!empty($_posts[0])) {
  303. $post = $_posts[0];
  304. } else {
  305. $this->notFound();
  306. }
  307. $user = $this->BcAuth->user();
  308. if(empty($this->params['admin']) && !empty($user) && !Configure::read('BcRequest.agent')) {
  309. $this->set('editLink', array('admin' => true, 'prefix' => 'blog', 'controller' => 'blog_posts', 'action' => 'edit', $post['BlogPost']['blog_content_id'], $post['BlogPost']['id']));
  310. }
  311. }
  312. // ナビゲーションを設定
  313. if(!empty($post['BlogPost']['blog_category_id'])) {
  314. $blogCategories = $this->BlogCategory->getpath($post['BlogPost']['blog_category_id'],array('name','title'));
  315. if($blogCategories) {
  316. foreach($blogCategories as $blogCategory) {
  317. $this->crumbs[] = array('name' => $blogCategory['BlogCategory']['title'], 'url' => '/'.$this->blogContent['BlogContent']['name'].'/archives/category/'.$blogCategory['BlogCategory']['name']);
  318. }
  319. }
  320. }
  321. $this->pageTitle = $post['BlogPost']['name'];
  322. $single = true;
  323. $template = $this->blogContent['BlogContent']['template'].DS.'single';
  324. if($this->preview) {
  325. $this->blogContent['BlogContent']['comment_use'] = false;
  326. }
  327. $this->set('post', $post);
  328. }
  329. // 表示設定
  330. $this->crumbs += $crumbs;
  331. $this->set('single',$single);
  332. $this->set('posts', $posts);
  333. $this->set('year', $year);
  334. $this->set('month', $month);
  335. $this->contentsTitle = $this->pageTitle;
  336. $this->subMenuElements = array_merge($this->subMenuElements,array('blog_calendar', 'blog_recent_entries', 'blog_category_archives', 'blog_monthly_archives'));
  337. $this->layout = $this->blogContent['BlogContent']['layout'];
  338. $this->render($template);
  339. }
  340. /**
  341. * コメントを送信する
  342. *
  343. * @param int $id
  344. * @return void
  345. * @access public
  346. */
  347. function add_comment($id) {
  348. // blog_post_idを取得
  349. $conditions = array(
  350. 'BlogPost.no' => $id,
  351. 'BlogPost.blog_content_id' => $this->contentId
  352. );
  353. $conditions = am($conditions, $this->BlogPost->getConditionAllowPublish());
  354. // 毎秒抽出条件が違うのでキャッシュしない
  355. $data = $this->BlogPost->find('first', array(
  356. 'conditions'=> $conditions,
  357. 'fields' => array('BlogPost.id'),
  358. 'cache' => false,
  359. 'recursive' => -1
  360. ));
  361. if(empty($data['BlogPost']['id'])) {
  362. $this->notFound();
  363. } else {
  364. $postId = $data['BlogPost']['id'];
  365. }
  366. if($this->BlogPost->BlogComment->add($this->data, $this->contentId, $postId, $this->blogContent['BlogContent']['comment_approve'])) {
  367. $this->_sendComment();
  368. if($this->blogContent['BlogContent']['comment_approve']) {
  369. $commentMessage = '送信が完了しました。送信された内容は確認後公開させて頂きます。';
  370. }else {
  371. $commentMessage = 'コメントの送信が完了しました。';
  372. }
  373. $this->data = null;
  374. }else {
  375. $commentMessage = 'コメントの送信に失敗しました。';
  376. }
  377. $this->set('commentMessage',$commentMessage);
  378. }
  379. /**
  380. * ブログ記事を取得する
  381. *
  382. * @param array $options
  383. * @return array
  384. * @access protected
  385. */
  386. function _getBlogPosts($options = array()) {
  387. $_options = array(
  388. 'listDirection' => $this->blogContent['BlogContent']['list_direction'],
  389. 'listCount' => $this->blogContent['BlogContent']['list_count'],
  390. 'conditions' => array()
  391. );
  392. $_conditions = array(
  393. 'category' => null,
  394. 'tag' => null,
  395. 'year' => null,
  396. 'month' => null,
  397. 'day' => null,
  398. 'id' => null,
  399. 'keyword' => null
  400. );
  401. $options = am($_options, $options);
  402. $__conditions = array();
  403. if(!empty($this->params['named'])) {
  404. $__conditions = am($options['conditions'], $this->params['named']);
  405. } else {
  406. $__conditions = $options['conditions'];
  407. }
  408. unset($options['conditions']);
  409. $_conditions = am($_conditions, $__conditions);
  410. extract($options);
  411. $expects = array('BlogContent', 'BlogCategory', 'User', 'BlogTag');
  412. $conditions = array('BlogPost.blog_content_id' => $this->contentId);
  413. // カテゴリ条件
  414. if($_conditions['category']) {
  415. $category = $_conditions['category'];
  416. $categoryId = $this->BlogCategory->field('id', array(
  417. 'BlogCategory.blog_content_id' => $this->contentId,
  418. 'BlogCategory.name' => $category
  419. ));
  420. $categoryIds = array(0 => $categoryId);
  421. // 指定したカテゴリ名にぶら下がる子カテゴリを取得
  422. $catChildren = $this->BlogCategory->children($categoryId);
  423. if($catChildren) {
  424. $catChildren = Set::extract('/BlogCategory/id',$catChildren);
  425. $categoryIds = am($categoryIds, $catChildren);
  426. }
  427. $conditions['BlogPost.blog_category_id'] = $categoryIds;
  428. }
  429. // タグ条件
  430. if($_conditions['tag']) {
  431. $tag = $_conditions['tag'];
  432. if(!is_array($tag)) {
  433. $tag = array($tag);
  434. }
  435. foreach($tag as $key => $value) {
  436. $tag[$key] = urldecode($value);
  437. }
  438. $tags = $this->BlogPost->BlogTag->find('all', array(
  439. 'conditions'=> array('BlogTag.name' => $tag),
  440. 'recursive' => 1
  441. ));
  442. if(isset($tags[0]['BlogPost'][0]['id'])) {
  443. $ids = Set::extract('/BlogPost/id',$tags);
  444. $conditions['BlogPost.id'] = $ids;
  445. } else {
  446. return array();
  447. }
  448. }
  449. // キーワード条件
  450. if($_conditions['keyword']) {
  451. $keyword = $_conditions['keyword'];
  452. if(preg_match('/\s/', $keyword)) {
  453. $keywords = explode("\s", $keyword);
  454. } else {
  455. $keywords = array($keyword);
  456. }
  457. foreach($keywords as $key => $value) {
  458. $keywords[$key] = urldecode($value);
  459. $conditions['or'][]['BlogPost.name LIKE'] = '%'.$value.'%';
  460. $conditions['or'][]['BlogPost.content LIKE'] = '%'.$value.'%';
  461. $conditions['or'][]['BlogPost.detail LIKE'] = '%'.$value.'%';
  462. }
  463. }
  464. // 年月日条件
  465. if($_conditions['year'] || $_conditions['month'] || $_conditions['day']) {
  466. $year = $_conditions['year'];
  467. $month = $_conditions['month'];
  468. $day = $_conditions['day'];
  469. $db=& ConnectionManager::getDataSource($this->BlogPost->useDbConfig);
  470. switch (preg_replace('/^bc_/', '', $db->config['driver'])) {
  471. case 'mysql':
  472. case 'csv':
  473. if($year) $conditions["YEAR(BlogPost.posts_date)"] = $year;
  474. if($month) $conditions["MONTH(BlogPost.posts_date)"] = $month;
  475. if($day) $conditions["DAY(BlogPost.posts_date)"] = $day;
  476. break;
  477. case 'postres':
  478. if($year) $conditions["date_part('year'(BlogPost.posts_date)"] = $year;
  479. if($month) $conditions["date_part('month'(BlogPost.posts_date)"] = $month;
  480. if($day) $conditions["date_part('day'(BlogPost.posts_date)"] = $day;
  481. break;
  482. case 'sqlite':
  483. case 'sqlite3':
  484. if($year) $conditions["strftime('%Y',BlogPost.posts_date)"] = $year;
  485. if($month) $conditions["strftime('%m',BlogPost.posts_date)"] = sprintf('%02d',$month);
  486. if($day) $conditions["strftime('%d',BlogPost.posts_date)"] = sprintf('%02d',$day);
  487. break;
  488. }
  489. }
  490. if($_conditions['id']) {
  491. $conditions["BlogPost.no"] = $_conditions['id'];
  492. $expects[] = 'BlogComment';
  493. $this->BlogPost->hasMany['BlogComment']['conditions'] = array('BlogComment.status'=>true);
  494. $listCount = 1;
  495. }
  496. unset($_conditions['category']);
  497. unset($_conditions['tag']);
  498. unset($_conditions['keyword']);
  499. unset($_conditions['year']);
  500. unset($_conditions['month']);
  501. unset($_conditions['day']);
  502. unset($_conditions['id']);
  503. unset($_conditions['page']);
  504. unset($_conditions['num']);
  505. unset($_conditions['sort']);
  506. unset($_conditions['direction']);
  507. if($_conditions) {
  508. // とりあえず BlogPost のフィールド固定
  509. $conditions = am($conditions, $this->postConditions(array('BlogPost' => $_conditions)));
  510. }
  511. // プレビューの場合は公開ステータスを条件にしない
  512. if(!$this->preview) {
  513. $conditions = am($conditions, $this->BlogPost->getConditionAllowPublish());
  514. }
  515. $this->BlogPost->expects($expects, false);
  516. if(!empty($direction)) {
  517. $listDirection = $direction;
  518. }
  519. $order = "BlogPost.posts_date {$listDirection}";
  520. if(!empty($sort)) {
  521. $order = "BlogPost.{$sort} {$listDirection}";
  522. if($sort != 'id') {
  523. $order .= ", BlogPost.id ASC";
  524. }
  525. }
  526. // 毎秒抽出条件が違うのでキャッシュしない
  527. $this->paginate = array(
  528. 'conditions'=> $conditions,
  529. 'fields' => array(),
  530. 'order' => $order,
  531. 'limit' => $listCount,
  532. 'recursive' => 1,
  533. 'cache' => false
  534. );
  535. return $this->paginate('BlogPost');
  536. }
  537. /**
  538. * [MOBILE] ブログアーカイブを表示する
  539. *
  540. * @param mixed blog_post_id / type
  541. * @param mixed blog_post_id / ""
  542. * @return void
  543. * @access public
  544. */
  545. function mobile_archives() {
  546. $this->setAction('archives');
  547. }
  548. /**
  549. * [SMARTPHONE] ブログアーカイブを表示する
  550. *
  551. * @param mixed blog_post_id / type
  552. * @param mixed blog_post_id / ""
  553. * @return void
  554. * @access public
  555. */
  556. function smartphone_archives() {
  557. $this->setAction('archives');
  558. }
  559. /**
  560. * [ADMIN] プレビューを表示する
  561. *
  562. * @param int $blogContentsId
  563. * @param int $id
  564. * @param string $mode
  565. * @return void
  566. * @access public
  567. */
  568. function admin_preview($blogContentsId, $id, $mode) {
  569. if($mode == 'create') {
  570. $this->_createPreview($blogContentsId, $id);
  571. } elseif($mode == 'view') {
  572. $this->_viewPreview($blogContentsId, $id);
  573. }
  574. }
  575. /**
  576. * ブログ記事をプレビュー
  577. *
  578. * @param int $blogContentsId / type
  579. * @param int $id / ""
  580. * @return void
  581. * @access protected
  582. */
  583. function _createPreview($blogContentsId, $id) {
  584. Cache::write('blog_posts_preview_'.$id, $this->data);
  585. echo true;
  586. exit();
  587. }
  588. /**
  589. * プレビューを表示する
  590. *
  591. * @param int $blogContentId
  592. * @param int $id
  593. * @return void
  594. * @access protected
  595. */
  596. function _viewPreview($blogContentsId, $id){
  597. $data = Cache::read('blog_posts_preview_'.$id);
  598. Cache::delete('blog_posts_preview_'.$id);
  599. $this->data = $this->params['data'] = $data;
  600. $this->preview = true;
  601. $this->layoutPath = '';
  602. $this->subDir = '';
  603. unset($this->params['pass']);
  604. unset($this->params['prefix']);
  605. unset($this->params['plugin']);
  606. unset($this->params['admin']);
  607. $this->params['controller'] = $this->blogContent['BlogContent']['name'];
  608. $this->params['action'] = 'archives';
  609. $this->params['url']['url'] = $this->params['controller'].'/'.'archives'.'/'.$this->data['BlogPost']['no'];
  610. $this->params['pass'][0] = $this->data['BlogPost']['no'];
  611. $this->theme = $this->siteConfigs['theme'];
  612. $this->setAction('archives');
  613. }
  614. /**
  615. * ブログカレンダー用のデータを取得する
  616. *
  617. * @param int $id
  618. * @param int $year
  619. * @param int $month
  620. * @return array
  621. * @access public
  622. */
  623. function get_calendar($id,$year='',$month=''){
  624. $year = h($year);
  625. $month = h($month);
  626. $this->BlogContent->recursive = -1;
  627. $data['blogContent'] = $this->BlogContent->read(null,$id);
  628. $this->BlogPost->recursive = -1;
  629. $data['entryDates'] = $this->BlogPost->getEntryDates($id,$year,$month);
  630. if(!$year) {
  631. $year = date('Y');
  632. }
  633. if(!$month) {
  634. $month = date('m');
  635. }
  636. if($month==12) {
  637. $data['next'] = $this->BlogPost->existsEntry($id, $year+1, 1);
  638. } else {
  639. $data['next'] = $this->BlogPost->existsEntry($id, $year, $month+1);
  640. }
  641. if($month==1) {
  642. $data['prev'] = $this->BlogPost->existsEntry($id, $year-1, 12);
  643. } else {
  644. $data['prev'] = $this->BlogPost->existsEntry($id, $year, $month-1);
  645. }
  646. return $data;
  647. }
  648. /**
  649. * カテゴリー一覧用のデータを取得する
  650. *
  651. * @param int $id
  652. * @param mixed $limit Number Or false Or '0'(制限なし)
  653. * @param mixed $viewCount
  654. * @param mixed $contentType year Or null
  655. * @return array
  656. * @access public
  657. */
  658. function get_categories($id, $limit = false, $viewCount = false, $depth = 1, $contentType = null){
  659. if($limit === '0') {
  660. $limit = false;
  661. }
  662. $data = array();
  663. $this->BlogContent->recursive = -1;
  664. $data['blogContent'] = $this->BlogContent->read(null,$id);
  665. $data['categories'] = $this->BlogCategory->getCategoryList($id, array(
  666. 'type' => $contentType,
  667. 'limit' => $limit,
  668. 'depth' => $depth,
  669. 'viewCount' => $viewCount
  670. ));
  671. return $data;
  672. }
  673. /**
  674. * 月別アーカイブ一覧用のデータを取得する
  675. *
  676. * @param int $id
  677. * @return mixed $limit Number Or false Or '0'(制限なし)
  678. * @access public
  679. */
  680. function get_posted_months($id, $limit = 12, $viewCount = false){
  681. if($limit === '0') {
  682. $limit = false;
  683. }
  684. $this->BlogContent->recursive = -1;
  685. $data['blogContent'] = $this->BlogContent->read(null,$id);
  686. $this->BlogPost->recursive = -1;
  687. $data['postedDates'] = $this->BlogPost->getPostedDates($id, array(
  688. 'type' => 'month',
  689. 'limit' => $limit,
  690. 'viewCount' => $viewCount
  691. ));
  692. return $data;
  693. }
  694. /**
  695. * 年別アーカイブ一覧用のデータを取得する
  696. *
  697. * @param int $id
  698. * @param boolean $viewCount
  699. * @return mixed $count
  700. * @access public
  701. */
  702. function get_posted_years($id, $limit = false, $viewCount = false){
  703. if($limit === '0') {
  704. $limit = false;
  705. }
  706. $this->BlogContent->recursive = -1;
  707. $data['blogContent'] = $this->BlogContent->read(null,$id);
  708. $this->BlogPost->recursive = -1;
  709. $data['postedDates'] = $this->BlogPost->getPostedDates($id, array(
  710. 'type' => 'year',
  711. 'limit' => $limit,
  712. 'viewCount' => $viewCount
  713. ));
  714. return $data;
  715. }
  716. /**
  717. * 最近の投稿用のデータを取得する
  718. *
  719. * @param int $id
  720. * @param mixed $count
  721. * @return array
  722. * @access public
  723. */
  724. function get_recent_entries($id, $limit = 5){
  725. if($limit === '0') {
  726. $limit = false;
  727. }
  728. $this->BlogContent->recursive = -1;
  729. $data['blogContent'] = $this->BlogContent->read(null,$id);
  730. $this->BlogPost->recursive = -1;
  731. $conditions = array('BlogPost.blog_content_id'=>$id);
  732. $conditions = am($conditions, $this->BlogPost->getConditionAllowPublish());
  733. // 毎秒抽出条件が違うのでキャッシュしない
  734. $data['recentEntries'] = $this->BlogPost->find('all', array(
  735. 'fields' => array('no','name'),
  736. 'conditions'=> $conditions,
  737. 'limit' => $limit,
  738. 'order' => 'posts_date DESC',
  739. 'recursive' => -1,
  740. 'cache' => false
  741. ));
  742. return $data;
  743. }
  744. /**
  745. * 記事リストを出力
  746. * requestAction用
  747. *
  748. * @param int $blogContentId
  749. * @param mixed $num
  750. * @access public
  751. */
  752. function posts($blogContentId, $limit = 5) {
  753. if(!empty($this->params['named']['template'])) {
  754. $template = $this->params['named']['template'];
  755. } else {
  756. $template = 'posts';
  757. }
  758. unset($this->params['named']['template']);
  759. $this->layout = null;
  760. $this->contentId = $blogContentId;
  761. if($this->blogContent['BlogContent']['status']) {
  762. $datas = $this->_getBlogPosts(array('listCount' => $limit));
  763. } else {
  764. $datas = array();
  765. }
  766. $this->set('posts', $datas);
  767. $this->render($this->blogContent['BlogContent']['template'].DS . $template);
  768. }
  769. /**
  770. * [MOBILE] 記事リストを出力
  771. *
  772. * requestAction用
  773. *
  774. * @param int $blogContentId
  775. * @param mixed $num
  776. * @access public
  777. */
  778. function mobile_posts($blogContentId, $limit = 5) {
  779. $this->setAction('posts', $blogContentId, $limit);
  780. }
  781. /**
  782. * [SMARTPHONE] 記事リストを出力
  783. *
  784. * requestAction用
  785. *
  786. * @param int $blogContentId
  787. * @param mixed $num
  788. * @access public
  789. */
  790. function smartphone_posts($blogContentId, $limit = 5) {
  791. $this->setAction('posts', $blogContentId, $limit);
  792. }
  793. }
  794. ?>