Beispiel #1
0
function gpluspost_feeditem($pid, $uid)
{
    global $a;
    require_once 'include/api.php';
    require_once 'include/bbcode.php';
    require_once "include/html2plain.php";
    require_once "include/network.php";
    $skipwithoutlink = get_pconfig($uid, 'gpluspost', 'skip_without_link');
    $items = q("SELECT `uri`, `plink`, `author-link`, `author-name`, `created`, `edited`, `id`, `title`, `body` from `item` WHERE id=%d", intval($pid));
    foreach ($items as $item) {
        $item['body'] = bb_CleanPictureLinks($item['body']);
        $item['body'] = bb_remove_share_information($item['body'], true);
        if ($item["title"] != "") {
            $item['body'] = "*" . $item["title"] . "*\n\n" . $item['body'];
        }
        // Looking for the first image
        $image = '';
        if (preg_match("/\\[img\\=([0-9]*)x([0-9]*)\\](.*?)\\[\\/img\\]/is", $item['body'], $matches)) {
            $image = $matches[3];
        }
        if ($image == '') {
            if (preg_match("/\\[img\\](.*?)\\[\\/img\\]/is", $item['body'], $matches)) {
                $image = $matches[1];
            }
        }
        $multipleimages = strpos($item['body'], "[img") != strrpos($item['body'], "[img");
        // When saved into the database the content is sent through htmlspecialchars
        // That means that we have to decode all image-urls
        $image = htmlspecialchars_decode($image);
        $link = '';
        // look for bookmark-bbcode and handle it with priority
        if (preg_match("/\\[bookmark\\=([^\\]]*)\\](.*?)\\[\\/bookmark\\]/is", $item['body'], $matches)) {
            $link = $matches[1];
        }
        $multiplelinks = strpos($item['body'], "[bookmark") != strrpos($item['body'], "[bookmark");
        $body = $item['body'];
        $body = preg_replace("(\\[b\\](.*?)\\[\\/b\\])ism", '*$1*', $body);
        $body = preg_replace("(\\[i\\](.*?)\\[\\/i\\])ism", '_$1_', $body);
        $body = preg_replace("(\\[s\\](.*?)\\[\\/s\\])ism", '-$1-', $body);
        // At first convert the text to html
        $html = bbcode(api_clean_plain_items($body), false, false, 2);
        // Then convert it to plain text
        $msg = trim(html2plain($html, 0, true));
        $msg = html_entity_decode($msg, ENT_QUOTES, 'UTF-8');
        // If there is no bookmark element then take the first link
        if ($link == '') {
            $links = collecturls($html);
            if (sizeof($links) > 0) {
                reset($links);
                $link = current($links);
            }
            $multiplelinks = sizeof($links) > 1;
            if ($multiplelinks) {
                $html2 = bbcode($msg, false, false);
                $links2 = collecturls($html2);
                if (sizeof($links2) > 0) {
                    reset($links2);
                    $link = current($links2);
                    $multiplelinks = sizeof($links2) > 1;
                }
            }
        }
        $msglink = "";
        if ($multiplelinks) {
            $msglink = $item["plink"];
        } else {
            if ($link != "") {
                $msglink = $link;
            } else {
                if ($multipleimages) {
                    $msglink = $item["plink"];
                } else {
                    if ($image != "") {
                        $msglink = $image;
                    }
                }
            }
        }
        if ($msglink == "" and $skipwithoutlink) {
            continue;
        } else {
            if ($msglink == "") {
                $msglink = $item["plink"];
            }
        }
        // Fetching the title - or the first line
        if ($item["title"] != "") {
            $title = $item["title"];
        } else {
            $lines = explode("\n", $msg);
            $title = $lines[0];
        }
        //if ($image != $msglink)
        //	$html = trim(str_replace($msglink, "", $html));
        $title = trim(str_replace($msglink, "", $title));
        $msglink = original_url($msglink);
        if ($uid == 0) {
            $title = $item["author-name"] . ": " . $title;
        }
        $msglink = htmlspecialchars(html_entity_decode($msglink));
        if (strpos($msg, $msglink) == 0) {
            $msg .= "\n" . $msglink;
        }
        $msg = nl2br($msg);
        $title = str_replace("&", "&", $title);
        //$html = str_replace("&", "&", $html);
        echo "\t" . '<entry xmlns="http://www.w3.org/2005/Atom">' . "\n";
        echo "\t\t" . '<title type="html" xml:space="preserve"><![CDATA[' . $title . "]]></title>\n";
        echo "\t\t" . '<link rel="alternate" type="text/html" href="' . $msglink . '" />' . "\n";
        // <link rel="enclosure" type="audio/mpeg" length="1337" href="http://example.org/audio/ph34r_my_podcast.mp3"/>
        echo "\t\t<id>" . $item["uri"] . "</id>\n";
        echo "\t\t<updated>" . date("c", strtotime($item["edited"])) . "</updated>\n";
        echo "\t\t<published>" . date("c", strtotime($item["created"])) . "</published>\n";
        echo "\t\t<author>\n\t\t\t<name><![CDATA[" . $item["author-name"] . "]]></name>\n";
        echo "\t\t\t<uri>" . $item["author-link"] . "</uri>\n\t\t</author>\n";
        //echo '<content type="image/png" src="http://media.example.org/the_beach.png"/>';
        echo "\t\t" . '<content type="html" xml:space="preserve" xml:base="' . $item["plink"] . '"><![CDATA[' . $msg . "]]></content>\n";
        echo "\t</entry>\n";
    }
}
Beispiel #2
0
function api_convert_item($item)
{
    $body = $item['body'];
    $attachments = api_get_attachments($body);
    // Workaround for ostatus messages where the title is identically to the body
    $html = bbcode(api_clean_plain_items($body), false, false, 2, true);
    $statusbody = trim(html2plain($html, 0));
    // handle data: images
    $statusbody = api_format_items_embeded_images($item, $statusbody);
    $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"];
    }
    $statushtml = trim(bbcode($body, false, false));
    if ($item['title'] != "") {
        $statushtml = "<h4>" . bbcode($item['title']) . "</h4>\n" . $statushtml;
    }
    $entities = api_get_entitities($statustext, $body);
    return array("text" => $statustext, "html" => $statushtml, "attachments" => $attachments, "entities" => $entities);
}
Beispiel #3
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;
}