From bb451125449fbd6db541fd6d6795e4ddf34e9c1b Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 4 Dec 2015 05:57:33 +0100 Subject: [PATCH 1/2] OStatus: Picture posts are reformatted --- include/bbcode.php | 4 ++-- include/ostatus.php | 13 +++++++++++++ include/plaintext.php | 5 +++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/bbcode.php b/include/bbcode.php index acf6979d8..100c3b930 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -959,14 +959,14 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal $Text = preg_replace_callback("&\[url=/posts/([^\[\]]*)\](.*)\[\/url\]&Usi", 'bb_DiasporaLinks', $Text); // if the HTML is used to generate plain text, then don't do this search, but replace all URL of that kind to text - if ($simplehtml != 7) { +// if ($simplehtml != 7) { if (!$forplaintext) $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1$2', $Text); else { $Text = preg_replace("(\[url\]([$URLSearchString]*)\[\/url\])ism"," $1 ",$Text); $Text = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", 'bb_RemovePictureLinks', $Text); } - } +// } if ($tryoembed) $Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism",'tryoembed',$Text); diff --git a/include/ostatus.php b/include/ostatus.php index ebd5741e5..01f6873aa 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -1089,6 +1089,17 @@ function xml_add_element($doc, $parent, $element, $value = "", $attributes = arr $parent->appendChild($element); } +function ostatus_format_picture_post($body) { + $siteinfo = get_attached_data($body); + + if (($siteinfo["type"] == "photo") AND isset($siteinfo["url"]) AND isset($siteinfo["preview"])) { + $siteinfo["preview"] = str_replace(array("-1.jpg", "-1.png"), array("-2.jpg", "-2.png"), $siteinfo["preview"]); + $body = trim($siteinfo["text"])." [url]".$siteinfo["url"]."[/url]\n[img]".$siteinfo["preview"]."[/img]"; + } + + return $body; +} + function ostatus_add_header($doc, $owner) { $a = get_app(); @@ -1332,6 +1343,8 @@ function ostatus_entry($doc, $item, $owner, $toplevel = false) { else $body = $item['body']; + $body = ostatus_format_picture_post($body); + if ($item['title'] != "") $body = "[b]".$item['title']."[/b]\n\n".$body; diff --git a/include/plaintext.php b/include/plaintext.php index 4f435fc6a..204feb137 100644 --- a/include/plaintext.php +++ b/include/plaintext.php @@ -55,9 +55,10 @@ function get_attached_data($body) { $data = parseurl_getsiteinfo_cached($pictures[0][1], true); if ($data["type"] == "photo") { $post["type"] = "photo"; - if (isset($data["images"][0])) + if (isset($data["images"][0])) { $post["image"] = $data["images"][0]["src"]; - else + $post["url"] = $data["url"]; + } else $post["image"] = $data["url"]; $post["preview"] = $pictures[0][2]; From 37bd03422bf74bd7fe8213fa519c3eb3efd83af5 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 4 Dec 2015 06:50:23 +0100 Subject: [PATCH 2/2] The preview picture can now be remote or local --- include/ostatus.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/include/ostatus.php b/include/ostatus.php index 01f6873aa..593a9232a 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -9,6 +9,7 @@ require_once("include/socgraph.php"); require_once("include/Photo.php"); require_once("include/Scrape.php"); require_once("include/follow.php"); +require_once("mod/proxy.php"); define('OSTATUS_DEFAULT_POLL_INTERVAL', 30); // given in minutes define('OSTATUS_DEFAULT_POLL_TIMEFRAME', 1440); // given in minutes @@ -1092,9 +1093,25 @@ function xml_add_element($doc, $parent, $element, $value = "", $attributes = arr function ostatus_format_picture_post($body) { $siteinfo = get_attached_data($body); - if (($siteinfo["type"] == "photo") AND isset($siteinfo["url"]) AND isset($siteinfo["preview"])) { - $siteinfo["preview"] = str_replace(array("-1.jpg", "-1.png"), array("-2.jpg", "-2.png"), $siteinfo["preview"]); - $body = trim($siteinfo["text"])." [url]".$siteinfo["url"]."[/url]\n[img]".$siteinfo["preview"]."[/img]"; + if (($siteinfo["type"] == "photo")) { + if (isset($siteinfo["preview"])) + $preview = $siteinfo["preview"]; + else + $preview = $siteinfo["image"]; + + // Is it a remote picture? Then make a smaller preview here + $preview = proxy_url($preview, false, PROXY_SIZE_SMALL); + + // Is it a local picture? Then make it smaller here + $preview = str_replace(array("-0.jpg", "-0.png"), array("-2.jpg", "-2.png"), $preview); + $preview = str_replace(array("-1.jpg", "-1.png"), array("-2.jpg", "-2.png"), $preview); + + if (isset($siteinfo["url"])) + $url = $siteinfo["url"]; + else + $url = $siteinfo["image"]; + + $body = trim($siteinfo["text"])." [url]".$url."[/url]\n[img]".$preview."[/img]"; } return $body;