use Friendica\App;
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\Hook;
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;
require 'addon/pumpio/oauth/http.php';
require 'addon/pumpio/oauth/oauth_client.php';
-require_once 'include/enotify.php';
require_once "mod/share.php";
define('PUMPIO_DEFAULT_POLL_INTERVAL', 5); // given in minutes
function pumpio_install()
{
- Addon::registerHook('load_config', 'addon/pumpio/pumpio.php', 'pumpio_load_config');
- Addon::registerHook('post_local', 'addon/pumpio/pumpio.php', 'pumpio_post_local');
- Addon::registerHook('notifier_normal', 'addon/pumpio/pumpio.php', 'pumpio_send');
- Addon::registerHook('jot_networks', 'addon/pumpio/pumpio.php', 'pumpio_jot_nets');
- Addon::registerHook('connector_settings', 'addon/pumpio/pumpio.php', 'pumpio_settings');
- Addon::registerHook('connector_settings_post', 'addon/pumpio/pumpio.php', 'pumpio_settings_post');
- Addon::registerHook('cron', 'addon/pumpio/pumpio.php', 'pumpio_cron');
- Addon::registerHook('queue_predeliver', 'addon/pumpio/pumpio.php', 'pumpio_queue_hook');
- Addon::registerHook('check_item_notification', 'addon/pumpio/pumpio.php', 'pumpio_check_item_notification');
-}
-
-function pumpio_uninstall()
-{
- Addon::unregisterHook('load_config', 'addon/pumpio/pumpio.php', 'pumpio_load_config');
- Addon::unregisterHook('post_local', 'addon/pumpio/pumpio.php', 'pumpio_post_local');
- Addon::unregisterHook('notifier_normal', 'addon/pumpio/pumpio.php', 'pumpio_send');
- Addon::unregisterHook('jot_networks', 'addon/pumpio/pumpio.php', 'pumpio_jot_nets');
- Addon::unregisterHook('connector_settings', 'addon/pumpio/pumpio.php', 'pumpio_settings');
- Addon::unregisterHook('connector_settings_post', 'addon/pumpio/pumpio.php', 'pumpio_settings_post');
- Addon::unregisterHook('cron', 'addon/pumpio/pumpio.php', 'pumpio_cron');
- Addon::unregisterHook('queue_predeliver', 'addon/pumpio/pumpio.php', 'pumpio_queue_hook');
- Addon::unregisterHook('check_item_notification', 'addon/pumpio/pumpio.php', 'pumpio_check_item_notification');
+ Hook::register('load_config', 'addon/pumpio/pumpio.php', 'pumpio_load_config');
+ Hook::register('hook_fork', 'addon/pumpio/pumpio.php', 'hook_fork');
+ Hook::register('post_local', 'addon/pumpio/pumpio.php', 'pumpio_post_local');
+ Hook::register('notifier_normal', 'addon/pumpio/pumpio.php', 'pumpio_send');
+ Hook::register('jot_networks', 'addon/pumpio/pumpio.php', 'pumpio_jot_nets');
+ 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('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 '';
}
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;
}
$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);
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);
}
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.
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);
if ($success) {
Logger::log("pumpio_connect: authenticated");
- $o = L10n::t("You are now authenticated to pumpio.");
- $o .= '<br /><a href="'.$a->getBaseURL().'/settings/connectors">'.L10n::t("return to the connector page").'</a>';
+ $o = DI::l10n()->t("You are now authenticated to pumpio.");
+ $o .= '<br /><a href="'.DI::baseUrl()->get().'/settings/connectors">'.DI::l10n()->t("return to the connector page").'</a>';
} else {
Logger::log("pumpio_connect: could not connect");
$o = 'Could not connect to pumpio. Refresh the page or try again later.';
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 .= '<div class="profile-jot-net"><input type="checkbox" name="pumpio_enable"' . $selected . ' value="1" /> '
- . L10n::t('Post to pumpio') . '</div>';
+ 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')
+ ]
+ ];
}
}
/* Add our stylesheet to the page so we can make our settings look nice */
- $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->getBaseURL() . '/addon/pumpio/pumpio.css' . '" media="all" />' . "\r\n";
+ DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . DI::baseUrl()->get() . '/addon/pumpio/pumpio.css' . '" media="all" />' . "\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 .= '<span id="settings_pumpio_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_pumpio_expanded\'); openClose(\'settings_pumpio_inflated\');">';
- $s .= '<img class="connector'.$css.'" src="images/pumpio.png" /><h3 class="connector">'. L10n::t('Pump.io Import/Export/Mirror').'</h3>';
+ $s .= '<img class="connector'.$css.'" src="images/pumpio.png" /><h3 class="connector">'. DI::l10n()->t('Pump.io Import/Export/Mirror').'</h3>';
$s .= '</span>';
$s .= '<div id="settings_pumpio_expanded" class="settings-block" style="display: none;">';
$s .= '<span class="fakelink" onclick="openClose(\'settings_pumpio_expanded\'); openClose(\'settings_pumpio_inflated\');">';
- $s .= '<img class="connector'.$css.'" src="images/pumpio.png" /><h3 class="connector">'. L10n::t('Pump.io Import/Export/Mirror').'</h3>';
+ $s .= '<img class="connector'.$css.'" src="images/pumpio.png" /><h3 class="connector">'. DI::l10n()->t('Pump.io Import/Export/Mirror').'</h3>';
$s .= '</span>';
$s .= '<div id="pumpio-username-wrapper">';
- $s .= '<label id="pumpio-username-label" for="pumpio-username">'.L10n::t('pump.io username (without the servername)').'</label>';
+ $s .= '<label id="pumpio-username-label" for="pumpio-username">'.DI::l10n()->t('pump.io username (without the servername)').'</label>';
$s .= '<input id="pumpio-username" type="text" name="pumpio_user" value="'.$username.'" />';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="pumpio-servername-wrapper">';
- $s .= '<label id="pumpio-servername-label" for="pumpio-servername">'.L10n::t('pump.io servername (without "http://" or "https://" )').'</label>';
+ $s .= '<label id="pumpio-servername-label" for="pumpio-servername">'.DI::l10n()->t('pump.io servername (without "http://" or "https://" )').'</label>';
$s .= '<input id="pumpio-servername" type="text" name="pumpio_host" value="'.$servername.'" />';
$s .= '</div><div class="clear"></div>';
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 .= '<div id="pumpio-password-wrapper">';
if (($oauth_token == "") || ($oauth_token_secret == "")) {
$s .= '<div id="pumpio-authenticate-wrapper">';
- $s .= '<a href="'.$a->getBaseURL().'/pumpio/connect">'.L10n::t("Authenticate your pump.io connection").'</a>';
+ $s .= '<a href="'.DI::baseUrl()->get().'/pumpio/connect">'.DI::l10n()->t("Authenticate your pump.io connection").'</a>';
$s .= '</div><div class="clear"></div>';
} else {
$s .= '<div id="pumpio-import-wrapper">';
- $s .= '<label id="pumpio-import-label" for="pumpio-import">' . L10n::t('Import the remote timeline') . '</label>';
+ $s .= '<label id="pumpio-import-label" for="pumpio-import">' . DI::l10n()->t('Import the remote timeline') . '</label>';
$s .= '<input id="pumpio-import" type="checkbox" name="pumpio_import" value="1" ' . $import_checked . '/>';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="pumpio-enable-wrapper">';
- $s .= '<label id="pumpio-enable-label" for="pumpio-checkbox">' . L10n::t('Enable pump.io Post Addon') . '</label>';
+ $s .= '<label id="pumpio-enable-label" for="pumpio-checkbox">' . DI::l10n()->t('Enable pump.io Post Addon') . '</label>';
$s .= '<input id="pumpio-checkbox" type="checkbox" name="pumpio" value="1" ' . $checked . '/>';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="pumpio-bydefault-wrapper">';
- $s .= '<label id="pumpio-bydefault-label" for="pumpio-bydefault">' . L10n::t('Post to pump.io by default') . '</label>';
+ $s .= '<label id="pumpio-bydefault-label" for="pumpio-bydefault">' . DI::l10n()->t('Post to pump.io by default') . '</label>';
$s .= '<input id="pumpio-bydefault" type="checkbox" name="pumpio_bydefault" value="1" ' . $def_checked . '/>';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="pumpio-public-wrapper">';
- $s .= '<label id="pumpio-public-label" for="pumpio-public">' . L10n::t('Should posts be public?') . '</label>';
+ $s .= '<label id="pumpio-public-label" for="pumpio-public">' . DI::l10n()->t('Should posts be public?') . '</label>';
$s .= '<input id="pumpio-public" type="checkbox" name="pumpio_public" value="1" ' . $public_checked . '/>';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="pumpio-mirror-wrapper">';
- $s .= '<label id="pumpio-mirror-label" for="pumpio-mirror">' . L10n::t('Mirror all public posts') . '</label>';
+ $s .= '<label id="pumpio-mirror-label" for="pumpio-mirror">' . DI::l10n()->t('Mirror all public posts') . '</label>';
$s .= '<input id="pumpio-mirror" type="checkbox" name="pumpio_mirror" value="1" ' . $mirror_checked . '/>';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="pumpio-delete-wrapper">';
- $s .= '<label id="pumpio-delete-label" for="pumpio-delete">' . L10n::t('Check to delete this preset') . '</label>';
+ $s .= '<label id="pumpio-delete-label" for="pumpio-delete">' . DI::l10n()->t('Check to delete this preset') . '</label>';
$s .= '<input id="pumpio-delete" type="checkbox" name="pumpio_delete" value="1" />';
$s .= '</div><div class="clear"></div>';
}
/* provide a submit button */
- $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="pumpio-submit" name="pumpio-submit" class="settings-submit" value="' . L10n::t('Save Settings') . '" /></div></div>';
+ $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="pumpio-submit" name="pumpio-submit" class="settings-submit" value="' . DI::l10n()->t('Save Settings') . '" /></div></div>';
}
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'];
$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.ini.php');
+ $a->getConfigCache()->load($loader->loadAddonConfig('pumpio'));
+}
+
+function pumpio_hook_fork(App $a, array &$b)
+{
+ if ($b['name'] != 'notifier_normal') {
+ return;
+ }
+
+ $post = $b['data'];
+
+ // Deleting and editing is not supported by the addon (deleting could, but isn't by now)
+ if ($post['deleted'] || ($post['created'] !== $post['edited'])) {
+ $b['execute'] = false;
+ return;
+ }
+
+ // if post comes from pump.io don't send it back
+ if ($post['app'] == "pump.io") {
+ $b['execute'] = false;
+ return;
+ }
+
+ 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']);
+ $b['execute'] = false;
+ return;
+ }
+ } else {
+ // Comments are never exported when we don't import the pumpio timeline
+ if (!strstr($post['postopts'], 'pumpio') || ($post['parent'] != $post['id']) || $post['private']) {
+ $b['execute'] = false;
+ return;
+ }
+ }
}
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;
}
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;
}
}
}
- if ($b['verb'] == ACTIVITY_LIKE) {
+ if ($b['verb'] == Activity::LIKE) {
if ($b['deleted']) {
pumpio_action($a, $b["uid"], $b["thr-parent"], "unlike");
} else {
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");
}
// Support for native shares
// http://<hostname>/api/<type>/shares?id=<the-object-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 = [];
$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"] = [
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;
}
} 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();
}
}
}
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]);
$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/")) {
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();
}
}
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);
}
}
- $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;
}
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 {
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)
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 == "");
}
if ($lastdate != 0) {
- PConfig::set($uid, 'pumpio', 'lastdate', $lastdate);
+ DI::pConfig()->set($uid, 'pumpio', 'lastdate', $lastdate);
}
}
$contactid = 0;
- if (link_compare($post->actor->url, $own_id)) {
+ if (Strings::compareLink($post->actor->url, $own_id)) {
$contactid = $self[0]['id'];
} else {
$r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1",
- DBA::escape(normalise_link($post->actor->url)),
+ DBA::escape(Strings::normaliseLink($post->actor->url)),
intval($uid)
);
}
}
- 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']);
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;
$contactid = 0;
- if (link_compare($post->actor->url, $own_id)) {
+ if (Strings::compareLink($post->actor->url, $own_id)) {
$contactid = $self[0]['id'];
$post->actor->displayName = $self[0]['name'];
$post->actor->url = $self[0]['url'];
$post->actor->image->url = $self[0]['photo'];
} else {
$r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1",
- DBA::escape(normalise_link($post->actor->url)),
+ DBA::escape(Strings::normaliseLink($post->actor->url)),
intval($uid)
);
}
}
- $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;
$likedata = [];
$likedata['parent'] = $orig_post['id'];
- $likedata['verb'] = ACTIVITY_LIKE;
+ $likedata['verb'] = Activity::LIKE;
$likedata['gravity'] = GRAVITY_ACTIVITY;
$likedata['uid'] = $uid;
$likedata['wall'] = 0;
$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'] = '<object><type>' . ACTIVITY_OBJ_NOTE . '</type><local>1</local>' .
+ $likedata['object'] = '<object><type>' . Activity\ObjectType::NOTE . '</type><local>1</local>' .
'<id>' . $orig_post['uri'] . '</id><link>' . XML::escape('<link rel="alternate" type="text/html" href="' . XML::escape($orig_post['plink']) . '" />') . '</link><title>' . $orig_post['title'] . '</title><content>' . $orig_post['body'] . '</content></object>';
$ret = Item::insert($likedata);
function pumpio_get_contact($uid, $contact, $no_insert = false)
{
- $gcontact = ["url" => $contact->url, "network" => Protocol::PUMPIO, "generation" => 2,
- "name" => $contact->displayName, "hide" => true,
- "nick" => $contact->preferredUsername,
- "addr" => str_replace("acct:", "", $contact->id)];
-
- if (!empty($contact->location->displayName)) {
- $gcontact["location"] = $contact->location->displayName;
- }
-
- if (!empty($contact->summary)) {
- $gcontact["about"] = $contact->summary;
- }
-
- if (!empty($contact->image->url)) {
- $gcontact["photo"] = $contact->image->url;
- }
-
- GContact::update($gcontact);
$cid = Contact::getIdForURL($contact->url, $uid);
if ($no_insert) {
}
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' LIMIT 1",
- intval($uid), DBA::escape(normalise_link($contact->url)));
+ intval($uid), DBA::escape(Strings::normaliseLink($contact->url)));
if (!DBA::isResult($r)) {
// create contact record
intval($uid),
DBA::escape(DateTimeFormat::utcNow()),
DBA::escape($contact->url),
- DBA::escape(normalise_link($contact->url)),
+ DBA::escape(Strings::normaliseLink($contact->url)),
DBA::escape(str_replace("acct:", "", $contact->id)),
DBA::escape(''),
DBA::escape($contact->id), // What is it for?
);
$r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1",
- DBA::escape(normalise_link($contact->url)),
+ DBA::escape(Strings::normaliseLink($contact->url)),
intval($uid)
);
}
if (!empty($contact->image->url)) {
- Contact::updateAvatar($contact->image->url, $uid, $contact_id);
+ Contact::updateAvatar($contact_id, $contact->image->url);
}
return $contact_id;
// Two queries for speed issues
$condition = ['uri' => $post->object->id, 'uid' => $uid];
if (Item::exists($condition)) {
- Item::delete($condition);
+ Item::markForDeletion($condition);
return true;
}
$condition = ['extid' => $post->object->id, 'uid' => $uid];
if (Item::exists($condition)) {
- Item::delete($condition);
+ Item::markForDeletion($condition);
return true;
}
return false;
function pumpio_dopost(App $a, $client, $uid, $self, $post, $own_id, $threadcompletion = true)
{
- require_once('include/items.php');
-
if (($post->verb == "like") || ($post->verb == "favorite")) {
return pumpio_dolike($a, $uid, $self, $post, $own_id);
}
$postarray['uid'] = $uid;
$postarray['wall'] = 0;
$postarray['uri'] = $post->object->id;
- $postarray['object-type'] = NAMESPACE_ACTIVITY_SCHEMA.strtolower($post->object->objectType);
+ $postarray['object-type'] = ActivityNamespace::ACTIVITY_SCHEMA . strtolower($post->object->objectType);
if ($post->object->objectType != "comment") {
$contact_id = pumpio_get_contact($uid, $post->actor);
} else {
$contact_id = pumpio_get_contact($uid, $post->actor, true);
- if (link_compare($post->actor->url, $own_id)) {
+ if (Strings::compareLink($post->actor->url, $own_id)) {
$contact_id = $self[0]['id'];
$post->actor->displayName = $self[0]['name'];
$post->actor->url = $self[0]['url'];
} elseif ($contact_id == 0) {
// Take an existing contact, the contact of the note or - as a fallback - the id of the user
$r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1",
- DBA::escape(normalise_link($post->actor->url)),
+ DBA::escape(Strings::normaliseLink($post->actor->url)),
intval($uid)
);
$contact_id = $r[0]['id'];
} else {
$r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1",
- DBA::escape(normalise_link($post->actor->url)),
+ DBA::escape(Strings::normaliseLink($post->actor->url)),
intval($uid)
);
}
$postarray['contact-id'] = $contact_id;
- $postarray['verb'] = ACTIVITY_POST;
+ $postarray['verb'] = Activity::POST;
$postarray['owner-name'] = $post->actor->displayName;
$postarray['owner-link'] = $post->actor->url;
$postarray['author-name'] = $postarray['owner-name'];
$created = '';
}
- $postarray['body'] = share_header($share_author, $post->object->author->url,
- $post->object->author->image->url, "",
- $created, $post->links->self->href).
+ $postarray['body'] = Friendica\Content\Text\BBCode::getShareOpeningTag($share_author, $post->object->author->url,
+ $post->object->author->image->url, $post->links->self->href, $created) .
$postarray['body']."[/share]";
}
function pumpio_fetchinbox(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");
$own_id = "https://".$hostname."/".$username;
$client->access_token = $otoken;
$client->access_token_secret = $osecret;
- $last_id = PConfig::get($uid, 'pumpio', 'last_id');
+ $last_id = DI::pConfig()->get($uid, 'pumpio', 'last_id');
$url = 'https://'.$hostname.'/api/user/'.$username.'/inbox';
return;
}
- if ($user->items) {
+ if (!empty($user->items)) {
$posts = array_reverse($user->items);
if (count($posts)) {
pumpio_fetchallcomments($a, $uid, $item["uri"]);
}
- PConfig::set($uid, 'pumpio', 'last_id', $last_id);
+ DI::pConfig()->set($uid, 'pumpio', 'last_id', $last_id);
}
function pumpio_getallusers(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');
- $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");
$client = new oauth_client_class;
$client->oauth_version = '1.0a';
}
}
-function pumpio_queue_hook(App $a, array &$b)
-{
- $qi = q("SELECT * FROM `queue` WHERE `network` = '%s'",
- DBA::escape(Protocol::PUMPIO)
- );
-
- if (!DBA::isResult($qi)) {
- return;
- }
-
- foreach ($qi as $x) {
- if ($x['network'] !== Protocol::PUMPIO) {
- continue;
- }
-
- Logger::log('pumpio_queue: run');
-
- $r = q("SELECT `user`.* FROM `user` LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid`
- WHERE `contact`.`self` = 1 AND `contact`.`id` = %d LIMIT 1",
- intval($x['cid'])
- );
- if (!DBA::isResult($r)) {
- continue;
- }
-
- $userdata = $r[0];
-
- //Logger::log('pumpio_queue: fetching userdata '.print_r($userdata, true));
-
- $oauth_token = PConfig::get($userdata['uid'], "pumpio", "oauth_token");
- $oauth_token_secret = PConfig::get($userdata['uid'], "pumpio", "oauth_token_secret");
- $consumer_key = PConfig::get($userdata['uid'], "pumpio", "consumer_key");
- $consumer_secret = PConfig::get($userdata['uid'], "pumpio", "consumer_secret");
-
- $host = PConfig::get($userdata['uid'], "pumpio", "host");
- $user = PConfig::get($userdata['uid'], "pumpio", "user");
-
- $success = false;
-
- if ($oauth_token && $oauth_token_secret &&
- $consumer_key && $consumer_secret) {
- $username = $user.'@'.$host;
-
- Logger::log('pumpio_queue: able to post for user '.$username);
-
- $z = unserialize($x['content']);
-
- $client = new oauth_client_class;
- $client->oauth_version = '1.0a';
- $client->url_parameters = false;
- $client->authorization_header = true;
- $client->access_token = $oauth_token;
- $client->access_token_secret = $oauth_token_secret;
- $client->client_id = $consumer_key;
- $client->client_secret = $consumer_secret;
-
- if (pumpio_reachable($z['url'])) {
- $success = $client->CallAPI($z['url'], 'POST', $z['post'], ['FailOnAccessError'=>true, 'RequestContentType'=>'application/json'], $user);
- } else {
- $success = false;
- }
-
- if ($success) {
- $post_id = $user->object->id;
- Logger::log('pumpio_queue: send '.$username.': success '.$post_id);
- if ($post_id && $iscomment) {
- Logger::log('pumpio_send '.$username.': Update extid '.$post_id." for post id ".$z['item']);
- Item::update(['extid' => $post_id], ['id' => $z['item']]);
- }
- Queue::removeItem($x['id']);
- } else {
- Logger::log('pumpio_queue: send '.$username.': '.$z['url'].' general error: ' . print_r($user, true));
- }
- } else {
- Logger::log("pumpio_queue: Error getting tokens for user ".$userdata['uid']);
- }
-
- if (!$success) {
- Logger::log('pumpio_queue: delayed');
- Queue::updateTime($x['id']);
- }
- }
-}
-
function pumpio_getreceiver(App $a, array $b)
{
$receiver = [];
return $receiver;
}
- $public = PConfig::get($b['uid'], "pumpio", "public");
+ $public = DI::pConfig()->get($b['uid'], "pumpio", "public");
if ($public) {
$receiver["to"][] = [
function pumpio_fetchallcomments(App $a, $uid, $id)
{
- $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");
Logger::log("pumpio_fetchallcomments: completing comment for user ".$uid." post id ".$id);
// Fetching the original post
$condition = ["`uri` = ? AND `uid` = ? AND `extid` != ''", $id, $uid];
- $item = Item::selectFirst(['extid'], $condition);
- if (!DBA::isResult($item)) {
+ $original = Item::selectFirst(['extid'], $condition);
+ if (!DBA::isResult($original)) {
return false;
}
- $url = $item["extid"];
+ $url = $original["extid"];
$client = new oauth_client_class;
$client->oauth_version = '1.0a';
function pumpio_reachable($url)
{
- return Network::curl($url, false, $redirects, ['timeout'=>10])->isSuccess();
+ return DI::httpRequest()->get($url, ['timeout' => 10])->isSuccess();
}
/*