X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fdfrn_request.php;h=cec2d7f8b01c1420f82a6b6b76090c897b305047;hb=d8d20f2afa1ee6d8729fd3cb58c291d3f0419915;hp=5881b7b51bed3805f6a68aaef12239c24c15e6bd;hpb=cb05801a9031254f5882038de07a3ee4d5f89dd0;p=friendica.git diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index 5881b7b51b..cec2d7f8b0 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -68,7 +68,7 @@ function dfrn_request_post(&$a) { $dfrn_url = notags(trim($_POST['dfrn_url'])); $aes_allow = (((x($_POST,'aes_allow')) && ($_POST['aes_allow'] == 1)) ? 1 : 0); $confirm_key = ((x($_POST,'confirm_key')) ? $_POST['confirm_key'] : ""); - + $hidden = ((x($_POST,'hidden-contact')) ? intval($_POST['hidden-contact']) : 0); $contact_record = null; if(x($dfrn_url)) { @@ -98,8 +98,9 @@ function dfrn_request_post(&$a) { } if(is_array($contact_record)) { - $r = q("UPDATE `contact` SET `ret-aes` = %d WHERE `id` = %d LIMIT 1", + $r = q("UPDATE `contact` SET `ret-aes` = %d, hidden = %d WHERE `id` = %d LIMIT 1", intval($aes_allow), + intval($hidden), intval($contact_record['id']) ); } @@ -144,8 +145,8 @@ function dfrn_request_post(&$a) { */ $r = q("INSERT INTO `contact` ( `uid`, `created`,`url`, `nurl`, `name`, `nick`, `photo`, `site-pubkey`, - `request`, `confirm`, `notify`, `poll`, `poco`, `network`, `aes_allow`) - VALUES ( %d, '%s', '%s', '%s', '%s' , '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)", + `request`, `confirm`, `notify`, `poll`, `poco`, `network`, `aes_allow`, `hidden`) + VALUES ( %d, '%s', '%s', '%s', '%s' , '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d)", intval(local_user()), datetime_convert(), dbesc($dfrn_url), @@ -160,7 +161,8 @@ function dfrn_request_post(&$a) { $parms['dfrn-poll'], $parms['dfrn-poco'], dbesc(NETWORK_DFRN), - intval($aes_allow) + intval($aes_allow), + intval($hidden) ); } @@ -168,6 +170,21 @@ function dfrn_request_post(&$a) { info( t("Introduction complete.") . EOL); } + $r = q("select id from contact where uid = %d and url = '%s' and `site-pubkey` = '%s' limit 1", + intval(local_user()), + dbesc($dfrn_url), + $parms['key'] // this was already escaped + ); + if(count($r)) { + $g = q("select def_gid from user where uid = %d limit 1", + intval(local_user()) + ); + if($g && intval($g[0]['def_gid'])) { + require_once('include/group.php'); + group_add_member(local_user(),'',$r[0]['id'],$g[0]['def_gid']); + } + } + /** * Allow the blocked remote notification to complete */ @@ -180,7 +197,7 @@ function dfrn_request_post(&$a) { // (ignore reply, nothing we can do it failed) - goaway($dfrn_url); + goaway(zrl($dfrn_url)); return; // NOTREACHED } @@ -261,7 +278,7 @@ function dfrn_request_post(&$a) { WHERE `intro`.`blocked` = 1 AND `contact`.`self` = 0 AND `contact`.`network` != '%s' AND `intro`.`datetime` < UTC_TIMESTAMP() - INTERVAL 30 MINUTE ", - dbesc(NETWORK_MAIL) + dbesc(NETWORK_MAIL2) ); if(count($r)) { foreach($r as $rr) { @@ -286,7 +303,7 @@ function dfrn_request_post(&$a) { WHERE `intro`.`blocked` = 1 AND `contact`.`self` = 0 AND `contact`.`network` = '%s' AND `intro`.`datetime` < UTC_TIMESTAMP() - INTERVAL 3 DAY ", - dbesc(NETWORK_MAIL) + dbesc(NETWORK_MAIL2) ); if(count($r)) { foreach($r as $rr) { @@ -301,6 +318,8 @@ function dfrn_request_post(&$a) { } } + $email_follow = (x($_POST,'email_follow') ? intval($_POST['email_follow']) : 0); + $real_name = (x($_POST,'realname') ? notags(trim($_POST['realname'])) : ''); $url = trim($_POST['dfrn_url']); if(! strlen($url)) { @@ -308,17 +327,128 @@ function dfrn_request_post(&$a) { return; } - // Canonicalise email-style profile locator - $hcard = ''; - $url = webfinger_dfrn($url,$hcard); - if(substr($url,0,5) === 'stat:') { - $network = NETWORK_OSTATUS; - $url = substr($url,5); + if($email_follow) { + + if(! validate_email($url)) { + notice( t('Invalid email address.') . EOL); + return; + } + + $addr = $url; + $name = ($realname) ? $realname : $addr; + $nick = substr($addr,0,strpos($addr,'@')); + $url = 'http://' . substr($addr,strpos($addr,'@') + 1); + $nurl = normalise_url($host); + $poll = 'email ' . random_string(); + $notify = 'smtp ' . random_string(); + $blocked = 1; + $pending = 1; + $network = NETWORK_MAIL2; + $rel = CONTACT_IS_FOLLOWER; + + $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1); + if(get_config('system','dfrn_only')) + $mail_disabled = 1; + + if(! $mail_disabled) { + $failed = false; + $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1", + intval($uid) + ); + if(! count($r)) { + notice( t('This account has not been configured for email. Request failed.') . EOL); + return; + } + } + + $r = q("insert into contact ( uid, created, addr, name, nick, url, nurl, poll, notify, blocked, pending, network, rel ) + values( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d ) ", + intval($uid), + dbesc(datetime_convert()), + dbesc($addr), + dbesc($name), + dbesc($nick), + dbesc($url), + dbesc($nurl), + dbesc($poll), + dbesc($notify), + intval($blocked), + intval($pending), + dbesc($network), + intval($rel) + ); + + $r = q("select id from contact where poll = '%s' and uid = %d limit 1", + dbesc($poll), + intval($uid) + ); + if(count($r)) { + $contact_id = $r[0]['id']; + + $g = q("select def_gid from user where uid = %d limit 1", + intval($uid) + ); + if($g && intval($g[0]['def_gid'])) { + require_once('include/group.php'); + group_add_member($uid,'',$contact_id,$g[0]['def_gid']); + } + + $photo = avatar_img($addr); + + $r = q("UPDATE `contact` SET + `photo` = '%s', + `thumb` = '%s', + `micro` = '%s', + `name-date` = '%s', + `uri-date` = '%s', + `avatar-date` = '%s', + `hidden` = 0, + WHERE `id` = %d LIMIT 1 + ", + dbesc($photos[0]), + dbesc($photos[1]), + dbesc($photos[2]), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + intval($contact_id) + ); + } + + // contact is created. Now create an introduction + + $hash = random_string(); + + $r = q("insert into intro ( uid, `contact-id`, knowyou, note, hash, datetime, blocked ) + values( %d , %d, %d, '%s', '%s', '%s', %d ) ", + intval($uid), + intval($contact_id), + ((x($_POST,'knowyou') && ($_POST['knowyou'] == 1)) ? 1 : 0), + dbesc(notags(trim($_POST['dfrn-request-message']))), + dbesc($hash), + dbesc(datetime_convert()), + 1 + ); + + // Next send an email verify form to the requestor. + } + else { - $network = NETWORK_DFRN; + + // Canonicalise email-style profile locator + + $url = webfinger_dfrn($url,$hcard); + + if(substr($url,0,5) === 'stat:') { + $network = NETWORK_OSTATUS; + $url = substr($url,5); + } + else { + $network = NETWORK_DFRN; + } } logger('dfrn_request: url: ' . $url); @@ -536,6 +666,8 @@ function dfrn_request_content(&$a) { $o = replace_macros($tpl,array( '$dfrn_url' => $dfrn_url, '$aes_allow' => (($aes_allow) ? '' : "" ), + '$hidethem' => t('Hide this contact'), + '$hidechecked' => '', '$confirm_key' => $confirm_key, '$welcome' => sprintf( t('Welcome home %s.'), $a->user['username']), '$please' => sprintf( t('Please confirm your introduction/connection request to %s.'), $dfrn_url), @@ -567,7 +699,7 @@ function dfrn_request_content(&$a) { $auto_confirm = false; if(count($r)) { - if($r[0]['page-flags'] != PAGE_NORMAL) + if(($r[0]['page-flags'] != PAGE_NORMAL) && ($r[0]['page-flags'] != PAGE_PRVGROUP)) $auto_confirm = true; if(! $auto_confirm) { @@ -595,7 +727,8 @@ function dfrn_request_content(&$a) { 'node' => $r[0]['nickname'], 'dfrn_id' => $r[0]['issued-id'], 'intro_id' => $intro[0]['id'], - 'duplex' => (($r[0]['page-flags'] == PAGE_FREELOVE) ? 1 : 0) + 'duplex' => (($r[0]['page-flags'] == PAGE_FREELOVE) ? 1 : 0), + 'activity' => intval(get_pconfig($r[0]['uid'],'system','post_newfriend')) ); dfrn_confirm_post($a,$handsfree); } @@ -648,6 +781,11 @@ function dfrn_request_content(&$a) { $myaddr = ((x($_GET,'address')) ? $_GET['address'] : ''); } + // last, try a zrl + if(! strlen($myaddr)) + $myaddr = get_my_url(); + + $target_addr = $a->profile['nickname'] . '@' . substr(z_root(), strpos(z_root(),'://') + 3 );