| 1 |
<?php // $Id: movino_lists.module,v 1.2 2007/10/04 06:45:17 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_lists_help($section) {
|
| 25 |
switch ($section) {
|
| 26 |
case 'admin/help#help':
|
| 27 |
// TODO: expand
|
| 28 |
$output = '<p>'. t('Provides pages and Drupal blocks with various lists of Movino videos. If the Views module and the Movino Node module are enabled, a customizable set of Views are provided. Otherwise, a hard coded set of pages and blocks are used.') . '</p>';
|
| 29 |
return $output;
|
| 30 |
}
|
| 31 |
}
|
| 32 |
|
| 33 |
|
| 34 |
/**
|
| 35 |
* Implementation of hook_menu().
|
| 36 |
*/
|
| 37 |
function movino_lists_menu($may_cache) {
|
| 38 |
global $user;
|
| 39 |
$items = array();
|
| 40 |
|
| 41 |
if (!$may_cache) {
|
| 42 |
|
| 43 |
$items[] = array(
|
| 44 |
'path' => 'movino',
|
| 45 |
'title' => t('Movino'),
|
| 46 |
'description' => t('Movino content.'),
|
| 47 |
'callback' => 'movino_video_page',
|
| 48 |
'access' => user_access('view live Movino content') || user_access('view archived Movino content'),
|
| 49 |
);
|
| 50 |
$items[] = array(
|
| 51 |
'path' => 'movino/live',
|
| 52 |
'title' => t('Live content'),
|
| 53 |
'description' => t('Live Movino content.'),
|
| 54 |
'callback' => 'movino_video_page',
|
| 55 |
'access' => user_access('view live Movino content'),
|
| 56 |
);
|
| 57 |
$items[] = array(
|
| 58 |
'path' => 'movino/archived',
|
| 59 |
'title' => t('Archived content'),
|
| 60 |
'description' => t('Movino archived content.'),
|
| 61 |
'callback' => 'movino_video_page',
|
| 62 |
'access' => user_access('view archived Movino content'),
|
| 63 |
);
|
| 64 |
}
|
| 65 |
|
| 66 |
return $items;
|
| 67 |
}
|
| 68 |
|
| 69 |
|
| 70 |
/**
|
| 71 |
* Implementation of hook_block().
|
| 72 |
*/
|
| 73 |
function movino_lists_block($op = 'list', $delta = 0, $edit = array()) {
|
| 74 |
|
| 75 |
if ($op == 'list') {
|
| 76 |
// Block descriptions.
|
| 77 |
$blocks[0]['info'] = t('Movino: Most recent live video');
|
| 78 |
$blocks[1]['info'] = t('Movino: Live videos');
|
| 79 |
$blocks[2]['info'] = t('Movino: Archived videos');
|
| 80 |
return $blocks;
|
| 81 |
}
|
| 82 |
else if ($op == 'configure') {
|
| 83 |
// Block configuration forms.
|
| 84 |
switch($delta) {
|
| 85 |
case 1:
|
| 86 |
case 2:
|
| 87 |
$form['limit'] = array(
|
| 88 |
'#type' => 'textfield',
|
| 89 |
'#title' => t('Maximum number of videos'),
|
| 90 |
'#default_value' => variable_get('movino_lists_block_limit_'. $delta, 10),
|
| 91 |
'#maxlength' => 3,
|
| 92 |
'#size' => 3,
|
| 93 |
'#description' => t('The maximum number of videos to show in this block.'),
|
| 94 |
);
|
| 95 |
$form['more'] = array(
|
| 96 |
'#type' => 'checkbox',
|
| 97 |
'#title' => t('Show more-link'),
|
| 98 |
'#default_value' => variable_get('movino_lists_block_more_'. $delta, 1),
|
| 99 |
'#description' => t('Whether or not to show a link to the page when there are more videos available than the maximum set above.'),
|
| 100 |
);
|
| 101 |
return $form;
|
| 102 |
}
|
| 103 |
}
|
| 104 |
else if ($op == 'save') {
|
| 105 |
// Code to trigger when block configuration is saved.
|
| 106 |
switch ($delta) {
|
| 107 |
case 1:
|
| 108 |
case 2:
|
| 109 |
variable_set('movino_lists_block_limit_'. $delta, $edit['limit']);
|
| 110 |
variable_set('movino_lists_block_more_'. $delta, $edit['more']);
|
| 111 |
return;
|
| 112 |
}
|
| 113 |
}
|
| 114 |
else if ($op == 'view') {
|
| 115 |
$block = array();
|
| 116 |
|
| 117 |
switch ($delta) {
|
| 118 |
|
| 119 |
|
| 120 |
case 0:
|
| 121 |
|
| 122 |
$block['subject'] = t('Most recent live video');
|
| 123 |
$block['content'] = '';
|
| 124 |
|
| 125 |
if (!user_access('view live Movino content')) {
|
| 126 |
return $block;
|
| 127 |
}
|
| 128 |
|
| 129 |
// Fetch the live video info
|
| 130 |
$videos = movino_get_videos('live', NULL, NULL, 1);
|
| 131 |
|
| 132 |
// Return an empty block if there are no videos available.
|
| 133 |
if (!empty($videos)) {
|
| 134 |
|
| 135 |
// Pick the most recent video.
|
| 136 |
$video = array_shift($videos);
|
| 137 |
|
| 138 |
// Add the most recent video using an embedded player.
|
| 139 |
$block['content'] .= theme('movino_content', $video, FALSE);
|
| 140 |
}
|
| 141 |
return $block;
|
| 142 |
|
| 143 |
|
| 144 |
case 1:
|
| 145 |
$block['subject'] = t('Live videos');
|
| 146 |
$block['content'] = '';
|
| 147 |
|
| 148 |
if (!user_access('view live Movino content')) {
|
| 149 |
return $block;
|
| 150 |
}
|
| 151 |
|
| 152 |
// Fetch the live video metadata.
|
| 153 |
$limit = variable_get('movino_lists_block_limit_'. $delta, 10);
|
| 154 |
$videos = movino_get_videos('live', NULL, NULL, $limit + 1);
|
| 155 |
|
| 156 |
// Return an empty block if there are no videos available.
|
| 157 |
if (!empty($videos)) {
|
| 158 |
// Generate a list
|
| 159 |
$block['content'] .= theme('movino_video_list', $videos, FALSE, $limit);
|
| 160 |
if ($limit < count($videos) && variable_get('movino_lists_block_more_'. $delta, 1)) {
|
| 161 |
// Add a more link.
|
| 162 |
$block['content'] .= l(t('More live videos'), 'movino/live');
|
| 163 |
}
|
| 164 |
}
|
| 165 |
return $block;
|
| 166 |
|
| 167 |
|
| 168 |
case 2:
|
| 169 |
$block['subject'] = t('Archived videos', NULL, NULL, $limit);
|
| 170 |
$block['content'] = '';
|
| 171 |
|
| 172 |
if (!user_access('view archived Movino content')) {
|
| 173 |
return $block;
|
| 174 |
}
|
| 175 |
|
| 176 |
// Fetch the archived video metadata.
|
| 177 |
$limit = variable_get('movino_lists_block_limit_'. $delta, 10);
|
| 178 |
$videos = movino_get_videos('archived', NULL, NULL, $limit + 1);
|
| 179 |
|
| 180 |
// Return an empty block if there are no videos available.
|
| 181 |
if (!empty($videos)) {
|
| 182 |
// Generate a list
|
| 183 |
$block['content'] .= theme('movino_video_list', $videos, FALSE, $limit);
|
| 184 |
if ($limit < count($videos) && variable_get('movino_lists_block_more_'. $delta, 1)) {
|
| 185 |
// Add a more link.
|
| 186 |
$block['content'] .= l(t('More archived videos'), 'movino/archived');
|
| 187 |
}
|
| 188 |
}
|
| 189 |
return $block;
|
| 190 |
|
| 191 |
}
|
| 192 |
}
|
| 193 |
}
|
| 194 |
|
| 195 |
|
| 196 |
/**
|
| 197 |
* Implementation of hook_movino_video_prepare():
|
| 198 |
*/
|
| 199 |
function movino_lists_movino_video_prepare(&$video) {
|
| 200 |
// Add the path to the video page,
|
| 201 |
// except if we use movino nodes and
|
| 202 |
// the node module has already added the path.
|
| 203 |
if (!isset($video['page'])) {
|
| 204 |
$video['page'] = 'movino/video/' . $video['server'] . '/' . $video['id'];
|
| 205 |
}
|
| 206 |
}
|
| 207 |
|
| 208 |
|
| 209 |
/**
|
| 210 |
* Most Movino-related pages are generated through this function.
|
| 211 |
*
|
| 212 |
* @return page
|
| 213 |
*/
|
| 214 |
function movino_video_page($type = FALSE, $server_id = FALSE, $video_id = FALSE) {
|
| 215 |
|
| 216 |
if (!$type) {
|
| 217 |
$type = arg(1);
|
| 218 |
}
|
| 219 |
if (!$server_id) {
|
| 220 |
$server_id = arg(2);
|
| 221 |
}
|
| 222 |
if (!$video_id) {
|
| 223 |
$video_id = arg(3);
|
| 224 |
}
|
| 225 |
|
| 226 |
$valid_types = array('live', 'archived');
|
| 227 |
|
| 228 |
$msg = t('Unsupported request.');
|
| 229 |
$title = $msg;
|
| 230 |
|
| 231 |
if (empty($type) && empty($server_id) && empty($video_id)) {
|
| 232 |
return '<ul><li>'. l(t('Live Movino content'), 'movino/live') . '</li><li>' . l(t('Archived Movino content'), 'movino/archived') . '</li></ul>';
|
| 233 |
}
|
| 234 |
// Generate an overview page.
|
| 235 |
if (in_array($type, $valid_types)) {
|
| 236 |
$videos = movino_get_videos($type);
|
| 237 |
if (MOVINO_DEBUG) {
|
| 238 |
drupal_set_message('Displaying multiple videos: '. count($videos));
|
| 239 |
}
|
| 240 |
return theme('movino_video_list', $videos);
|
| 241 |
|
| 242 |
// Generate a single video page.
|
| 243 |
} elseif ($type = 'video') {
|
| 244 |
|
| 245 |
// Redirect to the node if movino nodes are enabled and it exists.
|
| 246 |
if (module_exists('movino_node') && $nid = movino_node_get_video_nid($server_id, $video_id)) {
|
| 247 |
drupal_goto('node/' . $nid);
|
| 248 |
}
|
| 249 |
|
| 250 |
$video = movino_get_video($server_id, $video_id);
|
| 251 |
if (!empty($video) && is_array($video)) {
|
| 252 |
// Found a matching video.
|
| 253 |
drupal_set_title(_movino_video_title($video));
|
| 254 |
return theme_movino_content($video, TRUE, FALSE, TRUE);
|
| 255 |
}
|
| 256 |
|
| 257 |
$msg = t('The video you requested does not exist.');
|
| 258 |
}
|
| 259 |
|
| 260 |
drupal_set_title($title);
|
| 261 |
return $msg;
|
| 262 |
}
|
| 263 |
|
| 264 |
|
| 265 |
/**
|
| 266 |
* Theme function for lists of video.
|
| 267 |
*
|
| 268 |
* @param array $videos
|
| 269 |
* The videos you want to list
|
| 270 |
* @param string $shorten_titles
|
| 271 |
* Optionally shorten long titles.
|
| 272 |
*
|
| 273 |
* @return string of HTML
|
| 274 |
*/
|
| 275 |
function theme_movino_video_list($videos, $pager = TRUE, $limit = 10, $element = 0) {
|
| 276 |
|
| 277 |
// Pager behaviour from pager_query().
|
| 278 |
global $pager_page_array, $pager_total, $pager_total_items;
|
| 279 |
$page = isset($_GET['page']) ? $_GET['page'] : '';
|
| 280 |
$pager_page_array = explode(',', $page);
|
| 281 |
$pager_total_items[$element] = count($videos);
|
| 282 |
$pager_total[$element] = ceil($pager_total_items[$element] / $limit);
|
| 283 |
$pager_page_array[$element] = max(0, min((int)$pager_page_array[$element], ((int)$pager_total[$element]) - 1));
|
| 284 |
|
| 285 |
if ($pager) {
|
| 286 |
$output .= theme('pager', array(), $limit, $element);
|
| 287 |
}
|
| 288 |
|
| 289 |
// Check that we have videos to display.
|
| 290 |
if (empty($videos) || !is_array($videos)) {
|
| 291 |
$output .= t('No videos available');
|
| 292 |
} else {
|
| 293 |
|
| 294 |
$first_video = array_shift($videos);
|
| 295 |
$output .= '<div class="movino-video-list movino-video-list-'.$first_video['type'].'">';
|
| 296 |
array_unshift($videos, $first_video);
|
| 297 |
|
| 298 |
// Filter out the videos to show on this page.
|
| 299 |
$offset = ($pager ? $pager_page_array[$element] : 0);
|
| 300 |
if ($limit > 0) {
|
| 301 |
$display_videos = array_slice($videos, ($offset * $limit), $limit);
|
| 302 |
} else {
|
| 303 |
$display_videos = $videos;
|
| 304 |
}
|
| 305 |
|
| 306 |
if (empty($videos)) {
|
| 307 |
$output .= t('Invalid page request.');
|
| 308 |
} else {
|
| 309 |
foreach ($display_videos as $video) {
|
| 310 |
$output .= '<div class="movino-content-list-item">';
|
| 311 |
$output .= theme('movino_content', $video, FALSE);
|
| 312 |
$output .= '</div>';
|
| 313 |
}
|
| 314 |
}
|
| 315 |
$output .= '</div>';
|
| 316 |
}
|
| 317 |
if ($pager) {
|
| 318 |
$output .= theme('pager', array(), $limit, $element);
|
| 319 |
}
|
| 320 |
|
| 321 |
return $output;
|
| 322 |
}
|