commit
cb34f06692
9427
include/api.php
9427
include/api.php
File diff suppressed because it is too large
Load Diff
|
@ -8,7 +8,7 @@
|
|||
* https://github.com/annando/Syncom
|
||||
*/
|
||||
|
||||
require_once("include/xml.php");
|
||||
use Friendica\Util\XML;
|
||||
|
||||
function node2bbcode(&$doc, $oldnode, $attributes, $startbb, $endbb)
|
||||
{
|
||||
|
@ -26,11 +26,12 @@ function node2bbcodesub(&$doc, $oldnode, $attributes, $startbb, $endbb)
|
|||
|
||||
$list = $xpath->query("//".$oldnode);
|
||||
foreach ($list as $oldNode) {
|
||||
|
||||
$attr = array();
|
||||
if ($oldNode->attributes->length)
|
||||
foreach ($oldNode->attributes as $attribute)
|
||||
if ($oldNode->attributes->length) {
|
||||
foreach ($oldNode->attributes as $attribute) {
|
||||
$attr[$attribute->name] = $attribute->value;
|
||||
}
|
||||
}
|
||||
|
||||
$replace = true;
|
||||
|
||||
|
@ -39,23 +40,22 @@ function node2bbcodesub(&$doc, $oldnode, $attributes, $startbb, $endbb)
|
|||
$i = 0;
|
||||
|
||||
foreach ($attributes as $attribute => $value) {
|
||||
|
||||
$startbb = str_replace('\x01'.++$i, '$1', $startbb);
|
||||
|
||||
if (strpos('*'.$startbb, '$1') > 0) {
|
||||
|
||||
if ($replace && (@$attr[$attribute] != '')) {
|
||||
|
||||
$startbb = preg_replace($value, $startbb, $attr[$attribute], -1, $count);
|
||||
|
||||
// If nothing could be changed
|
||||
if ($count == 0)
|
||||
if ($count == 0) {
|
||||
$replace = false;
|
||||
} else
|
||||
}
|
||||
} else {
|
||||
$replace = false;
|
||||
}
|
||||
} else {
|
||||
if (@$attr[$attribute] != $value)
|
||||
if (@$attr[$attribute] != $value) {
|
||||
$replace = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,8 @@ function html2bbcode($message, $basepath = '')
|
|||
|
||||
// Removing code blocks before the whitespace removal processing below
|
||||
$codeblocks = [];
|
||||
$message = preg_replace_callback('#<pre><code(?: class="([^"]*)")?>(.*)</code></pre>#iUs',
|
||||
$message = preg_replace_callback(
|
||||
'#<pre><code(?: class="([^"]*)")?>(.*)</code></pre>#iUs',
|
||||
function ($matches) use (&$codeblocks) {
|
||||
$return = '[codeblock-' . count($codeblocks) . ']';
|
||||
|
||||
|
@ -96,18 +97,21 @@ function html2bbcode($message, $basepath = '')
|
|||
}
|
||||
$codeblocks[] = $prefix . $matches[2] . '[/code]';
|
||||
return $return;
|
||||
}
|
||||
, $message);
|
||||
},
|
||||
$message
|
||||
);
|
||||
|
||||
$message = str_replace(array(
|
||||
"<li><p>",
|
||||
"</p></li>",
|
||||
),
|
||||
array(
|
||||
"<li>",
|
||||
"</li>",
|
||||
),
|
||||
$message);
|
||||
$message = str_replace(
|
||||
array(
|
||||
"<li><p>",
|
||||
"</p></li>",
|
||||
),
|
||||
array(
|
||||
"<li>",
|
||||
"</li>",
|
||||
),
|
||||
$message
|
||||
);
|
||||
|
||||
// remove namespaces
|
||||
$message = preg_replace('=<(\w+):(.+?)>=', '<removeme>', $message);
|
||||
|
@ -120,17 +124,18 @@ function html2bbcode($message, $basepath = '')
|
|||
|
||||
@$doc->loadHTML($message);
|
||||
|
||||
xml::deleteNode($doc, 'style');
|
||||
xml::deleteNode($doc, 'head');
|
||||
xml::deleteNode($doc, 'title');
|
||||
xml::deleteNode($doc, 'meta');
|
||||
xml::deleteNode($doc, 'xml');
|
||||
xml::deleteNode($doc, 'removeme');
|
||||
XML::deleteNode($doc, 'style');
|
||||
XML::deleteNode($doc, 'head');
|
||||
XML::deleteNode($doc, 'title');
|
||||
XML::deleteNode($doc, 'meta');
|
||||
XML::deleteNode($doc, 'xml');
|
||||
XML::deleteNode($doc, 'removeme');
|
||||
|
||||
$xpath = new DomXPath($doc);
|
||||
$list = $xpath->query("//pre");
|
||||
foreach ($list as $node)
|
||||
foreach ($list as $node) {
|
||||
$node->nodeValue = str_replace("\n", "\r", $node->nodeValue);
|
||||
}
|
||||
|
||||
$message = $doc->saveHTML();
|
||||
$message = str_replace(array("\n<", ">\n", "\r", "\n", "\xC3\x82\xC2\xA0"), array("<", ">", "<br />", " ", ""), $message);
|
||||
|
@ -158,7 +163,7 @@ function html2bbcode($message, $basepath = '')
|
|||
node2bbcode($doc, 'font', array('face'=>'/([\w ]+)/'), '[font=$1]', '[/font]');
|
||||
node2bbcode($doc, 'font', array('size'=>'/(\d+)/'), '[size=$1]', '[/size]');
|
||||
node2bbcode($doc, 'font', array('color'=>'/(.+)/'), '[color=$1]', '[/color]');
|
||||
*/
|
||||
*/
|
||||
// Untested
|
||||
//node2bbcode($doc, 'span', array('style'=>'/.*font-size:\s*(.+?)[,;].*font-family:\s*(.+?)[,;].*color:\s*(.+?)[,;].*/'), '[size=$1][font=$2][color=$3]', '[/color][/font][/size]');
|
||||
//node2bbcode($doc, 'span', array('style'=>'/.*font-size:\s*(\d+)[,;].*/'), '[size=$1]', '[/size]');
|
||||
|
@ -281,45 +286,52 @@ function html2bbcode($message, $basepath = '')
|
|||
|
||||
do {
|
||||
$oldmessage = $message;
|
||||
$message = str_replace(array(
|
||||
"[/size]\n\n",
|
||||
"\n[hr]",
|
||||
"[hr]\n",
|
||||
"\n[list",
|
||||
"[/list]\n",
|
||||
"\n[/",
|
||||
"[list]\n",
|
||||
"[list=1]\n",
|
||||
"\n[*]"),
|
||||
array(
|
||||
"[/size]\n",
|
||||
"[hr]",
|
||||
"[hr]",
|
||||
"[list",
|
||||
"[/list]",
|
||||
"[/",
|
||||
"[list]",
|
||||
"[list=1]",
|
||||
"[*]"),
|
||||
$message);
|
||||
$message = str_replace(
|
||||
array(
|
||||
"[/size]\n\n",
|
||||
"\n[hr]",
|
||||
"[hr]\n",
|
||||
"\n[list",
|
||||
"[/list]\n",
|
||||
"\n[/",
|
||||
"[list]\n",
|
||||
"[list=1]\n",
|
||||
"\n[*]"),
|
||||
array(
|
||||
"[/size]\n",
|
||||
"[hr]",
|
||||
"[hr]",
|
||||
"[list",
|
||||
"[/list]",
|
||||
"[/",
|
||||
"[list]",
|
||||
"[list=1]",
|
||||
"[*]"),
|
||||
$message
|
||||
);
|
||||
} while ($message != $oldmessage);
|
||||
|
||||
$message = str_replace(array('[b][b]', '[/b][/b]', '[i][i]', '[/i][/i]'),
|
||||
array('[b]', '[/b]', '[i]', '[/i]'), $message);
|
||||
$message = str_replace(
|
||||
array('[b][b]', '[/b][/b]', '[i][i]', '[/i][/i]'),
|
||||
array('[b]', '[/b]', '[i]', '[/i]'),
|
||||
$message
|
||||
);
|
||||
|
||||
// Handling Yahoo style of mails
|
||||
$message = str_replace('[hr][b]From:[/b]', '[quote][b]From:[/b]', $message);
|
||||
|
||||
// Restore code blocks
|
||||
$message = preg_replace_callback('#\[codeblock-([0-9]+)\]#iU',
|
||||
$message = preg_replace_callback(
|
||||
'#\[codeblock-([0-9]+)\]#iU',
|
||||
function ($matches) use ($codeblocks) {
|
||||
$return = '';
|
||||
if (isset($codeblocks[intval($matches[1])])) {
|
||||
$return = $codeblocks[$matches[1]];
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
, $message);
|
||||
},
|
||||
$message
|
||||
);
|
||||
|
||||
$message = trim($message);
|
||||
|
||||
|
@ -333,12 +345,13 @@ function html2bbcode($message, $basepath = '')
|
|||
/**
|
||||
* @brief Sub function to complete incomplete URL
|
||||
*
|
||||
* @param array $matches Result of preg_replace_callback
|
||||
* @param array $matches Result of preg_replace_callback
|
||||
* @param string $basepath Basepath that is used to complete the URL
|
||||
*
|
||||
* @return string The expanded URL
|
||||
*/
|
||||
function addHostnameSub($matches, $basepath) {
|
||||
function addHostnameSub($matches, $basepath)
|
||||
{
|
||||
$base = parse_url($basepath);
|
||||
unset($base['query']);
|
||||
unset($base['fragment']);
|
||||
|
@ -355,12 +368,13 @@ function addHostnameSub($matches, $basepath) {
|
|||
/**
|
||||
* @brief Complete incomplete URLs in BBCode
|
||||
*
|
||||
* @param string $body Body with URLs
|
||||
* @param string $body Body with URLs
|
||||
* @param string $basepath Basepath that is used to complete the URL
|
||||
*
|
||||
* @return string Body with expanded URLs
|
||||
*/
|
||||
function addHostname($body, $basepath) {
|
||||
function addHostname($body, $basepath)
|
||||
{
|
||||
$URLSearchString = "^\[\]";
|
||||
|
||||
$matches = array("/\[url\=([$URLSearchString]*)\].*?\[\/url\]/ism",
|
||||
|
@ -373,11 +387,14 @@ function addHostname($body, $basepath) {
|
|||
"/\[audio\](.*?)\[\/audio\]/ism",
|
||||
);
|
||||
|
||||
foreach ($matches AS $match) {
|
||||
$body = preg_replace_callback($match,
|
||||
function ($match) use ($basepath) {
|
||||
return addHostnameSub($match, $basepath);
|
||||
}, $body);
|
||||
foreach ($matches as $match) {
|
||||
$body = preg_replace_callback(
|
||||
$match,
|
||||
function ($match) use ($basepath) {
|
||||
return addHostnameSub($match, $basepath);
|
||||
},
|
||||
$body
|
||||
);
|
||||
}
|
||||
return $body;
|
||||
}
|
||||
|
|
|
@ -8,8 +8,7 @@ use Friendica\App;
|
|||
use Friendica\Core\System;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Network\Probe;
|
||||
|
||||
require_once("include/xml.php");
|
||||
use Friendica\Util\XML;
|
||||
|
||||
/**
|
||||
* @brief Curl wrapper
|
||||
|
@ -18,18 +17,18 @@ require_once("include/xml.php");
|
|||
* Set the cookiejar argument to a string (e.g. "/tmp/friendica-cookies.txt")
|
||||
* to preserve cookies from one request to the next.
|
||||
*
|
||||
* @param string $url URL to fetch
|
||||
* @param boolean $binary default false
|
||||
* TRUE if asked to return binary results (file download)
|
||||
* @param integer $redirects The recursion counter for internal use - default 0
|
||||
* @param integer $timeout Timeout in seconds, default system config value or 60 seconds
|
||||
* @param string $accept_content supply Accept: header with 'accept_content' as the value
|
||||
* @param string $cookiejar Path to cookie jar file
|
||||
* @param string $url URL to fetch
|
||||
* @param boolean $binary default false
|
||||
* TRUE if asked to return binary results (file download)
|
||||
* @param integer $redirects The recursion counter for internal use - default 0
|
||||
* @param integer $timeout Timeout in seconds, default system config value or 60 seconds
|
||||
* @param string $accept_content supply Accept: header with 'accept_content' as the value
|
||||
* @param string $cookiejar Path to cookie jar file
|
||||
*
|
||||
* @return string The fetched content
|
||||
*/
|
||||
function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_content=Null, $cookiejar = 0) {
|
||||
|
||||
function fetch_url($url, $binary = false, &$redirects = 0, $timeout = 0, $accept_content = null, $cookiejar = 0)
|
||||
{
|
||||
$ret = z_fetch_url(
|
||||
$url,
|
||||
$binary,
|
||||
|
@ -37,7 +36,8 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
|
|||
array('timeout'=>$timeout,
|
||||
'accept_content'=>$accept_content,
|
||||
'cookiejar'=>$cookiejar
|
||||
));
|
||||
)
|
||||
);
|
||||
|
||||
return($ret['body']);
|
||||
}
|
||||
|
@ -45,17 +45,17 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
|
|||
/**
|
||||
* @brief fetches an URL.
|
||||
*
|
||||
* @param string $url URL to fetch
|
||||
* @param boolean $binary default false
|
||||
* TRUE if asked to return binary results (file download)
|
||||
* @param int $redirects The recursion counter for internal use - default 0
|
||||
* @param array $opts (optional parameters) assoziative array with:
|
||||
* 'accept_content' => supply Accept: header with 'accept_content' as the value
|
||||
* 'timeout' => int Timeout in seconds, default system config value or 60 seconds
|
||||
* 'http_auth' => username:password
|
||||
* 'novalidate' => do not validate SSL certs, default is to validate using our CA list
|
||||
* 'nobody' => only return the header
|
||||
* 'cookiejar' => path to cookie jar file
|
||||
* @param string $url URL to fetch
|
||||
* @param boolean $binary default false
|
||||
* TRUE if asked to return binary results (file download)
|
||||
* @param int $redirects The recursion counter for internal use - default 0
|
||||
* @param array $opts (optional parameters) assoziative array with:
|
||||
* 'accept_content' => supply Accept: header with 'accept_content' as the value
|
||||
* 'timeout' => int Timeout in seconds, default system config value or 60 seconds
|
||||
* 'http_auth' => username:password
|
||||
* 'novalidate' => do not validate SSL certs, default is to validate using our CA list
|
||||
* 'nobody' => only return the header
|
||||
* 'cookiejar' => path to cookie jar file
|
||||
*
|
||||
* @return array an assoziative array with:
|
||||
* int 'return_code' => HTTP return code or 0 if timeout or failure
|
||||
|
@ -64,7 +64,8 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
|
|||
* string 'header' => HTTP headers
|
||||
* string 'body' => fetched content
|
||||
*/
|
||||
function z_fetch_url($url, $binary = false, &$redirects = 0, $opts = array()) {
|
||||
function z_fetch_url($url, $binary = false, &$redirects = 0, $opts = array())
|
||||
{
|
||||
$ret = array('return_code' => 0, 'success' => false, 'header' => '', 'info' => '', 'body' => '');
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
|
@ -89,14 +90,16 @@ function z_fetch_url($url, $binary = false, &$redirects = 0, $opts = array()) {
|
|||
curl_setopt($ch, CURLOPT_COOKIEFILE, $opts["cookiejar"]);
|
||||
}
|
||||
|
||||
// These settings aren't needed. We're following the location already.
|
||||
// @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
// @curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
|
||||
// These settings aren't needed. We're following the location already.
|
||||
// @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
// @curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
|
||||
|
||||
if (x($opts, 'accept_content')) {
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||
'Accept: ' . $opts['accept_content']
|
||||
));
|
||||
curl_setopt(
|
||||
$ch,
|
||||
CURLOPT_HTTPHEADER,
|
||||
array('Accept: ' . $opts['accept_content'])
|
||||
);
|
||||
}
|
||||
|
||||
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
@ -192,7 +195,7 @@ function z_fetch_url($url, $binary = false, &$redirects = 0, $opts = array()) {
|
|||
// allow for HTTP/2.x without fixing code
|
||||
|
||||
while (preg_match('/^HTTP\/[1-2].+? [1-5][0-9][0-9]/', $base)) {
|
||||
$chunk = substr($base, 0, strpos($base,"\r\n\r\n") + 4);
|
||||
$chunk = substr($base, 0, strpos($base, "\r\n\r\n") + 4);
|
||||
$header .= $chunk;
|
||||
$base = substr($base, strlen($chunk));
|
||||
}
|
||||
|
@ -216,7 +219,7 @@ function z_fetch_url($url, $binary = false, &$redirects = 0, $opts = array()) {
|
|||
if (preg_match('/(Location:|URI:)(.*?)\n/i', $header, $matches)) {
|
||||
$newurl = trim(array_pop($matches));
|
||||
}
|
||||
if (strpos($newurl,'/') === 0) {
|
||||
if (strpos($newurl, '/') === 0) {
|
||||
$newurl = $old_location_info["scheme"]."://".$old_location_info["host"].$newurl;
|
||||
}
|
||||
|
||||
|
@ -261,15 +264,16 @@ function z_fetch_url($url, $binary = false, &$redirects = 0, $opts = array()) {
|
|||
/**
|
||||
* @brief Send POST request to $url
|
||||
*
|
||||
* @param string $url URL to post
|
||||
* @param mixed $params array of POST variables
|
||||
* @param string $headers HTTP headers
|
||||
* @param string $url URL to post
|
||||
* @param mixed $params array of POST variables
|
||||
* @param string $headers HTTP headers
|
||||
* @param integer $redirects Recursion counter for internal use - default = 0
|
||||
* @param integer $timeout The timeout in seconds, default system config value or 60 seconds
|
||||
* @param integer $timeout The timeout in seconds, default system config value or 60 seconds
|
||||
*
|
||||
* @return string The content
|
||||
*/
|
||||
function post_url($url, $params, $headers = null, &$redirects = 0, $timeout = 0) {
|
||||
function post_url($url, $params, $headers = null, &$redirects = 0, $timeout = 0)
|
||||
{
|
||||
$stamp1 = microtime(true);
|
||||
|
||||
if (blocked_url($url)) {
|
||||
|
@ -394,8 +398,8 @@ function post_url($url, $params, $headers = null, &$redirects = 0, $timeout = 0)
|
|||
// 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.
|
||||
|
||||
function xml_status($st, $message = '') {
|
||||
|
||||
function xml_status($st, $message = '')
|
||||
{
|
||||
$result = array('status' => $st);
|
||||
|
||||
if ($message != '') {
|
||||
|
@ -410,7 +414,7 @@ function xml_status($st, $message = '') {
|
|||
|
||||
$xmldata = array("result" => $result);
|
||||
|
||||
echo xml::from_array($xmldata, $xml);
|
||||
echo XML::from_array($xmldata, $xml);
|
||||
|
||||
killme();
|
||||
}
|
||||
|
@ -427,17 +431,19 @@ function xml_status($st, $message = '') {
|
|||
/**
|
||||
* @brief Send HTTP status header and exit.
|
||||
*
|
||||
* @param integer $val HTTP status result value
|
||||
* @param array $description optional message
|
||||
* 'title' => header title
|
||||
* 'description' => optional message
|
||||
* @param integer $val HTTP status result value
|
||||
* @param array $description optional message
|
||||
* 'title' => header title
|
||||
* 'description' => optional message
|
||||
*/
|
||||
function http_status_exit($val, $description = array()) {
|
||||
function http_status_exit($val, $description = array())
|
||||
{
|
||||
$err = '';
|
||||
if ($val >= 400) {
|
||||
$err = 'Error';
|
||||
if (!isset($description["title"]))
|
||||
if (!isset($description["title"])) {
|
||||
$description["title"] = $err." ".$val;
|
||||
}
|
||||
}
|
||||
if ($val >= 200 && $val < 300)
|
||||
$err = 'OK';
|
||||
|
@ -447,12 +453,15 @@ function http_status_exit($val, $description = array()) {
|
|||
|
||||
if (isset($description["title"])) {
|
||||
$tpl = get_markup_template('http_status.tpl');
|
||||
echo replace_macros($tpl, array('$title' => $description["title"],
|
||||
'$description' => $description["description"]));
|
||||
echo replace_macros(
|
||||
$tpl,
|
||||
array(
|
||||
'$title' => $description["title"],
|
||||
'$description' => $description["description"])
|
||||
);
|
||||
}
|
||||
|
||||
killme();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -464,15 +473,17 @@ function http_status_exit($val, $description = array()) {
|
|||
* @param string $url The URL to be validated
|
||||
* @return boolean True if it's a valid URL, fals if something wrong with it
|
||||
*/
|
||||
function validate_url(&$url) {
|
||||
if (Config::get('system','disable_url_validation'))
|
||||
function validate_url(&$url)
|
||||
{
|
||||
if (Config::get('system', 'disable_url_validation')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
if (substr($url,0,4) != 'http')
|
||||
if (substr($url, 0, 4) != 'http')
|
||||
$url = 'http://' . $url;
|
||||
|
||||
/// @TODO Really supress function outcomes? Why not find them + debug them?
|
||||
|
@ -491,14 +502,17 @@ function validate_url(&$url) {
|
|||
* @param string $addr The email address
|
||||
* @return boolean True if it's a valid email address, false if it's not
|
||||
*/
|
||||
function validate_email($addr) {
|
||||
|
||||
if (Config::get('system','disable_email_validation'))
|
||||
function validate_email($addr)
|
||||
{
|
||||
if (Config::get('system', 'disable_email_validation')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (! strpos($addr,'@'))
|
||||
if (! strpos($addr, '@')) {
|
||||
return false;
|
||||
$h = substr($addr,strpos($addr,'@') + 1);
|
||||
}
|
||||
|
||||
$h = substr($addr, strpos($addr, '@') + 1);
|
||||
|
||||
if (($h) && (dns_get_record($h, DNS_A + DNS_CNAME + DNS_PTR + DNS_MX) || filter_var($h, FILTER_VALIDATE_IP) )) {
|
||||
return true;
|
||||
|
@ -515,8 +529,8 @@ function validate_email($addr) {
|
|||
* @param string $url URL which get tested
|
||||
* @return boolean True if url is allowed otherwise return false
|
||||
*/
|
||||
function allowed_url($url) {
|
||||
|
||||
function allowed_url($url)
|
||||
{
|
||||
$h = @parse_url($url);
|
||||
|
||||
if (! $h) {
|
||||
|
@ -557,9 +571,11 @@ function allowed_url($url) {
|
|||
* Returns true if it is or malformed URL, false if not.
|
||||
*
|
||||
* @param string $url The url to check the domain from
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function blocked_url($url) {
|
||||
function blocked_url($url)
|
||||
{
|
||||
$h = @parse_url($url);
|
||||
|
||||
if (! $h) {
|
||||
|
@ -587,18 +603,18 @@ function blocked_url($url) {
|
|||
*
|
||||
* Compare against our list (wildcards allowed).
|
||||
*
|
||||
* @param type $email
|
||||
* @param string $email email address
|
||||
* @return boolean False if not allowed, true if allowed
|
||||
* or if allowed list is not configured
|
||||
*/
|
||||
function allowed_email($email) {
|
||||
|
||||
$domain = strtolower(substr($email,strpos($email,'@') + 1));
|
||||
function allowed_email($email)
|
||||
{
|
||||
$domain = strtolower(substr($email, strpos($email, '@') + 1));
|
||||
if (! $domain) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$str_allowed = Config::get('system','allowed_email');
|
||||
$str_allowed = Config::get('system', 'allowed_email');
|
||||
if (! $str_allowed) {
|
||||
return true;
|
||||
}
|
||||
|
@ -606,12 +622,12 @@ function allowed_email($email) {
|
|||
$found = false;
|
||||
|
||||
$fnmatch = function_exists('fnmatch');
|
||||
$allowed = explode(',',$str_allowed);
|
||||
$allowed = explode(',', $str_allowed);
|
||||
|
||||
if (count($allowed)) {
|
||||
foreach ($allowed as $a) {
|
||||
$pat = strtolower(trim($a));
|
||||
if (($fnmatch && fnmatch($pat,$domain)) || ($pat == $domain)) {
|
||||
if (($fnmatch && fnmatch($pat, $domain)) || ($pat == $domain)) {
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
|
@ -620,8 +636,8 @@ function allowed_email($email) {
|
|||
return $found;
|
||||
}
|
||||
|
||||
function avatar_img($email) {
|
||||
|
||||
function avatar_img($email)
|
||||
{
|
||||
$avatar['size'] = 175;
|
||||
$avatar['email'] = $email;
|
||||
$avatar['url'] = '';
|
||||
|
@ -638,7 +654,8 @@ function avatar_img($email) {
|
|||
}
|
||||
|
||||
|
||||
function parse_xml_string($s, $strict = true) {
|
||||
function parse_xml_string($s, $strict = true)
|
||||
{
|
||||
// the "strict" parameter is deactivated
|
||||
|
||||
/// @todo Move this function to the xml class
|
||||
|
@ -655,10 +672,10 @@ function parse_xml_string($s, $strict = true) {
|
|||
return $x;
|
||||
}
|
||||
|
||||
function scale_external_images($srctext, $include_link = true, $scale_replace = false) {
|
||||
|
||||
function scale_external_images($srctext, $include_link = true, $scale_replace = false)
|
||||
{
|
||||
// Suppress "view full size"
|
||||
if (intval(Config::get('system','no_view_full_size'))) {
|
||||
if (intval(Config::get('system', 'no_view_full_size'))) {
|
||||
$include_link = false;
|
||||
}
|
||||
|
||||
|
@ -668,14 +685,14 @@ function scale_external_images($srctext, $include_link = true, $scale_replace =
|
|||
$s = htmlspecialchars_decode($srctext);
|
||||
|
||||
$matches = null;
|
||||
$c = preg_match_all('/\[img.*?\](.*?)\[\/img\]/ism',$s,$matches,PREG_SET_ORDER);
|
||||
$c = preg_match_all('/\[img.*?\](.*?)\[\/img\]/ism', $s, $matches, PREG_SET_ORDER);
|
||||
if ($c) {
|
||||
require_once('include/Photo.php');
|
||||
require_once 'include/Photo.php';
|
||||
foreach ($matches as $mtch) {
|
||||
logger('scale_external_image: ' . $mtch[1]);
|
||||
|
||||
$hostname = str_replace('www.','',substr(System::baseUrl(),strpos(System::baseUrl(),'://')+3));
|
||||
if (stristr($mtch[1],$hostname)) {
|
||||
$hostname = str_replace('www.', '', substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3));
|
||||
if (stristr($mtch[1], $hostname)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -695,7 +712,7 @@ function scale_external_images($srctext, $include_link = true, $scale_replace =
|
|||
}
|
||||
|
||||
// guess mimetype from headers or filename
|
||||
$type = guess_image_type($mtch[1],true);
|
||||
$type = guess_image_type($mtch[1], true);
|
||||
|
||||
if ($i) {
|
||||
$ph = new Photo($i, $type);
|
||||
|
@ -704,15 +721,18 @@ function scale_external_images($srctext, $include_link = true, $scale_replace =
|
|||
$orig_height = $ph->getHeight();
|
||||
|
||||
if ($orig_width > 640 || $orig_height > 640) {
|
||||
|
||||
$ph->scaleImage(640);
|
||||
$new_width = $ph->getWidth();
|
||||
$new_height = $ph->getHeight();
|
||||
logger('scale_external_images: ' . $orig_width . '->' . $new_width . 'w ' . $orig_height . '->' . $new_height . 'h' . ' match: ' . $mtch[0], LOGGER_DEBUG);
|
||||
$s = str_replace($mtch[0],'[img=' . $new_width . 'x' . $new_height. ']' . $scaled . '[/img]'
|
||||
$s = str_replace(
|
||||
$mtch[0],
|
||||
'[img=' . $new_width . 'x' . $new_height. ']' . $scaled . '[/img]'
|
||||
. "\n" . (($include_link)
|
||||
? '[url=' . $mtch[1] . ']' . t('view full size') . '[/url]' . "\n"
|
||||
: ''),$s);
|
||||
: ''),
|
||||
$s
|
||||
);
|
||||
logger('scale_external_images: new string: ' . $s, LOGGER_DEBUG);
|
||||
}
|
||||
}
|
||||
|
@ -721,32 +741,32 @@ function scale_external_images($srctext, $include_link = true, $scale_replace =
|
|||
}
|
||||
|
||||
// replace the special char encoding
|
||||
$s = htmlspecialchars($s,ENT_NOQUOTES,'UTF-8');
|
||||
$s = htmlspecialchars($s, ENT_NOQUOTES, 'UTF-8');
|
||||
return $s;
|
||||
}
|
||||
|
||||
|
||||
function fix_contact_ssl_policy(&$contact,$new_policy) {
|
||||
|
||||
function fix_contact_ssl_policy(&$contact, $new_policy)
|
||||
{
|
||||
$ssl_changed = false;
|
||||
if ((intval($new_policy) == SSL_POLICY_SELFSIGN || $new_policy === 'self') && strstr($contact['url'],'https:')) {
|
||||
if ((intval($new_policy) == SSL_POLICY_SELFSIGN || $new_policy === 'self') && strstr($contact['url'], 'https:')) {
|
||||
$ssl_changed = true;
|
||||
$contact['url'] = str_replace('https:','http:',$contact['url']);
|
||||
$contact['request'] = str_replace('https:','http:',$contact['request']);
|
||||
$contact['notify'] = str_replace('https:','http:',$contact['notify']);
|
||||
$contact['poll'] = str_replace('https:','http:',$contact['poll']);
|
||||
$contact['confirm'] = str_replace('https:','http:',$contact['confirm']);
|
||||
$contact['poco'] = str_replace('https:','http:',$contact['poco']);
|
||||
$contact['url'] = str_replace('https:', 'http:', $contact['url']);
|
||||
$contact['request'] = str_replace('https:', 'http:', $contact['request']);
|
||||
$contact['notify'] = str_replace('https:', 'http:', $contact['notify']);
|
||||
$contact['poll'] = str_replace('https:', 'http:', $contact['poll']);
|
||||
$contact['confirm'] = str_replace('https:', 'http:', $contact['confirm']);
|
||||
$contact['poco'] = str_replace('https:', 'http:', $contact['poco']);
|
||||
}
|
||||
|
||||
if ((intval($new_policy) == SSL_POLICY_FULL || $new_policy === 'full') && strstr($contact['url'],'http:')) {
|
||||
if ((intval($new_policy) == SSL_POLICY_FULL || $new_policy === 'full') && strstr($contact['url'], 'http:')) {
|
||||
$ssl_changed = true;
|
||||
$contact['url'] = str_replace('http:','https:',$contact['url']);
|
||||
$contact['request'] = str_replace('http:','https:',$contact['request']);
|
||||
$contact['notify'] = str_replace('http:','https:',$contact['notify']);
|
||||
$contact['poll'] = str_replace('http:','https:',$contact['poll']);
|
||||
$contact['confirm'] = str_replace('http:','https:',$contact['confirm']);
|
||||
$contact['poco'] = str_replace('http:','https:',$contact['poco']);
|
||||
$contact['url'] = str_replace('http:', 'https:', $contact['url']);
|
||||
$contact['request'] = str_replace('http:', 'https:', $contact['request']);
|
||||
$contact['notify'] = str_replace('http:', 'https:', $contact['notify']);
|
||||
$contact['poll'] = str_replace('http:', 'https:', $contact['poll']);
|
||||
$contact['confirm'] = str_replace('http:', 'https:', $contact['confirm']);
|
||||
$contact['poco'] = str_replace('http:', 'https:', $contact['poco']);
|
||||
}
|
||||
|
||||
if ($ssl_changed) {
|
||||
|
@ -771,13 +791,17 @@ function strip_tracking_query_params($url)
|
|||
parse_str($query, $querydata);
|
||||
|
||||
if (is_array($querydata)) {
|
||||
foreach ($querydata AS $param => $value) {
|
||||
if (in_array($param, array("utm_source", "utm_medium", "utm_term", "utm_content", "utm_campaign",
|
||||
"wt_mc", "pk_campaign", "pk_kwd", "mc_cid", "mc_eid",
|
||||
"fb_action_ids", "fb_action_types", "fb_ref",
|
||||
"awesm", "wtrid",
|
||||
"woo_campaign", "woo_source", "woo_medium", "woo_content", "woo_term"))) {
|
||||
|
||||
foreach ($querydata as $param => $value) {
|
||||
if (in_array(
|
||||
$param,
|
||||
array(
|
||||
"utm_source", "utm_medium", "utm_term", "utm_content", "utm_campaign",
|
||||
"wt_mc", "pk_campaign", "pk_kwd", "mc_cid", "mc_eid",
|
||||
"fb_action_ids", "fb_action_types", "fb_ref",
|
||||
"awesm", "wtrid",
|
||||
"woo_campaign", "woo_source", "woo_medium", "woo_content", "woo_term")
|
||||
)
|
||||
) {
|
||||
$pair = $param . "=" . urlencode($value);
|
||||
$url = str_replace($pair, "", $url);
|
||||
|
||||
|
@ -812,18 +836,20 @@ function strip_tracking_query_params($url)
|
|||
*
|
||||
* @see ParseUrl::getSiteinfo
|
||||
*
|
||||
* @param string $url A user-submitted URL
|
||||
* @param int $depth The current redirection recursion level (internal)
|
||||
* @param bool $fetchbody Wether to fetch the body or not after the HEAD requests
|
||||
* @param string $url A user-submitted URL
|
||||
* @param int $depth The current redirection recursion level (internal)
|
||||
* @param bool $fetchbody Wether to fetch the body or not after the HEAD requests
|
||||
* @return string A canonical URL
|
||||
*/
|
||||
function original_url($url, $depth = 1, $fetchbody = false) {
|
||||
function original_url($url, $depth = 1, $fetchbody = false)
|
||||
{
|
||||
$a = get_app();
|
||||
|
||||
$url = strip_tracking_query_params($url);
|
||||
|
||||
if ($depth > 10)
|
||||
if ($depth > 10) {
|
||||
return($url);
|
||||
}
|
||||
|
||||
$url = trim($url, "'");
|
||||
|
||||
|
@ -849,24 +875,29 @@ function original_url($url, $depth = 1, $fetchbody = false) {
|
|||
return($url);
|
||||
|
||||
if ((($curl_info['http_code'] == "301") || ($curl_info['http_code'] == "302"))
|
||||
&& (($curl_info['redirect_url'] != "") || ($curl_info['location'] != ""))) {
|
||||
if ($curl_info['redirect_url'] != "")
|
||||
&& (($curl_info['redirect_url'] != "") || ($curl_info['location'] != ""))
|
||||
) {
|
||||
if ($curl_info['redirect_url'] != "") {
|
||||
return(original_url($curl_info['redirect_url'], ++$depth, $fetchbody));
|
||||
else
|
||||
} else {
|
||||
return(original_url($curl_info['location'], ++$depth, $fetchbody));
|
||||
}
|
||||
}
|
||||
|
||||
// Check for redirects in the meta elements of the body if there are no redirects in the header.
|
||||
if (!$fetchbody)
|
||||
if (!$fetchbody) {
|
||||
return(original_url($url, ++$depth, true));
|
||||
}
|
||||
|
||||
// if the file is too large then exit
|
||||
if ($curl_info["download_content_length"] > 1000000)
|
||||
if ($curl_info["download_content_length"] > 1000000) {
|
||||
return($url);
|
||||
}
|
||||
|
||||
// if it isn't a HTML file then exit
|
||||
if (($curl_info["content_type"] != "") && !strstr(strtolower($curl_info["content_type"]),"html"))
|
||||
if (($curl_info["content_type"] != "") && !strstr(strtolower($curl_info["content_type"]), "html")) {
|
||||
return($url);
|
||||
}
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
|
||||
|
@ -883,8 +914,9 @@ function original_url($url, $depth = 1, $fetchbody = false) {
|
|||
|
||||
$a->save_timestamp($stamp1, "network");
|
||||
|
||||
if (trim($body) == "")
|
||||
if (trim($body) == "") {
|
||||
return($url);
|
||||
}
|
||||
|
||||
// Check for redirect in meta elements
|
||||
$doc = new DOMDocument();
|
||||
|
@ -895,29 +927,34 @@ function original_url($url, $depth = 1, $fetchbody = false) {
|
|||
$list = $xpath->query("//meta[@content]");
|
||||
foreach ($list as $node) {
|
||||
$attr = array();
|
||||
if ($node->attributes->length)
|
||||
foreach ($node->attributes as $attribute)
|
||||
if ($node->attributes->length) {
|
||||
foreach ($node->attributes as $attribute) {
|
||||
$attr[$attribute->name] = $attribute->value;
|
||||
}
|
||||
}
|
||||
|
||||
if (@$attr["http-equiv"] == 'refresh') {
|
||||
$path = $attr["content"];
|
||||
$pathinfo = explode(";", $path);
|
||||
$content = "";
|
||||
foreach ($pathinfo AS $value)
|
||||
if (substr(strtolower($value), 0, 4) == "url=")
|
||||
foreach ($pathinfo as $value) {
|
||||
if (substr(strtolower($value), 0, 4) == "url=") {
|
||||
return(original_url(substr($value, 4), ++$depth));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return($url);
|
||||
}
|
||||
|
||||
function short_link($url) {
|
||||
require_once('library/slinky.php');
|
||||
function short_link($url)
|
||||
{
|
||||
require_once 'library/slinky.php';
|
||||
$slinky = new Slinky($url);
|
||||
$yourls_url = Config::get('yourls','url1');
|
||||
$yourls_url = Config::get('yourls', 'url1');
|
||||
if ($yourls_url) {
|
||||
$yourls_username = Config::get('yourls','username1');
|
||||
$yourls_username = Config::get('yourls', 'username1');
|
||||
$yourls_password = Config::get('yourls', 'password1');
|
||||
$yourls_ssl = Config::get('yourls', 'ssl1');
|
||||
$yourls = new Slinky_YourLS();
|
||||
|
@ -944,7 +981,8 @@ function short_link($url) {
|
|||
*
|
||||
* @param array $x The input content
|
||||
*/
|
||||
function json_return_and_die($x) {
|
||||
function json_return_and_die($x)
|
||||
{
|
||||
header("content-type: application/json");
|
||||
echo json_encode($x);
|
||||
killme();
|
||||
|
@ -957,10 +995,11 @@ function json_return_and_die($x) {
|
|||
* @param string $url2
|
||||
* @return string The matching part
|
||||
*/
|
||||
function matching_url($url1, $url2) {
|
||||
|
||||
if (($url1 == "") || ($url2 == ""))
|
||||
function matching_url($url1, $url2)
|
||||
{
|
||||
if (($url1 == "") || ($url2 == "")) {
|
||||
return "";
|
||||
}
|
||||
|
||||
$url1 = normalise_link($url1);
|
||||
$url2 = normalise_link($url2);
|
||||
|
@ -968,22 +1007,27 @@ function matching_url($url1, $url2) {
|
|||
$parts1 = parse_url($url1);
|
||||
$parts2 = parse_url($url2);
|
||||
|
||||
if (!isset($parts1["host"]) || !isset($parts2["host"]))
|
||||
if (!isset($parts1["host"]) || !isset($parts2["host"])) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if ($parts1["scheme"] != $parts2["scheme"])
|
||||
if ($parts1["scheme"] != $parts2["scheme"]) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if ($parts1["host"] != $parts2["host"])
|
||||
if ($parts1["host"] != $parts2["host"]) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if ($parts1["port"] != $parts2["port"])
|
||||
if ($parts1["port"] != $parts2["port"]) {
|
||||
return "";
|
||||
}
|
||||
|
||||
$match = $parts1["scheme"]."://".$parts1["host"];
|
||||
|
||||
if ($parts1["port"])
|
||||
if ($parts1["port"]) {
|
||||
$match .= ":".$parts1["port"];
|
||||
}
|
||||
|
||||
$pathparts1 = explode("/", $parts1["path"]);
|
||||
$pathparts2 = explode("/", $parts2["path"]);
|
||||
|
@ -994,9 +1038,9 @@ function matching_url($url1, $url2) {
|
|||
$path1 = $pathparts1[$i];
|
||||
$path2 = $pathparts2[$i];
|
||||
|
||||
if ($path1 == $path2)
|
||||
if ($path1 == $path2) {
|
||||
$path .= $path1."/";
|
||||
|
||||
}
|
||||
} while (($path1 == $path2) && ($i++ <= count($pathparts1)));
|
||||
|
||||
$match .= $path;
|
||||
|
@ -1011,7 +1055,8 @@ function matching_url($url1, $url2) {
|
|||
*
|
||||
* @return string The glued URL
|
||||
*/
|
||||
function unParseUrl($parsed) {
|
||||
function unParseUrl($parsed)
|
||||
{
|
||||
$get = function ($key) use ($parsed) {
|
||||
return isset($parsed[$key]) ? $parsed[$key] : null;
|
||||
};
|
||||
|
@ -1023,10 +1068,9 @@ function unParseUrl($parsed) {
|
|||
$scheme = $get('scheme');
|
||||
$query = $get('query');
|
||||
$fragment = $get('fragment');
|
||||
$authority =
|
||||
($userinfo !== null ? $userinfo."@" : '') .
|
||||
$get('host') .
|
||||
($port ? ":$port" : '');
|
||||
$authority = ($userinfo !== null ? $userinfo."@" : '') .
|
||||
$get('host') .
|
||||
($port ? ":$port" : '');
|
||||
|
||||
return (strlen($scheme) ? $scheme.":" : '') .
|
||||
(strlen($authority) ? "//".$authority : '') .
|
||||
|
|
|
@ -10,6 +10,7 @@ use Friendica\Core\Config;
|
|||
use Friendica\Database\DBM;
|
||||
use Friendica\Network\Probe;
|
||||
use Friendica\Util\Lock;
|
||||
use Friendica\Util\XML;
|
||||
|
||||
require_once 'include/Contact.php';
|
||||
require_once 'include/threads.php';
|
||||
|
@ -23,7 +24,6 @@ require_once 'include/Photo.php';
|
|||
require_once 'include/follow.php';
|
||||
require_once 'include/api.php';
|
||||
require_once 'mod/proxy.php';
|
||||
require_once 'include/xml.php';
|
||||
|
||||
/**
|
||||
* @brief This class contain functions for the OStatus protocol
|
||||
|
@ -169,24 +169,29 @@ class ostatus
|
|||
$contact['nurl'] = normalise_link($contact['url']);
|
||||
|
||||
$value = $xpath->evaluate('atom:author/atom:uri/text()', $context)->item(0)->nodeValue;
|
||||
if ($value != "")
|
||||
if ($value != "") {
|
||||
$contact["alias"] = $value;
|
||||
}
|
||||
|
||||
$value = $xpath->evaluate('atom:author/poco:displayName/text()', $context)->item(0)->nodeValue;
|
||||
if ($value != "")
|
||||
if ($value != "") {
|
||||
$contact["name"] = $value;
|
||||
}
|
||||
|
||||
$value = $xpath->evaluate('atom:author/poco:preferredUsername/text()', $context)->item(0)->nodeValue;
|
||||
if ($value != "")
|
||||
if ($value != "") {
|
||||
$contact["nick"] = $value;
|
||||
}
|
||||
|
||||
$value = $xpath->evaluate('atom:author/poco:note/text()', $context)->item(0)->nodeValue;
|
||||
if ($value != "")
|
||||
if ($value != "") {
|
||||
$contact["about"] = html2bbcode($value);
|
||||
}
|
||||
|
||||
$value = $xpath->evaluate('atom:author/poco:address/poco:formatted/text()', $context)->item(0)->nodeValue;
|
||||
if ($value != "")
|
||||
if ($value != "") {
|
||||
$contact["location"] = $value;
|
||||
}
|
||||
|
||||
$contact['name-date'] = datetime_convert();
|
||||
|
||||
|
@ -238,8 +243,9 @@ class ostatus
|
|||
*/
|
||||
public static function salmon_author($xml, $importer)
|
||||
{
|
||||
if ($xml == "")
|
||||
if ($xml == "") {
|
||||
return;
|
||||
}
|
||||
|
||||
$doc = new DOMDocument();
|
||||
@$doc->loadXML($xml);
|
||||
|
@ -1113,14 +1119,16 @@ class ostatus
|
|||
{
|
||||
$elements = explode(":", $href);
|
||||
|
||||
if ((count($elements) <= 2) || ($elements[0] != "tag"))
|
||||
if ((count($elements) <= 2) || ($elements[0] != "tag")) {
|
||||
return $href;
|
||||
}
|
||||
|
||||
$server = explode(",", $elements[1]);
|
||||
$conversation = explode("=", $elements[2]);
|
||||
|
||||
if ((count($elements) == 4) && ($elements[2] == "post"))
|
||||
if ((count($elements) == 4) && ($elements[2] == "post")) {
|
||||
return "http://".$server[0]."/notice/".$elements[3];
|
||||
}
|
||||
|
||||
if ((count($conversation) != 2) || ($conversation[1] =="")) {
|
||||
return $href;
|
||||
|
@ -1146,26 +1154,31 @@ class ostatus
|
|||
|
||||
// Skip if it isn't a pure repeated messages
|
||||
// Does it start with a share?
|
||||
if (strpos($body, "[share") > 0)
|
||||
if (strpos($body, "[share") > 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// Does it end with a share?
|
||||
if (strlen($body) > (strrpos($body, "[/share]") + 8))
|
||||
if (strlen($body) > (strrpos($body, "[/share]") + 8)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
$attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism", "$1", $body);
|
||||
// Skip if there is no shared message in there
|
||||
if ($body == $attributes)
|
||||
if ($body == $attributes) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$guid = "";
|
||||
preg_match("/guid='(.*?)'/ism", $attributes, $matches);
|
||||
if ($matches[1] != "")
|
||||
if ($matches[1] != "") {
|
||||
$guid = $matches[1];
|
||||
}
|
||||
|
||||
preg_match('/guid="(.*?)"/ism', $attributes, $matches);
|
||||
if ($matches[1] != "")
|
||||
if ($matches[1] != "") {
|
||||
$guid = $matches[1];
|
||||
}
|
||||
|
||||
return $guid;
|
||||
}
|
||||
|
@ -1232,39 +1245,39 @@ class ostatus
|
|||
$root->setAttribute("xmlns:mastodon", NAMESPACE_MASTODON);
|
||||
|
||||
$attributes = array("uri" => "https://friendi.ca", "version" => FRIENDICA_VERSION."-".DB_UPDATE_VERSION);
|
||||
xml::add_element($doc, $root, "generator", FRIENDICA_PLATFORM, $attributes);
|
||||
xml::add_element($doc, $root, "id", System::baseUrl()."/profile/".$owner["nick"]);
|
||||
xml::add_element($doc, $root, "title", sprintf("%s timeline", $owner["name"]));
|
||||
xml::add_element($doc, $root, "subtitle", sprintf("Updates from %s on %s", $owner["name"], $a->config["sitename"]));
|
||||
xml::add_element($doc, $root, "logo", $owner["photo"]);
|
||||
xml::add_element($doc, $root, "updated", datetime_convert("UTC", "UTC", "now", ATOM_TIME));
|
||||
XML::add_element($doc, $root, "generator", FRIENDICA_PLATFORM, $attributes);
|
||||
XML::add_element($doc, $root, "id", System::baseUrl()."/profile/".$owner["nick"]);
|
||||
XML::add_element($doc, $root, "title", sprintf("%s timeline", $owner["name"]));
|
||||
XML::add_element($doc, $root, "subtitle", sprintf("Updates from %s on %s", $owner["name"], $a->config["sitename"]));
|
||||
XML::add_element($doc, $root, "logo", $owner["photo"]);
|
||||
XML::add_element($doc, $root, "updated", datetime_convert("UTC", "UTC", "now", ATOM_TIME));
|
||||
|
||||
$author = self::add_author($doc, $owner);
|
||||
$root->appendChild($author);
|
||||
|
||||
$attributes = array("href" => $owner["url"], "rel" => "alternate", "type" => "text/html");
|
||||
xml::add_element($doc, $root, "link", "", $attributes);
|
||||
XML::add_element($doc, $root, "link", "", $attributes);
|
||||
|
||||
/// @TODO We have to find out what this is
|
||||
/// $attributes = array("href" => System::baseUrl()."/sup",
|
||||
/// "rel" => "http://api.friendfeed.com/2008/03#sup",
|
||||
/// "type" => "application/json");
|
||||
/// xml::add_element($doc, $root, "link", "", $attributes);
|
||||
/// XML::add_element($doc, $root, "link", "", $attributes);
|
||||
|
||||
self::hublinks($doc, $root, $owner["nick"]);
|
||||
|
||||
$attributes = array("href" => System::baseUrl()."/salmon/".$owner["nick"], "rel" => "salmon");
|
||||
xml::add_element($doc, $root, "link", "", $attributes);
|
||||
XML::add_element($doc, $root, "link", "", $attributes);
|
||||
|
||||
$attributes = array("href" => System::baseUrl()."/salmon/".$owner["nick"], "rel" => "http://salmon-protocol.org/ns/salmon-replies");
|
||||
xml::add_element($doc, $root, "link", "", $attributes);
|
||||
XML::add_element($doc, $root, "link", "", $attributes);
|
||||
|
||||
$attributes = array("href" => System::baseUrl()."/salmon/".$owner["nick"], "rel" => "http://salmon-protocol.org/ns/salmon-mention");
|
||||
xml::add_element($doc, $root, "link", "", $attributes);
|
||||
XML::add_element($doc, $root, "link", "", $attributes);
|
||||
|
||||
$attributes = array("href" => System::baseUrl()."/api/statuses/user_timeline/".$owner["nick"].".atom",
|
||||
"rel" => "self", "type" => "application/atom+xml");
|
||||
xml::add_element($doc, $root, "link", "", $attributes);
|
||||
XML::add_element($doc, $root, "link", "", $attributes);
|
||||
|
||||
return $root;
|
||||
}
|
||||
|
@ -1279,7 +1292,7 @@ class ostatus
|
|||
public static function hublinks($doc, $root, $nick)
|
||||
{
|
||||
$h = System::baseUrl() . '/pubsubhubbub/'.$nick;
|
||||
xml::add_element($doc, $root, "link", "", array("href" => $h, "rel" => "hub"));
|
||||
XML::add_element($doc, $root, "link", "", array("href" => $h, "rel" => "hub"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1301,7 +1314,7 @@ class ostatus
|
|||
"href" => $siteinfo["image"],
|
||||
"type" => $imgdata["mime"],
|
||||
"length" => intval($imgdata["size"]));
|
||||
xml::add_element($doc, $root, "link", "", $attributes);
|
||||
XML::add_element($doc, $root, "link", "", $attributes);
|
||||
break;
|
||||
case 'video':
|
||||
$attributes = array("rel" => "enclosure",
|
||||
|
@ -1309,7 +1322,7 @@ class ostatus
|
|||
"type" => "text/html; charset=UTF-8",
|
||||
"length" => "",
|
||||
"title" => $siteinfo["title"]);
|
||||
xml::add_element($doc, $root, "link", "", $attributes);
|
||||
XML::add_element($doc, $root, "link", "", $attributes);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -1322,7 +1335,7 @@ class ostatus
|
|||
"type" => $imgdata["mime"],
|
||||
"length" => intval($imgdata["size"]));
|
||||
|
||||
xml::add_element($doc, $root, "link", "", $attributes);
|
||||
XML::add_element($doc, $root, "link", "", $attributes);
|
||||
}
|
||||
|
||||
$arr = explode('[/attach],', $item['attach']);
|
||||
|
@ -1341,7 +1354,7 @@ class ostatus
|
|||
if (trim($matches[4]) != "") {
|
||||
$attributes["title"] = trim($matches[4]);
|
||||
}
|
||||
xml::add_element($doc, $root, "link", "", $attributes);
|
||||
XML::add_element($doc, $root, "link", "", $attributes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1362,15 +1375,15 @@ class ostatus
|
|||
$profile = $r[0];
|
||||
}
|
||||
$author = $doc->createElement("author");
|
||||
xml::add_element($doc, $author, "id", $owner["url"]);
|
||||
xml::add_element($doc, $author, "activity:object-type", ACTIVITY_OBJ_PERSON);
|
||||
xml::add_element($doc, $author, "uri", $owner["url"]);
|
||||
xml::add_element($doc, $author, "name", $owner["nick"]);
|
||||
xml::add_element($doc, $author, "email", $owner["addr"]);
|
||||
xml::add_element($doc, $author, "summary", bbcode($owner["about"], false, false, 7));
|
||||
XML::add_element($doc, $author, "id", $owner["url"]);
|
||||
XML::add_element($doc, $author, "activity:object-type", ACTIVITY_OBJ_PERSON);
|
||||
XML::add_element($doc, $author, "uri", $owner["url"]);
|
||||
XML::add_element($doc, $author, "name", $owner["nick"]);
|
||||
XML::add_element($doc, $author, "email", $owner["addr"]);
|
||||
XML::add_element($doc, $author, "summary", bbcode($owner["about"], false, false, 7));
|
||||
|
||||
$attributes = array("rel" => "alternate", "type" => "text/html", "href" => $owner["url"]);
|
||||
xml::add_element($doc, $author, "link", "", $attributes);
|
||||
XML::add_element($doc, $author, "link", "", $attributes);
|
||||
|
||||
$attributes = array(
|
||||
"rel" => "avatar",
|
||||
|
@ -1378,7 +1391,7 @@ class ostatus
|
|||
"media:width" => 175,
|
||||
"media:height" => 175,
|
||||
"href" => $owner["photo"]);
|
||||
xml::add_element($doc, $author, "link", "", $attributes);
|
||||
XML::add_element($doc, $author, "link", "", $attributes);
|
||||
|
||||
if (isset($owner["thumb"])) {
|
||||
$attributes = array(
|
||||
|
@ -1387,34 +1400,34 @@ class ostatus
|
|||
"media:width" => 80,
|
||||
"media:height" => 80,
|
||||
"href" => $owner["thumb"]);
|
||||
xml::add_element($doc, $author, "link", "", $attributes);
|
||||
XML::add_element($doc, $author, "link", "", $attributes);
|
||||
}
|
||||
|
||||
xml::add_element($doc, $author, "poco:preferredUsername", $owner["nick"]);
|
||||
xml::add_element($doc, $author, "poco:displayName", $owner["name"]);
|
||||
xml::add_element($doc, $author, "poco:note", bbcode($owner["about"], false, false, 7));
|
||||
XML::add_element($doc, $author, "poco:preferredUsername", $owner["nick"]);
|
||||
XML::add_element($doc, $author, "poco:displayName", $owner["name"]);
|
||||
XML::add_element($doc, $author, "poco:note", bbcode($owner["about"], false, false, 7));
|
||||
|
||||
if (trim($owner["location"]) != "") {
|
||||
$element = $doc->createElement("poco:address");
|
||||
xml::add_element($doc, $element, "poco:formatted", $owner["location"]);
|
||||
XML::add_element($doc, $element, "poco:formatted", $owner["location"]);
|
||||
$author->appendChild($element);
|
||||
}
|
||||
|
||||
if (trim($profile["homepage"]) != "") {
|
||||
$urls = $doc->createElement("poco:urls");
|
||||
xml::add_element($doc, $urls, "poco:type", "homepage");
|
||||
xml::add_element($doc, $urls, "poco:value", $profile["homepage"]);
|
||||
xml::add_element($doc, $urls, "poco:primary", "true");
|
||||
XML::add_element($doc, $urls, "poco:type", "homepage");
|
||||
XML::add_element($doc, $urls, "poco:value", $profile["homepage"]);
|
||||
XML::add_element($doc, $urls, "poco:primary", "true");
|
||||
$author->appendChild($urls);
|
||||
}
|
||||
|
||||
if (count($profile)) {
|
||||
xml::add_element($doc, $author, "followers", "", array("url" => System::baseUrl()."/viewcontacts/".$owner["nick"]));
|
||||
xml::add_element($doc, $author, "statusnet:profile_info", "", array("local_id" => $owner["uid"]));
|
||||
XML::add_element($doc, $author, "followers", "", array("url" => System::baseUrl()."/viewcontacts/".$owner["nick"]));
|
||||
XML::add_element($doc, $author, "statusnet:profile_info", "", array("local_id" => $owner["uid"]));
|
||||
}
|
||||
|
||||
if ($profile["publish"]) {
|
||||
xml::add_element($doc, $author, "mastodon:scope", "public");
|
||||
XML::add_element($doc, $author, "mastodon:scope", "public");
|
||||
}
|
||||
return $author;
|
||||
}
|
||||
|
@ -1434,8 +1447,10 @@ class ostatus
|
|||
*/
|
||||
private static function construct_verb($item)
|
||||
{
|
||||
if ($item['verb'])
|
||||
if ($item['verb']) {
|
||||
return $item['verb'];
|
||||
}
|
||||
|
||||
return ACTIVITY_POST;
|
||||
}
|
||||
|
||||
|
@ -1466,11 +1481,13 @@ class ostatus
|
|||
private static function entry($doc, $item, $owner, $toplevel = false)
|
||||
{
|
||||
$repeated_guid = self::get_reshared_guid($item);
|
||||
if ($repeated_guid != "")
|
||||
if ($repeated_guid != "") {
|
||||
$xml = self::reshare_entry($doc, $item, $owner, $repeated_guid, $toplevel);
|
||||
}
|
||||
|
||||
if ($xml)
|
||||
if ($xml) {
|
||||
return $xml;
|
||||
}
|
||||
|
||||
if ($item["verb"] == ACTIVITY_LIKE) {
|
||||
return self::like_entry($doc, $item, $owner, $toplevel);
|
||||
|
@ -1492,12 +1509,12 @@ class ostatus
|
|||
private static function source_entry($doc, $contact)
|
||||
{
|
||||
$source = $doc->createElement("source");
|
||||
xml::add_element($doc, $source, "id", $contact["poll"]);
|
||||
xml::add_element($doc, $source, "title", $contact["name"]);
|
||||
xml::add_element($doc, $source, "link", "", array("rel" => "alternate", "type" => "text/html", "href" => $contact["alias"]));
|
||||
xml::add_element($doc, $source, "link", "", array("rel" => "self", "type" => "application/atom+xml", "href" => $contact["poll"]));
|
||||
xml::add_element($doc, $source, "icon", $contact["photo"]);
|
||||
xml::add_element($doc, $source, "updated", datetime_convert("UTC", "UTC", $contact["success_update"]."+00:00", ATOM_TIME));
|
||||
XML::add_element($doc, $source, "id", $contact["poll"]);
|
||||
XML::add_element($doc, $source, "title", $contact["name"]);
|
||||
XML::add_element($doc, $source, "link", "", array("rel" => "alternate", "type" => "text/html", "href" => $contact["alias"]));
|
||||
XML::add_element($doc, $source, "link", "", array("rel" => "self", "type" => "application/atom+xml", "href" => $contact["poll"]));
|
||||
XML::add_element($doc, $source, "icon", $contact["photo"]);
|
||||
XML::add_element($doc, $source, "updated", datetime_convert("UTC", "UTC", $contact["success_update"]."+00:00", ATOM_TIME));
|
||||
|
||||
return $source;
|
||||
}
|
||||
|
@ -1510,8 +1527,8 @@ class ostatus
|
|||
*
|
||||
* @return array Contact array
|
||||
*/
|
||||
private static function contact_entry($url, $owner) {
|
||||
|
||||
private static function contact_entry($url, $owner)
|
||||
{
|
||||
$r = q(
|
||||
"SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` IN (0, %d) ORDER BY `uid` DESC LIMIT 1",
|
||||
dbesc(normalise_link($url)),
|
||||
|
@ -1596,7 +1613,7 @@ class ostatus
|
|||
|
||||
$as_object = $doc->createElement("activity:object");
|
||||
|
||||
xml::add_element($doc, $as_object, "activity:object-type", NAMESPACE_ACTIVITY_SCHEMA."activity");
|
||||
XML::add_element($doc, $as_object, "activity:object-type", NAMESPACE_ACTIVITY_SCHEMA."activity");
|
||||
|
||||
self::entry_content($doc, $as_object, $repeated_item, $owner, "", "", false);
|
||||
|
||||
|
@ -1605,7 +1622,7 @@ class ostatus
|
|||
|
||||
$as_object2 = $doc->createElement("activity:object");
|
||||
|
||||
xml::add_element($doc, $as_object2, "activity:object-type", self::construct_objecttype($repeated_item));
|
||||
XML::add_element($doc, $as_object2, "activity:object-type", self::construct_objecttype($repeated_item));
|
||||
|
||||
$title = sprintf("New comment by %s", $contact["nick"]);
|
||||
|
||||
|
@ -1656,7 +1673,7 @@ class ostatus
|
|||
);
|
||||
$parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']);
|
||||
|
||||
xml::add_element($doc, $as_object, "activity:object-type", self::construct_objecttype($parent[0]));
|
||||
XML::add_element($doc, $as_object, "activity:object-type", self::construct_objecttype($parent[0]));
|
||||
|
||||
self::entry_content($doc, $as_object, $parent[0], $owner, "New entry");
|
||||
|
||||
|
@ -1679,18 +1696,18 @@ class ostatus
|
|||
private static function add_person_object($doc, $owner, $contact)
|
||||
{
|
||||
$object = $doc->createElement("activity:object");
|
||||
xml::add_element($doc, $object, "activity:object-type", ACTIVITY_OBJ_PERSON);
|
||||
XML::add_element($doc, $object, "activity:object-type", ACTIVITY_OBJ_PERSON);
|
||||
|
||||
if ($contact['network'] == NETWORK_PHANTOM) {
|
||||
xml::add_element($doc, $object, "id", $contact['url']);
|
||||
XML::add_element($doc, $object, "id", $contact['url']);
|
||||
return $object;
|
||||
}
|
||||
|
||||
xml::add_element($doc, $object, "id", $contact["alias"]);
|
||||
xml::add_element($doc, $object, "title", $contact["nick"]);
|
||||
XML::add_element($doc, $object, "id", $contact["alias"]);
|
||||
XML::add_element($doc, $object, "title", $contact["nick"]);
|
||||
|
||||
$attributes = array("rel" => "alternate", "type" => "text/html", "href" => $contact["url"]);
|
||||
xml::add_element($doc, $object, "link", "", $attributes);
|
||||
XML::add_element($doc, $object, "link", "", $attributes);
|
||||
|
||||
$attributes = array(
|
||||
"rel" => "avatar",
|
||||
|
@ -1698,14 +1715,14 @@ class ostatus
|
|||
"media:width" => 175,
|
||||
"media:height" => 175,
|
||||
"href" => $contact["photo"]);
|
||||
xml::add_element($doc, $object, "link", "", $attributes);
|
||||
XML::add_element($doc, $object, "link", "", $attributes);
|
||||
|
||||
xml::add_element($doc, $object, "poco:preferredUsername", $contact["nick"]);
|
||||
xml::add_element($doc, $object, "poco:displayName", $contact["name"]);
|
||||
XML::add_element($doc, $object, "poco:preferredUsername", $contact["nick"]);
|
||||
XML::add_element($doc, $object, "poco:displayName", $contact["name"]);
|
||||
|
||||
if (trim($contact["location"]) != "") {
|
||||
$element = $doc->createElement("poco:address");
|
||||
xml::add_element($doc, $element, "poco:formatted", $contact["location"]);
|
||||
XML::add_element($doc, $element, "poco:formatted", $contact["location"]);
|
||||
$object->appendChild($element);
|
||||
}
|
||||
|
||||
|
@ -1722,8 +1739,8 @@ class ostatus
|
|||
*
|
||||
* @return object Entry element
|
||||
*/
|
||||
private static function follow_entry($doc, $item, $owner, $toplevel) {
|
||||
|
||||
private static function follow_entry($doc, $item, $owner, $toplevel)
|
||||
{
|
||||
$item["id"] = $item["parent"] = 0;
|
||||
$item["created"] = $item["edited"] = date("c");
|
||||
$item["private"] = true;
|
||||
|
@ -1795,7 +1812,7 @@ class ostatus
|
|||
|
||||
$title = self::entry_header($doc, $entry, $owner, $toplevel);
|
||||
|
||||
xml::add_element($doc, $entry, "activity:object-type", ACTIVITY_OBJ_NOTE);
|
||||
XML::add_element($doc, $entry, "activity:object-type", ACTIVITY_OBJ_NOTE);
|
||||
|
||||
self::entry_content($doc, $entry, $item, $owner, $title);
|
||||
|
||||
|
@ -1857,30 +1874,31 @@ class ostatus
|
|||
$verb = self::construct_verb($item);
|
||||
}
|
||||
|
||||
xml::add_element($doc, $entry, "id", $item["uri"]);
|
||||
xml::add_element($doc, $entry, "title", $title);
|
||||
XML::add_element($doc, $entry, "id", $item["uri"]);
|
||||
XML::add_element($doc, $entry, "title", $title);
|
||||
|
||||
$body = self::format_picture_post($item['body']);
|
||||
|
||||
if ($item['title'] != "")
|
||||
if ($item['title'] != "") {
|
||||
$body = "[b]".$item['title']."[/b]\n\n".$body;
|
||||
}
|
||||
|
||||
$body = bbcode($body, false, false, 7);
|
||||
|
||||
xml::add_element($doc, $entry, "content", $body, array("type" => "html"));
|
||||
XML::add_element($doc, $entry, "content", $body, array("type" => "html"));
|
||||
|
||||
xml::add_element($doc, $entry, "link", "", array("rel" => "alternate", "type" => "text/html",
|
||||
XML::add_element($doc, $entry, "link", "", array("rel" => "alternate", "type" => "text/html",
|
||||
"href" => System::baseUrl()."/display/".$item["guid"])
|
||||
);
|
||||
|
||||
if ($complete && ($item["id"] > 0)) {
|
||||
xml::add_element($doc, $entry, "status_net", "", array("notice_id" => $item["id"]));
|
||||
XML::add_element($doc, $entry, "status_net", "", array("notice_id" => $item["id"]));
|
||||
}
|
||||
|
||||
xml::add_element($doc, $entry, "activity:verb", $verb);
|
||||
XML::add_element($doc, $entry, "activity:verb", $verb);
|
||||
|
||||
xml::add_element($doc, $entry, "published", datetime_convert("UTC", "UTC", $item["created"]."+00:00", ATOM_TIME));
|
||||
xml::add_element($doc, $entry, "updated", datetime_convert("UTC", "UTC", $item["edited"]."+00:00", ATOM_TIME));
|
||||
XML::add_element($doc, $entry, "published", datetime_convert("UTC", "UTC", $item["created"]."+00:00", ATOM_TIME));
|
||||
XML::add_element($doc, $entry, "updated", datetime_convert("UTC", "UTC", $item["edited"]."+00:00", ATOM_TIME));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1918,12 +1936,12 @@ class ostatus
|
|||
$attributes = array(
|
||||
"ref" => $parent_item,
|
||||
"href" => $parent_plink);
|
||||
xml::add_element($doc, $entry, "thr:in-reply-to", "", $attributes);
|
||||
XML::add_element($doc, $entry, "thr:in-reply-to", "", $attributes);
|
||||
|
||||
$attributes = array(
|
||||
"rel" => "related",
|
||||
"href" => $parent_plink);
|
||||
xml::add_element($doc, $entry, "link", "", $attributes);
|
||||
XML::add_element($doc, $entry, "link", "", $attributes);
|
||||
}
|
||||
|
||||
if (intval($item["parent"]) > 0) {
|
||||
|
@ -1942,14 +1960,14 @@ class ostatus
|
|||
}
|
||||
}
|
||||
|
||||
xml::add_element($doc, $entry, "link", "", array("rel" => "ostatus:conversation", "href" => $conversation_href));
|
||||
XML::add_element($doc, $entry, "link", "", array("rel" => "ostatus:conversation", "href" => $conversation_href));
|
||||
|
||||
$attributes = array(
|
||||
"href" => $conversation_href,
|
||||
"local_id" => $item["parent"],
|
||||
"ref" => $conversation_uri);
|
||||
|
||||
xml::add_element($doc, $entry, "ostatus:conversation", $conversation_uri, $attributes);
|
||||
XML::add_element($doc, $entry, "ostatus:conversation", $conversation_uri, $attributes);
|
||||
}
|
||||
|
||||
$tags = item_getfeedtags($item);
|
||||
|
@ -1977,14 +1995,14 @@ class ostatus
|
|||
dbesc(normalise_link($mention))
|
||||
);
|
||||
if ($r[0]["forum"] || $r[0]["prv"]) {
|
||||
xml::add_element($doc, $entry, "link", "",
|
||||
XML::add_element($doc, $entry, "link", "",
|
||||
array(
|
||||
"rel" => "mentioned",
|
||||
"ostatus:object-type" => ACTIVITY_OBJ_GROUP,
|
||||
"href" => $mention)
|
||||
);
|
||||
} else {
|
||||
xml::add_element($doc, $entry, "link", "",
|
||||
XML::add_element($doc, $entry, "link", "",
|
||||
array(
|
||||
"rel" => "mentioned",
|
||||
"ostatus:object-type" => ACTIVITY_OBJ_PERSON,
|
||||
|
@ -1994,18 +2012,18 @@ class ostatus
|
|||
}
|
||||
|
||||
if (!$item["private"]) {
|
||||
xml::add_element($doc, $entry, "link", "", array("rel" => "ostatus:attention",
|
||||
XML::add_element($doc, $entry, "link", "", array("rel" => "ostatus:attention",
|
||||
"href" => "http://activityschema.org/collection/public"));
|
||||
xml::add_element($doc, $entry, "link", "", array("rel" => "mentioned",
|
||||
XML::add_element($doc, $entry, "link", "", array("rel" => "mentioned",
|
||||
"ostatus:object-type" => "http://activitystrea.ms/schema/1.0/collection",
|
||||
"href" => "http://activityschema.org/collection/public"));
|
||||
xml::add_element($doc, $entry, "mastodon:scope", "public");
|
||||
XML::add_element($doc, $entry, "mastodon:scope", "public");
|
||||
}
|
||||
|
||||
if (count($tags)) {
|
||||
foreach ($tags as $t) {
|
||||
if ($t[0] != "@") {
|
||||
xml::add_element($doc, $entry, "category", "", array("term" => $t[2]));
|
||||
XML::add_element($doc, $entry, "category", "", array("term" => $t[2]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2014,8 +2032,9 @@ class ostatus
|
|||
|
||||
if ($complete && ($item["id"] > 0)) {
|
||||
$app = $item["app"];
|
||||
if ($app == "")
|
||||
if ($app == "") {
|
||||
$app = "web";
|
||||
}
|
||||
|
||||
$attributes = array("local_id" => $item["id"], "source" => $app);
|
||||
|
||||
|
@ -2024,10 +2043,10 @@ class ostatus
|
|||
}
|
||||
|
||||
if ($item["coord"] != "") {
|
||||
xml::add_element($doc, $entry, "georss:point", $item["coord"]);
|
||||
XML::add_element($doc, $entry, "georss:point", $item["coord"]);
|
||||
}
|
||||
|
||||
xml::add_element($doc, $entry, "statusnet:notice_info", "", $attributes);
|
||||
XML::add_element($doc, $entry, "statusnet:notice_info", "", $attributes);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file include/salmon.php
|
||||
*/
|
||||
use Friendica\Network\Probe;
|
||||
use Friendica\Util\XML;
|
||||
|
||||
require_once 'include/crypto.php';
|
||||
|
||||
function get_salmon_key($uri, $keyhash) {
|
||||
function get_salmon_key($uri, $keyhash)
|
||||
{
|
||||
$ret = array();
|
||||
|
||||
logger('Fetching salmon key for '.$uri);
|
||||
|
@ -42,7 +46,6 @@ function get_salmon_key($uri, $keyhash) {
|
|||
logger('Key located: ' . print_r($ret, true));
|
||||
|
||||
if (count($ret) == 1) {
|
||||
|
||||
// We only found one one key so we don't care if the hash matches.
|
||||
// If it's the wrong key we'll find out soon enough because
|
||||
// message verification will fail. This also covers some older
|
||||
|
@ -64,8 +67,8 @@ function get_salmon_key($uri, $keyhash) {
|
|||
|
||||
|
||||
|
||||
function slapper($owner, $url, $slap) {
|
||||
|
||||
function slapper($owner, $url, $slap)
|
||||
{
|
||||
// does contact have a salmon endpoint?
|
||||
|
||||
if (! strlen($url)) {
|
||||
|
@ -109,7 +112,7 @@ function slapper($owner, $url, $slap) {
|
|||
|
||||
$namespaces = array("me" => "http://salmon-protocol.org/ns/magic-env");
|
||||
|
||||
$salmon = xml::from_array($xmldata, $xml, false, $namespaces);
|
||||
$salmon = XML::from_array($xmldata, $xml, false, $namespaces);
|
||||
|
||||
// slap them
|
||||
post_url($url, $salmon, array(
|
||||
|
@ -123,7 +126,6 @@ function slapper($owner, $url, $slap) {
|
|||
// check for success, e.g. 2xx
|
||||
|
||||
if ($return_code > 299) {
|
||||
|
||||
logger('GNU Social salmon failed. Falling back to compliant mode');
|
||||
|
||||
// Now try the compliant mode that normally isn't used for GNU Social
|
||||
|
@ -136,7 +138,7 @@ function slapper($owner, $url, $slap) {
|
|||
|
||||
$namespaces = array("me" => "http://salmon-protocol.org/ns/magic-env");
|
||||
|
||||
$salmon = xml::from_array($xmldata, $xml, false, $namespaces);
|
||||
$salmon = XML::from_array($xmldata, $xml, false, $namespaces);
|
||||
|
||||
// slap them
|
||||
post_url($url, $salmon, array(
|
||||
|
@ -159,13 +161,13 @@ function slapper($owner, $url, $slap) {
|
|||
|
||||
$namespaces = array("me" => "http://salmon-protocol.org/ns/magic-env");
|
||||
|
||||
$salmon = xml::from_array($xmldata, $xml, false, $namespaces);
|
||||
$salmon = XML::from_array($xmldata, $xml, false, $namespaces);
|
||||
|
||||
// slap them
|
||||
post_url($url, $salmon, array(
|
||||
'Content-type: application/magic-envelope+xml',
|
||||
'Content-length: ' . strlen($salmon)
|
||||
));
|
||||
'Content-length: ' . strlen($salmon))
|
||||
);
|
||||
$return_code = $a->get_curl_code();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,11 +6,12 @@ This file is part of the Diaspora protocol. It is used for fetching single publi
|
|||
use Friendica\App;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Protocol\Diaspora;
|
||||
use Friendica\Util\XML;
|
||||
|
||||
require_once("include/crypto.php");
|
||||
require_once("include/xml.php");
|
||||
require_once "include/crypto.php";
|
||||
|
||||
function fetch_init(App $a) {
|
||||
function fetch_init(App $a)
|
||||
{
|
||||
|
||||
if (($a->argc != 3) || (!in_array($a->argv[1], array("post", "status_message", "reshare")))) {
|
||||
header($_SERVER["SERVER_PROTOCOL"].' 404 '.t('Not Found'));
|
||||
|
@ -20,13 +21,22 @@ function fetch_init(App $a) {
|
|||
$guid = $a->argv[2];
|
||||
|
||||
// Fetch the item
|
||||
$item = q("SELECT `uid`, `title`, `body`, `guid`, `contact-id`, `private`, `created`, `app`, `location`, `coord`
|
||||
$item = q(
|
||||
"SELECT `uid`, `title`, `body`, `guid`, `contact-id`, `private`, `created`, `app`, `location`, `coord`
|
||||
FROM `item` WHERE `wall` AND NOT `private` AND `guid` = '%s' AND `network` IN ('%s', '%s') AND `id` = `parent` LIMIT 1",
|
||||
dbesc($guid), NETWORK_DFRN, NETWORK_DIASPORA);
|
||||
dbesc($guid),
|
||||
NETWORK_DFRN,
|
||||
NETWORK_DIASPORA
|
||||
);
|
||||
if (!$item) {
|
||||
$r = q("SELECT `author-link`
|
||||
$r = q(
|
||||
"SELECT `author-link`
|
||||
FROM `item` WHERE `uid` = 0 AND `guid` = '%s' AND `network` IN ('%s', '%s') AND `id` = `parent` LIMIT 1",
|
||||
dbesc($guid), NETWORK_DFRN, NETWORK_DIASPORA);
|
||||
dbesc($guid),
|
||||
NETWORK_DFRN,
|
||||
NETWORK_DIASPORA
|
||||
);
|
||||
|
||||
if ($r) {
|
||||
$parts = parse_url($r[0]["author-link"]);
|
||||
$host = $parts["scheme"]."://".$parts["host"];
|
||||
|
@ -45,9 +55,13 @@ function fetch_init(App $a) {
|
|||
}
|
||||
|
||||
// Fetch some data from the author (We could combine both queries - but I think this is more readable)
|
||||
$r = q("SELECT `user`.`prvkey`, `contact`.`addr`, `user`.`nickname`, `contact`.`nick` FROM `user`
|
||||
$r = q(
|
||||
"SELECT `user`.`prvkey`, `contact`.`addr`, `user`.`nickname`, `contact`.`nick` FROM `user`
|
||||
INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
|
||||
WHERE `user`.`uid` = %d", intval($item[0]["uid"]));
|
||||
WHERE `user`.`uid` = %d",
|
||||
intval($item[0]["uid"])
|
||||
);
|
||||
|
||||
if (!$r) {
|
||||
header($_SERVER["SERVER_PROTOCOL"].' 404 '.t('Not Found'));
|
||||
killme();
|
||||
|
|
|
@ -7,13 +7,13 @@ use Friendica\Core\Cache;
|
|||
use Friendica\Core\System;
|
||||
use Friendica\Core\PConfig;
|
||||
use Friendica\Database\DBM;
|
||||
use Friendica\Util\XML;
|
||||
|
||||
require_once 'include/datetime.php';
|
||||
require_once 'include/bbcode.php';
|
||||
require_once 'include/ForumManager.php';
|
||||
require_once 'include/group.php';
|
||||
require_once 'mod/proxy.php';
|
||||
require_once 'include/xml.php';
|
||||
require_once 'include/enotify.php';
|
||||
|
||||
/**
|
||||
|
@ -114,7 +114,7 @@ function ping_init(App $a)
|
|||
}
|
||||
} else {
|
||||
header("Content-type: text/xml");
|
||||
echo xml::from_array($data, $xml);
|
||||
echo XML::from_array($data, $xml);
|
||||
}
|
||||
killme();
|
||||
}
|
||||
|
@ -411,7 +411,7 @@ function ping_init(App $a)
|
|||
$data = ping_format_xml_data($data, $sysnotify_count, $notifications, $sysmsgs, $sysmsgs_info, $groups_unseen, $forums_unseen);
|
||||
|
||||
header("Content-type: text/xml");
|
||||
echo xml::from_array(array("result" => $data), $xml);
|
||||
echo XML::from_array(array("result" => $data), $xml);
|
||||
}
|
||||
|
||||
killme();
|
||||
|
|
|
@ -13,10 +13,9 @@ use Friendica\Core\System;
|
|||
use Friendica\Core\Cache;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Database\DBM;
|
||||
use Friendica\Util\XML;
|
||||
|
||||
use dba;
|
||||
use xml;
|
||||
|
||||
use DomXPath;
|
||||
use DOMDocument;
|
||||
|
||||
|
@ -124,7 +123,7 @@ class Probe {
|
|||
return array();
|
||||
}
|
||||
|
||||
$links = xml::element_to_array($xrd);
|
||||
$links = XML::element_to_array($xrd);
|
||||
if (!isset($links["xrd"]["link"])) {
|
||||
logger("No xrd data found for ".$host, LOGGER_DEBUG);
|
||||
return array();
|
||||
|
@ -706,7 +705,7 @@ class Probe {
|
|||
return false;
|
||||
}
|
||||
|
||||
$xrd_arr = xml::element_to_array($xrd);
|
||||
$xrd_arr = XML::element_to_array($xrd);
|
||||
if (!isset($xrd_arr["xrd"]["link"])) {
|
||||
logger("No XML webfinger links for ".$url, LOGGER_DEBUG);
|
||||
return false;
|
||||
|
|
|
@ -6,10 +6,9 @@
|
|||
namespace Friendica;
|
||||
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Util\XML;
|
||||
|
||||
use xml;
|
||||
use dba;
|
||||
|
||||
use DomXPath;
|
||||
use DOMDocument;
|
||||
|
||||
|
@ -204,17 +203,17 @@ class ParseUrl
|
|||
$doc = new DOMDocument();
|
||||
@$doc->loadHTML($body);
|
||||
|
||||
xml::deleteNode($doc, "style");
|
||||
xml::deleteNode($doc, "script");
|
||||
xml::deleteNode($doc, "option");
|
||||
xml::deleteNode($doc, "h1");
|
||||
xml::deleteNode($doc, "h2");
|
||||
xml::deleteNode($doc, "h3");
|
||||
xml::deleteNode($doc, "h4");
|
||||
xml::deleteNode($doc, "h5");
|
||||
xml::deleteNode($doc, "h6");
|
||||
xml::deleteNode($doc, "ol");
|
||||
xml::deleteNode($doc, "ul");
|
||||
XML::deleteNode($doc, "style");
|
||||
XML::deleteNode($doc, "script");
|
||||
XML::deleteNode($doc, "option");
|
||||
XML::deleteNode($doc, "h1");
|
||||
XML::deleteNode($doc, "h2");
|
||||
XML::deleteNode($doc, "h3");
|
||||
XML::deleteNode($doc, "h4");
|
||||
XML::deleteNode($doc, "h5");
|
||||
XML::deleteNode($doc, "h6");
|
||||
XML::deleteNode($doc, "ol");
|
||||
XML::deleteNode($doc, "ul");
|
||||
|
||||
$xpath = new DomXPath($doc);
|
||||
|
||||
|
|
|
@ -13,12 +13,12 @@ use Friendica\Core\Config;
|
|||
use Friendica\Core\System;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBM;
|
||||
use Friendica\Util\XML;
|
||||
|
||||
use dba;
|
||||
use DOMDocument;
|
||||
use DomXPath;
|
||||
use ostatus;
|
||||
use xml;
|
||||
|
||||
require_once "include/Contact.php";
|
||||
require_once "include/enotify.php";
|
||||
|
@ -402,17 +402,17 @@ class DFRN
|
|||
$mail = $doc->createElement("dfrn:mail");
|
||||
$sender = $doc->createElement("dfrn:sender");
|
||||
|
||||
xml::add_element($doc, $sender, "dfrn:name", $owner['name']);
|
||||
xml::add_element($doc, $sender, "dfrn:uri", $owner['url']);
|
||||
xml::add_element($doc, $sender, "dfrn:avatar", $owner['thumb']);
|
||||
XML::add_element($doc, $sender, "dfrn:name", $owner['name']);
|
||||
XML::add_element($doc, $sender, "dfrn:uri", $owner['url']);
|
||||
XML::add_element($doc, $sender, "dfrn:avatar", $owner['thumb']);
|
||||
|
||||
$mail->appendChild($sender);
|
||||
|
||||
xml::add_element($doc, $mail, "dfrn:id", $item['uri']);
|
||||
xml::add_element($doc, $mail, "dfrn:in-reply-to", $item['parent-uri']);
|
||||
xml::add_element($doc, $mail, "dfrn:sentdate", datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME));
|
||||
xml::add_element($doc, $mail, "dfrn:subject", $item['title']);
|
||||
xml::add_element($doc, $mail, "dfrn:content", $item['body']);
|
||||
XML::add_element($doc, $mail, "dfrn:id", $item['uri']);
|
||||
XML::add_element($doc, $mail, "dfrn:in-reply-to", $item['parent-uri']);
|
||||
XML::add_element($doc, $mail, "dfrn:sentdate", datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME));
|
||||
XML::add_element($doc, $mail, "dfrn:subject", $item['title']);
|
||||
XML::add_element($doc, $mail, "dfrn:content", $item['body']);
|
||||
|
||||
$root->appendChild($mail);
|
||||
|
||||
|
@ -437,11 +437,11 @@ class DFRN
|
|||
|
||||
$suggest = $doc->createElement("dfrn:suggest");
|
||||
|
||||
xml::add_element($doc, $suggest, "dfrn:url", $item['url']);
|
||||
xml::add_element($doc, $suggest, "dfrn:name", $item['name']);
|
||||
xml::add_element($doc, $suggest, "dfrn:photo", $item['photo']);
|
||||
xml::add_element($doc, $suggest, "dfrn:request", $item['request']);
|
||||
xml::add_element($doc, $suggest, "dfrn:note", $item['note']);
|
||||
XML::add_element($doc, $suggest, "dfrn:url", $item['url']);
|
||||
XML::add_element($doc, $suggest, "dfrn:name", $item['name']);
|
||||
XML::add_element($doc, $suggest, "dfrn:photo", $item['photo']);
|
||||
XML::add_element($doc, $suggest, "dfrn:request", $item['request']);
|
||||
XML::add_element($doc, $suggest, "dfrn:note", $item['note']);
|
||||
|
||||
$root->appendChild($suggest);
|
||||
|
||||
|
@ -489,18 +489,18 @@ class DFRN
|
|||
|
||||
$relocate = $doc->createElement("dfrn:relocate");
|
||||
|
||||
xml::add_element($doc, $relocate, "dfrn:url", $owner['url']);
|
||||
xml::add_element($doc, $relocate, "dfrn:name", $owner['name']);
|
||||
xml::add_element($doc, $relocate, "dfrn:addr", $owner['addr']);
|
||||
xml::add_element($doc, $relocate, "dfrn:avatar", $owner['avatar']);
|
||||
xml::add_element($doc, $relocate, "dfrn:photo", $photos[4]);
|
||||
xml::add_element($doc, $relocate, "dfrn:thumb", $photos[5]);
|
||||
xml::add_element($doc, $relocate, "dfrn:micro", $photos[6]);
|
||||
xml::add_element($doc, $relocate, "dfrn:request", $owner['request']);
|
||||
xml::add_element($doc, $relocate, "dfrn:confirm", $owner['confirm']);
|
||||
xml::add_element($doc, $relocate, "dfrn:notify", $owner['notify']);
|
||||
xml::add_element($doc, $relocate, "dfrn:poll", $owner['poll']);
|
||||
xml::add_element($doc, $relocate, "dfrn:sitepubkey", Config::get('system','site_pubkey'));
|
||||
XML::add_element($doc, $relocate, "dfrn:url", $owner['url']);
|
||||
XML::add_element($doc, $relocate, "dfrn:name", $owner['name']);
|
||||
XML::add_element($doc, $relocate, "dfrn:addr", $owner['addr']);
|
||||
XML::add_element($doc, $relocate, "dfrn:avatar", $owner['avatar']);
|
||||
XML::add_element($doc, $relocate, "dfrn:photo", $photos[4]);
|
||||
XML::add_element($doc, $relocate, "dfrn:thumb", $photos[5]);
|
||||
XML::add_element($doc, $relocate, "dfrn:micro", $photos[6]);
|
||||
XML::add_element($doc, $relocate, "dfrn:request", $owner['request']);
|
||||
XML::add_element($doc, $relocate, "dfrn:confirm", $owner['confirm']);
|
||||
XML::add_element($doc, $relocate, "dfrn:notify", $owner['notify']);
|
||||
XML::add_element($doc, $relocate, "dfrn:poll", $owner['poll']);
|
||||
XML::add_element($doc, $relocate, "dfrn:sitepubkey", Config::get('system','site_pubkey'));
|
||||
|
||||
$root->appendChild($relocate);
|
||||
|
||||
|
@ -539,17 +539,17 @@ class DFRN
|
|||
$root->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
|
||||
$root->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
|
||||
|
||||
xml::add_element($doc, $root, "id", System::baseUrl()."/profile/".$owner["nick"]);
|
||||
xml::add_element($doc, $root, "title", $owner["name"]);
|
||||
XML::add_element($doc, $root, "id", System::baseUrl()."/profile/".$owner["nick"]);
|
||||
XML::add_element($doc, $root, "title", $owner["name"]);
|
||||
|
||||
$attributes = array("uri" => "https://friendi.ca", "version" => FRIENDICA_VERSION."-".DB_UPDATE_VERSION);
|
||||
xml::add_element($doc, $root, "generator", FRIENDICA_PLATFORM, $attributes);
|
||||
XML::add_element($doc, $root, "generator", FRIENDICA_PLATFORM, $attributes);
|
||||
|
||||
$attributes = array("rel" => "license", "href" => "http://creativecommons.org/licenses/by/3.0/");
|
||||
xml::add_element($doc, $root, "link", "", $attributes);
|
||||
XML::add_element($doc, $root, "link", "", $attributes);
|
||||
|
||||
$attributes = array("rel" => "alternate", "type" => "text/html", "href" => $alternatelink);
|
||||
xml::add_element($doc, $root, "link", "", $attributes);
|
||||
XML::add_element($doc, $root, "link", "", $attributes);
|
||||
|
||||
|
||||
if ($public) {
|
||||
|
@ -557,26 +557,26 @@ class DFRN
|
|||
ostatus::hublinks($doc, $root, $owner["nick"]);
|
||||
|
||||
$attributes = array("rel" => "salmon", "href" => System::baseUrl()."/salmon/".$owner["nick"]);
|
||||
xml::add_element($doc, $root, "link", "", $attributes);
|
||||
XML::add_element($doc, $root, "link", "", $attributes);
|
||||
|
||||
$attributes = array("rel" => "http://salmon-protocol.org/ns/salmon-replies", "href" => System::baseUrl()."/salmon/".$owner["nick"]);
|
||||
xml::add_element($doc, $root, "link", "", $attributes);
|
||||
XML::add_element($doc, $root, "link", "", $attributes);
|
||||
|
||||
$attributes = array("rel" => "http://salmon-protocol.org/ns/salmon-mention", "href" => System::baseUrl()."/salmon/".$owner["nick"]);
|
||||
xml::add_element($doc, $root, "link", "", $attributes);
|
||||
XML::add_element($doc, $root, "link", "", $attributes);
|
||||
}
|
||||
|
||||
// For backward compatibility we keep this element
|
||||
if ($owner['page-flags'] == PAGE_COMMUNITY) {
|
||||
xml::add_element($doc, $root, "dfrn:community", 1);
|
||||
XML::add_element($doc, $root, "dfrn:community", 1);
|
||||
}
|
||||
|
||||
// The former element is replaced by this one
|
||||
xml::add_element($doc, $root, "dfrn:account_type", $owner["account-type"]);
|
||||
XML::add_element($doc, $root, "dfrn:account_type", $owner["account-type"]);
|
||||
|
||||
/// @todo We need a way to transmit the different page flags like "PAGE_PRVGROUP"
|
||||
|
||||
xml::add_element($doc, $root, "updated", datetime_convert("UTC", "UTC", "now", ATOM_TIME));
|
||||
XML::add_element($doc, $root, "updated", datetime_convert("UTC", "UTC", "now", ATOM_TIME));
|
||||
|
||||
$author = self::add_author($doc, $owner, $authorelement, $public);
|
||||
$root->appendChild($author);
|
||||
|
@ -620,9 +620,9 @@ class DFRN
|
|||
$attributes = array("dfrn:updated" => $namdate);
|
||||
}
|
||||
|
||||
xml::add_element($doc, $author, "name", $owner["name"], $attributes);
|
||||
xml::add_element($doc, $author, "uri", System::baseUrl().'/profile/'.$owner["nickname"], $attributes);
|
||||
xml::add_element($doc, $author, "dfrn:handle", $owner["addr"], $attributes);
|
||||
XML::add_element($doc, $author, "name", $owner["name"], $attributes);
|
||||
XML::add_element($doc, $author, "uri", System::baseUrl().'/profile/'.$owner["nickname"], $attributes);
|
||||
XML::add_element($doc, $author, "dfrn:handle", $owner["addr"], $attributes);
|
||||
|
||||
$attributes = array("rel" => "photo", "type" => "image/jpeg",
|
||||
"media:width" => 175, "media:height" => 175, "href" => $owner['photo']);
|
||||
|
@ -631,13 +631,13 @@ class DFRN
|
|||
$attributes["dfrn:updated"] = $picdate;
|
||||
}
|
||||
|
||||
xml::add_element($doc, $author, "link", "", $attributes);
|
||||
XML::add_element($doc, $author, "link", "", $attributes);
|
||||
|
||||
$attributes["rel"] = "avatar";
|
||||
xml::add_element($doc, $author, "link", "", $attributes);
|
||||
XML::add_element($doc, $author, "link", "", $attributes);
|
||||
|
||||
if ($hidewall) {
|
||||
xml::add_element($doc, $author, "dfrn:hide", "true");
|
||||
XML::add_element($doc, $author, "dfrn:hide", "true");
|
||||
}
|
||||
|
||||
// The following fields will only be generated if the data isn't meant for a public feed
|
||||
|
@ -648,7 +648,7 @@ class DFRN
|
|||
$birthday = feed_birthday($owner['uid'], $owner['timezone']);
|
||||
|
||||
if ($birthday) {
|
||||
xml::add_element($doc, $author, "dfrn:birthday", $birthday);
|
||||
XML::add_element($doc, $author, "dfrn:birthday", $birthday);
|
||||
}
|
||||
|
||||
// Only show contact details when we are allowed to
|
||||
|
@ -664,60 +664,60 @@ class DFRN
|
|||
if (DBM::is_result($r)) {
|
||||
$profile = $r[0];
|
||||
|
||||
xml::add_element($doc, $author, "poco:displayName", $profile["name"]);
|
||||
xml::add_element($doc, $author, "poco:updated", $namdate);
|
||||
XML::add_element($doc, $author, "poco:displayName", $profile["name"]);
|
||||
XML::add_element($doc, $author, "poco:updated", $namdate);
|
||||
|
||||
if (trim($profile["dob"]) > '0001-01-01') {
|
||||
xml::add_element($doc, $author, "poco:birthday", "0000-".date("m-d", strtotime($profile["dob"])));
|
||||
XML::add_element($doc, $author, "poco:birthday", "0000-".date("m-d", strtotime($profile["dob"])));
|
||||
}
|
||||
|
||||
xml::add_element($doc, $author, "poco:note", $profile["about"]);
|
||||
xml::add_element($doc, $author, "poco:preferredUsername", $profile["nickname"]);
|
||||
XML::add_element($doc, $author, "poco:note", $profile["about"]);
|
||||
XML::add_element($doc, $author, "poco:preferredUsername", $profile["nickname"]);
|
||||
|
||||
$savetz = date_default_timezone_get();
|
||||
date_default_timezone_set($profile["timezone"]);
|
||||
xml::add_element($doc, $author, "poco:utcOffset", date("P"));
|
||||
XML::add_element($doc, $author, "poco:utcOffset", date("P"));
|
||||
date_default_timezone_set($savetz);
|
||||
|
||||
if (trim($profile["homepage"]) != "") {
|
||||
$urls = $doc->createElement("poco:urls");
|
||||
xml::add_element($doc, $urls, "poco:type", "homepage");
|
||||
xml::add_element($doc, $urls, "poco:value", $profile["homepage"]);
|
||||
xml::add_element($doc, $urls, "poco:primary", "true");
|
||||
XML::add_element($doc, $urls, "poco:type", "homepage");
|
||||
XML::add_element($doc, $urls, "poco:value", $profile["homepage"]);
|
||||
XML::add_element($doc, $urls, "poco:primary", "true");
|
||||
$author->appendChild($urls);
|
||||
}
|
||||
|
||||
if (trim($profile["pub_keywords"]) != "") {
|
||||
$keywords = explode(",", $profile["pub_keywords"]);
|
||||
|
||||
foreach ($keywords AS $keyword) {
|
||||
xml::add_element($doc, $author, "poco:tags", trim($keyword));
|
||||
foreach ($keywords as $keyword) {
|
||||
XML::add_element($doc, $author, "poco:tags", trim($keyword));
|
||||
}
|
||||
}
|
||||
|
||||
if (trim($profile["xmpp"]) != "") {
|
||||
$ims = $doc->createElement("poco:ims");
|
||||
xml::add_element($doc, $ims, "poco:type", "xmpp");
|
||||
xml::add_element($doc, $ims, "poco:value", $profile["xmpp"]);
|
||||
xml::add_element($doc, $ims, "poco:primary", "true");
|
||||
XML::add_element($doc, $ims, "poco:type", "xmpp");
|
||||
XML::add_element($doc, $ims, "poco:value", $profile["xmpp"]);
|
||||
XML::add_element($doc, $ims, "poco:primary", "true");
|
||||
$author->appendChild($ims);
|
||||
}
|
||||
|
||||
if (trim($profile["locality"].$profile["region"].$profile["country-name"]) != "") {
|
||||
$element = $doc->createElement("poco:address");
|
||||
|
||||
xml::add_element($doc, $element, "poco:formatted", formatted_location($profile));
|
||||
XML::add_element($doc, $element, "poco:formatted", formatted_location($profile));
|
||||
|
||||
if (trim($profile["locality"]) != "") {
|
||||
xml::add_element($doc, $element, "poco:locality", $profile["locality"]);
|
||||
XML::add_element($doc, $element, "poco:locality", $profile["locality"]);
|
||||
}
|
||||
|
||||
if (trim($profile["region"]) != "") {
|
||||
xml::add_element($doc, $element, "poco:region", $profile["region"]);
|
||||
XML::add_element($doc, $element, "poco:region", $profile["region"]);
|
||||
}
|
||||
|
||||
if (trim($profile["country-name"]) != "") {
|
||||
xml::add_element($doc, $element, "poco:country", $profile["country-name"]);
|
||||
XML::add_element($doc, $element, "poco:country", $profile["country-name"]);
|
||||
}
|
||||
|
||||
$author->appendChild($element);
|
||||
|
@ -744,9 +744,9 @@ class DFRN
|
|||
$contact = get_contact_details_by_url($contact_url, $item["uid"]);
|
||||
|
||||
$author = $doc->createElement($element);
|
||||
xml::add_element($doc, $author, "name", $contact["name"]);
|
||||
xml::add_element($doc, $author, "uri", $contact["url"]);
|
||||
xml::add_element($doc, $author, "dfrn:handle", $contact["addr"]);
|
||||
XML::add_element($doc, $author, "name", $contact["name"]);
|
||||
XML::add_element($doc, $author, "uri", $contact["url"]);
|
||||
XML::add_element($doc, $author, "dfrn:handle", $contact["addr"]);
|
||||
|
||||
/// @Todo
|
||||
/// - Check real image type and image size
|
||||
|
@ -757,7 +757,7 @@ class DFRN
|
|||
"media:width" => 80,
|
||||
"media:height" => 80,
|
||||
"href" => $contact["photo"]);
|
||||
xml::add_element($doc, $author, "link", "", $attributes);
|
||||
XML::add_element($doc, $author, "link", "", $attributes);
|
||||
|
||||
$attributes = array(
|
||||
"rel" => "avatar",
|
||||
|
@ -765,7 +765,7 @@ class DFRN
|
|||
"media:width" => 80,
|
||||
"media:height" => 80,
|
||||
"href" => $contact["photo"]);
|
||||
xml::add_element($doc, $author, "link", "", $attributes);
|
||||
XML::add_element($doc, $author, "link", "", $attributes);
|
||||
|
||||
return $author;
|
||||
}
|
||||
|
@ -790,13 +790,13 @@ class DFRN
|
|||
return false;
|
||||
}
|
||||
if ($r->type) {
|
||||
xml::add_element($doc, $entry, "activity:object-type", $r->type);
|
||||
XML::add_element($doc, $entry, "activity:object-type", $r->type);
|
||||
}
|
||||
if ($r->id) {
|
||||
xml::add_element($doc, $entry, "id", $r->id);
|
||||
XML::add_element($doc, $entry, "id", $r->id);
|
||||
}
|
||||
if ($r->title) {
|
||||
xml::add_element($doc, $entry, "title", $r->title);
|
||||
XML::add_element($doc, $entry, "title", $r->title);
|
||||
}
|
||||
|
||||
if ($r->link) {
|
||||
|
@ -812,19 +812,19 @@ class DFRN
|
|||
if (is_object($data)) {
|
||||
foreach ($data->link AS $link) {
|
||||
$attributes = array();
|
||||
foreach ($link->attributes() AS $parameter => $value) {
|
||||
foreach ($link->attributes() as $parameter => $value) {
|
||||
$attributes[$parameter] = $value;
|
||||
}
|
||||
xml::add_element($doc, $entry, "link", "", $attributes);
|
||||
XML::add_element($doc, $entry, "link", "", $attributes);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$attributes = array("rel" => "alternate", "type" => "text/html", "href" => $r->link);
|
||||
xml::add_element($doc, $entry, "link", "", $attributes);
|
||||
XML::add_element($doc, $entry, "link", "", $attributes);
|
||||
}
|
||||
}
|
||||
if ($r->content) {
|
||||
xml::add_element($doc, $entry, "content", bbcode($r->content), array("type" => "html"));
|
||||
XML::add_element($doc, $entry, "content", bbcode($r->content), array("type" => "html"));
|
||||
}
|
||||
|
||||
return $entry;
|
||||
|
@ -863,7 +863,7 @@ class DFRN
|
|||
$attributes["title"] = trim($matches[4]);
|
||||
}
|
||||
|
||||
xml::add_element($doc, $root, "link", "", $attributes);
|
||||
XML::add_element($doc, $root, "link", "", $attributes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -893,7 +893,7 @@ class DFRN
|
|||
|
||||
if ($item['deleted']) {
|
||||
$attributes = array("ref" => $item['uri'], "when" => datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', ATOM_TIME));
|
||||
return xml::create_element($doc, "at:deleted-entry", "", $attributes);
|
||||
return XML::create_element($doc, "at:deleted-entry", "", $attributes);
|
||||
}
|
||||
|
||||
if (!$single) {
|
||||
|
@ -944,7 +944,7 @@ class DFRN
|
|||
$attributes = array("ref" => $parent_item, "type" => "text/html",
|
||||
"href" => $parent[0]['plink'],
|
||||
"dfrn:diaspora_guid" => $parent[0]['guid']);
|
||||
xml::add_element($doc, $entry, "thr:in-reply-to", "", $attributes);
|
||||
XML::add_element($doc, $entry, "thr:in-reply-to", "", $attributes);
|
||||
}
|
||||
|
||||
// Add conversation data. This is used for OStatus
|
||||
|
@ -967,23 +967,23 @@ class DFRN
|
|||
"href" => $conversation_href,
|
||||
"ref" => $conversation_uri);
|
||||
|
||||
xml::add_element($doc, $entry, "ostatus:conversation", $conversation_uri, $attributes);
|
||||
XML::add_element($doc, $entry, "ostatus:conversation", $conversation_uri, $attributes);
|
||||
|
||||
xml::add_element($doc, $entry, "id", $item["uri"]);
|
||||
xml::add_element($doc, $entry, "title", $item["title"]);
|
||||
XML::add_element($doc, $entry, "id", $item["uri"]);
|
||||
XML::add_element($doc, $entry, "title", $item["title"]);
|
||||
|
||||
xml::add_element($doc, $entry, "published", datetime_convert("UTC", "UTC", $item["created"] . "+00:00", ATOM_TIME));
|
||||
xml::add_element($doc, $entry, "updated", datetime_convert("UTC", "UTC", $item["edited"] . "+00:00", ATOM_TIME));
|
||||
XML::add_element($doc, $entry, "published", datetime_convert("UTC", "UTC", $item["created"] . "+00:00", ATOM_TIME));
|
||||
XML::add_element($doc, $entry, "updated", datetime_convert("UTC", "UTC", $item["edited"] . "+00:00", ATOM_TIME));
|
||||
|
||||
// "dfrn:env" is used to read the content
|
||||
xml::add_element($doc, $entry, "dfrn:env", base64url_encode($body, true));
|
||||
XML::add_element($doc, $entry, "dfrn:env", base64url_encode($body, true));
|
||||
|
||||
// The "content" field is not read by the receiver. We could remove it when the type is "text"
|
||||
// We keep it at the moment, maybe there is some old version that doesn't read "dfrn:env"
|
||||
xml::add_element($doc, $entry, "content", (($type == 'html') ? $htmlbody : $body), array("type" => $type));
|
||||
XML::add_element($doc, $entry, "content", (($type == 'html') ? $htmlbody : $body), array("type" => $type));
|
||||
|
||||
// We save this value in "plink". Maybe we should read it from there as well?
|
||||
xml::add_element(
|
||||
XML::add_element(
|
||||
$doc,
|
||||
$entry,
|
||||
"link",
|
||||
|
@ -995,50 +995,50 @@ class DFRN
|
|||
// "comment-allow" is some old fashioned stuff for old Friendica versions.
|
||||
// It is included in the rewritten code for completeness
|
||||
if ($comment) {
|
||||
xml::add_element($doc, $entry, "dfrn:comment-allow", intval($item['last-child']));
|
||||
XML::add_element($doc, $entry, "dfrn:comment-allow", intval($item['last-child']));
|
||||
}
|
||||
|
||||
if ($item['location']) {
|
||||
xml::add_element($doc, $entry, "dfrn:location", $item['location']);
|
||||
XML::add_element($doc, $entry, "dfrn:location", $item['location']);
|
||||
}
|
||||
|
||||
if ($item['coord']) {
|
||||
xml::add_element($doc, $entry, "georss:point", $item['coord']);
|
||||
XML::add_element($doc, $entry, "georss:point", $item['coord']);
|
||||
}
|
||||
|
||||
if (($item['private']) || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) {
|
||||
xml::add_element($doc, $entry, "dfrn:private", (($item['private']) ? $item['private'] : 1));
|
||||
XML::add_element($doc, $entry, "dfrn:private", (($item['private']) ? $item['private'] : 1));
|
||||
}
|
||||
|
||||
if ($item['extid']) {
|
||||
xml::add_element($doc, $entry, "dfrn:extid", $item['extid']);
|
||||
XML::add_element($doc, $entry, "dfrn:extid", $item['extid']);
|
||||
}
|
||||
|
||||
if ($item['bookmark']) {
|
||||
xml::add_element($doc, $entry, "dfrn:bookmark", "true");
|
||||
XML::add_element($doc, $entry, "dfrn:bookmark", "true");
|
||||
}
|
||||
|
||||
if ($item['app']) {
|
||||
xml::add_element($doc, $entry, "statusnet:notice_info", "", array("local_id" => $item['id'], "source" => $item['app']));
|
||||
XML::add_element($doc, $entry, "statusnet:notice_info", "", array("local_id" => $item['id'], "source" => $item['app']));
|
||||
}
|
||||
|
||||
xml::add_element($doc, $entry, "dfrn:diaspora_guid", $item["guid"]);
|
||||
XML::add_element($doc, $entry, "dfrn:diaspora_guid", $item["guid"]);
|
||||
|
||||
// The signed text contains the content in Markdown, the sender handle and the signatur for the content
|
||||
// It is needed for relayed comments to Diaspora.
|
||||
if ($item['signed_text']) {
|
||||
$sign = base64_encode(json_encode(array('signed_text' => $item['signed_text'],'signature' => $item['signature'],'signer' => $item['signer'])));
|
||||
xml::add_element($doc, $entry, "dfrn:diaspora_signature", $sign);
|
||||
XML::add_element($doc, $entry, "dfrn:diaspora_signature", $sign);
|
||||
}
|
||||
|
||||
xml::add_element($doc, $entry, "activity:verb", construct_verb($item));
|
||||
XML::add_element($doc, $entry, "activity:verb", construct_verb($item));
|
||||
|
||||
if ($item['object-type'] != "") {
|
||||
xml::add_element($doc, $entry, "activity:object-type", $item['object-type']);
|
||||
XML::add_element($doc, $entry, "activity:object-type", $item['object-type']);
|
||||
} elseif ($item['id'] == $item['parent']) {
|
||||
xml::add_element($doc, $entry, "activity:object-type", ACTIVITY_OBJ_NOTE);
|
||||
XML::add_element($doc, $entry, "activity:object-type", ACTIVITY_OBJ_NOTE);
|
||||
} else {
|
||||
xml::add_element($doc, $entry, "activity:object-type", ACTIVITY_OBJ_COMMENT);
|
||||
XML::add_element($doc, $entry, "activity:object-type", ACTIVITY_OBJ_COMMENT);
|
||||
}
|
||||
|
||||
$actobj = self::create_activity($doc, "activity:object", $item['object']);
|
||||
|
@ -1056,7 +1056,7 @@ class DFRN
|
|||
if (count($tags)) {
|
||||
foreach ($tags as $t) {
|
||||
if (($type != 'html') || ($t[0] != "@")) {
|
||||
xml::add_element($doc, $entry, "category", "", array("scheme" => "X-DFRN:".$t[0].":".$t[1], "term" => $t[2]));
|
||||
XML::add_element($doc, $entry, "category", "", array("scheme" => "X-DFRN:".$t[0].":".$t[1], "term" => $t[2]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1069,7 +1069,7 @@ class DFRN
|
|||
}
|
||||
}
|
||||
|
||||
foreach ($mentioned AS $mention) {
|
||||
foreach ($mentioned as $mention) {
|
||||
$r = q(
|
||||
"SELECT `forum`, `prv` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s'",
|
||||
intval($owner["uid"]),
|
||||
|
@ -1077,7 +1077,7 @@ class DFRN
|
|||
);
|
||||
|
||||
if (DBM::is_result($r) && ($r[0]["forum"] || $r[0]["prv"])) {
|
||||
xml::add_element(
|
||||
XML::add_element(
|
||||
$doc,
|
||||
$entry,
|
||||
"link",
|
||||
|
@ -1087,7 +1087,7 @@ class DFRN
|
|||
"href" => $mention)
|
||||
);
|
||||
} else {
|
||||
xml::add_element(
|
||||
XML::add_element(
|
||||
$doc,
|
||||
$entry,
|
||||
"link",
|
||||
|
@ -1705,7 +1705,7 @@ class DFRN
|
|||
$obj_element = $obj_doc->createElementNS(NAMESPACE_ATOM1, $element);
|
||||
|
||||
$activity_type = $xpath->query("activity:object-type/text()", $activity)->item(0)->nodeValue;
|
||||
xml::add_element($obj_doc, $obj_element, "type", $activity_type);
|
||||
XML::add_element($obj_doc, $obj_element, "type", $activity_type);
|
||||
|
||||
$id = $xpath->query("atom:id", $activity)->item(0);
|
||||
if (is_object($id)) {
|
||||
|
@ -1719,7 +1719,7 @@ class DFRN
|
|||
|
||||
$links = $xpath->query("atom:link", $activity);
|
||||
if (is_object($links)) {
|
||||
foreach ($links AS $link) {
|
||||
foreach ($links as $link) {
|
||||
$obj_element->appendChild($obj_doc->importNode($link, true));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,10 +17,10 @@ use Friendica\Core\PConfig;
|
|||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBM;
|
||||
use Friendica\Network\Probe;
|
||||
use Friendica\Util\XML;
|
||||
|
||||
use dba;
|
||||
use SimpleXMLElement;
|
||||
use xml;
|
||||
|
||||
require_once 'include/items.php';
|
||||
require_once 'include/bb2diaspora.php';
|
||||
|
@ -672,7 +672,7 @@ class Diaspora
|
|||
if (!in_array($fieldname, array("parent_author_signature", "target_author_signature"))
|
||||
|| ($orig_type == "relayable_retraction")
|
||||
) {
|
||||
xml::copy($entry, $fields, $fieldname);
|
||||
XML::copy($entry, $fields, $fieldname);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1912,7 +1912,7 @@ class Diaspora
|
|||
"title" => "",
|
||||
"content" => $parent_body));
|
||||
|
||||
return xml::from_array($xmldata, $xml, true);
|
||||
return XML::from_array($xmldata, $xml, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2344,7 +2344,7 @@ class Diaspora
|
|||
"id" => $contact["url"]."/".$contact["name"],
|
||||
"link" => $link));
|
||||
|
||||
return xml::from_array($xmldata, $xml, true);
|
||||
return XML::from_array($xmldata, $xml, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3039,7 +3039,7 @@ class Diaspora
|
|||
|
||||
$namespaces = array("me" => "http://salmon-protocol.org/ns/magic-env");
|
||||
|
||||
return xml::from_array($xmldata, $xml, false, $namespaces);
|
||||
return XML::from_array($xmldata, $xml, false, $namespaces);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3172,7 +3172,7 @@ class Diaspora
|
|||
{
|
||||
$data = array($type => $message);
|
||||
|
||||
return xml::from_array($data, $xml);
|
||||
return XML::from_array($data, $xml);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,31 +1,34 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file include/xml.php
|
||||
* @file src/Util/XML.php
|
||||
*/
|
||||
namespace Friendica\Util;
|
||||
|
||||
use DomXPath;
|
||||
use SimpleXMLElement;
|
||||
|
||||
/**
|
||||
* @brief This class contain methods to work with XML data
|
||||
*
|
||||
*/
|
||||
class xml {
|
||||
class XML
|
||||
{
|
||||
/**
|
||||
* @brief Creates an XML structure out of a given array
|
||||
*
|
||||
* @param array $array The array of the XML structure that will be generated
|
||||
* @param object $xml The createdXML will be returned by reference
|
||||
* @param bool $remove_header Should the XML header be removed or not?
|
||||
* @param array $namespaces List of namespaces
|
||||
* @param bool $root - interally used parameter. Mustn't be used from outside.
|
||||
* @param array $array The array of the XML structure that will be generated
|
||||
* @param object $xml The createdXML will be returned by reference
|
||||
* @param bool $remove_header Should the XML header be removed or not?
|
||||
* @param array $namespaces List of namespaces
|
||||
* @param bool $root interally used parameter. Mustn't be used from outside.
|
||||
*
|
||||
* @return string The created XML
|
||||
*/
|
||||
public static function from_array($array, &$xml, $remove_header = false, $namespaces = array(), $root = true) {
|
||||
|
||||
public static function from_array($array, &$xml, $remove_header = false, $namespaces = array(), $root = true)
|
||||
{
|
||||
if ($root) {
|
||||
foreach ($array as $key => $value) {
|
||||
foreach ($namespaces AS $nskey => $nsvalue) {
|
||||
foreach ($namespaces as $nskey => $nsvalue) {
|
||||
$key .= " xmlns".($nskey == "" ? "":":").$nskey.'="'.$nsvalue.'"';
|
||||
}
|
||||
|
||||
|
@ -50,7 +53,7 @@ class xml {
|
|||
}
|
||||
}
|
||||
|
||||
foreach($array as $key => $value) {
|
||||
foreach ($array as $key => $value) {
|
||||
if (!isset($element) && isset($xml)) {
|
||||
$element = $xml;
|
||||
}
|
||||
|
@ -72,7 +75,7 @@ class xml {
|
|||
} elseif (isset($namespaces[""])) {
|
||||
$namespace = $namespaces[""];
|
||||
} else {
|
||||
$namespace = NULL;
|
||||
$namespace = null;
|
||||
}
|
||||
|
||||
// Remove undefined namespaces from the key
|
||||
|
@ -90,7 +93,7 @@ class xml {
|
|||
if ((count($element_parts) > 1) && isset($namespaces[$element_parts[0]])) {
|
||||
$namespace = $namespaces[$element_parts[0]];
|
||||
} else {
|
||||
$namespace = NULL;
|
||||
$namespace = null;
|
||||
}
|
||||
|
||||
$element->addAttribute($attr_key, $attr_value, $namespace);
|
||||
|
@ -102,7 +105,7 @@ class xml {
|
|||
if (!is_array($value)) {
|
||||
$element = $xml->addChild($key, xmlify($value), $namespace);
|
||||
} elseif (is_array($value)) {
|
||||
$element = $xml->addChild($key, NULL, $namespace);
|
||||
$element = $xml->addChild($key, null, $namespace);
|
||||
self::from_array($value, $element, $remove_header, $namespaces, false);
|
||||
}
|
||||
}
|
||||
|
@ -111,16 +114,17 @@ class xml {
|
|||
/**
|
||||
* @brief Copies an XML object
|
||||
*
|
||||
* @param object $source The XML source
|
||||
* @param object $target The XML target
|
||||
* @param object $source The XML source
|
||||
* @param object $target The XML target
|
||||
* @param string $elementname Name of the XML element of the target
|
||||
*/
|
||||
public static function copy(&$source, &$target, $elementname) {
|
||||
if (count($source->children()) == 0)
|
||||
public static function copy(&$source, &$target, $elementname)
|
||||
{
|
||||
if (count($source->children()) == 0) {
|
||||
$target->addChild($elementname, xmlify($source));
|
||||
else {
|
||||
} else {
|
||||
$child = $target->addChild($elementname);
|
||||
foreach ($source->children() AS $childfield => $childentry) {
|
||||
foreach ($source->children() as $childfield => $childentry) {
|
||||
self::copy($childentry, $child, $childfield);
|
||||
}
|
||||
}
|
||||
|
@ -129,17 +133,18 @@ class xml {
|
|||
/**
|
||||
* @brief Create an XML element
|
||||
*
|
||||
* @param object $doc XML root
|
||||
* @param string $element XML element name
|
||||
* @param string $value XML value
|
||||
* @param array $attributes array containing the attributes
|
||||
* @param object $doc XML root
|
||||
* @param string $element XML element name
|
||||
* @param string $value XML value
|
||||
* @param array $attributes array containing the attributes
|
||||
*
|
||||
* @return object XML element object
|
||||
*/
|
||||
public static function create_element($doc, $element, $value = "", $attributes = array()) {
|
||||
public static function create_element($doc, $element, $value = "", $attributes = array())
|
||||
{
|
||||
$element = $doc->createElement($element, xmlify($value));
|
||||
|
||||
foreach ($attributes AS $key => $value) {
|
||||
foreach ($attributes as $key => $value) {
|
||||
$attribute = $doc->createAttribute($key);
|
||||
$attribute->value = xmlify($value);
|
||||
$element->appendChild($attribute);
|
||||
|
@ -150,13 +155,14 @@ class xml {
|
|||
/**
|
||||
* @brief Create an XML and append it to the parent object
|
||||
*
|
||||
* @param object $doc XML root
|
||||
* @param object $parent parent object
|
||||
* @param string $element XML element name
|
||||
* @param string $value XML value
|
||||
* @param array $attributes array containing the attributes
|
||||
* @param object $doc XML root
|
||||
* @param object $parent parent object
|
||||
* @param string $element XML element name
|
||||
* @param string $value XML value
|
||||
* @param array $attributes array containing the attributes
|
||||
*/
|
||||
public static function add_element($doc, $parent, $element, $value = "", $attributes = array()) {
|
||||
public static function add_element($doc, $parent, $element, $value = "", $attributes = array())
|
||||
{
|
||||
$element = self::create_element($doc, $element, $value, $attributes);
|
||||
$parent->appendChild($element);
|
||||
}
|
||||
|
@ -165,14 +171,14 @@ class xml {
|
|||
* @brief Convert an XML document to a normalised, case-corrected array
|
||||
* used by webfinger
|
||||
*
|
||||
* @param object $xml_element The XML document
|
||||
* @param object $xml_element The XML document
|
||||
* @param integer $recursion_depth recursion counter for internal use - default 0
|
||||
* internal use, recursion counter
|
||||
* internal use, recursion counter
|
||||
*
|
||||
* @return array | sring The array from the xml element or the string
|
||||
*/
|
||||
public static function element_to_array($xml_element, &$recursion_depth=0) {
|
||||
|
||||
public static function element_to_array($xml_element, &$recursion_depth=0)
|
||||
{
|
||||
// If we're getting too deep, bail out
|
||||
if ($recursion_depth > 512) {
|
||||
return(null);
|
||||
|
@ -180,7 +186,8 @@ class xml {
|
|||
|
||||
if (!is_string($xml_element)
|
||||
&& !is_array($xml_element)
|
||||
&& (get_class($xml_element) == 'SimpleXMLElement')) {
|
||||
&& (get_class($xml_element) == 'SimpleXMLElement')
|
||||
) {
|
||||
$xml_element_copy = $xml_element;
|
||||
$xml_element = get_object_vars($xml_element);
|
||||
}
|
||||
|
@ -192,12 +199,11 @@ class xml {
|
|||
}
|
||||
|
||||
foreach ($xml_element as $key => $value) {
|
||||
|
||||
$recursion_depth++;
|
||||
$result_array[strtolower($key)] =
|
||||
self::element_to_array($value, $recursion_depth);
|
||||
$result_array[strtolower($key)] = self::element_to_array($value, $recursion_depth);
|
||||
$recursion_depth--;
|
||||
}
|
||||
|
||||
if ($recursion_depth == 0) {
|
||||
$temp_array = $result_array;
|
||||
$result_array = array(
|
||||
|
@ -206,7 +212,6 @@ class xml {
|
|||
}
|
||||
|
||||
return ($result_array);
|
||||
|
||||
} else {
|
||||
return (trim(strval($xml_element)));
|
||||
}
|
||||
|
@ -215,31 +220,32 @@ class xml {
|
|||
/**
|
||||
* @brief Convert the given XML text to an array in the XML structure.
|
||||
*
|
||||
* xml::to_array() will convert the given XML text to an array in the XML structure.
|
||||
* Xml::to_array() will convert the given XML text to an array in the XML structure.
|
||||
* 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...)
|
||||
*
|
||||
* Examples: $array = xml::to_array(file_get_contents('feed.xml'));
|
||||
* $array = xml::to_array(file_get_contents('feed.xml', true, 1, 'attribute'));
|
||||
* Examples: $array = Xml::to_array(file_get_contents('feed.xml'));
|
||||
* $array = Xml::to_array(file_get_contents('feed.xml', true, 1, 'attribute'));
|
||||
*
|
||||
* @param object $contents The XML text
|
||||
* @param boolean $namespaces True or false include namespace information
|
||||
* in the returned array as array elements.
|
||||
* @param object $contents The XML text
|
||||
* @param boolean $namespaces True or false include namespace information
|
||||
* in the returned array as array elements.
|
||||
* @param integer $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.
|
||||
* 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.
|
||||
*/
|
||||
public static function to_array($contents, $namespaces = true, $get_attributes = 1, $priority = 'attribute') {
|
||||
public static function to_array($contents, $namespaces = true, $get_attributes = 1, $priority = 'attribute')
|
||||
{
|
||||
if (!$contents) {
|
||||
return array();
|
||||
}
|
||||
|
||||
if (!function_exists('xml_parser_create')) {
|
||||
logger('xml::to_array: parser function missing');
|
||||
logger('Xml::to_array: parser function missing');
|
||||
return array();
|
||||
}
|
||||
|
||||
|
@ -248,13 +254,13 @@ class xml {
|
|||
libxml_clear_errors();
|
||||
|
||||
if ($namespaces) {
|
||||
$parser = @xml_parser_create_ns("UTF-8",':');
|
||||
$parser = @xml_parser_create_ns("UTF-8", ':');
|
||||
} else {
|
||||
$parser = @xml_parser_create();
|
||||
}
|
||||
|
||||
if (! $parser) {
|
||||
logger('xml::to_array: xml_parser_create: no resource');
|
||||
logger('Xml::to_array: xml_parser_create: no resource');
|
||||
return array();
|
||||
}
|
||||
|
||||
|
@ -266,7 +272,7 @@ class xml {
|
|||
@xml_parser_free($parser);
|
||||
|
||||
if (! $xml_values) {
|
||||
logger('xml::to_array: libxml: parse error: ' . $contents, LOGGER_DATA);
|
||||
logger('Xml::to_array: libxml: parse error: ' . $contents, LOGGER_DATA);
|
||||
foreach (libxml_get_errors() as $err) {
|
||||
logger('libxml: parse: ' . $err->code . " at " . $err->line . ":" . $err->column . " : " . $err->message, LOGGER_DATA);
|
||||
}
|
||||
|
@ -305,7 +311,7 @@ class xml {
|
|||
//Set the attributes too.
|
||||
if (isset($attributes) and $get_attributes) {
|
||||
foreach ($attributes as $attr => $val) {
|
||||
if($priority == 'tag') {
|
||||
if ($priority == 'tag') {
|
||||
$attributes_data[$attr] = $val;
|
||||
} else {
|
||||
$result['@attributes'][$attr] = $val; // Set all the attributes in a array called 'attr'
|
||||
|
@ -331,7 +337,6 @@ class xml {
|
|||
$repeated_tag_index[$tag.'_'.$level] = 1;
|
||||
|
||||
$current = &$current[$tag];
|
||||
|
||||
} else { // There was another element with the same tag name
|
||||
|
||||
if (isset($current[$tag][0])) { // If there is a 0th element it is already an array
|
||||
|
@ -345,12 +350,10 @@ class xml {
|
|||
$current[$tag]['0_attr'] = $current[$tag.'_attr'];
|
||||
unset($current[$tag.'_attr']);
|
||||
}
|
||||
|
||||
}
|
||||
$last_item_index = $repeated_tag_index[$tag.'_'.$level]-1;
|
||||
$current = &$current[$tag][$last_item_index];
|
||||
}
|
||||
|
||||
} elseif ($type == "complete") { // Tags that ends in 1 line '<tag />'
|
||||
//See if the key is already taken.
|
||||
if (!isset($current[$tag])) { //New Key
|
||||
|
@ -359,7 +362,6 @@ class xml {
|
|||
if ($priority == 'tag' and $attributes_data) {
|
||||
$current[$tag. '_attr'] = $attributes_data;
|
||||
}
|
||||
|
||||
} 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...
|
||||
|
||||
|
@ -370,7 +372,6 @@ class xml {
|
|||
$current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data;
|
||||
}
|
||||
$repeated_tag_index[$tag.'_'.$level]++;
|
||||
|
||||
} 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
|
||||
$repeated_tag_index[$tag.'_'.$level] = 1;
|
||||
|
@ -388,7 +389,6 @@ class xml {
|
|||
$repeated_tag_index[$tag.'_'.$level]++; // 0 and 1 indexes are already taken
|
||||
}
|
||||
}
|
||||
|
||||
} elseif ($type == 'close') { // End of tag '</tag>'
|
||||
$current = &$parent[$level-1];
|
||||
}
|
||||
|
@ -400,10 +400,11 @@ class xml {
|
|||
/**
|
||||
* @brief Delete a node in a XML object
|
||||
*
|
||||
* @param object $doc XML document
|
||||
* @param object $doc XML document
|
||||
* @param string $node Node name
|
||||
*/
|
||||
public static function deleteNode(&$doc, $node) {
|
||||
public static function deleteNode(&$doc, $node)
|
||||
{
|
||||
$xpath = new DomXPath($doc);
|
||||
$list = $xpath->query("//".$node);
|
||||
foreach ($list as $child) {
|
Loading…
Reference in New Issue
Block a user