prepare ajax
This commit is contained in:
parent
6d458f8fa4
commit
7d153816f9
2 changed files with 109 additions and 0 deletions
26
comments.php
26
comments.php
|
|
@ -96,6 +96,7 @@ class CommentsPlugin extends Plugin
|
|||
|
||||
if ($this->enable) {
|
||||
$this->enable([
|
||||
'onPageInitialized' => ['onPageInitialized', 0],
|
||||
'onFormProcessed' => ['onFormProcessed', 0],
|
||||
'onFormPageHeaderProcessed' => ['onFormPageHeaderProcessed', 0],
|
||||
'onTwigSiteVariables' => ['onTwigSiteVariables', 0]
|
||||
|
|
@ -150,6 +151,31 @@ class CommentsPlugin extends Plugin
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle ajax call.
|
||||
*/
|
||||
public function onPageInitialized()
|
||||
{
|
||||
// initialize with page settings (post-cache)
|
||||
// if (!$this->isAdmin() && isset($this->grav['page']->header()->{'star-ratings'})) {
|
||||
// // if not in admin merge potential page-level configs
|
||||
// $this->config->set('plugins.star-ratings', $this->mergeConfig($page));
|
||||
// }
|
||||
$this->callback = 'nested-comments';
|
||||
// $this->callback = $this->config->get('plugins.star-ratings.callback');
|
||||
// $this->total_stars = $this->config->get('plugins.star-ratings.total_stars');
|
||||
// $this->only_full_stars = $this->config->get('plugins.star-ratings.only_full_stars');
|
||||
|
||||
// Process vote if required
|
||||
if ($this->callback === $this->grav['uri']->path()) {
|
||||
// try to add the vote
|
||||
$result = $this->addVote();
|
||||
echo json_encode(['status' => $result[0], 'message' => $result[1], 'data' => ['score' => $result[2][0], 'count' => $result[2][1]]]);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle form processing instructions.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue