diff --git a/CHANGELOG.md b/CHANGELOG.md index ce96c73..88cba16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. - Added a little space between the post-submission message and the Continue button. - Smarter continue button URL logic after the form was submitted. - Contributing guidelines and bug reporting form. +- Refactored for compliance with Moodle coding guidelines. - Copyright notice to 2024. ## [1.3.1] - 2023-10-23 ### Added diff --git a/classes/local_contact.php b/classes/local_contact.php index 99d0850..610cca3 100644 --- a/classes/local_contact.php +++ b/classes/local_contact.php @@ -29,9 +29,32 @@ * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class local_contact { + /** + * The name of the sender for the message. + * + * @var string + */ public $fromname; + + /** + * The email address of the sender for the message. + * + * @var string + */ public $fromemail; + + /** + * True if the information submitted is considered to have been sent from a spambot. + * + * @var bool + */ public $isspambot; + + /** + * Error message in case there are any issues. + * + * @var string + */ public $errmsg; /** @@ -164,10 +187,10 @@ public function __construct() { // Validate against email address whitelist and blacklist. $skipdomaintest = false; - // TODO: Create a plugin setting for this list. + // TODO: MDL-0 - Create a plugin setting for this list. $whitelist = ''; // Future code: $config->whitelistemails . $whitelist = ',' . $whitelist . ','; - // TODO: Create a plugin blacklistemails setting. + // TODO: MDL-0 - Create a plugin blacklistemails setting. $blacklist = ''; // Future code: $config->blacklistemails . $blacklist = ',' . $blacklist . ','; if (!$this->isspambot && stripos($whitelist, ',' . $this->fromemail . ',') != false) { @@ -185,7 +208,7 @@ public function __construct() { // Validate against domain whitelist and blacklist... except for the nice people. if (!$skipdomaintest && !$this->isspambot) { - // TODO: Create a plugin whitelistdomains setting. + // TODO: MDL-0 - Create a plugin whitelistdomains setting. $whitelist = ''; // Future code: $config->whitelistdomains . $whitelist = ',' . $whitelist . ','; $domain = substr(strrchr($this->fromemail, '@'), 1); @@ -194,7 +217,7 @@ public function __construct() { // Ya, you check out. This email domain is gold here! $blacklist = ''; } else { - // TODO: Create a plugin blacklistdomains setting. + // TODO: MDL-0 - Create a plugin blacklistdomains setting. $blacklist = 'example.com,example.net,sample.com,test.com,specified.com'; // Future code:$config->blacklistdomains . $blacklist = ',' . $blacklist . ','; if ( @@ -208,7 +231,7 @@ public function __construct() { } } - // TODO: Test IP address against blacklist. + // TODO: MDL-0 - Test IP address against blacklist. // END: Spambot detection... Wait, got some photo ID on you? ;-) . } diff --git a/lang/en/local_contact.php b/lang/en/local_contact.php index 1edea61..3827dd4 100644 --- a/lang/en/local_contact.php +++ b/lang/en/local_contact.php @@ -25,27 +25,24 @@ defined('MOODLE_INTERNAL') || die(); -$string['pluginname'] = 'Contact Form'; -$string['privacy:metadata'] = 'The Contact Form plugin does not store any personal data about any user.'; -$string['globalhelp'] = 'Contact Form is a plugin for Moodle that allows your site to process information submitted through HTML web forms to the site\'s support email address.'; +$string['attachment'] = 'Enable file attachments'; +$string['attachment_description'] = 'When enabled, Contact Form will support one attachment. See README.md for details on how to add support for an attachment to your form.'; $string['configure'] = 'Configure this plugin'; -$string['confirmationpage'] = 'Status'; - -$string['field-name'] = 'name'; -$string['field-email'] = 'email'; -$string['field-subject'] = 'subject'; -$string['field-message'] = 'message'; - -$string['noreplyto'] = 'No reply-to'; -$string['noreplyto_description'] = 'Some SMTP servers reject emails if the from and noreply-to fields in the heading are different. Enable this option to ensure that the no-reply field matches the from address instead of the sender\'s email address.'; - +$string['confirmationemail'] = ' +

Dear [fromname],

+

Thank you for contacting us. If required, we will be in touch with you very soon.

+

Regards,

+

[supportname]
+[sitefullname]
+[siteurl]

+'; $string['confirmationmessage'] = 'Thank you for contacting us. If required, we will be in touch with you very soon.'; +$string['confirmationpage'] = 'Status'; $string['confirmationsent'] = 'An email has been sent to your address at {$a}.'; -$string['forbidden'] = 'Forbidden'; -$string['errorsendingtitle'] = 'Failed to send e-mail'; -$string['errorsending'] = 'An error occurred while sending the message. Please try again later.'; - $string['defaultsubject'] = 'New message'; +$string['duplicateemailaddresses'] = 'There are multiple users with the same email address.'; +$string['errorsending'] = 'An error occurred while sending the message. Please try again later.'; +$string['errorsendingtitle'] = 'Failed to send e-mail'; $string['extrainfo'] = '

Additional User Information

'; -$string['confirmationemail'] = ' -

Dear [fromname],

-

Thank you for contacting us. If required, we will be in touch with you very soon.

-

Regards,

-

[supportname]
-[sitefullname]
-[siteurl]

-'; +$string['field-email'] = 'email'; +$string['field-message'] = 'message'; +$string['field-name'] = 'name'; +$string['field-subject'] = 'subject'; +$string['forbidden'] = 'Forbidden'; +$string['globalhelp'] = 'Contact Form is a plugin for Moodle that allows your site to process information submitted through HTML web forms to the site\'s support email address.'; $string['lockedout'] = 'LOCKED OUT'; +$string['loginrequired'] = 'Login required'; +$string['loginrequired_description'] = 'Only allow logged-in users to submit the Contact forms. Guests are not considered to be logged-in.'; +$string['norecaptcha'] = 'No ReCAPTCHA'; +$string['norecaptcha_description'] = 'Don\'t use ReCAPTCHA with forms procesed by Contact form.'; +$string['noreplyto'] = 'No reply-to'; +$string['noreplyto_description'] = 'Some SMTP servers reject emails if the from and noreply-to fields in the heading are different. Enable this option to ensure that the no-reply field matches the from address instead of the sender\'s email address.'; +$string['nosubjectsitename'] = 'No site name in email subject field'; +$string['nosubjectsitename_description'] = 'Enable to not prefix email subject with [site name]. Does not affect Moodle\'s own Email subject prefix text setting.'; $string['notconfirmed'] = 'NOT CONFIRMED'; -$string['duplicateemailaddresses'] = 'There are multiple users with the same email address.'; - -$string['senderaddress'] = 'Custom sender'; -$string['senderaddress_description'] = 'Emails will be delivered from this email address. If this field is blank, emails will be delivered from the no-reply email address.'; - +$string['pluginname'] = 'Contact Form'; +$string['privacy:metadata'] = 'The Contact Form plugin does not store any personal data about any user.'; +$string['recapchainfo'] = 'Using ReCAPTCHA'; +$string['recapchainfo_description'] = 'ReCAPTCHA is currently enabled in Moodle. You must:
+'; $string['recipient_list'] = 'List of available recipients'; $string['recipient_list_description'] = 'You can configure a list of potential recipients here, any of which can be used in a Contact Form to specify the email recipient using a hidden text field, or in a select dropdown list to allow users to select the recipient without divulging the recipient\'s actual email address. If the list is empty, emails will be sent to the Moodle email address, either the support email address or the primary Moodle administrator. Each line must consist of a unique text alias/label, a single email address and a name, each separated by pipe characters. For example: @@ -86,22 +92,5 @@ science|thomas.edison@example.com|Mr. Edison philosophy|aristotle@example.com|Aristotle '; - -$string['loginrequired'] = 'Login required'; -$string['loginrequired_description'] = 'Only allow logged-in users to submit the Contact forms. Guests are not considered to be logged-in.'; - -$string['nosubjectsitename'] = 'No site name in email subject field'; -$string['nosubjectsitename_description'] = 'Enable to not prefix email subject with [site name]. Does not affect Moodle\'s own Email subject prefix text setting.'; - -$string['attachment'] = 'Enable file attachments'; -$string['attachment_description'] = 'When enabled, Contact Form will support one attachment. See README.md for details on how to add support for an attachment to your form.'; - -$string['recapchainfo'] = 'Using ReCAPTCHA'; -$string['recapchainfo_description'] = 'ReCAPTCHA is currently enabled in Moodle. You must:
-'; - -$string['norecaptcha'] = 'No ReCAPTCHA'; -$string['norecaptcha_description'] = 'Don\'t use ReCAPTCHA with forms procesed by Contact form.'; +$string['senderaddress'] = 'Custom sender'; +$string['senderaddress_description'] = 'Emails will be delivered from this email address. If this field is blank, emails will be delivered from the no-reply email address.'; diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 7c11221..4b57ef3 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -3,4 +3,5 @@ thirdparty vendor + test.php