PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/seezoo/seezoo/
PHP | 180 lines | 112 code | 24 blank | 44 comment | 15 complexity | 6852b7d2e1530e0e57737f6b7030822e MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * ===============================================================================
  4. *
  5. * Seezoo dashboard ブログping送信先管理コントローラ
  6. *
  7. * @package Seezoo Core
  8. * @author Yoshiaki Sugimoto <neo.yoshiaki.sugimoto@gmail.com>
  9. *
  10. * ===============================================================================
  11. */
  12. class Ping extends SZ_Controller
  13. {
  14. public $page_title = 'ping送信先管理';
  15. public $page_description = '新規記事投稿時のping送信先を管理します。';
  16. public $msg;
  17. public $ticket_name = 'sz_ticket';
  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. */
  30. function index()
  31. {
  32. $this->_enable_check();
  33. $data->ping_list = $this->blog_model->get_ping_list();
  34. $data->times = 0;
  35. $data->js_token = $this->_set_ticket();
  36. $this->load->view('dashboard/blog/ping_settings', $data);
  37. }
  38. /**
  39. * Ajax応答:ping送信先追加
  40. * @param string $token
  41. */
  42. function ajax_add_ping($token = FALSE)
  43. {
  44. if (!$this->session->userdata('sz_token') || $this->session->userdata('sz_token') !== $token)
  45. {
  46. exit('error');
  47. }
  48. $data = array(
  49. 'ping_server' => $this->input->post('ping_server', TRUE),
  50. 'ping_name' => $this->input->post('ping_name', TRUE)
  51. );
  52. $ret = $this->blog_model->add_new_ping($data);
  53. if ($ret && is_numeric($ret))
  54. {
  55. $data['sz_blog_ping_list'] = $ret;
  56. echo json_encode($data);
  57. }
  58. else
  59. {
  60. echo 'error';
  61. }
  62. exit;
  63. }
  64. /**
  65. * ping送信先編集
  66. * @param $pid
  67. * @param $token
  68. */
  69. function edit_ping($pid, $token = FALSE)
  70. {
  71. if (!$token|| $this->session->flashdata($this->ticket_name) !== $token || (int)$pid === 0)
  72. {
  73. exit('error');
  74. }
  75. $this->session->keep_flashdata($this->ticket_name);
  76. $data->ping = $this->blog_model->get_ping_one($pid);
  77. $data->ticket = $token;
  78. $this->load->view('dashboard/blog/edit_ping', $data);
  79. }
  80. /**
  81. * Ajax応答:ping送信先削除
  82. * @param $pid
  83. * @param $token
  84. */
  85. function delete_ping($pid, $token = FALSE)
  86. {
  87. if (!$token|| $this->session->flashdata($this->ticket_name) !== $token || (int)$pid === 0)
  88. {
  89. exit('error');
  90. }
  91. $ret = $this->blog_model->delete_ping_data($pid);
  92. $this->session->keep_flashdata($this->ticket_name);
  93. echo ($ret) ? 'complete' : 'error';
  94. }
  95. /**
  96. * Ajax応答:ping送信先編集実行
  97. */
  98. function ajax_do_edit_ping()
  99. {
  100. $token = $this->input->post('ticket');
  101. if (!$token|| $this->session->flashdata($this->ticket_name) !== $token || (int)$this->input->post('pid') === 0)
  102. {
  103. exit('error');
  104. }
  105. $data = array(
  106. 'ping_server' => $this->input->post('ping_server', TRUE),
  107. 'ping_name' => $this->input->post('ping_name', TRUE)
  108. );
  109. $ret = $this->blog_model->update_ping_data((int)$this->input->post('pid'), $data);
  110. if ($ret)
  111. {
  112. echo 'complete';
  113. }
  114. else
  115. {
  116. $this->session->keep_flashdata($this->ticket_name);
  117. echo 'error';
  118. }
  119. exit;
  120. }
  121. /**
  122. * ブログが利用可能かどうか判定
  123. */
  124. function _enable_check()
  125. {
  126. // if blog id unabled, redirect index
  127. if ((int)$this->info->is_enable === 0)
  128. {
  129. redirect('dashboard/blog/settings/');
  130. }
  131. }
  132. /**
  133. * トークン生成
  134. */
  135. function _set_ticket()
  136. {
  137. $ticket = md5(uniqid(mt_rand(), TRUE));
  138. $this->session->set_flashdata($this->ticket_name, $ticket);
  139. return $ticket;
  140. }
  141. /**
  142. * トークンチェック
  143. * @param $ticket
  144. */
  145. function _check_ticket($ticket = FALSE)
  146. {
  147. if (!$ticket)
  148. {
  149. $ticket = $this->input->post($this->ticket_name);
  150. }
  151. if (!$ticket || $ticket !== $this->session->flashdata($this->ticket_name))
  152. {
  153. exit('不正な操作です。また、リロードは禁止されています。');
  154. }
  155. }
  156. }