]> git.mxchange.org Git - friendica-addons.git/blobdiff - pumpio/pumpio.php
Remove direct item sql queries
[friendica-addons.git] / pumpio / pumpio.php
index 8e194f85a0406ec61931a2e2fa1f22b542bbbe54..d57f1485a5d71b2eb7cf634ea9b1af3c071343d4 100644 (file)
@@ -6,6 +6,8 @@
  * Author: Michael Vogel <http://pirati.ca/profile/heluecht>
  */
 
+use Friendica\Content\Text\BBCode;
+use Friendica\Content\Text\HTML;
 use Friendica\Core\Addon;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
@@ -16,9 +18,9 @@ use Friendica\Model\GContact;
 use Friendica\Model\Group;
 use Friendica\Model\Item;
 use Friendica\Model\Queue;
-use Friendica\Util\Network;
 use Friendica\Model\User;
 use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Network;
 
 require 'addon/pumpio/oauth/http.php';
 require 'addon/pumpio/oauth/oauth_client.php';
@@ -470,12 +472,9 @@ function pumpio_send(&$a,&$b) {
        $public = PConfig::get($b['uid'], "pumpio", "public");
 
        if($oauth_token && $oauth_token_secret) {
-
-               require_once('include/bbcode.php');
-
                $title = trim($b['title']);
 
-               $content = bbcode($b['body'], false, false, 4);
+               $content = BBCode::convert($b['body'], false, 4);
 
                $params = [];
 
@@ -784,8 +783,6 @@ function pumpio_fetchtimeline(&$a, $uid) {
                                                $public = true;
 
                        if ($public && !stristr($post->generator->displayName, $application_name)) {
-                               require_once('include/html2bbcode.php');
-
                                $_SESSION["authenticated"] = true;
                                $_SESSION["uid"] = $uid;
 
@@ -800,11 +797,11 @@ function pumpio_fetchtimeline(&$a, $uid) {
                                }
 
                                if ($post->object->displayName != "")
-                                       $_REQUEST["title"] = html2bbcode($post->object->displayName);
+                                       $_REQUEST["title"] = HTML::toBBCode($post->object->displayName);
                                else
                                        $_REQUEST["title"] = "";
 
-                               $_REQUEST["body"] = html2bbcode($post->object->content);
+                               $_REQUEST["body"] = HTML::toBBCode($post->object->content);
 
                                // To-Do: Picture has to be cached and stored locally
                                if ($post->object->fullImage->url != "") {
@@ -948,7 +945,7 @@ function pumpio_dolike(&$a, $uid, $self, $post, $own_id, $threadcompletion = tru
        $likedata['gravity'] = 3;
        $likedata['uid'] = $uid;
        $likedata['wall'] = 0;
-       $likedata['uri'] = item_new_uri($a->get_baseurl(), $uid);
+       $likedata['uri'] = Item::newURI($uid);
        $likedata['parent-uri'] = $orig_post["uri"];
        $likedata['contact-id'] = $contactid;
        $likedata['app'] = $post->generator->displayName;
@@ -1045,26 +1042,22 @@ function pumpio_get_contact($uid, $contact, $no_insert = false) {
 function pumpio_dodelete(&$a, $uid, $self, $post, $own_id) {
 
        // Two queries for speed issues
-       $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
-                               dbesc($post->object->id),
-                               intval($uid)
-               );
-
-       if (count($r))
-               return Item::deleteById($r[0]["id"]);
-
-       $r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1",
-                               dbesc($post->object->id),
-                               intval($uid)
-               );
+       $condition = ['uri' => $post->object->id, 'uid' => $uid];
+       if (dba::exists('item', $condition)) {
+               Item::delete($condition);
+               return true;
+       }
 
-       if (count($r))
-               return Item::deleteById($r[0]["id"]);
+       $condition = ['extid' => $post->object->id, 'uid' => $uid];
+       if (dba::exists('item', $condition)) {
+               Item::delete($condition);
+               return true;
+       }
+       return false;
 }
 
 function pumpio_dopost(&$a, $client, $uid, $self, $post, $own_id, $threadcompletion = true) {
        require_once('include/items.php');
-       require_once('include/html2bbcode.php');
 
        if (($post->verb == "like") || ($post->verb == "favorite"))
                return pumpio_dolike($a, $uid, $self, $post, $own_id);
@@ -1193,7 +1186,7 @@ function pumpio_dopost(&$a, $client, $uid, $self, $post, $own_id, $threadcomplet
        $postarray['author-avatar'] = $post->actor->image->url;
        $postarray['plink'] = $post->object->url;
        $postarray['app'] = $post->generator->displayName;
-       $postarray['body'] = html2bbcode($post->object->content);
+       $postarray['body'] = HTML::toBBCode($post->object->content);
        $postarray['object'] = json_encode($post);
 
        if ($post->object->fullImage->url != "")
@@ -1224,14 +1217,6 @@ function pumpio_dopost(&$a, $client, $uid, $self, $post, $own_id, $threadcomplet
                                                        DateTimeFormat::utc($post->object->created),
                                                        $post->links->self->href).
                                                $postarray['body']."[/share]";
-
-                       /*
-                       $postarray['body'] = "[share author='".$share_author.
-                                       "' profile='".$post->object->author->url.
-                                       "' avatar='".$post->object->author->image->url.
-                                       "' posted='".DateTimeFormat::convert($post->object->created, 'UTC', 'UTC', ).
-                                       "' link='".$post->links->self->href."']".$postarray['body']."[/share]";
-                       */
                } else {
                        // Let shares look like wall-to-wall posts
                        $postarray['author-name'] = $post->object->author->displayName;
@@ -1256,59 +1241,6 @@ function pumpio_dopost(&$a, $client, $uid, $self, $post, $own_id, $threadcomplet
 
                if ($threadcompletion)
                        pumpio_fetchallcomments($a, $uid, $postarray['parent-uri']);
-
-               $user = q("SELECT * FROM `user` WHERE `uid` = %d AND `account_expired` = 0 LIMIT 1",
-                               intval($uid)
-                       );
-
-               if(!count($user))
-                       return $top_item;
-
-               $importer_url = $a->get_baseurl() . '/profile/' . $user[0]['nickname'];
-
-               if (link_compare($own_id, $postarray['author-link']))
-                       return $top_item;
-
-               if (!function_exists("check_item_notification")) {
-                       $myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 AND `deleted` = 0",
-                                       dbesc($postarray['parent-uri']),
-                                       intval($uid)
-                                       );
-
-                       if(count($myconv)) {
-
-                               foreach($myconv as $conv) {
-                                       // now if we find a match, it means we're in this conversation
-
-                                       if(!link_compare($conv['author-link'],$importer_url) && !link_compare($conv['author-link'],$own_id))
-                                               continue;
-
-                                       require_once('include/enotify.php');
-
-                                       $conv_parent = $conv['parent'];
-
-                                       notification([
-                                               'type'         => NOTIFY_COMMENT,
-                                               'notify_flags' => $user[0]['notify-flags'],
-                                               'language'     => $user[0]['language'],
-                                               'to_name'      => $user[0]['username'],
-                                               'to_email'     => $user[0]['email'],
-                                               'uid'          => $user[0]['uid'],
-                                               'item'         => $postarray,
-                                               'link'         => $a->get_baseurl().'/display/'.urlencode(Item::getGuidById($top_item)),
-                                               'source_name'  => $postarray['author-name'],
-                                               'source_link'  => $postarray['author-link'],
-                                               'source_photo' => $postarray['author-avatar'],
-                                               'verb'         => ACTIVITY_POST,
-                                               'otype'        => 'item',
-                                               'parent'       => $conv_parent,
-                                               ]);
-
-                                       // only send one notification
-                                       break;
-                               }
-                       }
-               }
        }
 
        return $top_item;