]>
git.immae.eu Git - github/shaarli/Shaarli.git/blob - application/front/controllers/TagCloudController.php
3 declare(strict_types
=1);
5 namespace Shaarli\Front\Controller
;
8 use Slim\Http\Response
;
13 * Slim controller used to render the tag cloud page.
15 * @package Front\Controller
17 class TagCloudController
extends ShaarliController
19 public function index(Request
$request, Response
$response): Response
21 if ($this->container
->loginManager
->isLoggedIn() === true) {
22 $visibility = $this->container
->sessionManager
->getSessionParameter('visibility');
25 $searchTags = $request->getQueryParam('searchtags');
26 $filteringTags = $searchTags !== null ? explode(' ', $searchTags) : [];
28 $tags = $this->container
->bookmarkService
->bookmarksCountPerTag($filteringTags, $visibility ?? null);
30 // We sort tags alphabetically, then choose a font size according to count.
31 // First, find max value.
33 foreach ($tags as $count) {
34 $maxCount = max($maxCount, $count);
37 alphabetical_sort($tags, false, true);
39 $logMaxCount = $maxCount > 1 ? log($maxCount, 30) : 1;
41 foreach ($tags as $key => $value) {
42 if (in_array($key, $filteringTags)) {
45 // Tag font size scaling:
46 // default 15 and 30 logarithm bases affect scaling,
47 // 2.2 and 0.8 are arbitrary font sizes in em.
48 $size = log($value, 15) / $logMaxCount * 2.2 +
0.8;
51 'size' => number_format($size, 2, '.', ''),
55 $searchTags = implode(' ', escape($filteringTags));
57 'search_tags' => $searchTags,
60 $data = $this->executeHooks($data);
61 foreach ($data as $key => $value) {
62 $this->assignView($key, $value);
65 $searchTags = !empty($searchTags) ? $searchTags .' - ' : '';
68 $searchTags. t('Tag cloud') .' - '. $this->container
->conf
->get('general.title', 'Shaarli')
71 return $response->write($this->render('tag.cloud'));
75 * @param mixed[] $data Template data
77 * @return mixed[] Template data after active plugins render_picwall hook execution.
79 protected function executeHooks(array $data): array
81 $this->container
->pluginManager
->executeHooks(
84 ['loggedin' => $this->container
->loginManager
->isLoggedIn()]