function api_format_items($r, $user_info) { //logger('api_format_items: ' . print_r($r,true)); //logger('api_format_items: ' . print_r($user_info,true)); $a = get_app(); $ret = array(); if (!$r) { return $ret; } foreach ($r as $item) { localize_item($item); $status_user = $item['author_xchan'] == $user_info['guid'] ? $user_info : api_item_get_user($a, $item); if (array_key_exists('status', $status_user)) { unset($status_user['status']); } if ($item['parent'] != $item['id']) { $r = q("select id from item where parent= %d and id < %d order by id desc limit 1", intval($item['parent']), intval($item['id'])); if ($r) { $in_reply_to_status_id = $r[0]['id']; } else { $in_reply_to_status_id = $item['parent']; } xchan_query($r, true); $in_reply_to_screen_name = $r[0]['author']['xchan_name']; $in_reply_to_user_id = $r[0]['author']['abook_id']; } else { $in_reply_to_screen_name = ''; $in_reply_to_user_id = 0; $in_reply_to_status_id = 0; } unobscure($item); // Workaround for ostatus messages where the title is identically to the body $statusbody = trim(html2plain(prepare_text($item['body'], $item['mimetype']), 0)); $statustitle = trim($item['title']); if ($statustitle != '' and strpos($statusbody, $statustitle) !== false) { $statustext = trim($statusbody); } else { $statustext = trim($statustitle . "\n\n" . $statusbody); } $status = array('text' => $statustext, 'truncated' => False, 'created_at' => api_date($item['created']), 'in_reply_to_status_id' => $in_reply_to_status_id, 'source' => $item['app'] ? $item['app'] : 'web', 'id' => intval($item['id']), 'in_reply_to_user_id' => $in_reply_to_user_id, 'in_reply_to_screen_name' => $in_reply_to_screen_name, 'geo' => '', 'favorited' => intval($item['item_starred']) ? true : false, 'user' => $status_user, 'statusnet_html' => trim(prepare_text($item['body'], $item['mimetype'])), 'statusnet_conversation_id' => $item['parent']); // Seesmic doesn't like the following content if ($_SERVER['HTTP_USER_AGENT'] != 'Seesmic') { $status2 = array('updated' => api_date($item['edited']), 'published' => api_date($item['created']), 'message_id' => $item['mid'], 'url' => $item['plink'], 'coordinates' => $item['coord'], 'place' => $item['location'], 'contributors' => '', 'annotations' => '', 'entities' => '', 'objecttype' => $item['obj_type'] ? $item['obj_type'] : ACTIVITY_OBJ_NOTE, 'verb' => $item['verb'] ? $item['verb'] : ACTIVITY_POST, 'self' => $a->get_baseurl() . "/api/statuses/show/" . $item['id'] . "." . $type, 'edit' => $a->get_baseurl() . "/api/statuses/show/" . $item['id'] . "." . $type); $status = array_merge($status, $status2); } $ret[] = $status; } return $ret; }
function api_direct_messages_box(&$a, $type, $box) { if (local_user() === false) { return false; } $user_info = api_get_user($a); // params $count = x($_GET, 'count') ? $_GET['count'] : 20; $page = x($_REQUEST, 'page') ? $_REQUEST['page'] - 1 : 0; if ($page < 0) { $page = 0; } $start = $page * $count; if ($box == "sentbox") { $sql_extra = "`from-url`='%s'"; } else { $sql_extra = "`from-url`!='%s'"; } $r = q("SELECT * FROM `mail` WHERE uid=%d AND {$sql_extra} ORDER BY created DESC LIMIT %d,%d", intval(local_user()), dbesc($a->get_baseurl() . '/profile/' . $a->user['nickname']), intval($start), intval($count)); $ret = array(); foreach ($r as $item) { switch ($box) { case "inbox": $recipient = $user_info; $sender = api_get_user($a, $item['contact-id']); break; case "sentbox": $recipient = api_get_user($a, $item['contact-id']); $sender = $user_info; break; } $ret[] = array('id' => $item['id'], 'created_at' => api_date($item['created']), 'sender_id' => $sender['id'], 'sender_screen_name' => $sender['screen_name'], 'sender' => $sender, 'recipient_id' => $recipient['id'], 'recipient_screen_name' => $recipient['screen_name'], 'recipient' => $recipient, 'text' => $item['title'] . "\n" . strip_tags(bbcode($item['body']))); } $data = array('$messages' => $ret); switch ($type) { case "atom": case "rss": $data = api_rss_extra($a, $data, $user_info); } return api_apply_template("direct_messages", $type, $data); }
function api_account_rate_limit_status(&$a, $type) { $hash = array('reset_time_in_seconds' => strtotime('now + 1 hour'), 'remaining_hits' => (string) 150, 'hourly_limit' => (string) 150, 'reset_time' => api_date(datetime_convert('UTC', 'UTC', 'now + 1 hour', ATOM_TIME))); if ($type == "xml") { $hash['resettime_in_seconds'] = $hash['reset_time_in_seconds']; } return api_apply_template('ratelimit', $type, array('$hash' => $hash)); }
function api_format_items($r, $user_info) { //logger('api_format_items: ' . print_r($r,true)); //logger('api_format_items: ' . print_r($user_info,true)); $a = get_app(); $ret = array(); foreach ($r as $item) { localize_item($item); $status_user = $item['cid'] == $user_info['id'] ? $user_info : api_item_get_user($a, $item); if ($item['parent'] != $item['id']) { $r = q("select id from item where parent=%s and id<%s order by id desc limit 1", intval($item['parent']), intval($item['id'])); if ($r) { $in_reply_to_status_id = $r[0]['id']; } else { $in_reply_to_status_id = $item['parent']; } $r = q("select `item`.`contact-id`, `contact`.nick, `item`.`author-name` from item, contact\n\t\t\t\t\twhere `contact`.`id` = `item`.`contact-id` and `item`.id=%d", intval($in_reply_to_status_id)); $in_reply_to_screen_name = $r[0]['author-name']; $in_reply_to_user_id = $r[0]['contact-id']; } else { $in_reply_to_screen_name = ''; $in_reply_to_user_id = 0; $in_reply_to_status_id = 0; } // Workaround for ostatus messages where the title is identically to the body $statusbody = trim(html2plain(bbcode($item['body'], false, false, true), 0)); $statustitle = trim($item['title']); if ($statustitle != '' and strpos($statusbody, $statustitle) !== false) { $statustext = trim($statusbody); } else { $statustext = trim($statustitle . "\n\n" . $statusbody); } if ($item["network"] == NETWORK_FEED and strlen($statustext) > 1000) { $statustext = substr($statustext, 0, 1000) . "... \n" . $item["plink"]; } $status = array('text' => $statustext, 'truncated' => False, 'created_at' => api_date($item['created']), 'in_reply_to_status_id' => $in_reply_to_status_id, 'source' => $item['app'] ? $item['app'] : 'web', 'id' => intval($item['id']), 'in_reply_to_user_id' => $in_reply_to_user_id, 'in_reply_to_screen_name' => $in_reply_to_screen_name, 'geo' => '', 'favorited' => $item['starred'] ? true : false, 'user' => $status_user, 'statusnet_html' => trim(bbcode($item['body'])), 'statusnet_conversation_id' => $item['parent']); // Seesmic doesn't like the following content if ($_SERVER['HTTP_USER_AGENT'] != 'Seesmic') { $status2 = array('updated' => api_date($item['edited']), 'published' => api_date($item['created']), 'message_id' => $item['uri'], 'url' => $item['plink'] != '' ? $item['plink'] : $item['author-link'], 'coordinates' => $item['coord'], 'place' => $item['location'], 'contributors' => '', 'annotations' => '', 'entities' => '', 'objecttype' => $item['object-type'] ? $item['object-type'] : ACTIVITY_OBJ_NOTE, 'verb' => $item['verb'] ? $item['verb'] : ACTIVITY_POST, 'self' => $a->get_baseurl() . "/api/statuses/show/" . $item['id'] . "." . $type, 'edit' => $a->get_baseurl() . "/api/statuses/show/" . $item['id'] . "." . $type); $status = array_merge($status, $status2); } $ret[] = $status; } return $ret; }