From: Michael Date: Mon, 25 Nov 2019 22:58:01 +0000 (+0000) Subject: Settings page added X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=0235126589e0ad23c3e72a34203402b73bf3dea0;p=friendica-addons.git Settings page added --- diff --git a/discourse/discourse.php b/discourse/discourse.php index 3b0f7cf4..d8bb95f2 100644 --- a/discourse/discourse.php +++ b/discourse/discourse.php @@ -14,6 +14,7 @@ use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\Logger; use Friendica\Core\PConfig; +use Friendica\Core\Renderer; use Friendica\Core\Protocol; use Friendica\Database\DBA; use Friendica\Model\Contact; @@ -25,9 +26,9 @@ Use Friendica\Util\DateTimeFormat; function discourse_install() { - Hook::register('email_getmessage', __FILE__, 'discourse_email_getmessage'); - Hook::register('addon_settings', __FILE__, 'discourse_settings'); - Hook::register('addon_settings_post', __FILE__, 'discourse_settings_post'); + Hook::register('email_getmessage', __FILE__, 'discourse_email_getmessage'); + Hook::register('connector_settings', __FILE__, 'discourse_settings'); + Hook::register('connector_settings_post', __FILE__, 'discourse_settings_post'); } function discourse_uninstall() @@ -37,29 +38,64 @@ function discourse_uninstall() Hook::unregister('connector_settings_post', __FILE__, 'discourse_settings_post'); } -function discourse_addon_settings(App $a, &$s) +function discourse_settings(App $a, &$s) { + if (!local_user()) { + return; + } + + $enabled = intval(PConfig::get(local_user(), 'discourse', 'enabled')); + $css = ($enabled ? '' : '-disabled'); + + $s .= ''; + $s .= '

' . L10n::t('Discourse') . '

'; + $s .= '
'; + $s .= ''; } -function discourse_addon_settings_post(App $a) +function discourse_settings_post(App $a) { + if (!local_user() || empty($_POST['discourse-submit'])) { + return; + } + + PConfig::set(local_user(), 'discourse', 'enabled', intval($_POST['enabled'])); } function discourse_email_getmessage(App $a, &$message) { -// Logger::info('Got raw message', $message); + if (empty($message['item']['uid'])) { + return; + } + + if (!PConfig::get($message['item']['uid'], 'discourse', 'enabled')) { + return; + } // We do assume that all Discourse servers are running with SSL if (preg_match('=topic/(.*\d)/(.*\d)@(.*)=', $message['item']['uri'], $matches) && discourse_fetch_post_from_api($message, $matches[2], $matches[3])) { - Logger::info('Fetched comment via API', ['host' => $matches[3], 'topic' => $matches[1], 'post' => $matches[2]]); + Logger::info('Fetched comment via API (message-id mode)', ['host' => $matches[3], 'topic' => $matches[1], 'post' => $matches[2]]); return; } if (preg_match('=topic/(.*\d)@(.*)=', $message['item']['uri'], $matches) && discourse_fetch_topic_from_api($message, 'https://' . $matches[2], $matches[1], 1)) { discourse_fetch_post_from_api($message, $matches[2], $matches[3]); - Logger::info('Fetched starting post via API', ['host' => $matches[2], 'topic' => $matches[1]]); + Logger::info('Fetched starting post via API (message-id mode)', ['host' => $matches[2], 'topic' => $matches[1]]); return; } @@ -70,10 +106,11 @@ function discourse_email_getmessage(App $a, &$message) if (empty($message['item']['plink']) || !preg_match('=(http.*)/t/.*/(.*\d)/(.*\d)=', $message['item']['plink'], $matches)) { Logger::info('This is no Discourse post'); + return; } if (discourse_fetch_topic_from_api($message, $matches[1], $matches[2], $matches[3])) { - Logger::info('Fetched post from via API', ['host' => $matches[1], 'topic' => $matches[2], 'id' => $matches[3]]); + Logger::info('Fetched post via API (plink mode)', ['host' => $matches[1], 'topic' => $matches[2], 'id' => $matches[3]]); return; }