X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2FScrape.php;h=642b8e624c5601d1a7ab20c6b4f5c4e76fe5b8b3;hb=8bfd405beef2224628e1666c1a1248e3c5a2205c;hp=1b319481ba1e27c9a1fb1e7d5bd0e9b9c2efadaa;hpb=96342878398e394173ba1a2dd825afbcb19e7199;p=friendica.git diff --git a/include/Scrape.php b/include/Scrape.php index 1b319481ba..642b8e624c 100644 --- a/include/Scrape.php +++ b/include/Scrape.php @@ -249,20 +249,6 @@ function scrape_feed($url) { 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) { @@ -301,6 +287,26 @@ function scrape_feed($url) { return $ret; }} + +/** + * + * Probe a network address to discover what kind of protocols we need to communicate with it. + * + * Warning: this function is a bit touchy and there are some subtle dependencies within the logic flow. + * Edit with care. + * + */ + +/** + * + * PROBE_DIASPORA has a bias towards returning Diaspora information + * while PROBE_NORMAL has a bias towards dfrn/zot - in the case where + * an address (such as a Friendika address) supports more than one type + * of network. + * + */ + + define ( 'PROBE_NORMAL', 0); define ( 'PROBE_DIASPORA', 1); @@ -312,10 +318,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); @@ -332,6 +340,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) @@ -406,7 +416,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(); @@ -417,8 +428,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); } @@ -447,7 +465,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']; @@ -464,8 +482,10 @@ function probe_url($url, $mode = PROBE_NORMAL) { } if($diaspora && $diaspora_base && $diaspora_guid) { - if($mode == PROBE_DIASPORA || ! $notify) - $notify = $diaspora_base . 'receive/post/' . $diaspora_guid; + 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); } @@ -473,7 +493,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; @@ -500,6 +520,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')) @@ -510,7 +533,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; @@ -617,7 +640,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; } @@ -631,14 +654,19 @@ 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;