]> git.mxchange.org Git - friendica.git/commitdiff
for profile and photos, detect contacts from local hub and auto-redir
authorZach Prezkuta <fermion@gmx.com>
Tue, 9 Oct 2012 15:50:24 +0000 (09:50 -0600)
committerZach Prezkuta <fermion@gmx.com>
Tue, 9 Oct 2012 15:50:24 +0000 (09:50 -0600)
include/redir.php [new file with mode: 0644]
mod/photos.php
mod/profile.php

diff --git a/include/redir.php b/include/redir.php
new file mode 100644 (file)
index 0000000..ecc07df
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+
+function auto_redir(&$a, $contact_nick) {
+
+       if(local_user()) {
+
+               $r = q("SELECT id FROM contact WHERE uid = ( SELECT uid FROM user WHERE nickname = '%s' LIMIT 1 ) AND nick = '%s' AND network = '%s' LIMIT 1",
+                          dbesc($contact_nick),
+                          dbesc($a->user['nickname']),
+                          dbesc(NETWORK_DFRN)
+               );
+               if(!$r || $r[0]['id'] == remote_user())
+                       return;
+
+
+               $r = q("SELECT * FROM contact WHERE nick = '%s' AND network = '%s' AND uid = %d LIMIT 1",
+                      dbesc($contact_nick),
+                      dbesc(NETWORK_DFRN),
+                      intval(local_user())
+               );
+
+               if(! $r)
+                       return;
+
+               $cid = $r[0]['id'];
+
+               $dfrn_id = $orig_id = (($r[0]['issued-id']) ? $r[0]['issued-id'] : $r[0]['dfrn-id']);
+
+               if($r[0]['duplex'] && $r[0]['issued-id']) {
+                       $orig_id = $r[0]['issued-id'];
+                       $dfrn_id = '1:' . $orig_id;
+               }
+               if($r[0]['duplex'] && $r[0]['dfrn-id']) {
+                       $orig_id = $r[0]['dfrn-id'];
+                       $dfrn_id = '0:' . $orig_id;
+               }
+
+               $sec = random_string();
+
+               q("INSERT INTO `profile_check` ( `uid`, `cid`, `dfrn_id`, `sec`, `expire`)
+                       VALUES( %d, %s, '%s', '%s', %d )",
+                       intval(local_user()),
+                       intval($cid),
+                       dbesc($dfrn_id),
+                       dbesc($sec),
+                       intval(time() + 45)
+               );
+
+               $url = curPageURL();
+
+               logger('check_redir: ' . $r[0]['name'] . ' ' . $sec, LOGGER_DEBUG); 
+               $dest = (($url) ? '&destination_url=' . $url : '');
+               goaway ($r[0]['poll'] . '?dfrn_id=' . $dfrn_id 
+                       . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . '&type=profile&sec=' . $sec . $dest );
+       }
+
+       return;
+}
+
+
index 9a3a402a4b1a169aff24c0bd89934e338a4ffdb9..7108e95698041eef9153fd0fc0f1eca339b470ac 100644 (file)
@@ -4,14 +4,18 @@ require_once('include/items.php');
 require_once('include/acl_selectors.php');
 require_once('include/bbcode.php');
 require_once('include/security.php');
+require_once('include/redir.php');
 
 
 function photos_init(&$a) {
 
+       if($a->argc > 1)
+               auto_redir($a, $a->argv[1]);
 
        if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
                return;
        }
+
        $o = '';
 
        if($a->argc > 1) {
index b33b181de1b1b7332611799ac225d366c12fd48a..3eb97e1572737d130e788f891e80506a1bade41c 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 
 require_once('include/contact_widgets.php');
+require_once('include/redir.php');
 
 
 function profile_init(&$a) {
@@ -30,6 +31,9 @@ function profile_init(&$a) {
                $which = $a->user['nickname'];
                $profile = $a->argv[1];         
        }
+       else {
+               auto_redir($a, $which);
+       }
 
        profile_load($a,$which,$profile);