use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Protocol\Diaspora;
-use Friendica\Util\Xml;
+use Friendica\Util\XML;
require_once 'include/HTTPExceptions.php';
require_once 'include/bbcode.php';
$data3 = array($root_element => $data2);
- $ret = Xml::from_array($data3, $xml, false, $namespaces);
+ $ret = XML::from_array($data3, $xml, false, $namespaces);
return $ret;
}
* https://github.com/annando/Syncom
*/
-use Friendica\Util\Xml;
-
+use Friendica\Util\XML;
function node2bbcode(&$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;
$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;
+ }
}
}
@$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");
use Friendica\Core\System;
use Friendica\Core\Config;
use Friendica\Network\Probe;
-use Friendica\Util\Xml;
+use Friendica\Util\XML;
/**
* @brief Curl wrapper
$xmldata = array("result" => $result);
- echo Xml::from_array($xmldata, $xml);
+ echo XML::from_array($xmldata, $xml);
killme();
}
* Checks if the provided url domain is on the domain blocklist.
* Returns true if it is or malformed URL, false if not.
*
- * @param string $url The url to check the domain from
+ * @param string $url The url to check the domain from
+ *
* @return boolean
*/
function blocked_url($url)
use Friendica\Database\DBM;
use Friendica\Network\Probe;
use Friendica\Util\Lock;
-use Friendica\Util\Xml;
+use Friendica\Util\XML;
require_once 'include/Contact.php';
require_once 'include/threads.php';
$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;
}
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"));
}
/**
"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",
"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;
"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']);
if (trim($matches[4]) != "") {
$attributes["title"] = trim($matches[4]);
}
- Xml::add_element($doc, $root, "link", "", $attributes);
+ XML::add_element($doc, $root, "link", "", $attributes);
}
}
}
$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",
"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(
"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;
}
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;
}
$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);
$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"]);
);
$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");
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",
"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);
}
$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);
$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']);
$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));
}
/**
$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) {
}
}
- 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);
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,
}
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]));
}
}
}
}
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);
}
}
* @file include/salmon.php
*/
use Friendica\Network\Probe;
-use Friendica\Util\Xml;
+use Friendica\Util\XML;
require_once 'include/crypto.php';
$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(
$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(
$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();
}
use Friendica\App;
use Friendica\Core\System;
use Friendica\Protocol\Diaspora;
-use Friendica\Util\Xml;
+use Friendica\Util\XML;
require_once "include/crypto.php";
use Friendica\Core\System;
use Friendica\Core\PConfig;
use Friendica\Database\DBM;
-use Friendica\Util\Xml;
+use Friendica\Util\XML;
require_once 'include/datetime.php';
require_once 'include/bbcode.php';
}
} else {
header("Content-type: text/xml");
- echo Xml::from_array($data, $xml);
+ echo XML::from_array($data, $xml);
}
killme();
}
$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();
use Friendica\Core\Cache;
use Friendica\Core\Config;
use Friendica\Database\DBM;
-use Friendica\Util\Xml;
+use Friendica\Util\XML;
use dba;
use DomXPath;
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();
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;
namespace Friendica;
use Friendica\Core\Config;
-use Friendica\Util\Xml;
+use Friendica\Util\XML;
use dba;
use DomXPath;
$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);
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
-use Friendica\Util\Xml;
+use Friendica\Util\XML;
use dba;
use DOMDocument;
$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);
$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);
$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);
$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) {
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);
$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']);
$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
$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
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);
$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
"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",
"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;
}
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) {
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;
$attributes["title"] = trim($matches[4]);
}
- Xml::add_element($doc, $root, "link", "", $attributes);
+ XML::add_element($doc, $root, "link", "", $attributes);
}
}
}
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) {
$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
"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",
// "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']);
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]));
}
}
}
}
}
- foreach ($mentioned AS $mention) {
+ foreach ($mentioned as $mention) {
$r = q(
"SELECT `forum`, `prv` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s'",
intval($owner["uid"]),
);
if (DBM::is_result($r) && ($r[0]["forum"] || $r[0]["prv"])) {
- Xml::add_element(
+ XML::add_element(
$doc,
$entry,
"link",
"href" => $mention)
);
} else {
- Xml::add_element(
+ XML::add_element(
$doc,
$entry,
"link",
$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)) {
use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Network\Probe;
-use Friendica\Util\Xml;
+use Friendica\Util\XML;
use dba;
use SimpleXMLElement;
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);
}
}
"title" => "",
"content" => $parent_body));
- return Xml::from_array($xmldata, $xml, true);
+ return XML::from_array($xmldata, $xml, true);
}
/**
"id" => $contact["url"]."/".$contact["name"],
"link" => $link));
- return Xml::from_array($xmldata, $xml, true);
+ return XML::from_array($xmldata, $xml, true);
}
/**
$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);
}
/**
{
$data = array($type => $message);
- return Xml::from_array($data, $xml);
+ return XML::from_array($data, $xml);
}
/**
--- /dev/null
+<?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
+{
+ /**
+ * @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.
+ *
+ * @return string The created XML
+ */
+ 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) {
+ $key .= " xmlns".($nskey == "" ? "":":").$nskey.'="'.$nsvalue.'"';
+ }
+
+ if (is_array($value)) {
+ $root = new SimpleXMLElement("<".$key."/>");
+ self::from_array($value, $root, $remove_header, $namespaces, false);
+ } else {
+ $root = new SimpleXMLElement("<".$key.">".xmlify($value)."</".$key.">");
+ }
+
+ $dom = dom_import_simplexml($root)->ownerDocument;
+ $dom->formatOutput = true;
+ $xml = $dom;
+
+ $xml_text = $dom->saveXML();
+
+ if ($remove_header) {
+ $xml_text = trim(substr($xml_text, 21));
+ }
+
+ return $xml_text;
+ }
+ }
+
+ foreach ($array as $key => $value) {
+ if (!isset($element) && isset($xml)) {
+ $element = $xml;
+ }
+
+ if (is_integer($key)) {
+ if (isset($element)) {
+ if (is_scalar($value)) {
+ $element[0] = $value;
+ } else {
+ /// @todo: handle nested array values
+ }
+ }
+ continue;
+ }
+
+ $element_parts = explode(":", $key);
+ if ((count($element_parts) > 1) && isset($namespaces[$element_parts[0]])) {
+ $namespace = $namespaces[$element_parts[0]];
+ } elseif (isset($namespaces[""])) {
+ $namespace = $namespaces[""];
+ } else {
+ $namespace = null;
+ }
+
+ // Remove undefined namespaces from the key
+ if ((count($element_parts) > 1) && is_null($namespace)) {
+ $key = $element_parts[1];
+ }
+
+ if (substr($key, 0, 11) == "@attributes") {
+ if (!isset($element) || !is_array($value)) {
+ continue;
+ }
+
+ foreach ($value as $attr_key => $attr_value) {
+ $element_parts = explode(":", $attr_key);
+ if ((count($element_parts) > 1) && isset($namespaces[$element_parts[0]])) {
+ $namespace = $namespaces[$element_parts[0]];
+ } else {
+ $namespace = null;
+ }
+
+ $element->addAttribute($attr_key, $attr_value, $namespace);
+ }
+
+ continue;
+ }
+
+ if (!is_array($value)) {
+ $element = $xml->addChild($key, xmlify($value), $namespace);
+ } elseif (is_array($value)) {
+ $element = $xml->addChild($key, null, $namespace);
+ self::from_array($value, $element, $remove_header, $namespaces, false);
+ }
+ }
+ }
+
+ /**
+ * @brief Copies an XML object
+ *
+ * @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) {
+ $target->addChild($elementname, xmlify($source));
+ } else {
+ $child = $target->addChild($elementname);
+ foreach ($source->children() as $childfield => $childentry) {
+ self::copy($childentry, $child, $childfield);
+ }
+ }
+ }
+
+ /**
+ * @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
+ *
+ * @return object XML element object
+ */
+ public static function create_element($doc, $element, $value = "", $attributes = array())
+ {
+ $element = $doc->createElement($element, xmlify($value));
+
+ foreach ($attributes as $key => $value) {
+ $attribute = $doc->createAttribute($key);
+ $attribute->value = xmlify($value);
+ $element->appendChild($attribute);
+ }
+ return $element;
+ }
+
+ /**
+ * @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
+ */
+ public static function add_element($doc, $parent, $element, $value = "", $attributes = array())
+ {
+ $element = self::create_element($doc, $element, $value, $attributes);
+ $parent->appendChild($element);
+ }
+
+ /**
+ * @brief Convert an XML document to a normalised, case-corrected array
+ * used by webfinger
+ *
+ * @param object $xml_element The XML document
+ * @param integer $recursion_depth recursion counter for internal use - default 0
+ * 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)
+ {
+ // If we're getting too deep, bail out
+ if ($recursion_depth > 512) {
+ return(null);
+ }
+
+ if (!is_string($xml_element)
+ && !is_array($xml_element)
+ && (get_class($xml_element) == 'SimpleXMLElement')
+ ) {
+ $xml_element_copy = $xml_element;
+ $xml_element = get_object_vars($xml_element);
+ }
+
+ if (is_array($xml_element)) {
+ $result_array = array();
+ if (count($xml_element) <= 0) {
+ return (trim(strval($xml_element_copy)));
+ }
+
+ foreach ($xml_element as $key => $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(
+ strtolower($xml_element_copy->getName()) => $temp_array,
+ );
+ }
+
+ return ($result_array);
+ } else {
+ return (trim(strval($xml_element)));
+ }
+ }
+
+ /**
+ * @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.
+ * 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'));
+ *
+ * @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.
+ *
+ * @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')
+ {
+ if (!$contents) {
+ return array();
+ }
+
+ if (!function_exists('xml_parser_create')) {
+ logger('Xml::to_array: parser function missing');
+ return array();
+ }
+
+
+ libxml_use_internal_errors(true);
+ libxml_clear_errors();
+
+ if ($namespaces) {
+ $parser = @xml_parser_create_ns("UTF-8", ':');
+ } else {
+ $parser = @xml_parser_create();
+ }
+
+ if (! $parser) {
+ logger('Xml::to_array: xml_parser_create: no resource');
+ return array();
+ }
+
+ xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8");
+ // http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss
+ xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
+ xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
+ @xml_parse_into_struct($parser, trim($contents), $xml_values);
+ @xml_parser_free($parser);
+
+ if (! $xml_values) {
+ 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);
+ }
+ libxml_clear_errors();
+ return;
+ }
+
+ //Initializations
+ $xml_array = array();
+ $parents = array();
+ $opened_tags = array();
+ $arr = array();
+
+ $current = &$xml_array; // Reference
+
+ // Go through the tags.
+ $repeated_tag_index = array(); // Multiple tags with same name will be turned into an array
+ foreach ($xml_values as $data) {
+ unset($attributes, $value); // Remove existing values, or there will be trouble
+
+ // This command will extract these variables into the foreach scope
+ // tag(string), type(string), level(int), attributes(array).
+ extract($data); // We could use the array by itself, but this cooler.
+
+ $result = array();
+ $attributes_data = array();
+
+ if (isset($value)) {
+ if ($priority == 'tag') {
+ $result = $value;
+ } else {
+ $result['value'] = $value; // Put the value in a assoc array if we are in the 'Attribute' mode
+ }
+ }
+
+ //Set the attributes too.
+ if (isset($attributes) and $get_attributes) {
+ foreach ($attributes as $attr => $val) {
+ if ($priority == 'tag') {
+ $attributes_data[$attr] = $val;
+ } else {
+ $result['@attributes'][$attr] = $val; // Set all the attributes in a array called 'attr'
+ }
+ }
+ }
+
+ // See tag status and do the needed.
+ if ($namespaces && strpos($tag, ':')) {
+ $namespc = substr($tag, 0, strrpos($tag, ':'));
+ $tag = strtolower(substr($tag, strlen($namespc)+1));
+ $result['@namespace'] = $namespc;
+ }
+ $tag = strtolower($tag);
+
+ if ($type == "open") { // The starting of the tag '<tag>'
+ $parent[$level-1] = &$current;
+ if (!is_array($current) || (!in_array($tag, array_keys($current)))) { // Insert New tag
+ $current[$tag] = $result;
+ if ($attributes_data) {
+ $current[$tag. '_attr'] = $attributes_data;
+ }
+ $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
+ $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result;
+ $repeated_tag_index[$tag.'_'.$level]++;
+ } else { // This section will make the value an array if multiple tags with the same name appear together
+ $current[$tag] = array($current[$tag], $result); // This will combine the existing item and the new item together to make an array
+ $repeated_tag_index[$tag.'_'.$level] = 2;
+
+ if (isset($current[$tag.'_attr'])) { // The attribute of the last(0th) tag must be moved as well
+ $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
+ $current[$tag] = $result;
+ $repeated_tag_index[$tag.'_'.$level] = 1;
+ 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...
+
+ // ...push the new element into that array.
+ $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result;
+
+ if ($priority == 'tag' and $get_attributes and $attributes_data) {
+ $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;
+ if ($priority == 'tag' and $get_attributes) {
+ if (isset($current[$tag.'_attr'])) { // The attribute of the last(0th) tag must be moved as well
+
+ $current[$tag]['0_attr'] = $current[$tag.'_attr'];
+ unset($current[$tag.'_attr']);
+ }
+
+ if ($attributes_data) {
+ $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data;
+ }
+ }
+ $repeated_tag_index[$tag.'_'.$level]++; // 0 and 1 indexes are already taken
+ }
+ }
+ } elseif ($type == 'close') { // End of tag '</tag>'
+ $current = &$parent[$level-1];
+ }
+ }
+
+ return($xml_array);
+ }
+
+ /**
+ * @brief Delete a node in a XML object
+ *
+ * @param object $doc XML document
+ * @param string $node Node name
+ */
+ public static function deleteNode(&$doc, $node)
+ {
+ $xpath = new DomXPath($doc);
+ $list = $xpath->query("//".$node);
+ foreach ($list as $child) {
+ $child->parentNode->removeChild($child);
+ }
+ }
+}
+++ /dev/null
-<?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
-{
- /**
- * @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.
- *
- * @return string The created XML
- */
- 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) {
- $key .= " xmlns".($nskey == "" ? "":":").$nskey.'="'.$nsvalue.'"';
- }
-
- if (is_array($value)) {
- $root = new SimpleXMLElement("<".$key."/>");
- self::from_array($value, $root, $remove_header, $namespaces, false);
- } else {
- $root = new SimpleXMLElement("<".$key.">".xmlify($value)."</".$key.">");
- }
-
- $dom = dom_import_simplexml($root)->ownerDocument;
- $dom->formatOutput = true;
- $xml = $dom;
-
- $xml_text = $dom->saveXML();
-
- if ($remove_header) {
- $xml_text = trim(substr($xml_text, 21));
- }
-
- return $xml_text;
- }
- }
-
- foreach ($array as $key => $value) {
- if (!isset($element) && isset($xml)) {
- $element = $xml;
- }
-
- if (is_integer($key)) {
- if (isset($element)) {
- if (is_scalar($value)) {
- $element[0] = $value;
- } else {
- /// @todo: handle nested array values
- }
- }
- continue;
- }
-
- $element_parts = explode(":", $key);
- if ((count($element_parts) > 1) && isset($namespaces[$element_parts[0]])) {
- $namespace = $namespaces[$element_parts[0]];
- } elseif (isset($namespaces[""])) {
- $namespace = $namespaces[""];
- } else {
- $namespace = null;
- }
-
- // Remove undefined namespaces from the key
- if ((count($element_parts) > 1) && is_null($namespace)) {
- $key = $element_parts[1];
- }
-
- if (substr($key, 0, 11) == "@attributes") {
- if (!isset($element) || !is_array($value)) {
- continue;
- }
-
- foreach ($value as $attr_key => $attr_value) {
- $element_parts = explode(":", $attr_key);
- if ((count($element_parts) > 1) && isset($namespaces[$element_parts[0]])) {
- $namespace = $namespaces[$element_parts[0]];
- } else {
- $namespace = null;
- }
-
- $element->addAttribute($attr_key, $attr_value, $namespace);
- }
-
- continue;
- }
-
- if (!is_array($value)) {
- $element = $xml->addChild($key, xmlify($value), $namespace);
- } elseif (is_array($value)) {
- $element = $xml->addChild($key, null, $namespace);
- self::from_array($value, $element, $remove_header, $namespaces, false);
- }
- }
- }
-
- /**
- * @brief Copies an XML object
- *
- * @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) {
- $target->addChild($elementname, xmlify($source));
- } else {
- $child = $target->addChild($elementname);
- foreach ($source->children() as $childfield => $childentry) {
- self::copy($childentry, $child, $childfield);
- }
- }
- }
-
- /**
- * @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
- *
- * @return object XML element object
- */
- public static function create_element($doc, $element, $value = "", $attributes = array())
- {
- $element = $doc->createElement($element, xmlify($value));
-
- foreach ($attributes as $key => $value) {
- $attribute = $doc->createAttribute($key);
- $attribute->value = xmlify($value);
- $element->appendChild($attribute);
- }
- return $element;
- }
-
- /**
- * @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
- */
- public static function add_element($doc, $parent, $element, $value = "", $attributes = array())
- {
- $element = self::create_element($doc, $element, $value, $attributes);
- $parent->appendChild($element);
- }
-
- /**
- * @brief Convert an XML document to a normalised, case-corrected array
- * used by webfinger
- *
- * @param object $xml_element The XML document
- * @param integer $recursion_depth recursion counter for internal use - default 0
- * 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)
- {
- // If we're getting too deep, bail out
- if ($recursion_depth > 512) {
- return(null);
- }
-
- if (!is_string($xml_element)
- && !is_array($xml_element)
- && (get_class($xml_element) == 'SimpleXMLElement')
- ) {
- $xml_element_copy = $xml_element;
- $xml_element = get_object_vars($xml_element);
- }
-
- if (is_array($xml_element)) {
- $result_array = array();
- if (count($xml_element) <= 0) {
- return (trim(strval($xml_element_copy)));
- }
-
- foreach ($xml_element as $key => $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(
- strtolower($xml_element_copy->getName()) => $temp_array,
- );
- }
-
- return ($result_array);
- } else {
- return (trim(strval($xml_element)));
- }
- }
-
- /**
- * @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.
- * 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'));
- *
- * @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.
- *
- * @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')
- {
- if (!$contents) {
- return array();
- }
-
- if (!function_exists('xml_parser_create')) {
- logger('Xml::to_array: parser function missing');
- return array();
- }
-
-
- libxml_use_internal_errors(true);
- libxml_clear_errors();
-
- if ($namespaces) {
- $parser = @xml_parser_create_ns("UTF-8", ':');
- } else {
- $parser = @xml_parser_create();
- }
-
- if (! $parser) {
- logger('Xml::to_array: xml_parser_create: no resource');
- return array();
- }
-
- xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8");
- // http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss
- xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
- xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
- @xml_parse_into_struct($parser, trim($contents), $xml_values);
- @xml_parser_free($parser);
-
- if (! $xml_values) {
- 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);
- }
- libxml_clear_errors();
- return;
- }
-
- //Initializations
- $xml_array = array();
- $parents = array();
- $opened_tags = array();
- $arr = array();
-
- $current = &$xml_array; // Reference
-
- // Go through the tags.
- $repeated_tag_index = array(); // Multiple tags with same name will be turned into an array
- foreach ($xml_values as $data) {
- unset($attributes, $value); // Remove existing values, or there will be trouble
-
- // This command will extract these variables into the foreach scope
- // tag(string), type(string), level(int), attributes(array).
- extract($data); // We could use the array by itself, but this cooler.
-
- $result = array();
- $attributes_data = array();
-
- if (isset($value)) {
- if ($priority == 'tag') {
- $result = $value;
- } else {
- $result['value'] = $value; // Put the value in a assoc array if we are in the 'Attribute' mode
- }
- }
-
- //Set the attributes too.
- if (isset($attributes) and $get_attributes) {
- foreach ($attributes as $attr => $val) {
- if ($priority == 'tag') {
- $attributes_data[$attr] = $val;
- } else {
- $result['@attributes'][$attr] = $val; // Set all the attributes in a array called 'attr'
- }
- }
- }
-
- // See tag status and do the needed.
- if ($namespaces && strpos($tag, ':')) {
- $namespc = substr($tag, 0, strrpos($tag, ':'));
- $tag = strtolower(substr($tag, strlen($namespc)+1));
- $result['@namespace'] = $namespc;
- }
- $tag = strtolower($tag);
-
- if ($type == "open") { // The starting of the tag '<tag>'
- $parent[$level-1] = &$current;
- if (!is_array($current) || (!in_array($tag, array_keys($current)))) { // Insert New tag
- $current[$tag] = $result;
- if ($attributes_data) {
- $current[$tag. '_attr'] = $attributes_data;
- }
- $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
- $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result;
- $repeated_tag_index[$tag.'_'.$level]++;
- } else { // This section will make the value an array if multiple tags with the same name appear together
- $current[$tag] = array($current[$tag], $result); // This will combine the existing item and the new item together to make an array
- $repeated_tag_index[$tag.'_'.$level] = 2;
-
- if (isset($current[$tag.'_attr'])) { // The attribute of the last(0th) tag must be moved as well
- $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
- $current[$tag] = $result;
- $repeated_tag_index[$tag.'_'.$level] = 1;
- 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...
-
- // ...push the new element into that array.
- $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result;
-
- if ($priority == 'tag' and $get_attributes and $attributes_data) {
- $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;
- if ($priority == 'tag' and $get_attributes) {
- if (isset($current[$tag.'_attr'])) { // The attribute of the last(0th) tag must be moved as well
-
- $current[$tag]['0_attr'] = $current[$tag.'_attr'];
- unset($current[$tag.'_attr']);
- }
-
- if ($attributes_data) {
- $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data;
- }
- }
- $repeated_tag_index[$tag.'_'.$level]++; // 0 and 1 indexes are already taken
- }
- }
- } elseif ($type == 'close') { // End of tag '</tag>'
- $current = &$parent[$level-1];
- }
- }
-
- return($xml_array);
- }
-
- /**
- * @brief Delete a node in a XML object
- *
- * @param object $doc XML document
- * @param string $node Node name
- */
- public static function deleteNode(&$doc, $node)
- {
- $xpath = new DomXPath($doc);
- $list = $xpath->query("//".$node);
- foreach ($list as $child) {
- $child->parentNode->removeChild($child);
- }
- }
-}