PageRenderTime 1811ms CodeModel.GetById 45ms RepoModel.GetById 554ms app.codeStats 0ms

/baser/plugins/blog/controllers/blog_contents_controller.php

https://github.com/hashing/basercms
PHP | 330 lines | 158 code | 37 blank | 135 comment | 24 complexity | 02ada215155c5fb832a7632e50f6a768 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 BlogContentsController extends BlogAppController {
  29. /**
  30. * クラス名
  31. *
  32. * @var string
  33. * @access public
  34. */
  35. var $name = 'BlogContents';
  36. /**
  37. * モデル
  38. *
  39. * @var array
  40. * @access public
  41. */
  42. var $uses = array('SiteConfig', 'Blog.BlogCategory', 'Blog.BlogContent');
  43. /**
  44. * ヘルパー
  45. *
  46. * @var array
  47. * @access public
  48. */
  49. var $helpers = array(BC_HTML_HELPER, BC_TIME_HELPER, BC_FORM_HELPER, 'Blog.Blog');
  50. /**
  51. * コンポーネント
  52. *
  53. * @var array
  54. * @access public
  55. */
  56. var $components = array('BcAuth','Cookie','BcAuthConfigure');
  57. /**
  58. * ぱんくずナビ
  59. *
  60. * @var string
  61. * @access public
  62. */
  63. var $crumbs = array(
  64. array('name' => 'プラグイン管理', 'url' => array('plugin' => '', 'controller' => 'plugins', 'action' => 'index')),
  65. array('name' => 'ブログ管理', 'url' => array('controller' => 'blog_contents', 'action' => 'index'))
  66. );
  67. /**
  68. * サブメニューエレメント
  69. *
  70. * @var array
  71. * @access public
  72. */
  73. var $subMenuElements = array();
  74. /**
  75. * before_filter
  76. *
  77. * @return void
  78. * @access public
  79. */
  80. function beforeFilter() {
  81. parent::beforeFilter();
  82. if(isset($this->params['prefix']) && $this->params['prefix']=='admin') {
  83. $this->subMenuElements = array('blog_common');
  84. }
  85. }
  86. /**
  87. * [ADMIN] ブログコンテンツ一覧
  88. *
  89. * @return void
  90. * @access public
  91. */
  92. function admin_index() {
  93. $datas = $this->BlogContent->find('all',array('order'=>array('BlogContent.id')));
  94. $this->set('datas', $datas);
  95. if($this->RequestHandler->isAjax() || !empty($this->params['url']['ajax'])) {
  96. $this->render('ajax_index');
  97. return;
  98. }
  99. $this->pageTitle = 'ブログ一覧';
  100. $this->help = 'blog_contents_index';
  101. }
  102. /**
  103. * [ADMIN] ブログコンテンツ追加
  104. *
  105. * @return void
  106. * @access public
  107. */
  108. function admin_add() {
  109. $this->pageTitle = '新規ブログ登録';
  110. if(!$this->data) {
  111. $this->data = $this->BlogContent->getDefaultValue();
  112. }else {
  113. /* 登録処理 */
  114. $this->BlogContent->create($this->data);
  115. // データを保存
  116. if($this->BlogContent->save()) {
  117. $id = $this->BlogContent->getLastInsertId();
  118. $message = '新規ブログ「'.$this->data['BlogContent']['title'].'」を追加しました。';
  119. $this->Session->setFlash($message);
  120. $this->BlogContent->saveDbLog($message);
  121. $this->redirect(array('action' => 'edit', $id));
  122. }else {
  123. $this->Session->setFlash('入力エラーです。内容を修正してください。');
  124. }
  125. }
  126. // テーマの一覧を取得
  127. $this->set('themes',$this->SiteConfig->getThemes());
  128. $this->render('form');
  129. }
  130. /**
  131. * [ADMIN] 編集処理
  132. *
  133. * @param int $id
  134. * @return void
  135. * @access public
  136. */
  137. function admin_edit($id) {
  138. /* 除外処理 */
  139. if(!$id && empty($this->data)) {
  140. $this->Session->setFlash('無効なIDです。');
  141. $this->redirect(array('action' => 'index'));
  142. }
  143. if(empty($this->data)) {
  144. $this->data = $this->BlogContent->read(null, $id);
  145. }else {
  146. /* 更新処理 */
  147. if($this->BlogContent->save($this->data)) {
  148. $message = 'ブログ「'.$this->data['BlogContent']['title'].'」を更新しました。';
  149. $this->Session->setFlash($message);
  150. $this->BlogContent->saveDbLog($message);
  151. if($this->data['BlogContent']['edit_layout_template']){
  152. $this->redirectEditLayout($this->data['BlogContent']['layout']);
  153. }elseif ($this->data['BlogContent']['edit_blog_template']) {
  154. $this->redirectEditBlog($this->data['BlogContent']['template']);
  155. }else{
  156. $this->redirect(array('action' => 'edit', $id));
  157. }
  158. }else {
  159. $this->Session->setFlash('入力エラーです。内容を修正してください。');
  160. }
  161. }
  162. $this->set('publishLink', '/'.$this->data['BlogContent']['name'].'/index');
  163. /* 表示設定 */
  164. $this->set('blogContent',$this->data);
  165. $this->subMenuElements = array('blog_posts','blog_categories','blog_common');
  166. $this->set('themes',$this->SiteConfig->getThemes());
  167. $this->pageTitle = 'ブログ設定編集:'.$this->data['BlogContent']['title'];
  168. $this->help = 'blog_contents_form';
  169. $this->render('form');
  170. }
  171. /**
  172. * レイアウト編集画面にリダイレクトする
  173. *
  174. * @param string $template
  175. * @return void
  176. * @access public
  177. */
  178. function redirectEditLayout($template){
  179. $target = WWW_ROOT.'themed'.DS.$this->siteConfigs['theme'].DS.'layouts'.DS.$template.$this->ext;
  180. $sorces = array(BASER_PLUGINS.'blog'.DS.'views'.DS.'layouts'.DS.$template.$this->ext,
  181. BASER_VIEWS.'layouts'.DS.$template.$this->ext);
  182. if($this->siteConfigs['theme']){
  183. if(!file_exists($target)){
  184. foreach($sorces as $source){
  185. if(file_exists($source)){
  186. copy($source,$target);
  187. chmod($target,0666);
  188. break;
  189. }
  190. }
  191. }
  192. $this->redirect(array('plugin' => null, 'controller' => 'theme_files', 'action' => 'edit', $this->siteConfigs['theme'], 'layouts', $template.$this->ext));
  193. }else{
  194. $this->Session->setFlash('現在、「テーマなし」の場合、管理画面でのテンプレート編集はサポートされていません。');
  195. $this->redirect(array('action' => 'index'));
  196. }
  197. }
  198. /**
  199. * ブログテンプレート編集画面にリダイレクトする
  200. *
  201. * @param string $template
  202. * @return void
  203. * @access public
  204. */
  205. function redirectEditBlog($template){
  206. $path = 'blog'.DS.$template;
  207. $target = WWW_ROOT.'themed'.DS.$this->siteConfigs['theme'].DS.$path;
  208. $sorces = array(BASER_PLUGINS.'blog'.DS.'views'.DS.$path);
  209. if($this->siteConfigs['theme']){
  210. if(!file_exists($target.DS.'index'.$this->ext)){
  211. foreach($sorces as $source){
  212. if(is_dir($source)){
  213. $folder = new Folder();
  214. $folder->create(dirname($target), 0777);
  215. $folder->copy(array('from'=>$source,'to'=>$target,'chmod'=>0777,'skip'=>array('_notes')));
  216. break;
  217. }
  218. }
  219. }
  220. $path = str_replace(DS, '/', $path);
  221. $this->redirect(array('plugin' => null, 'controller' => 'theme_files', 'action' => 'edit', $this->siteConfigs['theme'], 'etc', $path.'/index'.$this->ext));
  222. }else{
  223. $this->Session->setFlash('現在、「テーマなし」の場合、管理画面でのテンプレート編集はサポートされていません。');
  224. $this->redirect(array('action' => 'index'));
  225. }
  226. }
  227. /**
  228. * [ADMIN] 削除処理
  229. *
  230. * @param int $id
  231. * @return void
  232. * @access public
  233. * @deprecated
  234. */
  235. function admin_delete($id = null) {
  236. /* 除外処理 */
  237. if(!$id) {
  238. $this->Session->setFlash('無効なIDです。');
  239. $this->redirect(array('action' => 'index'));
  240. }
  241. // メッセージ用にデータを取得
  242. $post = $this->BlogContent->read(null, $id);
  243. /* 削除処理 */
  244. if($this->BlogContent->del($id)) {
  245. $message = 'ブログ「'.$post['BlogContent']['title'].'」 を削除しました。';
  246. $this->Session->setFlash($message);
  247. $this->BlogContent->saveDbLog($message);
  248. }else {
  249. $this->Session->setFlash('データベース処理中にエラーが発生しました。');
  250. }
  251. $this->redirect(array('action' => 'index'));
  252. }
  253. /**
  254. * [ADMIN] Ajax 削除処理
  255. *
  256. * @param int $id
  257. * @return void
  258. * @access public
  259. */
  260. function admin_ajax_delete($id = null) {
  261. /* 除外処理 */
  262. if(!$id) {
  263. $this->ajaxError(500, '無効な処理です。');
  264. }
  265. // メッセージ用にデータを取得
  266. $post = $this->BlogContent->read(null, $id);
  267. /* 削除処理 */
  268. if($this->BlogContent->del($id)) {
  269. $this->BlogContent->saveDbLog('ブログ「'.$post['BlogContent']['title'].'」 を削除しました。');
  270. echo true;
  271. }
  272. exit();
  273. }
  274. /**
  275. * [ADMIN] データコピー(AJAX)
  276. *
  277. * @param int $id
  278. * @return void
  279. * @access public
  280. */
  281. function admin_ajax_copy($id) {
  282. if(!$id) {
  283. $this->ajaxError(500, '無効な処理です。');
  284. }
  285. $result = $this->BlogContent->copy($id);
  286. if($result) {
  287. $this->set('data', $result);
  288. } else {
  289. $this->ajaxError(500, $this->BlogContent->validationErrors);
  290. }
  291. }
  292. }
  293. ?>