searchsubtrackcommand.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 SearchSubTrackCommand 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 track a search query they're already subscribed to.
  32. $channel->error($cur, sprintf(_m('You are already tracking the search "%s".'), $this->keyword));
  33. return;
  34. }
  35. try {
  36. SearchSub::start($cur->getProfile(), $this->keyword);
  37. } catch (Exception $e) {
  38. // TRANS: Message given having failed to set up a search subscription by track command.
  39. $channel->error($cur, sprintf(
  40. _m('Could not start a search subscription for query "%s".'),
  41. $this->keyword
  42. ));
  43. return;
  44. }
  45. // TRANS: Message given having added a search subscription by track command.
  46. $channel->output($cur, sprintf(
  47. _m('You are subscribed to the search "%s".'),
  48. $this->keyword
  49. ));
  50. }
  51. }