searchsubtrackcommand.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. class SearchSubTrackCommand extends Command
  3. {
  4. var $keyword = null;
  5. function __construct($user, $keyword)
  6. {
  7. parent::__construct($user);
  8. $this->keyword = $keyword;
  9. }
  10. function handle($channel)
  11. {
  12. $cur = $this->user;
  13. $searchsub = SearchSub::pkeyGet(array('search' => $this->keyword,
  14. 'profile_id' => $cur->id));
  15. if ($searchsub) {
  16. // TRANS: Error text shown a user tries to track a search query they're already subscribed to.
  17. $channel->error($cur, sprintf(_m('You are already tracking the search "%s".'), $this->keyword));
  18. return;
  19. }
  20. try {
  21. SearchSub::start($cur->getProfile(), $this->keyword);
  22. } catch (Exception $e) {
  23. // TRANS: Message given having failed to set up a search subscription by track command.
  24. $channel->error($cur, sprintf(_m('Could not start a search subscription for query "%s".'),
  25. $this->keyword));
  26. return;
  27. }
  28. // TRANS: Message given having added a search subscription by track command.
  29. $channel->output($cur, sprintf(_m('You are subscribed to the search "%s".'),
  30. $this->keyword));
  31. }
  32. }