]> git.mxchange.org Git - friendica.git/blobdiff - mod/dfrn_request.php
Merge branch 'rewrites/dbm_is_result' of github.com:Quix0r/friendica into rewrites...
[friendica.git] / mod / dfrn_request.php
index 9b7dede2e2244d326d512c7d840ffa6a8cd90db3..8bca431dd234f9110839abb5b76efe072f3d24e5 100644 (file)
@@ -1,12 +1,15 @@
 <?php
 
 /**
- *
- * Module: dfrn_request
+ * @file mod/dfrn_request.php
+ * @brief Module: dfrn_request
  *
  * Purpose: Handles communication associated with the issuance of
  * 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');
@@ -14,7 +17,6 @@ require_once('include/Scrape.php');
 require_once('include/Probe.php');
 require_once('include/group.php');
 
-if(! function_exists('dfrn_request_init')) {
 function dfrn_request_init(&$a) {
 
        if($a->argc > 1)
@@ -22,7 +24,7 @@ function dfrn_request_init(&$a) {
 
        profile_load($a,$which);
        return;
-}}
+}
 
 
 /**
@@ -40,8 +42,6 @@ function dfrn_request_init(&$a) {
  * After logging in, we click 'submit' to approve the linkage.
  *
  */
-
-if(! function_exists('dfrn_request_post')) {
 function dfrn_request_post(&$a) {
 
        if(($a->argc != 2) || (! count($a->profile))) {
@@ -55,7 +55,7 @@ function dfrn_request_post(&$a) {
        }
 
 
-       /**
+       /*
         *
         * Scenario 2: We've introduced ourself to another cell, then have been returned to our own cell
         * to confirm the request, and then we've clicked submit (perhaps after logging in).
@@ -65,7 +65,7 @@ function dfrn_request_post(&$a) {
 
        if((x($_POST,'localconfirm')) && ($_POST['localconfirm'] == 1)) {
 
-               /**
+               /*
                 * Ensure this is a valid request
                 */
 
@@ -77,23 +77,24 @@ 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)) {
 
-                               /**
+                               /*
                                 * 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' OR `nurl` = '%s') AND `self` = 0 LIMIT 1",
+                               $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND NOT `self` LIMIT 1",
                                        intval(local_user()),
-                                       dbesc($dfrn_url),
                                        dbesc(normalise_link($dfrn_url))
                                );
 
                                if(dbm::is_result($r)) {
                                        if(strlen($r[0]['dfrn-id'])) {
 
-                                               /**
+                                               /*
                                                 * We don't need to be here. It has already happened.
                                                 */
 
@@ -113,7 +114,7 @@ function dfrn_request_post(&$a) {
                                }
                                else {
 
-                                       /**
+                                       /*
                                         * Scrape the other site's profile page to pick up the dfrn links, key, fn, and photo
                                         */
 
@@ -141,19 +142,18 @@ function dfrn_request_post(&$a) {
 
                                        $photo = $parms["photo"];
 
-                                       /********* Escape the entire array ********/
+                                       // Escape the entire array
 
                                        dbesc_array($parms);
 
-                                       /******************************************/
 
-                                       /**
+                                       /*
                                         * Create a contact record on our site for the other person
                                         */
 
                                        $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),
@@ -170,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)
                                        );
                                }
 
@@ -195,7 +197,7 @@ function dfrn_request_post(&$a) {
                                } else
                                        $forwardurl = $a->get_baseurl()."/contacts";
 
-                               /**
+                               /*
                                 * Allow the blocked remote notification to complete
                                 */
 
@@ -222,7 +224,7 @@ function dfrn_request_post(&$a) {
                return; // NOTREACHED
        }
 
-       /**
+       /*
         * Otherwise:
         *
         * Scenario 1:
@@ -256,11 +258,13 @@ function dfrn_request_post(&$a) {
        $contact_record = null;
        $failed         = false;
        $parms          = null;
+       $blocked = 1;
+       $pending = 1;
 
 
        if( x($_POST,'dfrn_url')) {
 
-               /**
+               /*
                 * Block friend request spam
                 */
 
@@ -277,7 +281,7 @@ function dfrn_request_post(&$a) {
                        }
                }
 
-               /**
+               /*
                 *
                 * Cleanup old introductions that remain blocked.
                 * Also remove the contact record, but only if there is no existing relationship
@@ -304,7 +308,7 @@ function dfrn_request_post(&$a) {
                        }
                }
 
-               /**
+               /*
                 *
                 * Cleanup any old email intros - which will have a greater lifetime
                 */
@@ -354,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;
 
@@ -368,6 +370,7 @@ function dfrn_request_post(&$a) {
                                $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
                                        intval($uid)
                                );
+
                                if(! dbm::is_result($r)) {
                                        notice( t('This account has not been configured for email. Request failed.') . EOL);
                                        return;
@@ -543,8 +546,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'],
@@ -560,7 +563,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
@@ -616,7 +621,7 @@ function dfrn_request_post(&$a) {
                        // END $network === NETWORK_DFRN
                } elseif (($network != NETWORK_PHANTOM) AND ($url != "")) {
 
-                       /**
+                       /*
                         *
                         * Substitute our user's feed URL into $url template
                         * Send the subscriber home to subscribe
@@ -645,12 +650,9 @@ function dfrn_request_post(&$a) {
                }
 
        }       return;
-}}
-
-
+}
 
 
-if(! function_exists('dfrn_request_content')) {
 function dfrn_request_content(&$a) {
 
        if(($a->argc != 2) || (! count($a->profile)))
@@ -786,7 +788,7 @@ function dfrn_request_content(&$a) {
        }
        else {
 
-               /**
+               /*
                 * Normal web request. Display our user's introduction form.
                 */
 
@@ -798,7 +800,7 @@ function dfrn_request_content(&$a) {
                }
 
 
-               /**
+               /*
                 * Try to auto-fill the profile address
                 */
 
@@ -821,7 +823,7 @@ function dfrn_request_content(&$a) {
                $target_addr = $a->profile['nickname'] . '@' . substr(z_root(), strpos(z_root(),'://') + 3 );
 
 
-               /**
+               /*
                 *
                 * The auto_request form only has the profile address
                 * because nobody is going to read the comments and
@@ -846,7 +848,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;
                }
 
@@ -886,4 +888,4 @@ function dfrn_request_content(&$a) {
        }
 
        return; // Somebody is fishing.
-}}
+}