Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
function api_format_items($r, $user_info, $filter_user = false)
{
    $a = get_app();
    $ret = array();
    foreach ($r as $item) {
        api_share_as_retweet($item);
        localize_item($item);
        $status_user = api_item_get_user($a, $item);
        // Look if the posts are matching if they should be filtered by user id
        if ($filter_user and $status_user["id"] != $user_info["id"]) {
            continue;
        }
        if ($item['thr-parent'] != $item['uri']) {
            $r = q("SELECT id FROM item WHERE uid=%d AND uri='%s' LIMIT 1", intval(api_user()), dbesc($item['thr-parent']));
            if ($r) {
                $in_reply_to_status_id = intval($r[0]['id']);
            } else {
                $in_reply_to_status_id = intval($item['parent']);
            }
            $in_reply_to_status_id_str = (string) intval($item['parent']);
            $in_reply_to_screen_name = NULL;
            $in_reply_to_user_id = NULL;
            $in_reply_to_user_id_str = NULL;
            $r = q("SELECT `author-link` FROM item WHERE uid=%d AND id=%d LIMIT 1", intval(api_user()), intval($in_reply_to_status_id));
            if ($r) {
                $r = q("SELECT * FROM unique_contacts WHERE `url` = '%s'", dbesc(normalise_link($r[0]['author-link'])));
                if ($r) {
                    if ($r[0]['nick'] == "") {
                        $r[0]['nick'] = api_get_nick($r[0]["url"]);
                    }
                    $in_reply_to_screen_name = $r[0]['nick'] ? $r[0]['nick'] : $r[0]['name'];
                    $in_reply_to_user_id = intval($r[0]['id']);
                    $in_reply_to_user_id_str = (string) intval($r[0]['id']);
                }
            }
        } else {
            $in_reply_to_screen_name = NULL;
            $in_reply_to_user_id = NULL;
            $in_reply_to_status_id = NULL;
            $in_reply_to_user_id_str = NULL;
            $in_reply_to_status_id_str = NULL;
        }
        $converted = api_convert_item($item);
        $status = array('text' => $converted["text"], 'truncated' => False, 'created_at' => api_date($item['created']), 'in_reply_to_status_id' => $in_reply_to_status_id, 'in_reply_to_status_id_str' => $in_reply_to_status_id_str, 'source' => $item['app'] ? $item['app'] : 'web', 'id' => intval($item['id']), 'id_str' => (string) intval($item['id']), 'in_reply_to_user_id' => $in_reply_to_user_id, 'in_reply_to_user_id_str' => $in_reply_to_user_id_str, 'in_reply_to_screen_name' => $in_reply_to_screen_name, 'geo' => NULL, 'favorited' => $item['starred'] ? true : false, 'user' => $status_user, 'statusnet_html' => $converted["html"], 'statusnet_conversation_id' => $item['parent']);
        if (count($converted["attachments"]) > 0) {
            $status["attachments"] = $converted["attachments"];
        }
        if (count($converted["entities"]) > 0) {
            $status["entities"] = $converted["entities"];
        }
        if ($item['item_network'] != "" and $status["source"] == 'web') {
            $status["source"] = network_to_name($item['item_network'], $user_info['url']);
        } else {
            if ($item['item_network'] != "" and network_to_name($item['item_network'], $user_info['url']) != $status["source"]) {
                $status["source"] = trim($status["source"] . ' (' . network_to_name($item['item_network'], $user_info['url']) . ')');
            }
        }
        // Retweets are only valid for top postings
        // It doesn't work reliable with the link if its a feed
        $IsRetweet = $item['owner-link'] != $item['author-link'];
        if ($IsRetweet) {
            $IsRetweet = ($item['owner-name'] != $item['author-name'] or $item['owner-avatar'] != $item['author-avatar']);
        }
        if ($IsRetweet and $item["id"] == $item["parent"]) {
            $retweeted_status = $status;
            $retweeted_status["user"] = api_get_user($a, $item["author-link"]);
            $status["retweeted_status"] = $retweeted_status;
        }
        // "uid" and "self" are only needed for some internal stuff, so remove it from here
        unset($status["user"]["uid"]);
        unset($status["user"]["self"]);
        if ($item["coord"] != "") {
            $coords = explode(' ', $item["coord"]);
            if (count($coords) == 2) {
                $status["geo"] = array('type' => 'Point', 'coordinates' => array((double) $coords[0], (double) $coords[1]));
            }
        }
        $ret[] = $status;
    }
    return $ret;
}
Ejemplo n.º 3
0
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;
}
Ejemplo n.º 4
0
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);
        $status = array('created_at' => api_date($item['created']), 'published' => api_date($item['created']), 'updated' => api_date($item['edited']), 'id' => intval($item['id']), 'message_id' => $item['uri'], 'text' => strip_tags(bbcode($item['body'])), 'statusnet_html' => bbcode($item['body']), 'source' => $item['app'] ? $item['app'] : 'web', 'url' => $item['plink'] != '' ? $item['plink'] : $item['author-link'], 'truncated' => False, 'in_reply_to_status_id' => $item['parent'] != $item['id'] ? intval($item['parent']) : '', 'in_reply_to_user_id' => '', 'favorited' => $item['starred'] ? true : false, 'in_reply_to_screen_name' => '', 'geo' => '', 'coordinates' => $item['coord'], 'place' => $item['location'], 'contributors' => '', 'annotations' => '', 'entities' => '', 'user' => $status_user, '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);
        $ret[] = $status;
    }
    return $ret;
}
Ejemplo n.º 5
0
function api_format_items($r, $user_info, $filter_user = false)
{
    $a = get_app();
    $ret = array();
    foreach ($r as $item) {
        api_share_as_retweet($a, api_user(), $item);
        localize_item($item);
        $status_user = api_item_get_user($a, $item);
        // Look if the posts are matching if they should be filtered by user id
        if ($filter_user and $status_user["id"] != $user_info["id"]) {
            continue;
        }
        if ($item['thr-parent'] != $item['uri']) {
            $r = q("SELECT id FROM item WHERE uid=%d AND uri='%s' LIMIT 1", intval(api_user()), dbesc($item['thr-parent']));
            if ($r) {
                $in_reply_to_status_id = intval($r[0]['id']);
            } else {
                $in_reply_to_status_id = intval($item['parent']);
            }
            $in_reply_to_status_id_str = (string) intval($item['parent']);
            $in_reply_to_screen_name = NULL;
            $in_reply_to_user_id = NULL;
            $in_reply_to_user_id_str = NULL;
            $r = q("SELECT `author-link` FROM item WHERE uid=%d AND id=%d LIMIT 1", intval(api_user()), intval($in_reply_to_status_id));
            if ($r) {
                $r = q("SELECT * FROM unique_contacts WHERE `url` = '%s'", dbesc(normalise_link($r[0]['author-link'])));
                if ($r) {
                    if ($r[0]['nick'] == "") {
                        $r[0]['nick'] = api_get_nick($r[0]["url"]);
                    }
                    $in_reply_to_screen_name = $r[0]['nick'] ? $r[0]['nick'] : $r[0]['name'];
                    $in_reply_to_user_id = intval($r[0]['id']);
                    $in_reply_to_user_id_str = (string) intval($r[0]['id']);
                }
            }
        } else {
            $in_reply_to_screen_name = NULL;
            $in_reply_to_user_id = NULL;
            $in_reply_to_status_id = NULL;
            $in_reply_to_user_id_str = NULL;
            $in_reply_to_status_id_str = NULL;
        }
        // Workaround for ostatus messages where the title is identically to the body
        //$statusbody = trim(html2plain(bbcode(api_clean_plain_items($item['body']), false, false, 5, true), 0));
        $html = bbcode(api_clean_plain_items($item['body']), false, false, 2, true);
        $statusbody = trim(html2plain($html, 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, 'in_reply_to_status_id_str' => $in_reply_to_status_id_str, 'source' => $item['app'] ? $item['app'] : 'web', 'id' => intval($item['id']), 'id_str' => (string) intval($item['id']), 'in_reply_to_user_id' => $in_reply_to_user_id, 'in_reply_to_user_id_str' => $in_reply_to_user_id_str, 'in_reply_to_screen_name' => $in_reply_to_screen_name, 'geo' => NULL, 'favorited' => $item['starred'] ? true : false, 'user' => $status_user, 'statusnet_html' => trim(bbcode($item['body'], false, false)), 'statusnet_conversation_id' => $item['parent']);
        if ($item['title'] != "") {
            $status['statusnet_html'] = "<h4>" . bbcode($item['title']) . "</h4>\n" . $status['statusnet_html'];
        }
        $entities = api_get_entitities($status['text'], $item['body']);
        if (count($entities) > 0) {
            $status['entities'] = $entities;
        }
        if ($item['item_network'] != "" and $status["source"] == 'web') {
            $status["source"] = network_to_name($item['item_network']);
        } else {
            if ($item['item_network'] != "" and network_to_name($item['item_network']) != $status["source"]) {
                $status["source"] = trim($status["source"] . ' (' . network_to_name($item['item_network']) . ')');
            }
        }
        // Retweets are only valid for top postings
        // It doesn't work reliable with the link if its a feed
        $IsRetweet = $item['owner-link'] != $item['author-link'];
        if ($IsRetweet) {
            $IsRetweet = ($item['owner-name'] != $item['author-name'] or $item['owner-avatar'] != $item['author-avatar']);
        }
        if ($IsRetweet and $item["id"] == $item["parent"]) {
            $retweeted_status = $status;
            $retweeted_status["user"] = api_get_user($a, $item["author-link"]);
            $status["retweeted_status"] = $retweeted_status;
        }
        // "uid" and "self" are only needed for some internal stuff, so remove it from here
        unset($status["user"]["uid"]);
        unset($status["user"]["self"]);
        // 'geo' => array('type' => 'Point',
        //                   'coordinates' => array((float) $notice->lat,
        //                                          (float) $notice->lon));
        $ret[] = $status;
    }
    return $ret;
}