X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2FScrape.php;h=e42d22afc64c9e0a792a90bc8abcd0a6c7a8930d;hb=bef8f95ef3e638cb843810ed68cd9617e6e2cc48;hp=cc46af64454be5d6b9254da8b3cdc5f9510ff0a7;hpb=b465d1f30bf100f67614e0765c4c5f8588908e26;p=friendica.git diff --git a/include/Scrape.php b/include/Scrape.php index cc46af6445..e42d22afc6 100644 --- a/include/Scrape.php +++ b/include/Scrape.php @@ -30,8 +30,11 @@ function scrape_dfrn($url) { } } - - $dom = HTML5_Parser::parse($s); + try { + $dom = HTML5_Parser::parse($s); + } catch (DOMException $e) { + logger('scrape_dfrn: parse error: ' . $e); + } if(! $dom) return $ret; @@ -132,9 +135,11 @@ function scrape_meta($url) { } } - - - $dom = HTML5_Parser::parse($s); + try { + $dom = HTML5_Parser::parse($s); + } catch (DOMException $e) { + logger('scrape_meta: parse error: ' . $e); + } if(! $dom) return $ret; @@ -177,7 +182,11 @@ function scrape_vcard($url) { } } - $dom = HTML5_Parser::parse($s); + try { + $dom = HTML5_Parser::parse($s); + } catch (DOMException $e) { + logger('scrape_vcard: parse error: ' . $e); + } if(! $dom) return $ret; @@ -243,26 +252,16 @@ function scrape_feed($url) { } } - $dom = HTML5_Parser::parse($s); + try { + $dom = HTML5_Parser::parse($s); + } catch (DOMException $e) { + logger('scrape_feed: parse error: ' . $e); + } if(! $dom) return $ret; - $items = $dom->getElementsByTagName('img'); - - // get img elements (twitter) - - if($items) { - foreach($items as $item) { - $x = $item->getAttribute('id'); - if($x === 'profile-image') { - $ret['photo'] = $item->getAttribute('src'); - } - } - } - - $head = $dom->getElementsByTagName('base'); if($head) { foreach($head as $head0) { @@ -332,10 +331,12 @@ function probe_url($url, $mode = PROBE_NORMAL) { if(! $url) return $result; + $network = null; $diaspora = false; $diaspora_base = ''; $diaspora_guid = ''; $diaspora_key = ''; + $has_lrdd = false; $email_conversant = false; $twitter = ((strpos($url,'twitter.com') !== false) ? true : false); @@ -352,6 +353,8 @@ function probe_url($url, $mode = PROBE_NORMAL) { $links = lrdd($url); if(count($links)) { + $has_lrdd = true; + logger('probe_url: found lrdd links: ' . print_r($links,true), LOGGER_DATA); foreach($links as $link) { if($link['@attributes']['rel'] === NAMESPACE_ZOT) @@ -366,6 +369,8 @@ function probe_url($url, $mode = PROBE_NORMAL) { $hcard = unamp($link['@attributes']['href']); if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') $profile = unamp($link['@attributes']['href']); + if($link['@attributes']['rel'] === 'http://portablecontacts.net/spec/1.0') + $poco = unamp($link['@attributes']['href']); if($link['@attributes']['rel'] === 'http://joindiaspora.com/seed_location') { $diaspora_base = unamp($link['@attributes']['href']); $diaspora = true; @@ -426,7 +431,8 @@ function probe_url($url, $mode = PROBE_NORMAL) { $addr = $orig_url; $network = NETWORK_MAIL; $name = substr($url,0,strpos($url,'@')); - $profile = 'http://' . substr($url,strpos($url,'@')+1); + $phost = substr($url,strpos($url,'@')+1); + $profile = 'http://' . $phost; // fix nick character range $vcard = array('fn' => $name, 'nick' => $name, 'photo' => gravatar_img($url)); $notify = 'smtp ' . random_string(); @@ -437,8 +443,15 @@ function probe_url($url, $mode = PROBE_NORMAL) { $adr = imap_rfc822_parse_adrlist($x->from,''); elseif(stristr($x->to,$orig_url)) $adr = imap_rfc822_parse_adrlist($x->to,''); - if(isset($adr) && strlen($adr[0]->personal)) - $vcard['fn'] = notags($adr[0]->personal); + if(isset($adr)) { + foreach($adr as $feadr) { + if((strcasecmp($feadr->mailbox,$name) == 0) + &&(strcasecmp($feadr->host,$phost) == 0) + && (strlen($feadr->personal))) { + $vcard['fn'] = notags($feadr->personal); + } + } + } } imap_close($mbox); } @@ -467,7 +480,7 @@ function probe_url($url, $mode = PROBE_NORMAL) { } if(strlen($dfrn)) { - $ret = scrape_dfrn($dfrn); + $ret = scrape_dfrn(($hcard) ? $hcard : $dfrn); if(is_array($ret) && x($ret,'dfrn-request')) { $network = NETWORK_DFRN; $request = $ret['dfrn-request']; @@ -484,8 +497,10 @@ function probe_url($url, $mode = PROBE_NORMAL) { } if($diaspora && $diaspora_base && $diaspora_guid) { - if($mode == PROBE_DIASPORA || ! $notify) + if($mode == PROBE_DIASPORA || ! $notify) { $notify = $diaspora_base . 'receive/users/' . $diaspora_guid; + $batch = $diaspora_base . 'receive/public' ; + } if(strpos($url,'@')) $addr = str_replace('acct:', '', $url); } @@ -493,7 +508,7 @@ function probe_url($url, $mode = PROBE_NORMAL) { if($network !== NETWORK_ZOT && $network !== NETWORK_DFRN && $network !== NETWORK_MAIL) { if($diaspora) $network = NETWORK_DIASPORA; - else + elseif($has_lrdd) $network = NETWORK_OSTATUS; $priority = 0; @@ -520,6 +535,9 @@ function probe_url($url, $mode = PROBE_NORMAL) { else $poll = $tapi . '?screen_name=' . $tid; $profile = 'http://twitter.com/#!/' . $tid; + $vcard['photo'] = 'https://api.twitter.com/1/users/profile_image/' . $tid; + $vcard['nick'] = $tid; + $vcard['fn'] = $tid . '@twitter'; } if(! x($vcard,'fn')) @@ -530,7 +548,7 @@ function probe_url($url, $mode = PROBE_NORMAL) { if($twitter || ! $poll) $check_feed = true; - if((! isset($vcard)) || (! $profile)) + if((! isset($vcard)) || (! x($vcard,'fn')) || (! $profile)) $check_feed = true; if(($at_addr) && (! count($links))) $check_feed = false; @@ -637,7 +655,7 @@ function probe_url($url, $mode = PROBE_NORMAL) { $vcard['nick'] = trim(substr($vcard['nick'],0,strpos($vcard['nick'],' '))); } if(! $network) - $network = 'feed'; + $network = NETWORK_FEED; if(! $priority) $priority = 2; } @@ -651,18 +669,24 @@ function probe_url($url, $mode = PROBE_NORMAL) { if(! $profile) $profile = $url; - $vcard['fn'] = notags($vcard['fn']); - $vcard['nick'] = str_replace(' ','',notags($vcard['nick'])); + // No human could be associated with this link, use the URL as the contact name + if(($network === NETWORK_FEED) && ($poll) && (! x($vcard,'fn'))) + $vcard['fn'] = $url; + $vcard['fn'] = notags($vcard['fn']); + $vcard['nick'] = str_replace(' ','',notags($vcard['nick'])); + $result['name'] = $vcard['fn']; $result['nick'] = $vcard['nick']; $result['url'] = $profile; $result['addr'] = $addr; + $result['batch'] = $batch; $result['notify'] = $notify; $result['poll'] = $poll; $result['request'] = $request; $result['confirm'] = $confirm; + $result['poco'] = $poco; $result['photo'] = $vcard['photo']; $result['priority'] = $priority; $result['network'] = $network;