diff --git a/include/items.php b/include/items.php index ad121bbf5f..2af2b5f55c 100644 --- a/include/items.php +++ b/include/items.php @@ -1263,7 +1263,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) $when = datetime_convert('UTC','UTC','now','Y-m-d H:i:s'); } if($deleted && is_array($contact)) { - $r = q("SELECT `item`.*, `contact`.`self` FROM `item` left join `contact` on `item`.`contact-id` = `contact`.id` + $r = q("SELECT `item`.*, `contact`.`self` FROM `item` left join `contact` on `item`.`contact-id` = `contact`.`id` WHERE `uri` = '%s' AND `item`.`uid` = %d AND `contact-id` = %d LIMIT 1", dbesc($uri), intval($importer['uid']), diff --git a/include/socgraph.php b/include/socgraph.php index 3e9c00633b..c81c7b6952 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -123,4 +123,40 @@ function poco_load($cid,$uid = 0,$url = null) { intval($uid) ); +} + + +function count_common_friends($uid,$cid) { + + $r = q("SELECT count(*) as `total` + 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 ) ", + intval($cid), + intval($uid), + intval($uid), + intval($cid) + ); + + if(count($r)) + return $r[0]['total']; + return 0; + +} + + +function common_friends($uid,$cid) { + + $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 ) ", + intval($cid), + intval($uid), + intval($uid), + intval($cid) + ); + + return $r; + } \ No newline at end of file diff --git a/mod/common.php b/mod/common.php new file mode 100644 index 0000000000..852388c149 --- /dev/null +++ b/mod/common.php @@ -0,0 +1,61 @@ +argc > 1) + $cid = intval($a->argv[1]); + if(! $cid) + return; + + $c = q("select name, url, photo from contact where id = %d and uid = %d limit 1", + intval($cid), + intval(local_user()) + ); + + $a->page['aside'] .= '
' + . '
' . $c[0]['name'] . '
' + . '
' + . '' . $c[0]['name'] . '
' + . '
'; + + + if(! count($c)) + return; + + $o .= '

' . t('Common Friends') . '

'; + +// $o .= '

' . sprintf( t('You and %s'),$c[0]['name']) . '

'; + + + $r = common_friends(local_user(),$cid); + + if(! count($r)) { + $o .= t('No friends in common.'); + return $o; + } + + $tpl = get_markup_template('common_friends.tpl'); + + foreach($r as $rr) { + + $o .= replace_macros($tpl,array( + '$url' => $rr['url'], + '$name' => $rr['name'], + '$photo' => $rr['photo'], + '$tags' => '' + )); + } + + $o .= cleardiv(); +// $o .= paginate($a); + return $o; +} diff --git a/mod/contacts.php b/mod/contacts.php index 9bbcea07d3..ecfbe6c2c7 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -1,6 +1,7 @@ ' . sprintf( t('Network type: %s'),network_to_name($r[0]['network'])) . ''; + $common = count_common_friends(local_user(),$r[0]['id']); + $common_text = (($common) ? sprintf( tt('%d friends in common','%d friends in common', $common),$common) : ''); $o .= replace_macros($tpl,array( '$header' => t('Contact Editor'), '$submit' => t('Submit'), @@ -275,6 +278,8 @@ function contacts_content(&$a) { '$lbl_rep2' => t('Occasionally your friends may wish to inquire about this person\'s online legitimacy.'), '$lbl_rep3' => t('You may help them choose whether or not to interact with this person by providing a reputation to guide them.'), '$lbl_rep4' => t('Please take a moment to elaborate on this selection if you feel it could be helpful to others.'), + '$common_text' => $common_text, + '$common_link' => $a->get_baseurl() . '/common/' . $r[0]['id'], '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$r[0]['name'],$r[0]['url']), '$blockunblock' => t('Block/Unblock contact'), '$ignorecont' => t('Ignore contact'), diff --git a/view/common_friends.tpl b/view/common_friends.tpl new file mode 100644 index 0000000000..1f610d8c4f --- /dev/null +++ b/view/common_friends.tpl @@ -0,0 +1,12 @@ +
+
+ + $name + +
+
+
+ $name +
+
+
\ No newline at end of file diff --git a/view/contact_edit.tpl b/view/contact_edit.tpl index 248140a6bd..c2e3e36fba 100644 --- a/view/contact_edit.tpl +++ b/view/contact_edit.tpl @@ -19,6 +19,7 @@ $nettype
+
+ + {{ if $common_text }} +
+ $common_text + + {{ endif }} + + $insecure $blocked $ignored diff --git a/view/profile_vcard.tpl b/view/profile_vcard.tpl index d65b65784c..c78eb9b7f5 100644 --- a/view/profile_vcard.tpl +++ b/view/profile_vcard.tpl @@ -21,7 +21,7 @@ {{ if $pdesc }}
$profile.pdesc
{{ endif }} -
$profile.name
+
$profile.name