From 2676a0f0e5022c96e45679b1fa2507cb79df8658 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 5 Oct 2015 22:19:34 +0200 Subject: [PATCH 1/2] The proxy function sometimes kills embedded pictures ... --- include/bbcode.php | 30 +++++++++++++++++++++++++----- include/oembed.php | 2 +- include/text.php | 4 ++-- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/include/bbcode.php b/include/bbcode.php index 13061958c..a4ad09ccf 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -2,7 +2,23 @@ require_once("include/oembed.php"); require_once('include/event.php'); require_once('include/map.php'); +require_once('mod/proxy.php'); +function bb_PictureCacheExt($matches) { + if (strpos($matches[3], "data:image/") === 0) + return ($matches[0]); + + $matches[3] = proxy_url($matches[3]); + return "[img=".$matches[1]."x".$matches[2]."]".$matches[3]."[/img]"; +} + +function bb_PictureCache($matches) { + if (strpos($matches[1], "data:image/") === 0) + return ($matches[0]); + + $matches[1] = proxy_url($matches[1]); + return "[img]".$matches[1]."[/img]"; +} function bb_map_coords($match) { // the extra space in the following line is intentional @@ -101,9 +117,9 @@ function bb_attachment($Text, $simplehtml = false, $tryoembed = true) { $text = $oembed; else { if (($image != "") AND !strstr(strtolower($oembed), "
', $url, $image, $title); + $text .= sprintf('
', $url, proxy_url($image), $title); elseif (($preview != "") AND !strstr(strtolower($oembed), "
', $url, $preview, $title); + $text .= sprintf('
', $url, proxy_url($preview), $title); $text .= $oembed; @@ -455,7 +471,7 @@ function bb_replace_images($body, $images) { // We're depending on the property of 'foreach' (specified on the PHP website) that // it loops over the array starting from the first element and going sequentially // to the last element - $newbody = str_replace('[$#saved_image' . $cnt . '#$]', '' . t('Image/photo') . '', $newbody); + $newbody = str_replace('[$#saved_image' . $cnt . '#$]', '' . t('Image/photo') . '', $newbody); $cnt++; } @@ -585,7 +601,7 @@ function bb_ShareAttributes($share, $simplehtml) { default: $headline = trim($share[1]).'
'; if ($avatar != "") - $headline .= ''; + $headline .= ''; $headline .= sprintf(t('%s wrote the following post'.$reldate.':'), $profile, $author, $link); $headline .= "
"; @@ -1102,13 +1118,17 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal "
" . $t_wrote . "
$2
", $Text); + // [img=widthxheight]image source[/img] - //$Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '', $Text); + $Text = preg_replace_callback("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", 'bb_PictureCacheExt', $Text); + $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '', $Text); $Text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*)\](.*?)\[\/zmg\]/ism", '', $Text); // Images // [img]pathtoimage[/img] + $Text = preg_replace_callback("/\[img\](.*?)\[\/img\]/ism", 'bb_PictureCache', $Text); + $Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); $Text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); diff --git a/include/oembed.php b/include/oembed.php index d4d7ce05e..0e1238360 100755 --- a/include/oembed.php +++ b/include/oembed.php @@ -157,7 +157,7 @@ function oembed_format_object($j){ case "rich": { // not so safe.. if (!get_config("system","no_oembed_rich_content")) - $ret.= $jhtml; + $ret.= proxy_parse_html($jhtml); }; break; } diff --git a/include/text.php b/include/text.php index 0002f074e..1d27963cc 100644 --- a/include/text.php +++ b/include/text.php @@ -1410,8 +1410,8 @@ function prepare_body(&$item,$attach = false, $preview = false) { put_item_in_cache($item, true); $s = $item["rendered-html"]; - require_once("mod/proxy.php"); - $s = proxy_parse_html($s); + //require_once("mod/proxy.php"); + //$s = proxy_parse_html($s); $prep_arr = array('item' => $item, 'html' => $s, 'preview' => $preview); call_hooks('prepare_body', $prep_arr); From 7ed61b2edc50b8ff51f48446afc2b9743296d107 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 5 Oct 2015 22:25:14 +0200 Subject: [PATCH 2/2] Removed "proxy_parse_html" since it is now done in the bbcode function. --- include/text.php | 3 --- mod/display.php | 12 ++++++------ mod/follow.php | 2 +- mod/notifications.php | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/include/text.php b/include/text.php index 1d27963cc..c5b28b508 100644 --- a/include/text.php +++ b/include/text.php @@ -1410,9 +1410,6 @@ function prepare_body(&$item,$attach = false, $preview = false) { put_item_in_cache($item, true); $s = $item["rendered-html"]; - //require_once("mod/proxy.php"); - //$s = proxy_parse_html($s); - $prep_arr = array('item' => $item, 'html' => $s, 'preview' => $preview); call_hooks('prepare_body', $prep_arr); $s = $prep_arr['html']; diff --git a/mod/display.php b/mod/display.php index be5dd7cae..f945f9fe6 100644 --- a/mod/display.php +++ b/mod/display.php @@ -115,8 +115,8 @@ function display_fetchauthor($a, $item) { if (count($r)) { $profiledata["photo"] = proxy_url($r[0]["photo"]); - $profiledata["address"] = proxy_parse_html(bbcode($r[0]["location"])); - $profiledata["about"] = proxy_parse_html(bbcode($r[0]["about"])); + $profiledata["address"] = bbcode($r[0]["location"]); + $profiledata["about"] = bbcode($r[0]["about"]); if ($r[0]["nick"] != "") $profiledata["nickname"] = $r[0]["nick"]; } @@ -127,9 +127,9 @@ function display_fetchauthor($a, $item) { if ($profiledata["photo"] == "") $profiledata["photo"] = proxy_url($r[0]["avatar"]); if ($profiledata["address"] == "") - $profiledata["address"] = proxy_parse_html(bbcode($r[0]["location"])); + $profiledata["address"] = bbcode($r[0]["location"]); if ($profiledata["about"] == "") - $profiledata["about"] = proxy_parse_html(bbcode($r[0]["about"])); + $profiledata["about"] = bbcode($r[0]["about"]); if (($profiledata["nickname"] == "") AND ($r[0]["nick"] != "")) $profiledata["nickname"] = $r[0]["nick"]; } @@ -193,8 +193,8 @@ function display_fetchauthor($a, $item) { $r = q("SELECT `avatar`, `nick`, `location`, `about` FROM `unique_contacts` WHERE `url` = '%s'", dbesc(normalise_link($profiledata["url"]))); if (count($r)) { $profiledata["photo"] = proxy_url($r[0]["avatar"]); - $profiledata["address"] = proxy_parse_html(bbcode($r[0]["location"])); - $profiledata["about"] = proxy_parse_html(bbcode($r[0]["about"])); + $profiledata["address"] = bbcode($r[0]["location"]); + $profiledata["about"] = bbcode($r[0]["about"]); if ($r[0]["nick"] != "") $profiledata["nickname"] = $r[0]["nick"]; } diff --git a/mod/follow.php b/mod/follow.php index 2c8452b1b..25169e403 100644 --- a/mod/follow.php +++ b/mod/follow.php @@ -100,7 +100,7 @@ function follow_content(&$a) { '$request' => $request, '$location' => bbcode($r[0]["location"]), '$location_label' => t("Location:"), - '$about' => proxy_parse_html(bbcode($r[0]["about"], false, false)), + '$about' => bbcode($r[0]["about"], false, false), '$about_label' => t("About:"), '$keywords' => $r[0]["keywords"], '$keywords_label' => t("Tags:") diff --git a/mod/notifications.php b/mod/notifications.php index 69ab592af..95ebff96f 100644 --- a/mod/notifications.php +++ b/mod/notifications.php @@ -235,7 +235,7 @@ function notifications_content(&$a) { '$fullname' => $rr['name'], '$location' => bbcode($rr['glocation'], false, false), '$location_label' => t('Location:'), - '$about' => proxy_parse_html(bbcode($rr['gabout'], false, false)), + '$about' => bbcode($rr['gabout'], false, false), '$about_label' => t('About:'), '$keywords' => $rr['gkeywords'], '$keywords_label' => t('Tags:'),