| 1 |
<?php
|
| 2 |
// $Id: term_popular.module,v 1.3 2006/05/13 20:40:56 frjo Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Original author: fajerstarter
|
| 7 |
* From http://drupal.org/node/22036
|
| 8 |
* Modified by Fredrik Jonsson fredrik at combonet dot se
|
| 9 |
* Display a page with weighted tag cloud (as seen on Flickr and Technocrati).
|
| 10 |
*/
|
| 11 |
|
| 12 |
/**
|
| 13 |
* Implementation of hook_help().
|
| 14 |
*/
|
| 15 |
function term_popular_help($section) {
|
| 16 |
switch ($section) {
|
| 17 |
case 'admin/modules#description':
|
| 18 |
return t('Display a page with weighted tag cloud with your categories (as seen on Flickr and Technocrati).');
|
| 19 |
break;
|
| 20 |
case 'term_popular':
|
| 21 |
return '<p>'. variable_get('term_popular_message', '') .'</p>';
|
| 22 |
break;
|
| 23 |
}
|
| 24 |
}
|
| 25 |
|
| 26 |
/**
|
| 27 |
* Implementation of hook_settings().
|
| 28 |
*/
|
| 29 |
function term_popular_settings() {
|
| 30 |
$form['term_popular_message'] = array(
|
| 31 |
'#type' => 'textarea',
|
| 32 |
'#title' => t('Popular categories message'),
|
| 33 |
'#default_value' => variable_get('term_popular_message', ''),
|
| 34 |
'#cols' => 60,
|
| 35 |
'#rows' => 5,
|
| 36 |
'#description' => t('Define a message to be displayed above the popular categories.'),
|
| 37 |
);
|
| 38 |
|
| 39 |
$vocab_options = array();
|
| 40 |
foreach (taxonomy_get_vocabularies() as $vocabulary) {
|
| 41 |
$vocab_options[$vocabulary->vid] = $vocabulary->name;
|
| 42 |
}
|
| 43 |
$form['term_popular_show_vocabularies'] = array(
|
| 44 |
'#type' => 'checkboxes',
|
| 45 |
'#title' => t('Select which vocabularies to be included on the page'),
|
| 46 |
'#default_value' => variable_get('term_popular_show_vocabularies', array()),
|
| 47 |
'#options' => $vocab_options,
|
| 48 |
);
|
| 49 |
|
| 50 |
$form['term_popular_max_terms'] = array(
|
| 51 |
'#type' => 'textfield',
|
| 52 |
'#title' => t('Maximum number of terms'),
|
| 53 |
'#default_value' => variable_get('term_popular_max_terms', 100),
|
| 54 |
'#size' => 4,
|
| 55 |
'#maxlength' => 5,
|
| 56 |
'#description' => t('Specify how many subcategories should be included on the categorie page. Enter "all" to include all subcategories or "0" to include no subcategories.'),
|
| 57 |
);
|
| 58 |
|
| 59 |
return $form;
|
| 60 |
}
|
| 61 |
|
| 62 |
/**
|
| 63 |
* Implementation of hook_menu().
|
| 64 |
*/
|
| 65 |
function term_popular_menu($may_cache) {
|
| 66 |
$items = array();
|
| 67 |
|
| 68 |
if ($may_cache) {
|
| 69 |
$items[] = array(
|
| 70 |
'path' => 'term_popular',
|
| 71 |
'title' => t('popular categories'),
|
| 72 |
'callback' => 'term_popular_page',
|
| 73 |
'access' => user_access('access content'),
|
| 74 |
'type' => MENU_SUGGESTED_ITEM
|
| 75 |
);
|
| 76 |
}
|
| 77 |
|
| 78 |
return $items;
|
| 79 |
}
|
| 80 |
|
| 81 |
/**
|
| 82 |
* Return a list of popular terms in HTML.
|
| 83 |
*/
|
| 84 |
function term_popular_list($text_scale = 3) {
|
| 85 |
$vocabulary_fields = variable_get('term_popular_show_vocabularies', array());
|
| 86 |
$max = variable_get('term_popular_max_terms', 100);
|
| 87 |
if ($vocabulary_fields != NULL && $max != NULL) {
|
| 88 |
$result = db_query('SELECT * FROM {term_data} WHERE vid IN (%s)', implode(', ', $vocabulary_fields));
|
| 89 |
while ($term = db_fetch_object($result)) {
|
| 90 |
$term_names[$term->tid] = $term->name;
|
| 91 |
$popularity[$term->tid] = taxonomy_term_count_nodes($term->tid) ;
|
| 92 |
}
|
| 93 |
arsort($popularity);
|
| 94 |
$popularity_temp = $popularity;
|
| 95 |
$most_popular = (array_shift($popularity_temp));
|
| 96 |
natcasesort($term_names);
|
| 97 |
$i = 1;
|
| 98 |
while (list($key, $val) = each($term_names) and $i <= $max) {
|
| 99 |
if ($popularity[$key] > 0) {
|
| 100 |
$output .= '<span style="font-size: '. round(($popularity[$key] / $most_popular * $text_scale) + 1, 1) . 'em">' . l( $val, 'taxonomy/term/'. $key .'/all') . '</span>' . "\n";
|
| 101 |
$i++;
|
| 102 |
}
|
| 103 |
}
|
| 104 |
return $output;
|
| 105 |
}
|
| 106 |
}
|
| 107 |
|
| 108 |
/**
|
| 109 |
* Theme Popular Terms page
|
| 110 |
*/
|
| 111 |
function term_popular_page() {
|
| 112 |
$text_scale = 3;
|
| 113 |
$output = '<div class="box term_popular">';
|
| 114 |
$output .= term_popular_list($text_scale);
|
| 115 |
$output .= '</div>';
|
| 116 |
print theme('page', $output);
|
| 117 |
}
|
| 118 |
|
| 119 |
/**
|
| 120 |
* Implementation of hook_block().
|
| 121 |
*
|
| 122 |
* Generates a block with Popular Terms.
|
| 123 |
*/
|
| 124 |
function term_popular_block($op = 'list', $delta = 0) {
|
| 125 |
if ($op == 'list') {
|
| 126 |
$blocks[0]['info'] = t('Popular categories');
|
| 127 |
return $blocks;
|
| 128 |
}
|
| 129 |
else if ($op == 'view') {
|
| 130 |
if (user_access('access content')) {
|
| 131 |
$text_scale = 2;
|
| 132 |
$output = term_popular_list($text_scale);
|
| 133 |
$output .= '<div class="more-link">'. l(t('more'), 'term_popular') .'</div>';
|
| 134 |
|
| 135 |
$block['subject'] = t('Popular categories');
|
| 136 |
$block['content'] = $output;
|
| 137 |
}
|
| 138 |
return $block;
|
| 139 |
}
|
| 140 |
}
|
| 141 |
?>
|