added more curly braces + a bit more usage of dbm::is_result()

Signed-off-by: Roland Häder <roland@mxchange.org>
This commit is contained in:
Roland Häder 2017-01-25 15:59:27 +01:00 committed by Roland Haeder
parent 55e2411f07
commit 3849e7c9ff
No known key found for this signature in database
GPG key ID: B72F8185C6C7BD78
5 changed files with 160 additions and 97 deletions

View file

@ -637,18 +637,24 @@ class dfrn {
$entry = $doc->createElement($element); $entry = $doc->createElement($element);
$r = parse_xml_string($activity, false); $r = parse_xml_string($activity, false);
if(!$r) if (!$r) {
return false; return false;
if($r->type) }
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) }
if ($r->id) {
xml::add_element($doc, $entry, "id", $r->id); xml::add_element($doc, $entry, "id", $r->id);
if($r->title) }
if ($r->title) {
xml::add_element($doc, $entry, "title", $r->title); xml::add_element($doc, $entry, "title", $r->title);
if($r->link) { }
if(substr($r->link,0,1) == '<') {
if(strstr($r->link,'&') && (! strstr($r->link,'&amp;'))) if ($r->link) {
if (substr($r->link,0,1) == '<') {
if (strstr($r->link,'&') && (! strstr($r->link,'&amp;'))) {
$r->link = str_replace('&','&amp;', $r->link); $r->link = str_replace('&','&amp;', $r->link);
}
$r->link = preg_replace('/\<link(.*?)\"\>/','<link$1"/>',$r->link); $r->link = preg_replace('/\<link(.*?)\"\>/','<link$1"/>',$r->link);
@ -657,8 +663,9 @@ class dfrn {
if (is_object($data)) { if (is_object($data)) {
foreach ($data->link AS $link) { foreach ($data->link AS $link) {
$attributes = array(); $attributes = array();
foreach ($link->attributes() AS $parameter => $value) foreach ($link->attributes() AS $parameter => $value) {
$attributes[$parameter] = $value; $attributes[$parameter] = $value;
}
xml::add_element($doc, $entry, "link", "", $attributes); xml::add_element($doc, $entry, "link", "", $attributes);
} }
} }
@ -667,8 +674,9 @@ class dfrn {
xml::add_element($doc, $entry, "link", "", $attributes); xml::add_element($doc, $entry, "link", "", $attributes);
} }
} }
if($r->content) 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; return $entry;
} }
@ -687,20 +695,22 @@ class dfrn {
*/ */
private static function get_attachment($doc, $root, $item) { private static function get_attachment($doc, $root, $item) {
$arr = explode('[/attach],',$item['attach']); $arr = explode('[/attach],',$item['attach']);
if(count($arr)) { if (count($arr)) {
foreach($arr as $r) { foreach ($arr as $r) {
$matches = false; $matches = false;
$cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|',$r,$matches); $cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|',$r,$matches);
if($cnt) { if ($cnt) {
$attributes = array("rel" => "enclosure", $attributes = array("rel" => "enclosure",
"href" => $matches[1], "href" => $matches[1],
"type" => $matches[3]); "type" => $matches[3]);
if(intval($matches[2])) if (intval($matches[2])) {
$attributes["length"] = intval($matches[2]); $attributes["length"] = intval($matches[2]);
}
if(trim($matches[4]) != "") if (trim($matches[4]) != "") {
$attributes["title"] = trim($matches[4]); $attributes["title"] = trim($matches[4]);
}
xml::add_element($doc, $root, "link", "", $attributes); xml::add_element($doc, $root, "link", "", $attributes);
} }
@ -724,20 +734,22 @@ class dfrn {
$mentioned = array(); $mentioned = array();
if(!$item['parent']) if (!$item['parent']) {
return; return;
}
if($item['deleted']) { if ($item['deleted']) {
$attributes = array("ref" => $item['uri'], "when" => datetime_convert('UTC','UTC',$item['edited'] . '+00:00',ATOM_TIME)); $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);
} }
$entry = $doc->createElement("entry"); $entry = $doc->createElement("entry");
if($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid']) if ($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid']) {
$body = fix_private_photos($item['body'],$owner['uid'],$item,$cid); $body = fix_private_photos($item['body'],$owner['uid'],$item,$cid);
else } else {
$body = $item['body']; $body = $item['body'];
}
// Remove the abstract element. It is only locally important. // Remove the abstract element. It is only locally important.
$body = remove_abstract($body); $body = remove_abstract($body);
@ -745,8 +757,9 @@ class dfrn {
if ($type == 'html') { if ($type == 'html') {
$htmlbody = $body; $htmlbody = $body;
if ($item['title'] != "") if ($item['title'] != "") {
$htmlbody = "[b]".$item['title']."[/b]\n\n".$htmlbody; $htmlbody = "[b]".$item['title']."[/b]\n\n".$htmlbody;
}
$htmlbody = bbcode($htmlbody, false, false, 7); $htmlbody = bbcode($htmlbody, false, false, 7);
} }
@ -757,7 +770,7 @@ class dfrn {
$dfrnowner = self::add_entry_author($doc, "dfrn:owner", $item["owner-link"], $item); $dfrnowner = self::add_entry_author($doc, "dfrn:owner", $item["owner-link"], $item);
$entry->appendChild($dfrnowner); $entry->appendChild($dfrnowner);
if(($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) { if (($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) {
$parent = q("SELECT `guid` FROM `item` WHERE `id` = %d", intval($item["parent"])); $parent = q("SELECT `guid` FROM `item` WHERE `id` = %d", intval($item["parent"]));
$parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']); $parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']);
$attributes = array("ref" => $parent_item, "type" => "text/html", $attributes = array("ref" => $parent_item, "type" => "text/html",
@ -785,26 +798,33 @@ class dfrn {
// "comment-allow" is some old fashioned stuff for old Friendica versions. // "comment-allow" is some old fashioned stuff for old Friendica versions.
// It is included in the rewritten code for completeness // It is included in the rewritten code for completeness
if ($comment) 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']) if ($item['location']) {
xml::add_element($doc, $entry, "dfrn:location", $item['location']); xml::add_element($doc, $entry, "dfrn:location", $item['location']);
}
if($item['coord']) 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'])) 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']) if ($item['extid']) {
xml::add_element($doc, $entry, "dfrn:extid", $item['extid']); xml::add_element($doc, $entry, "dfrn:extid", $item['extid']);
}
if($item['bookmark']) if ($item['bookmark']) {
xml::add_element($doc, $entry, "dfrn:bookmark", "true"); xml::add_element($doc, $entry, "dfrn:bookmark", "true");
}
if($item['app']) 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"]);
@ -817,47 +837,57 @@ class dfrn {
xml::add_element($doc, $entry, "activity:verb", construct_verb($item)); xml::add_element($doc, $entry, "activity:verb", construct_verb($item));
if ($item['object-type'] != "") 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']) } 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 } 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']); $actobj = self::create_activity($doc, "activity:object", $item['object']);
if ($actobj) if ($actobj) {
$entry->appendChild($actobj); $entry->appendChild($actobj);
}
$actarg = self::create_activity($doc, "activity:target", $item['target']); $actarg = self::create_activity($doc, "activity:target", $item['target']);
if ($actarg) if ($actarg) {
$entry->appendChild($actarg); $entry->appendChild($actarg);
}
$tags = item_getfeedtags($item); $tags = item_getfeedtags($item);
if(count($tags)) { if( count($tags)) {
foreach($tags as $t) foreach ($tags as $t) {
if (($type != 'html') OR ($t[0] != "@")) if (($type != 'html') OR ($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]));
} }
}
}
if(count($tags)) if (count($tags)) {
foreach($tags as $t) foreach($tags as $t) {
if ($t[0] == "@") if ($t[0] == "@") {
$mentioned[$t[1]] = $t[1]; $mentioned[$t[1]] = $t[1];
}
}
}
foreach ($mentioned AS $mention) { foreach ($mentioned AS $mention) {
$r = q("SELECT `forum`, `prv` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s'", $r = q("SELECT `forum`, `prv` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s'",
intval($owner["uid"]), intval($owner["uid"]),
dbesc(normalise_link($mention))); dbesc(normalise_link($mention)));
if ($r[0]["forum"] OR $r[0]["prv"])
if ($r[0]["forum"] OR $r[0]["prv"]) {
xml::add_element($doc, $entry, "link", "", array("rel" => "mentioned", xml::add_element($doc, $entry, "link", "", array("rel" => "mentioned",
"ostatus:object-type" => ACTIVITY_OBJ_GROUP, "ostatus:object-type" => ACTIVITY_OBJ_GROUP,
"href" => $mention)); "href" => $mention));
else } else {
xml::add_element($doc, $entry, "link", "", array("rel" => "mentioned", xml::add_element($doc, $entry, "link", "", array("rel" => "mentioned",
"ostatus:object-type" => ACTIVITY_OBJ_PERSON, "ostatus:object-type" => ACTIVITY_OBJ_PERSON,
"href" => $mention)); "href" => $mention));
} }
}
self::get_attachment($doc, $entry, $item); self::get_attachment($doc, $entry, $item);
@ -880,16 +910,20 @@ class dfrn {
$idtosend = $orig_id = (($contact['dfrn-id']) ? $contact['dfrn-id'] : $contact['issued-id']); $idtosend = $orig_id = (($contact['dfrn-id']) ? $contact['dfrn-id'] : $contact['issued-id']);
if($contact['duplex'] && $contact['dfrn-id']) if ($contact['duplex'] && $contact['dfrn-id']) {
$idtosend = '0:' . $orig_id; $idtosend = '0:' . $orig_id;
if($contact['duplex'] && $contact['issued-id']) }
if ($contact['duplex'] && $contact['issued-id']) {
$idtosend = '1:' . $orig_id; $idtosend = '1:' . $orig_id;
}
$rino = get_config('system','rino_encrypt'); $rino = get_config('system','rino_encrypt');
$rino = intval($rino); $rino = intval($rino);
// use RINO1 if mcrypt isn't installed and RINO2 was selected // use RINO1 if mcrypt isn't installed and RINO2 was selected
if ($rino==2 and !function_exists('mcrypt_create_iv')) $rino=1; if ($rino==2 and !function_exists('mcrypt_create_iv')) {
$rino=1;
}
logger("Local rino version: ". $rino, LOGGER_DEBUG); logger("Local rino version: ". $rino, LOGGER_DEBUG);
@ -928,10 +962,11 @@ class dfrn {
logger('dfrn_deliver: ' . $xml, LOGGER_DATA); logger('dfrn_deliver: ' . $xml, LOGGER_DATA);
if(! $xml) if (! $xml) {
return 3; return 3;
}
if(strpos($xml,'<?xml') === false) { if (strpos($xml,'<?xml') === false) {
logger('dfrn_deliver: no valid XML returned'); logger('dfrn_deliver: no valid XML returned');
logger('dfrn_deliver: returned XML: ' . $xml, LOGGER_DATA); logger('dfrn_deliver: returned XML: ' . $xml, LOGGER_DATA);
return 3; return 3;
@ -939,8 +974,9 @@ class dfrn {
$res = parse_xml_string($xml); $res = parse_xml_string($xml);
if((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id))) if ((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id))) {
return (($res->status) ? $res->status : 3); return (($res->status) ? $res->status : 3);
}
$postvars = array(); $postvars = array();
$sent_dfrn_id = hex2bin((string) $res->dfrn_id); $sent_dfrn_id = hex2bin((string) $res->dfrn_id);
@ -952,13 +988,14 @@ class dfrn {
logger("Remote rino version: ".$rino_remote_version." for ".$contact["url"], LOGGER_DEBUG); logger("Remote rino version: ".$rino_remote_version." for ".$contact["url"], LOGGER_DEBUG);
if($owner['page-flags'] == PAGE_PRVGROUP) if ($owner['page-flags'] == PAGE_PRVGROUP) {
$page = 2; $page = 2;
}
$final_dfrn_id = ''; $final_dfrn_id = '';
if($perm) { if ($perm) {
if((($perm == 'rw') && (! intval($contact['writable']))) if ((($perm == 'rw') && (! intval($contact['writable'])))
|| (($perm == 'r') && (intval($contact['writable'])))) { || (($perm == 'r') && (intval($contact['writable'])))) {
q("update contact set writable = %d where id = %d", q("update contact set writable = %d where id = %d",
intval(($perm == 'rw') ? 1 : 0), intval(($perm == 'rw') ? 1 : 0),
@ -968,7 +1005,7 @@ class dfrn {
} }
} }
if(($contact['duplex'] && strlen($contact['pubkey'])) if (($contact['duplex'] && strlen($contact['pubkey']))
|| ($owner['page-flags'] == PAGE_COMMUNITY && strlen($contact['pubkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY && strlen($contact['pubkey']))
|| ($contact['rel'] == CONTACT_IS_SHARING && strlen($contact['pubkey']))) { || ($contact['rel'] == CONTACT_IS_SHARING && strlen($contact['pubkey']))) {
openssl_public_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['pubkey']); openssl_public_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['pubkey']);
@ -980,10 +1017,11 @@ class dfrn {
$final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.')); $final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.'));
if(strpos($final_dfrn_id,':') == 1) if (strpos($final_dfrn_id,':') == 1) {
$final_dfrn_id = substr($final_dfrn_id,2); $final_dfrn_id = substr($final_dfrn_id,2);
}
if($final_dfrn_id != $orig_id) { if ($final_dfrn_id != $orig_id) {
logger('dfrn_deliver: wrong dfrn_id.'); logger('dfrn_deliver: wrong dfrn_id.');
// did not decode properly - cannot trust this site // did not decode properly - cannot trust this site
return 3; return 3;
@ -991,11 +1029,12 @@ class dfrn {
$postvars['dfrn_id'] = $idtosend; $postvars['dfrn_id'] = $idtosend;
$postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION; $postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION;
if($dissolve) if ($dissolve) {
$postvars['dissolve'] = '1'; $postvars['dissolve'] = '1';
}
if((($contact['rel']) && ($contact['rel'] != CONTACT_IS_SHARING) && (! $contact['blocked'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) { if ((($contact['rel']) && ($contact['rel'] != CONTACT_IS_SHARING) && (! $contact['blocked'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
$postvars['data'] = $atom; $postvars['data'] = $atom;
$postvars['perm'] = 'rw'; $postvars['perm'] = 'rw';
} else { } else {
@ -1005,11 +1044,12 @@ class dfrn {
$postvars['ssl_policy'] = $ssl_policy; $postvars['ssl_policy'] = $ssl_policy;
if($page) if ($page) {
$postvars['page'] = $page; $postvars['page'] = $page;
}
if($rino>0 && $rino_remote_version>0 && (! $dissolve)) { if ($rino>0 && $rino_remote_version>0 && (! $dissolve)) {
logger('rino version: '. $rino_remote_version); logger('rino version: '. $rino_remote_version);
switch($rino_remote_version) { switch($rino_remote_version) {
@ -1047,23 +1087,25 @@ class dfrn {
$postvars['rino'] = $rino_remote_version; $postvars['rino'] = $rino_remote_version;
$postvars['data'] = bin2hex($data); $postvars['data'] = bin2hex($data);
#logger('rino: sent key = ' . $key, LOGGER_DEBUG); //logger('rino: sent key = ' . $key, LOGGER_DEBUG);
if($dfrn_version >= 2.1) { if ($dfrn_version >= 2.1) {
if(($contact['duplex'] && strlen($contact['pubkey'])) if (($contact['duplex'] && strlen($contact['pubkey'])) {
|| ($owner['page-flags'] == PAGE_COMMUNITY && strlen($contact['pubkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY && strlen($contact['pubkey']))
|| ($contact['rel'] == CONTACT_IS_SHARING && strlen($contact['pubkey']))) || ($contact['rel'] == CONTACT_IS_SHARING && strlen($contact['pubkey'])))
openssl_public_encrypt($key,$postvars['key'],$contact['pubkey']); openssl_public_encrypt($key,$postvars['key'],$contact['pubkey']);
else } else {
openssl_private_encrypt($key,$postvars['key'],$contact['prvkey']); openssl_private_encrypt($key,$postvars['key'],$contact['prvkey']);
}
} else { } else {
if(($contact['duplex'] && strlen($contact['prvkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) if (($contact['duplex'] && strlen($contact['prvkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
openssl_private_encrypt($key,$postvars['key'],$contact['prvkey']); openssl_private_encrypt($key,$postvars['key'],$contact['prvkey']);
else } else {
openssl_public_encrypt($key,$postvars['key'],$contact['pubkey']); openssl_public_encrypt($key,$postvars['key'],$contact['pubkey']);
}
} }
@ -1088,13 +1130,13 @@ class dfrn {
return -10; return -10;
} }
if(strpos($xml,'<?xml') === false) { if (strpos($xml,'<?xml') === false) {
logger('dfrn_deliver: phase 2: no valid XML returned'); logger('dfrn_deliver: phase 2: no valid XML returned');
logger('dfrn_deliver: phase 2: returned XML: ' . $xml, LOGGER_DATA); logger('dfrn_deliver: phase 2: returned XML: ' . $xml, LOGGER_DATA);
return 3; return 3;
} }
if($contact['term-date'] != '0000-00-00 00:00:00') { if ($contact['term-date'] != '0000-00-00 00:00:00') {
logger("dfrn_deliver: $url back from the dead - removing mark for death"); logger("dfrn_deliver: $url back from the dead - removing mark for death");
require_once('include/Contact.php'); require_once('include/Contact.php');
unmark_for_death($contact); unmark_for_death($contact);
@ -1165,7 +1207,8 @@ class dfrn {
`name`, `nick`, `about`, `location`, `keywords`, `xmpp`, `bdyear`, `bd`, `hidden`, `contact-type` `name`, `nick`, `about`, `location`, `keywords`, `xmpp`, `bdyear`, `bd`, `hidden`, `contact-type`
FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `network` != '%s'", FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `network` != '%s'",
intval($importer["uid"]), dbesc(normalise_link($author["link"])), dbesc(NETWORK_STATUSNET)); intval($importer["uid"]), dbesc(normalise_link($author["link"])), dbesc(NETWORK_STATUSNET));
if ($r) {
if (dbm::is_result($r)) {
$contact = $r[0]; $contact = $r[0];
$author["contact-id"] = $r[0]["id"]; $author["contact-id"] = $r[0]["id"];
$author["network"] = $r[0]["network"]; $author["network"] = $r[0]["network"];
@ -1186,16 +1229,20 @@ class dfrn {
$href = ""; $href = "";
$width = 0; $width = 0;
foreach($avatar->attributes AS $attributes) { foreach($avatar->attributes AS $attributes) {
if ($attributes->name == "href") if ($attributes->name == "href") {
$href = $attributes->textContent; $href = $attributes->textContent;
if ($attributes->name == "width") }
if ($attributes->name == "width") {
$width = $attributes->textContent; $width = $attributes->textContent;
if ($attributes->name == "updated") }
if ($attributes->name == "updated") {
$contact["avatar-date"] = $attributes->textContent; $contact["avatar-date"] = $attributes->textContent;
} }
if (($width > 0) AND ($href != "")) }
if (($width > 0) AND ($href != "")) {
$avatarlist[$width] = $href; $avatarlist[$width] = $href;
} }
}
if (count($avatarlist) > 0) { if (count($avatarlist) > 0) {
krsort($avatarlist); krsort($avatarlist);
$author["avatar"] = current($avatarlist); $author["avatar"] = current($avatarlist);
@ -1208,40 +1255,50 @@ class dfrn {
// When was the last change to name or uri? // When was the last change to name or uri?
$name_element = $xpath->query($element."/atom:name", $context)->item(0); $name_element = $xpath->query($element."/atom:name", $context)->item(0);
foreach($name_element->attributes AS $attributes) foreach ($name_element->attributes AS $attributes) {
if ($attributes->name == "updated") if ($attributes->name == "updated") {
$poco["name-date"] = $attributes->textContent; $poco["name-date"] = $attributes->textContent;
}
}
$link_element = $xpath->query($element."/atom:link", $context)->item(0); $link_element = $xpath->query($element."/atom:link", $context)->item(0);
foreach($link_element->attributes AS $attributes) foreach ($link_element->attributes AS $attributes) {
if ($attributes->name == "updated") if ($attributes->name == "updated") {
$poco["uri-date"] = $attributes->textContent; $poco["uri-date"] = $attributes->textContent;
}
}
// Update contact data // Update contact data
$value = $xpath->evaluate($element."/dfrn:handle/text()", $context)->item(0)->nodeValue; $value = $xpath->evaluate($element."/dfrn:handle/text()", $context)->item(0)->nodeValue;
if ($value != "") if ($value != "") {
$poco["addr"] = $value; $poco["addr"] = $value;
}
$value = $xpath->evaluate($element."/poco:displayName/text()", $context)->item(0)->nodeValue; $value = $xpath->evaluate($element."/poco:displayName/text()", $context)->item(0)->nodeValue;
if ($value != "") if ($value != "") {
$poco["name"] = $value; $poco["name"] = $value;
}
$value = $xpath->evaluate($element."/poco:preferredUsername/text()", $context)->item(0)->nodeValue; $value = $xpath->evaluate($element."/poco:preferredUsername/text()", $context)->item(0)->nodeValue;
if ($value != "") if ($value != "") {
$poco["nick"] = $value; $poco["nick"] = $value;
}
$value = $xpath->evaluate($element."/poco:note/text()", $context)->item(0)->nodeValue; $value = $xpath->evaluate($element."/poco:note/text()", $context)->item(0)->nodeValue;
if ($value != "") if ($value != "") {
$poco["about"] = $value; $poco["about"] = $value;
}
$value = $xpath->evaluate($element."/poco:address/poco:formatted/text()", $context)->item(0)->nodeValue; $value = $xpath->evaluate($element."/poco:address/poco:formatted/text()", $context)->item(0)->nodeValue;
if ($value != "") if ($value != "") {
$poco["location"] = $value; $poco["location"] = $value;
}
/// @todo Only search for elements with "poco:type" = "xmpp" /// @todo Only search for elements with "poco:type" = "xmpp"
$value = $xpath->evaluate($element."/poco:ims/poco:value/text()", $context)->item(0)->nodeValue; $value = $xpath->evaluate($element."/poco:ims/poco:value/text()", $context)->item(0)->nodeValue;
if ($value != "") if ($value != "") {
$poco["xmpp"] = $value; $poco["xmpp"] = $value;
}
/// @todo Add support for the following fields that we don't support by now in the contact table: /// @todo Add support for the following fields that we don't support by now in the contact table:
/// - poco:utcOffset /// - poco:utcOffset
@ -1257,17 +1314,20 @@ class dfrn {
// If the contact isn't searchable then set the contact to "hidden". // If the contact isn't searchable then set the contact to "hidden".
// Problem: This can be manually overridden by the user. // Problem: This can be manually overridden by the user.
if ($hide) if ($hide) {
$contact["hidden"] = true; $contact["hidden"] = true;
}
// Save the keywords into the contact table // Save the keywords into the contact table
$tags = array(); $tags = array();
$tagelements = $xpath->evaluate($element."/poco:tags/text()", $context); $tagelements = $xpath->evaluate($element."/poco:tags/text()", $context);
foreach($tagelements AS $tag) foreach ($tagelements AS $tag) {
$tags[$tag->nodeValue] = $tag->nodeValue; $tags[$tag->nodeValue] = $tag->nodeValue;
}
if (count($tags)) if (count($tags)) {
$poco["keywords"] = implode(", ", $tags); $poco["keywords"] = implode(", ", $tags);
}
// "dfrn:birthday" contains the birthday converted to UTC // "dfrn:birthday" contains the birthday converted to UTC
$old_bdyear = $contact["bdyear"]; $old_bdyear = $contact["bdyear"];
@ -1297,13 +1357,15 @@ class dfrn {
$contact = array_merge($contact, $poco); $contact = array_merge($contact, $poco);
if ($old_bdyear != $contact["bdyear"]) if ($old_bdyear != $contact["bdyear"]) {
self::birthday_event($contact, $birthday); self::birthday_event($contact, $birthday);
}
// Get all field names // Get all field names
$fields = array(); $fields = array();
foreach ($r[0] AS $field => $data) foreach ($r[0] AS $field => $data) {
$fields[$field] = $data; $fields[$field] = $data;
}
unset($fields["id"]); unset($fields["id"]);
unset($fields["uid"]); unset($fields["uid"]);
@ -1368,8 +1430,9 @@ class dfrn {
* @return string XML string * @return string XML string
*/ */
private static function transform_activity($xpath, $activity, $element) { private static function transform_activity($xpath, $activity, $element) {
if (!is_object($activity)) if (!is_object($activity)) {
return ""; return "";
}
$obj_doc = new DOMDocument("1.0", "utf-8"); $obj_doc = new DOMDocument("1.0", "utf-8");
$obj_doc->formatOutput = true; $obj_doc->formatOutput = true;

View file

@ -586,17 +586,18 @@ function dfrn_confirm_post(App $a, $handsfree = null) {
dbesc($decrypted_source_url), dbesc($decrypted_source_url),
intval($local_uid) intval($local_uid)
); );
if(! count($ret)) { if (!dbm::is_result($ret)) {
if(strstr($decrypted_source_url,'http:')) if (strstr($decrypted_source_url,'http:')) {
$newurl = str_replace('http:','https:',$decrypted_source_url); $newurl = str_replace('http:','https:',$decrypted_source_url);
else } else {
$newurl = str_replace('https:','http:',$decrypted_source_url); $newurl = str_replace('https:','http:',$decrypted_source_url);
}
$ret = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1", $ret = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1",
dbesc($newurl), dbesc($newurl),
intval($local_uid) intval($local_uid)
); );
if(! count($ret)) { if (!dbm::is_result($ret)) {
// this is either a bogus confirmation (?) or we deleted the original introduction. // this is either a bogus confirmation (?) or we deleted the original introduction.
$message = t('Contact record was not found for you on our site.'); $message = t('Contact record was not found for you on our site.');
xml_status(3,$message); xml_status(3,$message);
@ -611,7 +612,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) {
$foreign_pubkey = $ret[0]['site-pubkey']; $foreign_pubkey = $ret[0]['site-pubkey'];
$dfrn_record = $ret[0]['id']; $dfrn_record = $ret[0]['id'];
if(! $foreign_pubkey) { if (! $foreign_pubkey) {
$message = sprintf( t('Site public key not available in contact record for URL %s.'), $newurl); $message = sprintf( t('Site public key not available in contact record for URL %s.'), $newurl);
xml_status(3,$message); xml_status(3,$message);
} }
@ -619,7 +620,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) {
$decrypted_dfrn_id = ""; $decrypted_dfrn_id = "";
openssl_public_decrypt($dfrn_id,$decrypted_dfrn_id,$foreign_pubkey); openssl_public_decrypt($dfrn_id,$decrypted_dfrn_id,$foreign_pubkey);
if(strlen($aes_key)) { if (strlen($aes_key)) {
$decrypted_aes_key = ""; $decrypted_aes_key = "";
openssl_private_decrypt($aes_key,$decrypted_aes_key,$my_prvkey); openssl_private_decrypt($aes_key,$decrypted_aes_key,$my_prvkey);
$dfrn_pubkey = openssl_decrypt($public_key,'AES-256-CBC',$decrypted_aes_key); $dfrn_pubkey = openssl_decrypt($public_key,'AES-256-CBC',$decrypted_aes_key);

View file

@ -264,13 +264,12 @@ function profiles_post(App $a) {
} }
else { else {
$newname = $lookup; $newname = $lookup;
/* if(strstr($lookup,' ')) { /* if (strstr($lookup,' ')) {
$r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1", $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
dbesc($newname), dbesc($newname),
intval(local_user()) intval(local_user())
); );
} } else {
else {
$r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1", $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
dbesc($lookup), dbesc($lookup),
intval(local_user()) intval(local_user())

View file

@ -311,7 +311,7 @@ function update_1031() {
$r = q("SELECT `id`, `object` FROM `item` WHERE `object` != '' "); $r = q("SELECT `id`, `object` FROM `item` WHERE `object` != '' ");
if (dbm::is_result($r)) { if (dbm::is_result($r)) {
foreach ($r as $rr) { foreach ($r as $rr) {
if(strstr($rr['object'],'type=&quot;http')) { if (strstr($rr['object'],'type=&quot;http')) {
q("UPDATE `item` SET `object` = '%s' WHERE `id` = %d", q("UPDATE `item` SET `object` = '%s' WHERE `id` = %d",
dbesc(str_replace('type=&quot;http','href=&quot;http',$rr['object'])), dbesc(str_replace('type=&quot;http','href=&quot;http',$rr['object'])),
intval($rr['id']) intval($rr['id'])

View file

@ -12,7 +12,7 @@ function po2php_run(&$argv, &$argc) {
$pofile = $argv[1]; $pofile = $argv[1];
$outfile = dirname($pofile)."/strings.php"; $outfile = dirname($pofile)."/strings.php";
if(strstr($outfile,'util')) if (strstr($outfile,'util'))
$lang = 'en'; $lang = 'en';
else else
$lang = str_replace('-','_',basename(dirname($pofile))); $lang = str_replace('-','_',basename(dirname($pofile)));