Skip to content

Commit

Permalink
Contact 1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed Dec 21, 2013
1 parent af0c8d9 commit 14c7490
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 1 deletion.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
monstra-cms-contact
Contact
===================

Simple contact plugin for Monstra CMS

Usage:

Shordcode for content
```
{contact recipient="[email protected]"}
```

Code for templates
```
<?php Contact::display('[email protected]'); ?>
```
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Contact 1.1.1, 2013-12-22
------------------------
- PHPMailer used
- PSR coding fixes
96 changes: 96 additions & 0 deletions contact.plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

/**
* Contact plugin
*
* @package Monstra
* @subpackage Plugins
* @author Romanenko Sergey / Awilum
* @copyright 2012 - 2014 Romanenko Sergey / Awilum
* @version 1.1.1
*
*/

// Register plugin
Plugin::register( __FILE__,
__('Contact', 'contact'),
__('Contact plugin for Monstra', 'contact'),
'1.1.1',
'Awilum',
'http://monstra.org/');

/**
* Shorcode: {contact recipient="[email protected]"}
*/
Shortcode::add('contact', 'Contact::_shorcode');

/**
* Usage: <?php Contact::display('[email protected]'); ?>
*/
class Contact
{
public static function _shorcode($attributes)
{
return Contact::form($attributes['recipient']);
}

public static function form($recipient)
{
$name = Request::post('contact_name');
$email = Request::post('contact_email');
$body = Request::post('contact_body');

$errors = array();

if (Request::post('contact_submit')) {

if (Security::check(Request::post('csrf'))) {

if (Request::post('contact_name') == '' || Request::post('contact_email') == '' || Request::post('contact_body') == '') {
$errors['contact_empty_fields'] = __('Empty required fields!', 'contact');
}

if ( ! Valid::email(Request::post('contact_email'))) {
$errors['contact_email_not_valid'] = __('Email address is not valid!', 'contact');
}

if (Option::get('captcha_installed') == 'true' && ! CryptCaptcha::check(Request::post('answer'))) {
$errors['users_captcha_wrong'] = __('Captcha code is wrong', 'users');
}

if (count($errors) == 0) {

$mail = new PHPMailer();
$mail->SetFrom($email);
$mail->AddReplyTo($email);
$mail->AddAddress($recipient);
$mail->Subject = $name;
$mail->Body = $body;

if ($mail->Send()) {
Notification::set('success', __('A letter has been sent!', 'contact'));
Request::redirect(Page::url());
} else {
Notification::set('error', __('A Letter was not sent!', 'contact'));
}

}

} else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); }

}

return View::factory('contact/views/frontend/form')
->assign('name', $name)
->assign('email', $email)
->assign('body', $body)
->assign('errors', $errors)
->render();
}

public static function display($recipient)
{
echo Contact::form($recipient);
}

}
11 changes: 11 additions & 0 deletions install/contact.manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<root>
<plugin_location>plugins/contact/contact.plugin.php</plugin_location>
<plugin_status>active</plugin_status>
<plugin_priority>15</plugin_priority>
<plugin_name>Contact</plugin_name>
<plugin_description>Contact plugin for Monstra</plugin_description>
<plugin_version>1.1.0</plugin_version>
<plugin_author>Awilum</plugin_author>
<plugin_author_uri>http://monstra.org/</plugin_author_uri>
</root>
17 changes: 17 additions & 0 deletions languages/en.lang.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

return array(
'contact' => array(
'Contact' => 'Contact',
'Contact plugin for Monstra' => 'Contact plugin for Monstra',
'Name' => 'Name',
'Email' => 'Email',
'Message' => 'Message',
'Send' => 'Send',
'Empty required fields!' => 'Empty required fields!',
'Email address is not valid!' => 'Email address is not valid!',
'A letter has been sent!' => 'A letter has been sent!',
'A Letter was not sent!' => 'A Letter was not sent!',
'Wrong captcha!' => 'Wrong captcha!',
),
);
17 changes: 17 additions & 0 deletions languages/ru.lang.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

return array(
'contact' => array(
'Contact' => 'Контакт',
'Contact plugin for Monstra' => 'Плагин контакт для Монстра!',
'Name' => 'Имя',
'Email' => 'Емейл',
'Message' => 'Сообщение',
'Send' => 'Отправить',
'Empty required fields!' => 'Пустые поля обязательные для заполнения!',
'Email address is not valid!' => 'Адрес электронной почты не действителен!',
'A letter has been sent!' => 'Письмо было отправлено!',
'A Letter was not sent!' => 'Письмо не было отправлено!',
'Wrong captcha!' => 'Неправильная капча!',
),
);
28 changes: 28 additions & 0 deletions views/frontend/form.view.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php if (Notification::get('success')) Alert::success(Notification::get('success')); ?>
<?php if (Notification::get('error')) Alert::error(Notification::get('error')); ?>
<br />
<form method="post">
<?php echo (Form::hidden('csrf', Security::token())); ?>
<label><?php echo __('Name', 'contact'); ?></label>
<input type="text" name="contact_name" class="input-xlarge" value="<?php echo $name; ?>" /><br />
<label><?php echo __('Email', 'contact'); ?></label>
<input type="text" name="contact_email" class="input-xlarge" value="<?php echo $email; ?>" /><br />
<label><?php echo __('Message', 'contact'); ?></label>
<textarea class="input-xxlarge" rows="10" name="contact_body"><?php echo $body; ?></textarea><br /><br />

<?php if (Option::get('captcha_installed') == 'true') { ?>
<label><?php echo __('Captcha', 'users'); ?><label>
<input type="text" name="answer"><?php if (isset($errors['captcha_wrong'])) echo Html::nbsp(3).'<span class="error">'.$errors['captcha_wrong'].'</span>'; ?>
<?php CryptCaptcha::draw(); ?>
<?php } ?>

<br />
<?php if (count($errors) > 0) { ?>
<ul>
<?php foreach ($errors as $error) { ?>
<li><?php echo $error; ?></li>
<?php } ?>
</ul>
<?php } ?>
<input type="submit" class="btn" value="<?php echo __('Send', 'contact'); ?>" name="contact_submit"/>
</form>

0 comments on commit 14c7490

Please sign in to comment.