]> git.mxchange.org Git - friendica.git/commitdiff
fix several probe related issues
authorFriendika <info@friendika.com>
Thu, 18 Aug 2011 06:01:44 +0000 (23:01 -0700)
committerFriendika <info@friendika.com>
Thu, 18 Aug 2011 06:01:44 +0000 (23:01 -0700)
boot.php
include/Scrape.php
include/diaspora.php
mod/hcard.php
mod/profile.php
view/profile_vcard.tpl

index 09d9f4ef87125eaf3de6d28604fbdc9f73a3fc48..050cf10ce817615599c43d378b8e81eaa94a45c1 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -803,8 +803,12 @@ function profile_load(&$a, $nickname, $profile = 0) {
        if(! (x($a->page,'aside')))
                $a->page['aside'] = '';
 
-       $a->page['aside'] .= profile_sidebar($a->profile);
-       $a->page['aside'] .= contact_block();
+       $block = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);
+
+       $a->page['aside'] .= profile_sidebar($a->profile, $block);
+
+       if(! $block)
+               $a->page['aside'] .= contact_block();
 
        return;
 }}
@@ -827,7 +831,7 @@ function profile_load(&$a, $nickname, $profile = 0) {
 
 
 if(! function_exists('profile_sidebar')) {
-function profile_sidebar($profile) {
+function profile_sidebar($profile, $block = 0) {
 
        $a = get_app();
 
@@ -846,10 +850,9 @@ function profile_sidebar($profile) {
 
        $tabs = '';
 
-       $photo = '<div id="profile-photo-wrapper"><img class="photo" src="' . $profile['photo'] . '" alt="' . $profile['name'] . '" /></div>';
+       $photo = '<div id="profile-photo-wrapper"><img class="photo" width="175" height="175" src="' . $profile['photo'] . '" alt="' . $profile['name'] . '" /></div>';
 
        // don't show connect link to yourself
-       
        $connect = (($profile['uid'] != local_user()) ? '<li><a id="dfrn-request-link" href="dfrn_request/' . $profile['nickname'] . '">' . t('Connect') . '</a></li>' : '');
 
        // don't show connect link to authenticated visitors either
@@ -877,6 +880,7 @@ function profile_sidebar($profile) {
 
        }
 
+
        $gender = ((x($profile,'gender') == 1) ? '<div class="mf"><span class="gender-label">' . t('Gender:') . '</span> <span class="x-gender">' . $profile['gender'] . '</span></div><div class="profile-clear"></div>' : '');
 
        $pubkey = ((x($profile,'pubkey') == 1) ? '<div class="key" style="display:none;">' . $profile['pubkey'] . '</div>' : '');
@@ -885,13 +889,13 @@ function profile_sidebar($profile) {
 
        $homepage = ((x($profile,'homepage') == 1) ? '<div class="homepage"><span class="homepage-label">' . t('Homepage:') . ' </span><span class="homepage-url">' . linkify($profile['homepage']) . '</span></div><div class="profile-clear"></div>' : '');
 
-       if($profile['hidewall'] && (! local_user()) && (! remote_user())) {
-               $location = $gender = $marital = $homepage = '';
+       if(($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) {
+               $location = $pdesc = $connect = $gender = $marital = $homepage = '';
        }
 
        $podloc = $a->get_baseurl();
        $searchable = (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' );
-       $nickname = $profile['nick'];
+       $nickname = $profile['nickname'];
        $photo300 = $a->get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg';
        $photo100 = $a->get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg';
        $photo50  = $a->get_baseurl() . '/photo/custom/50/'  . $profile['uid'] . '.jpg';
@@ -902,13 +906,19 @@ function profile_sidebar($profile) {
 <dl class='entity_nickname'>
 <dt>Nickname</dt>
 <dd>
-<a class="nickname url uid" href="$podloc" rel="me">$nickname</a>
+<a class="nickname url uid" href="$podloc/" rel="me">$nickname</a>
+</dd>
+</dl>
+<dl class='entity_fn'>
+<dt>Full name</dt>
+<dd>
+<span class='fn'>$fullname</span>
 </dd>
 </dl>
 <dl class="entity_url">
 <dt>URL</dt>
 <dd>
-<a class="url" href="$podloc" id="pod_location" rel="me">$podloc</a>
+<a class="url" href="$podloc/" id="pod_location" rel="me">$podloc/</a>
 </dd>
 </dl>
 <dl class="entity_photo">
index dbd98c9ecc134dc9e05728ebc8543ca2b7ca6aa8..1b319481ba1e27c9a1fb1e7d5bd0e9b9c2efadaa 100644 (file)
@@ -44,8 +44,9 @@ function scrape_dfrn($url) {
                $x = $item->getAttribute('rel');
                if(($x === 'alternate') && ($item->getAttribute('type') === 'application/atom+xml'))
                        $ret['feed_atom'] = $item->getAttribute('href');
-               if(substr($x,0,5) == "dfrn-")
+               if(substr($x,0,5) == "dfrn-") {
                        $ret[$x] = $item->getAttribute('href');
+               }
                if($x === 'lrdd') {
                        $decoded = urldecode($item->getAttribute('href'));
                        if(preg_match('/acct:([^@]*)@/',$decoded,$matches))
@@ -55,17 +56,28 @@ function scrape_dfrn($url) {
 
        // Pull out hCard profile elements
 
+       $largest_photo = 0;
+
        $items = $dom->getElementsByTagName('*');
        foreach($items as $item) {
                if(attribute_contains($item->getAttribute('class'), 'vcard')) {
                        $level2 = $item->getElementsByTagName('*');
                        foreach($level2 as $x) {
-                               if(attribute_contains($x->getAttribute('class'),'fn'))
+                               if(attribute_contains($x->getAttribute('class'),'fn')) {
                                        $ret['fn'] = $x->textContent;
-                               if(attribute_contains($x->getAttribute('class'),'photo'))
-                                       $ret['photo'] = $x->getAttribute('src');
-                               if(attribute_contains($x->getAttribute('class'),'key'))
+                               }
+                               if((attribute_contains($x->getAttribute('class'),'photo'))
+                                       || (attribute_contains($x->getAttribute('class'),'avatar'))) {
+                                       $size = intval($x->getAttribute('width'));
+                                       // dfrn prefers 175, so if we find this, we set largest_size so it can't be topped.
+                                       if(($size > $largest_photo) || ($size == 175) || (! $largest_photo)) {
+                                               $ret['photo'] = $x->getAttribute('src');
+                                               $largest_photo = (($size == 175) ? 9999 : $size);
+                                       }
+                               }
+                               if(attribute_contains($x->getAttribute('class'),'key')) {
                                        $ret['key'] = $x->textContent;
+                               }
                        }
                }
        }
@@ -190,8 +202,9 @@ function scrape_vcard($url) {
                                        }
                                }
                                if((attribute_contains($x->getAttribute('class'),'nickname'))
-                                       || (attribute_contains($x->getAttribute('class'),'uid')))
+                                       || (attribute_contains($x->getAttribute('class'),'uid'))) {
                                        $ret['nick'] = $x->textContent;
+                               }
                        }
                }
        }
@@ -288,8 +301,10 @@ function scrape_feed($url) {
        return $ret;
 }}
 
+define ( 'PROBE_NORMAL',   0);
+define ( 'PROBE_DIASPORA', 1);
 
-function probe_url($url) {
+function probe_url($url, $mode = PROBE_NORMAL) {
        require_once('include/email.php');
 
        $result = array();
@@ -366,7 +381,7 @@ function probe_url($url) {
                                }
                        }
                }
-               else {
+               elseif($mode == PROBE_NORMAL) {
 
                        // Check email
 
@@ -411,38 +426,46 @@ function probe_url($url) {
                }
        }       
 
-       if(strlen($zot)) {
-               $s = fetch_url($zot);
-               if($s) {
-                       $j = json_decode($s);
-                       if($j) {
-                               $network = NETWORK_ZOT;
-                               $vcard   = array(
-                                       'fn'    => $j->fullname, 
-                                       'nick'  => $j->nickname, 
-                                       'photo' => $j->photo
-                               );
-                               $profile  = $j->url;
-                               $notify   = $j->post;
-                               $pubkey   = $j->pubkey;
-                               $poll     = 'N/A';
+       if($mode == PROBE_NORMAL) {
+               if(strlen($zot)) {
+                       $s = fetch_url($zot);
+                       if($s) {
+                               $j = json_decode($s);
+                               if($j) {
+                                       $network = NETWORK_ZOT;
+                                       $vcard   = array(
+                                               'fn'    => $j->fullname, 
+                                               'nick'  => $j->nickname, 
+                                               'photo' => $j->photo
+                                       );
+                                       $profile  = $j->url;
+                                       $notify   = $j->post;
+                                       $pubkey   = $j->pubkey;
+                                       $poll     = 'N/A';
+                               }
                        }
                }
-       }
 
-       if(strlen($dfrn)) {
-               $ret = scrape_dfrn($dfrn);
-               if(is_array($ret) && x($ret,'dfrn-request')) {
-                       $network = NETWORK_DFRN;
-                       $request = $ret['dfrn-request'];
-                       $confirm = $ret['dfrn-confirm'];
-                       $notify  = $ret['dfrn-notify'];
-                       $poll    = $ret['dfrn-poll'];
+               if(strlen($dfrn)) {
+                       $ret = scrape_dfrn($dfrn);
+                       if(is_array($ret) && x($ret,'dfrn-request')) {
+                               $network = NETWORK_DFRN;
+                               $request = $ret['dfrn-request'];
+                               $confirm = $ret['dfrn-confirm'];
+                               $notify  = $ret['dfrn-notify'];
+                               $poll    = $ret['dfrn-poll'];
+
+                               $vcard = array();
+                               $vcard['fn'] = $ret['fn'];
+                               $vcard['nick'] = $ret['nick'];
+                               $vcard['photo'] = $ret['photo'];
+                       }
                }
        }
 
        if($diaspora && $diaspora_base && $diaspora_guid) {
-               $notify = $diaspora_base . 'receive/post/' . $diaspora_guid;
+               if($mode == PROBE_DIASPORA || ! $notify)
+                       $notify = $diaspora_base . 'receive/post/' . $diaspora_guid;
                if(strpos($url,'@'))
                        $addr = str_replace('acct:', '', $url);
        }                       
@@ -454,7 +477,7 @@ function probe_url($url) {
                        $network  = NETWORK_OSTATUS;
                $priority = 0;
 
-               if($hcard) {
+               if($hcard && ! $vcard) {
                        $vcard = scrape_vcard($hcard);
 
                        // Google doesn't use absolute url in profile photos
index e089e3f040e8c6977850ebca241c9262ceda871b..9987c213930f130a6b2c83776f6dd44a04742a6a 100644 (file)
@@ -279,6 +279,13 @@ function diaspora_get_contact_by_handle($uid,$handle) {
 }
 
 function find_person_by_handle($handle) {
+               $r = q("select * from fcontact where network = '%s' and addr = '%s' limit 1",
+                       dbesc(NETWORK_DIASPORA),
+                       dbesc($handle)
+               );
+               if(count($r))
+                       return $r[0];
+
                // we don't care about the uid, we just want to save an expensive webfinger probe
                $r = q("select * from contact where network = '%s' and addr = '%s' LIMIT 1",
                        dbesc(NETWORK_DIASPORA),
index 5505ca08e690bc063f86ba92ed784ea31cfef775..19e649dcb6ce7a1ee25d5fe42f4bdfe5991ca705 100644 (file)
@@ -2,8 +2,7 @@
 
 function hcard_init(&$a) {
 
-       if((get_config('system','block_public')) && (! local_user()) && (! remote_user()))
-               return;
+       $blocked = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);
 
        if($a->argc > 1)
                $which = $a->argv[1];
@@ -31,10 +30,12 @@ function hcard_init(&$a) {
                $a->page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\r\n";
        }
 
-       $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : '');
-       $keywords = str_replace(array(',',' ',',,'),array(' ',',',','),$keywords);
-       if(strlen($keywords))
-               $a->page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\r\n" ;
+       if(! $blocked) {
+               $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : '');
+               $keywords = str_replace(array(',',' ',',,'),array(' ',',',','),$keywords);
+               if(strlen($keywords))
+                       $a->page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\r\n" ;
+       }
 
        $a->page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . (($a->profile['net-publish']) ? 'true' : 'false') . '" />' . "\r\n" ;
        $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $a->get_baseurl() . '/dfrn_poll/' . $which .'" />' . "\r\n" ;
index a4c6ea710726b8a1437300e02fae13b00ce073b4..2dd5df75855079153c9bb47e5b22736baa50b510 100644 (file)
@@ -2,8 +2,7 @@
 
 function profile_init(&$a) {
 
-       if((get_config('system','block_public')) && (! local_user()) && (! remote_user()))
-               return;
+       $blocked = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);
 
        if($a->argc > 1)
                $which = $a->argv[1];
@@ -31,10 +30,12 @@ function profile_init(&$a) {
                $a->page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\r\n";
        }
 
-       $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : '');
-       $keywords = str_replace(array(',',' ',',,'),array(' ',',',','),$keywords);
-       if(strlen($keywords))
-               $a->page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\r\n" ;
+       if(! $blocked) {
+               $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : '');
+               $keywords = str_replace(array(',',' ',',,'),array(' ',',',','),$keywords);
+               if(strlen($keywords))
+                       $a->page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\r\n" ;
+       }
 
        $a->page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . (($a->profile['net-publish']) ? 'true' : 'false') . '" />' . "\r\n" ;
        $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $a->get_baseurl() . '/dfrn_poll/' . $which .'" />' . "\r\n" ;
index 86655951de4525318e4bedc9205d29ace9e0651e..34f265ee671ed1ffe8d8559b76afccbed4f4162b 100644 (file)
 
        $pubkey
 
+$diaspora
+
 </div>
 
 $marital
 
 $homepage
 
-$diaspora