searchsubuntrackcommand.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. defined('GNUSOCIAL') || die();
  17. class SearchSubUntrackCommand extends Command
  18. {
  19. public $keyword = null;
  20. public function __construct($user, $keyword)
  21. {
  22. parent::__construct($user);
  23. $this->keyword = $keyword;
  24. }
  25. public function handle($channel)
  26. {
  27. $cur = $this->user;
  28. $searchsub = SearchSub::pkeyGet(array('search' => $this->keyword,
  29. 'profile_id' => $cur->id));
  30. if (!$searchsub) {
  31. // TRANS: Error text shown a user tries to untrack a search query they're not subscribed to.
  32. // TRANS: %s is the keyword for the search.
  33. $channel->error($cur, sprintf(_m('You are not tracking the search "%s".'), $this->keyword));
  34. return;
  35. }
  36. try {
  37. SearchSub::cancel($cur->getProfile(), $this->keyword);
  38. } catch (Exception $e) {
  39. // TRANS: Message given having failed to cancel a search subscription by untrack command.
  40. // TRANS: %s is the keyword for the query.
  41. $channel->error($cur, sprintf(
  42. _m('Could not end a search subscription for query "%s".'),
  43. $this->keyword
  44. ));
  45. return;
  46. }
  47. // TRANS: Message given having removed a search subscription by untrack command.
  48. // TRANS: %s is the keyword for the search.
  49. $channel->output($cur, sprintf(
  50. _m('You are no longer subscribed to the search "%s".'),
  51. $this->keyword
  52. ));
  53. }
  54. }