Skip to content

Commit

Permalink
- fixed tag cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
luizlaydner committed Aug 28, 2007
1 parent b004316 commit 4d4dac8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 28 deletions.
39 changes: 12 additions & 27 deletions tag/lib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require_once(dirname(__FILE__) . '/../config.php'); require_once(dirname(__FILE__) . '/../config.php');


define('DEFAULT_TAG_TABLE_FIELDS', 'id, tagtype, name, rawname, flag'); define('DEFAULT_TAG_TABLE_FIELDS', 'id, tagtype, name, rawname, flag');
define('MAX_TAG_LENGTH',50);

/** /**
* Creates tags * Creates tags
Expand Down Expand Up @@ -562,8 +564,7 @@ function get_item_tags($item_type, $item_id, $sort='ti.ordering ASC', $fields=DE
* (to avoid field name ambiguity in the query, use the identifier "it" Ex: 'it.name ASC' ) * (to avoid field name ambiguity in the query, use the identifier "it" Ex: 'it.name ASC' )
* @param string $fields a comma separated list of fields to return * @param string $fields a comma separated list of fields to return
* (optional, by default all fields are returned). The first field will be used as key for the * (optional, by default all fields are returned). The first field will be used as key for the
* array so must be a unique field such as 'id'. To avoid field name ambiguity in the query, * array so must be a unique field such as 'id'. )
* use the identifier "it" Ex: 'it.name, it.id' )
* @param int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set). * @param int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set).
* @param int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set). * @param int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set).
* @return mixed an array of objects indexed by their ids, or false if no records were found or an error occured. * @return mixed an array of objects indexed by their ids, or false if no records were found or an error occured.
Expand Down Expand Up @@ -985,7 +986,7 @@ function tag_normalize($tag_names_csv, $lowercase=true) {
//removes excess white spaces //removes excess white spaces
$value = preg_replace('/\s\s+/', ' ', $value); $value = preg_replace('/\s\s+/', ' ', $value);


return $value; return substr($value,0,MAX_TAG_LENGTH);
} }


} }
Expand Down Expand Up @@ -1125,33 +1126,16 @@ function tag_names_csv($tag_objects) {




/** /**
* Returns a number of random tags, ordered by their popularity * Returns most popular tags, ordered by their popularity
* *
* @param int $nr_of_tags number of random tags to be returned * @param int $nr_of_tags number of random tags to be returned
* @param unknown_type $tag_type * @param unknown_type $tag_type
* @return mixed an array of tag objects with the following fields: id, name and count * @return mixed an array of tag objects with the following fields: id, name and count
*/ */
function rand_tags_count($nr_of_tags=20, $tag_type = 'default') { function popular_tags_count($nr_of_tags=20, $tag_type = 'default') {


global $CFG; global $CFG;


if (!$tags = get_all_tags($tag_type)) {
return array();
}

if(sizeof($tags) < $nr_of_tags) {
$nr_of_tags = sizeof($tags);
}

$rndtags = array_rand($tags, $nr_of_tags);

$tags_id_csv_with_apos = "'";
foreach($rndtags as $tagid) {
$tags_id_csv_with_apos .= $tags[$tagid]->id . "','";
}
$tags_id_csv_with_apos = substr($tags_id_csv_with_apos,0,-2);


$query = " $query = "
SELECT SELECT
tg.id, tg.name, tg.rawname, COUNT(ti.id) AS count, tg.flag tg.id, tg.name, tg.rawname, COUNT(ti.id) AS count, tg.flag
Expand All @@ -1163,15 +1147,14 @@ function rand_tags_count($nr_of_tags=20, $tag_type = 'default') {
tg.id = ti.tagid tg.id = ti.tagid
WHERE WHERE
ti.tagid ti.tagid
IN
({$tags_id_csv_with_apos})
GROUP BY GROUP BY
tagid tagid
ORDER BY ORDER BY
count count
ASC"; DESC

";
return get_records_sql($query);
return get_records_sql($query,0,$nr_of_tags);




} }
Expand Down Expand Up @@ -1459,6 +1442,8 @@ function print_tag_cloud($tagcloud, $shuffle=true, $max_size=180, $min_size=80)
shuffle($tagcloud); shuffle($tagcloud);
} }


sort($tagcloud);

$count = array(); $count = array();
foreach ($tagcloud as $key => $value){ foreach ($tagcloud as $key => $value){
if(!empty($value->count)) { if(!empty($value->count)) {
Expand Down
2 changes: 1 addition & 1 deletion tag/search.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
echo '<br/><br/>'; echo '<br/><br/>';


print_box_start('generalbox', 'big-tag-cloud-box'); print_box_start('generalbox', 'big-tag-cloud-box');
print_tag_cloud(rand_tags_count(60), true, 170,70); print_tag_cloud(popular_tags_count(60), true, 170,70);
print_box_end(); print_box_end();


print_footer(); print_footer();
Expand Down

0 comments on commit 4d4dac8

Please sign in to comment.