| 1 |
<?php // $Id: movino_views.module,v 1.1 2007/08/05 20:29:08 tomsun Exp $
|
| 2 |
/*
|
| 3 |
Movino Web Frontend
|
| 4 |
Copyright 2006, 2007 Tom Sundström
|
| 5 |
|
| 6 |
This program is free software; you can redistribute it and/or modify
|
| 7 |
it under the terms of the GNU General Public License version 2 as
|
| 8 |
published by the Free Software Foundation.
|
| 9 |
|
| 10 |
This program is distributed in the hope that it will be useful,
|
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
GNU General Public License for more details.
|
| 14 |
|
| 15 |
You should have received a copy of the GNU General Public
|
| 16 |
License along with this program; if not, write to the Free Software
|
| 17 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 18 |
*/
|
| 19 |
|
| 20 |
|
| 21 |
/**
|
| 22 |
* Implementation of hook_help().
|
| 23 |
*/
|
| 24 |
function movino_views_help($section) {
|
| 25 |
switch ($section) {
|
| 26 |
case 'admin/help#help':
|
| 27 |
// TODO: expand
|
| 28 |
$output = '<p>'. t('Makes Movino content available to the Views module.') . '</p>';
|
| 29 |
return $output;
|
| 30 |
}
|
| 31 |
}
|
| 32 |
|
| 33 |
|
| 34 |
/**
|
| 35 |
* Implementation of hook_views_tables
|
| 36 |
*/
|
| 37 |
function movino_views_tables() {
|
| 38 |
$tables['movino_node_mapping'] = array(
|
| 39 |
'name' => 'movino_node_mapping',
|
| 40 |
'join' => array(
|
| 41 |
'left' => array(
|
| 42 |
'table' => 'node',
|
| 43 |
'field' => 'nid'
|
| 44 |
),
|
| 45 |
'right' => array(
|
| 46 |
'field' => 'nid'
|
| 47 |
),
|
| 48 |
),
|
| 49 |
);
|
| 50 |
|
| 51 |
|
| 52 |
$tables['movino_videos'] = array(
|
| 53 |
'name' => 'movino_videos',
|
| 54 |
'join' => array(
|
| 55 |
'left' => array(
|
| 56 |
'table' => 'movino_node_mapping',
|
| 57 |
'field' => 'vid'
|
| 58 |
),
|
| 59 |
'right' => array(
|
| 60 |
'field' => 'vid'
|
| 61 |
),
|
| 62 |
),
|
| 63 |
'fields' => array(
|
| 64 |
'vid' => array(
|
| 65 |
'name' => t('Movino: Video cache ID'),
|
| 66 |
'sortable' => false,
|
| 67 |
'help' => t('Display the video cache ID.'),
|
| 68 |
),
|
| 69 |
'player' => array(
|
| 70 |
'field' => 'vid',
|
| 71 |
'handler' => '_movino_views_handler_player',
|
| 72 |
'name' => t('Movino: Video player'),
|
| 73 |
'sortable' => false,
|
| 74 |
'help' => t('Display an embedded player.'),
|
| 75 |
'option' => array(
|
| 76 |
'width' => array(
|
| 77 |
'#prefix' => t('Width'),
|
| 78 |
'#type' => 'textfield',
|
| 79 |
'#size' => 3,
|
| 80 |
),
|
| 81 |
'height' => array(
|
| 82 |
'#prefix' => t('Height'),
|
| 83 |
'#type' => 'textfield',
|
| 84 |
'#size' => 3,
|
| 85 |
'#description' => t('Optionally override the default width and height of the player. Leave blank for defaults.'),
|
| 86 |
),
|
| 87 |
'allow_resize' => array(
|
| 88 |
'#prefix' => t('Player resizing'),
|
| 89 |
'#type' => 'select',
|
| 90 |
'#options' => array(
|
| 91 |
0 => 'Default value',
|
| 92 |
1 => 'Provide resize controls',
|
| 93 |
2 => 'Disable resizing',
|
| 94 |
),
|
| 95 |
),
|
| 96 |
'#type' => 'movino_views_multioptions_output',
|
| 97 |
'#process' => array('movino_views_multioptions_process' => NULL),
|
| 98 |
'#after_build' => array('movino_views_multioptions_after_build'),
|
| 99 |
),
|
| 100 |
),
|
| 101 |
'icon' => array(
|
| 102 |
'field' => 'vid',
|
| 103 |
'handler' => '_movino_views_handler_image',
|
| 104 |
'name' => t('Movino: Preview image'),
|
| 105 |
'sortable' => false,
|
| 106 |
'help' => t('Display the preview image.'),
|
| 107 |
'option' => array(
|
| 108 |
'width' => array(
|
| 109 |
'#prefix' => t('Width'),
|
| 110 |
'#type' => 'textfield',
|
| 111 |
'#size' => 3,
|
| 112 |
),
|
| 113 |
'height' => array(
|
| 114 |
'#prefix' => t('Height'),
|
| 115 |
'#type' => 'textfield',
|
| 116 |
'#size' => 3,
|
| 117 |
'#description' => t('Optionally override the default width and height of the preview image. Leave blank for defaults.'),
|
| 118 |
),
|
| 119 |
'#type' => 'movino_views_multioptions_output',
|
| 120 |
'#process' => array('movino_views_multioptions_process' => NULL),
|
| 121 |
'#after_build' => array('movino_views_multioptions_after_build'),
|
| 122 |
),
|
| 123 |
),
|
| 124 |
'id' => array(
|
| 125 |
'name' => t('Movino: Video feed ID'),
|
| 126 |
'sortable' => false,
|
| 127 |
'help' => t('Display the video feed ID.'),
|
| 128 |
),
|
| 129 |
'server' => array(
|
| 130 |
'name' => t('Movino: Video server ID'),
|
| 131 |
'sortable' => false,
|
| 132 |
'help' => t('Display the server ID.'),
|
| 133 |
),
|
| 134 |
'server' => array(
|
| 135 |
'name' => t('Movino: Video server ID'),
|
| 136 |
'sortable' => false,
|
| 137 |
'help' => t('Display the server ID.'),
|
| 138 |
),
|
| 139 |
'type' => array(
|
| 140 |
'name' => t('Movino: Video type'),
|
| 141 |
'sortable' => false,
|
| 142 |
'help' => t('Displays whether the video is broadcasted live or is archived.'),
|
| 143 |
),
|
| 144 |
'author' => array(
|
| 145 |
'name' => t('Movino: Author string'),
|
| 146 |
'sortable' => false,
|
| 147 |
'help' => t('Display the author string supplied from the video server.'),
|
| 148 |
),
|
| 149 |
'url' => array(
|
| 150 |
'name' => t('Movino: URL'),
|
| 151 |
'sortable' => false,
|
| 152 |
'help' => t('Display the URL to the video.'),
|
| 153 |
),
|
| 154 |
'size' => array(
|
| 155 |
'name' => t('Movino: Video size'),
|
| 156 |
'sortable' => false,
|
| 157 |
'help' => t('Display the size (width x height) of the video.'),
|
| 158 |
),
|
| 159 |
'encoding' => array(
|
| 160 |
'name' => t('Movino: Video encoding'),
|
| 161 |
'sortable' => false,
|
| 162 |
'help' => t('Display the video encoding string.'),
|
| 163 |
),
|
| 164 |
'preview' => array(
|
| 165 |
'name' => t('Movino: Preview URL'),
|
| 166 |
'sortable' => false,
|
| 167 |
'help' => t('Display the url to the preview image.'),
|
| 168 |
),
|
| 169 |
),
|
| 170 |
'filters' => array(
|
| 171 |
'type' => array(
|
| 172 |
'name' => t('Movino: Video type'),
|
| 173 |
'operator' => '_movino_views_handler_operator_type',
|
| 174 |
'handler' => '_movino_views_handler_filter_type',
|
| 175 |
'help' => t('This filter allows you to select only live or archived videos.'),
|
| 176 |
'value' => array(
|
| 177 |
'#type' => 'select',
|
| 178 |
'#options' => array(
|
| 179 |
'live' => 'Live video',
|
| 180 |
'archived' => 'Archived video',
|
| 181 |
),
|
| 182 |
),
|
| 183 |
),
|
| 184 |
),
|
| 185 |
);
|
| 186 |
|
| 187 |
|
| 188 |
$tables['movino_servers'] = array(
|
| 189 |
'name' => 'movino_servers',
|
| 190 |
'join' => array(
|
| 191 |
'left' => array(
|
| 192 |
'table' => 'movino_videos',
|
| 193 |
'field' => 'server'
|
| 194 |
),
|
| 195 |
'right' => array(
|
| 196 |
'field' => 'id'
|
| 197 |
),
|
| 198 |
),
|
| 199 |
'fields' => array(
|
| 200 |
'name' => array(
|
| 201 |
'name' => t('Movino: Video server name'),
|
| 202 |
'sortable' => false,
|
| 203 |
'help' => t('Display the video server name.'),
|
| 204 |
),
|
| 205 |
),
|
| 206 |
);
|
| 207 |
|
| 208 |
|
| 209 |
return $tables;
|
| 210 |
}
|
| 211 |
|
| 212 |
|
| 213 |
/*
|
| 214 |
* Image field.
|
| 215 |
*/
|
| 216 |
function _movino_views_handler_image($fieldinfo, $fielddata, $value, $data) {
|
| 217 |
$video = movino_get_video_by_vid($value);
|
| 218 |
if (!empty($video)) {
|
| 219 |
if (isset($fielddata['options'])) {
|
| 220 |
$options = unserialize($fielddata['options']);
|
| 221 |
if (!empty($options['width']) && !empty($options['height'])) {
|
| 222 |
$video['icon_width'] = $options['width'];
|
| 223 |
$video['icon_height'] = $options['height'];
|
| 224 |
}
|
| 225 |
}
|
| 226 |
return theme('movino_content', $video, TRUE, array('icon'), array());
|
| 227 |
}
|
| 228 |
}
|
| 229 |
|
| 230 |
|
| 231 |
/*
|
| 232 |
* Player field.
|
| 233 |
*/
|
| 234 |
function _movino_views_handler_player($fieldinfo, $fielddata, $value, $data) {
|
| 235 |
$video = movino_get_video_by_vid($value);
|
| 236 |
if (!empty($video)) {
|
| 237 |
if (isset($fielddata['options'])) {
|
| 238 |
$options = unserialize($fielddata['options']);
|
| 239 |
if (!empty($options['width']) && !empty($options['height'])) {
|
| 240 |
$video['width'] = $options['width'];
|
| 241 |
$video['height'] = $options['height'];
|
| 242 |
}
|
| 243 |
if (!empty($options['allow_resize'])) {
|
| 244 |
$video['allow_resize'] = ($options['allow_resize'] == 2 ? FALSE : TRUE);
|
| 245 |
}
|
| 246 |
}
|
| 247 |
return theme('movino_content', $video, TRUE, array('player'), array());
|
| 248 |
}
|
| 249 |
}
|
| 250 |
|
| 251 |
|
| 252 |
/**
|
| 253 |
* Format a field as text.
|
| 254 |
*/
|
| 255 |
/*
|
| 256 |
function views_handler_field_int($fieldinfo, $fielddata, $value, $data) {
|
| 257 |
return intval($value);
|
| 258 |
}
|
| 259 |
*/
|
| 260 |
|
| 261 |
|
| 262 |
/**
|
| 263 |
* Handle multiple options per field
|
| 264 |
*/
|
| 265 |
/*
|
| 266 |
function movino_views_multioptions_output($fieldinfo, $fielddata, $value, $data) {
|
| 267 |
return $fielddata['options'];
|
| 268 |
}
|
| 269 |
*/
|
| 270 |
function theme_movino_views_multioptions_output($element) {
|
| 271 |
return $element['#children'];
|
| 272 |
}
|
| 273 |
function movino_views_multioptions_process($element) {
|
| 274 |
if (!isset($element['#default_value'])) {
|
| 275 |
return $element;
|
| 276 |
}
|
| 277 |
$values = unserialize($element['#default_value']);
|
| 278 |
if (is_array($values) && !empty($values)) {
|
| 279 |
foreach ($values as $key => $value) {
|
| 280 |
if (substr($key, 0, 1) != '#') {
|
| 281 |
$element[$key]['#default_value'] = $value;
|
| 282 |
}
|
| 283 |
}
|
| 284 |
}
|
| 285 |
return $element;
|
| 286 |
}
|
| 287 |
function movino_views_multioptions_after_build($element) {
|
| 288 |
$values = array();
|
| 289 |
if (is_array($element) && !empty($element)) {
|
| 290 |
foreach ($element as $key => $value) {
|
| 291 |
if (substr($key, 0, 1) != '#') {
|
| 292 |
$values[$key] = $element[$key]['#value'];
|
| 293 |
}
|
| 294 |
}
|
| 295 |
}
|
| 296 |
$element['#value'] = serialize($values);
|
| 297 |
form_set_value($element, $element['#value']);
|
| 298 |
return $element;
|
| 299 |
}
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
/**
|
| 304 |
* A list of options to be used in LIKE queries
|
| 305 |
*/
|
| 306 |
function _movino_views_handler_operator_type() {
|
| 307 |
return array('=' => t('Is'));
|
| 308 |
}
|
| 309 |
|
| 310 |
/**
|
| 311 |
* Custom filter for LIKE operations
|
| 312 |
*/
|
| 313 |
function _movino_views_handler_filter_type($op, $filter, $filterinfo, &$query) {
|
| 314 |
switch (trim($filter['value'])) {
|
| 315 |
case (''):
|
| 316 |
return;
|
| 317 |
break;
|
| 318 |
}
|
| 319 |
switch ($op) {
|
| 320 |
case 'handler':
|
| 321 |
$table = $filterinfo['table'];
|
| 322 |
$column = $filterinfo['field'];
|
| 323 |
$field = "$table.$column";
|
| 324 |
$query->ensure_table($table);
|
| 325 |
|
| 326 |
switch ($filter['operator']) {
|
| 327 |
case '=':
|
| 328 |
$query->add_where("UPPER(%s) = UPPER('%s')",
|
| 329 |
$field, $filter['value']);
|
| 330 |
break;
|
| 331 |
}
|
| 332 |
break;
|
| 333 |
}
|
| 334 |
}
|