Baidupush.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace app\admin\controller;
  3. use addons\baidupush\library\Push;
  4. use app\common\controller\Backend;
  5. /**
  6. * 百度推送管理
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Baidupush extends Backend
  11. {
  12. public function _initialize()
  13. {
  14. parent::_initialize();
  15. }
  16. public function index()
  17. {
  18. $config = get_addon_config('baidupush');
  19. $config['status'] = explode(',', $config['status']);
  20. $this->view->assign('addonConfig', $config);
  21. return $this->view->fetch();
  22. }
  23. /**
  24. * 快速收录提交
  25. */
  26. public function daily()
  27. {
  28. $action = $this->request->post("action");
  29. $urls = $this->request->post("urls");
  30. $urls = explode("\n", str_replace("\r", "", $urls));
  31. $urls = array_unique(array_filter($urls));
  32. if (!$urls) {
  33. $this->error("URL列表不能为空");
  34. }
  35. $result = false;
  36. if ($action == 'urls') {
  37. $result = Push::init(['type' => 'daily'])->realtime($urls);
  38. } elseif ($action == 'del') {
  39. $result = Push::init(['type' => 'daily'])->delete($urls);
  40. }
  41. if ($result) {
  42. $data = Push::init()->getData();
  43. $this->success("推送成功", null, $data);
  44. } else {
  45. $this->error("推送失败:" . Push::init()->getError());
  46. }
  47. }
  48. /**
  49. * 普通收录
  50. */
  51. public function normal()
  52. {
  53. $action = $this->request->post("action");
  54. $urls = $this->request->post("urls");
  55. $urls = explode("\n", str_replace("\r", "", $urls));
  56. $urls = array_unique(array_filter($urls));
  57. if (!$urls) {
  58. $this->error("URL列表不能为空");
  59. }
  60. $result = false;
  61. if ($action == 'urls') {
  62. $result = Push::init(['type' => 'normal'])->realtime($urls);
  63. } elseif ($action == 'del') {
  64. $result = Push::init(['type' => 'normal'])->delete($urls);
  65. }
  66. if ($result) {
  67. $data = Push::init()->getData();
  68. $this->success("推送成功", null, $data);
  69. } else {
  70. $this->error("推送失败:" . Push::init()->getError());
  71. }
  72. }
  73. }