Skip to content

Commit

Permalink
Added event PostViewed, dispatch this event when a post is viewed
Browse files Browse the repository at this point in the history
  • Loading branch information
karsasmus committed Mar 30, 2017
1 parent f3314b7 commit 68ec3ba
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/source/classes/Controller/ThemeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
Leafpub\Session,
Leafpub\Models\Setting,
Leafpub\Models\Tag,
Leafpub\Models\User;
Leafpub\Models\User,
Leafpub\Events\Post\PostViewed;

/**
* ThemeController
Expand Down Expand Up @@ -129,9 +130,13 @@ public function post($request, $response, $args) {
'preview' => Session::isAuthenticated() && isset($request->getParams()['preview'])
]);

return $html === false ?
$this->notFound($request, $response) :
if ($html === false){
return $this->notFound($request, $response);
} else {
$ev = new PostViewed(['post' => $args['post'], 'request' => $request]);
\Leafpub\Leafpub::dispatchEvent(PostViewed::NAME, $ev);
$response->write($html);
}
}

/**
Expand Down
17 changes: 17 additions & 0 deletions app/source/classes/Events/Post/PostViewed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Leafpub: Simple, beautiful publishing. (https://leafpub.org)
*
* @link https://github.com/Leafpub/leafpub
* @copyright Copyright (c) 2016 Leafpub Team
* @license https://github.com/Leafpub/leafpub/blob/master/LICENSE.md (GPL License)
*/
namespace Leafpub\Events\Post;

use Leafpub\Events\LeafpubEvent;

class PostViewed extends LeafpubEvent {
const NAME = 'post.viewed';
}

?>

0 comments on commit 68ec3ba

Please sign in to comment.