Skip to content

Commit

Permalink
Refactored some code for Moodle coding guidelines compliance.
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-milette committed Apr 26, 2024
1 parent fe80365 commit 8c4aa99
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 54 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 28 additions & 5 deletions classes/local_contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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 (
Expand All @@ -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? ;-) .
}
Expand Down
87 changes: 38 additions & 49 deletions lang/en/local_contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = '
<p>Dear [fromname],</p>
<p>Thank you for contacting us. If required, we will be in touch with you very soon.</p>
<p>Regards,</p>
<p>[supportname]<br>
[sitefullname]<br>
<a href="[siteurl]">[siteurl]</a></p>
';
$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'] = '<hr>
<p><strong>Additional User Information</strong></p>
<ul>
Expand All @@ -56,21 +53,30 @@
<li><strong>Web Form:</strong> <a href="[http_referer]">[http_referer]</a></li>
</ul>
';
$string['confirmationemail'] = '
<p>Dear [fromname],</p>
<p>Thank you for contacting us. If required, we will be in touch with you very soon.</p>
<p>Regards,</p>
<p>[supportname]<br>
[sitefullname]<br>
<a href="[siteurl]">[siteurl]</a></p>
';
$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 <strong>Email subject prefix text</strong> 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 <strong>must</strong>:<br>
<ul>
<li>Ensure that the {recaptcha} tag is included in all forms processed by Contact Form for Moodle.</li>
<li>Ensure that the <a href="https://moodle.org/plugins/filter_filtercodes">FilterCodes plugin</a> is installed and enabled.</li>
</ul>';
$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:
Expand All @@ -86,22 +92,5 @@
science|thomas.edison@example.com|Mr. Edison
philosophy|aristotle@example.com|Aristotle
</pre>';

$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 <strong>Email subject prefix text</strong> 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 <strong>must</strong>:<br>
<ul>
<li>Ensure that the {recaptcha} tag is included in all forms processed by Contact Form for Moodle.</li>
<li>Ensure that the <a href="https://moodle.org/plugins/filter_filtercodes">FilterCodes plugin</a> is installed and enabled.</li>
</ul>';

$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.';
1 change: 1 addition & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<rule ref="moodle"/>
<exclude-pattern>thirdparty</exclude-pattern>
<exclude-pattern>vendor</exclude-pattern>
<exclude-pattern>test.php</exclude-pattern>
</ruleset>

0 comments on commit 8c4aa99

Please sign in to comment.