From 8bd6e1aef9bcace19e4517b4f53c976d4c0a2760 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 1 May 2012 19:16:18 -0700 Subject: [PATCH 01/10] first try common friends for visitors --- include/contact_widgets.php | 39 ++++++++++++++++++++++++++++++++++ include/socgraph.php | 42 +++++++++++++++++++++++++++++++++++++ mod/profile.php | 4 ++++ view/match.tpl | 2 +- 4 files changed, 86 insertions(+), 1 deletion(-) diff --git a/include/contact_widgets.php b/include/contact_widgets.php index 96b02f2939..1aaef115c9 100644 --- a/include/contact_widgets.php +++ b/include/contact_widgets.php @@ -133,3 +133,42 @@ function categories_widget($baseurl,$selected = '') { )); } +function common_friends_visitor_widget($profile_uid) { + + $a = get_app(); + + if(local_user() == $profile_uid) + return; + + $cid = $zcid = 0; + + if(can_write_wall($a,$profile_uid)) + $cid = local_user(); + else { + if(get_my_url()) { + $r = q("select id from gcontact where nurl = '%s' limit 1", + dbesc(normalise_link(get_my_url())) + ); + if(count($r)) + $zcid = $r[0]['id']; + } + } + + if($cid == 0 && $zcid == 0) + return; + + require_once('include/socgraph.php'); + + + $t = count_common_friends_remote($profile_uid,$cid,$zcid); + if(! $t) + return; + + $r = common_friends_remote($profile_uid,$cid,$zcid); + + return replace_macros(get_markup_template('remote_friends_common.tpl'), array( + '$desc' => sprintf( tt("%d friend in common", "%d friends in common", $t), $t), + '$items = $r + )); + +}; \ No newline at end of file diff --git a/include/socgraph.php b/include/socgraph.php index 4a1c8a1cad..bd1fbded5c 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -199,6 +199,48 @@ function common_friends($uid,$cid) { } + +function count_common_friends_remote($uid,$cid,$zid) { + + $r = q("SELECT count(*) as `total` + FROM `glink` left join `gcontact` on `glink`.`gcid` = `gcontact`.`id` + where ((`glink`.cid != 0 and `glink`.`cid` = %d) or ( `glink`.`zcid` != 0 and `glink`.`zcid` = %d )) + and `glink`.`uid` = %d + and `gcontact`.`nurl` in (select nurl from contact where uid = %d and self = 0 and id != %d ) ", + intval($cid), + intval($zid), + intval($uid), + intval($uid), + intval($cid) + ); + + if(count($r)) + return $r[0]['total']; + return 0; + +} + +function common_friends_remote($uid,$cid,$zid,$limit = 6) { + + $r = q("SELECT `gcontact`.* + FROM `glink` left join `gcontact` on `glink`.`gcid` = `gcontact`.`id` + where ((`glink`.cid != 0 and `glink`.`cid` = %d) or ( `glink`.`zcid` != 0 and `glink`.`zcid` = %d )) + and `glink`.`uid` = %d + and `gcontact`.`nurl` in (select nurl from contact where uid = %d and self = 0 and id != %d ) + order by `gcontact`.`name` asc limit 0, %d", + intval($cid), + intval($zid), + intval($uid), + intval($uid), + intval($cid), + intval($limit) + ); + + return $r; + +} + + function count_all_friends($uid,$cid) { $r = q("SELECT count(*) as `total` diff --git a/mod/profile.php b/mod/profile.php index e9d4ca344e..41c5eed4bd 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -143,6 +143,10 @@ function profile_content(&$a, $update = 0) { return $o; } + + $o .= common_friends_vistor_widget($a->profile['profile_uid']); + + if(x($_SESSION,'new_member') && $_SESSION['new_member'] && $is_owner) $o .= '' . t('Tips for New Members') . '' . EOL; diff --git a/view/match.tpl b/view/match.tpl index 5f2fc7a302..b052845ae7 100644 --- a/view/match.tpl +++ b/view/match.tpl @@ -13,4 +13,4 @@
$conntxt
{{ endif }} - \ No newline at end of file + From 1fc796b2766abfee2d55c9b434d584a61fdb4b07 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 1 May 2012 19:19:24 -0700 Subject: [PATCH 02/10] typo --- include/contact_widgets.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/contact_widgets.php b/include/contact_widgets.php index 1aaef115c9..fedb946112 100644 --- a/include/contact_widgets.php +++ b/include/contact_widgets.php @@ -168,7 +168,7 @@ function common_friends_visitor_widget($profile_uid) { return replace_macros(get_markup_template('remote_friends_common.tpl'), array( '$desc' => sprintf( tt("%d friend in common", "%d friends in common", $t), $t), - '$items = $r + '$items' = $r )); }; \ No newline at end of file From 15c185015690664f9b6aef849cc6f79b68fd9c63 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 1 May 2012 19:20:41 -0700 Subject: [PATCH 03/10] another one --- include/contact_widgets.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/contact_widgets.php b/include/contact_widgets.php index fedb946112..0bf0b29d41 100644 --- a/include/contact_widgets.php +++ b/include/contact_widgets.php @@ -168,7 +168,7 @@ function common_friends_visitor_widget($profile_uid) { return replace_macros(get_markup_template('remote_friends_common.tpl'), array( '$desc' => sprintf( tt("%d friend in common", "%d friends in common", $t), $t), - '$items' = $r + '$items' => $r )); }; \ No newline at end of file From 91085f0969afbdca93c79d9be3d8fa815e9dfa27 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 1 May 2012 19:24:22 -0700 Subject: [PATCH 04/10] really fat fingers today - though none of this has gone further than my own site --- mod/profile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/profile.php b/mod/profile.php index 41c5eed4bd..69f044e89f 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -144,7 +144,7 @@ function profile_content(&$a, $update = 0) { } - $o .= common_friends_vistor_widget($a->profile['profile_uid']); + $o .= common_friends_visitor_widget($a->profile['profile_uid']); if(x($_SESSION,'new_member') && $_SESSION['new_member'] && $is_owner) From 72dbc2faeef26c6cdc749ce8403ebbd77b9b896f Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 1 May 2012 20:11:35 -0700 Subject: [PATCH 05/10] fn not found --- include/gprobe.php | 1 + 1 file changed, 1 insertion(+) diff --git a/include/gprobe.php b/include/gprobe.php index fdf786ca81..5ca42729a7 100644 --- a/include/gprobe.php +++ b/include/gprobe.php @@ -2,6 +2,7 @@ require_once("boot.php"); require_once('include/Scrape.php'); +require_once('include/socgraph.php'); function gprobe_run($argv, $argc){ global $a, $db; From 066d69b21c4d612b35a3e15ae1d5db6344935e53 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 1 May 2012 20:22:59 -0700 Subject: [PATCH 06/10] add template --- view/remote_friends_common.tpl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 view/remote_friends_common.tpl diff --git a/view/remote_friends_common.tpl b/view/remote_friends_common.tpl new file mode 100644 index 0000000000..b44a5b639d --- /dev/null +++ b/view/remote_friends_common.tpl @@ -0,0 +1,21 @@ +
+
$desc
+ {{ if $items }} + {{ for $items as $item }} +
+
+ + $item.name + +
+
+ +
+
+ {{ endfor }} + {{ endif }} +
+
+ From 594803afca25bf173cc42bb523a6931cc386777a Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 1 May 2012 20:33:19 -0700 Subject: [PATCH 07/10] reduce the scope a bit --- include/contact_widgets.php | 6 +++--- include/socgraph.php | 24 ++++++++---------------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/include/contact_widgets.php b/include/contact_widgets.php index 0bf0b29d41..3fd311e4a2 100644 --- a/include/contact_widgets.php +++ b/include/contact_widgets.php @@ -154,17 +154,17 @@ function common_friends_visitor_widget($profile_uid) { } } - if($cid == 0 && $zcid == 0) + if($zcid == 0) return; require_once('include/socgraph.php'); - $t = count_common_friends_remote($profile_uid,$cid,$zcid); + $t = count_common_friends_zcid($profile_uid,$zcid); if(! $t) return; - $r = common_friends_remote($profile_uid,$cid,$zcid); + $r = common_friends_zcid($profile_uid,$zcid); return replace_macros(get_markup_template('remote_friends_common.tpl'), array( '$desc' => sprintf( tt("%d friend in common", "%d friends in common", $t), $t), diff --git a/include/socgraph.php b/include/socgraph.php index bd1fbded5c..a3e20a6414 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -200,18 +200,14 @@ function common_friends($uid,$cid) { } -function count_common_friends_remote($uid,$cid,$zid) { +function count_common_friends_zcid($uid,$zcid) { $r = q("SELECT count(*) as `total` FROM `glink` left join `gcontact` on `glink`.`gcid` = `gcontact`.`id` - where ((`glink`.cid != 0 and `glink`.`cid` = %d) or ( `glink`.`zcid` != 0 and `glink`.`zcid` = %d )) - and `glink`.`uid` = %d - and `gcontact`.`nurl` in (select nurl from contact where uid = %d and self = 0 and id != %d ) ", - intval($cid), - intval($zid), + where `glink`.`zcid` = %d + and `gcontact`.`nurl` in (select nurl from contact where uid = %d and self = 0 ) ", + intval($zcid), intval($uid), - intval($uid), - intval($cid) ); if(count($r)) @@ -220,19 +216,15 @@ function count_common_friends_remote($uid,$cid,$zid) { } -function common_friends_remote($uid,$cid,$zid,$limit = 6) { +function common_friends_zcid($uid,$zcid,$limit = 6) { $r = q("SELECT `gcontact`.* FROM `glink` left join `gcontact` on `glink`.`gcid` = `gcontact`.`id` - where ((`glink`.cid != 0 and `glink`.`cid` = %d) or ( `glink`.`zcid` != 0 and `glink`.`zcid` = %d )) - and `glink`.`uid` = %d - and `gcontact`.`nurl` in (select nurl from contact where uid = %d and self = 0 and id != %d ) + where `glink`.`zcid` = %d + and `gcontact`.`nurl` in (select nurl from contact where uid = %d and self = 0 ) order by `gcontact`.`name` asc limit 0, %d", - intval($cid), - intval($zid), + intval($zcid), intval($uid), - intval($uid), - intval($cid), intval($limit) ); From e247ed3de25e740c8a0993b35a78e7bb5134c3f3 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 1 May 2012 20:36:35 -0700 Subject: [PATCH 08/10] cross fingers --- include/socgraph.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/socgraph.php b/include/socgraph.php index a3e20a6414..cf00422560 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -207,7 +207,7 @@ function count_common_friends_zcid($uid,$zcid) { where `glink`.`zcid` = %d and `gcontact`.`nurl` in (select nurl from contact where uid = %d and self = 0 ) ", intval($zcid), - intval($uid), + intval($uid) ); if(count($r)) From 1fab28c413d79a132b1592ff51db3729141d6998 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 1 May 2012 20:38:06 -0700 Subject: [PATCH 09/10] fix size --- view/remote_friends_common.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/remote_friends_common.tpl b/view/remote_friends_common.tpl index b44a5b639d..a5a36b1376 100644 --- a/view/remote_friends_common.tpl +++ b/view/remote_friends_common.tpl @@ -5,7 +5,7 @@
From becdb1f5085f2561b8b0acebbdbf43e4a81d50da Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 1 May 2012 21:22:27 -0700 Subject: [PATCH 10/10] final touches - show friends in common with total strangers from different sites --- include/contact_widgets.php | 13 +++++++++---- include/socgraph.php | 7 ++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/include/contact_widgets.php b/include/contact_widgets.php index 3fd311e4a2..cfe27c5c9b 100644 --- a/include/contact_widgets.php +++ b/include/contact_widgets.php @@ -154,17 +154,22 @@ function common_friends_visitor_widget($profile_uid) { } } - if($zcid == 0) + if($cid == 0 && $zcid == 0) return; require_once('include/socgraph.php'); - - $t = count_common_friends_zcid($profile_uid,$zcid); + if($cid) + $t = count_common_friends($profile_uid,$cid); + else + $t = count_common_friends($profile_uid,$cid); if(! $t) return; - $r = common_friends_zcid($profile_uid,$zcid); + if($cid) + $r = common_friends($profile_uid,$cid,5); + else + $r = common_friends_zcid($profile_uid,$zcid); return replace_macros(get_markup_template('remote_friends_common.tpl'), array( '$desc' => sprintf( tt("%d friend in common", "%d friends in common", $t), $t), diff --git a/include/socgraph.php b/include/socgraph.php index cf00422560..a08d580741 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -182,17 +182,18 @@ function count_common_friends($uid,$cid) { } -function common_friends($uid,$cid) { +function common_friends($uid,$cid,$limit=9999) { $r = q("SELECT `gcontact`.* FROM `glink` left join `gcontact` on `glink`.`gcid` = `gcontact`.`id` where `glink`.`cid` = %d and `glink`.`uid` = %d and `gcontact`.`nurl` in (select nurl from contact where uid = %d and self = 0 and id != %d ) - order by `gcontact`.`name` asc ", + order by `gcontact`.`name` asc limit 0, %d", intval($cid), intval($uid), intval($uid), - intval($cid) + intval($cid), + intval($limit) ); return $r;