+function common_friends_visitor_widget($profile_uid) {
+
+ $a = get_app();
+
+ if (local_user() == $profile_uid) {
+ return;
+ }
+
+ $cid = $zcid = 0;
+
+ if (is_array($_SESSION['remote'])) {
+ foreach ($_SESSION['remote'] as $visitor) {
+ if ($visitor['uid'] == $profile_uid) {
+ $cid = $visitor['cid'];
+ break;
+ }
+ }
+ }
+
+ if (! $cid) {
+ if (get_my_url()) {
+ $r = dba::select('contact', array('id'),
+ array('nurl' => normalise_link(get_my_url()), 'uid' => $profile_uid), array('limit' => 1));
+ if (dbm::is_result($r)) {
+ $cid = $r['id'];
+ } else {
+ $r = dba::select('gcontact', array('id'), array('nurl' => normalise_link(get_my_url())), array('limit' => 1));
+ if (dbm::is_result($r))
+ $zcid = $r['id'];
+ }
+ }
+ }
+
+ if ($cid == 0 && $zcid == 0) {
+ return;
+ }
+
+ require_once 'include/socgraph.php';
+
+ if ($cid) {
+ $t = count_common_friends($profile_uid, $cid);
+ } else {
+ $t = count_common_friends_zcid($profile_uid, $zcid);
+ }
+ if (! $t) {
+ return;
+ }
+
+ if ($cid) {
+ $r = common_friends($profile_uid, $cid, 0, 5, true);
+ } else {
+ $r = common_friends_zcid($profile_uid, $zcid, 0, 5, true);
+ }
+
+ return replace_macros(get_markup_template('remote_friends_common.tpl'), array(
+ '$desc' => sprintf( tt("%d contact in common", "%d contacts in common", $t), $t),
+ '$base' => System::baseUrl(),
+ '$uid' => $profile_uid,
+ '$cid' => (($cid) ? $cid : '0'),
+ '$linkmore' => (($t > 5) ? 'true' : ''),
+ '$more' => t('show more'),
+ '$items' => $r
+ ));
+
+};