2012-10-09 17:50:24 +02:00
< ? php
function auto_redir ( & $a , $contact_nick ) {
2012-10-16 01:33:00 +02:00
// disabling temporarily - seeing a lot of recursive redirects, triggered in my case
// because one of my contacts has the same nickname as me so it's redirecting to his site
// (I'm trying to load my own profile page and he is remote so it shouldn't redirect anyway).
// Need some time to sort this out.
return ;
2012-10-09 17:50:24 +02:00
if ( local_user ()) {
2012-10-16 01:33:00 +02:00
$r = q ( " SELECT id FROM contact WHERE uid = ( SELECT uid FROM user WHERE nickname = '%s' LIMIT 1 ) AND nick = '%s' AND network = '%s' and self = 0 LIMIT 1 " ,
2012-10-09 17:50:24 +02:00
dbesc ( $contact_nick ),
dbesc ( $a -> user [ 'nickname' ]),
dbesc ( NETWORK_DFRN )
);
2012-10-16 01:33:00 +02:00
if (( ! $r ) || ( ! count ( $r )) || $r [ 0 ][ 'id' ] == remote_user ())
2012-10-09 17:50:24 +02:00
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 ())
);
2012-10-16 01:33:00 +02:00
if ( ! ( $r && count ( $r )))
2012-10-09 17:50:24 +02:00
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 ;
}