]> git.mxchange.org Git - friendica-addons.git/blobdiff - pumpio/pumpio.php
Add Temporal::utc() shorthand to Temporal::convert()
[friendica-addons.git] / pumpio / pumpio.php
index a9c7084dc6d3780a1db2330501a9e32181c7afb8..45dd57499de7a5f21dffba9a4baee0cd9bedef2e 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,9 +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\Temporal;
 
 require 'addon/pumpio/oauth/http.php';
 require 'addon/pumpio/oauth/oauth_client.php';
@@ -157,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;
@@ -553,7 +556,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);
                }
@@ -629,7 +632,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);
        }
@@ -669,7 +672,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(Temporal::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,7 +871,7 @@ function pumpio_dounlike(&$a, $uid, $self, $post, $own_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(Temporal::utcNow()),
                dbesc(ACTIVITY_LIKE),
                intval($uid),
                intval($contactid),
@@ -973,7 +976,7 @@ function pumpio_dolike(&$a, $uid, $self, $post, $own_id, $threadcompletion = tru
        $likedata['object'] = '<object><type>' . ACTIVITY_OBJ_NOTE . '</type><local>1</local>' .
                '<id>' . $orig_post['uri'] . '</id><link>' . xmlify('<link rel="alternate" type="text/html" href="' . xmlify($orig_post['plink']) . '" />') . '</link><title>' . $orig_post['title'] . '</title><content>' . $orig_post['body'] . '</content></object>';
 
-       $ret = item_store($likedata);
+       $ret = Item::insert($likedata);
 
        logger("pumpio_dolike: ".$ret." User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']);
 }
@@ -999,7 +1002,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(Temporal::utcNow()),
                        dbesc($contact->url),
                        dbesc(normalise_link($contact->url)),
                        dbesc(str_replace("acct:", "", $contact->id)),
@@ -1208,11 +1211,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'] = Temporal::utc($post->published);
        if (isset($post->updated))
-               $postarray['edited'] = datetime_convert('UTC','UTC',$post->updated);
+               $postarray['edited'] = Temporal::utc($post->updated);
        elseif (isset($post->received))
-               $postarray['edited'] = datetime_convert('UTC','UTC',$post->received);
+               $postarray['edited'] = Temporal::utc($post->received);
        else
                $postarray['edited'] = $postarray['created'];
 
@@ -1227,7 +1230,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),
+                                                       Temporal::utc($post->object->created),
                                                        $post->links->self->href).
                                                $postarray['body']."[/share]";
 
@@ -1235,7 +1238,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='".Temporal::convert($post->object->created, 'UTC', 'UTC', ).
                                        "' link='".$post->links->self->href."']".$postarray['body']."[/share]";
                        */
                } else {
@@ -1249,7 +1252,7 @@ function pumpio_dopost(&$a, $client, $uid, $self, $post, $own_id, $threadcomplet
        if (trim($postarray['body']) == "")
                return false;
 
-       $top_item = item_store($postarray);
+       $top_item = Item::insert($postarray);
        $postarray["id"] = $top_item;
 
        if (($top_item == 0) && ($post->verb == "update")) {
@@ -1305,7 +1308,7 @@ function pumpio_dopost(&$a, $client, $uid, $self, $post, $own_id, $threadcomplet
                                                'to_email'     => $user[0]['email'],
                                                'uid'          => $user[0]['uid'],
                                                'item'         => $postarray,
-                                               'link'         => $a->get_baseurl().'/display/'.urlencode(get_item_guid($top_item)),
+                                               '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'],
@@ -1698,7 +1701,7 @@ function pumpio_fetchallcomments(&$a, $uid, $id) {
 
 
 function pumpio_reachable($url) {
-       $data = z_fetch_url($url, false, $redirects, ['timeout'=>10]);
+       $data = Network::curl($url, false, $redirects, ['timeout'=>10]);
        return(intval($data['return_code']) != 0);
 }