From 25237c09298191b5f7c1914c14a8b714e0882e80 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 26 Jul 2014 15:01:01 +0200 Subject: [PATCH 1/3] Make the friendica android client work again (it had problems with the GUID in the notifications) --- include/api.php | 4 +++- include/items.php | 35 +++++++++++++++++++++++++++++++++++ mod/notify.php | 14 ++++++++++++++ mod/ping.php | 16 ++++++++-------- 4 files changed, 60 insertions(+), 9 deletions(-) diff --git a/include/api.php b/include/api.php index b10c2bf496..7cc72948d1 100644 --- a/include/api.php +++ b/include/api.php @@ -1127,9 +1127,11 @@ `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` FROM `item`, `contact` WHERE `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0 - AND `contact`.`id` = `item`.`contact-id` + AND `contact`.`id` = `item`.`contact-id` AND `item`.`uid` = %d AND `item`.`verb` = '%s' AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 $sql_extra", + intval(api_user()), + dbesc(ACTIVITY_POST), intval($id) ); diff --git a/include/items.php b/include/items.php index 6f5c88a478..5b8bb242b3 100644 --- a/include/items.php +++ b/include/items.php @@ -1413,6 +1413,41 @@ function get_item_guid($id) { return(""); } +function get_item_id($guid, $uid = 0) { + + $nick = ""; + $id = 0; + + if ($uid == 0) + $uid == local_user(); + + // Does the given user have this item? + if ($uid) { + $r = q("SELECT `item`.`id`, `user`.`nickname` FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid` + WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 + AND `item`.`guid` = '%s' AND `item`.`uid` = %d", dbesc($guid), intval($uid)); + if (count($r)) { + $id = $r[0]["id"]; + $nick = $r[0]["nickname"]; + } + } + + // Or is it anywhere on the server? + if ($nick == "") { + $r = q("SELECT `item`.`id`, `user`.`nickname` FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid` + WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 + AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' + AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' + AND `item`.`private` = 0 AND `item`.`wall` = 1 + AND `item`.`guid` = '%s'", dbesc($guid)); + if (count($r)) { + $id = $r[0]["id"]; + $nick = $r[0]["nickname"]; + } + } + return(array("nick" => $nick, "id" => $id)); +} + // return - test function get_item_contact($item,$contacts) { if(! count($contacts) || (! is_array($item))) diff --git a/mod/notify.php b/mod/notify.php index 256bb77932..f9c5a09b27 100644 --- a/mod/notify.php +++ b/mod/notify.php @@ -17,6 +17,20 @@ function notify_init(&$a) { dbesc($r[0]['otype']), intval(local_user()) ); + + // Friendica-Client + $friendicamobile = ($_SERVER['HTTP_USER_AGENT'] == "Apache-HttpClient/UNAVAILABLE (java 1.4)"); + + // The friendica client has problems with the GUID. this is some workaround + if ($friendicamobile) { + require_once("include/items.php"); + $urldata = parse_url($r[0]['link']); + $guid = basename($urldata["path"]); + $itemdata = get_item_id($guid, local_user()); + if ($itemdata["id"] != 0) + $r[0]['link'] = $a->get_baseurl().'/display/'.$itemdata["nick"].'/'.$itemdata["id"]; + } + goaway($r[0]['link']); } diff --git a/mod/ping.php b/mod/ping.php index 07884f4530..21154f9ffe 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -59,11 +59,11 @@ function ping_init(&$a) { $home = 0; $network = 0; - $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`wall`, `item`.`author-name`, - `item`.`contact-id`, `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object`, - `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink` + $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`wall`, `item`.`author-name`, + `item`.`contact-id`, `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object`, + `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink` FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent` - WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND + WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `pitem`.`parent` != 0 ORDER BY `item`.`created` DESC", intval(local_user()) @@ -109,14 +109,14 @@ function ping_init(&$a) { } } - $intros1 = q("SELECT `intro`.`id`, `intro`.`datetime`, - `fcontact`.`name`, `fcontact`.`url`, `fcontact`.`photo` + $intros1 = q("SELECT `intro`.`id`, `intro`.`datetime`, + `fcontact`.`name`, `fcontact`.`url`, `fcontact`.`photo` FROM `intro` LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id` WHERE `intro`.`uid` = %d AND `intro`.`blocked` = 0 AND `intro`.`ignore` = 0 AND `intro`.`fid`!=0", intval(local_user()) ); - $intros2 = q("SELECT `intro`.`id`, `intro`.`datetime`, - `contact`.`name`, `contact`.`url`, `contact`.`photo` + $intros2 = q("SELECT `intro`.`id`, `intro`.`datetime`, + `contact`.`name`, `contact`.`url`, `contact`.`photo` FROM `intro` LEFT JOIN `contact` ON `intro`.`contact-id` = `contact`.`id` WHERE `intro`.`uid` = %d AND `intro`.`blocked` = 0 AND `intro`.`ignore` = 0 AND `intro`.`contact-id`!=0", intval(local_user()) From 72eee45b92fe43c9543a861e169ffb5403d99879 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 27 Jul 2014 16:10:09 +0200 Subject: [PATCH 2/3] 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;
 }

From 9f09d90c6dc49df74faa6e7184184f64fe541c94 Mon Sep 17 00:00:00 2001
From: Michael Vogel 
Date: Sun, 27 Jul 2014 21:59:44 +0200
Subject: [PATCH 3/3] Better detection for links in the body that can be
 removed because of added information.

---
 include/items.php | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/include/items.php b/include/items.php
index e9da49982b..6a72320cd1 100644
--- a/include/items.php
+++ b/include/items.php
@@ -944,11 +944,12 @@ function add_page_info_to_body($body, $texturl = false, $no_photos = false) {
 	// 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))
+		if (($removedlink == "") OR strstr($body, $removedlink))
 			$body = $removedlink;
 
-		$removedlink = trim(str_replace("[url]".$matches[1]."[/url]", "", $body));
-		if (strstr($body, $removedlink))
+		$url = str_replace(array('/', '.'), array('\/', '\.'), $matches[1]);
+		$removedlink = preg_replace("/\[url\=".$url."\](.*?)\[\/url\]/ism", '', $body);
+		if (($removedlink == "") OR strstr($body, $removedlink))
 			$body = $removedlink;
 	}