* @maintainer Brion Vibber <brion@status.net>
*/
-/**
-
-
-Things to consider...
-* should we purge incomplete subscriptions that never get a verification pingback?
-* when can we send subscription renewal checks?
- - at next send time probably ok
-* when can we handle trimming of subscriptions?
- - at next send time probably ok
-* should we keep a fail count?
-
-*/
+if (!defined('STATUSNET')) {
+ exit(1);
+}
+/**
+ * Things to consider...
+ * should we purge incomplete subscriptions that never get a verification pingback?
+ * when can we send subscription renewal checks?
+ * - at next send time probably ok
+ * when can we handle trimming of subscriptions?
+ * - at next send time probably ok
+ * should we keep a fail count?
+ */
class PushHubAction extends Action
{
function arg($arg, $def=null)
return parent::arg($arg, $def);
}
- function prepare($args)
+ protected function prepare($args)
{
StatusNet::setApi(true); // reduce exception reports to aid in debugging
return parent::prepare($args);
}
- function handle()
+ protected function handle()
{
$mode = $this->trimmed('hub.mode');
switch ($mode) {
$this->subunsub($mode);
break;
case "publish":
- // @todo i18n FIXME: added i18n and use sprintf when using parameters.
- throw new ClientException("Publishing outside feeds not supported.", 400);
+ // TRANS: Client exception.
+ throw new ClientException(_m('Publishing outside feeds not supported.'), 400);
default:
- // @todo i18n FIXME: added i18n and use sprintf when using parameters.
- throw new ClientException("Unrecognized mode '$mode'.", 400);
+ // TRANS: Client exception. %s is a mode.
+ throw new ClientException(sprintf(_m('Unrecognized mode "%s".'),$mode), 400);
}
}
$topic = $this->argUrl('hub.topic');
if (!$this->recognizedFeed($topic)) {
- // @todo i18n FIXME: added i18n and use sprintf when using parameters.
- throw new ClientException("Unsupported hub.topic $topic; this hub only serves local user and group Atom feeds.");
+ // TRANS: Client exception. %s is a topic.
+ throw new ClientException(sprintf(_m('Unsupported hub.topic %s this hub only serves local user and group Atom feeds.'),$topic));
}
$verify = $this->arg('hub.verify'); // @fixme may be multiple
if ($verify != 'sync' && $verify != 'async') {
- // @todo i18n FIXME: added i18n and use sprintf when using parameters.
- throw new ClientException("Invalid hub.verify $verify; must be sync or async.");
+ // TRANS: Client exception. %s is sync or async.
+ throw new ClientException(sprintf(_m('Invalid hub.verify "%s". It must be sync or async.'),$verify));
}
$lease = $this->arg('hub.lease_seconds', null);
if ($mode == 'subscribe' && $lease != '' && !preg_match('/^\d+$/', $lease)) {
- // @todo i18n FIXME: added i18n and use sprintf when using parameters.
- throw new ClientException("Invalid hub.lease $lease; must be empty or positive integer.");
+ // TRANS: Client exception. %s is the invalid lease value.
+ throw new ClientException(sprintf(_m('Invalid hub.lease "%s". It must be empty or positive integer.'),$lease));
}
$token = $this->arg('hub.verify_token', null);
$secret = $this->arg('hub.secret', null);
if ($secret != '' && strlen($secret) >= 200) {
- // @todo i18n FIXME: added i18n and use sprintf when using parameters.
- throw new ClientException("Invalid hub.secret $secret; must be under 200 bytes.");
+ // TRANS: Client exception. %s is the invalid hub secret.
+ throw new ClientException(sprintf(_m('Invalid hub.secret "%s". It must be under 200 bytes.'),$secret));
}
- $sub = HubSub::staticGet($topic, $callback);
+ $sub = HubSub::getByHashkey($topic, $callback);
if (!$sub) {
// Creating a new one!
$sub = new HubSub();
$groupFeed = common_local_url('ApiTimelineGroup', $params);
if ($feed == $userFeed) {
- $user = User::staticGet('id', $id);
+ $user = User::getKV('id', $id);
if (!$user) {
- // @todo i18n FIXME: added i18n and use sprintf when using parameters.
- throw new ClientException("Invalid hub.topic $feed; user doesn't exist.");
+ // TRANS: Client exception. %s is a feed URL.
+ throw new ClientException(sprintt(_m('Invalid hub.topic "%s". User does not exist.'),$feed));
} else {
return true;
}
}
if ($feed == $groupFeed) {
- $user = User_group::staticGet('id', $id);
+ $user = User_group::getKV('id', $id);
if (!$user) {
- // @todo i18n FIXME: added i18n and use sprintf when using parameters.
- throw new ClientException("Invalid hub.topic $feed; group doesn't exist.");
+ // TRANS: Client exception. %s is a feed URL.
+ throw new ClientException(sprintf(_m('Invalid hub.topic "%s". Group does not exist.'),$feed));
+ } else {
+ return true;
+ }
+ }
+ } else if (preg_match('!/(\d+)/lists/(\d+)/statuses\.atom$!', $feed, $matches)) {
+ $user = $matches[1];
+ $id = $matches[2];
+ $params = array('user' => $user, 'id' => $id, 'format' => 'atom');
+ $listFeed = common_local_url('ApiTimelineList', $params);
+
+ if ($feed == $listFeed) {
+ $list = Profile_list::getKV('id', $id);
+ $user = User::getKV('id', $user);
+ if (!$list || !$user || $list->tagger != $user->id) {
+ // TRANS: Client exception. %s is a feed URL.
+ throw new ClientException(sprintf(_m('Invalid hub.topic %s; list does not exist.'),$feed));
} else {
return true;
}
}
- common_log(LOG_DEBUG, "Not a user or group feed? $feed $userFeed $groupFeed");
+ common_log(LOG_DEBUG, "Not a user, group or people tag feed? $feed $userFeed $groupFeed $listFeed");
}
common_log(LOG_DEBUG, "LOST $feed");
return false;
$url = $this->arg($arg);
$params = array('domain_check' => false, // otherwise breaks my local tests :P
'allowed_schemes' => array('http', 'https'));
- if (Validate::uri($url, $params)) {
+ $validate = new Validate;
+ if ($validate->uri($url, $params)) {
return $url;
} else {
- // @todo i18n FIXME: added i18n and use sprintf when using parameters.
- throw new ClientException("Invalid URL passed for $arg: '$url'");
+ // TRANS: Client exception.
+ // TRANS: %1$s is this argument to the method this exception occurs in, %2$s is a URL.
+ throw new ClientException(sprintf(_m('Invalid URL passed for %1$s: "%2$s"'),$arg,$url));
}
}
*/
protected function getSub($feed, $callback)
{
- return HubSub::staticGet($feed, $callback);
+ return HubSub::getByHashkey($feed, $callback);
}
}