-function securemail_uninstall() {
- unregister_hook('plugin_settings', 'addon/securemail/securemail.php', 'securemail_settings');
- unregister_hook('plugin_settings_post', 'addon/securemail/securemail.php', 'securemail_settings_post');
-
- unregister_hook('emailer_send_prepare', 'addon/securemail/securemail.php', 'securemail_emailer_send_prepare');
-
- logger("removed securemail");
-}
-
-
-function securemail_settings(&$a,&$s){
- if(! local_user()) {
- return;
- }
-
- $enable = intval(get_pconfig(local_user(),'securemail','enable'));
- $publickey = get_pconfig(local_user(),'securemail','pkey');
-
- $t = get_markup_template( "admin.tpl", "addon/securemail/" );
-
- $s = replace_macros($t, array(
- '$title' => t('"Secure Mail" Settings'),
- '$submit' => t('Save Settings'),
- '$test' => t('Save and send test'), //NOTE: update also in 'post'
- '$enable' => array('securemail-enable', t('Enable Secure Mail'), $enable, ""),
- '$publickey' => array('securemail-pkey', t('Public key'), $publickey, t("Your public PGP key, ascii armored format"), "rows='10'")
- ));
-
-
-
- return;
-}
-function securemail_settings_post(&$a, &$b){
-
- if(! local_user()) {
- return;
- }
-
- if($_POST['securemail-submit']) {
- set_pconfig(local_user(),'securemail','pkey',trim($_POST['securemail-pkey']));
- $enable = ((x($_POST,'securemail-enable')) ? 1 : 0);
- set_pconfig(local_user(),'securemail','enable', $enable);
- info( t('Secure Mail Settings saved.') . EOL);
-
- if ($_POST['securemail-submit'] == t('Save and send test')) {
- $sitename = $a->config['sitename'];
-
- $hostname = $a->get_hostname();
- if (strpos($hostname, ':')){
- $hostname = substr($hostname, 0, strpos($hostname, ':'));
- }
-
- $sender_email = $a->config['sender_email'];
- if (empty($sender_email)){
- $sender_email = 'noreply@'.$hostname;
- }
-
- $subject = "Friendica - Secure Mail - Test";
- $message = "This is a test message from your Friendica Secure Mail addon.\n\nBye!";
-
- $params = array(
- 'uid' => local_user(),
- 'fromName' => $sitename,
- 'fromEmail' => $sender_email,
- 'toEmail' => $a->user['email'],
- 'messageSubject' => $subject,
- 'htmlVersion' => "<p>{$message}</p>",
- 'textVersion' => $message,
- );
-
- // enable addon for test
- set_pconfig(local_user(),'securemail','enable', 1);
-
- $res = Emailer::send($params);
-
- // revert to saved value
- set_pconfig(local_user(),'securemail','enable', $enable);
-
- if ($res) {
- info( t("Test email sent") . EOL);
- } else {
- notice( t("There was an error sending the test email") .EOL);
- }
- }
- }
+/**
+ * @brief Build user settings form
+ *
+ * @link https://github.com/friendica/friendica/blob/develop/doc/Addons.md#addon_settings 'addon_settings' hook
+ *
+ * @param App $a App instance
+ * @param string $s output html
+ *
+ * @see App
+ */
+function securemail_settings(App &$a, &$s)
+{
+ if (!local_user()) {
+ return;
+ }
+
+ $enable = intval(DI::pConfig()->get(local_user(), 'securemail', 'enable'));
+ $publickey = DI::pConfig()->get(local_user(), 'securemail', 'pkey');
+
+ $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/securemail/');
+
+ $s .= Renderer::replaceMacros($t, [
+ '$title' => DI::l10n()->t('"Secure Mail" Settings'),
+ '$submit' => DI::l10n()->t('Save Settings'),
+ '$test' => DI::l10n()->t('Save and send test'), //NOTE: update also in 'post'
+ '$enable' => ['securemail-enable', DI::l10n()->t('Enable Secure Mail'), $enable, ''],
+ '$publickey' => ['securemail-pkey', DI::l10n()->t('Public key'), $publickey, DI::l10n()->t('Your public PGP key, ascii armored format'), 'rows="10"']
+ ]);