]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Fix division by zero in tagcloud 1411/head
authorArthurHoaro <arthur@hoa.ro>
Sun, 26 Jan 2020 13:52:10 +0000 (14:52 +0100)
committerArthurHoaro <arthur@hoa.ro>
Sun, 26 Jan 2020 13:52:10 +0000 (14:52 +0100)
It happens if we have a maximum of 1 occurrence in tags (log(1) = 0)

index.php

index 474d9af5d630439224e051b37ab29cc38457c378..b53b16fefb383400f90eb1b99374b24c907daf68 100644 (file)
--- a/index.php
+++ b/index.php
@@ -659,6 +659,7 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM
 
         alphabetical_sort($tags, false, true);
 
+        $logMaxCount = $maxcount > 1 ? log($maxcount, 30) : 1;
         $tagList = array();
         foreach ($tags as $key => $value) {
             if (in_array($key, $filteringTags)) {
@@ -666,8 +667,8 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM
             }
             // Tag font size scaling:
             //   default 15 and 30 logarithm bases affect scaling,
-            //   22 and 6 are arbitrary font sizes for max and min sizes.
-            $size = log($value, 15) / log($maxcount, 30) * 2.2 + 0.8;
+            //   2.2 and 0.8 are arbitrary font sizes in em.
+            $size = log($value, 15) / $logMaxCount * 2.2 + 0.8;
             $tagList[$key] = array(
                 'count' => $value,
                 'size' => number_format($size, 2, '.', ''),