X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fdfrn_request.php;h=b809929d7e14b4b506348b3200b437534b35e63f;hb=39927e3dc5d0fc942ef9428b5c5c0d9b8cbb2f56;hp=ceec83e90b25a7202a6955c3bd7736de721f4401;hpb=cafd4003522a472d2709569ea5eb5f80b817af23;p=friendica.git diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php old mode 100755 new mode 100644 index ceec83e90b..b809929d7e --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -43,7 +43,7 @@ function dfrn_request_post(&$a) { return; - if($_POST['cancel']) { + if(x($_POST, 'cancel')) { goaway(z_root()); } @@ -77,9 +77,10 @@ function dfrn_request_post(&$a) { * Lookup the contact based on their URL (which is the only unique thing we have at the moment) */ - $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `self` = 0 LIMIT 1", + $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND (`url` = '%s' OR `nurl` = '%s') AND `self` = 0 LIMIT 1", intval(local_user()), - dbesc($dfrn_url) + dbesc($dfrn_url), + dbesc(normalise_link($dfrn_url)) ); if(count($r)) { @@ -179,7 +180,7 @@ function dfrn_request_post(&$a) { // (ignore reply, nothing we can do it failed) - goaway($dfrn_url); + goaway(zrl($dfrn_url)); return; // NOTREACHED } @@ -260,7 +261,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) { @@ -285,7 +286,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) { @@ -300,6 +301,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)) { @@ -307,17 +310,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); @@ -594,7 +708,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); } @@ -647,6 +762,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 ); @@ -663,10 +783,28 @@ function dfrn_request_content(&$a) { else $tpl = get_markup_template('auto_request.tpl'); - $page_desc = sprintf( t('Diaspora members: Please do not use this form. Instead, enter "%s" into your Diaspora search bar.'), - $target_addr) . EOL . EOL; + # $page_desc = sprintf( t('Diaspora members: Please do not use this form. Instead, enter "%s" into your Diaspora search bar.'), + # $target_addr) . EOL . EOL; + + $page_desc .= t("Please enter your 'Identity Address' from one of the following supported communications networks:"); + + // see if we are allowed to have NETWORK_MAIL2 contacts + + $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) { + $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1", + intval($a->profile['uid']) + ); + if(! count($r)) + $mail_disabled = 1; + } + + $emailnet = (($mail_disabled) ? '' : t("Connect as an email follower \x28Coming soon\x29")); - $page_desc .= t("Please enter your 'Identity Address' from one of the following supported social networks:"); + $invite_desc = t('If you are not yet a member of the free social web, follow this link to find a public Friendica site and join us today.'); $o .= replace_macros($tpl,array( '$header' => t('Friend/Connection Request'), @@ -677,11 +815,13 @@ function dfrn_request_content(&$a) { '$no' => t('No'), '$add_note' => t('Add a personal note:'), '$page_desc' => $page_desc, - '$friendika' => t('Friendica'), + '$friendica' => t('Friendica'), '$statusnet' => t('StatusNet/Federated Social Web'), '$diaspora' => t('Diaspora'), - '$diasnote' => t('- please share from your own site as noted above'), + '$diasnote' => sprintf (t(' - please do not use this form. Instead, enter %s into your Diaspora search bar.'),$target_addr), '$your_address' => t('Your Identity Address:'), + '$invite_desc' => $invite_desc, + '$emailnet' => $emailnet, '$submit' => t('Submit Request'), '$cancel' => t('Cancel'), '$nickname' => $a->argv[1],