Fix coding standards issues

This commit is contained in:
fabrixxm 2017-04-14 09:13:19 +02:00
parent c91b574f3a
commit 41da664692

View file

@ -6,18 +6,18 @@
* Author: Fabio Comuni <http://kirgroup.com/profile/fabrixxm>
*/
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() {
@ -26,7 +26,7 @@ function securemail_install() {
register_hook('emailer_send_prepare', 'addon/securemail/securemail.php', 'securemail_emailer_send_prepare');
logger("installed securemail");
logger('installed securemail');
}
function securemail_uninstall() {
@ -35,11 +35,20 @@ function securemail_uninstall() {
unregister_hook('emailer_send_prepare', 'addon/securemail/securemail.php', 'securemail_emailer_send_prepare');
logger("removed securemail");
logger('removed securemail');
}
function securemail_settings(&$a,&$s){
/**
* @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;
}
@ -47,21 +56,28 @@ function securemail_settings(&$a,&$s){
$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){
/**
* @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;
@ -86,8 +102,8 @@ function securemail_settings_post(&$a, &$b){
$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(),
@ -108,15 +124,25 @@ function securemail_settings_post(&$a, &$b){
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;
}
@ -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) {