]> git.mxchange.org Git - friendica.git/blobdiff - mod/dfrn_request.php
More usage of dbm::is_result($r) instead of count($r):
[friendica.git] / mod / dfrn_request.php
index c8742394b5fdd3ce8497da011ac623f2f8d13c45..66c891ef089cdf711e92eae1f4ca89225d8a7598 100644 (file)
@@ -8,6 +8,8 @@
  * friend requests.
  *
  * @see PDF with dfrn specs: https://github.com/friendica/friendica/blob/master/spec/dfrn2.pdf
+ *    You also find a graphic which describes the confirmation process at
+ *    https://github.com/friendica/friendica/blob/master/spec/dfrn2_contact_request.png
  */
 
 require_once('include/enotify.php');
@@ -75,6 +77,8 @@ function dfrn_request_post(&$a) {
                        $confirm_key = ((x($_POST,'confirm_key')) ? $_POST['confirm_key'] : "");
                        $hidden = ((x($_POST,'hidden-contact')) ? intval($_POST['hidden-contact']) : 0);
                        $contact_record = null;
+                       $blocked = 1;
+                       $pending = 1;
 
                        if(x($dfrn_url)) {
 
@@ -83,11 +87,11 @@ function dfrn_request_post(&$a) {
                                 */
 
                                $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND NOT `self` LIMIT 1",
-                                       dbesc($dfrn_url),
+                                       intval(local_user()),
                                        dbesc(normalise_link($dfrn_url))
                                );
 
-                               if(count($r)) {
+                               if(dbm::is_result($r)) {
                                        if(strlen($r[0]['dfrn-id'])) {
 
                                                /*
@@ -148,8 +152,8 @@ function dfrn_request_post(&$a) {
                                         */
 
                                        $r = q("INSERT INTO `contact` ( `uid`, `created`,`url`, `nurl`, `addr`, `name`, `nick`, `photo`, `site-pubkey`,
-                                               `request`, `confirm`, `notify`, `poll`, `poco`, `network`, `aes_allow`, `hidden`)
-                                               VALUES ( %d, '%s', '%s', '%s', '%s', '%s' , '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d)",
+                                               `request`, `confirm`, `notify`, `poll`, `poco`, `network`, `aes_allow`, `hidden`, `blocked`, `pending`)
+                                               VALUES ( %d, '%s', '%s', '%s', '%s', '%s' , '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d)",
                                                intval(local_user()),
                                                datetime_convert(),
                                                dbesc($dfrn_url),
@@ -166,7 +170,9 @@ function dfrn_request_post(&$a) {
                                                $parms['dfrn-poco'],
                                                dbesc(NETWORK_DFRN),
                                                intval($aes_allow),
-                                               intval($hidden)
+                                               intval($hidden),
+                                               intval($blocked),
+                                               intval($pending)
                                        );
                                }
 
@@ -179,7 +185,7 @@ function dfrn_request_post(&$a) {
                                        dbesc($dfrn_url),
                                        $parms['key'] // this was already escaped
                                );
-                               if(count($r)) {
+                               if(dbm::is_result($r)) {
                                        $def_gid = get_default_group(local_user(), $r[0]["network"]);
                                        if(intval($def_gid))
                                                group_add_member(local_user(), '', $r[0]['id'], $def_gid);
@@ -252,6 +258,8 @@ function dfrn_request_post(&$a) {
        $contact_record = null;
        $failed         = false;
        $parms          = null;
+       $blocked = 1;
+       $pending = 1;
 
 
        if( x($_POST,'dfrn_url')) {
@@ -265,7 +273,7 @@ function dfrn_request_post(&$a) {
                                dbesc(datetime_convert('UTC','UTC','now - 24 hours')),
                                intval($uid)
                        );
-                       if(count($r) > $maxreq) {
+                       if(dbm::is_result($r) > $maxreq) {
                                notice( sprintf( t('%s has received too many connection requests today.'),  $a->profile['name']) . EOL);
                                notice( t('Spam protection measures have been invoked.') . EOL);
                                notice( t('Friends are advised to please try again in 24 hours.') . EOL);
@@ -287,7 +295,7 @@ function dfrn_request_post(&$a) {
                        AND `intro`.`datetime` < UTC_TIMESTAMP() - INTERVAL 30 MINUTE ",
                        dbesc(NETWORK_MAIL2)
                );
-               if(count($r)) {
+               if(dbm::is_result($r)) {
                        foreach($r as $rr) {
                                if(! $rr['rel']) {
                                        q("DELETE FROM `contact` WHERE `id` = %d",
@@ -312,7 +320,7 @@ function dfrn_request_post(&$a) {
                        AND `intro`.`datetime` < UTC_TIMESTAMP() - INTERVAL 3 DAY ",
                        dbesc(NETWORK_MAIL2)
                );
-               if(count($r)) {
+               if(dbm::is_result($r)) {
                        foreach($r as $rr) {
                                if(! $rr['rel']) {
                                        q("DELETE FROM `contact` WHERE `id` = %d",
@@ -350,8 +358,6 @@ function dfrn_request_post(&$a) {
                        $nurl    = normalise_url($host);
                        $poll    = 'email ' . random_string();
                        $notify  = 'smtp ' . random_string();
-                       $blocked = 1;
-                       $pending = 1;
                        $network = NETWORK_MAIL2;
                        $rel     = CONTACT_IS_FOLLOWER;
 
@@ -364,7 +370,7 @@ function dfrn_request_post(&$a) {
                                $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
                                        intval($uid)
                                );
-                               if(! count($r)) {
+                               if(! dbm::is_result($r)) {
 
                                        notice( t('This account has not been configured for email. Request failed.') . EOL);
                                        return;
@@ -392,7 +398,7 @@ function dfrn_request_post(&$a) {
                                dbesc($poll),
                                intval($uid)
                        );
-                       if(count($r)) {
+                       if(dbm::is_result($r)) {
                                $contact_id = $r[0]['id'];
 
                                $def_gid = get_default_group($uid, $r[0]["network"]);
@@ -536,8 +542,8 @@ function dfrn_request_post(&$a) {
 
                                dbesc_array($parms);
                                $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `addr`, `name`, `nick`, `issued-id`, `photo`, `site-pubkey`,
-                                       `request`, `confirm`, `notify`, `poll`, `poco`, `network` )
-                                       VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )",
+                                       `request`, `confirm`, `notify`, `poll`, `poco`, `network`, `blocked`, `pending` )
+                                       VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d )",
                                        intval($uid),
                                        dbesc(datetime_convert()),
                                        $parms['url'],
@@ -553,7 +559,9 @@ function dfrn_request_post(&$a) {
                                        $parms['dfrn-notify'],
                                        $parms['dfrn-poll'],
                                        $parms['dfrn-poco'],
-                                       dbesc(NETWORK_DFRN)
+                                       dbesc(NETWORK_DFRN),
+                                       intval($blocked),
+                                       intval($pending)
                                );
 
                                // find the contact record we just created
@@ -564,7 +572,7 @@ function dfrn_request_post(&$a) {
                                                $parms['url'],
                                                $parms['issued-id']
                                        );
-                                       if(count($r)) {
+                                       if(dbm::is_result($r)) {
                                                $contact_record = $r[0];
                                                update_contact_avatar($photo, $uid, $contact_record["id"], true);
                                        }
@@ -721,7 +729,7 @@ function dfrn_request_content(&$a) {
 
                        $auto_confirm = false;
 
-                       if(count($r)) {
+                       if(dbm::is_result($r)) {
                                if(($r[0]['page-flags'] != PAGE_NORMAL) && ($r[0]['page-flags'] != PAGE_PRVGROUP))
                                        $auto_confirm = true;
 
@@ -834,7 +842,7 @@ function dfrn_request_content(&$a) {
                        $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
                                intval($a->profile['uid'])
                        );
-                       if(! count($r))
+                       if(! dbm::is_result($r))
                                $mail_disabled = 1;
                }