-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added option to send email notifications when new comments are added
- Loading branch information
1 parent
8d51c21
commit 05083f7
Showing
7 changed files
with
161 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ Zend Framework 2 module for drop-in self-hosted comments. | |
), | ||
``` | ||
|
||
*** | ||
|
||
#### Usage | ||
|
||
In your views use the `rbComment` helper to display the count, the list and a form for adding new comments. Invoke it | ||
|
@@ -38,6 +40,8 @@ The `$theme` parameter is used to specify the theme of the comments box (if none | |
Currently, the module is designed to allow only one comment box per page, as it uses | ||
the page uri to identify a thread. | ||
|
||
*** | ||
|
||
#### Themes | ||
|
||
The module comes with 2 themes for now. To implement new ones create a new partial using | ||
|
@@ -54,6 +58,8 @@ Basic theme with no external dependencies. Contains the minimum styling to make | |
This theme requires the [UIkit](http://www.getuikit.com/) CSS framework. If you use it in your project this theme | ||
will make your comments box look awesome. | ||
|
||
*** | ||
|
||
#### Configuration | ||
The default configuration of the module can be found in the file `config/module.config.php`. | ||
To override the defaults, add your values under the `rb_comment` key in the `config/autoload/local.php` file | ||
|
@@ -69,6 +75,47 @@ visible. If 0 they will not be shown. This is useful for moderation. | |
This array contains the translations for the strings used in the comments box. To change or translate to another language | ||
override these values with your own. | ||
|
||
This array contains email notifications parameters | ||
```php | ||
'email' => array( | ||
/** | ||
* Send email notifications. | ||
*/ | ||
'notify' => false, | ||
/** | ||
* Email addresses where to send the notification. | ||
*/ | ||
'to' => array(), | ||
/** | ||
* From header. Usually something like [email protected] | ||
*/ | ||
'from' => '', | ||
/** | ||
* Subject of the notification email. | ||
*/ | ||
'subject' => 'New Comment', | ||
/** | ||
* Text of the comment link. | ||
*/ | ||
'context_link_text' => 'See this comment in context', | ||
), | ||
``` | ||
For sending the emails the module uses a service factory called `RbComment\Mailer`. As a default it configures a sendmail transport. This should be changed in production and customized to your needs (probably with smtp). To do this rewrite the service factory in your `config/autoload/global.php` file. | ||
```php | ||
'service_manager' => array( | ||
'factories' => array( | ||
/** | ||
* Placeholder transport config. Do not use this in production. | ||
* Replace with smtp. | ||
*/ | ||
'RbComment\Mailer' => function () { | ||
return new Zend\Mail\Transport\Sendmail(); | ||
}, | ||
), | ||
), | ||
``` | ||
*** | ||
#### Preview | ||
|
||
![Preview](demo/preview.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,11 @@ | |
'RbComment\Controller\Comment' => 'RbComment\Controller\CommentController', | ||
), | ||
), | ||
'controller_plugins' => array( | ||
'invokables' => array( | ||
'rbMailer' => 'RbComment\Mvc\Controller\Plugin\Mailer', | ||
) | ||
), | ||
'view_helpers' => array( | ||
'invokables' => array( | ||
'rbComment' => 'RbComment\View\Helper\Comment', | ||
|
@@ -33,7 +38,21 @@ | |
'rbcomment/theme/default' => __DIR__ . '/../view/theme/default.phtml', | ||
), | ||
), | ||
'service_manager' => array( | ||
'factories' => array( | ||
/** | ||
* Placeholder transport config. Do not use this in production. | ||
* Replace with smtp. | ||
*/ | ||
'RbComment\Mailer' => function () { | ||
return new Zend\Mail\Transport\Sendmail(); | ||
}, | ||
), | ||
), | ||
'rb_comment' => array( | ||
/** | ||
* Default visibility of the comments. | ||
*/ | ||
'default_visibility' => 1, | ||
'strings' => array( | ||
'author' => 'Author', | ||
|
@@ -43,5 +62,27 @@ | |
'comments' => 'Comments', | ||
'required' => 'All fields are required. Contact info will not be published.', | ||
), | ||
'email' => array( | ||
/** | ||
* Send email notifications. | ||
*/ | ||
'notify' => false, | ||
/** | ||
* Email addresses where to send the notification. | ||
*/ | ||
'to' => array(), | ||
/** | ||
* From header. Usually something like [email protected] | ||
*/ | ||
'from' => '', | ||
/** | ||
* Subject of the notification email. | ||
*/ | ||
'subject' => 'New Comment', | ||
/** | ||
* Text of the comment link. | ||
*/ | ||
'context_link_text' => 'See this comment in context', | ||
), | ||
), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace RbComment\Mvc\Controller\Plugin; | ||
|
||
use Zend\Mail\Message; | ||
use Zend\Mime\Part as MimePart; | ||
use Zend\Mime\Message as MimeMessage; | ||
use Zend\Mvc\Controller\Plugin\AbstractPlugin; | ||
use Zend\ServiceManager\ServiceLocatorInterface; | ||
use Zend\ServiceManager\ServiceLocatorAwareInterface; | ||
|
||
class Mailer extends AbstractPlugin implements ServiceLocatorAwareInterface | ||
{ | ||
private $serviceLocator; | ||
|
||
public function setServiceLocator(ServiceLocatorInterface $serviceLocator) | ||
{ | ||
$this->serviceLocator = $serviceLocator; | ||
return $this; | ||
} | ||
|
||
public function getServiceLocator() | ||
{ | ||
return $this->serviceLocator; | ||
} | ||
|
||
public function __invoke($comment) | ||
{ | ||
$serviceManager = $this->getServiceLocator()->getServiceLocator(); | ||
$viewHelperManager = $serviceManager->get('viewhelpermanager'); | ||
$serverUrlHelper = $viewHelperManager->get('serverUrl'); | ||
|
||
$mailerService = $serviceManager->get('RbComment\Mailer'); | ||
|
||
$config = $serviceManager->get('Config'); | ||
$mailerConfig = $config['rb_comment']['email']; | ||
|
||
$htmlContent = $comment->content; | ||
$htmlContent .= '<br><br>'; | ||
$htmlContent .= '<a href="' . $serverUrlHelper() . $comment->uri . '#rbcomment-' . $comment->id . '">' . | ||
$mailerConfig['context_link_text'] . | ||
'</a>'; | ||
|
||
$html = new MimePart($htmlContent); | ||
$html->type = "text/html"; | ||
|
||
$body = new MimeMessage(); | ||
$body->setParts(array($html)); | ||
|
||
$message = new Message(); | ||
$message->addFrom($mailerConfig['from']) | ||
->setSubject($mailerConfig['subject']) | ||
->setBody($body); | ||
|
||
foreach($mailerConfig['to'] as $mConfig) { | ||
$message->addTo($mConfig); | ||
} | ||
|
||
$mailerService->send($message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters