X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FOStatus%2Factions%2Fpushhub.php;h=c883647e681ef8768b58694cf9458ca49b81e894;hb=2729c622ff7ae8b657e6058548f863d96985b534;hp=842d65e7d29d9eac29518249560aa98c3e37a7e7;hpb=6c1321b108206d05b75703da22ea8abab82071bf;p=quix0rs-gnu-social.git diff --git a/plugins/OStatus/actions/pushhub.php b/plugins/OStatus/actions/pushhub.php index 842d65e7d2..c883647e68 100644 --- a/plugins/OStatus/actions/pushhub.php +++ b/plugins/OStatus/actions/pushhub.php @@ -23,20 +23,19 @@ * @maintainer Brion Vibber */ -/** - - -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) @@ -48,13 +47,13 @@ class PushHubAction extends Action 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) { @@ -63,9 +62,11 @@ class PushHubAction extends Action $this->subunsub($mode); break; case "publish": - throw new ClientException("Publishing outside feeds not supported.", 400); + // TRANS: Client exception. + throw new ClientException(_m('Publishing outside feeds not supported.'), 400); default: - throw new ClientException("Unrecognized mode '$mode'.", 400); + // TRANS: Client exception. %s is a mode. + throw new ClientException(sprintf(_m('Unrecognized mode "%s".'),$mode), 400); } } @@ -84,27 +85,31 @@ class PushHubAction extends Action $topic = $this->argUrl('hub.topic'); if (!$this->recognizedFeed($topic)) { - 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') { - 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)) { - 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) { - 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(); @@ -150,22 +155,40 @@ class PushHubAction extends Action $groupFeed = common_local_url('ApiTimelineGroup', $params); if ($feed == $userFeed) { - $user = User::staticGet('id', $id); + $user = User::getKV('id', $id); if (!$user) { - 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) { - 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; @@ -180,10 +203,13 @@ class PushHubAction extends Action $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 { - 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)); } } @@ -196,7 +222,6 @@ class PushHubAction extends Action */ protected function getSub($feed, $callback) { - return HubSub::staticGet($feed, $callback); + return HubSub::getByHashkey($feed, $callback); } } -