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

/src/system/application/controllers/dashboard/blog/entries.php

https://bitbucket.org/seezoo/seezoo/
PHP | 183 lines | 114 code | 25 blank | 44 comment | 9 complexity | 17fad96de0148dc8d92903e0789ed847 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * ===============================================================================
  4. *
  5. * Seezoo dashboard 投稿済みブログエントリ表示用コントローラ
  6. *
  7. * @package Seezoo Core
  8. * @author Yoshiaki Sugimoto <neo.yoshiaki.sugimoto@gmail.com>
  9. *
  10. * ===============================================================================
  11. */
  12. class Entries extends SZ_Controller
  13. {
  14. public $page_title = 'エントリー一覧';
  15. public $page_description = '投稿されたエントリーの一覧を表示します。';
  16. public $msg;
  17. private $limit = 20;
  18. /**
  19. * コンストラクタ
  20. */
  21. function __construct()
  22. {
  23. parent::SZ_Controller();
  24. $this->load->model('blog_model');
  25. $this->info = $this->blog_model->get_blog_info();
  26. }
  27. /**
  28. * デフォルトメソッド
  29. * @param $offset
  30. */
  31. function index($offset = 0)
  32. {
  33. $this->_enable_check();
  34. $data->entry = $this->blog_model->get_all_entries($this->limit, $offset);
  35. $total = $this->blog_model->get_entry_count();
  36. $path = page_link() . 'dashboard/blog/entries/index';
  37. $data->pagination = $this->_pagination($path, $total, 5, $this->limit);
  38. $data->category = $this->blog_model->get_category_array();
  39. $this->load->view('dashboard/blog/entries', $data);
  40. }
  41. /**
  42. * エントリ詳細表示
  43. * @param int $eid
  44. */
  45. function detail($eid = 0)
  46. {
  47. $this->_enable_check();
  48. if (!$eid)
  49. {
  50. $this->msg = '対象の記事IDが見つかりませんでした。';
  51. $this->index();
  52. return;
  53. }
  54. $data->entry = $this->blog_model->get_entry_one($eid, TRUE);
  55. if (!$data->entry)
  56. {
  57. $this->msg = '対象の記事が見つかりませんでした。';
  58. $this->index();
  59. return;
  60. }
  61. $data->category = $this->blog_model->get_category_array();
  62. $this->load->view('dashboard/blog/detail', $data);
  63. }
  64. /**
  65. * 削除確認
  66. */
  67. function delete_confirm($eid = 0)
  68. {
  69. if (!$eid)
  70. {
  71. $this->msg = '対象の記事IDが見つかりませんでした。';
  72. $this->index();
  73. return;
  74. }
  75. $data->entry = $this->blog_model->get_entry_one($eid);
  76. if (!$data->entry)
  77. {
  78. $this->msg = '対象の記事が見つかりませんでした。';
  79. $this->index();
  80. return;
  81. }
  82. $data->category = $this->blog_model->get_category_array();
  83. $data->ticket = $this->_set_delete_ticket();
  84. $data->ref = $this->input->server('HTTP_REFERER');
  85. $data->id = (int)$eid;
  86. $this->load->view('dashboard/blog/delete_confirm', $data);
  87. }
  88. /**
  89. * エントリ削除
  90. */
  91. function do_delete()
  92. {
  93. $this->_enable_check();
  94. $this->_check_ticket();
  95. $eid = $this->input->post('sz_blog_id');
  96. if (!$eid)
  97. {
  98. $this->msg = '対象の記事IDが見つかりませんでした。';
  99. $this->index();
  100. return;
  101. }
  102. $ret = $this->blog_model->delete_entry($eid);
  103. redirect($this->input->post('referer'));
  104. }
  105. /**
  106. * 削除用トークンセット
  107. */
  108. function _set_delete_ticket()
  109. {
  110. $ticket = md5(uniqid(mt_rand(), TRUE));
  111. $this->session->set_userdata('sz_blog_delete_ticket', $ticket);
  112. return $ticket;
  113. }
  114. /**
  115. * 削除用トークンチェック
  116. */
  117. function _check_ticket()
  118. {
  119. $ticket = $this->input->post('sz_blog_delete_ticket');
  120. if (!$ticket || $ticket != $this->session->userdata('sz_blog_delete_ticket'))
  121. {
  122. exit('クッキーを有効にしてください。有効な場合は不正な操作です。');
  123. }
  124. }
  125. /**
  126. * ブログが利用可能か判定
  127. */
  128. function _enable_check()
  129. {
  130. // if blog id unabled, redirect index
  131. if ((int)$this->info->is_enable === 0)
  132. {
  133. redirect('dashboard/blog/settings');
  134. }
  135. }
  136. /**
  137. * ページネーションセット
  138. * @param string $path
  139. * @param int $total
  140. * @param int $segment
  141. * @param int $limit
  142. */
  143. function _pagination($path, $total, $segment, $limit)
  144. {
  145. $this->load->library('pagination');
  146. $config = array(
  147. 'base_url' => $path,
  148. 'total_rows' => $total,
  149. 'per_page' => $limit,
  150. 'uri_segment' => $segment,
  151. 'num_links' => 5,
  152. 'prev_link' => '&laquo;前へ',
  153. 'next_link' => '&raquo;次へ'
  154. );
  155. $this->pagination->initialize($config);
  156. return $this->pagination->create_links();
  157. }
  158. }