PageRenderTime 43ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/baser/plugins/feed/controllers/feed_details_controller.php

https://github.com/hashing/basercms
PHP | 297 lines | 121 code | 46 blank | 130 comment | 20 complexity | ff1d822f6aabce9d3e974a9b2728dd2f 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.feed.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.feed.controllers
  27. */
  28. class FeedDetailsController extends FeedAppController {
  29. /**
  30. * クラス名
  31. *
  32. * @var string
  33. * @access public
  34. */
  35. var $name = 'FeedDetails';
  36. /**
  37. * モデル
  38. *
  39. * @var array
  40. * @access public
  41. */
  42. var $uses = array('Feed.FeedDetail','Feed.FeedConfig', 'Feed.RssEx');
  43. /**
  44. * ヘルパー
  45. *
  46. * @var array
  47. * @access public
  48. */
  49. var $helpers = array(BC_FORM_HELPER);
  50. /**
  51. * コンポーネント
  52. *
  53. * @var array
  54. * @access public
  55. */
  56. var $components = array('BcAuth','Cookie','BcAuthConfigure');
  57. /**
  58. * ぱんくずナビ
  59. *
  60. * @var array
  61. * @access public
  62. */
  63. var $crumbs = array(
  64. array('name' => 'プラグイン管理', 'url' => array('plugin' => '', 'controller' => 'plugins', 'action' => 'index')),
  65. array('name' => 'フィード管理', 'url' => array('controller' => 'feed_configs', 'action' => 'index'))
  66. );
  67. /**
  68. * サブメニューエレメント
  69. *
  70. * @var array
  71. * @access public
  72. */
  73. var $subMenuElements = array();
  74. /**
  75. * beforeFilter
  76. *
  77. * @return void
  78. * @access public
  79. */
  80. function beforeFilter() {
  81. parent::beforeFilter();
  82. $feedConfig = $this->FeedConfig->read(null,$this->params['pass'][0]);
  83. $this->crumbs[] = array('name' => 'フィード設定情報: '.$feedConfig['FeedConfig']['name'], 'url' => array('controller' => 'feed_configs', 'action' => 'edit', $this->params['pass'][0]));
  84. if($this->params['prefix']=='admin') {
  85. $this->subMenuElements = array('feed_details');
  86. $this->help = 'feed_details_form';
  87. }
  88. }
  89. /**
  90. * [ADMIN] 登録
  91. *
  92. * @param int feed_config_id
  93. * @return void
  94. * @access public
  95. */
  96. function admin_add($feedConfigId) {
  97. /* 除外処理 */
  98. if(!$feedConfigId) {
  99. $this->Session->setFlash('無効なIDです');
  100. $this->redirect(array('controller' => 'feed_configs', 'action' => 'index'));
  101. }
  102. if(empty($this->data)) {
  103. $this->data = $this->FeedDetail->getDefaultValue($feedConfigId);
  104. }else {
  105. if(!preg_match('/^http/is', $this->data['FeedDetail']['url']) && !preg_match('/^\//is', $this->data['FeedDetail']['url'])){
  106. $this->data['FeedDetail']['url'] = '/'.$this->data['FeedDetail']['url'];
  107. }
  108. $this->FeedDetail->create($this->data);
  109. // データを保存
  110. if($this->FeedDetail->save()) {
  111. $id = $this->FeedDetail->getLastInsertId();
  112. $this->Session->setFlash('フィード「'.$this->data['FeedDetail']['name'].'」を追加しました。');
  113. $this->FeedDetail->saveDbLog('フィード「'.$this->data['FeedDetail']['name'].'」を追加しました。');
  114. $this->redirect(array('controller' => 'feed_configs', 'action' => 'edit', $feedConfigId, $id, '#' => 'headFeedDetail'));
  115. }else {
  116. $this->Session->setFlash('入力エラーです。内容を修正してください。');
  117. }
  118. }
  119. // 表示設定
  120. $this->pageTitle = '新規フィード情報登録';
  121. $this->render('form');
  122. }
  123. /**
  124. * [ADMIN] 編集
  125. *
  126. * @param int $feedConfigId
  127. * @param int $id
  128. * @return void
  129. * @access public
  130. */
  131. function admin_edit($feedConfigId,$id) {
  132. if(!$id && empty($this->data)) {
  133. $this->Session->setFlash('無効なIDです。');
  134. $this->redirect(array('controller' => 'feed_configs', 'action' => 'index'));
  135. }
  136. if(empty($this->data)) {
  137. $this->data = $this->FeedDetail->read(null, $id);
  138. }else {
  139. if(!preg_match('/^http/is', $this->data['FeedDetail']['url']) && !preg_match('/^\//is', $this->data['FeedDetail']['url'])){
  140. $this->data['FeedDetail']['url'] = '/'.$this->data['FeedDetail']['url'];
  141. }
  142. $this->FeedDetail->set($this->data);
  143. // データを保存
  144. if($this->FeedDetail->save()) {
  145. $this->requestAction(array('controller' => 'feed_configs', 'action' => 'clear_cache'), array('pass' => array($this->data['FeedDetail']['feed_config_id'], $this->data['FeedDetail']['url'])));
  146. $this->Session->setFlash('フィード詳細「'.$this->data['FeedDetail']['name'].'」を更新しました。');
  147. $this->FeedDetail->saveDbLog('フィード詳細「'.$this->data['FeedDetail']['name'].'」を更新しました。');
  148. $this->redirect(array('controller' => 'feed_configs', 'action' => 'edit', $feedConfigId, $id, '#' => 'headFeedDetail'));
  149. }else {
  150. $this->Session->setFlash('入力エラーです。内容を修正してください。');
  151. }
  152. }
  153. // 表示設定
  154. $this->pageTitle = 'フィード情報編集';
  155. $this->render('form');
  156. }
  157. /**
  158. * フィードのキャッシュを削除する
  159. *
  160. * @param string $feedConfigId
  161. * @param string $url
  162. * @return void
  163. * @access protected
  164. */
  165. function _clearViewCatch($feedConfigId, $url) {
  166. clearViewCache('/feed/index/'.$feedConfigId);
  167. clearViewCache('/feed/ajax/'.$feedConfigId);
  168. clearViewCache('/feed/cachetime/'.$feedConfigId);
  169. if(strpos($url,'http')===false) {
  170. // 実際のキャッシュではSSLを利用しているかどうかわからないので、両方削除する
  171. clearCache($this->RssEx->__createCacheHash('', 'http://'.$_SERVER['HTTP_HOST'].$this->base.$url), 'views', '.rss');
  172. clearCache($this->RssEx->__createCacheHash('', 'https://'.$_SERVER['HTTP_HOST'].$this->base.$url), 'views', '.rss');
  173. }else {
  174. clearCache($this->RssEx->__createCacheHash('', $url),'views','.rss');
  175. }
  176. }
  177. /**
  178. * [ADMIN] 削除 (ajax)
  179. *
  180. * @param int $feedConfigId
  181. * @param int $id
  182. * @return void
  183. * @access public
  184. */
  185. function admin_ajax_delete($feedConfigId, $id = null) {
  186. if(!$id) {
  187. $this->ajaxError(500, '無効な処理です。');
  188. }
  189. if($this->_del($id)) {
  190. exit(true);
  191. }
  192. exit();
  193. }
  194. /**
  195. * [ADMIN] 削除
  196. *
  197. * @param int $feedConfigId
  198. * @param int $id
  199. * @return void
  200. * @access public
  201. */
  202. function admin_delete($feedConfigId, $id = null) {
  203. /* 除外処理 */
  204. if(!$id) {
  205. $this->Session->setFlash('無効なIDです。');
  206. $this->redirect(array('controller' => 'feed_configs', 'action' => 'index'));
  207. }
  208. // メッセージ用にデータを取得
  209. $FeedDetail = $this->FeedDetail->read(null, $id);
  210. // 削除実行
  211. if($this->FeedDetail->del($id)) {
  212. $this->Session->setFlash($FeedDetail['FeedDetail']['name'].' を削除しました。');
  213. $this->FeedDetail->saveDbLog('フィード「'.$FeedDetail['FeedDetail']['name'].'」を削除しました。');
  214. }else {
  215. $this->Session->setFlash('データベース処理中にエラーが発生しました。');
  216. }
  217. $this->redirect(array('controller' => 'feed_configs', 'action' => 'edit', $feedConfigId, $id, '#' => 'headFeedDetail'));
  218. }
  219. /**
  220. * 一括削除
  221. *
  222. * @param array $ids
  223. * @return boolean
  224. * @access protected
  225. */
  226. function _batch_del($ids) {
  227. if($ids) {
  228. foreach($ids as $id) {
  229. $this->_del($id);
  230. }
  231. }
  232. return true;
  233. }
  234. /**
  235. * データを削除する
  236. *
  237. * @param int $id
  238. * @return boolean
  239. * @access protected
  240. */
  241. function _del($id) {
  242. $data = $this->FeedDetail->read(null, $id);
  243. if($this->FeedDetail->del($id)) {
  244. $this->FeedDetail->saveDbLog('フィード「'.$data['FeedDetail']['name'].'」を削除しました。');
  245. return true;
  246. } else {
  247. return false;
  248. }
  249. }
  250. }
  251. ?>