X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=discourse%2Fdiscourse.php;h=3d27c5b0b09afc4a45fdf5787622d232c6748fb6;hb=30af3b93ed2328aeab9ba4341e5fdd21ac9c0638;hp=06b8667763f517afb946cd68b0e1cbc4c37486a7;hpb=9640142a720dfc7683e7bbf60d6f4f8799b918e9;p=friendica-addons.git diff --git a/discourse/discourse.php b/discourse/discourse.php index 06b86677..3d27c5b0 100644 --- a/discourse/discourse.php +++ b/discourse/discourse.php @@ -17,7 +17,6 @@ use Friendica\Core\Renderer; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; -use Friendica\Network\HTTPRequest; use Friendica\Util\DateTimeFormat; use Friendica\Util\Strings; @@ -37,32 +36,38 @@ function discourse_install() Hook::register('connector_settings_post', __FILE__, 'discourse_settings_post'); } -function discourse_settings(App $a, &$s) +function discourse_settings(array &$data) { - if (!local_user()) { + if (!DI::userSession()->getLocalUserId()) { return; } - $enabled = intval(DI::pConfig()->get(local_user(), 'discourse', 'enabled')); + $enabled = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'discourse', 'enabled')); - $t = Renderer::getMarkupTemplate('settings.tpl', 'addon/discourse/'); - $s .= Renderer::replaceMacros($t, [ - '$title' => DI::l10n()->t('Discourse'), + $t = Renderer::getMarkupTemplate('connector_settings.tpl', 'addon/discourse/'); + $html = Renderer::replaceMacros($t, [ '$enabled' => ['enabled', DI::l10n()->t('Enable processing of Discourse mailing list mails'), $enabled, DI::l10n()->t('If enabled, incoming mails from Discourse will be improved so they look much better. To make it work, you have to configure the e-mail settings in Friendica. You also have to enable the mailing list mode in Discourse. Then you have to add the Discourse mail account as contact.')], - '$submit' => DI::l10n()->t('Save Settings'), ]); + + $data = [ + 'connector' => 'discourse', + 'title' => DI::l10n()->t('Discourse'), + 'image' => 'images/discourse.png', + 'enabled' => $enabled, + 'html' => $html, + ]; } -function discourse_settings_post(App $a) +function discourse_settings_post() { - if (!local_user() || empty($_POST['discourse-submit'])) { + if (!DI::userSession()->getLocalUserId() || empty($_POST['discourse-submit'])) { return; } - DI::pConfig()->set(local_user(), 'discourse', 'enabled', intval($_POST['enabled'])); + DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'discourse', 'enabled', intval($_POST['enabled'])); } -function discourse_email_getmessage(App $a, &$message) +function discourse_email_getmessage(&$message) { if (empty($message['item']['uid'])) { return; @@ -107,7 +112,7 @@ function discourse_email_getmessage(App $a, &$message) } // Remove the title on comments, they don't serve any purpose there - if ($message['item']['parent-uri'] != $message['item']['uri']) { + if ($message['item']['thr-parent'] != $message['item']['uri']) { unset($message['item']['title']); } } @@ -115,7 +120,7 @@ function discourse_email_getmessage(App $a, &$message) function discourse_fetch_post($host, $topic, $pid) { $url = $host . '/t/' . $topic . '/' . $pid . '.json'; - $curlResult = HTTPRequest::curl($url); + $curlResult = DI::httpClient()->get($url); if (!$curlResult->isSuccess()) { Logger::info('No success', ['url' => $url]); return false; @@ -152,7 +157,7 @@ function discourse_fetch_post_from_api(&$message, $post, $host) { $hostaddr = 'https://' . $host; $url = $hostaddr . '/posts/' . $post . '.json'; - $curlResult = HTTPRequest::curl($url); + $curlResult = DI::httpClient()->get($url); if (!$curlResult->isSuccess()) { return false; } @@ -204,7 +209,7 @@ function discourse_get_user($post, $hostaddr) $avatar = $contact['photo']; unset($contact['photo']); DBA::update('contact', $contact, ['id' => $contact['id']]); - Contact::updateAvatar($avatar, 0, $contact['id']); + Contact::updateAvatar($contact['id'], $avatar); $contact['photo'] = $avatar; }