/[drupal]/contributions/modules/taxonomy_ticker/taxonomy_ticker.module
ViewVC logotype

Contents of /contributions/modules/taxonomy_ticker/taxonomy_ticker.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.20 - (show annotations) (download) (as text)
Mon Jan 7 16:26:14 2008 UTC (22 months, 2 weeks ago) by yrocq
Branch: MAIN
CVS Tags: HEAD
Changes since 1.19: +2 -2 lines
File MIME type: text/x-php
Fixed random category selected when none has been set in the administration page
1 <?php
2 // $Id: taxonomy_ticker.module,v 1.19 2008/01/07 16:19:20 yrocq Exp $
3
4
5 /**
6 * @file
7 * Enables user to use a ticker to display a type of content.
8 */
9
10 /**
11 * Implementation of hook_help().
12 */
13 function taxonomy_ticker_help($section) {
14 switch ($section) {
15 case 'admin/modules#description':
16 return t('Allows the use of a ticker to display a type of content.');
17 }
18 }
19
20 function taxonomy_ticker_contents() {
21 $tid = variable_get("taxonomy_ticker_tid", array());
22
23 if (count($tid))
24 {
25 // Scrolling vertically.
26 if (variable_get('taxonomy_ticker_direction', 0) == 0) {
27 drupal_add_js(drupal_get_path('module', 'taxonomy_ticker') .'/taxonomy_ticker.js');
28 drupal_add_css(drupal_get_path('module', 'taxonomy_ticker') .'/taxonomy_ticker.css');
29 }
30 else {
31 drupal_add_js(drupal_get_path('module', 'taxonomy_ticker') .'/taxonomy_ticker_horizontally.js');
32 drupal_add_css(drupal_get_path('module', 'taxonomy_ticker') .'/taxonomy_ticker_horizontally.css');
33 }
34
35 $tickerspeed = variable_get('taxonomy_ticker_speed', 8);
36 // Removing the style tag from scrollPane breaks the scrolling functionality.
37 $block = '<div id="scrollerClipper" style="z-index: '. $tickerspeed .'" onmouseover="pauseScroll();" onmouseout="reStartScroll();"><div id="outerscrollPane"><div id="scrollPane" style="position: relative; top: 0px; left: 0px;">';
38
39 $type_q = ($type ? "n.type = '$type'" : 1);
40
41 foreach ($tid as $key => $val) {
42 $tid[$key] = "r.tid = '$val'";
43 }
44 if (!empty($tid)) $tids = "AND (". join(" OR ", $tid) .")";
45
46 $query = db_rewrite_sql("SELECT n.nid, n.title, n.type FROM {node} n LEFT JOIN {term_node} r ON r.nid = n.nid WHERE n.status = 1 ". $tids ." AND $type_q ORDER BY n.changed DESC");
47
48 $results = db_query_range($query, 0, variable_get('taxonomy_ticker_count', 5));
49
50 $block .= '<div id="firstscrollerContentItem"></div>';
51 while ($result = db_fetch_object($results)) {
52 /**
53 * The commented code that follows is an example of how to integrate taxonomy_ticker with
54 * a flexinode content-type, which could be used to show some html content instead of just
55 * displaying the title of the node.
56 */
57 /*
58 $node = node_load(array('nid'=>$result->nid));
59 if ( $node->flexinode_2 != '' ) {
60 // $block .= "<div class=\"scrollerContentItem\"><p><a href=\"" . $node->flexinode_2 . "\">$result->title</a></p></div>";
61 $block .= "<div class=\"scrollerContentItem\"><p>$node->flexinode_2</p></div>";
62 }
63 else {
64 */
65 if (variable_get('taxonomy_ticker_teaser', 0) == 1) {
66 $node = node_load(array('nid' => $result->nid));
67 $teaser = '<br/>'. $node->teaser;
68 }
69 else $teaser = '';
70 $block .= '<div class="scrollerContentItem"><p>'. l($result->title, 'node/'. $result->nid) . $teaser .'</p></div>';
71 /*
72 }
73 */
74 }
75
76 $block .= '<div id="lastscrollerContentItem"></div>';
77 $block .= '<div style="clear: both"></div></div></div></div>';
78 }
79 else
80 {
81 $block='';
82 }
83 return $block;
84 }
85
86 function taxonomy_ticker_block($op = 'list', $delta = 0, $edit = array()) {
87 switch ($op) {
88 case 'list':
89 $blocks[0]['info'] = t('A ticker block');
90 return $blocks;
91
92 case 'view':
93 $blocks["content"] = taxonomy_ticker_contents();
94 $blocks["subject"] = t('Ticker');
95 return $blocks;
96 }
97 }
98
99 function taxonomy_ticker_menu($maycache) {
100 $items = array();
101
102 if (!$may_cache) {
103 $items[] = array(
104 'path' => 'admin/settings/taxonomy-ticker',
105 'title' => t('taxonomy ticker'),
106 'description' => t('Configure taxonomy, number of items, scroll speed and scroll direction of the items in the taxonomy ticker block.'),
107 'callback' => 'drupal_get_form',
108 'callback arguments' => 'taxonomy_ticker_admin_settings',
109 'access' => user_access('administer site configuration'),
110 'type' => MENU_NORMAL_ITEM,
111 );
112 }
113
114 return $items;
115 }
116
117 function taxonomy_ticker_admin_settings() {
118 $form['taxonomy_ticker_tid'] = array(
119 '#type' => 'select',
120 '#title' => t('Terms'),
121 '#default_value' => variable_get('taxonomy_ticker_tid', array()),
122 '#options' => taxonomy_form_all(),
123 '#description' => t('Take nodes associated to the selected terms.'),
124 '#extra' => 0,
125 '#multiple' => TRUE,
126 '#required' => TRUE,
127 );
128
129 $form['taxonomy_ticker_count'] = array(
130 '#type' => 'textfield',
131 '#title' => t('Number of items'),
132 '#default_value' => variable_get('taxonomy_ticker_count', 5),
133 '#size' => 3,
134 '#maxlength' => 3,
135 '#description' => t('The number of items to display in the ticker.'),
136 );
137
138 $form['taxonomy_ticker_direction'] = array(
139 '#type' => 'select',
140 '#title' => t('Direction of scroll'),
141 '#default_value' => variable_get('taxonomy_ticker_direction', 0),
142 '#options' => array(0 => t('Vertically'), 1 => t('Horizontally')),
143 '#description' => t('The direction in which the items scroll in the ticker.'),
144 );
145
146 $form['taxonomy_ticker_speed'] = array(
147 '#type' => 'select',
148 '#title' => t('Scroll Speed'),
149 '#default_value' => variable_get('taxonomy_ticker_speed', 8),
150 '#options' => array(1 => t('Super Fast'), 4 => t('Fast'), 8 => t('Standard'), 12 => t('Slow'), 16 => t('Super Slow')),
151 '#description' => t('The speed in which the items scroll in the ticker.'),
152 );
153
154 $form['taxonomy_ticker_teaser'] = array(
155 '#type' => 'radios',
156 '#title' => t('Include teaser'),
157 '#default_value' => variable_get('taxonomy_ticker_teaser', 0),
158 '#options' => array(t('Disabled'), t('Enabled')),
159 '#description' => t('This option makes teasers appear under the titles (best used when scrolling vertically)'),
160 );
161
162 return system_settings_form($form);
163 }
164
165
166

  ViewVC Help
Powered by ViewVC 1.1.2