return parent::arg($arg, $def);
}
- function prepare($args)
+ protected function prepare(array $args=array())
{
- StatusNet::setApi(true); // reduce exception reports to aid in debugging
+ GNUsocial::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) {
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') {
- // 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)) {
// 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) {
// 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);
- if (!$sub) {
+ $sub = HubSub::getByHashkey($topic, $callback);
+ if (!$sub instanceof HubSub) {
// Creating a new one!
$sub = new HubSub();
$sub->topic = $topic;
}
}
- if (!common_config('queue', 'enabled')) {
- // Won't be able to background it.
- $verify = 'sync';
- }
- if ($verify == 'async') {
- $sub->scheduleVerify($mode, $token);
- header('HTTP/1.1 202 Accepted');
- } else {
+ $verify = $this->arg('hub.verify'); // TODO: deprecated
+ $token = $this->arg('hub.verify_token', null); // TODO: deprecated
+ if ($verify == 'sync') { // pre-0.4 PuSH
$sub->verify($mode, $token);
header('HTTP/1.1 204 No Content');
+ } else { // If $verify is not "sync", we might be using PuSH 0.4
+ $sub->scheduleVerify($mode, $token); // If we were certain it's PuSH 0.4, token could be removed
+ header('HTTP/1.1 202 Accepted');
}
}
* user or group Atom feeds.
*
* @param string $feed URL
- * @return boolean true if it matches
+ * @return boolean true if it matches, false if not a recognized local feed
+ * @throws exception if local entity does not exist
*/
- function recognizedFeed($feed)
+ protected function recognizedFeed($feed)
{
$matches = array();
+ // Simple mapping to local ID for user or group
if (preg_match('!/(\d+)\.atom$!', $feed, $matches)) {
$id = $matches[1];
$params = array('id' => $id, 'format' => 'atom');
- $userFeed = common_local_url('ApiTimelineUser', $params);
- $groupFeed = common_local_url('ApiTimelineGroup', $params);
- if ($feed == $userFeed) {
- $user = User::staticGet('id', $id);
- if (!$user) {
+ // Double-check against locally generated URLs
+ switch ($feed) {
+ case common_local_url('ApiTimelineUser', $params):
+ $user = User::getKV('id', $id);
+ if (!$user instanceof User) {
// 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;
+ throw new ClientException(sprintf(_m('Invalid hub.topic "%s". User does not exist.'),$feed));
}
- }
- if ($feed == $groupFeed) {
- $user = User_group::staticGet('id', $id);
- if (!$user) {
+ return true;
+
+ case common_local_url('ApiTimelineGroup', $params):
+ $group = Local_group::getKV('group_id', $id);
+ if (!$group instanceof Local_group) {
// 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;
+ throw new ClientException(sprintf(_m('Invalid hub.topic "%s". Local_group does not exist.'),$feed));
}
+ return true;
}
- } else if (preg_match('!/(\d+)/lists/(\d+)/statuses\.atom$!', $feed, $matches)) {
+ common_debug("Feed was not recognized by any local User or Group Atom feed URLs: {$feed}");
+ return false;
+ }
+
+ // Profile lists are unique per user, so we need both IDs
+ 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::staticGet('id', $id);
- $user = User::staticGet('id', $user);
- if (!$list || !$user || $list->tagger != $user->id) {
+ // Double-check against locally generated URLs
+ switch ($feed) {
+ case common_local_url('ApiTimelineList', $params):
+ $list = Profile_list::getKV('id', $id);
+ $user = User::getKV('id', $user);
+ if (!$list instanceof Profile_list || !$user instanceof User || $list->tagger != $user->id) {
// TRANS: Client exception. %s is a feed URL.
- throw new ClientException(sprintf(_m('Invalid hub.topic %s; people tag does not exist.'),$feed));
- } else {
- return true;
+ throw new ClientException(sprintf(_m('Invalid hub.topic %s; list does not exist.'),$feed));
}
+ return true;
}
- common_log(LOG_DEBUG, "Not a user, group or people tag feed? $feed $userFeed $groupFeed $listFeed");
+ common_debug("Feed was not recognized by any local Profile_list Atom feed URL: {$feed}");
+ return false;
}
- common_log(LOG_DEBUG, "LOST $feed");
+
+ common_debug("Unknown feed URL structure, can't match against local user, group or profile_list: {$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 {
// TRANS: Client exception.
*/
protected function getSub($feed, $callback)
{
- return HubSub::staticGet($feed, $callback);
+ return HubSub::getByHashkey($feed, $callback);
}
}