1<?php
2/**
3 * TagCloud_example5.php
4 *
5 * Generate a Tag Cloud and specify a special tag separators yourself.
6 *
7 * PHP version 5
8 *
9 * LICENSE: This source file is subject to version 3.01 of the PHP license
10 * that is available through the world-wide-web at the following URI:
11 * http://www.php.net/license/3_01.txt.  If you did not receive a copy of
12 * the PHP License and are unable to obtain it through the web, please
13 * send a note to license@php.net so we can mail you a copy immediately.
14 *
15 * @category  HTML
16 * @package   HTML_TagCloud
17 * @author    Bastian Onken <bastianonken@php.net>
18 * @copyright 2010 Bastian Onken
19 * @license   http://www.php.net/license/3_01.txt  PHP License 3.01
20 * @version   SVN: $Id$
21 * @link      http://pear.php.net/package/HTML_TagCloud
22 * @since     File available since Release 0.2.4
23 */
24
25require_once 'HTML/TagCloud.php';
26
27// To get the date function working properly we have to set the time zone
28date_default_timezone_set('UTC');
29
30// Set up font sizes, colors and a non-default tag separator
31$baseFontSize  = 150;
32$fontSizeRange = 75;
33$sizeSuffix    = '%';
34$latestColor   = 'FF0000';
35$earliestColor = 'FFFB00';
36$thresholds    = 6;
37$tagSeparator  = '<span style="color:#DDDDDD;"> / </span>';
38
39// Create an instance of HTML_TagCloud with settings we defined above
40$tagCloud = new HTML_TagCloud(
41    $baseFontSize, $fontSizeRange, $latestColor, $earliestColor, $thresholds,
42    $sizeSuffix, $tagSeparator
43);
44
45// Set up some tags
46$tagFixtures = array(
47    'blogs',
48    'folksonomy',
49    'wikis',
50    'rss',
51    'widgets',
52    'ajax',
53    'podcasting',
54    'semantic',
55    'xhtml',
56    'design',
57    'mobility'
58);
59
60// Set up some time occurrences
61$timeFixtures = array(
62    '-1 year',
63    '-6 month',
64    '-3 month',
65    '-1 month',
66    '-1 week',
67    '-1 day'
68);
69
70// Build and add randomized tags to the TagCloud
71foreach ($tagFixtures as $tag) {
72    // Set up how many occurrences this tag has
73    $numberOfOccurrences = rand(1, 50);
74    // Randomize through the time fixtures and set up the age of this tag
75    $time = $timeFixtures[rand(0, count($timeFixtures)-1)];
76    // Finally add it to the cloud, to see how the time and count values are
77    //  interpreted we add them to the tagname to see their current value
78    $tagCloud->addElement($tag, $dummyURL, $numberOfOccurrences, strtotime($time));
79}
80
81// Now return a HTML page that contains additional TagCloud style definitions
82//  and display both TagClouds we created above
83?>
84<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
85<html lang="en">
86<head>
87<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
88<title>My customized Tag Cloud</title>
89<style type="text/css">
90.tagcloud {
91    font-family: 'lucida grande',trebuchet,'trebuchet ms',verdana,arial,
92                  helvetica,sans-serif;
93    line-height: 1.8em;
94    word-spacing: 0ex;
95    letter-spacing: normal;
96    text-decoration: none;
97    text-transform: none;
98    text-align: justify;
99    text-indent: 0ex;
100    margin: 1em 0em 0em 0em;
101    border: 2px dotted #ddd;
102    padding: 1em;
103}
104.tagcloud a:link {
105    border-width: 0;
106}
107.tagcloud a:visited {
108    border-width: 0;
109}
110.tagcloud a:hover {
111    border-width: 1px;
112    color:white !important;
113    background-color: #FF0000;
114}
115.tagcloud a:active {
116    border-width: 1px;
117    color:white !important;
118    background-color: #FFFB00;
119}
120.tagcloudElement {
121    padding: 2px 5px;
122    position: relative;
123    vertical-align: middle;
124}
125<?php
126
127// Print out CSS
128print $tagCloud->buildCSS();
129
130?>
131</style>
132</head>
133<body>
134<p>This box shows a randomized tag cloud, hit reload to mix them up:</p>
135<?php
136
137// Print out HTML
138print $tagCloud->buildHTML();
139
140// Show source, you don't need this line in your code, it's just for showing off
141?>
142<br/>
143Take a look at the source:<br/>
144<?php
145
146show_source(__FILE__);
147
148?>
149</body>
150</html>