Merge pull request #716 from dawnbreak/docu
Some documentation for include/network.php and some fixes.
This commit is contained in:
commit
b4f65840d1
@ -398,18 +398,22 @@ function json_return_and_die($x, $content_type = 'application/json') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
// Generic XML return
|
* @brief Generic XML return.
|
||||||
// Outputs a basic dfrn XML status structure to STDOUT, with a <status> variable
|
*
|
||||||
// of $st and an optional text <message> of $message and terminates the current process.
|
* Outputs a basic dfrn XML status structure to STDOUT, with a <status> variable
|
||||||
|
* of $st and an optional text <message> of $message and terminates the current
|
||||||
|
* process.
|
||||||
|
*
|
||||||
|
* @param string $st
|
||||||
|
* @param string $message
|
||||||
|
*/
|
||||||
function xml_status($st, $message = '') {
|
function xml_status($st, $message = '') {
|
||||||
|
|
||||||
$xml_message = ((strlen($message)) ? "\t<message>" . xmlify($message) . "</message>\r\n" : '');
|
$xml_message = ((strlen($message)) ? "\t<message>" . xmlify($message) . "</message>\r\n" : '');
|
||||||
|
|
||||||
if($st)
|
if($st)
|
||||||
logger('xml_status returning non_zero: ' . $st . " message=" . $message);
|
logger('Returning non_zero: ' . $st . " message=" . $message);
|
||||||
|
|
||||||
header( "Content-type: text/xml" );
|
header( "Content-type: text/xml" );
|
||||||
echo '<?xml version="1.0" encoding="UTF-8"?>'."\r\n";
|
echo '<?xml version="1.0" encoding="UTF-8"?>'."\r\n";
|
||||||
@ -418,15 +422,13 @@ function xml_status($st, $message = '') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Send HTTP status header
|
* @brief Send HTTP status header.
|
||||||
*
|
*
|
||||||
* @param int $val
|
* @param int $val
|
||||||
* integer HTTP status result value
|
* integer HTTP status result value
|
||||||
* @param string $msg
|
* @param string $msg
|
||||||
* optional message
|
* optional message
|
||||||
* @returns nil
|
|
||||||
*/
|
*/
|
||||||
function http_status($val, $msg = '') {
|
function http_status($val, $msg = '') {
|
||||||
if ($val >= 400)
|
if ($val >= 400)
|
||||||
@ -434,12 +436,11 @@ function http_status($val, $msg = '') {
|
|||||||
if ($val >= 200 && $val < 300)
|
if ($val >= 200 && $val < 300)
|
||||||
$msg = (($msg) ? $msg : 'OK');
|
$msg = (($msg) ? $msg : 'OK');
|
||||||
|
|
||||||
logger('http_status_exit ' . $val . ' ' . $msg);
|
logger('' . $val . ' ' . $msg);
|
||||||
header($_SERVER['SERVER_PROTOCOL'] . ' ' . $val . ' ' . $msg);
|
header($_SERVER['SERVER_PROTOCOL'] . ' ' . $val . ' ' . $msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Send HTTP status header and exit.
|
* @brief Send HTTP status header and exit.
|
||||||
*
|
*
|
||||||
@ -447,19 +448,20 @@ function http_status($val, $msg = '') {
|
|||||||
* integer HTTP status result value
|
* integer HTTP status result value
|
||||||
* @param string $msg
|
* @param string $msg
|
||||||
* optional message
|
* optional message
|
||||||
* @returns (does not return, process is terminated)
|
* @return does not return, process is terminated
|
||||||
*/
|
*/
|
||||||
function http_status_exit($val, $msg = '') {
|
function http_status_exit($val, $msg = '') {
|
||||||
http_status($val, $msg);
|
http_status($val, $msg);
|
||||||
killme();
|
killme();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief convert an XML document to a normalised, case-corrected array used by webfinger.
|
||||||
// convert an XML document to a normalised, case-corrected array
|
*
|
||||||
// used by webfinger
|
* @param string|array|SimpleXMLElement $xml_element
|
||||||
|
* @param int $recursion_depth[in,out]
|
||||||
|
* @return NULL|string|array
|
||||||
|
*/
|
||||||
function convert_xml_element_to_array($xml_element, &$recursion_depth=0) {
|
function convert_xml_element_to_array($xml_element, &$recursion_depth=0) {
|
||||||
|
|
||||||
// If we're getting too deep, bail out
|
// If we're getting too deep, bail out
|
||||||
@ -481,7 +483,6 @@ function convert_xml_element_to_array($xml_element, &$recursion_depth=0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach($xml_element as $key=>$value) {
|
foreach($xml_element as $key=>$value) {
|
||||||
|
|
||||||
$recursion_depth++;
|
$recursion_depth++;
|
||||||
$result_array[strtolower($key)] =
|
$result_array[strtolower($key)] =
|
||||||
convert_xml_element_to_array($value, $recursion_depth);
|
convert_xml_element_to_array($value, $recursion_depth);
|
||||||
@ -495,7 +496,6 @@ function convert_xml_element_to_array($xml_element, &$recursion_depth=0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return ($result_array);
|
return ($result_array);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return (trim(strval($xml_element)));
|
return (trim(strval($xml_element)));
|
||||||
}
|
}
|
||||||
@ -523,32 +523,43 @@ function z_dns_check($h,$check_mx = 0) {
|
|||||||
// Specific record type flags are unreliable on FreeBSD and Mac,
|
// Specific record type flags are unreliable on FreeBSD and Mac,
|
||||||
// so now we'll ignore these and just check for the existence of any DNS record.
|
// so now we'll ignore these and just check for the existence of any DNS record.
|
||||||
return((@dns_get_record($h) || filter_var($h, FILTER_VALIDATE_IP)) ? true : false);
|
return((@dns_get_record($h) || filter_var($h, FILTER_VALIDATE_IP)) ? true : false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take a URL from the wild, prepend http:// if necessary
|
/**
|
||||||
// and check DNS to see if it's real (or check if is a valid IP address)
|
* @brief Validates a given URL
|
||||||
// return true if it's OK, false if something is wrong with it
|
*
|
||||||
|
* Take a URL from the wild, prepend http:// if necessary and check DNS to see
|
||||||
|
* if it's real (or check if is a valid IP address).
|
||||||
|
*
|
||||||
|
* @see z_dns_check()
|
||||||
|
*
|
||||||
|
* @param string $url[in,out] URL to check
|
||||||
|
* @return boolean Return true if it's OK, false if something is wrong with it
|
||||||
|
*/
|
||||||
function validate_url(&$url) {
|
function validate_url(&$url) {
|
||||||
|
|
||||||
// no naked subdomains (allow localhost for tests)
|
// no naked subdomains (allow localhost for tests)
|
||||||
if(strpos($url, '.') === false && strpos($url, '/localhost/') === false)
|
if(strpos($url, '.') === false && strpos($url, '/localhost/') === false)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(substr($url, 0, 4) != 'http')
|
if(substr($url, 0, 4) != 'http')
|
||||||
$url = 'http://' . $url;
|
$url = 'http://' . $url;
|
||||||
|
|
||||||
$h = @parse_url($url);
|
$h = @parse_url($url);
|
||||||
|
|
||||||
if(($h) && z_dns_check($h['host'])) {
|
if(($h) && z_dns_check($h['host'])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// checks that email is an actual resolvable internet address
|
/**
|
||||||
|
* @brief Checks that email is an actual resolvable internet address.
|
||||||
|
*
|
||||||
|
* @param string $addr
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
function validate_email($addr) {
|
function validate_email($addr) {
|
||||||
|
|
||||||
if(get_config('system', 'disable_email_validation'))
|
if(get_config('system', 'disable_email_validation'))
|
||||||
@ -556,20 +567,24 @@ function validate_email($addr) {
|
|||||||
|
|
||||||
if(! strpos($addr, '@'))
|
if(! strpos($addr, '@'))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
$h = substr($addr, strpos($addr, '@') + 1);
|
$h = substr($addr, strpos($addr, '@') + 1);
|
||||||
|
|
||||||
if(($h) && z_dns_check($h, true)) {
|
if(($h) && z_dns_check($h, true)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check $url against our list of allowed sites,
|
/**
|
||||||
// wildcards allowed. If allowed_sites is unset return true;
|
* @brief Check $url against our list of allowed sites.
|
||||||
// If url is allowed, return true.
|
*
|
||||||
// otherwise, return false
|
* Wildcards allowed. If allowed_sites is unset return true.
|
||||||
|
*
|
||||||
|
* @param string $url
|
||||||
|
* @return boolean Return true if url is allowed, otherwise return false
|
||||||
|
*/
|
||||||
function allowed_url($url) {
|
function allowed_url($url) {
|
||||||
|
|
||||||
$h = @parse_url($url);
|
$h = @parse_url($url);
|
||||||
@ -606,15 +621,17 @@ function allowed_url($url) {
|
|||||||
return $found;
|
return $found;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if email address is allowed to register here.
|
/**
|
||||||
// Compare against our list (wildcards allowed).
|
* @brief Check if email address is allowed to register here.
|
||||||
// Returns false if not allowed, true if allowed or if
|
*
|
||||||
// allowed list is not configured.
|
* Compare against our list (wildcards allowed).
|
||||||
|
*
|
||||||
|
* @param string $email
|
||||||
|
* @return boolean Returns false if not allowed, true if allowed or if allowed list is
|
||||||
|
* not configured.
|
||||||
|
*/
|
||||||
function allowed_email($email) {
|
function allowed_email($email) {
|
||||||
|
|
||||||
|
|
||||||
$domain = strtolower(substr($email, strpos($email, '@') + 1));
|
$domain = strtolower(substr($email, strpos($email, '@') + 1));
|
||||||
if(! $domain)
|
if(! $domain)
|
||||||
return false;
|
return false;
|
||||||
@ -660,6 +677,7 @@ function allowed_email($email) {
|
|||||||
} elseif (!$str_allowed && !$found_not_allowed) {
|
} elseif (!$str_allowed && !$found_not_allowed) {
|
||||||
$return = true;
|
$return = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -669,10 +687,12 @@ function parse_xml_string($s,$strict = true) {
|
|||||||
if($strict) {
|
if($strict) {
|
||||||
if(! strstr($s,'<?xml'))
|
if(! strstr($s,'<?xml'))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
$s2 = substr($s,strpos($s,'<?xml'));
|
$s2 = substr($s,strpos($s,'<?xml'));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
$s2 = $s;
|
$s2 = $s;
|
||||||
|
|
||||||
libxml_use_internal_errors(true);
|
libxml_use_internal_errors(true);
|
||||||
|
|
||||||
$x = @simplexml_load_string($s2);
|
$x = @simplexml_load_string($s2);
|
||||||
@ -680,8 +700,10 @@ function parse_xml_string($s,$strict = true) {
|
|||||||
logger('libxml: parse: error: ' . $s2, LOGGER_DATA);
|
logger('libxml: parse: error: ' . $s2, LOGGER_DATA);
|
||||||
foreach(libxml_get_errors() as $err)
|
foreach(libxml_get_errors() as $err)
|
||||||
logger('libxml: parse: ' . $err->code." at ".$err->line.":".$err->column." : ".$err->message, LOGGER_DATA);
|
logger('libxml: parse: ' . $err->code." at ".$err->line.":".$err->column." : ".$err->message, LOGGER_DATA);
|
||||||
|
|
||||||
libxml_clear_errors();
|
libxml_clear_errors();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $x;
|
return $x;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -697,7 +719,7 @@ function scale_external_images($s, $include_link = true, $scale_replace = false)
|
|||||||
require_once('include/photo/photo_driver.php');
|
require_once('include/photo/photo_driver.php');
|
||||||
|
|
||||||
foreach($matches as $mtch) {
|
foreach($matches as $mtch) {
|
||||||
logger('scale_external_image: ' . $mtch[2] . ' ' . $mtch[3]);
|
logger('data: ' . $mtch[2] . ' ' . $mtch[3]);
|
||||||
|
|
||||||
if(substr($mtch[1],0,1) == '=') {
|
if(substr($mtch[1],0,1) == '=') {
|
||||||
$owidth = intval(substr($mtch[2],1));
|
$owidth = intval(substr($mtch[2],1));
|
||||||
@ -748,12 +770,12 @@ function scale_external_images($s, $include_link = true, $scale_replace = false)
|
|||||||
$ph->scaleImage(1024);
|
$ph->scaleImage(1024);
|
||||||
$new_width = $ph->getWidth();
|
$new_width = $ph->getWidth();
|
||||||
$new_height = $ph->getHeight();
|
$new_height = $ph->getHeight();
|
||||||
logger('scale_external_images: ' . $orig_width . '->' . $new_width . 'w ' . $orig_height . '->' . $new_height . 'h' . ' match: ' . $mtch[0], LOGGER_DEBUG);
|
logger('data: ' . $orig_width . '->' . $new_width . 'w ' . $orig_height . '->' . $new_height . 'h' . ' match: ' . $mtch[0], LOGGER_DEBUG);
|
||||||
$s = str_replace($mtch[0],'[' . $tag . '=' . $new_width . 'x' . $new_height. ']' . $scaled . '[/' . $tag . ']'
|
$s = str_replace($mtch[0],'[' . $tag . '=' . $new_width . 'x' . $new_height. ']' . $scaled . '[/' . $tag . ']'
|
||||||
. "\n" . (($include_link)
|
. "\n" . (($include_link)
|
||||||
? '[zrl=' . $mtch[2] . ']' . t('view full size') . '[/zrl]' . "\n"
|
? '[zrl=' . $mtch[2] . ']' . t('view full size') . '[/zrl]' . "\n"
|
||||||
: ''),$s);
|
: ''),$s);
|
||||||
logger('scale_external_images: new string: ' . $s, LOGGER_DEBUG);
|
logger('new string: ' . $s, LOGGER_DEBUG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -768,27 +790,31 @@ function scale_external_images($s, $include_link = true, $scale_replace = false)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* xml2array() will convert the given XML text to an array in the XML structure.
|
* @brief xml2array() will convert the given XML text to an array in the XML structure.
|
||||||
|
*
|
||||||
* Link: http://www.bin-co.com/php/scripts/xml2array/
|
* Link: http://www.bin-co.com/php/scripts/xml2array/
|
||||||
* Portions significantly re-written by mike@macgirvin.com for Friendica (namespaces, lowercase tags, get_attribute default changed, more...)
|
* Portions significantly re-written by mike@macgirvin.com for Friendica
|
||||||
* Arguments : $contents - The XML text
|
* (namespaces, lowercase tags, get_attribute default changed, more...)
|
||||||
* $namespaces - true or false include namespace information in the returned array as array elements.
|
*
|
||||||
* $get_attributes - 1 or 0. If this is 1 the function will get the attributes as well as the tag values - this results in a different array structure in the return value.
|
|
||||||
* $priority - Can be 'tag' or 'attribute'. This will change the way the resulting array sturcture. For 'tag', the tags are given more importance.
|
|
||||||
* Return: The parsed XML in an array form. Use print_r() to see the resulting array structure.
|
|
||||||
* Examples: $array = xml2array(file_get_contents('feed.xml'));
|
* Examples: $array = xml2array(file_get_contents('feed.xml'));
|
||||||
* $array = xml2array(file_get_contents('feed.xml', true, 1, 'attribute'));
|
* $array = xml2array(file_get_contents('feed.xml', true, 1, 'attribute'));
|
||||||
|
*
|
||||||
|
* @param string $contents The XML text
|
||||||
|
* @param boolean $namespaces true or false include namespace information in the returned array as array elements
|
||||||
|
* @param int $get_attributes 1 or 0. If this is 1 the function will get the attributes as well as the tag values - this results in a different array structure in the return value.
|
||||||
|
* @param string $priority Can be 'tag' or 'attribute'. This will change the way the resulting array sturcture. For 'tag', the tags are given more importance.
|
||||||
|
*
|
||||||
|
* @return array The parsed XML in an array form. Use print_r() to see the resulting array structure.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function xml2array($contents, $namespaces = true, $get_attributes=1, $priority = 'attribute') {
|
function xml2array($contents, $namespaces = true, $get_attributes=1, $priority = 'attribute') {
|
||||||
if(!$contents) return array();
|
if(!$contents)
|
||||||
|
return array();
|
||||||
|
|
||||||
if(!function_exists('xml_parser_create')) {
|
if(!function_exists('xml_parser_create')) {
|
||||||
logger('xml2array: parser function missing');
|
logger('xml2array: parser function missing');
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
libxml_use_internal_errors(true);
|
libxml_use_internal_errors(true);
|
||||||
libxml_clear_errors();
|
libxml_clear_errors();
|
||||||
|
|
||||||
@ -814,6 +840,7 @@ function xml2array($contents, $namespaces = true, $get_attributes=1, $priority =
|
|||||||
foreach(libxml_get_errors() as $err)
|
foreach(libxml_get_errors() as $err)
|
||||||
logger('libxml: parse: ' . $err->code . " at " . $err->line . ":" . $err->column . " : " . $err->message, LOGGER_DATA);
|
logger('libxml: parse: ' . $err->code . " at " . $err->line . ":" . $err->column . " : " . $err->message, LOGGER_DATA);
|
||||||
libxml_clear_errors();
|
libxml_clear_errors();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -880,7 +907,6 @@ function xml2array($contents, $namespaces = true, $get_attributes=1, $priority =
|
|||||||
$current[$tag]['0_attr'] = $current[$tag.'_attr'];
|
$current[$tag]['0_attr'] = $current[$tag.'_attr'];
|
||||||
unset($current[$tag.'_attr']);
|
unset($current[$tag.'_attr']);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
$last_item_index = $repeated_tag_index[$tag.'_'.$level]-1;
|
$last_item_index = $repeated_tag_index[$tag.'_'.$level]-1;
|
||||||
$current = &$current[$tag][$last_item_index];
|
$current = &$current[$tag][$last_item_index];
|
||||||
@ -891,7 +917,8 @@ function xml2array($contents, $namespaces = true, $get_attributes=1, $priority =
|
|||||||
if(!isset($current[$tag])) { //New Key
|
if(!isset($current[$tag])) { //New Key
|
||||||
$current[$tag] = $result;
|
$current[$tag] = $result;
|
||||||
$repeated_tag_index[$tag.'_'.$level] = 1;
|
$repeated_tag_index[$tag.'_'.$level] = 1;
|
||||||
if($priority == 'tag' and $attributes_data) $current[$tag. '_attr'] = $attributes_data;
|
if($priority == 'tag' and $attributes_data)
|
||||||
|
$current[$tag. '_attr'] = $attributes_data;
|
||||||
|
|
||||||
} else { // If taken, put all things inside a list(array)
|
} else { // If taken, put all things inside a list(array)
|
||||||
if(isset($current[$tag][0]) and is_array($current[$tag])) { // If it is already an array...
|
if(isset($current[$tag][0]) and is_array($current[$tag])) { // If it is already an array...
|
||||||
@ -903,13 +930,11 @@ function xml2array($contents, $namespaces = true, $get_attributes=1, $priority =
|
|||||||
$current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data;
|
$current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data;
|
||||||
}
|
}
|
||||||
$repeated_tag_index[$tag.'_'.$level]++;
|
$repeated_tag_index[$tag.'_'.$level]++;
|
||||||
|
|
||||||
} else { // If it is not an array...
|
} else { // If it is not an array...
|
||||||
$current[$tag] = array($current[$tag],$result); //...Make it an array using using the existing value and the new value
|
$current[$tag] = array($current[$tag],$result); //...Make it an array using using the existing value and the new value
|
||||||
$repeated_tag_index[$tag.'_'.$level] = 1;
|
$repeated_tag_index[$tag.'_'.$level] = 1;
|
||||||
if($priority == 'tag' and $get_attributes) {
|
if($priority == 'tag' and $get_attributes) {
|
||||||
if(isset($current[$tag.'_attr'])) { // The attribute of the last(0th) tag must be moved as well
|
if(isset($current[$tag.'_attr'])) { // The attribute of the last(0th) tag must be moved as well
|
||||||
|
|
||||||
$current[$tag]['0_attr'] = $current[$tag.'_attr'];
|
$current[$tag]['0_attr'] = $current[$tag.'_attr'];
|
||||||
unset($current[$tag.'_attr']);
|
unset($current[$tag.'_attr']);
|
||||||
}
|
}
|
||||||
@ -1015,8 +1040,14 @@ function email_send($addr, $subject, $headers, $item) {
|
|||||||
mail($addr, $subject, $body, $headers);
|
mail($addr, $subject, $body, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Creates an xchan entry for URL.
|
||||||
|
*
|
||||||
|
* @param string $url URL to discover
|
||||||
|
* @param array $arr fallback values if scrape_feed() is empty
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
function discover_by_url($url, $arr = null) {
|
function discover_by_url($url, $arr = null) {
|
||||||
require_once('library/HTML5/Parser.php');
|
require_once('library/HTML5/Parser.php');
|
||||||
|
|
||||||
@ -1024,6 +1055,7 @@ function discover_by_url($url,$arr = null) {
|
|||||||
if(! $x) {
|
if(! $x) {
|
||||||
if(! $arr)
|
if(! $arr)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
$network = (($arr['network']) ? $arr['network'] : 'unknown');
|
$network = (($arr['network']) ? $arr['network'] : 'unknown');
|
||||||
$name = (($arr['name']) ? $arr['name'] : 'unknown');
|
$name = (($arr['name']) ? $arr['name'] : 'unknown');
|
||||||
$photo = (($arr['photo']) ? $arr['photo'] : '');
|
$photo = (($arr['photo']) ? $arr['photo'] : '');
|
||||||
@ -1051,19 +1083,19 @@ function discover_by_url($url,$arr = null) {
|
|||||||
$level = 0;
|
$level = 0;
|
||||||
$x = z_fetch_url($guid, false, $level, array('novalidate' => true));
|
$x = z_fetch_url($guid, false, $level, array('novalidate' => true));
|
||||||
if(! $x['success']) {
|
if(! $x['success']) {
|
||||||
logger('probe_url: feed fetch failed for ' . $poll);
|
logger('Feed fetch failed for ' . $guid);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$xml = $x['body'];
|
$xml = $x['body'];
|
||||||
logger('probe_url: fetch feed: ' . $guid . ' returns: ' . $xml, LOGGER_DATA);
|
logger('Fetch feed: ' . $guid . ' returns: ' . $xml, LOGGER_DATA);
|
||||||
logger('probe_url: scrape_feed: headers: ' . $x['header'], LOGGER_DATA);
|
logger('scrape_feed: headers: ' . $x['header'], LOGGER_DATA);
|
||||||
|
|
||||||
// Don't try and parse an empty string
|
// Don't try and parse an empty string
|
||||||
$feed->set_raw_data(($xml) ? $xml : '<?xml version="1.0" encoding="utf-8" ?><xml></xml>');
|
$feed->set_raw_data(($xml) ? $xml : '<?xml version="1.0" encoding="utf-8" ?><xml></xml>');
|
||||||
|
|
||||||
$feed->init();
|
$feed->init();
|
||||||
if($feed->error())
|
if($feed->error())
|
||||||
logger('probe_url: scrape_feed: Error parsing XML: ' . $feed->error());
|
logger('scrape_feed: Error parsing XML: ' . $feed->error());
|
||||||
|
|
||||||
$name = unxmlify(trim($feed->get_title()));
|
$name = unxmlify(trim($feed->get_title()));
|
||||||
$photo = $feed->get_image_url();
|
$photo = $feed->get_image_url();
|
||||||
@ -1118,7 +1150,7 @@ function discover_by_url($url,$arr = null) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($poll === $profile)
|
if($guid === $profile)
|
||||||
$lnk = $feed->get_permalink();
|
$lnk = $feed->get_permalink();
|
||||||
if(isset($lnk) && strlen($lnk))
|
if(isset($lnk) && strlen($lnk))
|
||||||
$profile = $lnk;
|
$profile = $lnk;
|
||||||
@ -1130,9 +1162,6 @@ function discover_by_url($url,$arr = null) {
|
|||||||
if(! $name)
|
if(! $name)
|
||||||
$name = notags($feed->get_description());
|
$name = notags($feed->get_description());
|
||||||
|
|
||||||
if(! $guid)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
$r = q("select * from xchan where xchan_hash = '%s' limit 1",
|
$r = q("select * from xchan where xchan_hash = '%s' limit 1",
|
||||||
dbesc($guid)
|
dbesc($guid)
|
||||||
);
|
);
|
||||||
@ -1146,7 +1175,6 @@ function discover_by_url($url,$arr = null) {
|
|||||||
[
|
[
|
||||||
'xchan_hash' => $guid,
|
'xchan_hash' => $guid,
|
||||||
'xchan_guid' => $guid,
|
'xchan_guid' => $guid,
|
||||||
'xchan_pubkey' => $pubkey,
|
|
||||||
'xchan_addr' => $addr,
|
'xchan_addr' => $addr,
|
||||||
'xchan_url' => $profile,
|
'xchan_url' => $profile,
|
||||||
'xchan_name' => $name,
|
'xchan_name' => $name,
|
||||||
@ -1164,11 +1192,10 @@ function discover_by_url($url,$arr = null) {
|
|||||||
dbesc($photos[3]),
|
dbesc($photos[3]),
|
||||||
dbesc($guid)
|
dbesc($guid)
|
||||||
);
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function discover_by_webbie($webbie) {
|
function discover_by_webbie($webbie) {
|
||||||
require_once('library/HTML5/Parser.php');
|
require_once('library/HTML5/Parser.php');
|
||||||
|
|
||||||
@ -1266,7 +1293,6 @@ function discover_by_webbie($webbie) {
|
|||||||
if(! $x)
|
if(! $x)
|
||||||
$probe_old = true;
|
$probe_old = true;
|
||||||
|
|
||||||
|
|
||||||
if((! $dfrn) && (! $has_salmon))
|
if((! $dfrn) && (! $has_salmon))
|
||||||
$probe_old = true;
|
$probe_old = true;
|
||||||
|
|
||||||
@ -1342,7 +1368,6 @@ function discover_by_webbie($webbie) {
|
|||||||
$location = find_webfinger_location($v,$rhs);
|
$location = find_webfinger_location($v,$rhs);
|
||||||
if($address)
|
if($address)
|
||||||
$nickname = substr($address,0,strpos($address,'@'));
|
$nickname = substr($address,0,strpos($address,'@'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if($salmon_key && $has_salmon && $atom_feed && (! $dfrn) && (! $diaspora)) {
|
if($salmon_key && $has_salmon && $atom_feed && (! $dfrn) && (! $diaspora)) {
|
||||||
@ -1410,12 +1435,7 @@ function discover_by_webbie($webbie) {
|
|||||||
$diaspora_guid = $vcard['uid'];
|
$diaspora_guid = $vcard['uid'];
|
||||||
if(($vcard['url']) && (! $diaspora_base))
|
if(($vcard['url']) && (! $diaspora_base))
|
||||||
$diaspora_base = $vcard['url'];
|
$diaspora_base = $vcard['url'];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1429,7 +1449,6 @@ function discover_by_webbie($webbie) {
|
|||||||
$host = $m['host'];
|
$host = $m['host'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if($diaspora && $diaspora_base && $diaspora_guid) {
|
if($diaspora && $diaspora_base && $diaspora_guid) {
|
||||||
if($dfrn)
|
if($dfrn)
|
||||||
$network = 'friendica-over-diaspora';
|
$network = 'friendica-over-diaspora';
|
||||||
@ -1438,7 +1457,6 @@ function discover_by_webbie($webbie) {
|
|||||||
|
|
||||||
$base = trim($diaspora_base, '/');
|
$base = trim($diaspora_base, '/');
|
||||||
$notify = $base . '/receive';
|
$notify = $base . '/receive';
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if($gnusoc) {
|
if($gnusoc) {
|
||||||
@ -1447,15 +1465,12 @@ function discover_by_webbie($webbie) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
logger('network: ' . $network);
|
logger('network: ' . $network);
|
||||||
logger('address: ' . $address);
|
logger('address: ' . $address);
|
||||||
logger('fullname: ' . $fullname);
|
logger('fullname: ' . $fullname);
|
||||||
logger('pubkey: ' . $pubkey);
|
logger('pubkey: ' . $pubkey);
|
||||||
logger('location: ' . $location);
|
logger('location: ' . $location);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// if we have everything we need, let's create the records
|
// if we have everything we need, let's create the records
|
||||||
|
|
||||||
if($network && $address && $fullname && $pubkey && $location) {
|
if($network && $address && $fullname && $pubkey && $location) {
|
||||||
@ -1522,7 +1537,6 @@ function discover_by_webbie($webbie) {
|
|||||||
|
|
||||||
function webfinger_rfc7033($webbie,$zot = false) {
|
function webfinger_rfc7033($webbie,$zot = false) {
|
||||||
|
|
||||||
|
|
||||||
if(strpos($webbie,'@')) {
|
if(strpos($webbie,'@')) {
|
||||||
$lhs = substr($webbie,0,strpos($webbie,'@'));
|
$lhs = substr($webbie,0,strpos($webbie,'@'));
|
||||||
$rhs = substr($webbie,strpos($webbie,'@')+1);
|
$rhs = substr($webbie,strpos($webbie,'@')+1);
|
||||||
@ -1561,8 +1575,10 @@ function webfinger_rfc7033($webbie,$zot = false) {
|
|||||||
// Otherwise we have to store every alias that we may ever encounter and
|
// Otherwise we have to store every alias that we may ever encounter and
|
||||||
// validate every URL we ever find against every possible alias
|
// validate every URL we ever find against every possible alias
|
||||||
|
|
||||||
// @fixme pump.io is going to be a real bugger since it doesn't return subject or aliases
|
/**
|
||||||
// or provide lookup by url
|
* @FIXME pump.io is going to be a real bugger since it doesn't return
|
||||||
|
* subject or aliases or provide lookup by url
|
||||||
|
*/
|
||||||
|
|
||||||
$j['address'] = find_webfinger_address($j,$rhs);
|
$j['address'] = find_webfinger_address($j,$rhs);
|
||||||
$j['location'] = find_webfinger_location($j,$rhs);
|
$j['location'] = find_webfinger_location($j,$rhs);
|
||||||
@ -1634,8 +1650,6 @@ function match_webfinger_location($s,$h) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function old_webfinger($webbie) {
|
function old_webfinger($webbie) {
|
||||||
|
|
||||||
$host = '';
|
$host = '';
|
||||||
@ -1682,14 +1696,14 @@ function fetch_lrdd_template($host) {
|
|||||||
}
|
}
|
||||||
if(! strpos($tpl,'{uri}'))
|
if(! strpos($tpl,'{uri}'))
|
||||||
$tpl = '';
|
$tpl = '';
|
||||||
return $tpl;
|
|
||||||
|
|
||||||
|
return $tpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function fetch_xrd_links($url) {
|
function fetch_xrd_links($url) {
|
||||||
|
|
||||||
logger('fetch_xrd_links: ' . $url, LOGGER_DEBUG);
|
logger('url: ' . $url, LOGGER_DEBUG);
|
||||||
|
|
||||||
$redirects = 0;
|
$redirects = 0;
|
||||||
$x = z_fetch_url($url,false,$redirects,array('timeout' => 20));
|
$x = z_fetch_url($url,false,$redirects,array('timeout' => 20));
|
||||||
@ -1698,7 +1712,7 @@ function fetch_xrd_links($url) {
|
|||||||
return array();
|
return array();
|
||||||
|
|
||||||
$xml = $x['body'];
|
$xml = $x['body'];
|
||||||
logger('fetch_xrd_links: ' . $xml, LOGGER_DATA);
|
logger('data: ' . $xml, LOGGER_DATA);
|
||||||
|
|
||||||
if ((! $xml) || (! stristr($xml,'<xrd')))
|
if ((! $xml) || (! stristr($xml,'<xrd')))
|
||||||
return array();
|
return array();
|
||||||
@ -1739,7 +1753,7 @@ function fetch_xrd_links($url) {
|
|||||||
$links[]['@attributes'] = array('rel' => 'subject' , 'href' => $arr['xrd']['subject']);
|
$links[]['@attributes'] = array('rel' => 'subject' , 'href' => $arr['xrd']['subject']);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger('fetch_xrd_links: ' . print_r($links,true), LOGGER_DATA);
|
logger('data: ' . print_r($links, true), LOGGER_DATA);
|
||||||
|
|
||||||
return $links;
|
return $links;
|
||||||
}
|
}
|
||||||
@ -1749,7 +1763,7 @@ function scrape_vcard($url) {
|
|||||||
|
|
||||||
$ret = array();
|
$ret = array();
|
||||||
|
|
||||||
logger('scrape_vcard: url=' . $url);
|
logger('url=' . $url);
|
||||||
|
|
||||||
$x = z_fetch_url($url);
|
$x = z_fetch_url($url);
|
||||||
if(! $x['success'])
|
if(! $x['success'])
|
||||||
@ -1773,7 +1787,7 @@ function scrape_vcard($url) {
|
|||||||
try {
|
try {
|
||||||
$dom = HTML5_Parser::parse($s);
|
$dom = HTML5_Parser::parse($s);
|
||||||
} catch (DOMException $e) {
|
} catch (DOMException $e) {
|
||||||
logger('scrape_vcard: parse error: ' . $e);
|
logger('Parse error: ' . $e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(! $dom)
|
if(! $dom)
|
||||||
@ -1822,8 +1836,12 @@ function scrape_vcard($url) {
|
|||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param string $url The URL to scrape
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
function scrape_feed($url) {
|
function scrape_feed($url) {
|
||||||
|
|
||||||
$ret = array();
|
$ret = array();
|
||||||
@ -1837,14 +1855,13 @@ function scrape_feed($url) {
|
|||||||
$code = $x['return_code'];
|
$code = $x['return_code'];
|
||||||
$s = $x['body'];
|
$s = $x['body'];
|
||||||
|
|
||||||
logger('scrape_feed: returns: ' . $code . ' headers=' . $headers, LOGGER_DEBUG);
|
logger('returns: ' . $code . ' headers=' . $headers, LOGGER_DEBUG);
|
||||||
|
|
||||||
if(! $s) {
|
if(! $s) {
|
||||||
logger('scrape_feed: no data returned for ' . $url);
|
logger('No data returned for ' . $url);
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$lines = explode("\n", $headers);
|
$lines = explode("\n", $headers);
|
||||||
if(count($lines)) {
|
if(count($lines)) {
|
||||||
foreach($lines as $line) {
|
foreach($lines as $line) {
|
||||||
@ -1869,15 +1886,14 @@ function scrape_feed($url) {
|
|||||||
try {
|
try {
|
||||||
$dom = HTML5_Parser::parse($s);
|
$dom = HTML5_Parser::parse($s);
|
||||||
} catch (DOMException $e) {
|
} catch (DOMException $e) {
|
||||||
logger('scrape_feed: parse error: ' . $e);
|
logger('Parse error: ' . $e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(! $dom) {
|
if(! $dom) {
|
||||||
logger('scrape_feed: failed to parse.');
|
logger('Failed to parse.');
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$head = $dom->getElementsByTagName('base');
|
$head = $dom->getElementsByTagName('base');
|
||||||
if($head) {
|
if($head) {
|
||||||
foreach($head as $head0) {
|
foreach($head as $head0) {
|
||||||
@ -1971,8 +1987,8 @@ function format_and_send_email($sender,$xchan,$item) {
|
|||||||
'$source_link' => $sender['xchan_url'],
|
'$source_link' => $sender['xchan_url'],
|
||||||
'$source_photo' => $sender['xchan_photo_m'],
|
'$source_photo' => $sender['xchan_photo_m'],
|
||||||
'$username' => $xchan['xchan_name'],
|
'$username' => $xchan['xchan_name'],
|
||||||
'$hsitelink' => $datarray['hsitelink'],
|
'$hsitelink' => $datarray['hsitelink'], /// @FIXME $datarray is undefined
|
||||||
'$hitemlink' => $datarray['hitemlink'],
|
'$hitemlink' => $datarray['hitemlink'], /// @FIXME $datarray is undefined
|
||||||
'$thanks' => $thanks,
|
'$thanks' => $thanks,
|
||||||
'$site_admin' => $site_admin,
|
'$site_admin' => $site_admin,
|
||||||
'$title' => $title,
|
'$title' => $title,
|
||||||
@ -2004,6 +2020,7 @@ function format_and_send_email($sender,$xchan,$item) {
|
|||||||
$hostname = App::get_hostname();
|
$hostname = App::get_hostname();
|
||||||
if(strpos($hostname, ':'))
|
if(strpos($hostname, ':'))
|
||||||
$hostname = substr($hostname,0,strpos($hostname,':'));
|
$hostname = substr($hostname,0,strpos($hostname,':'));
|
||||||
|
|
||||||
$sender_email = get_config('system', 'reply_address');
|
$sender_email = get_config('system', 'reply_address');
|
||||||
if(! $sender_email)
|
if(! $sender_email)
|
||||||
$sender_email = 'noreply' . '@' . $hostname;
|
$sender_email = 'noreply' . '@' . $hostname;
|
||||||
@ -2020,7 +2037,6 @@ function format_and_send_email($sender,$xchan,$item) {
|
|||||||
'textVersion' => $email_text_body,
|
'textVersion' => $email_text_body,
|
||||||
'additionalMailHeader' => '',
|
'additionalMailHeader' => '',
|
||||||
));
|
));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2058,8 +2074,6 @@ function do_delivery($deliveries) {
|
|||||||
|
|
||||||
if($deliver)
|
if($deliver)
|
||||||
Zotlabs\Daemon\Master::Summon(array('Deliver',$deliver));
|
Zotlabs\Daemon\Master::Summon(array('Deliver',$deliver));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2133,12 +2147,12 @@ function get_site_info() {
|
|||||||
foreach(App::$config['feature_lock'] as $k => $v) {
|
foreach(App::$config['feature_lock'] as $k => $v) {
|
||||||
if($k === 'config_loaded')
|
if($k === 'config_loaded')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
$locked_features[$k] = intval($v);
|
$locked_features[$k] = intval($v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$data = Array(
|
$data = Array(
|
||||||
'version' => $version,
|
'version' => $version,
|
||||||
'version_tag' => $tag,
|
'version_tag' => $tag,
|
||||||
@ -2166,16 +2180,20 @@ function get_site_info() {
|
|||||||
'local_posts' => $local_posts_stat,
|
'local_posts' => $local_posts_stat,
|
||||||
'hide_in_statistics' => $hide_in_statistics
|
'hide_in_statistics' => $hide_in_statistics
|
||||||
);
|
);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param string $url
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
function check_siteallowed($url) {
|
function check_siteallowed($url) {
|
||||||
|
|
||||||
$retvalue = true;
|
$retvalue = true;
|
||||||
|
|
||||||
|
|
||||||
$arr = array('url' => $url);
|
$arr = array('url' => $url);
|
||||||
call_hooks('check_siteallowed',$arr);
|
call_hooks('check_siteallowed',$arr);
|
||||||
|
|
||||||
@ -2201,9 +2219,16 @@ function check_siteallowed($url) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $retvalue;
|
return $retvalue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param string $hash
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
function check_channelallowed($hash) {
|
function check_channelallowed($hash) {
|
||||||
|
|
||||||
$retvalue = true;
|
$retvalue = true;
|
||||||
@ -2233,6 +2258,7 @@ function check_channelallowed($hash) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $retvalue;
|
return $retvalue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2263,9 +2289,14 @@ function get_repository_version($branch = 'master') {
|
|||||||
return $matches[3];
|
return $matches[3];
|
||||||
}
|
}
|
||||||
return '?.?';
|
return '?.?';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get translated network name.
|
||||||
|
*
|
||||||
|
* @param string $s Network string, see boot.php
|
||||||
|
* @return string Translated name of the network
|
||||||
|
*/
|
||||||
function network_to_name($s) {
|
function network_to_name($s) {
|
||||||
|
|
||||||
$nets = array(
|
$nets = array(
|
||||||
@ -2289,14 +2320,10 @@ function network_to_name($s) {
|
|||||||
$replace = array_values($nets);
|
$replace = array_values($nets);
|
||||||
|
|
||||||
return str_replace($search, $replace, $s);
|
return str_replace($search, $replace, $s);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function z_mail($params) {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Send a text email message
|
* @brief Send a text email message.
|
||||||
*
|
*
|
||||||
* @param array $params an assoziative array with:
|
* @param array $params an assoziative array with:
|
||||||
* * \e string \b fromName name of the sender
|
* * \e string \b fromName name of the sender
|
||||||
@ -2308,6 +2335,7 @@ function z_mail($params) {
|
|||||||
* * \e string \b textVersion text only version of the message
|
* * \e string \b textVersion text only version of the message
|
||||||
* * \e string \b additionalMailHeader additions to the smtp mail header
|
* * \e string \b additionalMailHeader additions to the smtp mail header
|
||||||
*/
|
*/
|
||||||
|
function z_mail($params) {
|
||||||
|
|
||||||
if(! $params['fromEmail']) {
|
if(! $params['fromEmail']) {
|
||||||
$params['fromEmail'] = get_config('system','from_email');
|
$params['fromEmail'] = get_config('system','from_email');
|
||||||
@ -2354,8 +2382,13 @@ function z_mail($params) {
|
|||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// discover the best API path available for redmatrix/hubzilla servers
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Discover the best API path available for redmatrix/hubzilla servers.
|
||||||
|
*
|
||||||
|
* @param string $host
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
function probe_api_path($host) {
|
function probe_api_path($host) {
|
||||||
|
|
||||||
$schemes = ['https', 'http' ];
|
$schemes = ['https', 'http' ];
|
||||||
|
Reference in New Issue
Block a user