| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * @file video.module 5 * 6 */ 7 8 /** 9 * Implementation of hook_init(). 10 */ 11 function video_init() { 12 drupal_add_css(drupal_get_path('module', 'video') .'/css/video.css'); 13 drupal_add_js(drupal_get_path('module', 'video') .'/js/video.js'); 14 } 15 16 /** 17 * Invokes hook_video_*action*() in every module. 18 * Eg : 19 * hook_video_submit() 20 * hook_video_insert() 21 * hook_video_preview() 22 * hook_video_delete() 23 * hook_video_load() 24 * hook_video_form() - to show values once upload is completed eg. Resolution, and Convert on Save etc 25 * 26 * We cannot use module_invoke() for this, because the arguments need to 27 * be passed by reference. 28 */ 29 function video_module_invoke($action, &$array, &$video = NULL, $other = NULL) { 30 foreach (module_list() as $module) { 31 $function = $module . '_video_' . $action; 32 if (function_exists($function)) { 33 $function($array, $video, $other); 34 } 35 } 36 } 37 38 /** 39 * Implementation of hook_perm(). 40 */ 41 function video_perm() { 42 return array('bypass conversion video', 'convert on submission', 'override player dimensions', 'use default thumb'); 43 } 44 45 /** 46 * Implementation of hook_menu(). 47 */ 48 function video_menu() { 49 $items = array(); 50 $items['admin/settings/video'] = array( 51 'title' => 'Video', 52 'description' => 'Configure different aspects of the video module and its plugins', 53 'page callback' => 'drupal_get_form', 54 'page arguments' => array('video_general_admin_settings'), 55 'file' => 'video.admin.inc', 56 'access arguments' => array('administer site configuration'), 57 'type' => MENU_NORMAL_ITEM, 58 ); 59 $items['admin/settings/video/general'] = array( 60 'title' => 'General', 61 'type' => MENU_DEFAULT_LOCAL_TASK, 62 'weight' => 0, 63 ); 64 $items['admin/settings/video/players'] = array( 65 'title' => 'Players', 66 'description' => 'Configure your player settings for each video extension.', 67 'page callback' => 'drupal_get_form', 68 'page arguments' => array('video_players_admin_settings'), 69 'access arguments' => array('administer site configuration'), 70 'file' => 'video.admin.inc', 71 'type' => MENU_LOCAL_TASK, 72 'weight' => 1, 73 ); 74 $items['admin/settings/video/transcoders'] = array( 75 'title' => 'Transcoders', 76 'description' => 'Configure your transcoder to convert your videos or extra thumbnails.', 77 'page callback' => 'drupal_get_form', 78 'page arguments' => array('video_transcoder_admin_settings'), 79 'access arguments' => array('administer site configuration'), 80 'file' => 'video.admin.inc', 81 'type' => MENU_LOCAL_TASK, 82 'weight' => 2, 83 ); 84 $items['admin/settings/video/presets'] = array( 85 'title' => 'Presets', 86 'description' => 'Configure your transcoder presets to convert your videos.', 87 'page callback' => 'drupal_get_form', 88 'page arguments' => array('video_preset_admin_settings'), 89 'access arguments' => array('administer site configuration'), 90 'file' => 'video.admin.inc', 91 'type' => MENU_LOCAL_TASK, 92 'weight' => 3, 93 ); 94 $items['admin/settings/video/metadata'] = array( 95 'title' => 'Metadata', 96 'description' => 'Configure your metadata settings.', 97 'page callback' => 'drupal_get_form', 98 'page arguments' => array('video_metadata_admin_settings'), 99 'access arguments' => array('administer site configuration'), 100 'file' => 'video.admin.inc', 101 'type' => MENU_LOCAL_TASK, 102 'weight' => 4, 103 ); 104 105 $items['admin/settings/video/filesystem'] = array( 106 'title' => 'File System', 107 'description' => 'Configure your file system settings.', 108 'page callback' => 'drupal_get_form', 109 'page arguments' => array('video_filesystem_admin_settings'), 110 'access arguments' => array('administer site configuration'), 111 'file' => 'video.admin.inc', 112 'type' => MENU_LOCAL_TASK, 113 'weight' => 5, 114 ); 115 116 $items['admin/settings/video/cron'] = array( 117 'title' => 'Cron Settings', 118 'description' => 'Configure your cron settings.', 119 'page callback' => 'drupal_get_form', 120 'page arguments' => array('video_cron_admin_settings'), 121 'access arguments' => array('administer site configuration'), 122 'file' => 'video.admin.inc', 123 'type' => MENU_LOCAL_TASK, 124 'weight' => 6, 125 ); 126 127 128 return $items; 129 } 130 131 /** 132 * Implementation of hook_theme(). 133 */ 134 function video_theme() { 135 $theme = array(); 136 $theme['video_thumbnails'] = array( 137 'arguments' => array('file' => NULL, 'alt' => '', 'title' => '', 'attributes' => NULL, 'getsize' => TRUE), 138 'file' => 'video.theme.inc', 139 ); 140 $theme['video_widget_preview'] = array( 141 'arguments' => array('item' => TRUE), 142 'file' => 'video.theme.inc', 143 ); 144 $theme['video_image'] = array( 145 'arguments' => array('file' => NULL, 'alt' => '', 'title' => '', 'attributes' => NULL, 'getsize' => TRUE, 'imagecache' => NULL), 146 'file' => 'video.theme.inc', 147 ); 148 $theme['video_widget_video_thumb'] = array( 149 'arguments' => array('item' => TRUE), 150 'file' => 'video.theme.inc', 151 ); 152 $theme['video_formatter_video_plain'] = array( 153 'arguments' => array('element' => NULL), 154 'file' => 'video_formatter.inc', 155 ); 156 $theme['video_formatter_video_nodelink'] = array( 157 'arguments' => array('element' => NULL, 'imagecache' => NULL), 158 'file' => 'video_formatter.inc', 159 ); 160 $theme['video_formatter_video_thumbnail'] = array( 161 'arguments' => array('element' => NULL, 'imagecache' => NULL), 162 'file' => 'video_formatter.inc', 163 ); 164 $theme['video_formatter_video_nonodelink'] = array( 165 'arguments' => array('element' => NULL, 'imagecache' => NULL), 166 'file' => 'video_formatter.inc', 167 ); 168 169 //$theme['video_formatter_video_colorbox'] = array( 170 // 'arguments' => array('element' => NULL, 'imagecache' => NULL), 171 // 'file' => 'video_formatter.inc', 172 //); 173 $theme['video_formatter_video_media_js'] = array( 174 'arguments' => array('element' => NULL), 175 'file' => 'video_formatter.inc', 176 ); 177 $theme['video_encoding_failed'] = array( 178 'arguments' => array(), 179 'file' => 'video_formatter.inc', 180 ); 181 $theme['video_inprogress'] = array( 182 'arguments' => array(), 183 'file' => 'video_formatter.inc', 184 ); 185 186 $path = drupal_get_path('module', 'video') . '/theme'; 187 //Lets setup our themes for our players 188 $players = video_video_players(); 189 foreach ($players as $tpl => $value) { 190 $theme[$tpl] = array( 191 'arguments' => array('video' => NULL, 'node' => NULL, 'themed_output' => NULL), 192 //#843368 fix 193 // 'file' => 'video_formatter.inc', 194 'template' => str_replace('_', '-', $tpl), 195 'path' => $path, 196 ); 197 } 198 //We need to add an flv theme buffer to allow users to override in their own module to add in extra parameters before 199 //calling our flv template file. 200 $theme['video_flv'] = array( 201 'arguments' => array('video' => NULL, 'node' => NULL), 202 'file' => 'video_formatter.inc' 203 ); 204 $theme['video_html5'] = array( 205 'arguments' => array('video' => NULL, 'node' => NULL), 206 'file' => 'video_formatter.inc' 207 ); 208 //setup our imagecache presets 209 if (module_exists('imagecache')) { 210 //we need formatters for each of our thumbnails. 211 //@todo create a function to check for our colorbox module and only add theme elements that could be used. 212 $thumb_types = array('video_nodelink', 'video_thumbnail', 'video_nonodelink'); //array('video_colorbox', 'video_nodelink'); 213 foreach ($thumb_types as $types) { 214 foreach (imagecache_presets() as $preset) { 215 $theme['video_formatter_' . $preset['presetname'] . '__' . $types] = array( 216 'arguments' => array('element' => NULL), 217 'function' => 'theme_video_formatter_imagecache', 218 'file' => 'video_formatter.inc' 219 ); 220 } 221 } 222 } 223 return $theme; 224 } 225 226 /** 227 * Implementation of CCK's hook_field_formatter_info(). 228 */ 229 function video_field_formatter_info() { 230 $formatters = array( 231 'video_plain' => array( 232 'label' => t('Video'), 233 'field types' => array('filefield'), 234 'description' => t('Displays video files with player embedded.'), 235 ), 236 'video_nodelink' => array( 237 'label' => t('Video Thumbnail linked to node'), 238 'field types' => array('filefield'), 239 'description' => t('Displays the video thumbnail and links to the node.'), 240 ), 241 'video_thumbnail' => array( 242 'label' => t('Video Thumbnail'), 243 'field types' => array('filefield'), 244 'description' => t('Displays the video thumbnail.'), 245 ), 246 'video_nonodelink' => array( 247 'label' => t('Video Thumbnail'), 248 'field types' => array('filefield'), 249 'description' => t('Displays the video thumbnail (no link to node).'), 250 ), 251 //'video_colorbox' => array( 252 // 'label' => t('Video Thumbnail to Colorbox'), 253 // 'field types' => array('filefield'), 254 // 'description' => t('Displays the video thumbnail and adds colorbox support.'), 255 //), 256 'video_media_js' => array( 257 'label' => t('Video inject with jMedia'), 258 'field types' => array('filefield'), 259 'description' => t('Displays the video by using jmedia javascript.'), 260 ), 261 ); 262 //setup our imagecache presets 263 if (module_exists('imagecache')) { 264 //we need formatters for each of our thumbnails. 265 $thumb_types = array('video_nodelink', 'video_thumbnail', 'video_nonodelink'); //array('video_colorbox', 'video_nodelink'); 266 foreach ($thumb_types as $types) { 267 foreach (imagecache_presets() as $preset) { 268 $formatters[$preset['presetname'] . '__' . $types] = array( 269 'label' => t('@preset @label', array('@preset' => $preset['presetname'], '@label' => $formatters[$types]['label'])), 270 'field types' => array('filefield'), 271 ); 272 } 273 } 274 } 275 return $formatters; 276 } 277 278 /** 279 * Implmentation of hook_cron(). 280 */ 281 function video_cron() { 282 if (variable_get('video_cron', TRUE)) { 283 // This is a hack to execute S3 uploads before Zencoder 284 $filesystem = variable_get('vid_filesystem', 'drupal'); 285 $transcoder = variable_get('vid_convertor', 'video_ffmpeg'); 286 if ($filesystem == 'video_s3' && $transcoder == 'video_zencoder') { 287 video_s3_cron(); 288 } 289 290 module_load_include('inc', 'video', '/includes/conversion'); 291 $video_conversion = new video_conversion; 292 $video_conversion->run_queue(); 293 } 294 } 295 296 /** 297 * Implementation of hook_form_alter() 298 * @param string $form 299 * @param <type> $form_state 300 * @param <type> $form_id 301 */ 302 function video_form_alter(&$form, &$form_state, $form_id) { 303 if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) { 304 $form['buttons']['submit']['#submit'][] = 'video_node_update_submit'; 305 $form['#validate'][] = 'video_add_adminjs'; // Make sure the js is loaded even when the form is cached 306 video_add_adminjs(); 307 } 308 } 309 310 function video_node_update_submit($form, &$form_state) { 311 //lets update our video rending table to include the node id created 312 if (isset($form_state['nid']) && isset($form_state['values']['video_id']) && is_array($form_state['values']['video_id'])) { 313 foreach ($form_state['values']['video_id'] as $fid) { 314 // @TODO : check for enable trancoder 315 module_load_include('inc', 'video', '/includes/transcoder'); 316 $transcoder = new video_transcoder; 317 $video = array('nid' => $form_state['nid'], 'fid' => $fid); 318 $transcoder->update_job($video); 319 // Lets other module to know to update 320 video_module_invoke('update', $form, $form_state); 321 } 322 } 323 } 324 325 /** 326 * Implementation of hook_file_delete(). 327 */ 328 function video_file_delete($file) { 329 if (empty($file->fid)) { 330 watchdog('video', 'video_file_delete called with empty argument', array(), WATCHDOG_ERROR); 331 return; 332 } 333 334 // TODO: only execute this method if the file was uploaded by this module. 335 336 // Let other modules to know about the file delete 337 // before we delete the file, so the module has access to information in the database. 338 video_module_invoke('delete', $file); 339 340 // @TODO : check for enable trancoder 341 // delete the transcoder job 342 module_load_include('inc', 'video', '/includes/transcoder'); 343 $transcoder = new video_transcoder; 344 $transcoder->delete_job($file); 345 346 // TODO: Move this to the file system class 347 // Now lets delete our video thumbnails and folder. 348 $video_thumb_path = variable_get('video_thumb_path', 'video_thumbs'); 349 $thumb_folder = file_directory_path() .'/'. $video_thumb_path .'/'. $file->fid .'/'; 350 351 // Recursively delete our folder and files. 352 if (is_dir($thumb_folder)) { 353 rmdirr($thumb_folder); 354 355 // Delete any entries in the files table that may refer to the above path. 356 // TODO: this is a slow query 357 db_query('DELETE FROM {files} WHERE filepath LIKE "%b%%"', 358 strtr(db_escape_string($thumb_folder), array('%' => '\%', '_' => '\_')) 359 ); 360 } 361 } 362 363 /** 364 * Implementation of hook_views_api(). 365 */ 366 function video_views_api() { 367 return array( 368 'api' => 2.0, 369 'path' => drupal_get_path('module', 'video') .'/views', 370 ); 371 } 372 373 /** 374 * Returns the width/height and aspect ratio of the video 375 * 376 * @todo: move this to the transcoder class instead? 377 */ 378 function _video_aspect_ratio($video) { 379 //lets get our video dimensions from the file 380 module_load_include('inc', 'video', '/includes/transcoder'); 381 $transcoder = new video_transcoder; 382 $wxh = $transcoder->get_dimensions($video); 383 384 if (empty($wxh) || empty($wxh['width']) || empty($wxh['height'])) { 385 // No width and height found. This may be because the transcoder does not support retrieving dimensions. 386 return null; 387 } 388 389 return array( 390 'width' => $wxh['width'], 391 'height' => $wxh['height'], 392 'ratio' => number_format($wxh['width'] / $wxh['height'], 4), 393 ); 394 } 395 396 /** 397 * Default video dimensions. 398 */ 399 function video_default_dimensions() { 400 return "176x144\n352x288\n704x576\n1408x1152\n128x96\n160x120\n320x240\n640x480\n800x600\n1024x768\n1600x1200\n2048x1024\n1280x1024\n2560x2048\n5120x4096\n852x480\n1366x768\n1600x1024\n1920x1200\n2560x1600\n3200x2048\n3840x2400\n6400x4096\n7680x4800\n320x200\n640x350\n852x480\n1280x720\n1920x1080"; 401 } 402 403 /** 404 * Return our list of video extensions and their associated player. 405 */ 406 function video_video_extensions() { 407 return array( 408 'divx' => 'video_play_divx', 409 'mkv' => 'video_play_divx', 410 'mov' => 'video_play_quicktime', 411 '3gp' => 'video_play_quicktime', 412 '3g2' => 'video_play_quicktime', 413 'mp4' => 'video_play_quicktime', 414 'rm' => 'video_play_realmedia', 415 'f4v' => 'video_play_flv', 416 'flv' => 'video_play_flv', 417 'swf' => 'video_play_flash', 418 'dir' => 'video_play_dcr', 419 'dcr' => 'video_play_dcr', 420 'asf' => 'video_play_windowsmedia', 421 'wmv' => 'video_play_windowsmedia', 422 'avi' => 'video_play_windowsmedia', 423 'mpg' => 'video_play_windowsmedia', 424 'mpeg' => 'video_play_windowsmedia', 425 'ogg' => 'video_play_theora', 426 'ogv' => 'video_play_theora', 427 'webm' => 'video_play_theora' 428 ); 429 } 430 431 /** 432 * Return our supported video players. 433 */ 434 function video_video_players() { 435 return array( 436 'video_play_html5' => t('HTML5 Player'), 437 'video_play_divx' => t('Divx Player'), 438 'video_play_quicktime' => t('Quicktime'), 439 'video_play_realmedia' => t('Real Media Player'), 440 'video_play_flv' => t('FLV Flash Players'), 441 'video_play_flash' => t('SWF Flash Player'), 442 'video_play_dcr' => t('Director/Shockwave'), 443 'video_play_windowsmedia' => t('Windows Media Player'), 444 'video_play_theora' => t('Theora Player'), 445 ); 446 } 447 448 /** 449 * Utility function to remove all files and directories recursively. 450 */ 451 function rmdirr($dir) { 452 if ($objs = glob($dir . "/*")) { 453 foreach ($objs as $obj) { 454 is_dir($obj) ? rmdirr($obj) : unlink($obj); 455 } 456 } 457 @rmdir($dir); 458 } 459 460 function video_thumb_path($video = NULL, $checkexistence = TRUE) { 461 $dir = $basedir = file_directory_path() .'/'. variable_get('video_thumb_path', 'video_thumbs'); 462 463 if (is_array($video)) { 464 $dir .= '/'. $video['fid']; 465 } 466 elseif (is_object($video)) { 467 $dir .= '/'. $video->fid; 468 } 469 elseif ($video > 0) { 470 $dir .= '/'. intval($video); 471 } 472 elseif ($video != NULL) { 473 return NULL; 474 } 475 476 if ($checkexistence) { 477 field_file_check_directory(file_directory_path(), FILE_CREATE_DIRECTORY); 478 field_file_check_directory($basedir, FILE_CREATE_DIRECTORY); 479 480 if ($dir != $basedir) { 481 field_file_check_directory($dir, FILE_CREATE_DIRECTORY); 482 } 483 } 484 485 return $dir; 486 } 487 488 function video_add_adminjs() { 489 drupal_add_js(drupal_get_path('module', 'video') .'/js/video.admin.js'); 490 } 491 492 /** 493 * Increase the database timeout in preparation for long time 494 * operations, such as S3 uploads and local transcoding. 495 * 496 * Reconnecting to the database after this operation is not possible 497 * due to the way db_set_active stores the connection identifiers. 498 * 499 * At this moment, only mysqli and mysql are handled. The timeout is 500 * set to 1 day 501 */ 502 function _video_db_increase_timeout() { 503 global $db_type; 504 505 if ($db_type === 'mysqli' || $db_type === 'mysql') { 506 $timeout = 24 * 60 * 60; // one day 507 db_query('SET SESSION wait_timeout = %d', $timeout); 508 } 509 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |