From 41da6646929d5c0a1ff982ff3731374014691225 Mon Sep 17 00:00:00 2001 From: fabrixxm Date: Fri, 14 Apr 2017 09:13:19 +0200 Subject: [PATCH] Fix coding standards issues --- securemail/securemail.php | 115 ++++++++++++++++++++++++-------------- 1 file changed, 73 insertions(+), 42 deletions(-) diff --git a/securemail/securemail.php b/securemail/securemail.php index c4dc6c93..b5275e08 100644 --- a/securemail/securemail.php +++ b/securemail/securemail.php @@ -6,88 +6,104 @@ * Author: Fabio Comuni */ -require_once "include/Emailer.php"; +require_once 'include/Emailer.php'; /* because the fraking openpgp-php is in composer, require libs in composer * and then don't use autoloader to load classes... */ -$path = __DIR__."/vendor/phpseclib/phpseclib/phpseclib/"; +$path = __DIR__ . '/vendor/phpseclib/phpseclib/phpseclib/'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); /* so, we don't use the autoloader and include what we need */ -$path = __DIR__."/vendor/singpolyma/openpgp-php/lib"; +$path = __DIR__ . '/vendor/singpolyma/openpgp-php/lib'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); -require_once "openpgp.php"; -require_once "openpgp_crypt_symmetric.php"; +require_once 'openpgp.php'; +require_once 'openpgp_crypt_symmetric.php'; function securemail_install() { register_hook('plugin_settings', 'addon/securemail/securemail.php', 'securemail_settings'); register_hook('plugin_settings_post', 'addon/securemail/securemail.php', 'securemail_settings_post'); - register_hook('emailer_send_prepare', 'addon/securemail/securemail.php', 'securemail_emailer_send_prepare'); + register_hook('emailer_send_prepare', 'addon/securemail/securemail.php', 'securemail_emailer_send_prepare'); - logger("installed securemail"); + logger('installed securemail'); } 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'); + unregister_hook('emailer_send_prepare', 'addon/securemail/securemail.php', 'securemail_emailer_send_prepare'); - logger("removed securemail"); + logger('removed securemail'); } - -function securemail_settings(&$a,&$s){ - if(! local_user()) { +/** + * @brief Build user settings form + * + * @link https://github.com/friendica/friendica/blob/develop/doc/Plugins.md#plugin_settings 'plugin_settings' hook + * + * @param App $a App instance + * @param string $s output html + * + * @see App + */ +function securemail_settings(App &$a, string &$s){ + if (!local_user()) { return; } - $enable = intval(get_pconfig(local_user(),'securemail','enable')); - $publickey = get_pconfig(local_user(),'securemail','pkey'); + $enable = intval(get_pconfig(local_user(), 'securemail', 'enable')); + $publickey = get_pconfig(local_user(), 'securemail', 'pkey'); - $t = get_markup_template( "admin.tpl", "addon/securemail/" ); + $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'") + '$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()) { +/** + * @brief Handle data from user settings form + * + * @link https://github.com/friendica/friendica/blob/develop/doc/Plugins.md#plugin_settings_post 'plugin_settings_post' hook + * + * @param App $a App instance + * @param array $b hook data + * + * @see App + */ +function securemail_settings_post(App &$a, array &$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']) { + 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, ':')){ + if (strpos($hostname, ':')) { $hostname = substr($hostname, 0, strpos($hostname, ':')); } $sender_email = $a->config['sender_email']; - if (empty($sender_email)){ - $sender_email = 'noreply@'.$hostname; + 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!"; + $subject = 'Friendica - Secure Mail - Test'; + $message = 'This is a test message from your Friendica Secure Mail addon.\n\nBye!'; $params = array( 'uid' => local_user(), @@ -100,35 +116,45 @@ function securemail_settings_post(&$a, &$b){ ); // enable addon for test - set_pconfig(local_user(),'securemail','enable', 1); + set_pconfig(local_user(), 'securemail', 'enable', 1); $res = Emailer::send($params); // revert to saved value - set_pconfig(local_user(),'securemail','enable', $enable); + set_pconfig(local_user(), 'securemail', 'enable', $enable); if ($res) { - info( t("Test email sent") . EOL); + info(t('Test email sent') . EOL); } else { - notice( t("There was an error sending the test email") .EOL); + notice(t('There was an error sending the test email') . EOL); } } } } -function securemail_emailer_send_prepare(&$a, &$b) { +/** + * @brief Encrypt notification emails text + * + * @link https://github.com/friendica/friendica/blob/develop/doc/Plugins.md#emailer_send_prepare 'emailer_send_prepare' hook + * + * @param App $a App instance + * @param array $b hook data + * + * @see App + */ +function securemail_emailer_send_prepare(App &$a, array &$b) { if (!x($b,'uid')) { return; } $uid = $b['uid']; - $enable_checked = get_pconfig($uid,'securemail','enable'); + $enable_checked = get_pconfig($uid, 'securemail', 'enable'); if (!$enable_checked) { return; } - $public_key_ascii = get_pconfig($uid,'securemail','pkey'); + $public_key_ascii = get_pconfig($uid, 'securemail', 'pkey'); preg_match('/-----BEGIN ([A-Za-z ]+)-----/', $public_key_ascii, $matches); $marker = (empty($matches[1])) ? 'MESSAGE' : $matches[1]; @@ -141,7 +167,12 @@ function securemail_emailer_send_prepare(&$a, &$b) { 'filename' => 'encrypted.gpg' )); $encrypted = OpenPGP_Crypt_Symmetric::encrypt($key, new OpenPGP_Message(array($data))); - $armored_encrypted = wordwrap(OpenPGP::enarmor($encrypted->to_bytes(), "PGP MESSAGE"), 64, "\n", true); + $armored_encrypted = wordwrap( + OpenPGP::enarmor($encrypted->to_bytes(), 'PGP MESSAGE'), + 64, + '\n', + true + ); $b['textVersion'] = $armored_encrypted; $b['htmlVersion'] = null; @@ -153,7 +184,7 @@ function securemail_emailer_send_prepare(&$a, &$b) { function securemail_autoloader() { - $loader = require dirname(dirname(__DIR__))."/vendor/autoload.php"; + $loader = require dirname(dirname(__DIR__)) . '/vendor/autoload.php'; $map = require __DIR__ . '/vendor/composer/autoload_namespaces.php'; foreach ($map as $namespace => $path) { -- 2.39.5