/** * Handle the request * * Get favs and return them as json object * * @param array $args $_REQUEST data (unused) * * @return void */ protected function handle() { parent::handle(); $fave = new Fave(); $fave->selectAdd(); $fave->selectAdd('user_id'); $fave->notice_id = $this->original->id; $fave->orderBy('modified'); if (!is_null($this->cnt)) { $fave->limit(0, $this->cnt); } $ids = $fave->fetchAll('user_id'); // get nickname and profile image $ids_with_profile_data = array(); $i = 0; foreach ($ids as $id) { $profile = Profile::getKV('id', $id); $ids_with_profile_data[$i]['user_id'] = $id; $ids_with_profile_data[$i]['nickname'] = $profile->nickname; $ids_with_profile_data[$i]['fullname'] = $profile->fullname; $ids_with_profile_data[$i]['profileurl'] = $profile->profileurl; $profile = new Profile(); $profile->id = $id; $avatarurl = $profile->avatarUrl(24); $ids_with_profile_data[$i]['avatarurl'] = $avatarurl; $i++; } $this->initDocument('json'); $this->showJsonObjects($ids_with_profile_data); $this->endDocument('json'); }
/** * Handle the request * * Grab the file from the 'media' param, then store, and shorten * * @todo Upload throttle! * * @param array $args $_REQUEST data (unused) * * @return void */ function handle($args) { parent::handle($args); if ($_SERVER['REQUEST_METHOD'] != 'POST') { $this->clientError(_('This method requires a POST.'), 400, $this->format); return; } // Workaround for PHP returning empty $_POST and $_FILES when POST // length > post_max_size in php.ini if (empty($_FILES) && empty($_POST) && $_SERVER['CONTENT_LENGTH'] > 0) { // TRANS: Client error displayed when the number of bytes in a POST request exceeds a limit. // TRANS: %s is the number of bytes of the CONTENT_LENGTH. $msg = _m('The server was unable to handle that much POST data (%s byte) due to its current configuration.', 'The server was unable to handle that much POST data (%s bytes) due to its current configuration.', intval($_SERVER['CONTENT_LENGTH'])); $this->clientError(sprintf($msg, $_SERVER['CONTENT_LENGTH'])); return; } $upload = null; try { $upload = MediaFile::fromUpload('media', $this->auth_user); } catch (Exception $e) { $this->clientError($e->getMessage(), $e->getCode()); return; } if (isset($upload)) { $this->showResponse($upload); } else { $this->clientError(_('Upload failed.')); return; } }
/** * Handle the request * * Check the format and show the user info * * @param array $args $_REQUEST data (unused) * * @return void */ function handle($args) { parent::handle($args); if ($_SERVER['REQUEST_METHOD'] != 'POST') { $this->clientError(_('This method requires a POST.'), 400, $this->format); return; } if (!in_array($this->format, array('xml', 'json'))) { $this->clientError(_('API method not found.'), 404, $this->format); return; } if (empty($this->other)) { $this->clientError(_('Could not follow user: User not found.'), 403, $this->format); return; } if ($this->user->isSubscribed($this->other)) { $errmsg = sprintf(_('Could not follow user: %s is already on your list.'), $this->other->nickname); $this->clientError($errmsg, 403, $this->format); return; } $result = subs_subscribe_to($this->user, $this->other); if (is_string($result)) { $this->clientError($result, 403, $this->format); return; } $this->initDocument($this->format); $this->showProfile($this->other, $this->format); $this->endDocument($this->format); }
/** * Handle the request * * Save the new message * * @param array $args $_REQUEST data (unused) * * @return void */ protected function handle() { parent::handle(); if (empty($this->user) || empty($this->other)) { // TRANS: Client error displayed when trying to block a non-existing user or a user from another site. $this->clientError(_('No such user.'), 404); } // Don't allow blocking yourself! if ($this->user->id == $this->other->id) { // TRANS: Client error displayed when users try to block themselves. $this->clientError(_("You cannot block yourself!"), 403); } if (!$this->user->hasBlocked($this->other)) { if (Event::handle('StartBlockProfile', array($this->user, $this->other))) { $result = $this->user->block($this->other); if ($result) { Event::handle('EndBlockProfile', array($this->user, $this->other)); } } } if ($this->user->hasBlocked($this->other)) { $this->initDocument($this->format); $this->showProfile($this->other, $this->format); $this->endDocument($this->format); } else { // TRANS: Server error displayed when blocking a user has failed. $this->serverError(_('Block user failed.'), 500); } }
/** * Handle the request * * show a timeline of the user's repeated notices * * @param array $args $_REQUEST data (unused) * * @return void */ function handle($args) { parent::handle($args); $offset = ($this->page - 1) * $this->cnt; $limit = $this->cnt; $strm = $this->auth_user->repeatedToMe($offset, $limit, $this->since_id, $this->max_id); switch ($this->format) { case 'xml': $this->showXmlTimeline($strm); break; case 'json': $this->showJsonTimeline($strm); break; case 'atom': $profile = $this->auth_user->getProfile(); // TRANS: Title for Atom feed "repeated to me". %s is the user nickname. $title = sprintf(_("Repeated to %s"), $this->auth_user->nickname); $taguribase = TagURI::base(); $id = "tag:{$taguribase}:RepeatedToMe:" . $this->auth_user->id; $link = common_local_url('all', array('nickname' => $this->auth_user->nickname)); $this->showAtomTimeline($strm, $title, $id, $link); break; default: // TRANS: Client error displayed when trying to handle an unknown API method. $this->clientError(_('API method not found.'), $code = 404); break; } }
/** * Handle the request * * @param array $args $_REQUEST data (unused) * * @return void */ protected function handle() { parent::handle(); $this->initDocument('json'); $this->showJsonObjects('hello'); $this->endDocument('json'); }
/** * For initializing members of the class. * * @param array $argarray misc. arguments * * @return boolean true */ function prepare($argarray) { parent::prepare($argarray); $convId = $this->trimmed('id'); if (empty($convId)) { // TRANS: Client exception thrown when no conversation ID is given. throw new ClientException(_('No conversation ID.')); } $this->conversation = Conversation::staticGet('id', $convId); if (empty($this->conversation)) { // TRANS: Client exception thrown when referring to a non-existing conversation ID (%d). $this->clientError(_('No conversation ID found'), 404); return false; } $profile = Profile::current(); $stream = new ConversationNoticeStream($convId, $profile); $notice = $stream->getNotices(($this->page - 1) * $this->count, $this->count, $this->since_id, $this->max_id); $this->notices = $notice->fetchAll(); $originalConversation = new Notice(); $originalConversation->whereAdd('conversation=' . $convId); $originalConversation->limit(1); $originalConversation->orderBy('created'); $originalConversation->find(); if ($originalConversation->fetch()) { $this->originalNotice = $originalConversation; } return true; }
/** * Handle the request * * @param array $args $_REQUEST data (unused) * * @return void */ protected function handle() { parent::handle(); $user = common_current_user(); $profile = $user->getProfile(); // what to toggle if (QvitterPlugin::settings('enabledbydefault')) { $toggle = 'disable_qvitter'; } else { $toggle = 'enable_qvitter'; } // new value $state = Profile_prefs::getConfigData($profile, 'qvitter', $toggle); if ($state == 1) { $new_state = 0; } else { $new_state = 1; } try { $pref_saved = Profile_prefs::setData($profile, 'qvitter', $toggle, $new_state); $result['success'] = true; } catch (ServerException $e) { $result['success'] = false; $result['error'] = $e; } if (!$pref_saved) { $result['success'] = false; $result['error'] = 'Probably couldn\'t get topic from pref table'; } $this->initDocument('json'); $this->showJsonObjects($result); $this->endDocument('json'); }
/** * Handle the request * * Save the new message * * @param array $args $_REQUEST data (unused) * * @return void */ function handle($args) { parent::handle($args); if ($_SERVER['REQUEST_METHOD'] != 'POST') { $this->clientError(_('This method requires a POST.'), 400, $this->format); return; } if (empty($this->user) || empty($this->other)) { $this->clientError(_('No such user.'), 404, $this->format); return; } if ($this->user->hasBlocked($this->other)) { if (Event::handle('StartUnblockProfile', array($this->user, $this->other))) { $result = $this->user->unblock($this->other); if ($result) { Event::handle('EndUnblockProfile', array($this->user, $this->other)); } } } if (!$this->user->hasBlocked($this->other)) { $this->initDocument($this->format); $this->showProfile($this->other, $this->format); $this->endDocument($this->format); } else { // TRANS: Server error displayed when unblocking a user has failed. $this->serverError(_('Unblock user failed.')); } }
/** * Handle the request * * Grab the file from the 'media' param, then store, and shorten * * @todo Upload throttle! * * @param array $args $_REQUEST data (unused) * * @return void */ function handle($args) { parent::handle($args); if ($_SERVER['REQUEST_METHOD'] != 'POST') { $this->clientError(_('This method requires a POST.'), 400, $this->format); return; } // Workaround for PHP returning empty $_POST and $_FILES when POST // length > post_max_size in php.ini if (empty($_FILES) && empty($_POST) && $_SERVER['CONTENT_LENGTH'] > 0) { $msg = _('The server was unable to handle that much POST ' . 'data (%s bytes) due to its current configuration.'); $this->clientError(sprintf($msg, $_SERVER['CONTENT_LENGTH'])); return; } $upload = null; try { $upload = MediaFile::fromUpload('media', $this->auth_user); } catch (ClientException $ce) { $this->clientError($ce->getMessage()); return; } if (isset($upload)) { $this->showResponse($upload); } else { $this->clientError('Upload failed.'); return; } }
/** * Handle the request * * @return void */ protected function handle() { parent::handle(); $profile = $this->user->getProfile(); $base64img = $this->img; if (stristr($base64img, 'image/jpeg')) { $base64img_mime = 'image/jpeg'; } elseif (stristr($base64img, 'image/png')) { // should convert to jpg here!! $base64img_mime = 'image/png'; } $base64img = str_replace('data:image/jpeg;base64,', '', $base64img); $base64img = str_replace('data:image/png;base64,', '', $base64img); $base64img = str_replace(' ', '+', $base64img); $base64img_hash = md5($base64img); $base64img = base64_decode($base64img); $base64img_basename = basename('bg'); $base64img_filename = File::filename($profile, $base64img_basename, $base64img_mime); $base64img_path = File::path($base64img_filename); $base64img_success = file_put_contents($base64img_path, $base64img); $base64img_mimetype = MediaFile::getUploadedMimeType($base64img_path, $base64img_filename); $mediafile = new MediaFile($profile, $base64img_filename, $base64img_mimetype); $imagefile = new ImageFile($mediafile->fileRecord->id, File::path($mediafile->filename)); $imagefile->resizeTo(File::path($mediafile->filename), array('width' => 1280, 'height' => 1280, 'x' => $this->cropX, 'y' => $this->cropY, 'w' => $this->cropW, 'h' => $this->cropH)); $result['url'] = File::url($mediafile->filename); Profile_prefs::setData($profile, 'qvitter', 'background_image', $result['url']); $this->initDocument('json'); $this->showJsonObjects($result); $this->endDocument('json'); }
/** * Handle the request * * Save the new message * * @param array $args $_REQUEST data (unused) * * @return void */ function handle($args) { parent::handle($args); if ($_SERVER['REQUEST_METHOD'] != 'POST') { $this->clientError(_('This method requires a POST.'), 400, $this->format); return; } if (empty($this->user) || empty($this->other)) { $this->clientError(_('No such user.'), 404, $this->format); return; } // Don't allow blocking yourself! if ($this->user->id == $this->other->id) { $this->clientError(_("You cannot block yourself!"), 403, $this->format); return; } if (!$this->user->hasBlocked($this->other)) { if (Event::handle('StartBlockProfile', array($this->user, $this->other))) { $result = $this->user->block($this->other); if ($result) { Event::handle('EndBlockProfile', array($this->user, $this->other)); } } } if ($this->user->hasBlocked($this->other)) { $this->initDocument($this->format); $this->showProfile($this->other, $this->format); $this->endDocument($this->format); } else { $this->serverError(_('Block user failed.'), 500, $this->format); } }
/** * Handle the request * * Check the format and show the user info * * @param array $args $_REQUEST data (unused) * * @return void */ function handle($args) { parent::handle($args); if ($_SERVER['REQUEST_METHOD'] != 'POST') { $this->clientError(_('This method requires a POST.'), 400, $this->format); return; } if (!in_array($this->format, array('xml', 'json'))) { $this->clientError(_('API method not found.'), 404, $this->format); return; } if (empty($this->notice)) { $this->clientError(_('No status found with that ID.'), 404, $this->format); return; } // Note: Twitter lets you fave things repeatedly via API. if ($this->user->hasFave($this->notice)) { $this->clientError(_('This status is already a favorite.'), 403, $this->format); return; } $fave = Fave::addNew($this->user->getProfile(), $this->notice); if (empty($fave)) { $this->clientError(_('Could not create favorite.'), 403, $this->format); return; } $this->notify($fave, $this->notice, $this->user); $this->user->blowFavesCache(); if ($this->format == 'xml') { $this->showSingleXmlStatus($this->notice); } elseif ($this->format == 'json') { $this->show_single_json_status($this->notice); } }
/** * Take arguments for running * * @param array $args $_REQUEST args * * @return boolean success flag * */ function prepare($args) { parent::prepare($args); // TRANS: Server error displayed calling unimplemented API method for 'retweeted by me'. $this->serverError(_('Unimplemented.'), 503); return false; }
/** * Handle the request * * Check the format and show the user info * * @param array $args $_REQUEST data (unused) * * @return void */ function handle($args) { parent::handle($args); if ($_SERVER['REQUEST_METHOD'] != 'POST') { $this->clientError(_('This method requires a POST.'), 400, $this->format); return; } if (!in_array($this->format, array('xml', 'json'))) { $this->clientError(_('API method not found.'), 404, $this->format); return; } if (empty($this->notice)) { $this->clientError(_('No status found with that ID.'), 404, $this->format); return; } $fave = new Fave(); $fave->user_id = $this->user->id; $fave->notice_id = $this->notice->id; if (!$fave->find(true)) { $this->clientError(_('That status is not a favorite.'), 403, $this->favorite); return; } $result = $fave->delete(); if (!$result) { common_log_db_error($fave, 'DELETE', __FILE__); $this->clientError(_('Could not delete favorite.'), 404, $this->format); return; } $this->user->blowFavesCache(); if ($this->format == 'xml') { $this->showSingleXmlStatus($this->notice); } elseif ($this->format == 'json') { $this->show_single_json_status($this->notice); } }
/** * Handle the request * * Check the format and show the user info * * @param array $args $_REQUEST data (unused) * * @return void */ function handle($args) { parent::handle($args); if ($_SERVER['REQUEST_METHOD'] != 'POST') { $this->clientError(_('This method requires a POST.'), 400, $this->format); return; } if (!in_array($this->format, array('xml', 'json'))) { $this->clientError(_('API method not found.'), 404, $this->format); return; } if (empty($this->other)) { $this->clientError(_('Could not unfollow user: User not found.'), 403, $this->format); return; } // Don't allow unsubscribing from yourself! if ($this->user->id == $this->other->id) { $this->clientError(_("You cannot unfollow yourself."), 403, $this->format); return; } // throws an exception on error Subscription::cancel($this->user->getProfile(), $this->other); $this->initDocument($this->format); $this->showProfile($this->other, $this->format); $this->endDocument($this->format); }
/** * Handle the request * * @param array $args $_REQUEST data (unused) * * @return void */ protected function handle() { parent::handle(); $json_obects = array(); $this->initDocument('json'); $this->showJsonObjects($json_obects); $this->endDocument('json'); }
/** * Handle the request * * See which request params have been set, and update the profile * * @param array $args $_REQUEST data (unused) * * @return void */ function handle($args) { parent::handle($args); if ($_SERVER['REQUEST_METHOD'] != 'POST') { $this->clientError(_('This method requires a POST.'), 400, $this->format); return; } if (!in_array($this->format, array('xml', 'json'))) { $this->clientError(_('API method not found.'), 404, $this->format); return; } if (empty($this->user)) { $this->clientError(_('No such user.'), 404, $this->format); return; } $profile = $this->user->getProfile(); if (empty($profile)) { $this->clientError(_('User has no profile.')); return; } $original = clone $profile; if (!empty($this->name)) { $profile->fullname = $this->name; } if (!empty($this->url)) { $profile->homepage = $this->url; } if (!empty($this->description)) { $profile->bio = $this->description; } if (!empty($this->location)) { $profile->location = $this->location; $loc = Location::fromName($location); if (!empty($loc)) { $profile->lat = $loc->lat; $profile->lon = $loc->lon; $profile->location_id = $loc->location_id; $profile->location_ns = $loc->location_ns; } } $result = $profile->update($original); if (!$result) { common_log_db_error($profile, 'UPDATE', __FILE__); $this->serverError(_('Could not save profile.')); return; } common_broadcast_profile($profile); $twitter_user = $this->twitterUserArray($profile, true); if ($this->format == 'xml') { $this->initDocument('xml'); $this->showTwitterXmlUser($twitter_user); $this->endDocument('xml'); } elseif ($this->format == 'json') { $this->initDocument('json'); $this->showJsonObjects($twitter_user); $this->endDocument('json'); } }
/** * Handle the request * * @param array $args $_REQUEST data (unused) * * @return void */ protected function handle() { parent::handle(); // save the new bookmarks $saved = Profile_prefs::setData($this->scoped, 'qvitter', 'bookmarks', $this->bookmarks); $this->initDocument('json'); $this->showJsonObjects($saved); $this->endDocument('json'); }
/** * Handle the request * * @param array $args $_REQUEST data (unused) * * @return void */ protected function handle() { parent::handle(); // save the new bookmarks $saved = Profile_prefs::setData($this->scoped, $this->prefNamespace, $this->prefTopic, $this->prefData); $this->initDocument('json'); $this->showJsonObjects($saved); $this->endDocument('json'); }
/** * Handle the request * * show a timeline of the user's repeated notices * * @param array $args $_REQUEST data (unused) * * @return void */ function handle($args) { parent::handle($args); $offset = ($this->page - 1) * $this->cnt; $limit = $this->cnt; // TRANS: Title of list of repeated notices of the logged in user. // TRANS: %s is the nickname of the logged in user. $title = sprintf(_("Repeats of %s"), $this->auth_user->nickname); $sitename = common_config('site', 'name'); $profile = $this->auth_user->getProfile(); $subtitle = sprintf(_('%1$s notices that %2$s / %3$s has repeated.'), $sitename, $this->auth_user->nickname, $profile->getBestName()); $taguribase = TagURI::base(); $id = "tag:{$taguribase}:RepeatsOfMe:" . $this->auth_user->id; $link = common_local_url('all', array('nickname' => $this->auth_user->nickname)); // This is a really bad query for some reason if (!common_config('performance', 'high')) { $strm = $this->auth_user->repeatsOfMe($offset, $limit, $this->since_id, $this->max_id); } else { $strm = new Notice(); $strm->whereAdd('0 = 1'); $strm->find(); } switch ($this->format) { case 'xml': $this->showXmlTimeline($strm); break; case 'json': $this->showJsonTimeline($strm); break; case 'atom': header('Content-Type: application/atom+xml; charset=utf-8'); $atom = new AtomNoticeFeed($this->auth_user); $atom->setId($id); $atom->setTitle($title); $atom->setSubtitle($subtitle); $atom->setUpdated('now'); $atom->addLink($link); $atom->setSelfLink($this->getSelfUri()); $atom->addEntryFromNotices($strm); $this->raw($atom->getString()); break; case 'as': header('Content-Type: ' . ActivityStreamJSONDocument::CONTENT_TYPE); $doc = new ActivityStreamJSONDocument($this->auth_user); $doc->setTitle($title); $doc->addLink($link, 'alternate', 'text/html'); $doc->addItemsFromNotices($strm); $this->raw($doc->asString()); break; default: // TRANS: Client error displayed when coming across a non-supported API method. $this->clientError(_('API method not found.'), 404); break; } }
/** * Handle the request * * See which request params have been set, and update the user settings * * @param array $args $_REQUEST data (unused) * * @return void */ function handle($args) { parent::handle($args); if ($_SERVER['REQUEST_METHOD'] != 'POST') { $this->clientError(_('This method requires a POST.'), 400, $this->format); return; } if (!in_array($this->format, array('xml', 'json'))) { $this->clientError(_('API method not found.'), 404, $this->format); return; } // Note: Twitter no longer supports IM if (!in_array(strtolower($this->device), array('sms', 'im', 'none'))) { // TRANS: Client error displayed when no valid device parameter is provided for a user's delivery device setting. $this->clientError(_('You must specify a parameter named ' . '\'device\' with a value of one of: sms, im, none.')); return; } if (empty($this->user)) { // TRANS: Client error displayed when no existing user is provided for a user's delivery device setting. $this->clientError(_('No such user.'), 404, $this->format); return; } $original = clone $this->user; if (strtolower($this->device) == 'sms') { $this->user->smsnotify = true; } elseif (strtolower($this->device) == 'im') { $this->user->jabbernotify = true; } elseif (strtolower($this->device == 'none')) { $this->user->smsnotify = false; $this->user->jabbernotify = false; } $result = $this->user->update($original); if ($result === false) { common_log_db_error($this->user, 'UPDATE', __FILE__); // TRANS: Server error displayed when a user's delivery device cannot be updated. $this->serverError(_('Could not update user.')); return; } $profile = $this->user->getProfile(); $twitter_user = $this->twitterUserArray($profile, true); // Note: this Twitter API method is retarded because it doesn't give // any success/failure information. Twitter's docs claim that the // notification field will change to reflect notification choice, // but that's not true; notification> is used to indicate // whether the auth user is following the user in question. if ($this->format == 'xml') { $this->initDocument('xml'); $this->showTwitterXmlUser($twitter_user); $this->endDocument('xml'); } elseif ($this->format == 'json') { $this->initDocument('json'); $this->showJsonObjects($twitter_user); $this->endDocument('json'); } }
function handle($args) { parent::handle($args); if (empty($this->auth_user)) { $this->clientError(_('No such user.'), 404, $this->format); return; } $from = $this->auth_user->id; $to = $this->trimmed('id'); if (empty($from) || empty($to)) { $this->clientError(_('must set fromUser or toUser'), 406, $this->format); return; } $this->count = $this->trimmed('count'); if (empty($this->count)) { $this->count = MESSAGES_PER_PAGE; } if ($this->count > MESSAGES_PER_PAGE * 2) { $this->count = MESSAGES_PER_PAGE; } $this->sinceId = $this->trimmed('since_id'); $this->max_id = $this->trimmed('max_id'); if (empty($this->sinceId)) { $this->sinceId = 0; } if (empty($this->max_id)) { $this->max_id = 0; } if (!is_numeric($from) || !is_numeric($to) || !is_numeric($this->sinceId) || !is_numeric($this->max_id) || !is_numeric($this->count)) { $this->clientError(_('param error')); return; } if ($from == $to) { $this->clientError(_('can not get conversation for your self'), 406, $this->format); return; } $fromUser = $this->getTargetUser($from); $toUser = $this->getTargetUser($to); if (empty($fromUser) || empty($toUser)) { $this->clientError(_('invalid fromUser or toUser'), 406, $this->format); } $this->fromUserId = $fromUser->id; $this->toUserId = $toUser->id; $message = $this->getMessages(); $result = NULL; if (!empty($message)) { $result = $this->fillMessage($message); } if ($result == NULL) { $result = array(); } $this->showFullJsonObjects($result); }
/** * Handle the request * * See which request params have been set, and update the profile * * @return void */ protected function handle() { parent::handle(); if (!in_array($this->format, array('xml', 'json'))) { // TRANS: Client error displayed when coming across a non-supported API method. $this->clientError(_('API method not found.'), 404); } if (empty($this->user)) { // TRANS: Client error displayed if a user could not be found. $this->clientError(_('No such user.'), 404); } $profile = $this->user->getProfile(); if (empty($profile)) { // TRANS: Error message displayed when referring to a user without a profile. $this->clientError(_('User has no profile.')); } $original = clone $profile; if (!empty($this->name)) { $profile->fullname = $this->name; } if (!empty($this->url)) { $profile->homepage = $this->url; } if (!empty($this->description)) { $profile->bio = $this->description; } if (!empty($this->location)) { $profile->location = $this->location; $loc = Location::fromName($this->location); if (!empty($loc)) { $profile->lat = $loc->lat; $profile->lon = $loc->lon; $profile->location_id = $loc->location_id; $profile->location_ns = $loc->location_ns; } } $result = $profile->update($original); if (!$result) { common_log_db_error($profile, 'UPDATE', __FILE__); // TRANS: Server error displayed if a user profile could not be saved. $this->serverError(_('Could not save profile.')); } $twitter_user = $this->twitterUserArray($profile, true); if ($this->format == 'xml') { $this->initDocument('xml'); $this->showTwitterXmlUser($twitter_user, 'user', true); $this->endDocument('xml'); } elseif ($this->format == 'json') { $this->initDocument('json'); $this->showJsonObjects($twitter_user); $this->endDocument('json'); } }
/** * Handle the request * * Try to save the user's colors in her design. Create a new design * if the user doesn't already have one. * * @param array $args $_REQUEST data (unused) * * @return void */ protected function handle() { parent::handle(); $validhex = preg_match('/^[a-f0-9]{6}$/i', $this->linkcolor); if ($validhex === false || $validhex == 0) { $this->clientError(_('Not a valid hex color.'), 400); } // save the new color Profile_prefs::setData($this->scoped, 'theme', 'linkcolor', $this->linkcolor); $twitter_user = $this->twitterUserArray($this->scoped, true); $this->initDocument('json'); $this->showJsonObjects($twitter_user); $this->endDocument('json'); }
/** * Handle the request * * Check whether the credentials are valid and output the result * * @param array $args $_REQUEST data (unused) * * @return void */ function handle($args) { parent::handle($args); if ($_SERVER['REQUEST_METHOD'] != 'POST') { $this->clientError(_('This method requires a POST.'), 400, $this->format); return; } // Workaround for PHP returning empty $_POST and $_FILES when POST // length > post_max_size in php.ini if (empty($_FILES) && empty($_POST) && $_SERVER['CONTENT_LENGTH'] > 0) { // TRANS: Client error displayed when the number of bytes in a POST request exceeds a limit. // TRANS: %s is the number of bytes of the CONTENT_LENGTH. $msg = _m('The server was unable to handle that much POST data (%s byte) due to its current configuration.', 'The server was unable to handle that much POST data (%s bytes) due to its current configuration.', intval($_SERVER['CONTENT_LENGTH'])); $this->clientError(sprintf($msg, $_SERVER['CONTENT_LENGTH'])); return; } if (empty($this->user)) { // TRANS: Client error displayed updating profile image without having a user object. $this->clientError(_('No such user.'), 404, $this->format); return; } try { $imagefile = ImageFile::fromUpload('image'); } catch (Exception $e) { $this->clientError($e->getMessage(), 400, $this->format); return; } $type = $imagefile->preferredType(); $filename = Avatar::filename($user->id, image_type_to_extension($type), null, 'tmp' . common_timestamp()); $filepath = Avatar::path($filename); $imagefile->copyTo($filepath); $profile = $this->user->getProfile(); if (empty($profile)) { // TRANS: Error message displayed when referring to a user without a profile. $this->clientError(_('User has no profile.')); return; } $profile->setOriginal($filename); common_broadcast_profile($profile); $twitter_user = $this->twitterUserArray($profile, true); if ($this->format == 'xml') { $this->initDocument('xml'); $this->showTwitterXmlUser($twitter_user, 'user', true); $this->endDocument('xml'); } elseif ($this->format == 'json') { $this->initDocument('json'); $this->showJsonObjects($twitter_user); $this->endDocument('json'); } }
/** * Handle the request * * Try to save the user's colors in her design. Create a new design * if the user doesn't already have one. * * @param array $args $_REQUEST data (unused) * * @return void */ protected function handle() { parent::handle(); $validhex = preg_match('/^[a-f0-9]{6}$/i', $this->backgroundcolor); if ($validhex === false || $validhex == 0) { $this->clientError(_('Not a valid hex color.'), 400); } Profile_prefs::setData($this->scoped, 'theme', 'backgroundcolor', $this->backgroundcolor); // unset background-image Profile_prefs::setData($this->scoped, 'qvitter', 'background_image', ''); $twitter_user = $this->twitterUserArray($this->scoped, true); $this->initDocument('json'); $this->showJsonObjects($twitter_user); $this->endDocument('json'); }
function handle($args) { parent::handle($args); $auth = new ApiAuthAction(); $auth->checkBasicAuthUser(false); $this->user = $auth->auth_user; $type = $this->trimmed('type'); $hotResult = null; switch ($type) { case 'tags': $hotResult = $this->getHotTags(); break; case 'users': $hotResult = $this->getHotUsers(); break; default: $this->clientError(_('invalid type')); return; break; } $this->initDocument('json'); $this->showJsonObjects($hotResult); $this->endDocument('json'); }
/** * Handle the request * * Save the new message * * @param array $args $_REQUEST data (unused) * * @return void */ function handle($args) { parent::handle($args); if ($_SERVER['REQUEST_METHOD'] != 'POST') { $this->clientError(_('This method requires a POST.'), 400, $this->format); return; } if (empty($this->user)) { // TRANS: Client error displayed when trying to have a non-existing user leave a group. $this->clientError(_('No such user.'), 404, $this->format); return; } if (empty($this->group)) { // TRANS: Client error displayed when trying to leave a group that does not exist. $this->clientError(_('Group not found.'), 404, $this->format); return false; } $member = new Group_member(); $member->group_id = $this->group->id; $member->profile_id = $this->auth_user->id; if (!$member->find(true)) { // TRANS: Server error displayed when trying to leave a group the user is not a member of. $this->serverError(_('You are not a member of this group.')); return; } try { if (Event::handle('StartLeaveGroup', array($this->group, $this->user))) { Group_member::leave($this->group->id, $this->user->id); Event::handle('EndLeaveGroup', array($this->group, $this->user)); } } catch (Exception $e) { // TRANS: Server error displayed when leaving a group failed in the database. // TRANS: %1$s is the leaving user's nickname, $2$s is the group nickname for which the leave failed. $this->serverError(sprintf(_('Could not remove user %1$s from group %2$s.'), $cur->nickname, $this->group->nickname)); return; } switch ($this->format) { case 'xml': $this->showSingleXmlGroup($this->group); break; case 'json': $this->showSingleJsonGroup($this->group); break; default: $this->clientError(_('API method not found.'), 404, $this->format); break; } }
/** * Handle the request * * Grab the file from the 'media' param, then store, and shorten * * @todo Upload throttle! * * @param array $args $_REQUEST data (unused) * * @return void */ protected function handle() { parent::handle(); // Workaround for PHP returning empty $_POST and $_FILES when POST // length > post_max_size in php.ini if (empty($_FILES) && empty($_POST) && $_SERVER['CONTENT_LENGTH'] > 0) { // TRANS: Client error displayed when the number of bytes in a POST request exceeds a limit. // TRANS: %s is the number of bytes of the CONTENT_LENGTH. $msg = _m('The server was unable to handle that much POST data (%s byte) due to its current configuration.', 'The server was unable to handle that much POST data (%s bytes) due to its current configuration.', intval($_SERVER['CONTENT_LENGTH'])); $this->clientError(sprintf($msg, $_SERVER['CONTENT_LENGTH'])); } // we could catch "NoUploadedMediaException" as "no media uploaded", but here we _always_ want an upload $upload = MediaFile::fromUpload('media', $this->scoped); // Thumbnails will be generated/cached on demand when accessed (such as with /attachment/:id/thumbnail) $this->showResponse($upload); }