Micro optimizations for tag list

This commit is contained in:
Marcin Kurczewski 2013-10-29 23:21:41 +01:00
parent 96d994eeea
commit e0c4c28e70

View file

@ -1,10 +1,15 @@
<?php $max = max([0]+array_map(function($x) { return $x->getPostCount(); }, $this->context->transport->tags)); ?>
<?php $add = 0.25 ?>
<?php $mul = 0.75 / max(1, log(max(1, $max))) ?>
<?php $url = \Chibi\UrlHelper::route('post', 'list', ['query' => '{query}']) ?>
<div class="tags">
<ul>
<?php foreach ($this->context->transport->tags as $tag): ?>
<li class="tag" title="<?php echo $tag->name ?> (<?php echo $tag->getPostCount() ?>)">
<a href="<?php echo \Chibi\UrlHelper::route('post', 'list', ['query' => $tag->name]) ?>" style="opacity: <?php printf('%.02f', 0.25 + 0.75 * log($tag->getPostCount()) / max(1, log(max(1, $max)))) ?>">
<?php echo $tag->name . ' (' . $tag->getPostCount() . ')' ?>
<?php $name = $tag->name ?>
<?php $count = $tag->getPostCount() ?>
<li class="tag" title="<?php echo $name ?> (<?php echo $count ?>)">
<a href="<?php echo TextHelper::replaceTokens($url, ['query' => $name]) ?>" style="opacity: <?php printf('%.02f', $add + $mul * log($count)) ?>">
<?php echo $name . ' (' . $count . ')' ?>
</a>
</li>
<?php endforeach ?>