X-Git-Url: https://git.mxchange.org/?p=friendica-addons.git;a=blobdiff_plain;f=securemail%2Fsecuremail.php;h=68fc24ff845d0e19d9f95af9fce437fd048d1fb6;hp=c92410a6ead9f6c66f1a6236ebc5c1ea7efb0827;hb=27b60e003f92dd9f3aebbeddb34ebb905488ca82;hpb=0dce0cd8d9a9645973247665198bf2066c28c7f5 diff --git a/securemail/securemail.php b/securemail/securemail.php index c92410a6..68fc24ff 100644 --- a/securemail/securemail.php +++ b/securemail/securemail.php @@ -6,7 +6,9 @@ * Author: Fabio Comuni */ -require_once 'include/Emailer.php'; +use Friendica\App; +use Friendica\Core\PConfig; +use Friendica\Util\Emailer; /* because the fraking openpgp-php is in composer, require libs in composer * and then don't use autoloader to load classes... */ @@ -53,18 +55,18 @@ function securemail_settings(App &$a, &$s){ return; } - $enable = intval(get_pconfig(local_user(), 'securemail', 'enable')); - $publickey = get_pconfig(local_user(), 'securemail', 'pkey'); + $enable = intval(PConfig::get(local_user(), 'securemail', 'enable')); + $publickey = PConfig::get(local_user(), 'securemail', 'pkey'); $t = get_markup_template('admin.tpl', 'addon/securemail/'); - $s = replace_macros($t, array( + $s .= replace_macros($t, [ '$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"') - )); + '$enable' => ['securemail-enable', t('Enable Secure Mail'), $enable, ''], + '$publickey' => ['securemail-pkey', t('Public key'), $publickey, t('Your public PGP key, ascii armored format'), 'rows="10"'] + ]); } /** @@ -84,9 +86,9 @@ function securemail_settings_post(App &$a, array &$b){ } if ($_POST['securemail-submit']) { - set_pconfig(local_user(), 'securemail', 'pkey', trim($_POST['securemail-pkey'])); + PConfig::set(local_user(), 'securemail', 'pkey', trim($_POST['securemail-pkey'])); $enable = ((x($_POST, 'securemail-enable')) ? 1 : 0); - set_pconfig(local_user(), 'securemail', 'enable', $enable); + PConfig::set(local_user(), 'securemail', 'enable', $enable); info(t('Secure Mail Settings saved.') . EOL); if ($_POST['securemail-submit'] == t('Save and send test')) { @@ -105,7 +107,7 @@ function securemail_settings_post(App &$a, array &$b){ $subject = 'Friendica - Secure Mail - Test'; $message = 'This is a test message from your Friendica Secure Mail addon.'; - $params = array( + $params = [ 'uid' => local_user(), 'fromName' => $sitename, 'fromEmail' => $sender_email, @@ -113,15 +115,15 @@ function securemail_settings_post(App &$a, array &$b){ 'messageSubject' => $subject, 'htmlVersion' => "

{$message}

", 'textVersion' => $message, - ); + ]; // enable addon for test - set_pconfig(local_user(), 'securemail', 'enable', 1); + PConfig::set(local_user(), 'securemail', 'enable', 1); $res = Emailer::send($params); // revert to saved value - set_pconfig(local_user(), 'securemail', 'enable', $enable); + PConfig::set(local_user(), 'securemail', 'enable', $enable); if ($res) { info(t('Test email sent') . EOL); @@ -149,12 +151,12 @@ function securemail_emailer_send_prepare(App &$a, array &$b) { $uid = $b['uid']; - $enable_checked = get_pconfig($uid, 'securemail', 'enable'); + $enable_checked = PConfig::get($uid, 'securemail', 'enable'); if (!$enable_checked) { return; } - $public_key_ascii = get_pconfig($uid, 'securemail', 'pkey'); + $public_key_ascii = PConfig::get($uid, 'securemail', 'pkey'); preg_match('/-----BEGIN ([A-Za-z ]+)-----/', $public_key_ascii, $matches); $marker = (empty($matches[1])) ? 'MESSAGE' : $matches[1]; @@ -162,11 +164,11 @@ function securemail_emailer_send_prepare(App &$a, array &$b) { $key = OpenPGP_Message::parse($public_key); - $data = new OpenPGP_LiteralDataPacket($b['textVersion'], array( + $data = new OpenPGP_LiteralDataPacket($b['textVersion'], [ 'format' => 'u', 'filename' => 'encrypted.gpg' - )); - $encrypted = OpenPGP_Crypt_Symmetric::encrypt($key, new OpenPGP_Message(array($data))); + ]); + $encrypted = OpenPGP_Crypt_Symmetric::encrypt($key, new OpenPGP_Message([$data])); $armored_encrypted = wordwrap( OpenPGP::enarmor($encrypted->to_bytes(), 'PGP MESSAGE'), 64,