]> git.mxchange.org Git - friendica.git/blobdiff - mod/dfrn_request.php
show members of locked conversations
[friendica.git] / mod / dfrn_request.php
index 7ba81681fa3df600d88cd342d87e2270aa943abf..1458ba8e467dadfb5eb235d5590570fed93cb254 100644 (file)
@@ -45,7 +45,7 @@ function dfrn_request_post(&$a) {
                        if(x($dfrn_url)) {
        
                                $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `url` = '%s' LIMIT 1",
-                                       intval($_SESSION['uid']),
+                                       intval(get_uid()),
                                        dbesc($dfrn_url)
                                );
        
@@ -99,7 +99,7 @@ function dfrn_request_post(&$a) {
                                        $r = q("INSERT INTO `contact` ( `uid`, `created`,`url`, `name`, `photo`, `site-pubkey`,
                                                `request`, `confirm`, `notify`, `poll`, `aes_allow`) 
                                                VALUES ( %d, '%s', '%s', '%s' , '%s', '%s', '%s', '%s', '%s', '%s', %d)",
-                                               intval($_SESSION['uid']),
+                                               intval(get_uid()),
                                                datetime_convert(),
                                                dbesc($dfrn_url),
                                                $parms['fn'],
@@ -134,7 +134,7 @@ function dfrn_request_post(&$a) {
 
                // invalid/bogus request
 
-               notice( t("Unrecoverable protocol error.") . EOL );
+               notice( t('Unrecoverable protocol error.') . EOL );
                goaway($a->get_baseurl());
                return; // NOTREACHED
        }
@@ -158,7 +158,7 @@ function dfrn_request_post(&$a) {
        // in $a->argv[1] and we should have their complete info in $a->profile.
 
        if(! (is_array($a->profile) && count($a->profile))) {
-               notice(t("Profile unavailable.") . EOL);
+               notice( t('Profile unavailable.') . EOL);
                return;
        }
 
@@ -179,32 +179,12 @@ function dfrn_request_post(&$a) {
                        return;
                }
 
-               // Is this an email-style DFRN locator?
+               // Canonicalise email-style profile locator
 
-               if(strstr($url,'@')) {
-                       $username = substr($url,0,strpos($url,'@'));
-                       $hostname = substr($url,strpos($url,'@') + 1);
-                       require_once('Scrape.php');
-
-               
-                       $parms = scrape_meta('https://' . $url);
-                       if((x($parms,'dfrn-template')) && strstr($parms['dfrn-template'],'%s')) {
-                               $url = sprintf($parms['dfrn-template'],$username);
-                       }
-                       else {
-                               $parms = scrape_meta('http://' . $url);
-                               if((x($parms,'dfrn-template')) && strstr($parms['dfrn-template'],'%s')) {
-                                       $url = sprintf($parms['dfrn-template'],$username);
-                               }
-                               else {
-                                       $url = '';
-                               }
-                       }
-
-               }
+               $url = webfinger($url);
 
                if(! strlen($url)) {
-                       notice(t("Unable to resolve your name at the provided location.") . EOL);                       
+                       notice( t("Unable to resolve your name at the provided location.") . EOL);                      
                        return;
                }
 
@@ -234,14 +214,26 @@ function dfrn_request_post(&$a) {
                        );
                }
                else {
-       
+                       if(! validate_url($url)) {
+                               notice( t('Invalid profile URL.') . EOL);
+                               goaway($a->get_baseurl() . '/' . $a->cmd);
+                               return; // NOTREACHED
+                       }
+
+                       if(! allowed_url($url)) {
+                               notice( t('Disallowed profile URL.') . EOL);
+                               goaway($a->get_baseurl() . '/' . $a->cmd);
+                               return; // NOTREACHED
+                       }
+                       
+
                        require_once('Scrape.php');
 
                        $parms = scrape_dfrn($url);
 
                        if(! count($parms)) {
                                notice( t('Profile location is not valid or does not contain profile information.') . EOL );
-                               killme();
+                               goaway($a->get_baseurl() . '/' . $a->cmd);
                        }
                        else {
                                if(! x($parms,'fn'))
@@ -283,7 +275,7 @@ function dfrn_request_post(&$a) {
                        // find the contact record we just created
                        if($r) {        
                                $r = q("SELECT `id` FROM `contact` 
-                                       WHERE `uid` = '%s' AND `url` = '%s' AND `issued-id` = '%s' LIMIT 1",
+                                       WHERE `uid` = %d AND `url` = '%s' AND `issued-id` = '%s' LIMIT 1",
                                        intval($uid),
                                        $parms['url'],
                                        $parms['issued-id']
@@ -294,7 +286,7 @@ function dfrn_request_post(&$a) {
        
                }
                if($r === false) {
-                       notice( 'Failed to update contact record.' . EOL );
+                       notice( t('Failed to update contact record.') . EOL );
                        return;
                }
 
@@ -306,7 +298,7 @@ function dfrn_request_post(&$a) {
                                intval($uid),
                                intval($contact_record['id']),
                                ((x($_POST,'knowyou') && ($_POST['knowyou'] == 1)) ? 1 : 0),
-                               dbesc(trim($_POST['dfrn-request-message'])),
+                               dbesc(notags(trim($_POST['dfrn-request-message']))),
                                dbesc($hash),
                                dbesc(datetime_convert())
                        );
@@ -316,11 +308,11 @@ function dfrn_request_post(&$a) {
                // This notice will only be seen by the requestor if  the requestor and requestee are on the same server.
 
                if(! $failed) 
-                       notice( t("Your introduction has been sent.") . EOL );
+                       notice( t('Your introduction has been sent.') . EOL );
 
                // "Homecoming" - send the requestor back to their site to record the introduction.
 
-               $dfrn_url = bin2hex($a->get_baseurl() . "/profile/$nickname");
+               $dfrn_url = bin2hex($a->get_baseurl() . '/profile/' . $nickname);
                $aes_allow = ((function_exists('openssl_encrypt')) ? 1 : 0);
 
                goaway($parms['dfrn-request'] . "?dfrn_url=$dfrn_url" . '&confirm_key=' . $hash . (($aes_allow) ? "&aes_allow=1" : ""));
@@ -364,7 +356,7 @@ function dfrn_request_content(&$a) {
                $dfrn_url = notags(trim(hex2bin($_GET['dfrn_url'])));
                $aes_allow = (((x($_GET,'aes_allow')) && ($_GET['aes_allow'] == 1)) ? 1 : 0);
                $confirm_key = (x($_GET,'confirm_key') ? $_GET['confirm_key'] : "");
-               $o .= file_get_contents("view/dfrn_req_confirm.tpl");
+               $o .= load_view_file("view/dfrn_req_confirm.tpl");
                $o  = replace_macros($o,array(
                        '$dfrn_url' => $dfrn_url,
                        '$aes_allow' => (($aes_allow) ? '<input type="hidden" name="aes_allow" value="1" />' : "" ),
@@ -396,7 +388,7 @@ function dfrn_request_content(&$a) {
                        if(count($r)) {
 
                                if($r[0]['notify-flags'] & NOTIFY_INTRO) {
-                                       $email_tpl = file_get_contents('view/request_notify_eml.tpl');
+                                       $email_tpl = load_view_file('view/request_notify_eml.tpl');
                                        $email = replace_macros($email_tpl, array(
                                                '$requestor' => ((strlen(stripslashes($r[0]['name']))) ? stripslashes($r[0]['name']) : t('[Name Withheld]')),
                                                '$url' => stripslashes($r[0]['url']),
@@ -404,7 +396,10 @@ function dfrn_request_content(&$a) {
                                                '$siteurl' => $a->get_baseurl(),
                                                '$sitename' => $a->config['sitename']
                                        ));
-                                       $res = mail($r[0]['email'],t("Introduction received at ") . $a->config['sitename'],$email,t('From: Administrator@') . $_SERVER[SERVER_NAME] );
+                                       $res = mail($r[0]['email'], 
+                                               t("Introduction received at ") . $a->config['sitename'],
+                                               $email,
+                                               'From: ' . t('Administrator') . '@' . $_SERVER[SERVER_NAME] );
                                        // This is a redundant notification - no point throwing errors if it fails.
                                }
                        }
@@ -421,7 +416,7 @@ function dfrn_request_content(&$a) {
 
                // Normal web request. Display our user's introduction form. 
 
-               $o = file_get_contents("view/dfrn_request.tpl");
+               $o = load_view_file("view/dfrn_request.tpl");
                $o = replace_macros($o,array('$nickname' => $a->argv[1]));
                return $o;
        }