/[drupal]/contributions/modules/webcams/views.inc
ViewVC logotype

Contents of /contributions/modules/webcams/views.inc

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


Revision 1.2 - (show annotations) (download) (as text)
Sat Apr 19 01:06:24 2008 UTC (19 months, 1 week ago) by moonray
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
Changes since 1.1: +5 -3 lines
File MIME type: text/x-php
Views integration fix. Also fixed issue with multiple click events being attached when thickbox module is enabled and webcam times out.
1 <?php
2 // $Id$
3
4 /**
5 * Implementation of hook_views_tables().
6 */
7 function webcams_views_tables() {
8 $tables['webcams'] = array(
9 'name' => 'node',
10 'fields' => array(
11 'nid' => array(
12 'name' => t('Webcams: Display Webcams'),
13 'handler' => array(
14 'webcams_views_handler_all' => t('Group multiple webcams'),
15 'webcams_views_handler_single' => t('Do not group multiple webcams'),
16 ),
17 'option' => array(
18 '#type' => 'textfield',
19 '#title' => t('Size'),
20 '#size' => 9,
21 ),
22 'notafield' => true,
23 'sortable' => false,
24 'help' => t('Display webcam images. Use size to override the default webcam sizes. <em>i.e. 320x240</em>.'),
25 ),
26 ),
27 );
28 return $tables;
29 }
30
31 /**
32 * Views handler for displaying the image.
33 */
34 function webcams_views_handler_single($fieldinfo, $fielddata, $value, $data) {
35 $node = node_load($data->nid);
36
37 $webcam = $node->webcams[0];
38 if (empty($webcam)) {
39 return '';
40 }
41
42 if (!empty($fielddata['options'])) {
43 $options = explode('x', $fielddata['options'], 2);
44 if (!is_numeric($options[0]) || !is_numeric($options[1])) {
45 unset($options);
46 }
47 else {
48 $webcam->width = $options[0];
49 $webcam->height = $options[1];
50 }
51 }
52
53 $delay = $webcam->delay * 1000;
54 $errmsg = t('Webcam <em>@name</em> has timed out...', array('@name' => $webcam->name));
55
56 $js = "\n$.webcam.init('webcams{$webcam->nid}-webcam{$webcam->wid}', '{$webcam->name}', '{$webcam->url}', '{$webcam->default_url}', {$webcam->width}, {$webcam->height}, {$delay}, {$webcam->timeout}, 'webcams{$webcam->nid}-content', '{$errmsg}');";
57
58 $output = theme('webcams_webcam', $webcam, $fielddata['options']);
59 $output .= '<div id="webcams'. $data->nid .'-content" class="webcams-content"></div>'."\n";
60
61 drupal_add_css(drupal_get_path('module', 'webcams') .'/webcams.css');
62 drupal_add_js(drupal_get_path('module', 'webcams') .'/webcams.js');
63 drupal_add_js($js, 'inline', 'footer', FALSE);
64
65 return $output;
66 }
67
68 /**
69 * Views handler for displaying the image in a link to the the image node
70 */
71 function webcams_views_handler_all($fieldinfo, $fielddata, $value, $data) {
72 $js = '';
73 $output = '';
74 $node = node_load($data->nid);
75
76 if (!empty($fielddata['options'])) {
77 $options = explode('x', $fielddata['options'], 2);
78 if (!is_numeric($options[0]) || !is_numeric($options[1])) {
79 unset($options);
80 }
81 }
82
83 for ($i = 0; $i < count($node->webcams); $i++) {
84 $webcam = $node->webcams[$i];
85 if (empty($webcam)) {
86 continue;
87 }
88
89 if (isset($options[0]) && isset($options[1])) {
90 $webcam->width = $options[0];
91 $webcam->height = $options[1];
92 }
93
94 $delay = $webcam->delay * 1000;
95 $errmsg = t('Webcam <em>@name</em> has timed out...', array('@name' => $webcam->name));
96
97 $js .= "\n$.webcam.init('webcams{$webcam->nid}-webcam{$webcam->wid}', '{$webcam->name}', '{$webcam->url}', '{$webcam->default_url}', {$webcam->width}, {$webcam->height}, {$delay}, {$webcam->timeout}, 'webcams{$webcam->nid}-content', '{$errmsg}');";
98
99 $output .= theme('webcams_webcam', $webcam, $fielddata['options']);
100 }
101 $output .= '<div id="webcams'. $data->nid .'-content" class="webcams-content"></div>'."\n";
102
103 drupal_add_css(drupal_get_path('module', 'webcams') .'/webcams.css');
104 drupal_add_js(drupal_get_path('module', 'webcams') .'/webcams.js');
105 drupal_add_js($js, 'inline', 'footer', FALSE);
106
107 return $output;
108 }
109
110 /**
111 * Views - Generate a list of all the valid sizes that are available
112 */
113 function webcams_views_handler_filter_image_size($op) {
114 foreach (_image_get_sizes() as $key => $size) {
115 $a[$key] = $size['label'];
116 }
117 return $a;
118 }

  ViewVC Help
Powered by ViewVC 1.1.2