From 72eee45b92fe43c9543a861e169ffb5403d99879 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 27 Jul 2014 16:10:09 +0200 Subject: [PATCH] The title of bookmark links is now taken instead of the data that was fetched via oembed --- include/bbcode.php | 10 +++++++--- include/items.php | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/include/bbcode.php b/include/bbcode.php index 2f4b3df77e..af14a57560 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -64,7 +64,7 @@ function bb_attachment($Text, $plaintext = false, $tryoembed = true) { else { $text = sprintf('', $type); - $bookmark = array(sprintf('[bookmark=%s]%s[/bookmark]', $url, $title), $title, $url); + $bookmark = array(sprintf('[bookmark=%s]%s[/bookmark]', $url, $title), $url, $title); if ($tryoembed) $oembed = tryoembed($bookmark); else @@ -197,7 +197,8 @@ function stripcode_br_cb($s) { } function tryoembed($match){ - $url = ((count($match)==2)?$match[1]:$match[2]); + //$url = ((count($match)==2)?$match[1]:$match[2]); + $url = $match[1]; // Always embed the SSL version $url = str_replace(array("http://www.youtube.com/", "http://player.vimeo.com/"), @@ -207,6 +208,9 @@ function tryoembed($match){ $o = oembed_fetch_url($url); + if (isset($match[2])) + $o->title = $match[2]; + //echo "
"; var_dump($match, $url, $o); killme();
 
 	if ($o->type=="error") return $match[0];
@@ -792,7 +796,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
 
 	// Perform URL Search
 	if ($tryoembed)
-		$Text = preg_replace_callback("/\[bookmark\=([^\]]*)\].*?\[\/bookmark\]/ism",'tryoembed',$Text);
+		$Text = preg_replace_callback("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",'tryoembed',$Text);
 
 	if ($simplehtml == 5)
 		$Text = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",'[url]$1[/url]',$Text);
diff --git a/include/items.php b/include/items.php
index 5b8bb242b3..e9da49982b 100644
--- a/include/items.php
+++ b/include/items.php
@@ -939,7 +939,22 @@ function add_page_info_to_body($body, $texturl = false, $no_photos = false) {
 	}
 
 	if ($matches)
-		$body .= add_page_info($matches[1], $no_photos);
+		$footer = add_page_info($matches[1], $no_photos);
+
+	// Remove the link from the body if the link is attached at the end of the post
+	if (isset($footer) AND (trim($footer) != "") AND (strpos($footer, $matches[1]))) {
+		$removedlink = trim(str_replace($matches[1], "", $body));
+		if (strstr($body, $removedlink))
+			$body = $removedlink;
+
+		$removedlink = trim(str_replace("[url]".$matches[1]."[/url]", "", $body));
+		if (strstr($body, $removedlink))
+			$body = $removedlink;
+	}
+
+	// Add the page information to the bottom
+	if (isset($footer) AND (trim($footer) != ""))
+		$body .= $footer;
 
 	return $body;
 }
-- 
2.39.5