⌈⌋ ⎇ branch:  freshcode


Artifact [2eba9b3f5f]

Artifact 2eba9b3f5f7138f888d057e96d5f9c2aed501b1c:

  • File page_tags.php — part of check-in [13d1df713c] at 2021-04-05 06:20:05 on branch trunk — Use some short tags (user: mario size: 1664)

<?php
/**
 * type: page
 * title: Tags
 * description: Tag cloud
 * version: 0.3
 *
 * This frontend code is utilizing a separate `tags` table, which
 * gets populated per cron script (rather than at insertion or via
 * trigger [sqlite seems insufficient to handle that).
 *
 * Currently just outputs a plain search result list. Later versions
 * should delegate this to a proper /search feature.
 *
 */


$header_add = '<meta robots=noindex,nofollow>';
include("template/header.php");
include("template/table_main.php");




#-- print tag cloud
?>
<section style="min-height: 1750pt">
<h2 class=no-margin>Tags</h2>
<p id=tag_cloud>
<?php

// Query `tags` table to generate a cloud
$tags = db("SELECT COUNT(name) AS cnt, tag FROM tags GROUP BY tag")->fetchAll();
$count = array_column($tags, "cnt");
if ($count) {
    $avg = count($count) / array_sum($count);

    // Print tag cloud
    foreach ($tags as $t) {
    
        if ($t["cnt"] < 2) continue;

        // average
        $n = 
        $q = 1.0*$t["cnt"] / 1.0*$avg;
        
        /**
         * Qantify
         * - Values 0.1 - 20.0 are transitioned into the range 0.3 - 2.0
         */
        $q = atan($q * 0.55 - 0.1) * 1.35;
        
        // font size
        $q = sprintf("%.1f", $q * 100);

        // output
        print " <a href=\"/search?tag=" . urlencode($t["tag"])
            . "\" class=tag style=\"font-size: $q%;\"> $t[tag]</a> ";
    }

}
?></p></section><?php

#-- sidebar with Trove list
?>
<td id=sidebar>
<div id=trove_tags class=pick-tags>
<?=
tags::trove_select(tags::$tree);
?>
</div>
</td><?php



include("template/table_end.php");
include("template/bottom.php");


?>