]> git.mxchange.org Git - friendica-addons.git/blobdiff - discourse/discourse.php
fix $_POST variable
[friendica-addons.git] / discourse / discourse.php
index 2fce970daf957e4916ebe76795a499aa86f74be5..f52edb9fb74597294cc1aa9127aead42e850e6ba 100644 (file)
@@ -7,20 +7,18 @@
  * Author: Michael Vogel <http://pirati.ca/profile/heluecht>
  *
  */
+
 use Friendica\App;
+use Friendica\Content\Text\Markdown;
 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\Core\Renderer;
 use Friendica\Database\DBA;
+use Friendica\DI;
 use Friendica\Model\Contact;
-use Friendica\Util\XML;
-use Friendica\Content\Text\Markdown;
-use Friendica\Util\Network;
+use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Strings;
-Use Friendica\Util\DateTimeFormat;
 
 /* Todo:
  * - Obtaining API tokens to be able to read non public posts as well
@@ -44,26 +42,14 @@ function discourse_settings(App $a, &$s)
                return;
        }
 
-       $enabled = intval(PConfig::get(local_user(), 'discourse', 'enabled'));
-       $css = ($enabled ? '' : '-disabled');
-
-       $s .= '<span id="settings_discourse_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_discourse_expanded\'); openClose(\'settings_discourse_inflated\');">';
-       $s .= '<img class="connector' . $css . '" src="images/discourse.png" /><h3 class="connector">' . L10n::t('Discourse') . '</h3>';
-       $s .= '</span>';
-       $s .= '<div id="settings_discourse_expanded" class="settings-block" style="display: none;">';
-       $s .= '<span class="fakelink" onclick="openClose(\'settings_discourse_expanded\'); openClose(\'settings_discourse_inflated\');">';
-       $s .= '<img class="connector' . $css . '" src="images/discourse.png" /><h3 class="connector">' . L10n::t('Discourse') . '</h3>';
-       $s .= '</span>';
+       $enabled = intval(DI::pConfig()->get(local_user(), 'discourse', 'enabled'));
 
-       $field_checkbox = Renderer::getMarkupTemplate('field_checkbox.tpl');
-
-       $s .= Renderer::replaceMacros($field_checkbox, [
-               '$field' => ['enabled', L10n::t('Enable processing of Discourse mailing list mails'), $enabled, 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.')]
+       $t = Renderer::getMarkupTemplate('settings.tpl', 'addon/discourse/');
+       $s .= Renderer::replaceMacros($t, [
+               '$title'   => DI::l10n()->t('Discourse'),
+               '$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'),
        ]);
-
-       $s .= '<div class="clear"></div>';
-       $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="discourse-submit" class="settings-submit" value="' . L10n::t('Save Settings') . '" /></div>';
-       $s .= '</div>';
 }
 
 function discourse_settings_post(App $a)
@@ -72,7 +58,7 @@ function discourse_settings_post(App $a)
                 return;
         }
 
-       PConfig::set(local_user(), 'discourse', 'enabled', intval($_POST['enabled']));
+       DI::pConfig()->set(local_user(), 'discourse', 'enabled', intval($_POST['enabled']));
 }
 
 function discourse_email_getmessage(App $a, &$message)
@@ -81,7 +67,7 @@ function discourse_email_getmessage(App $a, &$message)
                return;
        }
 
-       if (!PConfig::get($message['item']['uid'], 'discourse', 'enabled')) {
+       if (!DI::pConfig()->get($message['item']['uid'], 'discourse', 'enabled')) {
                return;
        }
 
@@ -120,7 +106,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']);
        }
 }
@@ -128,7 +114,7 @@ function discourse_email_getmessage(App $a, &$message)
 function discourse_fetch_post($host, $topic, $pid)
 {
        $url = $host . '/t/' . $topic . '/' . $pid . '.json';
-       $curlResult = Network::curl($url);
+       $curlResult = DI::httpRequest()->get($url);
        if (!$curlResult->isSuccess()) {
                Logger::info('No success', ['url' => $url]);
                return false;
@@ -165,7 +151,7 @@ function discourse_fetch_post_from_api(&$message, $post, $host)
 {
        $hostaddr = 'https://' . $host;
        $url = $hostaddr . '/posts/' . $post . '.json';
-       $curlResult = Network::curl($url);
+       $curlResult = DI::httpRequest()->get($url);
        if (!$curlResult->isSuccess()) {
                return false;
        }
@@ -212,12 +198,12 @@ function discourse_get_user($post, $hostaddr)
        $contact['nurl'] = Strings::normaliseLink($contact['url']);
        $contact['baseurl'] = $hostaddr;
        Logger::info('Contact', $contact);
-       $contact['id'] = Contact::getIdForURL($contact['url'], 0, true, $contact);
+       $contact['id'] = Contact::getIdForURL($contact['url'], 0, false, $contact);
         if (!empty($contact['id'])) {
                $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;
        }
 
@@ -282,7 +268,7 @@ function discourse_get_html($message)
        $profile = discourse_get_profile($xpath);
        if (!empty($profile['url'])) {
                Logger::info('Found profile', $profile);
-               $message['item']['author-id'] = Contact::getIdForURL($profile['url'], 0, true, $profile);
+               $message['item']['author-id'] = Contact::getIdForURL($profile['url'], 0, false, $profile);
                $message['item']['author-link'] = $profile['url'];
                $message['item']['author-name'] = $profile['name'];
                $message['item']['author-avatar'] = $profile['photo'];