]> git.mxchange.org Git - friendica-addons.git/blobdiff - pumpio/pumpio.php
Merge pull request #520 from rabuzarus/20180206_-_membersince_frio_support
[friendica-addons.git] / pumpio / pumpio.php
index d0fe09d568e070fe6f2e730762a232faa28ac22e..8e194f85a0406ec61931a2e2fa1f22b542bbbe54 100644 (file)
@@ -5,6 +5,7 @@
  * Version: 0.2
  * Author: Michael Vogel <http://pirati.ca/profile/heluecht>
  */
+
 use Friendica\Core\Addon;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
@@ -13,10 +14,11 @@ use Friendica\Core\Worker;
 use Friendica\Model\Contact;
 use Friendica\Model\GContact;
 use Friendica\Model\Group;
-use Friendica\Model\User;
 use Friendica\Model\Item;
 use Friendica\Model\Queue;
 use Friendica\Util\Network;
+use Friendica\Model\User;
+use Friendica\Util\DateTimeFormat;
 
 require 'addon/pumpio/oauth/http.php';
 require 'addon/pumpio/oauth/oauth_client.php';
@@ -158,7 +160,7 @@ function pumpio_connect(&$a) {
        // Let's begin.  First we need a Request Token.  The request token is required to send the user
        // to pumpio's login page.
 
-       // Create a new instance of the TumblrOAuth library.  For this step, all we need to give the library is our
+       // Create a new instance of the oauth_client_class library.  For this step, all we need to give the library is our
        // Consumer Key and Consumer Secret
        $client = new oauth_client_class;
        $client->debug = 1;
@@ -541,10 +543,7 @@ function pumpio_send(&$a,&$b) {
                        logger('pumpio_send '.$username.': success '.$post_id);
                        if($post_id && $iscomment) {
                                logger('pumpio_send '.$username.': Update extid '.$post_id." for post id ".$b['id']);
-                               q("UPDATE `item` SET `extid` = '%s' WHERE `id` = %d",
-                                       dbesc($post_id),
-                                       intval($b['id'])
-                               );
+                               Item::update(['extid' => $post_id], ['id' => $b['id']]);
                        }
                } else {
                        logger('pumpio_send '.$username.': '.$url.' general error: ' . print_r($user,true));
@@ -554,7 +553,7 @@ function pumpio_send(&$a,&$b) {
                                $a->contact = $r[0]["id"];
 
                        $s = serialize(['url' => $url, 'item' => $b['id'], 'post' => $params]);
-                       
+
                        Queue::add($a->contact, NETWORK_PUMPIO, $s);
                        notice(L10n::t('Pump.io post failed. Queued for retry.').EOL);
                }
@@ -630,7 +629,7 @@ function pumpio_action(&$a, $uid, $uri, $action, $content = "") {
                        $a->contact = $r[0]["id"];
 
                $s = serialize(['url' => $url, 'item' => $orig_post["id"], 'post' => $params]);
-               
+
                Queue::add($a->contact, NETWORK_PUMPIO, $s);
                notice(L10n::t('Pump.io like failed. Queued for retry.').EOL);
        }
@@ -670,7 +669,7 @@ function pumpio_sync(&$a) {
        if ($abandon_days < 1)
                $abandon_days = 0;
 
-       $abandon_limit = date("Y-m-d H:i:s", time() - $abandon_days * 86400);
+       $abandon_limit = date(DateTimeFormat::MYSQL, time() - $abandon_days * 86400);
 
        $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'pumpio' AND `k` = 'import' AND `v` = '1' ORDER BY RAND() ");
        if(count($r)) {
@@ -868,13 +867,7 @@ function pumpio_dounlike(&$a, $uid, $self, $post, $own_id) {
                        $contactid = $orig_post['contact-id'];
        }
 
-       $r = q("UPDATE `item` SET `deleted` = 1, `unseen` = 1, `changed` = '%s' WHERE `verb` = '%s' AND `uid` = %d AND `contact-id` = %d AND `thr-parent` = '%s'",
-               dbesc(datetime_convert()),
-               dbesc(ACTIVITY_LIKE),
-               intval($uid),
-               intval($contactid),
-               dbesc($orig_post['uri'])
-       );
+       Item::delete(['verb' => ACTIVITY_LIKE, 'uid' => $uid, 'contact-id' => $contactid, 'thr-parent' => $orig_post['uri']]);
 
        if(count($r))
                logger("pumpio_dounlike: unliked existing like. User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']);
@@ -1000,7 +993,7 @@ function pumpio_get_contact($uid, $contact, $no_insert = false) {
                                        `location`, `about`, `writable`, `blocked`, `readonly`, `pending` )
                                VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', %d, 0, 0, 0)",
                        intval($uid),
-                       dbesc(datetime_convert()),
+                       dbesc(DateTimeFormat::utcNow()),
                        dbesc($contact->url),
                        dbesc(normalise_link($contact->url)),
                        dbesc(str_replace("acct:", "", $contact->id)),
@@ -1058,7 +1051,7 @@ function pumpio_dodelete(&$a, $uid, $self, $post, $own_id) {
                );
 
        if (count($r))
-               return Item::delete($r[0]["id"]);
+               return Item::deleteById($r[0]["id"]);
 
        $r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1",
                                dbesc($post->object->id),
@@ -1066,7 +1059,7 @@ function pumpio_dodelete(&$a, $uid, $self, $post, $own_id) {
                );
 
        if (count($r))
-               return Item::delete($r[0]["id"]);
+               return Item::deleteById($r[0]["id"]);
 }
 
 function pumpio_dopost(&$a, $client, $uid, $self, $post, $own_id, $threadcompletion = true) {
@@ -1209,11 +1202,11 @@ function pumpio_dopost(&$a, $client, $uid, $self, $post, $own_id, $threadcomplet
        if ($post->object->displayName != "")
                $postarray['title'] = $post->object->displayName;
 
-       $postarray['created'] = datetime_convert('UTC','UTC',$post->published);
+       $postarray['created'] = DateTimeFormat::utc($post->published);
        if (isset($post->updated))
-               $postarray['edited'] = datetime_convert('UTC','UTC',$post->updated);
+               $postarray['edited'] = DateTimeFormat::utc($post->updated);
        elseif (isset($post->received))
-               $postarray['edited'] = datetime_convert('UTC','UTC',$post->received);
+               $postarray['edited'] = DateTimeFormat::utc($post->received);
        else
                $postarray['edited'] = $postarray['created'];
 
@@ -1228,7 +1221,7 @@ function pumpio_dopost(&$a, $client, $uid, $self, $post, $own_id, $threadcomplet
 
                        $postarray['body'] = share_header($share_author, $post->object->author->url,
                                                        $post->object->author->image->url, "",
-                                                       datetime_convert('UTC','UTC',$post->object->created),
+                                                       DateTimeFormat::utc($post->object->created),
                                                        $post->links->self->href).
                                                $postarray['body']."[/share]";
 
@@ -1236,7 +1229,7 @@ function pumpio_dopost(&$a, $client, $uid, $self, $post, $own_id, $threadcomplet
                        $postarray['body'] = "[share author='".$share_author.
                                        "' profile='".$post->object->author->url.
                                        "' avatar='".$post->object->author->image->url.
-                                       "' posted='".datetime_convert('UTC','UTC',$post->object->created).
+                                       "' posted='".DateTimeFormat::convert($post->object->created, 'UTC', 'UTC', ).
                                        "' link='".$post->links->self->href."']".$postarray['body']."[/share]";
                        */
                } else {
@@ -1254,13 +1247,9 @@ function pumpio_dopost(&$a, $client, $uid, $self, $post, $own_id, $threadcomplet
        $postarray["id"] = $top_item;
 
        if (($top_item == 0) && ($post->verb == "update")) {
-               $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s' , `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d",
-                       dbesc($postarray["title"]),
-                       dbesc($postarray["body"]),
-                       dbesc($postarray["edited"]),
-                       dbesc($postarray["uri"]),
-                       intval($uid)
-                       );
+               $fields = ['title' => $postarray["title"], 'body' => $postarray["body"], 'changed' => $postarray["edited"]];
+               $condition = ['uri' => $postarray["uri"], 'uid' => $uid];
+               Item::update($fields, $condition);
        }
 
        if ($post->object->objectType == "comment") {
@@ -1489,10 +1478,7 @@ function pumpio_queue_hook(&$a,&$b) {
                                logger('pumpio_queue: send '.$username.': success '.$post_id);
                                if($post_id && $iscomment) {
                                        logger('pumpio_send '.$username.': Update extid '.$post_id." for post id ".$z['item']);
-                                       q("UPDATE `item` SET `extid` = '%s' WHERE `id` = %d",
-                                               dbesc($post_id),
-                                               intval($z['item'])
-                                       );
+                                       Item::update(['extid' => $post_id], ['id' => $z['item']]);
                                }
                                Queue::removeItem($x['id']);
                        } else