+ /**
+ * @brief Processes several actions, depending on the verb
+ *
+ * @param int $entrytype Is it a toplevel entry, a comment or a relayed comment?
+ * @param array $importer Record of the importer user mixed with contact of the content
+ * @param array $item the new item record
+ * @param bool $is_like Is the verb a "like"?
+ *
+ * @return bool Should the processing of the entries be continued?
+ */
+ private static function process_verbs($entrytype, $importer, &$item, &$is_like) {
+
+ logger("Process verb ".$item["verb"]." and object-type ".$item["object-type"]." for entrytype ".$entrytype, LOGGER_DEBUG);
+
+ if (($entrytype == DFRN_TOP_LEVEL)) {
+ // The filling of the the "contact" variable is done for legcy reasons
+ // The functions below are partly used by ostatus.php as well - where we have this variable
+ $r = q("SELECT * FROM `contact` WHERE `id` = %d", intval($importer["id"]));
+ $contact = $r[0];
+ $nickname = $contact["nick"];
+
+ // Big question: Do we need these functions? They were part of the "consume_feed" function.
+ // This function once was responsible for DFRN and OStatus.
+ if (activity_match($item["verb"],ACTIVITY_FOLLOW)) {
+ logger("New follower");
+ new_follower($importer, $contact, $item, $nickname);
+ return false;
+ }
+ if (activity_match($item["verb"],ACTIVITY_UNFOLLOW)) {
+ logger("Lost follower");
+ lose_follower($importer, $contact, $item);
+ return false;
+ }
+ if (activity_match($item["verb"],ACTIVITY_REQ_FRIEND)) {
+ logger("New friend request");
+ new_follower($importer, $contact, $item, $nickname, true);
+ return false;
+ }
+ if (activity_match($item["verb"],ACTIVITY_UNFRIEND)) {
+ logger("Lost sharer");
+ lose_sharer($importer, $contact, $item);
+ return false;
+ }
+ } else {
+ if(($item["verb"] == ACTIVITY_LIKE)
+ || ($item["verb"] == ACTIVITY_DISLIKE)
+ || ($item["verb"] == ACTIVITY_ATTEND)
+ || ($item["verb"] == ACTIVITY_ATTENDNO)
+ || ($item["verb"] == ACTIVITY_ATTENDMAYBE)) {
+ $is_like = true;
+ $item["type"] = "activity";
+ $item["gravity"] = GRAVITY_LIKE;
+ // only one like or dislike per person
+ // splitted into two queries for performance issues
+ $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `author-link` = '%s' AND `verb` = '%s' AND `parent-uri` = '%s' AND NOT `deleted` LIMIT 1",
+ intval($item["uid"]),
+ dbesc($item["author-link"]),
+ dbesc($item["verb"]),
+ dbesc($item["parent-uri"])
+ );
+ if (dbm::is_result($r)) {
+ return false;
+ }
+
+ $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `author-link` = '%s' AND `verb` = '%s' AND `thr-parent` = '%s' AND NOT `deleted` LIMIT 1",
+ intval($item["uid"]),
+ dbesc($item["author-link"]),
+ dbesc($item["verb"]),
+ dbesc($item["parent-uri"])
+ );
+ if (dbm::is_result($r)) {
+ return false;
+ }
+ } else {
+ $is_like = false;
+ }
+
+ if (($item["verb"] == ACTIVITY_TAG) && ($item["object-type"] == ACTIVITY_OBJ_TAGTERM)) {
+
+ $xo = parse_xml_string($item["object"],false);
+ $xt = parse_xml_string($item["target"],false);
+
+ if ($xt->type == ACTIVITY_OBJ_NOTE) {
+ $r = q("SELECT `id`, `tag` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+ dbesc($xt->id),
+ intval($importer["importer_uid"])
+ );
+
+ if (!dbm::is_result($r)) {
+ killme();
+ }
+
+ // extract tag, if not duplicate, add to parent item
+ if ($xo->content) {
+ if (!(stristr($r[0]["tag"],trim($xo->content)))) {
+ q("UPDATE `item` SET `tag` = '%s' WHERE `id` = %d",
+ dbesc($r[0]["tag"] . (strlen($r[0]["tag"]) ? ',' : '') . '#[url=' . $xo->id . ']'. $xo->content . '[/url]'),
+ intval($r[0]["id"])
+ );
+ create_tags_from_item($r[0]["id"]);
+ }
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
+ * @brief Processes the link elements
+ *
+ * @param object $links link elements
+ * @param array $item the item record
+ * @todo Add type-hints
+ */
+ private static function parse_links($links, &$item) {
+ $rel = "";
+ $href = "";
+ $type = "";
+ $length = "0";
+ $title = "";
+ foreach ($links AS $link) {
+ foreach ($link->attributes AS $attributes) {
+ /// @TODO Rewrite these repeated (same) if() statements to a switch()
+ if ($attributes->name == "href") {
+ $href = $attributes->textContent;
+ }
+ if ($attributes->name == "rel") {
+ $rel = $attributes->textContent;
+ }
+ if ($attributes->name == "type") {
+ $type = $attributes->textContent;
+ }
+ if ($attributes->name == "length") {
+ $length = $attributes->textContent;
+ }
+ if ($attributes->name == "title") {
+ $title = $attributes->textContent;
+ }
+ }
+ if (($rel != "") AND ($href != ""))
+ switch($rel) {
+ case "alternate":
+ $item["plink"] = $href;
+ break;
+ case "enclosure":
+ $enclosure = $href;
+ if (strlen($item["attach"])) {
+ $item["attach"] .= ",";
+ }
+
+ $item["attach"] .= '[attach]href="'.$href.'" length="'.$length.'" type="'.$type.'" title="'.$title.'"[/attach]';
+ break;
+ }
+ }
+ }
+
+ /**
+ * @brief Processes the entry elements which contain the items and comments
+ *
+ * @param array $header Array of the header elements that always stay the same
+ * @param object $xpath XPath object
+ * @param object $entry entry elements
+ * @param array $importer Record of the importer user mixed with contact of the content
+ * @todo Add type-hints
+ */
+ private static function process_entry($header, $xpath, $entry, $importer) {