forked from sebsauvage/Shaarli
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Process picwall rendering through Slim controller + UT
- Loading branch information
1 parent
bee3323
commit 485b168
Showing
15 changed files
with
342 additions
and
84 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
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
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,72 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shaarli\Front\Controller; | ||
|
||
use Shaarli\Front\Exception\ThumbnailsDisabledException; | ||
use Shaarli\Thumbnailer; | ||
use Slim\Http\Request; | ||
use Slim\Http\Response; | ||
|
||
/** | ||
* Class PicturesWallController | ||
* | ||
* Slim controller used to render the pictures wall page. | ||
* If thumbnails mode is set to NONE, we just render the template without any image. | ||
* | ||
* @package Front\Controller | ||
*/ | ||
class PictureWallController extends ShaarliController | ||
{ | ||
public function index(Request $request, Response $response): Response | ||
{ | ||
if ($this->container->conf->get('thumbnails.mode', Thumbnailer::MODE_NONE) === Thumbnailer::MODE_NONE) { | ||
throw new ThumbnailsDisabledException(); | ||
} | ||
|
||
$this->assignView( | ||
'pagetitle', | ||
t('Picture wall') .' - '. $this->container->conf->get('general.title', 'Shaarli') | ||
); | ||
|
||
// Optionally filter the results: | ||
$links = $this->container->bookmarkService->search($request->getQueryParams()); | ||
$linksToDisplay = []; | ||
|
||
// Get only bookmarks which have a thumbnail. | ||
// Note: we do not retrieve thumbnails here, the request is too heavy. | ||
$formatter = $this->container->formatterFactory->getFormatter('raw'); | ||
foreach ($links as $key => $link) { | ||
if (!empty($link->getThumbnail())) { | ||
$linksToDisplay[] = $formatter->format($link); | ||
} | ||
} | ||
|
||
$data = $this->executeHooks($linksToDisplay); | ||
foreach ($data as $key => $value) { | ||
$this->assignView($key, $value); | ||
} | ||
|
||
return $response->write($this->render('picwall')); | ||
} | ||
|
||
/** | ||
* @param mixed[] $linksToDisplay List of formatted bookmarks | ||
* | ||
* @return mixed[] Template data after active plugins render_picwall hook execution. | ||
*/ | ||
protected function executeHooks(array $linksToDisplay): array | ||
{ | ||
$data = [ | ||
'linksToDisplay' => $linksToDisplay, | ||
]; | ||
$this->container->pluginManager->executeHooks( | ||
'render_picwall', | ||
$data, | ||
['loggedin' => $this->container->loginManager->isLoggedIn()] | ||
); | ||
|
||
return $data; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
application/front/exceptions/ThumbnailsDisabledException.php
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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shaarli\Front\Exception; | ||
|
||
class ThumbnailsDisabledException extends ShaarliException | ||
{ | ||
public function __construct() | ||
{ | ||
$message = t('Picture wall unavailable (thumbnails are disabled).'); | ||
|
||
parent::__construct($message, 400); | ||
} | ||
} |
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
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
Oops, something went wrong.