Some code beautification.

This commit is contained in:
Michael Vogel 2015-06-07 23:53:51 +02:00
parent a3c497190d
commit af79cd316c

View file

@ -120,19 +120,25 @@ function ostatus_import($xml,$importer,&$contact) {
// Now get the item // Now get the item
$item["uri"] = $xpath->query('atom:id/text()', $entry)->item(0)->nodeValue; $item["uri"] = $xpath->query('atom:id/text()', $entry)->item(0)->nodeValue;
$r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s'",
intval($importer["uid"]), dbesc($item["uri"]));
if ($r) {
logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already existed under id ".$r[0]["id"], LOGGER_DEBUG);
continue;
}
$item["body"] = html2bbcode($xpath->query('atom:content/text()', $entry)->item(0)->nodeValue); $item["body"] = html2bbcode($xpath->query('atom:content/text()', $entry)->item(0)->nodeValue);
$item["object-type"] = $xpath->query('activity:object-type/text()', $entry)->item(0)->nodeValue; $item["object-type"] = $xpath->query('activity:object-type/text()', $entry)->item(0)->nodeValue;
$item["verb"] = $xpath->query('activity:verb/text()', $entry)->item(0)->nodeValue; $item["verb"] = $xpath->query('activity:verb/text()', $entry)->item(0)->nodeValue;
if ($item["verb"] == ACTIVITY_FOLLOW) { if ($item["verb"] == ACTIVITY_FOLLOW) {
// ignore "Follow" messages // ignore "Follow" messages
$item = array();
continue; continue;
} }
if ($item["verb"] == ACTIVITY_FAVORITE) { if ($item["verb"] == ACTIVITY_FAVORITE) {
// ignore "Favorite" messages // ignore "Favorite" messages
$item = array();
continue; continue;
} }
@ -304,50 +310,44 @@ function ostatus_import($xml,$importer,&$contact) {
} else } else
$item["parent-uri"] = $item["uri"]; $item["parent-uri"] = $item["uri"];
$r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s'", $item_id = item_store($item);
intval($importer["uid"]), dbesc($item["uri"])); //echo $xml;
if (!$r) { //print_r($item);
$item_id = item_store($item); //echo $item_id." ".$item["parent-uri"]."\n";
//echo $xml;
//print_r($item);
//echo $item_id." ".$item["parent-uri"]."\n";
if ($item_id) if (!$item_id) {
logger("Item was stored with id ".$item_id, LOGGER_DEBUG); logger("Error storing item ".print_r($item, true), LOGGER_DEBUG);
else continue;
logger("Error storing item ".print_r($item, true), LOGGER_DEBUG);
$item["id"] = $item_id;
if (!isset($item["parent"]) OR ($item["parent"] == 0))
$item["parent"] = $item_id;
if ($mention AND ($item["id"] != 0)) {
$u = q("SELECT `notify-flags`, `language`, `username`, `email` FROM user WHERE uid = %d LIMIT 1", intval($item['uid']));
notification(array(
'type' => NOTIFY_TAGSELF,
'notify_flags' => $u[0]["notify-flags"],
'language' => $u[0]["language"],
'to_name' => $u[0]["username"],
'to_email' => $u[0]["email"],
'uid' => $item["uid"],
'item' => $item,
'link' => $a->get_baseurl().'/display/'.urlencode(get_item_guid($item["id"])),
'source_name' => $item["author-name"],
'source_link' => $item["author-link"],
'source_photo' => $item["author-avatar"],
'verb' => ACTIVITY_TAG,
'otype' => 'item',
'parent' => $item["parent"]
));
}
} else {
$item_id = $r[0]["id"];
logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already existed under id ".$r[0]["id"], LOGGER_DEBUG);
} }
if (($conversation != "") AND ($item_id != 0)) { logger("Item was stored with id ".$item_id, LOGGER_DEBUG);
$item["id"] = $item_id;
if (!isset($item["parent"]) OR ($item["parent"] == 0))
$item["parent"] = $item_id;
if ($mention) {
$u = q("SELECT `notify-flags`, `language`, `username`, `email` FROM user WHERE uid = %d LIMIT 1", intval($item['uid']));
notification(array(
'type' => NOTIFY_TAGSELF,
'notify_flags' => $u[0]["notify-flags"],
'language' => $u[0]["language"],
'to_name' => $u[0]["username"],
'to_email' => $u[0]["email"],
'uid' => $item["uid"],
'item' => $item,
'link' => $a->get_baseurl().'/display/'.urlencode(get_item_guid($item["id"])),
'source_name' => $item["author-name"],
'source_link' => $item["author-link"],
'source_photo' => $item["author-avatar"],
'verb' => ACTIVITY_TAG,
'otype' => 'item',
'parent' => $item["parent"]
));
}
if ($conversation != "") {
// Check for duplicates. We really don't need to check the same conversation twice. // Check for duplicates. We really don't need to check the same conversation twice.
if (!in_array($conversation, $conversationlist)) { if (!in_array($conversation, $conversationlist)) {
complete_conversation($item_id, $conversation); complete_conversation($item_id, $conversation);