Enable comments plugin only on its route

This commit is contained in:
Flavio Copes 2015-10-08 17:29:48 +02:00
parent 5790ac019e
commit 61677d06d4
1 changed files with 9 additions and 2 deletions

View File

@ -13,7 +13,7 @@ use Symfony\Component\Yaml\Yaml;
class CommentsPlugin extends Plugin class CommentsPlugin extends Plugin
{ {
protected $route = 'comments'; protected $route = '/admin/comments';
/** /**
* @return array * @return array
@ -46,6 +46,10 @@ class CommentsPlugin extends Plugin
} }
} else { } else {
/** @var Uri $uri */
$uri = $this->grav['uri'];
//Admin //Admin
$this->enable([ $this->enable([
'onTwigTemplatePaths' => ['onTwigAdminTemplatePaths', 0], 'onTwigTemplatePaths' => ['onTwigAdminTemplatePaths', 0],
@ -53,6 +57,10 @@ class CommentsPlugin extends Plugin
'onDataTypeExcludeFromDataManagerPluginHook' => ['onDataTypeExcludeFromDataManagerPluginHook', 0], 'onDataTypeExcludeFromDataManagerPluginHook' => ['onDataTypeExcludeFromDataManagerPluginHook', 0],
]); ]);
if (strpos($uri->path(), $this->route) === false) {
return;
}
$page = $this->grav['uri']->param('page'); $page = $this->grav['uri']->param('page');
$comments = $this->getLastComments($page); $comments = $this->getLastComments($page);
@ -76,7 +84,6 @@ class CommentsPlugin extends Plugin
$email = filter_var(urldecode($post['email']), FILTER_SANITIZE_STRING); $email = filter_var(urldecode($post['email']), FILTER_SANITIZE_STRING);
$title = filter_var(urldecode($post['title']), FILTER_SANITIZE_STRING); $title = filter_var(urldecode($post['title']), FILTER_SANITIZE_STRING);
if ($this->config->get('plugins.comments.use_captcha')) { if ($this->config->get('plugins.comments.use_captcha')) {
//Validate the captcha //Validate the captcha
$recaptchaResponse = filter_var(urldecode($post['recaptchaResponse']), FILTER_SANITIZE_STRING); $recaptchaResponse = filter_var(urldecode($post['recaptchaResponse']), FILTER_SANITIZE_STRING);