| 1 |
<?php // $Id: movino.module,v 1.5 2008/05/04 15:02: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 |
define('MOVINO_DEBUG', FALSE);
|
| 21 |
if (MOVINO_DEBUG) {
|
| 22 |
drupal_set_message('Movino debug messages active.', 'error');
|
| 23 |
}
|
| 24 |
|
| 25 |
|
| 26 |
// Load components.
|
| 27 |
// TODO: check if any of these can be left unloaded in some cases.
|
| 28 |
_movino_component('variables'); // Variable defaults
|
| 29 |
_movino_component('theme'); // Theme functions
|
| 30 |
_movino_component('feeds'); // Feed parsing
|
| 31 |
_movino_component('servers'); // Server handling
|
| 32 |
_movino_component('videos'); // Video metadata handling
|
| 33 |
_movino_component('players'); // Integration with external players
|
| 34 |
|
| 35 |
|
| 36 |
/**
|
| 37 |
* Implementation of hook_help().
|
| 38 |
*/
|
| 39 |
function movino_help($section) {
|
| 40 |
switch ($section) {
|
| 41 |
case 'admin/help#help':
|
| 42 |
// TODO: expand
|
| 43 |
$output = '<p>'. t('Movino provides live video streaming capabilities to your Drupal website.') . '</p>';
|
| 44 |
return $output;
|
| 45 |
}
|
| 46 |
}
|
| 47 |
|
| 48 |
|
| 49 |
function movino_menu($may_cache) {
|
| 50 |
|
| 51 |
$items = array();
|
| 52 |
|
| 53 |
if (!$may_cache){
|
| 54 |
|
| 55 |
if (!defined('MOVINO_STANDALONE')) {
|
| 56 |
// Add default stylesheet.
|
| 57 |
drupal_add_css(drupal_get_path('module', 'movino') . '/movino.css');
|
| 58 |
|
| 59 |
// Update videos.
|
| 60 |
|
| 61 |
// Instead of using Cron, update on every page load
|
| 62 |
if (variable_get('movino_use_cron', 0) == 0 && variable_get('movino_use_dedicated_cron', 0) == 0) {
|
| 63 |
|
| 64 |
// Do not update if the user does not have access to the content.
|
| 65 |
if (user_access('view live Movino content') || user_access('view archived Movino content')) {
|
| 66 |
movino_update_video_cache();
|
| 67 |
}
|
| 68 |
}
|
| 69 |
}
|
| 70 |
|
| 71 |
if (variable_get('movino_use_dedicated_cron', 0) == 1) {
|
| 72 |
$items[] = array(
|
| 73 |
'title' => t('Movino feed update'),
|
| 74 |
'path' => 'movino/update',
|
| 75 |
'description' => t('Update feeds.'),
|
| 76 |
'callback' => '_movino_callback_update_feeds',
|
| 77 |
'access' => TRUE,
|
| 78 |
'type' => MENU_CALLBACK,
|
| 79 |
);
|
| 80 |
}
|
| 81 |
}
|
| 82 |
|
| 83 |
return $items;
|
| 84 |
}
|
| 85 |
|
| 86 |
|
| 87 |
/**
|
| 88 |
* Callback function for dedicated movino cron.
|
| 89 |
*/
|
| 90 |
function _movino_callback_update_feeds() {
|
| 91 |
if (arg(2) == 'live') {
|
| 92 |
movino_update_video_cache('live');
|
| 93 |
} elseif (arg(2) == 'archived') {
|
| 94 |
movino_update_video_cache('archived');
|
| 95 |
} else {
|
| 96 |
movino_update_video_cache();
|
| 97 |
}
|
| 98 |
|
| 99 |
// Clear page cache
|
| 100 |
// cache_clear_all();
|
| 101 |
|
| 102 |
echo 'ok';
|
| 103 |
exit(0);
|
| 104 |
}
|
| 105 |
|
| 106 |
|
| 107 |
/**
|
| 108 |
* Implementation of hook_perm().
|
| 109 |
*/
|
| 110 |
function movino_perm() {
|
| 111 |
return array(
|
| 112 |
'administer Movino',
|
| 113 |
'upload Movino content',
|
| 114 |
'view live Movino content',
|
| 115 |
'view archived Movino content',
|
| 116 |
'edit own Movino content',
|
| 117 |
);
|
| 118 |
}
|
| 119 |
|
| 120 |
|
| 121 |
/**
|
| 122 |
* Implementation of hook_cron().
|
| 123 |
*/
|
| 124 |
function movino_cron() {
|
| 125 |
|
| 126 |
// If the site admin has chosen to use cron,
|
| 127 |
// update cache on every call to cron.php
|
| 128 |
if (variable_get('movino_use_cron', 0) == 1) {
|
| 129 |
movino_update_video_cache();
|
| 130 |
}
|
| 131 |
}
|
| 132 |
|
| 133 |
|
| 134 |
/**
|
| 135 |
* Implementation of hook_block().
|
| 136 |
*/
|
| 137 |
function movino_block($op = 'list', $delta = 0, $edit = array()) {
|
| 138 |
|
| 139 |
if ($op == 'list') {
|
| 140 |
// Block descriptions.
|
| 141 |
$blocks[0]['info'] = t('Movino: Server info');
|
| 142 |
return $blocks;
|
| 143 |
}
|
| 144 |
else if ($op == 'view') {
|
| 145 |
$block = array();
|
| 146 |
|
| 147 |
switch ($delta) {
|
| 148 |
|
| 149 |
case 0:
|
| 150 |
$block['subject'] = t('Server info');
|
| 151 |
$block['content'] = '';
|
| 152 |
|
| 153 |
// Fetch server info
|
| 154 |
$servers = movino_get_servers();
|
| 155 |
if (empty($servers)) {
|
| 156 |
return $block;
|
| 157 |
}
|
| 158 |
|
| 159 |
// Add connect info for all servers.
|
| 160 |
foreach ($servers as $id => $server) {
|
| 161 |
|
| 162 |
// Only show info when the server is properly configured
|
| 163 |
// and the user is allowed access as a video source.
|
| 164 |
if (user_access('upload Movino content', $user_account)) {
|
| 165 |
|
| 166 |
$block['content'] .=
|
| 167 |
'<li>' .
|
| 168 |
'<span class="movino-server-name">' . $server['name'] . '</span>' .
|
| 169 |
' - ' .
|
| 170 |
'<span class="movino-server-info">http://' . $server['host'] . ':' . $server['source_port'] . '</span>' .
|
| 171 |
'</li>';
|
| 172 |
}
|
| 173 |
}
|
| 174 |
|
| 175 |
if (!empty($block['content'])) {
|
| 176 |
$block['content'] =
|
| 177 |
t('To stream content to this site, connect to one of the servers below using your favourite <a href="http://www.movino.org">Movino client</a>. If the server requires authentication, use your login details for this site.') .
|
| 178 |
'<ul>' . $block['content'] . '</ul>';
|
| 179 |
}
|
| 180 |
|
| 181 |
return $block;
|
| 182 |
|
| 183 |
}
|
| 184 |
}
|
| 185 |
}
|
| 186 |
|
| 187 |
|
| 188 |
/**
|
| 189 |
* Component loader
|
| 190 |
*
|
| 191 |
* @param string $component_id
|
| 192 |
* @param boolean $include
|
| 193 |
* If false, this function tells whether or not the component is included or not.
|
| 194 |
* If true, this function includes the component.
|
| 195 |
*/
|
| 196 |
function _movino_component($component_id, $include = TRUE, $get_all = FALSE) {
|
| 197 |
static $components = array();
|
| 198 |
|
| 199 |
// Return id of all currently loaded.
|
| 200 |
if ($get_all) {
|
| 201 |
return $components;
|
| 202 |
}
|
| 203 |
|
| 204 |
// Include the component.
|
| 205 |
if ($include) {
|
| 206 |
include_once(drupal_get_path('module', 'movino') . '/movino_' . $component_id . '.inc');
|
| 207 |
$components[$component_id] = TRUE;
|
| 208 |
return TRUE;
|
| 209 |
}
|
| 210 |
|
| 211 |
// Tell whether or not the component is included.
|
| 212 |
if (isset($components[$component_id])) {
|
| 213 |
return TRUE;
|
| 214 |
}
|
| 215 |
return FALSE;
|
| 216 |
}
|
| 217 |
|
| 218 |
|
| 219 |
/**
|
| 220 |
* Alternative to module_invoke_all().
|
| 221 |
* Supports one argument which is passed by reference.
|
| 222 |
*/
|
| 223 |
function movino_invoke_all($hook, &$arg) {
|
| 224 |
$modules = module_implements($hook);
|
| 225 |
if (!empty($modules)) {
|
| 226 |
foreach ($modules as $module) {
|
| 227 |
$function = $module . '_' . $hook;
|
| 228 |
$function($arg);
|
| 229 |
}
|
| 230 |
}
|
| 231 |
}
|
| 232 |
|
| 233 |
|
| 234 |
/**
|
| 235 |
* Generates the title of a video.
|
| 236 |
*
|
| 237 |
* @param array $video
|
| 238 |
* The video array
|
| 239 |
* @param boolean $shorten
|
| 240 |
* Whether or not long titles should be shortened.
|
| 241 |
*/
|
| 242 |
function _movino_video_title($video, $shorten = FALSE) {
|
| 243 |
if (empty($video['title'])) {
|
| 244 |
return t('Unnamed video');
|
| 245 |
}
|
| 246 |
|
| 247 |
if ($shorten && strlen($video['title']) > 22) {
|
| 248 |
return substr($video['title'], 0, 20) . '...';
|
| 249 |
}
|
| 250 |
|
| 251 |
return $video['title'];
|
| 252 |
}
|