X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=statusnet%2Fstatusnet.php;h=1a3ba1f9785049d1837d5d9ebde8bea8640a714e;hb=9cf43bb85bb2060e54b1b38fbcfe2864071e4deb;hp=ed7b87d83dd726ae3816e7191469996fd9cc649c;hpb=a5c3ef99ef2e535da6323d4fa7c7e72c31424749;p=friendica-addons.git diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index ed7b87d8..1a3ba1f9 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -36,28 +36,27 @@ define('STATUSNET_DEFAULT_POLL_INTERVAL', 5); // given in minutes require_once __DIR__ . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR . 'statusnetoauth.php'; + use CodebirdSN\CodebirdSN; use Friendica\App; use Friendica\Content\OEmbed; +use Friendica\Content\PageInfo; use Friendica\Content\Text\HTML; use Friendica\Content\Text\Plaintext; -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\Renderer; -use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Group; use Friendica\Model\Item; -use Friendica\Model\ItemContent; use Friendica\Model\Photo; +use Friendica\Model\Post; use Friendica\Model\User; +use Friendica\Protocol\Activity; use Friendica\Util\DateTimeFormat; -use Friendica\Util\Network; use Friendica\Util\Strings; function statusnet_install() @@ -75,28 +74,10 @@ function statusnet_install() Logger::log("installed GNU Social"); } -function statusnet_uninstall() -{ - Hook::unregister('connector_settings', 'addon/statusnet/statusnet.php', 'statusnet_settings'); - Hook::unregister('connector_settings_post', 'addon/statusnet/statusnet.php', 'statusnet_settings_post'); - Hook::unregister('notifier_normal', 'addon/statusnet/statusnet.php', 'statusnet_post_hook'); - Hook::unregister('hook_fork', 'addon/statusnet/statusnet.php', 'statusnet_hook_fork'); - Hook::unregister('post_local', 'addon/statusnet/statusnet.php', 'statusnet_post_local'); - Hook::unregister('jot_networks', 'addon/statusnet/statusnet.php', 'statusnet_jot_nets'); - Hook::unregister('cron', 'addon/statusnet/statusnet.php', 'statusnet_cron'); - Hook::unregister('prepare_body', 'addon/statusnet/statusnet.php', 'statusnet_prepare_body'); - Hook::unregister('check_item_notification', 'addon/statusnet/statusnet.php', 'statusnet_check_item_notification'); - - // old setting - remove only - Hook::unregister('post_local_end', 'addon/statusnet/statusnet.php', 'statusnet_post_hook'); - Hook::unregister('addon_settings', 'addon/statusnet/statusnet.php', 'statusnet_settings'); - Hook::unregister('addon_settings_post', 'addon/statusnet/statusnet.php', 'statusnet_settings_post'); -} - function statusnet_check_item_notification(App $a, &$notification_data) { - if (PConfig::get($notification_data["uid"], 'statusnet', 'post')) { - $notification_data["profiles"][] = PConfig::get($notification_data["uid"], 'statusnet', 'own_url'); + if (DI::pConfig()->get($notification_data["uid"], 'statusnet', 'post')) { + $notification_data["profiles"][] = DI::pConfig()->get($notification_data["uid"], 'statusnet', 'own_url'); } } @@ -106,13 +87,13 @@ function statusnet_jot_nets(App $a, array &$jotnets_fields) return; } - if (PConfig::get(local_user(), 'statusnet', 'post')) { + if (DI::pConfig()->get(local_user(), 'statusnet', 'post')) { $jotnets_fields[] = [ 'type' => 'checkbox', 'field' => [ 'statusnet_enable', - L10n::t('Post to GNU Social'), - PConfig::get(local_user(), 'statusnet', 'post_by_default') + DI::l10n()->t('Post to GNU Social'), + DI::pConfig()->get(local_user(), 'statusnet', 'post_by_default') ] ]; } @@ -132,18 +113,18 @@ function statusnet_settings_post(App $a, $post) /* * * * if the GNU Social-disconnect checkbox is set, clear the GNU Social configuration */ - PConfig::delete(local_user(), 'statusnet', 'consumerkey'); - PConfig::delete(local_user(), 'statusnet', 'consumersecret'); - PConfig::delete(local_user(), 'statusnet', 'post'); - PConfig::delete(local_user(), 'statusnet', 'post_by_default'); - PConfig::delete(local_user(), 'statusnet', 'oauthtoken'); - PConfig::delete(local_user(), 'statusnet', 'oauthsecret'); - PConfig::delete(local_user(), 'statusnet', 'baseapi'); - PConfig::delete(local_user(), 'statusnet', 'lastid'); - PConfig::delete(local_user(), 'statusnet', 'mirror_posts'); - PConfig::delete(local_user(), 'statusnet', 'import'); - PConfig::delete(local_user(), 'statusnet', 'create_user'); - PConfig::delete(local_user(), 'statusnet', 'own_url'); + DI::pConfig()->delete(local_user(), 'statusnet', 'consumerkey'); + DI::pConfig()->delete(local_user(), 'statusnet', 'consumersecret'); + DI::pConfig()->delete(local_user(), 'statusnet', 'post'); + DI::pConfig()->delete(local_user(), 'statusnet', 'post_by_default'); + DI::pConfig()->delete(local_user(), 'statusnet', 'oauthtoken'); + DI::pConfig()->delete(local_user(), 'statusnet', 'oauthsecret'); + DI::pConfig()->delete(local_user(), 'statusnet', 'baseapi'); + DI::pConfig()->delete(local_user(), 'statusnet', 'lastid'); + DI::pConfig()->delete(local_user(), 'statusnet', 'mirror_posts'); + DI::pConfig()->delete(local_user(), 'statusnet', 'import'); + DI::pConfig()->delete(local_user(), 'statusnet', 'create_user'); + DI::pConfig()->delete(local_user(), 'statusnet', 'own_url'); } else { if (isset($_POST['statusnet-preconf-apiurl'])) { /* * * @@ -151,81 +132,79 @@ function statusnet_settings_post(App $a, $post) * use them. All the data are available in the global config. * Check the API Url never the less and blame the admin if it's not working ^^ */ - $globalsn = Config::get('statusnet', 'sites'); + $globalsn = DI::config()->get('statusnet', 'sites'); foreach ($globalsn as $asn) { if ($asn['apiurl'] == $_POST['statusnet-preconf-apiurl']) { $apibase = $asn['apiurl']; - $c = Network::fetchUrl($apibase . 'statusnet/version.xml'); + $c = DI::httpRequest()->fetch($apibase . 'statusnet/version.xml'); if (strlen($c) > 0) { - PConfig::set(local_user(), 'statusnet', 'consumerkey', $asn['consumerkey']); - PConfig::set(local_user(), 'statusnet', 'consumersecret', $asn['consumersecret']); - PConfig::set(local_user(), 'statusnet', 'baseapi', $asn['apiurl']); - //PConfig::set(local_user(), 'statusnet', 'application_name', $asn['applicationname'] ); + DI::pConfig()->set(local_user(), 'statusnet', 'consumerkey', $asn['consumerkey']); + DI::pConfig()->set(local_user(), 'statusnet', 'consumersecret', $asn['consumersecret']); + DI::pConfig()->set(local_user(), 'statusnet', 'baseapi', $asn['apiurl']); + //DI::pConfig()->set(local_user(), 'statusnet', 'application_name', $asn['applicationname'] ); } else { - notice(L10n::t('Please contact your site administrator.
The provided API URL is not valid.') . EOL . $asn['apiurl'] . EOL); + notice(DI::l10n()->t('Please contact your site administrator.
The provided API URL is not valid.') . EOL . $asn['apiurl'] . EOL); } } } - $a->internalRedirect('settings/connectors'); + DI::baseUrl()->redirect('settings/connectors'); } else { if (isset($_POST['statusnet-consumersecret'])) { // check if we can reach the API of the GNU Social server // we'll check the API Version for that, if we don't get one we'll try to fix the path but will // resign quickly after this one try to fix the path ;-) $apibase = $_POST['statusnet-baseapi']; - $c = Network::fetchUrl($apibase . 'statusnet/version.xml'); + $c = DI::httpRequest()->fetch($apibase . 'statusnet/version.xml'); if (strlen($c) > 0) { // ok the API path is correct, let's save the settings - PConfig::set(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']); - PConfig::set(local_user(), 'statusnet', 'consumersecret', $_POST['statusnet-consumersecret']); - PConfig::set(local_user(), 'statusnet', 'baseapi', $apibase); - //PConfig::set(local_user(), 'statusnet', 'application_name', $_POST['statusnet-applicationname'] ); + DI::pConfig()->set(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']); + DI::pConfig()->set(local_user(), 'statusnet', 'consumersecret', $_POST['statusnet-consumersecret']); + DI::pConfig()->set(local_user(), 'statusnet', 'baseapi', $apibase); + //DI::pConfig()->set(local_user(), 'statusnet', 'application_name', $_POST['statusnet-applicationname'] ); } else { // the API path is not correct, maybe missing trailing / ? $apibase = $apibase . '/'; - $c = Network::fetchUrl($apibase . 'statusnet/version.xml'); + $c = DI::httpRequest()->fetch($apibase . 'statusnet/version.xml'); if (strlen($c) > 0) { // ok the API path is now correct, let's save the settings - PConfig::set(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']); - PConfig::set(local_user(), 'statusnet', 'consumersecret', $_POST['statusnet-consumersecret']); - PConfig::set(local_user(), 'statusnet', 'baseapi', $apibase); + DI::pConfig()->set(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']); + DI::pConfig()->set(local_user(), 'statusnet', 'consumersecret', $_POST['statusnet-consumersecret']); + DI::pConfig()->set(local_user(), 'statusnet', 'baseapi', $apibase); } else { // still not the correct API base, let's do noting - notice(L10n::t('We could not contact the GNU Social API with the Path you entered.') . EOL); + notice(DI::l10n()->t('We could not contact the GNU Social API with the Path you entered.') . EOL); } } - $a->internalRedirect('settings/connectors'); + DI::baseUrl()->redirect('settings/connectors'); } else { if (isset($_POST['statusnet-pin'])) { // if the user supplied us with a PIN from GNU Social, let the magic of OAuth happen - $api = PConfig::get(local_user(), 'statusnet', 'baseapi'); - $ckey = PConfig::get(local_user(), 'statusnet', 'consumerkey'); - $csecret = PConfig::get(local_user(), 'statusnet', 'consumersecret'); + $api = DI::pConfig()->get(local_user(), 'statusnet', 'baseapi'); + $ckey = DI::pConfig()->get(local_user(), 'statusnet', 'consumerkey'); + $csecret = DI::pConfig()->get(local_user(), 'statusnet', 'consumersecret'); // the token and secret for which the PIN was generated were hidden in the settings // form as token and token2, we need a new connection to GNU Social using these token // and secret to request a Access Token with the PIN $connection = new StatusNetOAuth($api, $ckey, $csecret, $_POST['statusnet-token'], $_POST['statusnet-token2']); $token = $connection->getAccessToken($_POST['statusnet-pin']); // ok, now that we have the Access Token, save them in the user config - PConfig::set(local_user(), 'statusnet', 'oauthtoken', $token['oauth_token']); - PConfig::set(local_user(), 'statusnet', 'oauthsecret', $token['oauth_token_secret']); - PConfig::set(local_user(), 'statusnet', 'post', 1); - PConfig::set(local_user(), 'statusnet', 'post_taglinks', 1); + DI::pConfig()->set(local_user(), 'statusnet', 'oauthtoken', $token['oauth_token']); + DI::pConfig()->set(local_user(), 'statusnet', 'oauthsecret', $token['oauth_token_secret']); + DI::pConfig()->set(local_user(), 'statusnet', 'post', 1); + DI::pConfig()->set(local_user(), 'statusnet', 'post_taglinks', 1); // reload the Addon Settings page, if we don't do it see Bug #42 - $a->internalRedirect('settings/connectors'); + DI::baseUrl()->redirect('settings/connectors'); } else { // if no PIN is supplied in the POST variables, the user has changed the setting // to post a dent for every new __public__ posting to the wall - PConfig::set(local_user(), 'statusnet', 'post', intval($_POST['statusnet-enable'])); - PConfig::set(local_user(), 'statusnet', 'post_by_default', intval($_POST['statusnet-default'])); - PConfig::set(local_user(), 'statusnet', 'mirror_posts', intval($_POST['statusnet-mirror'])); - PConfig::set(local_user(), 'statusnet', 'import', intval($_POST['statusnet-import'])); - PConfig::set(local_user(), 'statusnet', 'create_user', intval($_POST['statusnet-create_user'])); + DI::pConfig()->set(local_user(), 'statusnet', 'post', intval($_POST['statusnet-enable'])); + DI::pConfig()->set(local_user(), 'statusnet', 'post_by_default', intval($_POST['statusnet-default'])); + DI::pConfig()->set(local_user(), 'statusnet', 'mirror_posts', intval($_POST['statusnet-mirror'])); + DI::pConfig()->set(local_user(), 'statusnet', 'import', intval($_POST['statusnet-import'])); + DI::pConfig()->set(local_user(), 'statusnet', 'create_user', intval($_POST['statusnet-create_user'])); if (!intval($_POST['statusnet-mirror'])) - PConfig::delete(local_user(), 'statusnet', 'lastid'); - - info(L10n::t('GNU Social settings updated.') . EOL); + DI::pConfig()->delete(local_user(), 'statusnet', 'lastid'); } } } @@ -237,47 +216,50 @@ function statusnet_settings(App $a, &$s) if (!local_user()) { return; } - $a->page['htmlhead'] .= '' . "\r\n"; + + $user = User::getById(local_user()); + + DI::page()['htmlhead'] .= '' . "\r\n"; /* * * * 1) Check that we have a base api url and a consumer key & secret * 2) If no OAuthtoken & stuff is present, generate button to get some * allow the user to cancel the connection process at this step * 3) Checkbox for "Send public notices (respect size limitation) */ - $api = PConfig::get(local_user(), 'statusnet', 'baseapi'); - $ckey = PConfig::get(local_user(), 'statusnet', 'consumerkey'); - $csecret = PConfig::get(local_user(), 'statusnet', 'consumersecret'); - $otoken = PConfig::get(local_user(), 'statusnet', 'oauthtoken'); - $osecret = PConfig::get(local_user(), 'statusnet', 'oauthsecret'); - $enabled = PConfig::get(local_user(), 'statusnet', 'post'); + $api = DI::pConfig()->get(local_user(), 'statusnet', 'baseapi'); + $ckey = DI::pConfig()->get(local_user(), 'statusnet', 'consumerkey'); + $csecret = DI::pConfig()->get(local_user(), 'statusnet', 'consumersecret'); + $otoken = DI::pConfig()->get(local_user(), 'statusnet', 'oauthtoken'); + $osecret = DI::pConfig()->get(local_user(), 'statusnet', 'oauthsecret'); + $enabled = DI::pConfig()->get(local_user(), 'statusnet', 'post'); $checked = (($enabled) ? ' checked="checked" ' : ''); - $defenabled = PConfig::get(local_user(), 'statusnet', 'post_by_default'); + $defenabled = DI::pConfig()->get(local_user(), 'statusnet', 'post_by_default'); $defchecked = (($defenabled) ? ' checked="checked" ' : ''); - $mirrorenabled = PConfig::get(local_user(), 'statusnet', 'mirror_posts'); + $mirrorenabled = DI::pConfig()->get(local_user(), 'statusnet', 'mirror_posts'); $mirrorchecked = (($mirrorenabled) ? ' checked="checked" ' : ''); - $import = PConfig::get(local_user(), 'statusnet', 'import'); + $import = DI::pConfig()->get(local_user(), 'statusnet', 'import'); $importselected = ["", "", ""]; $importselected[$import] = ' selected="selected"'; - //$importenabled = PConfig::get(local_user(),'statusnet','import'); + //$importenabled = DI::pConfig()->get(local_user(),'statusnet','import'); //$importchecked = (($importenabled) ? ' checked="checked" ' : ''); - $create_userenabled = PConfig::get(local_user(), 'statusnet', 'create_user'); + $create_userenabled = DI::pConfig()->get(local_user(), 'statusnet', 'create_user'); $create_userchecked = (($create_userenabled) ? ' checked="checked" ' : ''); $css = (($enabled) ? '' : '-disabled'); $s .= ''; - $s .= '

' . L10n::t('GNU Social Import/Export/Mirror') . '

'; + $s .= '

' . DI::l10n()->t('GNU Social Import/Export/Mirror') . '

'; $s .= '
'; $s .= '
'; @@ -421,9 +403,9 @@ function statusnet_hook_fork(App $a, array &$b) return; } - if (PConfig::get($post['uid'], 'statusnet', 'import')) { + if (DI::pConfig()->get($post['uid'], 'statusnet', 'import')) { // Don't fork if it isn't a reply to a GNU Social post - if (($post['parent'] != $post['id']) && !Item::exists(['id' => $post['parent'], 'network' => Protocol::STATUSNET])) { + if (($post['parent'] != $post['id']) && !Post::exists(['id' => $post['parent'], 'network' => Protocol::STATUSNET])) { Logger::log('No GNU Social parent found for item ' . $post['id']); $b['execute'] = false; return; @@ -447,11 +429,11 @@ function statusnet_post_local(App $a, &$b) return; } - $statusnet_post = PConfig::get(local_user(), 'statusnet', 'post'); + $statusnet_post = DI::pConfig()->get(local_user(), 'statusnet', 'post'); $statusnet_enable = (($statusnet_post && !empty($_REQUEST['statusnet_enable'])) ? intval($_REQUEST['statusnet_enable']) : 0); // if API is used, default to the chosen settings - if ($b['api_source'] && intval(PConfig::get(local_user(), 'statusnet', 'post_by_default'))) { + if ($b['api_source'] && intval(DI::pConfig()->get(local_user(), 'statusnet', 'post_by_default'))) { $statusnet_enable = 1; } @@ -468,11 +450,11 @@ function statusnet_post_local(App $a, &$b) function statusnet_action(App $a, $uid, $pid, $action) { - $api = PConfig::get($uid, 'statusnet', 'baseapi'); - $ckey = PConfig::get($uid, 'statusnet', 'consumerkey'); - $csecret = PConfig::get($uid, 'statusnet', 'consumersecret'); - $otoken = PConfig::get($uid, 'statusnet', 'oauthtoken'); - $osecret = PConfig::get($uid, 'statusnet', 'oauthsecret'); + $api = DI::pConfig()->get($uid, 'statusnet', 'baseapi'); + $ckey = DI::pConfig()->get($uid, 'statusnet', 'consumerkey'); + $csecret = DI::pConfig()->get($uid, 'statusnet', 'consumersecret'); + $otoken = DI::pConfig()->get($uid, 'statusnet', 'oauthtoken'); + $osecret = DI::pConfig()->get($uid, 'statusnet', 'oauthsecret'); $connection = new StatusNetOAuth($api, $ckey, $csecret, $otoken, $osecret); @@ -497,12 +479,14 @@ function statusnet_post_hook(App $a, &$b) /** * Post to GNU Social */ - if (!PConfig::get($b["uid"], 'statusnet', 'import')) { + if (!DI::pConfig()->get($b["uid"], 'statusnet', 'import')) { if ($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited'])) return; } - $api = PConfig::get($b["uid"], 'statusnet', 'baseapi'); + $b['body'] = Post\Media::addAttachmentsToBody($b['uri-id'], $b['body']); + + $api = DI::pConfig()->get($b["uid"], 'statusnet', 'baseapi'); $hostname = preg_replace("=https?://([\w\.]*)/.*=ism", "$1", $api); if ($b['parent'] != $b['id']) { @@ -516,7 +500,7 @@ function statusnet_post_hook(App $a, &$b) } $condition = ['uri' => $b["thr-parent"], 'uid' => $b["uid"]]; - $orig_post = Item::selectFirst(['author-link', 'uri'], $condition); + $orig_post = Post::selectFirst(['author-link', 'uri'], $condition); if (!DBA::isResult($orig_post)) { Logger::log("statusnet_post_hook: no parent found " . $b["thr-parent"]); return; @@ -550,11 +534,11 @@ function statusnet_post_hook(App $a, &$b) } } - if (($b['verb'] == ACTIVITY_POST) && $b['deleted']) { + if (($b['verb'] == Activity::POST) && $b['deleted']) { statusnet_action($a, $b["uid"], substr($orig_post["uri"], $hostlength), "delete"); } - if ($b['verb'] == ACTIVITY_LIKE) { + if ($b['verb'] == Activity::LIKE) { Logger::log("statusnet_post_hook: parameter 2 " . substr($b["thr-parent"], $hostlength), Logger::DEBUG); if ($b['deleted']) statusnet_action($a, $b["uid"], substr($b["thr-parent"], $hostlength), "unlike"); @@ -578,13 +562,13 @@ function statusnet_post_hook(App $a, &$b) Logger::log('GNU Socialpost invoked'); - PConfig::load($b['uid'], 'statusnet'); + DI::pConfig()->load($b['uid'], 'statusnet'); - $api = PConfig::get($b['uid'], 'statusnet', 'baseapi'); - $ckey = PConfig::get($b['uid'], 'statusnet', 'consumerkey'); - $csecret = PConfig::get($b['uid'], 'statusnet', 'consumersecret'); - $otoken = PConfig::get($b['uid'], 'statusnet', 'oauthtoken'); - $osecret = PConfig::get($b['uid'], 'statusnet', 'oauthsecret'); + $api = DI::pConfig()->get($b['uid'], 'statusnet', 'baseapi'); + $ckey = DI::pConfig()->get($b['uid'], 'statusnet', 'consumerkey'); + $csecret = DI::pConfig()->get($b['uid'], 'statusnet', 'consumersecret'); + $otoken = DI::pConfig()->get($b['uid'], 'statusnet', 'oauthtoken'); + $osecret = DI::pConfig()->get($b['uid'], 'statusnet', 'oauthsecret'); if ($ckey && $csecret && $otoken && $osecret) { // If it's a repeated message from GNU Social then do a native retweet and exit @@ -595,14 +579,14 @@ function statusnet_post_hook(App $a, &$b) $dent = new StatusNetOAuth($api, $ckey, $csecret, $otoken, $osecret); $max_char = $dent->get_maxlength(); // max. length for a dent - PConfig::set($b['uid'], 'statusnet', 'max_char', $max_char); + DI::pConfig()->set($b['uid'], 'statusnet', 'max_char', $max_char); $tempfile = ""; - $msgarr = ItemContent::getPlaintextPost($b, $max_char, true, 7); + $msgarr = Plaintext::getPost($b, $max_char, true, 7); $msg = $msgarr["text"]; if (($msg == "") && isset($msgarr["title"])) - $msg = Plaintext::shorten($msgarr["title"], $max_char - 50); + $msg = Plaintext::shorten($msgarr["title"], $max_char - 50, $b['uid']); $image = ""; @@ -613,7 +597,7 @@ function statusnet_post_hook(App $a, &$b) } if ($image != "") { - $img_str = Network::fetchUrl($image); + $img_str = DI::httpRequest()->fetch($image); $tempfile = tempnam(get_temppath(), "cache"); file_put_contents($tempfile, $img_str); $postdata = ["status" => $msg, "media[]" => $tempfile]; @@ -640,7 +624,7 @@ function statusnet_post_hook(App $a, &$b) "\nmessage: " . $msg . "\nOriginal post: " . print_r($b, true) . "\nPost Data: " . print_r($postdata, true), Logger::DEBUG); if (!empty($result->source)) { - PConfig::set($b["uid"], "statusnet", "application_name", strip_tags($result->source)); + DI::pConfig()->set($b["uid"], "statusnet", "application_name", strip_tags($result->source)); } if (!empty($result->error)) { @@ -685,18 +669,18 @@ function statusnet_addon_admin_post(App $a) } } - $sites = Config::set('statusnet', 'sites', $sites); + $sites = DI::config()->set('statusnet', 'sites', $sites); } function statusnet_addon_admin(App $a, &$o) { - $sites = Config::get('statusnet', 'sites'); + $sites = DI::config()->get('statusnet', 'sites'); $sitesform = []; if (is_array($sites)) { foreach ($sites as $id => $s) { $sitesform[] = [ 'sitename' => ["sitename[$id]", "Site name", $s['sitename'], ""], - 'apiurl' => ["apiurl[$id]", "Api url", $s['apiurl'], L10n::t("Base API Path \x28remember the trailing /\x29")], + 'apiurl' => ["apiurl[$id]", "Api url", $s['apiurl'], DI::l10n()->t("Base API Path \x28remember the trailing /\x29")], 'secret' => ["secret[$id]", "Secret", $s['consumersecret'], ""], 'key' => ["key[$id]", "Key", $s['consumerkey'], ""], //'applicationname' => Array("applicationname[$id]", "Application name", $s['applicationname'], ""), @@ -707,16 +691,16 @@ function statusnet_addon_admin(App $a, &$o) /* empty form to add new site */ $id = count($sitesform); $sitesform[] = [ - 'sitename' => ["sitename[$id]", L10n::t("Site name"), "", ""], - 'apiurl' => ["apiurl[$id]", "Api url", "", L10n::t("Base API Path \x28remember the trailing /\x29")], - 'secret' => ["secret[$id]", L10n::t("Consumer Secret"), "", ""], - 'key' => ["key[$id]", L10n::t("Consumer Key"), "", ""], - //'applicationname' => Array("applicationname[$id]", L10n::t("Application name"), "", ""), + 'sitename' => ["sitename[$id]", DI::l10n()->t("Site name"), "", ""], + 'apiurl' => ["apiurl[$id]", "Api url", "", DI::l10n()->t("Base API Path \x28remember the trailing /\x29")], + 'secret' => ["secret[$id]", DI::l10n()->t("Consumer Secret"), "", ""], + 'key' => ["key[$id]", DI::l10n()->t("Consumer Key"), "", ""], + //'applicationname' => Array("applicationname[$id]", DI::l10n()->t("Application name"), "", ""), ]; $t = Renderer::getMarkupTemplate("admin.tpl", "addon/statusnet/"); $o = Renderer::replaceMacros($t, [ - '$submit' => L10n::t('Save Settings'), + '$submit' => DI::l10n()->t('Save Settings'), '$sites' => $sitesform, ]); } @@ -728,16 +712,16 @@ function statusnet_prepare_body(App $a, &$b) } if ($b["preview"]) { - $max_char = PConfig::get(local_user(), 'statusnet', 'max_char'); + $max_char = DI::pConfig()->get(local_user(), 'statusnet', 'max_char'); if (intval($max_char) == 0) { $max_char = 140; } $item = $b["item"]; - $item["plink"] = $a->getBaseURL() . "/display/" . $item["guid"]; + $item["plink"] = DI::baseUrl()->get() . "/display/" . $item["guid"]; $condition = ['uri' => $item["thr-parent"], 'uid' => local_user()]; - $orig_post = Item::selectFirst(['author-link', 'uri'], $condition); + $orig_post = Post::selectFirst(['author-link', 'uri'], $condition); if (DBA::isResult($orig_post)) { $nick = preg_replace("=https?://(.*)/(.*)=ism", "$2", $orig_post["author-link"]); @@ -749,7 +733,7 @@ function statusnet_prepare_body(App $a, &$b) } } - $msgarr = ItemContent::getPlaintextPost($item, $max_char, true, 7); + $msgarr = Plaintext::getPost($item, $max_char, true, 7); $msg = $msgarr["text"]; if (isset($msgarr["url"]) && ($msgarr["type"] != "photo")) { @@ -766,9 +750,9 @@ function statusnet_prepare_body(App $a, &$b) function statusnet_cron(App $a, $b) { - $last = Config::get('statusnet', 'last_poll'); + $last = DI::config()->get('statusnet', 'last_poll'); - $poll_interval = intval(Config::get('statusnet', 'poll_interval')); + $poll_interval = intval(DI::config()->get('statusnet', 'poll_interval')); if (!$poll_interval) { $poll_interval = STATUSNET_DEFAULT_POLL_INTERVAL; } @@ -790,7 +774,7 @@ function statusnet_cron(App $a, $b) } } - $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; } @@ -815,28 +799,28 @@ function statusnet_cron(App $a, $b) Logger::log('statusnet: cron_end'); - Config::set('statusnet', 'last_poll', time()); + DI::config()->set('statusnet', 'last_poll', time()); } function statusnet_fetchtimeline(App $a, $uid) { - $ckey = PConfig::get($uid, 'statusnet', 'consumerkey'); - $csecret = PConfig::get($uid, 'statusnet', 'consumersecret'); - $api = PConfig::get($uid, 'statusnet', 'baseapi'); - $otoken = PConfig::get($uid, 'statusnet', 'oauthtoken'); - $osecret = PConfig::get($uid, 'statusnet', 'oauthsecret'); - $lastid = PConfig::get($uid, 'statusnet', 'lastid'); + $ckey = DI::pConfig()->get($uid, 'statusnet', 'consumerkey'); + $csecret = DI::pConfig()->get($uid, 'statusnet', 'consumersecret'); + $api = DI::pConfig()->get($uid, 'statusnet', 'baseapi'); + $otoken = DI::pConfig()->get($uid, 'statusnet', 'oauthtoken'); + $osecret = DI::pConfig()->get($uid, 'statusnet', 'oauthsecret'); + $lastid = DI::pConfig()->get($uid, 'statusnet', 'lastid'); require_once 'mod/item.php'; // get the application name for the SN 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, 'statusnet', 'application_name'); + $application_name = DI::pConfig()->get($uid, 'statusnet', 'application_name'); if ($application_name == "") { - $application_name = Config::get('statusnet', 'application_name'); + $application_name = DI::config()->get('statusnet', 'application_name'); } if ($application_name == "") { - $application_name = $a->getHostName(); + $application_name = DI::baseUrl()->getHostname(); } $connection = new StatusNetOAuth($api, $ckey, $csecret, $otoken, $osecret); @@ -897,7 +881,7 @@ function statusnet_fetchtimeline(App $a, $uid) $_REQUEST["title"] = ""; - $_REQUEST["body"] = add_page_info_to_body($post->text, true); + $_REQUEST["body"] = $post->text; if (is_string($post->place->name)) { $_REQUEST["location"] = $post->place->name; } @@ -923,7 +907,7 @@ function statusnet_fetchtimeline(App $a, $uid) } } } - PConfig::set($uid, 'statusnet', 'lastid', $lastid); + DI::pConfig()->set($uid, 'statusnet', 'lastid', $lastid); } function statusnet_address($contact) @@ -1054,11 +1038,11 @@ function statusnet_fetch_contact($uid, $contact, $create_user) function statusnet_fetchuser(App $a, $uid, $screen_name = "", $user_id = "") { - $ckey = PConfig::get($uid, 'statusnet', 'consumerkey'); - $csecret = PConfig::get($uid, 'statusnet', 'consumersecret'); - $api = PConfig::get($uid, 'statusnet', 'baseapi'); - $otoken = PConfig::get($uid, 'statusnet', 'oauthtoken'); - $osecret = PConfig::get($uid, 'statusnet', 'oauthsecret'); + $ckey = DI::pConfig()->get($uid, 'statusnet', 'consumerkey'); + $csecret = DI::pConfig()->get($uid, 'statusnet', 'consumersecret'); + $api = DI::pConfig()->get($uid, 'statusnet', 'baseapi'); + $otoken = DI::pConfig()->get($uid, 'statusnet', 'oauthtoken'); + $osecret = DI::pConfig()->get($uid, 'statusnet', 'oauthsecret'); require_once __DIR__ . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR . 'codebirdsn.php'; @@ -1101,7 +1085,7 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex { Logger::log("statusnet_createpost: start", Logger::DEBUG); - $api = PConfig::get($uid, 'statusnet', 'baseapi'); + $api = DI::pConfig()->get($uid, 'statusnet', 'baseapi'); $hostname = preg_replace("=https?://([\w\.]*)/.*=ism", "$1", $api); $postarray = []; @@ -1118,36 +1102,29 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex $postarray['uri'] = $hostname . "::" . $content->id; - if (Item::exists(['extid' => $postarray['uri'], 'uid' => $uid])) { + if (Post::exists(['extid' => $postarray['uri'], 'uid' => $uid])) { return []; } $contactid = 0; if (!empty($content->in_reply_to_status_id)) { + $thr_parent = $hostname . "::" . $content->in_reply_to_status_id; - $parent = $hostname . "::" . $content->in_reply_to_status_id; - - $fields = ['uri', 'parent-uri', 'parent']; - $item = Item::selectFirst($fields, ['uri' => $parent, 'uid' => $uid]); - + $item = Post::selectFirst(['uri'], ['uri' => $thr_parent, 'uid' => $uid]); if (!DBA::isResult($item)) { - $item = Item::selectFirst($fields, ['extid' => $parent, 'uid' => $uid]); + $item = Post::selectFirst(['uri'], ['extid' => $thr_parent, 'uid' => $uid]); } if (DBA::isResult($item)) { $postarray['thr-parent'] = $item['uri']; - $postarray['parent-uri'] = $item['parent-uri']; - $postarray['parent'] = $item['parent']; - $postarray['object-type'] = ACTIVITY_OBJ_COMMENT; + $postarray['object-type'] = Activity\ObjectType::COMMENT; } else { - $postarray['thr-parent'] = $postarray['uri']; - $postarray['parent-uri'] = $postarray['uri']; - $postarray['object-type'] = ACTIVITY_OBJ_NOTE; + $postarray['object-type'] = Activity\ObjectType::NOTE; } // Is it me? - $own_url = PConfig::get($uid, 'statusnet', 'own_url'); + $own_url = DI::pConfig()->get($uid, 'statusnet', 'own_url'); if ($content->user->id == $own_url) { $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", @@ -1166,8 +1143,7 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex // Don't create accounts of people who just comment something $create_user = false; } else { - $postarray['parent-uri'] = $postarray['uri']; - $postarray['object-type'] = ACTIVITY_OBJ_NOTE; + $postarray['object-type'] = Activity\ObjectType::NOTE; } if ($contactid == 0) { @@ -1184,14 +1160,14 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex $postarray['contact-id'] = $contactid; - $postarray['verb'] = ACTIVITY_POST; + $postarray['verb'] = Activity::POST; $postarray['author-name'] = $content->user->name; $postarray['author-link'] = $content->user->statusnet_profile_url; $postarray['author-avatar'] = $content->user->profile_image_url; // To-Do: Maybe unreliable? Can the api be entered without trailing "/"? - $hostname = str_replace("/api/", "/notice/", PConfig::get($uid, 'statusnet', 'baseapi')); + $hostname = str_replace("/api/", "/notice/", DI::pConfig()->get($uid, 'statusnet', 'baseapi')); $postarray['plink'] = $hostname . $content->id; $postarray['app'] = strip_tags($content->source); @@ -1203,9 +1179,7 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex $postarray['body'] = HTML::toBBCode($content->statusnet_html); - $converted = statusnet_convertmsg($a, $postarray['body'], false); - $postarray['body'] = $converted["body"]; - $postarray['tag'] = $converted["tags"]; + $postarray['body'] = statusnet_convertmsg($a, $postarray['body']); $postarray['created'] = DateTimeFormat::utc($content->created_at); $postarray['edited'] = DateTimeFormat::utc($content->created_at); @@ -1235,12 +1209,12 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1) { $conversations = []; - $ckey = PConfig::get($uid, 'statusnet', 'consumerkey'); - $csecret = PConfig::get($uid, 'statusnet', 'consumersecret'); - $api = PConfig::get($uid, 'statusnet', 'baseapi'); - $otoken = PConfig::get($uid, 'statusnet', 'oauthtoken'); - $osecret = PConfig::get($uid, 'statusnet', 'oauthsecret'); - $create_user = PConfig::get($uid, 'statusnet', 'create_user'); + $ckey = DI::pConfig()->get($uid, 'statusnet', 'consumerkey'); + $csecret = DI::pConfig()->get($uid, 'statusnet', 'consumersecret'); + $api = DI::pConfig()->get($uid, 'statusnet', 'baseapi'); + $otoken = DI::pConfig()->get($uid, 'statusnet', 'oauthtoken'); + $osecret = DI::pConfig()->get($uid, 'statusnet', 'oauthsecret'); + $create_user = DI::pConfig()->get($uid, 'statusnet', 'create_user'); // "create_user" is deactivated, since currently you cannot add users manually by now $create_user = true; @@ -1288,7 +1262,7 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1) if ($mode == 1) { // Fetching timeline - $lastid = PConfig::get($uid, 'statusnet', 'lasthometimelineid'); + $lastid = DI::pConfig()->get($uid, 'statusnet', 'lasthometimelineid'); //$lastid = 1; $first_time = ($lastid == ""); @@ -1348,11 +1322,11 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1) } } } - PConfig::set($uid, 'statusnet', 'lasthometimelineid', $lastid); + DI::pConfig()->set($uid, 'statusnet', 'lasthometimelineid', $lastid); } // Fetching mentions - $lastid = PConfig::get($uid, 'statusnet', 'lastmentionid'); + $lastid = DI::pConfig()->get($uid, 'statusnet', 'lastmentionid'); $first_time = ($lastid == ""); if ($lastid != "") { @@ -1399,17 +1373,17 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1) } } - PConfig::set($uid, 'statusnet', 'lastmentionid', $lastid); + DI::pConfig()->set($uid, 'statusnet', 'lastmentionid', $lastid); } function statusnet_complete_conversation(App $a, $uid, $self, $create_user, $nick, $conversation) { - $ckey = PConfig::get($uid, 'statusnet', 'consumerkey'); - $csecret = PConfig::get($uid, 'statusnet', 'consumersecret'); - $api = PConfig::get($uid, 'statusnet', 'baseapi'); - $otoken = PConfig::get($uid, 'statusnet', 'oauthtoken'); - $osecret = PConfig::get($uid, 'statusnet', 'oauthsecret'); - $own_url = PConfig::get($uid, 'statusnet', 'own_url'); + $ckey = DI::pConfig()->get($uid, 'statusnet', 'consumerkey'); + $csecret = DI::pConfig()->get($uid, 'statusnet', 'consumersecret'); + $api = DI::pConfig()->get($uid, 'statusnet', 'baseapi'); + $otoken = DI::pConfig()->get($uid, 'statusnet', 'oauthtoken'); + $osecret = DI::pConfig()->get($uid, 'statusnet', 'oauthsecret'); + $own_url = DI::pConfig()->get($uid, 'statusnet', 'own_url'); $connection = new StatusNetOAuth($api, $ckey, $csecret, $otoken, $osecret); @@ -1434,7 +1408,7 @@ function statusnet_complete_conversation(App $a, $uid, $self, $create_user, $nic } } -function statusnet_convertmsg(App $a, $body, $no_tags = false) +function statusnet_convertmsg(App $a, $body) { $body = preg_replace("=\[url\=https?://([0-9]*).([0-9]*).([0-9]*).([0-9]*)/([0-9]*)\](.*?)\[\/url\]=ism", "$1.$2.$3.$4/$5", $body); @@ -1452,7 +1426,7 @@ function statusnet_convertmsg(App $a, $body, $no_tags = false) Logger::log("statusnet_convertmsg: expanding url " . $match[1], Logger::DEBUG); - $expanded_url = Network::finalUrl($match[1]); + $expanded_url = DI::httpRequest()->finalUrl($match[1]); Logger::log("statusnet_convertmsg: fetching data for " . $expanded_url, Logger::DEBUG); @@ -1476,7 +1450,7 @@ function statusnet_convertmsg(App $a, $body, $no_tags = false) } elseif ($oembed_data->type != "link") { $body = str_replace($search, "[url=" . $expanded_url . "]" . $expanded_url . "[/url]", $body); } else { - $img_str = Network::fetchUrl($expanded_url, true, 4); + $img_str = DI::httpRequest()->fetch($expanded_url, 4); $tempfile = tempnam(get_temppath(), "cache"); file_put_contents($tempfile, $img_str); @@ -1497,7 +1471,7 @@ function statusnet_convertmsg(App $a, $body, $no_tags = false) } if ($footerurl != "") { - $footer = add_page_info($footerurl); + $footer = "\n" . PageInfo::getFooterFromUrl($footerurl); } if (($footerlink != "") && (trim($footer) != "")) { @@ -1511,46 +1485,17 @@ function statusnet_convertmsg(App $a, $body, $no_tags = false) } } - if ($no_tags) { - return ["body" => $body, "tags" => ""]; - } - - $str_tags = ''; - - $cnt = preg_match_all("/([!#@])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", $body, $matches, PREG_SET_ORDER); - if ($cnt) { - foreach ($matches as $mtch) { - if (strlen($str_tags)) { - $str_tags .= ','; - } - - if ($mtch[1] == "#") { - // Replacing the hash tags that are directed to the GNU Social server with internal links - $snhash = "#[url=" . $mtch[2] . "]" . $mtch[3] . "[/url]"; - $frdchash = '#[url=' . $a->getBaseURL() . '/search?tag=' . $mtch[3] . ']' . $mtch[3] . '[/url]'; - $body = str_replace($snhash, $frdchash, $body); - - $str_tags .= $frdchash; - } else { - $str_tags .= "@[url=" . $mtch[2] . "]" . $mtch[3] . "[/url]"; - } - // To-Do: - // There is a problem with links with to GNU Social groups, so these links are stored with "@" like friendica groups - //$str_tags .= $mtch[1]."[url=".$mtch[2]."]".$mtch[3]."[/url]"; - } - } - - return ["body" => $body, "tags" => $str_tags]; + return $body; } function statusnet_fetch_own_contact(App $a, $uid) { - $ckey = PConfig::get($uid, 'statusnet', 'consumerkey'); - $csecret = PConfig::get($uid, 'statusnet', 'consumersecret'); - $api = PConfig::get($uid, 'statusnet', 'baseapi'); - $otoken = PConfig::get($uid, 'statusnet', 'oauthtoken'); - $osecret = PConfig::get($uid, 'statusnet', 'oauthsecret'); - $own_url = PConfig::get($uid, 'statusnet', 'own_url'); + $ckey = DI::pConfig()->get($uid, 'statusnet', 'consumerkey'); + $csecret = DI::pConfig()->get($uid, 'statusnet', 'consumersecret'); + $api = DI::pConfig()->get($uid, 'statusnet', 'baseapi'); + $otoken = DI::pConfig()->get($uid, 'statusnet', 'oauthtoken'); + $osecret = DI::pConfig()->get($uid, 'statusnet', 'oauthsecret'); + $own_url = DI::pConfig()->get($uid, 'statusnet', 'own_url'); $contact_id = 0; @@ -1564,7 +1509,7 @@ function statusnet_fetch_own_contact(App $a, $uid) return false; } - PConfig::set($uid, 'statusnet', 'own_url', Strings::normaliseLink($user->statusnet_profile_url)); + DI::pConfig()->set($uid, 'statusnet', 'own_url', Strings::normaliseLink($user->statusnet_profile_url)); $contact_id = statusnet_fetch_contact($uid, $user, true); } else { @@ -1573,7 +1518,7 @@ function statusnet_fetch_own_contact(App $a, $uid) if (DBA::isResult($r)) { $contact_id = $r[0]["id"]; } else { - PConfig::delete($uid, 'statusnet', 'own_url'); + DI::pConfig()->delete($uid, 'statusnet', 'own_url'); } } return $contact_id; @@ -1611,11 +1556,11 @@ function statusnet_is_retweet(App $a, $uid, $body) $link = $matches[1]; } - $ckey = PConfig::get($uid, 'statusnet', 'consumerkey'); - $csecret = PConfig::get($uid, 'statusnet', 'consumersecret'); - $api = PConfig::get($uid, 'statusnet', 'baseapi'); - $otoken = PConfig::get($uid, 'statusnet', 'oauthtoken'); - $osecret = PConfig::get($uid, 'statusnet', 'oauthsecret'); + $ckey = DI::pConfig()->get($uid, 'statusnet', 'consumerkey'); + $csecret = DI::pConfig()->get($uid, 'statusnet', 'consumersecret'); + $api = DI::pConfig()->get($uid, 'statusnet', 'baseapi'); + $otoken = DI::pConfig()->get($uid, 'statusnet', 'oauthtoken'); + $osecret = DI::pConfig()->get($uid, 'statusnet', 'oauthsecret'); $hostname = preg_replace("=https?://([\w\.]*)/.*=ism", "$1", $api); $id = preg_replace("=https?://" . $hostname . "/notice/(.*)=ism", "$1", $link);