mirror of
https://github.com/friendica/friendica
synced 2025-05-01 09:04:24 +02:00
Initial checkin
This commit is contained in:
commit
6348e70daa
393 changed files with 59765 additions and 0 deletions
80
include/Scrape.php
Normal file
80
include/Scrape.php
Normal file
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
require_once('library/HTML5/Parser.php');
|
||||
|
||||
if(! function_exists('attribute_contains')) {
|
||||
function attribute_contains($attr,$s) {
|
||||
$a = explode(' ', $attr);
|
||||
if(count($a) && in_array($s,$a))
|
||||
return true;
|
||||
return false;
|
||||
}}
|
||||
|
||||
|
||||
if(! function_exists('scrape_dfrn')) {
|
||||
function scrape_dfrn($url) {
|
||||
|
||||
$ret = array();
|
||||
$s = fetch_url($url);
|
||||
|
||||
if(! $s)
|
||||
return $ret;
|
||||
|
||||
$dom = HTML5_Parser::parse($s);
|
||||
|
||||
if(! $dom)
|
||||
return $ret;
|
||||
|
||||
$items = $dom->getElementsByTagName('link');
|
||||
|
||||
// get DFRN link elements
|
||||
|
||||
foreach($items as $item) {
|
||||
$x = $item->getAttribute('rel');
|
||||
if(substr($x,0,5) == "dfrn-")
|
||||
$ret[$x] = $item->getAttribute('href');
|
||||
}
|
||||
|
||||
// Pull out hCard profile elements
|
||||
|
||||
$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'))
|
||||
$ret['fn'] = $x->textContent;
|
||||
if(attribute_contains($x->getAttribute('class'),'photo'))
|
||||
$ret['photo'] = $x->getAttribute('src');
|
||||
if(attribute_contains($x->getAttribute('class'),'key'))
|
||||
$ret['key'] = $x->textContent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if(! function_exists('validate_dfrn')) {
|
||||
function validate_dfrn($a) {
|
||||
$errors = 0;
|
||||
if(! x($a,'key'))
|
||||
$errors ++;
|
||||
if(! x($a,'dfrn-request'))
|
||||
$errors ++;
|
||||
if(! x($a,'dfrn-confirm'))
|
||||
$errors ++;
|
||||
if(! x($a,'dfrn-notify'))
|
||||
$errors ++;
|
||||
if(! x($a,'dfrn-poll'))
|
||||
$errors ++;
|
||||
return $errors;
|
||||
}}
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue