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"; } }
function api_clean_plain_items($Text) { $include_entities = strtolower(x($_REQUEST, 'include_entities') ? $_REQUEST['include_entities'] : "false"); $Text = bb_CleanPictureLinks($Text); $URLSearchString = "^\\[\\]"; $Text = preg_replace("/([!#@])\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '$1$3', $Text); if ($include_entities == "true") { $Text = preg_replace("/\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '[url=$1]$1[/url]', $Text); } $Text = preg_replace_callback("((.*?)\\[class=(.*?)\\](.*?)\\[\\/class\\])ism", "api_cleanup_share", $Text); return $Text; }
function fbpost_prepare_body(&$a, &$b) { if ($b["item"]["network"] != NETWORK_FACEBOOK) { return; } if ($b["preview"]) { $msg = $b["item"]["body"]; require_once "include/bbcode.php"; require_once "include/html2plain.php"; $msg = bb_CleanPictureLinks($msg); $msg = bbcode($msg, false, false, 2, true); $msg = trim(html2plain($msg, 0)); $b['html'] = nl2br(htmlspecialchars($msg)); } }