X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=pumpio%2Fpumpio.php;h=d57f1485a5d71b2eb7cf634ea9b1af3c071343d4;hb=392bb7d5aa75e4549584ce618d8dbb8a9a6764db;hp=be4db5fafdcd9b82c49823f7d4d3276c932e4919;hpb=c6e5bc3429c9c610895ba826d841cddd8c0f378b;p=friendica-addons.git diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index be4db5fa..d57f1485 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -5,15 +5,22 @@ * Version: 0.2 * Author: Michael Vogel */ + +use Friendica\Content\Text\BBCode; +use Friendica\Content\Text\HTML; use Friendica\Core\Addon; use Friendica\Core\Config; +use Friendica\Core\L10n; use Friendica\Core\PConfig; 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\Model\User; +use Friendica\Util\DateTimeFormat; +use Friendica\Util\Network; require 'addon/pumpio/oauth/http.php'; require 'addon/pumpio/oauth/oauth_client.php'; @@ -49,7 +56,7 @@ function pumpio_module() {} function pumpio_content(&$a) { if(! local_user()) { - notice( t('Permission denied.') . EOL); + notice(L10n::t('Permission denied.') . EOL); return ''; } @@ -145,7 +152,7 @@ function pumpio_connect(&$a) { if (($consumer_key == "") || ($consumer_secret == "")) { logger("pumpio_connect: ".sprintf("Unable to register the client at the pump.io server '%s'.", $hostname)); - $o .= sprintf(t("Unable to register the client at the pump.io server '%s'."), $hostname); + $o .= L10n::t("Unable to register the client at the pump.io server '%s'.", $hostname); return($o); } @@ -155,7 +162,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; @@ -185,8 +192,8 @@ function pumpio_connect(&$a) { if($success) { logger("pumpio_connect: authenticated"); - $o .= t("You are now authenticated to pumpio."); - $o .= '
'.t("return to the connector page").''; + $o .= L10n::t("You are now authenticated to pumpio."); + $o .= '
'.L10n::t("return to the connector page").''; } else { logger("pumpio_connect: could not connect"); $o = 'Could not connect to pumpio. Refresh the page or try again later.'; @@ -204,7 +211,7 @@ function pumpio_jot_nets(&$a,&$b) { $pumpio_defpost = PConfig::get(local_user(),'pumpio','post_by_default'); $selected = ((intval($pumpio_defpost) == 1) ? ' checked="checked" ' : ''); $b .= '
' - . t('Post to pumpio') . '
'; + . L10n::t('Post to pumpio') . ''; } } @@ -242,20 +249,20 @@ function pumpio_settings(&$a,&$s) { /* Add some HTML to the existing form */ $s .= ''; - $s .= '

'. t('Pump.io Import/Export/Mirror').'

'; + $s .= '

'. L10n::t('Pump.io Import/Export/Mirror').'

'; $s .= '
'; $s .= ''; } @@ -465,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 = []; @@ -538,10 +542,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)); @@ -551,11 +552,10 @@ function pumpio_send(&$a,&$b) { $a->contact = $r[0]["id"]; $s = serialize(['url' => $url, 'item' => $b['id'], 'post' => $params]); - require_once('include/queue_fn.php'); - add_to_queue($a->contact,NETWORK_PUMPIO,$s); - notice(t('Pump.io post failed. Queued for retry.').EOL); - } + Queue::add($a->contact, NETWORK_PUMPIO, $s); + notice(L10n::t('Pump.io post failed. Queued for retry.').EOL); + } } } @@ -628,9 +628,9 @@ function pumpio_action(&$a, $uid, $uri, $action, $content = "") { $a->contact = $r[0]["id"]; $s = serialize(['url' => $url, 'item' => $orig_post["id"], 'post' => $params]); - require_once('include/queue_fn.php'); - add_to_queue($a->contact,NETWORK_PUMPIO,$s); - notice(t('Pump.io like failed. Queued for retry.').EOL); + + Queue::add($a->contact, NETWORK_PUMPIO, $s); + notice(L10n::t('Pump.io like failed. Queued for retry.').EOL); } } @@ -668,7 +668,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)) { @@ -719,7 +719,7 @@ function pumpio_fetchtimeline(&$a, $uid) { // get the application name for the pump.io app // 1st try personal config, then system config and fallback to the // hostname of the node if neither one is set. - $application_name = PConfig::get( $uid, 'pumpio', 'application_name'); + $application_name = PConfig::get($uid, 'pumpio', 'application_name'); if ($application_name == "") $application_name = Config::get('pumpio', 'application_name'); if ($application_name == "") @@ -783,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; @@ -799,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 != "") { @@ -866,13 +864,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']); @@ -953,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; @@ -963,16 +955,16 @@ function pumpio_dolike(&$a, $uid, $self, $post, $own_id, $threadcompletion = tru $author = '[url=' . $likedata['author-link'] . ']' . $likedata['author-name'] . '[/url]'; $objauthor = '[url=' . $orig_post['author-link'] . ']' . $orig_post['author-name'] . '[/url]'; - $post_type = t('status'); + $post_type = L10n::t('status'); $plink = '[url=' . $orig_post['plink'] . ']' . $post_type . '[/url]'; $likedata['object-type'] = ACTIVITY_OBJ_NOTE; - $likedata['body'] = sprintf( t('%1$s likes %2$s\'s %3$s'), $author, $objauthor, $plink); + $likedata['body'] = L10n::t('%1$s likes %2$s\'s %3$s', $author, $objauthor, $plink); $likedata['object'] = '' . ACTIVITY_OBJ_NOTE . '1' . '' . $orig_post['uri'] . '' . xmlify('') . '' . $orig_post['title'] . '' . $orig_post['body'] . ''; - $ret = item_store($likedata); + $ret = Item::insert($likedata); logger("pumpio_dolike: ".$ret." User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']); } @@ -998,7 +990,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)), @@ -1050,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::delete($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::delete($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); @@ -1198,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 != "") @@ -1207,11 +1195,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']; @@ -1226,17 +1214,9 @@ 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]"; - - /* - $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). - "' link='".$post->links->self->href."']".$postarray['body']."[/share]"; - */ } else { // Let shares look like wall-to-wall posts $postarray['author-name'] = $post->object->author->displayName; @@ -1248,76 +1228,19 @@ 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")) { - $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") { 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(get_item_guid($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; @@ -1433,8 +1356,6 @@ function pumpio_queue_hook(&$a,&$b) { if(! count($qi)) return; - require_once('include/queue_fn.php'); - foreach($qi as $x) { if($x['network'] !== NETWORK_PUMPIO) continue; @@ -1489,12 +1410,9 @@ 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']]); } - remove_queue_item($x['id']); + Queue::removeItem($x['id']); } else logger('pumpio_queue: send '.$username.': '.$url.' general error: ' . print_r($user,true)); } else @@ -1502,7 +1420,7 @@ function pumpio_queue_hook(&$a,&$b) { if (!$success) { logger('pumpio_queue: delayed'); - update_queue_time($x['id']); + Queue::updateTime($x['id']); } } } @@ -1699,7 +1617,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); }