tagController.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * Controller to handle every tag actions.
  4. */
  5. class FreshRSS_tag_Controller extends Minz_ActionController {
  6. /**
  7. * This action is called before every other action in that class. It is
  8. * the common boiler plate for every action. It is triggered by the
  9. * underlying framework.
  10. */
  11. public function firstAction() {
  12. if (!FreshRSS_Auth::hasAccess()) {
  13. Minz_Error::error(403);
  14. }
  15. // If ajax request, we do not print layout
  16. $this->ajax = Minz_Request::param('ajax');
  17. if ($this->ajax) {
  18. $this->view->_layout(false);
  19. Minz_Request::_param('ajax');
  20. }
  21. }
  22. /**
  23. * This action adds (checked=true) or removes (checked=false) a tag to an entry.
  24. */
  25. public function tagEntryAction() {
  26. if (Minz_Request::isPost()) {
  27. $id_tag = Minz_Request::param('id_tag');
  28. $name_tag = trim(Minz_Request::param('name_tag'));
  29. $id_entry = Minz_Request::param('id_entry');
  30. $checked = Minz_Request::paramTernary('checked');
  31. if ($id_entry != false) {
  32. $tagDAO = FreshRSS_Factory::createTagDao();
  33. if ($id_tag == 0 && $name_tag != '' && $checked) {
  34. //Create new tag
  35. $id_tag = $tagDAO->addTag(array('name' => $name_tag));
  36. }
  37. if ($id_tag != 0) {
  38. $tagDAO->tagEntry($id_tag, $id_entry, $checked);
  39. }
  40. }
  41. } else {
  42. Minz_Error::error(405);
  43. }
  44. if (!$this->ajax) {
  45. Minz_Request::forward(array(
  46. 'c' => 'index',
  47. 'a' => 'index',
  48. ), true);
  49. }
  50. }
  51. public function deleteAction() {
  52. if (Minz_Request::isPost()) {
  53. $id_tag = Minz_Request::param('id_tag');
  54. if ($id_tag != false) {
  55. $tagDAO = FreshRSS_Factory::createTagDao();
  56. $tagDAO->deleteTag($id_tag);
  57. }
  58. } else {
  59. Minz_Error::error(405);
  60. }
  61. if (!$this->ajax) {
  62. Minz_Request::forward(array(
  63. 'c' => 'index',
  64. 'a' => 'index',
  65. ), true);
  66. }
  67. }
  68. public function getTagsForEntryAction() {
  69. $this->view->_layout(false);
  70. header('Content-Type: application/json; charset=UTF-8');
  71. header('Cache-Control: private, no-cache, no-store, must-revalidate');
  72. $id_entry = Minz_Request::param('id_entry', 0);
  73. $tagDAO = FreshRSS_Factory::createTagDao();
  74. $this->view->tags = $tagDAO->getTagsForEntry($id_entry);
  75. }
  76. }