"follow" now creates an address book entry, which means we can start tying that into the "connections" module - still have to turn the "contact edit" page from a mockup to real code, but it's all starting to flow.

This commit is contained in:
friendica 2012-11-06 18:13:47 -08:00
parent 55df0452b6
commit 295b865d06
5 changed files with 69 additions and 44 deletions

View File

@ -3,8 +3,8 @@
function vcard_from_xchan($xchan) { function vcard_from_xchan($xchan) {
return replace_macros(get_markup_template('xchan_vcard.tpl'),array( return replace_macros(get_markup_template('xchan_vcard.tpl'),array(
$name => $abook['xchan_name'], '$name' => $xchan['xchan_name'],
$photo => $abook['xchan_photo_l'] '$photo' => $xchan['xchan_photo_l']
)); ));
} }
@ -206,26 +206,23 @@ function contact_photo_menu($contact) {
$poke_link=""; $poke_link="";
$sparkle = false; $sparkle = false;
if($contact['network'] === NETWORK_DFRN) { if($contact['xchan_network'] === NETWORK_ZOT) {
$sparkle = true; $sparkle = true;
$profile_link = $a->get_baseurl() . '/redir/' . $contact['id']; $profile_link = $a->get_baseurl() . '/magic?f=&id=' . $contact['abook_id'];
} }
else else
$profile_link = $contact['url']; $profile_link = $contact['xchan_url'];
if($profile_link === 'mailbox')
$profile_link = '';
if($sparkle) { if($sparkle) {
$status_link = $profile_link . "?url=status"; $status_link = $profile_link . "&url=status";
$photos_link = $profile_link . "?url=photos"; $photos_link = $profile_link . "&url=photos";
$profile_link = $profile_link . "?url=profile"; $profile_link = $profile_link . "&url=profile";
$pm_url = $a->get_baseurl() . '/message/new/' . $contact['id']; $pm_url = $a->get_baseurl() . '/message/new/' . $contact['xchan_hash'];
} }
$poke_link = $a->get_baseurl() . '/poke/?f=&c=' . $contact['id']; $poke_link = $a->get_baseurl() . '/poke/?f=&c=' . $contact['abook_id'];
$contact_url = $a->get_baseurl() . '/contacts/' . $contact['id']; $contact_url = $a->get_baseurl() . '/connections/' . $contact['abook_id'];
$posts_link = $a->get_baseurl() . '/network/?cid=' . $contact['id']; $posts_link = $a->get_baseurl() . '/network/?cid=' . $contact['abook_id'];
$menu = Array( $menu = Array(
t("Poke") => $poke_link, t("Poke") => $poke_link,
@ -245,10 +242,7 @@ function contact_photo_menu($contact) {
$o = ""; $o = "";
foreach($menu as $k=>$v){ foreach($menu as $k=>$v){
if ($v!="") { if ($v!="") {
if(($k !== t("Network Posts")) && ($k !== t("Send PM")) && ($k !== t('Edit Contact'))) $o .= "<li><a href=\"$v\">$k</a></li>\n";
$o .= "<li><a target=\"redir\" href=\"$v\">$k</a></li>\n";
else
$o .= "<li><a href=\"$v\">$k</a></li>\n";
} }
} }
return $o; return $o;

View File

@ -73,6 +73,8 @@ function new_contact($uid,$url,$channel,$interactive = false) {
if(! $x['success']) if(! $x['success'])
return $x; return $x;
$xchan_hash = $x['hash'];
// Do we already have an abook entry? // Do we already have an abook entry?
// go directly to the abook edit page. // go directly to the abook edit page.
@ -100,10 +102,20 @@ function new_contact($uid,$url,$channel,$interactive = false) {
} }
$r = q("insert into abook ( abook_account, abook_channel, abook_xchan, abook_their_perms, abook_created, abook_updated )
values( %d, %d, '%s', %d, '%s', '%s' ) ",
intval(get_account_id()),
intval(local_user()),
dbesc($xchan_hash),
intval($their_perms),
dbesc(datetime_convert()),
dbesc(datetime_convert())
);
if(! $r)
logger('mod_follow: abook creation failed');
// Else create an entry
// Then send a ping/message to the other side // Then send a ping/message to the other side

View File

@ -294,6 +294,7 @@ function import_xchan_from_json($j) {
if(! x($ret,'message')) { if(! x($ret,'message')) {
$ret['success'] = true; $ret['success'] = true;
$ret['hash'] = $xchan_hash;
} }
return $ret; return $ret;
} }

View File

@ -144,18 +144,36 @@ function connections_content(&$a) {
return; return;
} }
$xchan = null;
if(argc() == 3) { if(argc() == 3) {
$cmd = argv(2);
$cmd = argv(1); if(argv(1) === 'profile') {
if($cmd === 'profile') {
$xchan_hash = argv(2); $xchan_hash = argv(2);
if($xchan_hash) { if($xchan_hash) {
$r = q("select * from xchan where xchan_hash = '%s' limit 1", $r = q("select * from xchan where xchan_hash = '%s' limit 1",
dbesc($xchan_hash) dbesc($xchan_hash)
); );
if($r && count($r)) { if($r) {
$xchan = $r[0];
}
}
}
elseif(intval(argv(1)) && argv(2) === 'profile')
$r = q("SELECT abook.*, xchan.*
FROM abook left join xchan on abook_xchan = xchan_hash
WHERE abook_channel = %d and abook_id = %d LIMIT 1",
intval(local_user()),
intval(argv(1))
);
if($r)
$xchan = $r[0];
if($xchan) {
$o .= <<< EOT $o .= <<< EOT
<script language="JavaScript"> <script language="JavaScript">
<!-- <!--
@ -188,7 +206,7 @@ window.onresize=resize_iframe;
</script> </script>
<iframe id="glu" width="100%" src="{$r[0]['xchan_url']}" onload="resize_iframe()"> <iframe id="glu" width="100%" src="{$xchan['xchan_url']}" onload="resize_iframe()">
</iframe> </iframe>
EOT; EOT;
@ -196,10 +214,10 @@ EOT;
// $o .= '<div id="profile-frame-wrapper" style="width: 100%; height: 100%;"><iframe id="profile-frame" src="' . $r[0]['xchan_url'] . '" style="width: 100%; height: 100%;"></iframe></div>'; // $o .= '<div id="profile-frame-wrapper" style="width: 100%; height: 100%;"><iframe id="profile-frame" src="' . $r[0]['xchan_url'] . '" style="width: 100%; height: 100%;"></iframe></div>';
return $o; return $o;
}
}
} }
$contact_id = intval(argv(1)); $contact_id = intval(argv(1));
if(! $contact_id) if(! $contact_id)
return; return;
@ -207,7 +225,7 @@ EOT;
$cmd = argv(2); $cmd = argv(2);
$orig_record = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook_xchan = xchan_hash $orig_record = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook_xchan = xchan_hash
WHERE abook_id = %d AND abook_channel = %d AND NOT abook_flags & %d LIMIT 1", WHERE abook_id = %d AND abook_channel = %d AND NOT ( abook_flags & %d ) LIMIT 1",
intval($contact_id), intval($contact_id),
intval(local_user()), intval(local_user()),
intval(ABOOK_FLAG_SELF) intval(ABOOK_FLAG_SELF)
@ -305,7 +323,7 @@ EOT;
$slider_tpl = get_markup_template('contact_slider.tpl'); $slider_tpl = get_markup_template('contact_slider.tpl');
$slide = replace_macros($slider_tpl,array( $slide = replace_macros($slider_tpl,array(
'$me' => t('Me'), '$me' => t('Me'),
'$val' => $contact['closeness'], '$val' => $contact['abook_closeness'],
'$intimate' => t('Best Friends'), '$intimate' => t('Best Friends'),
'$friends' => t('Friends'), '$friends' => t('Friends'),
'$coworkers' => t('Co-workers'), '$coworkers' => t('Co-workers'),
@ -316,7 +334,8 @@ EOT;
$o .= replace_macros($tpl,array( $o .= replace_macros($tpl,array(
'$header' => t('Contact Settings') . ' for ' . $contact['name'], '$header' => t('Contact Settings') . ' for ' . $contact['xchan_name'],
'$viewprof' => t('View Profile'),
'$slide' => $slide, '$slide' => $slide,
'$tab_str' => $tab_str, '$tab_str' => $tab_str,
'$submit' => t('Submit'), '$submit' => t('Submit'),
@ -324,7 +343,7 @@ EOT;
'$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']), '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
'$lbl_info1' => t('Contact Information / Notes'), '$lbl_info1' => t('Contact Information / Notes'),
'$infedit' => t('Edit contact notes'), '$infedit' => t('Edit contact notes'),
'$close' => $contact['closeness'], '$close' => $contact['abook_closeness'],
'$them' => t('Their Settings'), '$them' => t('Their Settings'),
'$me' => t('My Settings'), '$me' => t('My Settings'),
@ -344,7 +363,7 @@ EOT;
'$common_link' => $a->get_baseurl(true) . '/common/loc/' . local_user() . '/' . $contact['id'], '$common_link' => $a->get_baseurl(true) . '/common/loc/' . local_user() . '/' . $contact['id'],
'$all_friends' => $all_friends, '$all_friends' => $all_friends,
'$relation_text' => $relation_text, '$relation_text' => $relation_text,
'$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']), '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['xchan_name'],$contact['xchan_url']),
'$blockunblock' => t('Block/Unblock contact'), '$blockunblock' => t('Block/Unblock contact'),
'$ignorecont' => t('Ignore contact'), '$ignorecont' => t('Ignore contact'),
'$lblcrepair' => t("Repair URL settings"), '$lblcrepair' => t("Repair URL settings"),
@ -360,7 +379,7 @@ EOT;
'$last_update' => $last_update, '$last_update' => $last_update,
'$udnow' => t('Update now'), '$udnow' => t('Update now'),
'$profile_select' => contact_profile_assign($contact['profile_id'],(($contact['network'] !== NETWORK_DFRN) ? true : false)), '$profile_select' => contact_profile_assign($contact['profile_id'],(($contact['network'] !== NETWORK_DFRN) ? true : false)),
'$contact_id' => $contact['id'], '$contact_id' => $contact['abook_id'],
'$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ), '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
'$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ), '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
'$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''), '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
@ -423,7 +442,7 @@ EOT;
} }
} }
$sql_extra = "and ( abook_flags & " . $search_flags . " ) "; $sql_extra = (($search_flags) ? "and ( abook_flags & " . $search_flags . " ) " : "");
$search = ((x($_REQUEST,'search')) ? notags(trim($_REQUEST['search'])) : ''); $search = ((x($_REQUEST,'search')) ? notags(trim($_REQUEST['search'])) : '');
@ -508,7 +527,6 @@ EOT;
$total = $r[0]['total']; $total = $r[0]['total'];
} }
$r = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash $r = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash
WHERE abook_channel = %d and not (abook_flags & %d) $sql_extra $sql_extra2 ORDER BY xchan_name LIMIT %d , %d ", WHERE abook_channel = %d and not (abook_flags & %d) $sql_extra $sql_extra2 ORDER BY xchan_name LIMIT %d , %d ",
intval(local_user()), intval(local_user()),
@ -540,27 +558,27 @@ EOT;
break; break;
} }
if(($rr['network'] === 'dfrn') && ($rr['rel'])) { if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
$url = "redir/{$rr['id']}"; $url = "redir/{$rr['abook_id']}";
$sparkle = ' class="sparkle" '; $sparkle = ' class="sparkle" ';
} }
else { else {
$url = $rr['url']; $url = $rr['xchan_url'];
$sparkle = ''; $sparkle = '';
} }
$contacts[] = array( $contacts[] = array(
'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']), 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['xchan_name'],$rr['xchan_url']),
'edit_hover' => t('Edit contact'), 'edit_hover' => t('Edit contact'),
'photo_menu' => contact_photo_menu($rr), 'photo_menu' => contact_photo_menu($rr),
'id' => $rr['id'], 'id' => $rr['abook_id'],
'alt_text' => $alt_text, 'alt_text' => $alt_text,
'dir_icon' => $dir_icon, 'dir_icon' => $dir_icon,
'thumb' => $rr['thumb'], 'thumb' => $rr['xchan_photo_m'],
'name' => $rr['name'], 'name' => $rr['xchan_name'],
'username' => $rr['name'], 'username' => $rr['xchan_name'],
'sparkle' => $sparkle, 'sparkle' => $sparkle,
'itemurl' => $rr['url'], 'itemurl' => $rr['xchan_url'],
'url' => $url, 'url' => $url,
'network' => network_to_name($rr['network']), 'network' => network_to_name($rr['network']),
); );

View File

@ -2,7 +2,7 @@
<h2>$header</h2> <h2>$header</h2>
<br /> <br />
<a href="" style="background-color: #CCC; padding: 10px; border-radius: 5px;">View Profile</a><a href="" style="background-color: #CCC; padding: 10px; border-radius: 5px; margin-left: 20px;">Archive</a> <a href="connections/$contact_id/profile">$viewprof</a>
<div id="contact-edit-wrapper"> <div id="contact-edit-wrapper">
<br /> <br />