]> git.mxchange.org Git - friendica.git/blobdiff - include/dfrn.php
Merge pull request #3168 from annando/bugfix-contact-posts
[friendica.git] / include / dfrn.php
index 272105128fe07a2ea4c9711a54cdf4d52deb6c67..702fbb15fe0f31a19c5eb831f4a0cb8d91b17f03 100644 (file)
@@ -105,8 +105,9 @@ class dfrn {
                        dbesc($owner_nick)
                );
 
-               if(! count($r))
+               if (! dbm::is_result($r)) {
                        killme();
+               }
 
                $owner = $r[0];
                $owner_id = $owner['uid'];
@@ -139,8 +140,9 @@ class dfrn {
                                intval($owner_id)
                        );
 
-                       if(! count($r))
+                       if (! dbm::is_result($r)) {
                                killme();
+                       }
 
                        $contact = $r[0];
                        require_once('include/security.php');
@@ -192,7 +194,7 @@ class dfrn {
                        `contact`.`name-date`, `contact`.`uri-date`, `contact`.`avatar-date`,
                        `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
                        `sign`.`signed_text`, `sign`.`signature`, `sign`.`signer`
-                       FROM `item` USE INDEX (`uid_wall_changed`, `uid_type_changed`) $sql_post_table
+                       FROM `item` USE INDEX (`uid_wall_changed`) $sql_post_table
                        STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
                        AND (NOT `contact`.`blocked` OR `contact`.`pending`)
                        LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id`
@@ -1103,12 +1105,22 @@ class dfrn {
         */
        private function birthday_event($contact, $birthday) {
 
+               // Check for duplicates
+               $r = q("SELECT `id` FROM `event` WHERE `uid` = %d AND `cid` = %d AND `start` = '%s' AND `type` = '%s' LIMIT 1",
+                       intval($contact["uid"]),
+                       intval($contact["id"]),
+                       dbesc(datetime_convert("UTC","UTC", $birthday)),
+                       dbesc("birthday"));
+
+               if (dbm::is_result($r)) {
+                       return;
+               }
+
                logger("updating birthday: ".$birthday." for contact ".$contact["id"]);
 
                $bdtext = sprintf(t("%s\'s birthday"), $contact["name"]);
                $bdtext2 = sprintf(t("Happy Birthday %s"), " [url=".$contact["url"]."]".$contact["name"]."[/url]") ;
 
-
                $r = q("INSERT INTO `event` (`uid`,`cid`,`created`,`edited`,`start`,`finish`,`summary`,`desc`,`type`)
                        VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s') ",
                        intval($contact["uid"]),
@@ -1159,7 +1171,7 @@ class dfrn {
 
                // Until now we aren't serving different sizes - but maybe later
                $avatarlist = array();
-               // @todo check if "avatar" or "photo" would be the best field in the specification
+               /// @todo check if "avatar" or "photo" would be the best field in the specification
                $avatars = $xpath->query($element."/atom:link[@rel='avatar']", $context);
                foreach($avatars AS $avatar) {
                        $href = "";
@@ -1379,7 +1391,7 @@ class dfrn {
 
                $objxml = $obj_doc->saveXML($obj_element);
 
-               // @todo This isn't totally clean. We should find a way to transform the namespaces
+               /// @todo This isn't totally clean. We should find a way to transform the namespaces
                $objxml = str_replace("<".$element.' xmlns="http://www.w3.org/2005/Atom">', "<".$element.">", $objxml);
                return($objxml);
        }
@@ -1409,9 +1421,9 @@ class dfrn {
                $msg["seen"] = 0;
                $msg["replied"] = 0;
 
-               dbesc_array($msg);
+               dbm::esc_array($msg, true);
 
-               $r = dbq("INSERT INTO `mail` (`".implode("`, `", array_keys($msg))."`) VALUES ('".implode("', '", array_values($msg))."')");
+               $r = dbq("INSERT INTO `mail` (`".implode("`, `", array_keys($msg))."`) VALUES (".implode(", ", array_values($msg)).")");
 
                // send notifications.
 
@@ -1443,6 +1455,7 @@ class dfrn {
         * @param array $importer Record of the importer user mixed with contact of the content
         */
        private function process_suggestion($xpath, $suggestion, $importer) {
+               $a = get_app();
 
                logger("Processing suggestions");
 
@@ -1462,7 +1475,7 @@ class dfrn {
                        dbesc(normalise_link($suggest["url"])),
                        intval($suggest["uid"])
                );
-               if(count($r))
+               if (dbm::is_result($r))
                        return false;
 
                // Do we already have an fcontact record for this person?
@@ -1473,7 +1486,7 @@ class dfrn {
                        dbesc($suggest["name"]),
                        dbesc($suggest["request"])
                );
-               if(count($r)) {
+               if (dbm::is_result($r)) {
                        $fid = $r[0]["id"];
 
                        // OK, we do. Do we already have an introduction for this person ?
@@ -1481,7 +1494,7 @@ class dfrn {
                                intval($suggest["uid"]),
                                intval($fid)
                        );
-                       if(count($r))
+                       if (dbm::is_result($r))
                                return false;
                }
                if(!$fid)
@@ -1496,7 +1509,7 @@ class dfrn {
                        dbesc($suggest["name"]),
                        dbesc($suggest["request"])
                );
-               if(count($r))
+               if (dbm::is_result($r))
                        $fid = $r[0]["id"];
                else
                        // database record did not get created. Quietly give up.
@@ -1745,7 +1758,7 @@ class dfrn {
                                LIMIT 1",
                                dbesc($item["parent-uri"])
                        );
-                       if($r && count($r)) {
+                       if (dbm::is_result($r)) {
                                $r = q("SELECT `item`.`forum_mode`, `item`.`wall` FROM `item`
                                        INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
                                        WHERE `item`.`uri` = '%s' AND (`item`.`parent-uri` = '%s' OR `item`.`thr-parent` = '%s')
@@ -1757,7 +1770,7 @@ class dfrn {
                                        dbesc($r[0]["parent-uri"]),
                                        intval($importer["importer_uid"])
                                );
-                               if($r && count($r))
+                               if (dbm::is_result($r))
                                        $is_a_remote_action = true;
                        }
 
@@ -1895,7 +1908,7 @@ class dfrn {
                                        dbesc($item["verb"]),
                                        dbesc($item["parent-uri"])
                                );
-                               if($r && count($r))
+                               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",
@@ -1904,7 +1917,7 @@ class dfrn {
                                        dbesc($item["verb"]),
                                        dbesc($item["parent-uri"])
                                );
-                               if($r && count($r))
+                               if (dbm::is_result($r))
                                        return false;
                        } else
                                $is_like = false;
@@ -1920,7 +1933,7 @@ class dfrn {
                                                intval($importer["importer_uid"])
                                        );
 
-                                       if(!count($r))
+                                       if (!dbm::is_result($r))
                                                return false;
 
                                        // extract tag, if not duplicate, add to parent item
@@ -2192,7 +2205,7 @@ class dfrn {
                                                dbesc($item["uri"]),
                                                intval($importer["uid"])
                                        );
-                                       if(count($r))
+                                       if (dbm::is_result($r))
                                                $ev["id"] = $r[0]["id"];
 
                                        $event_id = event_store($ev);
@@ -2213,7 +2226,7 @@ class dfrn {
                }
 
                // Update content if 'updated' changes
-               if(count($r)) {
+               if (dbm::is_result($r)) {
                        if (self::update_content($r[0], $item, $importer, $entrytype))
                                logger("Item ".$item["uri"]." was updated.", LOGGER_DEBUG);
                        else
@@ -2235,7 +2248,7 @@ class dfrn {
                                        intval($posted_id),
                                        intval($importer["importer_uid"])
                                );
-                               if(count($r)) {
+                               if (dbm::is_result($r)) {
                                        $parent = $r[0]["parent"];
                                        $parent_uri = $r[0]["parent-uri"];
                                }
@@ -2323,7 +2336,7 @@ class dfrn {
                                intval($importer["uid"]),
                                intval($importer["id"])
                        );
-               if(!count($r)) {
+               if (!dbm::is_result($r)) {
                        logger("Item with uri ".$uri." from contact ".$importer["id"]." for user ".$importer["uid"]." wasn't found.", LOGGER_DEBUG);
                        return;
                } else {
@@ -2352,7 +2365,7 @@ class dfrn {
                                                dbesc($xt->id),
                                                intval($importer["importer_uid"])
                                        );
-                                       if(count($i)) {
+                                       if (dbm::is_result($i)) {
 
                                                // For tags, the owner cannot remove the tag on the author's copy of the post.
 
@@ -2417,7 +2430,7 @@ class dfrn {
                                                        dbesc($item["parent-uri"]),
                                                        intval($importer["uid"])
                                        );
-                                       if(count($r)) {
+                                       if (dbm::is_result($r)) {
                                                q("UPDATE `item` SET `last-child` = 1 WHERE `id` = %d",
                                                        intval($r[0]["id"])
                                                );