]> git.mxchange.org Git - friendica-addons.git/commitdiff
Some more replaced item SQL queries
authorMichael <heluecht@pirati.ca>
Thu, 21 Jun 2018 06:23:27 +0000 (06:23 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 21 Jun 2018 06:23:27 +0000 (06:23 +0000)
mailstream/mailstream.php
statusnet/statusnet.php
viewsrc/viewsrc.php

index cf2fcc84852ebc96d36e23b4bafcccf270c8ff51..66b43303597bbea31a2ac145f494d8e803c81be6 100644 (file)
@@ -213,17 +213,17 @@ function mailstream_subject($item) {
        $parent = $item['thr-parent'];
        // Don't look more than 100 levels deep for a subject, in case of loops
        for ($i = 0; ($i < 100) && $parent; $i++) {
-               $r = q("SELECT `thr-parent`, `title` FROM `item` WHERE `uri` = '%s'", dbesc($parent));
-               if (!DBM::is_result($r)) {
+               $parent_item = Item::selectFirst(['thr-parent', 'title'], ['uri' => $parent]);
+               if (!DBM::is_result($parent_item)) {
                        break;
                }
-               if ($r[0]['thr-parent'] === $parent) {
+               if ($parent_item['thr-parent'] === $parent) {
                        break;
                }
-               if ($r[0]['title']) {
-                       return L10n::t('Re:') . ' ' . mailstream_decode_subject($r[0]['title']);
+               if ($parent_item['title']) {
+                       return L10n::t('Re:') . ' ' . mailstream_decode_subject($parent_item['title']);
                }
-               $parent = $r[0]['thr-parent'];
+               $parent = $parent_item['thr-parent'];
        }
        $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d",
                intval($item['contact-id']), intval($item['uid']));
index 43f5d400f85b4492b4843d22a652f1f6c98b8576..ced884cbad7252279ae29c1596d2b23de5db027a 100644 (file)
@@ -1075,12 +1075,7 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex
 
        $postarray['uri'] = $hostname . "::" . $content->id;
 
-       $r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1",
-                       dbesc($postarray['uri']),
-                       intval($uid)
-       );
-
-       if (DBM::is_result($r)) {
+       if (dba::exists('item', ['extid' => $postarray['uri'], 'uid' => $uid])) {
                return [];
        }
 
@@ -1090,30 +1085,22 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex
 
                $parent = $hostname . "::" . $content->in_reply_to_status_id;
 
-               $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
-                               dbesc($parent),
-                               intval($uid)
-               );
-               if (DBM::is_result($r)) {
-                       $postarray['thr-parent'] = $r[0]["uri"];
-                       $postarray['parent-uri'] = $r[0]["parent-uri"];
-                       $postarray['parent'] = $r[0]["parent"];
+               $fields = ['uri', 'parent-uri', 'parent'];
+               $item = Item::selectFirst($fields, ['uri' => $parent, 'uid' => $uid]);
+
+               if (!DBM::is_result($item)) {
+                       $item = Item::selectFirst($fields, ['extid' => $parent, 'uid' => $uid]);
+               }
+
+               if (DBM::is_result($item)) {
+                       $postarray['thr-parent'] = $item['uri'];
+                       $postarray['parent-uri'] = $item['parent-uri'];
+                       $postarray['parent'] = $item['parent'];
                        $postarray['object-type'] = ACTIVITY_OBJ_COMMENT;
                } else {
-                       $r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1",
-                                       dbesc($parent),
-                                       intval($uid)
-                       );
-                       if (DBM::is_result($r)) {
-                               $postarray['thr-parent'] = $r[0]['uri'];
-                               $postarray['parent-uri'] = $r[0]['parent-uri'];
-                               $postarray['parent'] = $r[0]['parent'];
-                               $postarray['object-type'] = ACTIVITY_OBJ_COMMENT;
-                       } else {
-                               $postarray['thr-parent'] = $postarray['uri'];
-                               $postarray['parent-uri'] = $postarray['uri'];
-                               $postarray['object-type'] = ACTIVITY_OBJ_NOTE;
-                       }
+                       $postarray['thr-parent'] = $postarray['uri'];
+                       $postarray['parent-uri'] = $postarray['uri'];
+                       $postarray['object-type'] = ACTIVITY_OBJ_NOTE;
                }
 
                // Is it me?
index c7ed10c717023bea22c63556292952cc5b884ce3..1655e8deb5b7eb9938e5e6fbc2be69c289539604 100644 (file)
@@ -8,6 +8,8 @@
  */
 use Friendica\Core\Addon;
 use Friendica\Core\L10n;
+use Friendica\ModelItem;
+use Friendica\Database\DBM;
 
 function viewsrc_install() {
        Addon::registerHook('item_photo_menu', 'addon/viewsrc/viewsrc.php', 'viewsrc_item_photo_menu');
@@ -40,14 +42,12 @@ function viewsrc_item_photo_menu(&$a, &$b)
        }
 
        if (local_user() != $b['item']['uid']) {
-               $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `guid` = '%s'",
-                               intval(local_user()), dbesc($b['item']['guid']));
-
-               if (!$r) {
+               $item = Item::selectFirstForUser(local_user(), ['id'], ['uid' => local_user(), 'guid' => $b['item']['guid']]);
+               if (!DBM::is_result($item)) {
                        return;
                }
 
-               $item_id = $r[0]['id'];
+               $item_id = $item['id'];
        } else {
                $item_id = $b['item']['id'];
        }