This repository has been archived by the owner on Feb 2, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
669 additions
and
114 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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\NewsBundle\Action; | ||
|
||
use Sonata\NewsBundle\Model\BlogInterface; | ||
use Sonata\NewsBundle\Model\PostManagerInterface; | ||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
abstract class AbstractPostArchiveAction extends Controller | ||
{ | ||
/** | ||
* @var BlogInterface | ||
*/ | ||
private $blog; | ||
|
||
/** | ||
* @var PostManagerInterface | ||
*/ | ||
private $postManager; | ||
|
||
/** | ||
* AbstractPostArchiveAction constructor. | ||
* | ||
* @param BlogInterface $blog | ||
* @param PostManagerInterface $postManager | ||
*/ | ||
public function __construct(BlogInterface $blog, PostManagerInterface $postManager) | ||
{ | ||
$this->blog = $blog; | ||
$this->postManager = $postManager; | ||
} | ||
|
||
/** | ||
* NEXT_MAJOR: make this method protected. | ||
* | ||
* @return Response | ||
*/ | ||
final public function renderArchive(Request $request, array $criteria = [], array $parameters = []) | ||
{ | ||
$pager = $this->postManager->getPager( | ||
$criteria, | ||
$request->get('page', 1) | ||
); | ||
|
||
$parameters = array_merge([ | ||
'pager' => $pager, | ||
'blog' => $this->blog, | ||
'tag' => false, | ||
'collection' => false, | ||
'route' => $request->get('_route'), | ||
'route_parameters' => $request->get('_route_params'), | ||
], $parameters); | ||
|
||
$response = $this->render(sprintf('@SonataNews/Post/archive.%s.twig', $request->getRequestFormat()), $parameters); | ||
|
||
if ('rss' === $request->getRequestFormat()) { | ||
$response->headers->set('Content-Type', 'application/rss+xml'); | ||
} | ||
|
||
return $response; | ||
} | ||
|
||
/** | ||
* @return PostManagerInterface | ||
*/ | ||
final protected function getPostManager() | ||
{ | ||
return $this->postManager; | ||
} | ||
} |
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,53 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\NewsBundle\Action; | ||
|
||
use Sonata\ClassificationBundle\Model\CollectionManagerInterface; | ||
use Sonata\NewsBundle\Model\BlogInterface; | ||
use Sonata\NewsBundle\Model\PostManagerInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
|
||
final class CollectionPostArchiveAction extends AbstractPostArchiveAction | ||
{ | ||
/** | ||
* @var CollectionManagerInterface | ||
*/ | ||
private $collectionManager; | ||
|
||
public function __construct(BlogInterface $blog, PostManagerInterface $postManager, CollectionManagerInterface $collectionManager) | ||
{ | ||
parent::__construct($blog, $postManager); | ||
|
||
$this->collectionManager = $collectionManager; | ||
} | ||
|
||
/** | ||
* @param string $tag | ||
* | ||
* @return Response | ||
*/ | ||
public function __invoke(Request $request, $tag) | ||
{ | ||
$collection = $this->collectionManager->findOneBy([ | ||
'slug' => $tag, | ||
'enabled' => true, | ||
]); | ||
|
||
if (!$collection || !$collection->getEnabled()) { | ||
throw new NotFoundHttpException('Unable to find the collection'); | ||
} | ||
|
||
return $this->renderArchive($request, ['collection' => $collection], ['collection' => $collection]); | ||
} | ||
} |
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,53 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\NewsBundle\Action; | ||
|
||
use Sonata\NewsBundle\Model\CommentInterface; | ||
use Sonata\NewsBundle\Model\CommentManagerInterface; | ||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
final class CommentListAction extends Controller | ||
{ | ||
/** | ||
* @var CommentManagerInterface | ||
*/ | ||
private $commentManager; | ||
|
||
/** | ||
* CommentListAction constructor. | ||
* | ||
* @param CommentManagerInterface $commentManager | ||
*/ | ||
public function __construct(CommentManagerInterface $commentManager) | ||
{ | ||
$this->commentManager = $commentManager; | ||
} | ||
|
||
/** | ||
* @param int $postId | ||
* | ||
* @return Response | ||
*/ | ||
public function __invoke($postId) | ||
{ | ||
$pager = $this->commentManager | ||
->getPager([ | ||
'postId' => $postId, | ||
'status' => CommentInterface::STATUS_VALID, | ||
], 1, 500); //no limit | ||
|
||
return $this->render('@SonataNews/Post/comments.html.twig', [ | ||
'pager' => $pager, | ||
]); | ||
} | ||
} |
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,41 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\NewsBundle\Action; | ||
|
||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\Routing\RouterInterface; | ||
|
||
final class HomeAction | ||
{ | ||
/** | ||
* @var RouterInterface | ||
*/ | ||
private $router; | ||
|
||
/** | ||
* HomeAction constructor. | ||
* | ||
* @param RouterInterface $router | ||
*/ | ||
public function __construct(RouterInterface $router) | ||
{ | ||
$this->router = $router; | ||
} | ||
|
||
/** | ||
* @return RedirectResponse | ||
*/ | ||
public function __invoke() | ||
{ | ||
return new RedirectResponse($this->router->generate('sonata_news_archive')); | ||
} | ||
} |
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,94 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\NewsBundle\Action; | ||
|
||
use Sonata\NewsBundle\Model\BlogInterface; | ||
use Sonata\NewsBundle\Model\CommentManagerInterface; | ||
use Sonata\NewsBundle\Util\HashGeneratorInterface; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\Routing\RouterInterface; | ||
use Symfony\Component\Security\Core\Exception\AccessDeniedException; | ||
|
||
class ModerateCommentAction | ||
{ | ||
/** | ||
* @var RouterInterface | ||
*/ | ||
private $router; | ||
|
||
/** | ||
* @var BlogInterface | ||
*/ | ||
private $blog; | ||
|
||
/** | ||
* @var CommentManagerInterface | ||
*/ | ||
private $commentManager; | ||
|
||
/** | ||
* @var HashGeneratorInterface | ||
*/ | ||
private $hashGenerator; | ||
|
||
/** | ||
* ModerateCommentAction constructor. | ||
* | ||
* @param RouterInterface $router | ||
* @param BlogInterface $blog | ||
* @param CommentManagerInterface $commentManager | ||
* @param HashGeneratorInterface $hashGenerator | ||
*/ | ||
public function __construct( | ||
RouterInterface $router, | ||
BlogInterface $blog, | ||
CommentManagerInterface $commentManager, | ||
HashGeneratorInterface $hashGenerator | ||
) { | ||
$this->router = $router; | ||
$this->blog = $blog; | ||
$this->commentManager = $commentManager; | ||
$this->hashGenerator = $hashGenerator; | ||
} | ||
|
||
/** | ||
* @param string $commentId | ||
* @param string $hash | ||
* @param string $status | ||
* | ||
* @throws AccessDeniedException | ||
* | ||
* @return RedirectResponse | ||
*/ | ||
public function __invoke($commentId, $hash, $status) | ||
{ | ||
$comment = $this->commentManager->findOneBy(['id' => $commentId]); | ||
|
||
if (!$comment) { | ||
throw new AccessDeniedException(); | ||
} | ||
|
||
$computedHash = $this->hashGenerator->generate($comment); | ||
|
||
if ($computedHash != $hash) { | ||
throw new AccessDeniedException(); | ||
} | ||
|
||
$comment->setStatus($status); | ||
|
||
$this->commentManager->save($comment); | ||
|
||
return new RedirectResponse($this->router->generate('sonata_news_view', [ | ||
'permalink' => $this->blog->getPermalinkGenerator()->generate($comment->getPost()), | ||
])); | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\NewsBundle\Action; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
final class MonthlyPostArchiveAction extends AbstractPostArchiveAction | ||
{ | ||
/** | ||
* @param string $year | ||
* @param string $month | ||
* | ||
* @return Response | ||
*/ | ||
public function __invoke(Request $request, $year, $month) | ||
{ | ||
return $this->renderArchive($request, [ | ||
'date' => $this->getPostManager()->getPublicationDateQueryParts(sprintf('%d-%d-%d', $year, $month, 1), 'month'), | ||
], []); | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\NewsBundle\Action; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
final class PostArchiveAction extends AbstractPostArchiveAction | ||
{ | ||
/** | ||
* @return Response | ||
*/ | ||
public function __invoke(Request $request) | ||
{ | ||
return $this->renderArchive($request); | ||
} | ||
} |
Oops, something went wrong.