X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=pumpio%2Fpumpio.php;h=cd44b682e6ddf5e760cd65ade8e4ed152cee7252;hb=a0344101f122248c3069a5dcfa3ebfcb67215d5a;hp=b5c5029fb358ee6a3bba99f0861fa103f5ac8f10;hpb=74f89673cb21c263e41d1e5957d85176eb5de8d5;p=friendica-addons.git
diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php
index b5c5029f..cd44b682 100644
--- a/pumpio/pumpio.php
+++ b/pumpio/pumpio.php
@@ -9,22 +9,20 @@
use Friendica\App;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
-use Friendica\Core\Config;
use Friendica\Core\Hook;
-use Friendica\Core\L10n;
use Friendica\Core\Logger;
-use Friendica\Core\PConfig;
use Friendica\Core\Protocol;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
+use Friendica\DI;
use Friendica\Model\Contact;
-use Friendica\Model\GContact;
use Friendica\Model\Group;
use Friendica\Model\Item;
-use Friendica\Model\Queue;
use Friendica\Model\User;
+use Friendica\Protocol\Activity;
+use Friendica\Protocol\ActivityNamespace;
+use Friendica\Util\ConfigFileLoader;
use Friendica\Util\DateTimeFormat;
-use Friendica\Util\Network;
use Friendica\Util\Strings;
use Friendica\Util\XML;
@@ -44,30 +42,15 @@ function pumpio_install()
Hook::register('connector_settings', 'addon/pumpio/pumpio.php', 'pumpio_settings');
Hook::register('connector_settings_post', 'addon/pumpio/pumpio.php', 'pumpio_settings_post');
Hook::register('cron', 'addon/pumpio/pumpio.php', 'pumpio_cron');
- Hook::register('queue_predeliver', 'addon/pumpio/pumpio.php', 'pumpio_queue_hook');
Hook::register('check_item_notification', 'addon/pumpio/pumpio.php', 'pumpio_check_item_notification');
}
-function pumpio_uninstall()
-{
- Hook::unregister('load_config', 'addon/pumpio/pumpio.php', 'pumpio_load_config');
- Hook::unregister('hook_fork', 'addon/pumpio/pumpio.php', 'pumpio_hook_fork');
- Hook::unregister('post_local', 'addon/pumpio/pumpio.php', 'pumpio_post_local');
- Hook::unregister('notifier_normal', 'addon/pumpio/pumpio.php', 'pumpio_send');
- Hook::unregister('jot_networks', 'addon/pumpio/pumpio.php', 'pumpio_jot_nets');
- Hook::unregister('connector_settings', 'addon/pumpio/pumpio.php', 'pumpio_settings');
- Hook::unregister('connector_settings_post', 'addon/pumpio/pumpio.php', 'pumpio_settings_post');
- Hook::unregister('cron', 'addon/pumpio/pumpio.php', 'pumpio_cron');
- Hook::unregister('queue_predeliver', 'addon/pumpio/pumpio.php', 'pumpio_queue_hook');
- Hook::unregister('check_item_notification', 'addon/pumpio/pumpio.php', 'pumpio_check_item_notification');
-}
-
function pumpio_module() {}
function pumpio_content(App $a)
{
if (!local_user()) {
- notice(L10n::t('Permission denied.') . EOL);
+ notice(DI::l10n()->t('Permission denied.') . EOL);
return '';
}
@@ -91,8 +74,8 @@ function pumpio_content(App $a)
function pumpio_check_item_notification($a, &$notification_data)
{
- $hostname = PConfig::get($notification_data["uid"], 'pumpio', 'host');
- $username = PConfig::get($notification_data["uid"], "pumpio", "user");
+ $hostname = DI::pConfig()->get($notification_data["uid"], 'pumpio', 'host');
+ $username = DI::pConfig()->get($notification_data["uid"], "pumpio", "user");
$notification_data["profiles"][] = "https://".$hostname."/".$username;
}
@@ -103,20 +86,20 @@ function pumpio_registerclient(App $a, $host)
$params = [];
- $application_name = Config::get('pumpio', 'application_name');
+ $application_name = DI::config()->get('pumpio', 'application_name');
if ($application_name == "") {
- $application_name = $a->getHostName();
+ $application_name = DI::baseUrl()->getHostname();
}
- $adminlist = explode(",", str_replace(" ", "", Config::get('config', 'admin_email')));
+ $adminlist = explode(",", str_replace(" ", "", DI::config()->get('config', 'admin_email')));
$params["type"] = "client_associate";
$params["contacts"] = $adminlist[0];
$params["application_type"] = "native";
$params["application_name"] = $application_name;
- $params["logo_url"] = $a->getBaseURL()."/images/friendica-256.png";
- $params["redirect_uris"] = $a->getBaseURL()."/pumpio/connect";
+ $params["logo_url"] = DI::baseUrl()->get()."/images/friendica-256.png";
+ $params["redirect_uris"] = DI::baseUrl()->get()."/pumpio/connect";
Logger::log("pumpio_registerclient: ".$url." parameters ".print_r($params, true), Logger::DEBUG);
@@ -143,18 +126,18 @@ function pumpio_registerclient(App $a, $host)
function pumpio_connect(App $a)
{
// Define the needed keys
- $consumer_key = PConfig::get(local_user(), 'pumpio', 'consumer_key');
- $consumer_secret = PConfig::get(local_user(), 'pumpio', 'consumer_secret');
- $hostname = PConfig::get(local_user(), 'pumpio', 'host');
+ $consumer_key = DI::pConfig()->get(local_user(), 'pumpio', 'consumer_key');
+ $consumer_secret = DI::pConfig()->get(local_user(), 'pumpio', 'consumer_secret');
+ $hostname = DI::pConfig()->get(local_user(), 'pumpio', 'host');
if ((($consumer_key == "") || ($consumer_secret == "")) && ($hostname != "")) {
Logger::log("pumpio_connect: register client");
$clientdata = pumpio_registerclient($a, $hostname);
- PConfig::set(local_user(), 'pumpio', 'consumer_key', $clientdata->client_id);
- PConfig::set(local_user(), 'pumpio', 'consumer_secret', $clientdata->client_secret);
+ DI::pConfig()->set(local_user(), 'pumpio', 'consumer_key', $clientdata->client_id);
+ DI::pConfig()->set(local_user(), 'pumpio', 'consumer_secret', $clientdata->client_secret);
- $consumer_key = PConfig::get(local_user(), 'pumpio', 'consumer_key');
- $consumer_secret = PConfig::get(local_user(), 'pumpio', 'consumer_secret');
+ $consumer_key = DI::pConfig()->get(local_user(), 'pumpio', 'consumer_key');
+ $consumer_secret = DI::pConfig()->get(local_user(), 'pumpio', 'consumer_secret');
Logger::log("pumpio_connect: ckey: ".$consumer_key." csecrect: ".$consumer_secret, Logger::DEBUG);
}
@@ -162,12 +145,11 @@ function pumpio_connect(App $a)
if (($consumer_key == "") || ($consumer_secret == "")) {
Logger::log("pumpio_connect: ".sprintf("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;
+ return DI::l10n()->t("Unable to register the client at the pump.io server '%s'.", $hostname);
}
// The callback URL is the script that gets called after the user authenticates with pumpio
- $callback_url = $a->getBaseURL()."/pumpio/connect";
+ $callback_url = DI::baseUrl()->get()."/pumpio/connect";
// Let's begin. First we need a Request Token. The request token is required to send the user
// to pumpio's login page.
@@ -191,8 +173,8 @@ function pumpio_connect(App $a)
if (($success = $client->Process())) {
if (strlen($client->access_token)) {
Logger::log("pumpio_connect: otoken: ".$client->access_token." osecrect: ".$client->access_token_secret, Logger::DEBUG);
- PConfig::set(local_user(), "pumpio", "oauth_token", $client->access_token);
- PConfig::set(local_user(), "pumpio", "oauth_token_secret", $client->access_token_secret);
+ DI::pConfig()->set(local_user(), "pumpio", "oauth_token", $client->access_token);
+ DI::pConfig()->set(local_user(), "pumpio", "oauth_token_secret", $client->access_token_secret);
}
}
$success = $client->Finalize($success);
@@ -203,8 +185,8 @@ function pumpio_connect(App $a)
if ($success) {
Logger::log("pumpio_connect: authenticated");
- $o = L10n::t("You are now authenticated to pumpio.");
- $o .= '
'.L10n::t("return to the connector page").'';
+ $o = DI::l10n()->t("You are now authenticated to pumpio.");
+ $o .= '
'.DI::l10n()->t("return to the connector page").'';
} else {
Logger::log("pumpio_connect: could not connect");
$o = 'Could not connect to pumpio. Refresh the page or try again later.';
@@ -213,19 +195,21 @@ function pumpio_connect(App $a)
return $o;
}
-function pumpio_jot_nets(App $a, &$b)
+function pumpio_jot_nets(App $a, array &$jotnets_fields)
{
if (! local_user()) {
return;
}
- $pumpio_post = PConfig::get(local_user(), 'pumpio', 'post');
-
- if (intval($pumpio_post) == 1) {
- $pumpio_defpost = PConfig::get(local_user(), 'pumpio', 'post_by_default');
- $selected = ((intval($pumpio_defpost) == 1) ? ' checked="checked" ' : '');
- $b .= '
'
- . L10n::t('Post to pumpio') . '
';
+ if (DI::pConfig()->get(local_user(), 'pumpio', 'post')) {
+ $jotnets_fields[] = [
+ 'type' => 'checkbox',
+ 'field' => [
+ 'pumpio_enable',
+ DI::l10n()->t('Post to pumpio'),
+ DI::pConfig()->get(local_user(), 'pumpio', 'post_by_default')
+ ]
+ ];
}
}
@@ -237,86 +221,86 @@ function pumpio_settings(App $a, &$s)
/* Add our stylesheet to the page so we can make our settings look nice */
- $a->page['htmlhead'] .= '' . "\r\n";
+ DI::page()['htmlhead'] .= '' . "\r\n";
/* Get the current state of our config variables */
- $import_enabled = PConfig::get(local_user(), 'pumpio', 'import');
+ $import_enabled = DI::pConfig()->get(local_user(), 'pumpio', 'import');
$import_checked = (($import_enabled) ? ' checked="checked" ' : '');
- $enabled = PConfig::get(local_user(), 'pumpio', 'post');
+ $enabled = DI::pConfig()->get(local_user(), 'pumpio', 'post');
$checked = (($enabled) ? ' checked="checked" ' : '');
$css = (($enabled) ? '' : '-disabled');
- $def_enabled = PConfig::get(local_user(), 'pumpio', 'post_by_default');
+ $def_enabled = DI::pConfig()->get(local_user(), 'pumpio', 'post_by_default');
$def_checked = (($def_enabled) ? ' checked="checked" ' : '');
- $public_enabled = PConfig::get(local_user(), 'pumpio', 'public');
+ $public_enabled = DI::pConfig()->get(local_user(), 'pumpio', 'public');
$public_checked = (($public_enabled) ? ' checked="checked" ' : '');
- $mirror_enabled = PConfig::get(local_user(), 'pumpio', 'mirror');
+ $mirror_enabled = DI::pConfig()->get(local_user(), 'pumpio', 'mirror');
$mirror_checked = (($mirror_enabled) ? ' checked="checked" ' : '');
- $servername = PConfig::get(local_user(), "pumpio", "host");
- $username = PConfig::get(local_user(), "pumpio", "user");
+ $servername = DI::pConfig()->get(local_user(), "pumpio", "host");
+ $username = DI::pConfig()->get(local_user(), "pumpio", "user");
/* Add some HTML to the existing form */
$s .= '';
- $s .= '![](images/pumpio.png)
'. L10n::t('Pump.io Import/Export/Mirror').'
';
+ $s .= '![](images/pumpio.png)
'. DI::l10n()->t('Pump.io Import/Export/Mirror').'
';
$s .= '';
$s .= '';
$s .= '
';
- $s .= '![](images/pumpio.png)
'. L10n::t('Pump.io Import/Export/Mirror').'
';
+ $s .= '![](images/pumpio.png)
'. DI::l10n()->t('Pump.io Import/Export/Mirror').'
';
$s .= '';
$s .= '
';
- $s .= '';
+ $s .= '';
$s .= '';
$s .= '
';
$s .= '
';
- $s .= '';
+ $s .= '';
$s .= '';
$s .= '
';
if (($username != '') && ($servername != '')) {
- $oauth_token = PConfig::get(local_user(), "pumpio", "oauth_token");
- $oauth_token_secret = PConfig::get(local_user(), "pumpio", "oauth_token_secret");
+ $oauth_token = DI::pConfig()->get(local_user(), "pumpio", "oauth_token");
+ $oauth_token_secret = DI::pConfig()->get(local_user(), "pumpio", "oauth_token_secret");
$s .= '
';
if (($oauth_token == "") || ($oauth_token_secret == "")) {
$s .= '
';
} else {
$s .= '
';
- $s .= '';
+ $s .= '';
$s .= '';
$s .= '
';
$s .= '
';
- $s .= '';
+ $s .= '';
$s .= '';
$s .= '
';
$s .= '
';
- $s .= '';
+ $s .= '';
$s .= '';
$s .= '
';
$s .= '
';
- $s .= '';
+ $s .= '';
$s .= '';
$s .= '
';
$s .= '
';
- $s .= '';
+ $s .= '';
$s .= '';
$s .= '
';
$s .= '
';
- $s .= '';
+ $s .= '';
$s .= '';
$s .= '
';
}
@@ -326,26 +310,26 @@ function pumpio_settings(App $a, &$s)
/* provide a submit button */
- $s .= '
';
+ $s .= '
';
}
function pumpio_settings_post(App $a, array &$b)
{
if (!empty($_POST['pumpio-submit'])) {
if (!empty($_POST['pumpio_delete'])) {
- PConfig::set(local_user(), 'pumpio', 'consumer_key' , '');
- PConfig::set(local_user(), 'pumpio', 'consumer_secret' , '');
- PConfig::set(local_user(), 'pumpio', 'oauth_token' , '');
- PConfig::set(local_user(), 'pumpio', 'oauth_token_secret', '');
- PConfig::set(local_user(), 'pumpio', 'post' , false);
- PConfig::set(local_user(), 'pumpio', 'import' , false);
- PConfig::set(local_user(), 'pumpio', 'host' , '');
- PConfig::set(local_user(), 'pumpio', 'user' , '');
- PConfig::set(local_user(), 'pumpio', 'public' , false);
- PConfig::set(local_user(), 'pumpio', 'mirror' , false);
- PConfig::set(local_user(), 'pumpio', 'post_by_default' , false);
- PConfig::set(local_user(), 'pumpio', 'lastdate' , 0);
- PConfig::set(local_user(), 'pumpio', 'last_id' , '');
+ DI::pConfig()->set(local_user(), 'pumpio', 'consumer_key' , '');
+ DI::pConfig()->set(local_user(), 'pumpio', 'consumer_secret' , '');
+ DI::pConfig()->set(local_user(), 'pumpio', 'oauth_token' , '');
+ DI::pConfig()->set(local_user(), 'pumpio', 'oauth_token_secret', '');
+ DI::pConfig()->set(local_user(), 'pumpio', 'post' , false);
+ DI::pConfig()->set(local_user(), 'pumpio', 'import' , false);
+ DI::pConfig()->set(local_user(), 'pumpio', 'host' , '');
+ DI::pConfig()->set(local_user(), 'pumpio', 'user' , '');
+ DI::pConfig()->set(local_user(), 'pumpio', 'public' , false);
+ DI::pConfig()->set(local_user(), 'pumpio', 'mirror' , false);
+ DI::pConfig()->set(local_user(), 'pumpio', 'post_by_default' , false);
+ DI::pConfig()->set(local_user(), 'pumpio', 'lastdate' , 0);
+ DI::pConfig()->set(local_user(), 'pumpio', 'last_id' , '');
} else {
// filtering the username if it is filled wrong
$user = $_POST['pumpio_user'];
@@ -362,24 +346,24 @@ function pumpio_settings_post(App $a, array &$b)
$host = trim($host);
$host = str_replace(["https://", "http://"], ["", ""], $host);
- PConfig::set(local_user(), 'pumpio', 'post' , defaults($_POST, 'pumpio', false));
- PConfig::set(local_user(), 'pumpio', 'import' , defaults($_POST, 'pumpio_import', false));
- PConfig::set(local_user(), 'pumpio', 'host' , $host);
- PConfig::set(local_user(), 'pumpio', 'user' , $user);
- PConfig::set(local_user(), 'pumpio', 'public' , defaults($_POST, 'pumpio_public', false));
- PConfig::set(local_user(), 'pumpio', 'mirror' , defaults($_POST, 'pumpio_mirror', false));
- PConfig::set(local_user(), 'pumpio', 'post_by_default', defaults($_POST, 'pumpio_bydefault', false));
+ DI::pConfig()->set(local_user(), 'pumpio', 'post' , $_POST['pumpio'] ?? false);
+ DI::pConfig()->set(local_user(), 'pumpio', 'import' , $_POST['pumpio_import'] ?? false);
+ DI::pConfig()->set(local_user(), 'pumpio', 'host' , $host);
+ DI::pConfig()->set(local_user(), 'pumpio', 'user' , $user);
+ DI::pConfig()->set(local_user(), 'pumpio', 'public' , $_POST['pumpio_public'] ?? false);
+ DI::pConfig()->set(local_user(), 'pumpio', 'mirror' , $_POST['pumpio_mirror'] ?? false);
+ DI::pConfig()->set(local_user(), 'pumpio', 'post_by_default', $_POST['pumpio_bydefault'] ?? false);
if (!empty($_POST['pumpio_mirror'])) {
- PConfig::delete(local_user(), 'pumpio', 'lastdate');
+ DI::pConfig()->delete(local_user(), 'pumpio', 'lastdate');
}
}
}
}
-function pumpio_load_config(App $a)
+function pumpio_load_config(App $a, ConfigFileLoader $loader)
{
- $a->loadConfigFile(__DIR__ . '/config/pumpio.config.php');
+ $a->getConfigCache()->load($loader->loadAddonConfig('pumpio'));
}
function pumpio_hook_fork(App $a, array &$b)
@@ -402,7 +386,7 @@ function pumpio_hook_fork(App $a, array &$b)
return;
}
- if (PConfig::get($post['uid'], 'pumpio', 'import')) {
+ if (DI::pConfig()->get($post['uid'], 'pumpio', 'import')) {
// Don't fork if it isn't a reply to a pump.io post
if (($post['parent'] != $post['id']) && !Item::exists(['id' => $post['parent'], 'network' => Protocol::PUMPIO])) {
Logger::log('No pump.io parent found for item ' . $post['id']);
@@ -424,11 +408,11 @@ function pumpio_post_local(App $a, array &$b)
return;
}
- $pumpio_post = intval(PConfig::get(local_user(), 'pumpio', 'post'));
+ $pumpio_post = intval(DI::pConfig()->get(local_user(), 'pumpio', 'post'));
$pumpio_enable = (($pumpio_post && !empty($_REQUEST['pumpio_enable'])) ? intval($_REQUEST['pumpio_enable']) : 0);
- if ($b['api_source'] && intval(PConfig::get(local_user(), 'pumpio', 'post_by_default'))) {
+ if ($b['api_source'] && intval(DI::pConfig()->get(local_user(), 'pumpio', 'post_by_default'))) {
$pumpio_enable = 1;
}
@@ -445,7 +429,7 @@ function pumpio_post_local(App $a, array &$b)
function pumpio_send(App $a, array &$b)
{
- if (!PConfig::get($b["uid"], 'pumpio', 'import') && ($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited']))) {
+ if (!DI::pConfig()->get($b["uid"], 'pumpio', 'import') && ($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited']))) {
return;
}
@@ -481,7 +465,7 @@ function pumpio_send(App $a, array &$b)
}
}
- if ($b['verb'] == ACTIVITY_LIKE) {
+ if ($b['verb'] == Activity::LIKE) {
if ($b['deleted']) {
pumpio_action($a, $b["uid"], $b["thr-parent"], "unlike");
} else {
@@ -490,15 +474,15 @@ function pumpio_send(App $a, array &$b)
return;
}
- if ($b['verb'] == ACTIVITY_DISLIKE) {
+ if ($b['verb'] == Activity::DISLIKE) {
return;
}
- if (($b['verb'] == ACTIVITY_POST) && ($b['created'] !== $b['edited']) && !$b['deleted']) {
+ if (($b['verb'] == Activity::POST) && ($b['created'] !== $b['edited']) && !$b['deleted']) {
pumpio_action($a, $b["uid"], $b["uri"], "update", $b["body"]);
}
- if (($b['verb'] == ACTIVITY_POST) && $b['deleted']) {
+ if (($b['verb'] == Activity::POST) && $b['deleted']) {
pumpio_action($a, $b["uid"], $b["uri"], "delete");
}
@@ -515,19 +499,19 @@ function pumpio_send(App $a, array &$b)
// Support for native shares
// http:///api//shares?id=
- $oauth_token = PConfig::get($b['uid'], "pumpio", "oauth_token");
- $oauth_token_secret = PConfig::get($b['uid'], "pumpio", "oauth_token_secret");
- $consumer_key = PConfig::get($b['uid'], "pumpio","consumer_key");
- $consumer_secret = PConfig::get($b['uid'], "pumpio","consumer_secret");
+ $oauth_token = DI::pConfig()->get($b['uid'], "pumpio", "oauth_token");
+ $oauth_token_secret = DI::pConfig()->get($b['uid'], "pumpio", "oauth_token_secret");
+ $consumer_key = DI::pConfig()->get($b['uid'], "pumpio","consumer_key");
+ $consumer_secret = DI::pConfig()->get($b['uid'], "pumpio","consumer_secret");
- $host = PConfig::get($b['uid'], "pumpio", "host");
- $user = PConfig::get($b['uid'], "pumpio", "user");
- $public = PConfig::get($b['uid'], "pumpio", "public");
+ $host = DI::pConfig()->get($b['uid'], "pumpio", "host");
+ $user = DI::pConfig()->get($b['uid'], "pumpio", "user");
+ $public = DI::pConfig()->get($b['uid'], "pumpio", "public");
if ($oauth_token && $oauth_token_secret) {
$title = trim($b['title']);
- $content = BBCode::convert($b['body'], false, 4);
+ $content = BBCode::convert($b['body'], false, BBCode::CONNECTORS);
$params = [];
@@ -561,8 +545,8 @@ function pumpio_send(App $a, array &$b)
$inReplyTo = ["id" => $orig_post["uri"],
"objectType" => "note"];
- if (($orig_post["object-type"] != "") && (strstr($orig_post["object-type"], NAMESPACE_ACTIVITY_SCHEMA))) {
- $inReplyTo["objectType"] = str_replace(NAMESPACE_ACTIVITY_SCHEMA, '', $orig_post["object-type"]);
+ if (($orig_post["object-type"] != "") && (strstr($orig_post["object-type"], ActivityNamespace::ACTIVITY_SCHEMA))) {
+ $inReplyTo["objectType"] = str_replace(ActivityNamespace::ACTIVITY_SCHEMA, '', $orig_post["object-type"]);
}
$params["object"] = [
@@ -595,7 +579,7 @@ function pumpio_send(App $a, array &$b)
if ($success) {
if ($user->generator->displayName) {
- PConfig::set($b["uid"], "pumpio", "application_name", $user->generator->displayName);
+ DI::pConfig()->set($b["uid"], "pumpio", "application_name", $user->generator->displayName);
}
$post_id = $user->object->id;
@@ -606,16 +590,7 @@ function pumpio_send(App $a, array &$b)
}
} else {
Logger::log('pumpio_send '.$username.': '.$url.' general error: ' . print_r($user, true));
-
- $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", $b['uid']);
- if (DBA::isResult($r)) {
- $a->contact = $r[0]["id"];
- }
-
- $s = serialize(['url' => $url, 'item' => $b['id'], 'post' => $params]);
-
- Queue::add($a->contact, Protocol::PUMPIO, $s);
- notice(L10n::t('Pump.io post failed. Queued for retry.').EOL);
+ Worker::defer();
}
}
}
@@ -623,16 +598,16 @@ function pumpio_send(App $a, array &$b)
function pumpio_action(App $a, $uid, $uri, $action, $content = "")
{
// Don't do likes and other stuff if you don't import the timeline
- if (!PConfig::get($uid, 'pumpio', 'import')) {
+ if (!DI::pConfig()->get($uid, 'pumpio', 'import')) {
return;
}
- $ckey = PConfig::get($uid, 'pumpio', 'consumer_key');
- $csecret = PConfig::get($uid, 'pumpio', 'consumer_secret');
- $otoken = PConfig::get($uid, 'pumpio', 'oauth_token');
- $osecret = PConfig::get($uid, 'pumpio', 'oauth_token_secret');
- $hostname = PConfig::get($uid, 'pumpio', 'host');
- $username = PConfig::get($uid, "pumpio", "user");
+ $ckey = DI::pConfig()->get($uid, 'pumpio', 'consumer_key');
+ $csecret = DI::pConfig()->get($uid, 'pumpio', 'consumer_secret');
+ $otoken = DI::pConfig()->get($uid, 'pumpio', 'oauth_token');
+ $osecret = DI::pConfig()->get($uid, 'pumpio', 'oauth_token_secret');
+ $hostname = DI::pConfig()->get($uid, 'pumpio', 'host');
+ $username = DI::pConfig()->get($uid, "pumpio", "user");
$orig_post = Item::selectFirst([], ['uri' => $uri, 'uid' => $uid]);
@@ -646,8 +621,8 @@ function pumpio_action(App $a, $uid, $uri, $action, $content = "")
$uri = $orig_post["uri"];
}
- if (($orig_post["object-type"] != "") && (strstr($orig_post["object-type"], NAMESPACE_ACTIVITY_SCHEMA))) {
- $objectType = str_replace(NAMESPACE_ACTIVITY_SCHEMA, '', $orig_post["object-type"]);
+ if (($orig_post["object-type"] != "") && (strstr($orig_post["object-type"], ActivityNamespace::ACTIVITY_SCHEMA))) {
+ $objectType = str_replace(ActivityNamespace::ACTIVITY_SCHEMA, '', $orig_post["object-type"]);
} elseif (strstr($uri, "/api/comment/")) {
$objectType = "comment";
} elseif (strstr($uri, "/api/note/")) {
@@ -682,17 +657,8 @@ function pumpio_action(App $a, $uid, $uri, $action, $content = "")
if ($success) {
Logger::log('pumpio_action '.$username.' '.$action.': success '.$uri);
} else {
- Logger::log('pumpio_action '.$username.' '.$action.': general error: '.$uri.' '.print_r($user, true));
-
- $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", $uid);
- if (DBA::isResult($r)) {
- $a->contact = $r[0]["id"];
- }
-
- $s = serialize(['url' => $url, 'item' => $orig_post["id"], 'post' => $params]);
-
- Queue::add($a->contact, Protocol::PUMPIO, $s);
- notice(L10n::t('Pump.io like failed. Queued for retry.').EOL);
+ Logger::log('pumpio_action '.$username.' '.$action.': general error: '.$uri);
+ Worker::defer();
}
}
@@ -704,9 +670,9 @@ function pumpio_sync(App $a)
return;
}
- $last = Config::get('pumpio', 'last_poll');
+ $last = DI::config()->get('pumpio', 'last_poll');
- $poll_interval = intval(Config::get('pumpio', 'poll_interval', PUMPIO_DEFAULT_POLL_INTERVAL));
+ $poll_interval = intval(DI::config()->get('pumpio', 'poll_interval', PUMPIO_DEFAULT_POLL_INTERVAL));
if ($last) {
$next = $last + ($poll_interval * 60);
@@ -725,7 +691,7 @@ function pumpio_sync(App $a)
}
}
- $abandon_days = intval(Config::get('system', 'account_abandon_days'));
+ $abandon_days = intval(DI::config()->get('system', 'account_abandon_days'));
if ($abandon_days < 1) {
$abandon_days = 0;
}
@@ -747,7 +713,7 @@ function pumpio_sync(App $a)
pumpio_fetchinbox($a, $rr['uid']);
// check for new contacts once a day
- $last_contact_check = PConfig::get($rr['uid'], 'pumpio', 'contact_check');
+ $last_contact_check = DI::pConfig()->get($rr['uid'], 'pumpio', 'contact_check');
if ($last_contact_check) {
$next_contact_check = $last_contact_check + 86400;
} else {
@@ -756,14 +722,14 @@ function pumpio_sync(App $a)
if ($next_contact_check <= time()) {
pumpio_getallusers($a, $rr["uid"]);
- PConfig::set($rr['uid'], 'pumpio', 'contact_check', time());
+ DI::pConfig()->set($rr['uid'], 'pumpio', 'contact_check', time());
}
}
}
Logger::log('pumpio: cron_end');
- Config::set('pumpio', 'last_poll', time());
+ DI::config()->set('pumpio', 'last_poll', time());
}
function pumpio_cron(App $a, $b)
@@ -773,23 +739,23 @@ function pumpio_cron(App $a, $b)
function pumpio_fetchtimeline(App $a, $uid)
{
- $ckey = PConfig::get($uid, 'pumpio', 'consumer_key');
- $csecret = PConfig::get($uid, 'pumpio', 'consumer_secret');
- $otoken = PConfig::get($uid, 'pumpio', 'oauth_token');
- $osecret = PConfig::get($uid, 'pumpio', 'oauth_token_secret');
- $lastdate = PConfig::get($uid, 'pumpio', 'lastdate');
- $hostname = PConfig::get($uid, 'pumpio', 'host');
- $username = PConfig::get($uid, "pumpio", "user");
+ $ckey = DI::pConfig()->get($uid, 'pumpio', 'consumer_key');
+ $csecret = DI::pConfig()->get($uid, 'pumpio', 'consumer_secret');
+ $otoken = DI::pConfig()->get($uid, 'pumpio', 'oauth_token');
+ $osecret = DI::pConfig()->get($uid, 'pumpio', 'oauth_token_secret');
+ $lastdate = DI::pConfig()->get($uid, 'pumpio', 'lastdate');
+ $hostname = DI::pConfig()->get($uid, 'pumpio', 'host');
+ $username = DI::pConfig()->get($uid, "pumpio", "user");
// 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 = DI::pConfig()->get($uid, 'pumpio', 'application_name');
if ($application_name == "") {
- $application_name = Config::get('pumpio', 'application_name');
+ $application_name = DI::config()->get('pumpio', 'application_name');
}
if ($application_name == "") {
- $application_name = $a->getHostName();
+ $application_name = DI::baseUrl()->getHostname();
}
$first_time = ($lastdate == "");
@@ -898,7 +864,7 @@ function pumpio_fetchtimeline(App $a, $uid)
}
if ($lastdate != 0) {
- PConfig::set($uid, 'pumpio', 'lastdate', $lastdate);
+ DI::pConfig()->set($uid, 'pumpio', 'lastdate', $lastdate);
}
}
@@ -933,7 +899,7 @@ function pumpio_dounlike(App $a, $uid, $self, $post, $own_id)
}
}
- Item::delete(['verb' => ACTIVITY_LIKE, 'uid' => $uid, 'contact-id' => $contactid, 'thr-parent' => $orig_post['uri']]);
+ Item::markForDeletion(['verb' => Activity::LIKE, 'uid' => $uid, 'contact-id' => $contactid, 'thr-parent' => $orig_post['uri']]);
if (DBA::isResult($r)) {
Logger::log("pumpio_dounlike: unliked existing like. User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']);
@@ -944,8 +910,6 @@ function pumpio_dounlike(App $a, $uid, $self, $post, $own_id)
function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion = true)
{
- require_once('include/items.php');
-
if (empty($post->object->id)) {
Logger::log('Got empty like: '.print_r($post, true), Logger::DEBUG);
return;
@@ -988,7 +952,7 @@ function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion =
}
}
- $condition = ['verb' => ACTIVITY_LIKE, 'uid' => $uid, 'contact-id' => $contactid, 'thr-parent' => $orig_post['uri']];
+ $condition = ['verb' => Activity::LIKE, 'uid' => $uid, 'contact-id' => $contactid, 'thr-parent' => $orig_post['uri']];
if (Item::exists($condition)) {
Logger::log("pumpio_dolike: found existing like. User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']);
return;
@@ -996,7 +960,7 @@ function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion =
$likedata = [];
$likedata['parent'] = $orig_post['id'];
- $likedata['verb'] = ACTIVITY_LIKE;
+ $likedata['verb'] = Activity::LIKE;
$likedata['gravity'] = GRAVITY_ACTIVITY;
$likedata['uid'] = $uid;
$likedata['wall'] = 0;
@@ -1013,13 +977,13 @@ function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion =
$author = '[url=' . $likedata['author-link'] . ']' . $likedata['author-name'] . '[/url]';
$objauthor = '[url=' . $orig_post['author-link'] . ']' . $orig_post['author-name'] . '[/url]';
- $post_type = L10n::t('status');
+ $post_type = DI::l10n()->t('status');
$plink = '[url=' . $orig_post['plink'] . ']' . $post_type . '[/url]';
- $likedata['object-type'] = ACTIVITY_OBJ_NOTE;
+ $likedata['object-type'] = Activity\ObjectType::NOTE;
- $likedata['body'] = L10n::t('%1$s likes %2$s\'s %3$s', $author, $objauthor, $plink);
+ $likedata['body'] = DI::l10n()->t('%1$s likes %2$s\'s %3$s', $author, $objauthor, $plink);
- $likedata['object'] = '