private static function fetchauthor($xpath, $context, $importer, $element, $onlyfetch, $xml = "")
{
$author = [];
- $author["name"] = $xpath->evaluate($element."/atom:name/text()", $context)->item(0)->nodeValue;
- $author["link"] = $xpath->evaluate($element."/atom:uri/text()", $context)->item(0)->nodeValue;
+ $author["name"] = XML::getFirstNodeValue($xpath, $element."/atom:name/text()", $context);
+ $author["link"] = XML::getFirstNodeValue($xpath, $element."/atom:uri/text()", $context);
$fields = ['id', 'uid', 'url', 'network', 'avatar-date', 'avatar', 'name-date', 'uri-date', 'addr',
'name', 'nick', 'about', 'location', 'keywords', 'xmpp', 'bdyear', 'bd', 'hidden', 'contact-type'];
}
// Update contact data
- $value = $xpath->evaluate($element . "/dfrn:handle/text()", $context)->item(0)->nodeValue;
+ $value = XML::getFirstNodeValue($xpath, $element . "/dfrn:handle/text()", $context);
if ($value != "") {
$poco["addr"] = $value;
}
- $value = $xpath->evaluate($element . "/poco:displayName/text()", $context)->item(0)->nodeValue;
+ $value = XML::getFirstNodeValue($xpath, $element . "/poco:displayName/text()", $context);
if ($value != "") {
$poco["name"] = $value;
}
- $value = $xpath->evaluate($element . "/poco:preferredUsername/text()", $context)->item(0)->nodeValue;
+ $value = XML::getFirstNodeValue($xpath, $element . "/poco:preferredUsername/text()", $context);
if ($value != "") {
$poco["nick"] = $value;
}
- $value = $xpath->evaluate($element . "/poco:note/text()", $context)->item(0)->nodeValue;
+ $value = XML::getFirstNodeValue($xpath, $element . "/poco:note/text()", $context);
if ($value != "") {
$poco["about"] = $value;
}
- $value = $xpath->evaluate($element . "/poco:address/poco:formatted/text()", $context)->item(0)->nodeValue;
+ $value = XML::getFirstNodeValue($xpath, $element . "/poco:address/poco:formatted/text()", $context);
if ($value != "") {
$poco["location"] = $value;
}
/// @todo Only search for elements with "poco:type" = "xmpp"
- $value = $xpath->evaluate($element . "/poco:ims/poco:value/text()", $context)->item(0)->nodeValue;
+ $value = XML::getFirstNodeValue($xpath, $element . "/poco:ims/poco:value/text()", $context);
if ($value != "") {
$poco["xmpp"] = $value;
}
/// - poco:country
// If the "hide" element is present then the profile isn't searchable.
- $hide = intval($xpath->evaluate($element . "/dfrn:hide/text()", $context)->item(0)->nodeValue == "true");
+ $hide = intval(XML::getFirstNodeValue($xpath, $element . "/dfrn:hide/text()", $context) == "true");
logger("Hidden status for contact " . $contact_old["url"] . ": " . $hide, LOGGER_DEBUG);
}
// "dfrn:birthday" contains the birthday converted to UTC
- $birthday = $xpath->evaluate($element . "/dfrn:birthday/text()", $context)->item(0)->nodeValue;
+ $birthday = XML::getFirstNodeValue($xpath, $element . "/poco:birthday/text()", $context);
if (strtotime($birthday) > time()) {
$bd_timestamp = strtotime($birthday);
}
// "poco:birthday" is the birthday in the format "yyyy-mm-dd"
- $value = $xpath->evaluate($element . "/poco:birthday/text()", $context)->item(0)->nodeValue;
+ $value = XML::getFirstNodeValue($xpath, $element . "/poco:birthday/text()", $context);
if (!in_array($value, ["", "0000-00-00", "0001-01-01"])) {
$bdyear = date("Y");
$item["source"] = $xml;
// Get the uri
- $item["uri"] = $xpath->query("atom:id/text()", $entry)->item(0)->nodeValue;
+ $item["uri"] = XML::getFirstNodeValue($xpath, "atom:id/text()", $entry);
- $item["edited"] = $xpath->query("atom:updated/text()", $entry)->item(0)->nodeValue;
+ $item["edited"] = XML::getFirstNodeValue($xpath, "atom:updated/text()", $entry);
$current = Item::selectFirst(['id', 'uid', 'edited', 'body'],
['uri' => $item["uri"], 'uid' => $importer["importer_uid"]]
$item["author-link"] = $author["link"];
$item["author-id"] = Contact::getIdForURL($author["link"], 0);
- $item["title"] = $xpath->query("atom:title/text()", $entry)->item(0)->nodeValue;
+ $item["title"] = XML::getFirstNodeValue($xpath, "atom:title/text()", $entry);
- $item["created"] = $xpath->query("atom:published/text()", $entry)->item(0)->nodeValue;
+ $item["created"] = XML::getFirstNodeValue($xpath, "atom:published/text()", $entry);
- $item["body"] = $xpath->query("dfrn:env/text()", $entry)->item(0)->nodeValue;
+ $item["body"] = XML::getFirstNodeValue($xpath, "dfrn:env/text()", $entry);
$item["body"] = str_replace([' ',"\t","\r","\n"], ['','','',''], $item["body"]);
// make sure nobody is trying to sneak some html tags by us
$item["body"] = notags(base64url_decode($item["body"]));
// We don't need the content element since "dfrn:env" is always present
//$item["body"] = $xpath->query("atom:content/text()", $entry)->item(0)->nodeValue;
- $item["location"] = $xpath->query("dfrn:location/text()", $entry)->item(0)->nodeValue;
+ $item["location"] = XML::getFirstNodeValue($xpath, "dfrn:location/text()", $entry);
- $georsspoint = $xpath->query("georss:point", $entry);
- if ($georsspoint) {
- $item["coord"] = $georsspoint->item(0)->nodeValue;
- }
+ $item["coord"] = XML::getFirstNodeValue($xpath, "georss:point", $entry);
- $item["private"] = $xpath->query("dfrn:private/text()", $entry)->item(0)->nodeValue;
+ $item["private"] = XML::getFirstNodeValue($xpath, "dfrn:private/text()", $entry);
- $item["extid"] = $xpath->query("dfrn:extid/text()", $entry)->item(0)->nodeValue;
+ $item["extid"] = XML::getFirstNodeValue($xpath, "dfrn:extid/text()", $entry);
- if ($xpath->query("dfrn:bookmark/text()", $entry)->item(0)->nodeValue == "true") {
+ if (XML::getFirstNodeValue($xpath, "dfrn:bookmark/text()", $entry) == "true") {
$item["bookmark"] = true;
}
}
}
- $item["guid"] = $xpath->query("dfrn:diaspora_guid/text()", $entry)->item(0)->nodeValue;
+ $item["guid"] = XML::getFirstNodeValue($xpath, "dfrn:diaspora_guid/text()", $entry);
// We store the data from "dfrn:diaspora_signature" in a different table, this is done in "Item::insert"
- $dsprsig = unxmlify($xpath->query("dfrn:diaspora_signature/text()", $entry)->item(0)->nodeValue);
+ $dsprsig = unxmlify(XML::getFirstNodeValue($xpath, "dfrn:diaspora_signature/text()", $entry));
if ($dsprsig != "") {
$item["dsprsig"] = $dsprsig;
}
- $item["verb"] = $xpath->query("activity:verb/text()", $entry)->item(0)->nodeValue;
+ $item["verb"] = XML::getFirstNodeValue($xpath, "activity:verb/text()", $entry);
- if ($xpath->query("activity:object-type/text()", $entry)->item(0)->nodeValue != "") {
- $item["object-type"] = $xpath->query("activity:object-type/text()", $entry)->item(0)->nodeValue;
+ if (XML::getFirstNodeValue($xpath, "activity:object-type/text()", $entry) != "") {
+ $item["object-type"] = XML::getFirstNodeValue($xpath, "activity:object-type/text()", $entry);
}
$object = $xpath->query("activity:object", $entry)->item(0);
$termhash = array_shift($parts);
$termurl = implode(":", $parts);
- if (strlen($item["tag"])) {
+ if (!empty($item["tag"])) {
$item["tag"] .= ",";
+ } else {
+ $item["tag"] = "";
}
$item["tag"] .= $termhash . "[url=" . $termurl . "]" . $term . "[/url]";
self::parseLinks($links, $item);
}
- $item['conversation-uri'] = $xpath->query('ostatus:conversation/text()', $entry)->item(0)->nodeValue;
+ $item['conversation-uri'] = XML::getFirstNodeValue($xpath, 'ostatus:conversation/text()', $entry);
$conv = $xpath->query('ostatus:conversation', $entry);
if (is_object($conv->item(0))) {
logger("Import DFRN message for user " . $importer["importer_uid"] . " from contact " . $importer["id"], LOGGER_DEBUG);
// is it a public forum? Private forums aren't exposed with this method
- $forum = intval($xpath->evaluate("/atom:feed/dfrn:community/text()")->item(0)->nodeValue);
+ $forum = intval(XML::getFirstNodeValue($xpath, "/atom:feed/dfrn:community/text()"));
// The account type is new since 3.5.1
if ($xpath->query("/atom:feed/dfrn:account_type")->length > 0) {
- $accounttype = intval($xpath->evaluate("/atom:feed/dfrn:account_type/text()")->item(0)->nodeValue);
+ $accounttype = intval(XML::getFirstNodeValue($xpath, "/atom:feed/dfrn:account_type/text()"));
if ($accounttype != $importer["contact-type"]) {
dba::update('contact', ['contact-type' => $accounttype], ['id' => $importer["id"]]);
$newentries = [];
$entries = $xpath->query("/atom:feed/atom:entry");
foreach ($entries as $entry) {
- $created = $xpath->query("atom:published/text()", $entry)->item(0)->nodeValue;
+ $created = XML::getFirstNodeValue($xpath, "atom:published/text()", $entry);
$newentries[strtotime($created)] = $entry;
}
if ($value != "") {
$author["author-nick"] = $value;
}
- $value = $xpath->evaluate('atom:author/poco:address/poco:formatted/text()')->item(0)->nodeValue;
+ $value = XML::getFirstNodeValue($xpath, 'atom:author/poco:address/poco:formatted/text()');
if ($value != "") {
$author["author-location"] = $value;
}
- $value = $xpath->evaluate('atom:author/poco:note/text()')->item(0)->nodeValue;
+ $value = XML::getFirstNodeValue($xpath, 'atom:author/poco:note/text()');
if ($value != "") {
$author["author-about"] = $value;
}
}
}
- $author["edited"] = $author["created"] = $xpath->query('/atom:feed/atom:updated/text()')->item(0)->nodeValue;
+ $author["edited"] = $author["created"] = XML::getFirstNodeValue($xpath, '/atom:feed/atom:updated/text()');
- $author["app"] = $xpath->evaluate('/atom:feed/atom:generator/text()')->item(0)->nodeValue;
+ $author["app"] = XML::getFirstNodeValue($xpath, '/atom:feed/atom:generator/text()');
$entries = $xpath->query('/atom:feed/atom:entry');
}
}
}
if ($item["plink"] == "") {
- $item["plink"] = $xpath->evaluate('link/text()', $entry)->item(0)->nodeValue;
+ $item["plink"] = XML::getFirstNodeValue($xpath, 'link/text()', $entry);
}
if ($item["plink"] == "") {
- $item["plink"] = $xpath->evaluate('rss:link/text()', $entry)->item(0)->nodeValue;
+ $item["plink"] = XML::getFirstNodeValue($xpath, 'rss:link/text()', $entry);
}
- $item["uri"] = $xpath->evaluate('atom:id/text()', $entry)->item(0)->nodeValue;
+ $item["uri"] = XML::getFirstNodeValue($xpath, 'atom:id/text()', $entry);
if ($item["uri"] == "") {
- $item["uri"] = $xpath->evaluate('guid/text()', $entry)->item(0)->nodeValue;
+ $item["uri"] = XML::getFirstNodeValue($xpath, 'guid/text()', $entry);
}
if ($item["uri"] == "") {
$item["uri"] = $item["plink"];
}
}
- $item["title"] = $xpath->evaluate('atom:title/text()', $entry)->item(0)->nodeValue;
+ $item["title"] = XML::getFirstNodeValue($xpath, 'atom:title/text()', $entry);
if ($item["title"] == "") {
- $item["title"] = $xpath->evaluate('title/text()', $entry)->item(0)->nodeValue;
+ $item["title"] = XML::getFirstNodeValue($xpath, 'title/text()', $entry);
}
if ($item["title"] == "") {
- $item["title"] = $xpath->evaluate('rss:title/text()', $entry)->item(0)->nodeValue;
+ $item["title"] = XML::getFirstNodeValue($xpath, 'rss:title/text()', $entry);
}
- $published = $xpath->query('atom:published/text()', $entry)->item(0)->nodeValue;
+ $published = XML::getFirstNodeValue($xpath, 'atom:published/text()', $entry);
if ($published == "") {
- $published = $xpath->query('pubDate/text()', $entry)->item(0)->nodeValue;
+ $published = XML::getFirstNodeValue($xpath, 'pubDate/text()', $entry);
}
if ($published == "") {
- $published = $xpath->query('dc:date/text()', $entry)->item(0)->nodeValue;
+ $published = XML::getFirstNodeValue($xpath, 'dc:date/text()', $entry);
}
- $updated = $xpath->query('atom:updated/text()', $entry)->item(0)->nodeValue;
+ $updated = XML::getFirstNodeValue($xpath, 'atom:updated/text()', $entry);
if ($updated == "") {
$updated = $published;
if ($updated != "") {
$item["edited"] = $updated;
}
- $creator = $xpath->query('author/text()', $entry)->item(0)->nodeValue;
+ $creator = XML::getFirstNodeValue($xpath, 'author/text()', $entry);
if ($creator == "") {
- $creator = $xpath->query('atom:author/atom:name/text()', $entry)->item(0)->nodeValue;
+ $creator = XML::getFirstNodeValue($xpath, 'atom:author/atom:name/text()', $entry);
}
if ($creator == "") {
- $creator = $xpath->query('dc:creator/text()', $entry)->item(0)->nodeValue;
+ $creator = XML::getFirstNodeValue($xpath, 'dc:creator/text()', $entry);
}
if ($creator != "") {
$item["author-name"] = $creator;
}
- $creator = $xpath->query('dc:creator/text()', $entry)->item(0)->nodeValue;
+ $creator = XML::getFirstNodeValue($xpath, 'dc:creator/text()', $entry);
if ($creator != "") {
$item["author-name"] = $creator;