PageRenderTime 50ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/seezoo/seezoo/
PHP | 164 lines | 95 code | 21 blank | 48 comment | 8 complexity | 7b888a9002194693d7d07cb1054a8b07 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 Comment extends SZ_Controller
  13. {
  14. public $page_title = 'コメント管理';
  15. public $page_description = '投稿につけられたコメントを管理します。';
  16. public $msg;
  17. public $ticket_name = 'sz_ticket';
  18. private $limit = 20;
  19. /**
  20. * コンストラクタ
  21. */
  22. function __construct()
  23. {
  24. parent::SZ_Controller();
  25. $this->load->model('blog_model');
  26. $this->info = $this->blog_model->get_blog_info();
  27. }
  28. /**
  29. * デフォルトメソッド
  30. * @param $offset
  31. */
  32. function index($offset = 0)
  33. {
  34. $this->_enable_check();
  35. $data->comments = $this->blog_model->get_posted_comments($this->limit, $offset);
  36. $total = $this->blog_model->get_posted_comments_count();
  37. // make display total string
  38. $endoftotal = (($offset+ $this->limit) > $total) ? $total : ($offset + $this->limit);
  39. if($total > 0)
  40. {
  41. $data->total = $total . '件中' . ($offset + 1) . '-' . $endoftotal . '件表示';
  42. }
  43. else
  44. {
  45. $data->total = '';
  46. }
  47. $path = page_link() . 'dashboard/blog/comment/index/';
  48. // set pagination
  49. $data->pagination = $this->_pagination($path, $total, 5, $this->limit);
  50. $data->titles = $this->blog_model->get_entry_titles();
  51. $data->ticket = $this->_set_ticket();
  52. $this->load->view('dashboard/blog/comments', $data);
  53. }
  54. /**
  55. * Ajax応答用コメント削除
  56. * @param $cid
  57. * @param $token
  58. */
  59. function delete_comment($cid, $token = FALSE)
  60. {
  61. if (!$token || $token !== $this->session->userdata('sz_token'))
  62. {
  63. echo 'access denied';
  64. }
  65. $ret = $this->blog_model->delete_comment_one((int)$cid);
  66. echo ($ret) ? 'complete' : 'error';
  67. exit;
  68. }
  69. /**
  70. * 選択されたコメントを一括削除
  71. */
  72. function delete_comment_selectables()
  73. {
  74. $this->_check_ticket();
  75. if (!$this->input->post('sz_delete_comment'))
  76. {
  77. redirect('dashboard/blog/comment');
  78. }
  79. $com = $this->input->post('sz_delete_comment');
  80. $ret = $this->blog_model->delete_comment($com);
  81. redirect('dashboard/blog/comment');
  82. }
  83. /**
  84. * ページネーションセット
  85. * @access private
  86. * @param string $path
  87. * @param int $total
  88. * @param int $segment
  89. * @param int $limit
  90. */
  91. function _pagination($path, $total, $segment, $limit)
  92. {
  93. $this->load->library('pagination');
  94. $config = array(
  95. 'base_url' => $path,
  96. 'total_rows' => $total,
  97. 'per_page' => $limit,
  98. 'uri_segment' => $segment,
  99. 'num_links' => 5,
  100. 'prev_link' => '&laquo;前へ',
  101. 'next_link' => '&raquo;次へ'
  102. );
  103. $this->pagination->initialize($config);
  104. return $this->pagination->create_links();
  105. }
  106. /**
  107. * トークン生成
  108. * @access private
  109. */
  110. function _set_ticket()
  111. {
  112. $ticket = md5(uniqid(mt_rand(), TRUE));
  113. $this->session->set_flashdata($this->ticket_name, $ticket);
  114. return $ticket;
  115. }
  116. /**
  117. * トークンチェック
  118. * @access private
  119. * @param string $ticket
  120. */
  121. function _check_ticket($ticket = FALSE)
  122. {
  123. if (!$ticket)
  124. {
  125. $ticket = $this->input->post($this->ticket_name);
  126. }
  127. if (!$ticket || $ticket !== $this->session->flashdata($this->ticket_name))
  128. {
  129. exit('不正な操作です。また、リロードは禁止されています。');
  130. }
  131. }
  132. /**
  133. * ブログが利用可能かどうか判定
  134. */
  135. function _enable_check()
  136. {
  137. // if blog id unabled, redirect index
  138. if ((int)$this->info->is_enable === 0)
  139. {
  140. redirect('dashboard/blog/settings');
  141. }
  142. }
  143. }