From: Brion Vibber Date: Thu, 17 Mar 2011 00:08:09 +0000 (-0700) Subject: SearchSub plugin: 'track X', 'untrack X', 'tracking', 'track off' commands now overri... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=0754edf9a24983e8a9ec48baf0086e8437e3f399;p=quix0rs-gnu-social.git SearchSub plugin: 'track X', 'untrack X', 'tracking', 'track off' commands now overridden :D --- diff --git a/plugins/SearchSub/SearchSubPlugin.php b/plugins/SearchSub/SearchSubPlugin.php index f7da8c44d9..c07f7695da 100644 --- a/plugins/SearchSub/SearchSubPlugin.php +++ b/plugins/SearchSub/SearchSubPlugin.php @@ -81,6 +81,10 @@ class SearchSubPlugin extends Plugin case 'SearchsubsAction': case 'SearchSubForm': case 'SearchUnsubForm': + case 'SearchSubTrackCommand': + case 'SearchSubTrackOffCommand': + case 'SearchSubTrackingCommand': + case 'SearchSubUntrackCommand': include_once $dir.'/'.strtolower($cls).'.php'; return false; default: @@ -269,4 +273,49 @@ class SearchSubPlugin extends Plugin } return true; } + + /** + * Replace the built-in stub track commands with ones that control + * search subscriptions. + * + * @param CommandInterpreter $cmd + * @param string $arg + * @param User $user + * @param Command $result + * @return boolean hook result + */ + function onEndInterpretCommand($cmd, $arg, $user, &$result) + { + if ($result instanceof TrackCommand) { + $result = new SearchSubTrackCommand($user, $arg); + return false; + } else if ($result instanceof TrackOffCommand) { + $result = new SearchSubTrackOffCommand($user); + return false; + } else if ($result instanceof TrackingCommand) { + $result = new SearchSubTrackingCommand($user); + return false; + } else if ($result instanceof UntrackCommand) { + $result = new SearchSubUntrackCommand($user, $arg); + return false; + } else { + return true; + } + } + + function onHelpCommandMessages($cmd, &$commands) + { + // TRANS: Help message for IM/SMS command "track " + $commands["track "] = _m('COMMANDHELP', "Start following notices matching the given search query."); + // TRANS: Help message for IM/SMS command "untrack " + $commands["untrack "] = _m('COMMANDHELP', "Stop following notices matching the given search query."); + // TRANS: Help message for IM/SMS command "track off" + $commands["track off"] = _m('COMMANDHELP', "Disable all tracked search subscriptions."); + // TRANS: Help message for IM/SMS command "untrack all" + $commands["untrack all"] = _m('COMMANDHELP', "Disable all tracked search subscriptions."); + // TRANS: Help message for IM/SMS command "tracks" + $commands["tracks"] = _m('COMMANDHELP', "List all your search subscriptions."); + // TRANS: Help message for IM/SMS command "tracking" + $commands["tracking"] = _m('COMMANDHELP', "List all your search subscriptions."); + } } diff --git a/plugins/SearchSub/searchsubtrackcommand.php b/plugins/SearchSub/searchsubtrackcommand.php new file mode 100644 index 0000000000..bba2cb36e7 --- /dev/null +++ b/plugins/SearchSub/searchsubtrackcommand.php @@ -0,0 +1,38 @@ +keyword = $keyword; + } + + function handle($channel) + { + $cur = $this->user; + $searchsub = SearchSub::pkeyGet(array('search' => $this->keyword, + 'profile_id' => $cur->id)); + + if ($searchsub) { + // TRANS: Error text shown a user tries to track a search query they're already subscribed to. + $channel->error($cur, sprintf(_m('You are already tracking the search "%s".'), $this->keyword)); + return; + } + + try { + SearchSub::start($cur->getProfile(), $this->keyword); + } catch (Exception $e) { + // TRANS: Message given having failed to set up a search subscription by track command. + $channel->error($cur, sprintf(_m('Could not start a search subscription for query "%s".'), + $this->keyword)); + return; + } + + // TRANS: Message given having added a search subscription by track command. + $channel->output($cur, sprintf(_m('You are subscribed to the search "%s".'), + $this->keyword)); + } +} \ No newline at end of file diff --git a/plugins/SearchSub/searchsubtrackingcommand.php b/plugins/SearchSub/searchsubtrackingcommand.php new file mode 100644 index 0000000000..385a22b8ba --- /dev/null +++ b/plugins/SearchSub/searchsubtrackingcommand.php @@ -0,0 +1,27 @@ +user; + $all = new SearchSub(); + $all->profile_id = $cur->id; + $all->find(); + + if ($all->N == 0) { + // TRANS: Error text shown a user tries to disable all a search subscriptions with track off command, but has none. + $channel->error($cur, _m('You are not tracking any searches.')); + return; + } + + $list = array(); + while ($all->fetch()) { + $list[] = $all->search; + } + + // TRANS: Message given having disabled all search subscriptions with 'track off'. + $channel->output($cur, sprintf(_m('You are tracking searches for: %s'), + '"' . implode('", "', $list) . '"')); + } +} \ No newline at end of file diff --git a/plugins/SearchSub/searchsubtrackoffcommand.php b/plugins/SearchSub/searchsubtrackoffcommand.php new file mode 100644 index 0000000000..1e5eb97ebc --- /dev/null +++ b/plugins/SearchSub/searchsubtrackoffcommand.php @@ -0,0 +1,33 @@ +user; + $all = new SearchSub(); + $all->profile_id = $cur->id; + $all->find(); + + if ($all->N == 0) { + // TRANS: Error text shown a user tries to disable all a search subscriptions with track off command, but has none. + $channel->error($cur, _m('You are not tracking any searches.')); + return; + } + + $profile = $cur->getProfile(); + while ($all->fetch()) { + try { + SearchSub::cancel($profile, $all->search); + } catch (Exception $e) { + // TRANS: Message given having failed to cancel one of the search subs with 'track off' command. + $channel->error($cur, sprintf(_m('Error disabling search subscription for query "%s".'), + $all->search)); + return; + } + } + + // TRANS: Message given having disabled all search subscriptions with 'track off'. + $channel->output($cur, _m('Disabled all your search subscriptions.')); + } +} \ No newline at end of file diff --git a/plugins/SearchSub/searchsubuntrackcommand.php b/plugins/SearchSub/searchsubuntrackcommand.php new file mode 100644 index 0000000000..9fb84cd130 --- /dev/null +++ b/plugins/SearchSub/searchsubuntrackcommand.php @@ -0,0 +1,38 @@ +keyword = $keyword; + } + + function handle($channel) + { + $cur = $this->user; + $searchsub = SearchSub::pkeyGet(array('search' => $this->keyword, + 'profile_id' => $cur->id)); + + if (!$searchsub) { + // TRANS: Error text shown a user tries to untrack a search query they're not subscribed to. + $channel->error($cur, sprintf(_m('You are not tracking the search "%s".'), $this->keyword)); + return; + } + + try { + SearchSub::cancel($cur->getProfile(), $this->keyword); + } catch (Exception $e) { + // TRANS: Message given having failed to cancel a search subscription by untrack command. + $channel->error($cur, sprintf(_m('Could not end a search subscription for query "%s".'), + $this->keyword)); + return; + } + + // TRANS: Message given having removed a search subscription by untrack command. + $channel->output($cur, sprintf(_m('You are no longer subscribed to the search "%s".'), + $this->keyword)); + } +} \ No newline at end of file