function create($args, $apidata) { parent::handle($args); if ($_SERVER['REQUEST_METHOD'] != 'POST') { $this->clientError(_('This method requires a POST.'), 400, $apidata['content-type']); return; } $id = $apidata['api_arg']; $other = $this->get_user($id); if (!$other) { $this->clientError(_('Could not follow user: User not found.'), 403, $apidata['content-type']); return; } $user = $apidata['user']; if ($user->isSubscribed($other)) { $errmsg = sprintf(_('Could not follow user: %s is already on your list.'), $other->nickname); $this->clientError($errmsg, 403, $apidata['content-type']); return; } $sub = new Subscription(); $sub->query('BEGIN'); $sub->subscriber = $user->id; $sub->subscribed = $other->id; $sub->created = DB_DataObject_Cast::dateTime(); # current time $result = $sub->insert(); if (!$result) { $errmsg = sprintf(_('Could not follow user: %s is already on your list.'), $other->nickname); $this->clientError($errmsg, 400, $apidata['content-type']); return; } $sub->query('COMMIT'); mail_subscribe_notify($other, $user); $type = $apidata['content-type']; $this->init_document($type); $this->show_profile($other, $type); $this->end_document($type); }
function subs_notify_email($listenee, $listener) { mail_subscribe_notify($listenee, $listener); }