]> git.mxchange.org Git - friendica.git/commitdiff
make contact ssl_policy change a function since it is used in a few places
authorfriendica <info@friendica.com>
Tue, 3 Apr 2012 06:07:26 +0000 (23:07 -0700)
committerfriendica <info@friendica.com>
Tue, 3 Apr 2012 06:07:26 +0000 (23:07 -0700)
include/delivery.php
include/network.php
include/notifier.php
mod/dfrn_notify.php

index 2407f11c02eb71bcf6dd8a178da32c590152eb31..794b8f27a3a3998c5d860b5c2f1a93311df0f6df 100755 (executable)
@@ -321,51 +321,9 @@ function delivery_run($argv, $argc){
                                                $x[0]['writable'] = 1;
                                        }
 
-
                                        $ssl_policy = get_config('system','ssl_policy');
-                                       // if contact's ssl policy changed, update our links
-
-                                       $ssl_changed = false;
-
-                                       if($ssl_policy == SSL_POLICY_SELFSIGN && strstr($x[0]['url'],'https:')) {
-                                               $ssl_changed = true;
-                                               $x[0]['url']     =      str_replace('https:','http:',$x[0]['url']);
-                                               $x[0]['request'] =      str_replace('https:','http:',$x[0]['request']);
-                                               $x[0]['notify']  =      str_replace('https:','http:',$x[0]['notify']);
-                                               $x[0]['poll']    =      str_replace('https:','http:',$x[0]['poll']);
-                                               $x[0]['confirm'] =      str_replace('https:','http:',$x[0]['confirm']);
-                                               $x[0]['poco']    =      str_replace('https:','http:',$x[0]['poco']);
-                                       }
-
-                                       if($ssl_policy == SSL_POLICY_FULL && strstr($x[0]['url'],'http:')) {
-                                               $ssl_changed = true;
-                                               $x[0]['url']     =      str_replace('http:','https:',$x[0]['url']);
-                                               $x[0]['request'] =      str_replace('http:','https:',$x[0]['request']);
-                                               $x[0]['notify']  =      str_replace('http:','https:',$x[0]['notify']);
-                                               $x[0]['poll']    =      str_replace('http:','https:',$x[0]['poll']);
-                                               $x[0]['confirm'] =      str_replace('http:','https:',$x[0]['confirm']);
-                                               $x[0]['poco']    =      str_replace('http:','https:',$x[0]['poco']);
-                                       }
+                                       fix_contact_ssl_policy($x[0],$ssl_policy);
 
-                                       if($ssl_changed) {
-                                               q("update contact set 
-                                                       url = '%s', 
-                                                       request = '%s',
-                                                       notify = '%s',
-                                                       poll = '%s',
-                                                       confirm = '%s',
-                                                       poco = '%s'
-                                                       where id = %d limit 1",
-                                                       dbesc($x[0]['url']),
-                                                       dbesc($x[0]['request']),
-                                                       dbesc($x[0]['notify']),
-                                                       dbesc($x[0]['poll']),
-                                                       dbesc($x[0]['confirm']),
-                                                       dbesc($x[0]['poco']),
-                                                       intval($x[0]['id'])
-                                               );
-                                       }
-                       
                                        // If we are setup as a soapbox we aren't accepting input from this person
 
                                        if($x[0]['page-flags'] == PAGE_SOAPBOX)
index 9e1ed2091d5d2f5429846ceeb9c6c600c159c39e..38d0980d50f781464127a77017aeced9f8310ebb 100755 (executable)
@@ -824,3 +824,48 @@ function scale_external_images($s,$include_link = true) {
        }
        return $s;
 }
+
+
+function fix_contact_ssl_policy(&$contact,$new_policy) {
+
+       $ssl_changed = false;
+       if((intval($new_policy) == SSL_POLICY_SELFSIGN || $new_policy === 'self') && strstr($contact['url'],'https:')) {
+               $ssl_changed = true;
+               $contact['url']     =   str_replace('https:','http:',$contact['url']);
+               $contact['request'] =   str_replace('https:','http:',$contact['request']);
+               $contact['notify']  =   str_replace('https:','http:',$contact['notify']);
+               $contact['poll']    =   str_replace('https:','http:',$contact['poll']);
+               $contact['confirm'] =   str_replace('https:','http:',$contact['confirm']);
+               $contact['poco']    =   str_replace('https:','http:',$contact['poco']);
+       }
+
+       if((intval($new_policy) == SSL_POLICY_FULL || $new_policy === 'full') && strstr($contact['url'],'http:')) {
+               $ssl_changed = true;
+               $contact['url']     =   str_replace('http:','https:',$contact['url']);
+               $contact['request'] =   str_replace('http:','https:',$contact['request']);
+               $contact['notify']  =   str_replace('http:','https:',$contact['notify']);
+               $contact['poll']    =   str_replace('http:','https:',$contact['poll']);
+               $contact['confirm'] =   str_replace('http:','https:',$contact['confirm']);
+               $contact['poco']    =   str_replace('http:','https:',$contact['poco']);
+       }
+
+       if($ssl_changed) {
+               q("update contact set 
+                       url = '%s', 
+                       request = '%s',
+                       notify = '%s',
+                       poll = '%s',
+                       confirm = '%s',
+                       poco = '%s'
+                       where id = %d limit 1",
+                       dbesc($contact['url']),
+                       dbesc($contact['request']),
+                       dbesc($contact['notify']),
+                       dbesc($contact['poll']),
+                       dbesc($contact['confirm']),
+                       dbesc($contact['poco']),
+                       intval($contact['id'])
+               );
+       }
+}
+
index e91185c514c166f64ee888b1e7577d074e0760db..ca7c7b92eb12e5dea61ad7fd63fb7dec8c1e9377 100755 (executable)
@@ -537,56 +537,17 @@ function notifier_run($argv, $argc){
                                                                $x[0]['writable'] = 1;
                                                        }
 
+                                                       // if contact's ssl policy changed, which we just determined
+                                                       // is on our own server, update our contact links
+                                                       
                                                        $ssl_policy = get_config('system','ssl_policy');
-                                                       // if contact's ssl policy changed, update our links
-
-                                                       $ssl_changed = false;
-
-                                                       if($ssl_policy == SSL_POLICY_SELFSIGN && strstr($x[0]['url'],'https:')) {
-                                                               $ssl_changed = true;
-                                                               $x[0]['url']     =      str_replace('https:','http:',$x[0]['url']);
-                                                               $x[0]['request'] =      str_replace('https:','http:',$x[0]['request']);
-                                                               $x[0]['notify']  =      str_replace('https:','http:',$x[0]['notify']);
-                                                               $x[0]['poll']    =      str_replace('https:','http:',$x[0]['poll']);
-                                                               $x[0]['confirm'] =      str_replace('https:','http:',$x[0]['confirm']);
-                                                               $x[0]['poco']    =      str_replace('https:','http:',$x[0]['poco']);
-                                                       }
-
-                                                       if($ssl_policy == SSL_POLICY_FULL && strstr($x[0]['url'],'http:')) {
-                                                               $ssl_changed = true;
-                                                               $x[0]['url']     =      str_replace('http:','https:',$x[0]['url']);
-                                                               $x[0]['request'] =      str_replace('http:','https:',$x[0]['request']);
-                                                               $x[0]['notify']  =      str_replace('http:','https:',$x[0]['notify']);
-                                                               $x[0]['poll']    =      str_replace('http:','https:',$x[0]['poll']);
-                                                               $x[0]['confirm'] =      str_replace('http:','https:',$x[0]['confirm']);
-                                                               $x[0]['poco']    =      str_replace('http:','https:',$x[0]['poco']);
-                                                       }
+                                                       fix_contact_ssl_policy($x[0],$ssl_policy);
 
-                                                       if($ssl_changed) {
-                                                               q("update contact set 
-                                                                       url = '%s', 
-                                                                       request = '%s',
-                                                                       notify = '%s',
-                                                                       poll = '%s',
-                                                                       confirm = '%s',
-                                                                       poco = '%s'
-                                                                       where id = %d limit 1",
-                                                                       dbesc($x[0]['url']),
-                                                                       dbesc($x[0]['request']),
-                                                                       dbesc($x[0]['notify']),
-                                                                       dbesc($x[0]['poll']),
-                                                                       dbesc($x[0]['confirm']),
-                                                                       dbesc($x[0]['poco']),
-                                                                       intval($x[0]['id'])
-                                                               );
-                                                       }
-                       
                                                        // If we are setup as a soapbox we aren't accepting input from this person
 
                                                        if($x[0]['page-flags'] == PAGE_SOAPBOX)
                                                                break;
 
-
                                                        require_once('library/simplepie/simplepie.inc');
                                                        logger('mod-delivery: local delivery');
                                                        local_delivery($x[0],$atom);
index 5d44e8144dad70c77599dccb76024748118df2e3..65d39d5fe12f8d844d7ce15f545e67dd6676fe03 100755 (executable)
@@ -99,51 +99,10 @@ function dfrn_notify_post(&$a) {
                $importer['forum'] = $page;
        }
 
-       // if contact's ssl policy changed, update our links
-
-       $ssl_changed = false;
 
-       if($ssl_policy == 'self' && strstr($importer['url'],'https:')) {
-               $ssl_changed = true;
-               $importer['url']     =  str_replace('https:','http:',$importer['url']);
-               $importer['request'] =  str_replace('https:','http:',$importer['request']);
-               $importer['notify']  =  str_replace('https:','http:',$importer['notify']);
-               $importer['poll']    =  str_replace('https:','http:',$importer['poll']);
-               $importer['confirm'] =  str_replace('https:','http:',$importer['confirm']);
-               $importer['poco']    =  str_replace('https:','http:',$importer['poco']);
-       }
-
-       if($ssl_policy == 'full' && strstr($importer['url'],'http:')) {
-               $ssl_changed = true;
-               $importer['url']     =  str_replace('http:','https:',$importer['url']);
-               $importer['request'] =  str_replace('http:','https:',$importer['request']);
-               $importer['notify']  =  str_replace('http:','https:',$importer['notify']);
-               $importer['poll']    =  str_replace('http:','https:',$importer['poll']);
-               $importer['confirm'] =  str_replace('http:','https:',$importer['confirm']);
-               $importer['poco']    =  str_replace('http:','https:',$importer['poco']);
-       }
+       // if contact's ssl policy changed, update our links
 
-       if($ssl_changed) {
-               q("update contact set 
-                       url = '%s', 
-                       nurl = '%s',
-                       request = '%s',
-                       notify = '%s',
-                       poll = '%s',
-                       confirm = '%s',
-                       poco = '%s'
-                       where id = %d limit 1",
-                       dbesc($importer['url']),
-                       dbesc($importer['nurl']),
-                       dbesc($importer['request']),
-                       dbesc($importer['notify']),
-                       dbesc($importer['poll']),
-                       dbesc($importer['confirm']),
-                       dbesc($importer['poco']),
-                       intval($importer['id'])
-               );
-       }
-                       
+       fix_contact_ssl_policy($importer,$ssl_policy);
 
        logger('dfrn_notify: received notify from ' . $importer['name'] . ' for ' . $importer['username']);
        logger('dfrn_notify: data: ' . $data, LOGGER_DATA);