⌈⌋ branch:  freshcode


Artifact Content

Artifact 9264673873ae21d46269e4a48bf41077083666e3:

  • File page_tags.php — part of check-in [5bda659526] at 2015-03-24 20:07:22 on branch trunk — Fix spacing to header block. Correct nowrap issue for title/version/datetime in .project headers (Firefox). (user: mario size: 1672)

<?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>
<?php
print tags::trove_select(tags::$tree);
?>
</div>
</td><?php



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


?>