/[drupal]/contributions/modules/webmedia/webmedia.module
ViewVC logotype

Contents of /contributions/modules/webmedia/webmedia.module

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


Revision 1.1 - (show annotations) (download) (as text)
Thu Jun 15 00:05:25 2006 UTC (3 years, 5 months ago) by khoogheem
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/x-php
support for streaming video into drupal
1 <?php
2 /*
3 * $Author: kevinh $
4 * $Date: 2006/06/14 23:10:39 $
5 * $Header: /Users/kevinh/Drupal\040Development/modules/RCS/webmedia.module,v 1.3 2006/06/14 23:10:39 kevinh Exp $
6 * $Log: webmedia.module,v $
7 * Revision 1.3 2006/06/14 23:10:39 kevinh
8 * updated to handle the owe_country info
9 *
10 * Revision 1.2 2006/06/14 03:08:55 kevinh
11 * Added language support and fixed settings
12 *
13 * Revision 1.1 2006/06/13 20:09:48 kevinh
14 * Initial revision
15 *
16 */
17
18 ////////////////////////////////////////////////////////
19 // //
20 // by: Kevin A. Hoogheem //
21 // (kevin@hoogheem.net) //
22 // //
23 // You can redistribute this software under the terms //
24 // of the GNU General Public License as published by //
25 // the Free Software Foundation; either version 2 of //
26 // the License, or (at your option) any later //
27 // version. //
28 // //
29 // You should have received a copy of the GNU General //
30 // Public License along with this program; if not, //
31 // write to the Free Software Foundation, Inc., 59 //
32 // Temple Place, Suite 330, Boston, MA 02111-1307 USA //
33 // //
34 // Copyright 2004 by Kevin A. Hoogheem //
35 // Please keep this copyright information intact. //
36 ////////////////////////////////////////////////////////
37 /**
38 * @file
39 * Enables users to submit TV/Radio Stations that are streaming content.
40 */
41 /*
42 CREATE TABLE IF NOT EXISTS `webmedia` (
43 `nid` int(11) NOT NULL default '0',
44 `station` varchar(80) NOT NULL default '',
45 `description` text NOT NULL,
46 `country` text NOT NULL,
47 `language` text NOT NULL,
48 `stationurl` varchar(120) NOT NULL default '',
49 `url` varchar(120) NOT NULL default '',
50 `live` tinyint(1) NOT NULL default '0',
51 `media` tinyint(2) NOT NULL default '0',
52 `bitrate` int(5) NOT NULL default '0',
53 PRIMARY KEY (`nid`)
54 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
55
56 */
57
58 function webmedia_help($section) {
59 switch ($section) {
60 case 'admin/modules#description':
61 // This description is shown in the listing at admin/modules.
62 return t('TV/Radio Broadcasts on the Internet');
63 case 'node/add#webmedia':
64 // This description shows up when users click "create content."
65 return t('TV/Radio Broadcasts on the Internet.');
66 }
67 }
68
69 function webmedia_node_name($node) {
70 return t('Web Media');
71 }
72
73 /**
74 * Implementation of hook_access().
75 *
76 * Node modules may implement node_access() to determine the operations
77 * users may perform on nodes. This example uses a very common access pattern.
78 */
79 function webmeida_access($op, $node) {
80 global $user;
81
82 if ($op == 'create') {
83 // Only users with permission to do so may create this node type.
84 return user_access('create web media node');
85 }
86
87 // Users who create a node may edit or delete it later, assuming they have the
88 // necessary permissions.
89 if ($op == 'update' || $op == 'delete') {
90 if (user_access('edit own web media nodes') && ($user->uid == $node->uid)) {
91 return TRUE;
92 }
93 }
94
95 }
96
97 function webmedia_perm() {
98 return array('create web media node', 'edit own web media nodes', 'view web media feed');
99 }
100
101 function webmedia_menu($may_cache) {
102 $items = array();
103
104 if ($may_cache) {
105 $items[] = array('path' => 'node/add/webmedia', 'title' => t('Web Media'),
106 'access' => user_access('create web media node'));
107 }
108
109 $items[] = array('path' => 'node/view/webmedia', 'title' => t('redirect webmedia'),
110 'access' => user_access('view web media feed'),
111 'callback' => '_webmedia_redirect_url',
112 'type' => MENU_CALLBACK);
113
114 return $items;
115 }
116
117 function webmedia_form(&$node) {
118 $aFeed_Type = array (
119 "0" => "<Pick Media Type>",
120 "1" => "Quicktime",
121 "2" => "MPEG-4",
122 "3" => "Real",
123 "4" => "Windows Media",
124 "5" => "Flash",
125 "6" => "SDP"
126 );
127
128 $output = '';
129
130 // In order to be able to attach taxonomy terms to this node, we need
131 // to display the appropriate form elements.
132 if (function_exists('taxonomy_node_form')) {
133 $output .= implode('', taxonomy_node_form('webmedia', $node));
134 }
135
136 // Now we define the form elements specific to our node type.
137 $feed_info .= form_textfield(t('Station URL'), 'stationurl', $node->stationurl, 30, 500, t('URL for Station'), NULL, FALSE );
138
139 if( module_exist("owe_country") ){
140 $feed_info .= form_select(t('Country'), 'country', $node->country, owe_api_get_country_list(), t('Country of the Feed'), $extra = 0, FALSE, FALSE);
141 }else{
142 $feed_info .= form_textfield(t('Country'), 'country', $node->country, 30, 80, t('Country of the Feed'), NULL, TRUE );
143 }
144 if( module_exist("owe_lang") ){
145 $feed_info .= form_select(t('Language'), 'language', $node->language, owe_api_get_langs_by_region(), t('Language of the Feed'), $extra = 0, FALSE, FALSE);
146 }else{
147 $feed_info .= form_textfield(t('Language'), 'language', $node->language, 30, 120, t('Language of the Feed'), NULL, TRUE );
148 }
149 $feed_info .= form_textarea(t('Description'), 'description', $node->description, 30, 5, t('A Description of the Family Name') );
150 $feed_info .= form_textfield(t('Feed URL'), 'url', $node->url, 30, 500, t('URL Of Feed'), NULL, TRUE );
151 $feed_info .= form_checkbox(t('Live'), 'live', $value = 1, $node->live, t('Live Feed or recorded replay.'), NULL, TRUE);
152 $feed_info .= form_select(t('Media Type'), 'media', $node->media, $aFeed_Type, t('Media Type of the Feed'), $extra = 0, FALSE, TRUE);
153 $feed_info .= form_textfield(t('Bitrate'), 'bitrate', $node->bitrate, 5, 5, t('Bitrate in Kbps'), NULL, TRUE );
154
155 $output .= form_group("Station Informaiton", NULL, $feed_info);
156
157
158 return $output;
159 }
160
161 function webmedia_settings(){
162 $aTrueFalse = array (
163 "True" => "Yes",
164 "False" => "No"
165 );
166
167 $output .= form_textfield(t('Player Height'), 'webmedia_player_height', variable_get('webmedia_player_height', '297'),
168 4, 4, t('The Height of the embeded player') );
169 $output .= form_textfield(t('Player Width'), 'webmedia_player_width', variable_get('webmedia_player_width', '420'),
170 4, 4, t('The Width of the embeded player') );
171 $output .= form_select(t('Autoplay'), 'webmedia_autoplay', variable_get('webmedia_autoplay', 'False'), $aTrueFalse,
172 t('Should the feed play on page load.'), NULL, FALSE);
173 $output .= form_select(t('Show Controller'), 'webmedia_controller', variable_get('webmedia_controller', 'False'), $aTrueFalse,
174 t('Show the Player controller.'), NULL, FALSE);
175 $output .= form_select(t('Loop Video'), 'webmedia_loop', variable_get('webmedia_loop', 'False'), $aTrueFalse,
176 t('Loop video if not live streaming.'), NULL, FALSE);
177 $output .= form_select(t('Hide Real Feed URL'), 'webmedia_hideurl', variable_get('webmedia_hideurl', 'False'), $aTrueFalse,
178 t('Hide the Real URL for Feed (not working yet).'), NULL, FALSE);
179
180
181 return $output;
182 }
183
184 function webmedia_validate(&$node){
185 if($node->media == 0) {
186 form_set_error('media', t('Media Type Must Be Selected'));
187 }
188
189 if($node->stationurl){
190 if( !_is_url($node->stationurl) ){
191 form_set_error('stationurl', t('Please use a valid http:// formed url'));
192 }
193 }
194
195 if( !is_numeric($node->bitrate) ){
196 form_set_error('bitrate', t('Bitrate must be a number'));
197 }
198
199 }
200
201 function webmedia_insert($node){
202 db_query("INSERT INTO {webmedia}
203 (nid, station, description, country, language, stationurl, url, live, media, bitrate)
204 VALUES
205 (%d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d)",
206 $node->nid, $node->title, $node->description, $node->country, $node->language,
207 check_url($node->stationurl), $node->url, $node->live, $node->media, $node->bitrate
208 );
209 }
210
211 function webmedia_update($node){
212 db_query("UPDATE {webmedia}
213 SET
214 station = '%s', description = '%s', country = '%s', language = '%s', stationurl = '%s',
215 url = '%s' , live = %d, media = %d, bitrate = %d
216 WHERE nid = %d",
217 $node->title, $node->description, $node->country, $node->language, check_url($node->stationurl),
218 $node->url, $node->live, $node->media, $node->bitrate, $node->nid
219 );
220 }
221
222 function node_example_delete($node) {
223 db_query('DELETE FROM {webmedia} WHERE nid = %d', $node->nid);
224 }
225
226 function webmedia_load($node) {
227 $info = db_fetch_object(db_query('SELECT * FROM {webmedia} WHERE nid = %d', $node->nid));
228
229 return $info;
230 }
231
232 function webmedia_view(&$node, $teaser = FALSE, $page = FALSE){
233 /* if(!$node->teaser){
234 $breadcrumb = drupal_get_breadcrumb();
235 $breadcrumb[] = l(drupal_get_title(), $_GET['q']);
236 drupal_set_breadcrumb($breadcrumb);
237 }
238 */
239
240 $node->body = theme('webmedia_body', $node);
241 $node->teaser = theme('webmedia_teaser', $node);
242 }
243
244
245 function theme_webmedia_body($node) {
246
247 $output = '<div class="webmedia_body">';
248 if( $node->description){
249 $output .= t('<strong>Description:</strong> <p>%description</p>', array('%description' => $node->description));
250 }
251 if( module_exist("owe_country") ){
252 $wInfo = db_fetch_object(db_query("SELECT country_short_name FROM {owe_country} where cid = $node->country"));
253 $output .= t('<strong>Country:</strong> %country', array('%country' => $wInfo->country_short_name));
254 }else{
255 $output .= t('<strong>Country:</strong> %country', array('%country' => $node->country));
256 }
257 $output .= "<p>";
258 $output .= t('<strong>Language:</strong> %language', array('%language' => $node->language));
259 $output .= "</p>";
260 $output .= "<p>";
261 if( $node->live ){
262 $output .= t('<strong>Feed:</strong> live');
263 }else{
264 $output .= t('<strong>Feed:</strong> recorded');
265 }
266 $output .= "</p>";
267
268 if ( user_access('view web media feed') ) {
269 $output .= _build_embed($node->media, $node->url, $node->nid);
270 }else {
271 $destination= drupal_get_destination();
272 $output .= t('<p><em><strong>You must <a href=%login&%destination>login</a> to view the feed for %title</em></strong>',
273 array('%login' => '?q=user/login', '%title' => $node->title, '%destination' => "destination=/node/$node->nid"));
274 }
275
276 if( $node->bitrate){
277 $output .= t('<p><strong>Bitrate:</strong> %bitrateKbps</p>', array('%bitrate' => $node->bitrate));
278 }
279
280 if( $node->stationurl){
281 $output .= t('<p><strong>Station Website:</strong> <a href=%stationurl title=%title target=\"_new\">%title</a></p>',
282 array('%stationurl' => check_url($node->stationurl), '%title' => $node->station));
283 }
284
285 $output .= '</div>';
286 return $output;
287 }
288
289 function theme_webmedia_teaser($node) {
290 $output = '<div class="webmedia_teaser">';
291 if( $node->description){
292 $output .= t('<strong>Description:</strong> <p>%description</p>', array('%description' => $node->description));
293 }
294 if( module_exist("owe_country") ){
295 $wInfo = db_fetch_object(db_query("SELECT country_short_name FROM {owe_country} where cid = $node->country"));
296 $output .= t('<strong>Country:</strong> %country', array('%country' => $wInfo->country_short_name));
297 }else{
298 $output .= t('<strong>Country:</strong> %country', array('%country' => $node->country));
299 }
300
301 $output .= "<p>";
302 if( $node->live ){
303 $output .= t('<strong>Feed:</strong> live');
304 }else{
305 $output .= t('<strong>Feed:</strong> recorded');
306 }
307 $output .= "</p>";
308
309 if( $node->bitrate){
310 $output .= t('<p><strong>Bitrate:</strong> %bitrateKbps</p>', array('%bitrate' => $node->bitrate));
311 }
312
313 $output .= '</div>';
314 return $output;
315 }
316
317
318 function _build_embed($media, $feed, $nid){
319 switch($media){
320 //Quicktime and SDP
321 case 5:
322 case 1:
323 $output = "
324 <OBJECT CLASSID='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B'
325 WIDTH='".variable_get('webmedia_player_width', 420)."'
326 HEIGHT='".variable_get('webmedia_player_height', 297)."'
327 CODEBASE='http://www.apple.com/qtactivex/qtplugin.cab'>
328 <PARAM name='SRC' VALUE='".$feed."'>
329 <PARAM name='AUTOPLAY' VALUE='".variable_get('webmedia_autoplay', 'True')."'>
330 <PARAM name='CONTROLLER' VALUE='".variable_get('webmedia_controller', 'False')."'>
331 <EMBED SRC='".$feed."'
332 WIDTH='".variable_get('webmedia_player_width', 420)."'
333 HEIGHT='".variable_get('webmedia_player_height', 297)."'
334 AUTOPLAY='".variable_get('webmedia_autoplay', 'True')."'
335 CONTROLLER='".variable_get('webmedia_controller', 'False')."'
336 PLUGINSPAGE='http://www.apple.com/quicktime/download/'>
337 </EMBED>
338 </OBJECT>
339 ";
340 break;
341 //MPEG-4
342 case 2:
343 $output = "
344 <OBJECT CLASSID='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B'
345 CODEBASE='http://www.apple.com/qtactivex/qtplugin.cab'
346 WIDTH='".variable_get('webmedia_player_width', 420)."'
347 HEIGHT='".variable_get('webmedia_player_height', 297)."' >
348 <PARAM NAME='src' VALUE='".$feed."' >
349 <PARAM NAME='autoplay' VALUE='".variable_get('webmedia_autoplay', 'True')."' >
350 <EMBED SRC='QTMimeType.pntg' TYPE='image/x-macpaint'
351 PLUGINSPAGE='http://www.apple.com/quicktime/download'
352 QTSRC='".$feed."'
353 WIDTH='".variable_get('webmedia_player_width', 420)."'
354 HEIGHT='".variable_get('webmedia_player_height', 297)."'
355 AUTOPLAY='".variable_get('webmedia_autoplay', 'True')."'>
356 </EMBED>
357 </OBJECT>
358 ";
359 break;
360 //Real Media
361 case 3:
362 $controller = variable_get('webmedia_controller', 'False');
363 $controller == "False" ? "none" : "all";
364 $output ="
365 <OBJECT ID=RVOCX CLASSID='clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA' WIDTH='420' HEIGHT='297'>
366 <PARAM name='src' value='".$feed."'>
367 <PARAM name='autostart' value='".variable_get('webmedia_autoplay', 'True')."'>
368 <PARAM name='controls' value='imagewindow'>
369 <PARAM name='console' value='video'>
370 <EMBED TYPE='audio/x-pn-realaudio-plugin'
371 SRC='".$feed."'
372 WIDTH='".variable_get('webmedia_player_width', 420)."'
373 HEIGHT='".variable_get('webmedia_player_height', 297)."'
374 AUTOSTART='".variable_get('webmedia_autoplay', 'True')."'
375 CONTROLS='".$controller."'
376 CONSOLE='video'>
377 </EMBED>
378 </OBJECT>";
379 break;
380 //Windows Media
381 case 4:
382 $loop = variable_get('webmedia_loop', 'False');
383 $loop == "False" ? "0" : "1";
384 $controller = variable_get('webmedia_controller', 'False');
385 $controller == "False" ? "none" : "all";
386 $output ="
387 <OBJECT ID='Player' name='Player'
388 height='".variable_get('webmedia_player_height', 297)."'
389 width='".variable_get('webmedia_player_width', 420)."'
390 CLASSID='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6'
391 STANDBY='Loading Media Feed...' >
392 <PARAM name='autoStart' value='".variable_get('webmedia_autoplay', 'True')."'>
393 <PARAM NAME='SendPlayStateChangeEvents' VALUE='True'>
394 <PARAM name='URL' value='".$feed."'>
395 <param name='uiMode' value='none'>
396 <param name='stretchToFit' value='true'>
397 <embed type='application/x-mplayer2'
398 pluginspage='http://www.microsoft.com/Windows/MediaPlayer/'
399 name='Player2'
400 EnableContextMenu='false'
401 autostart='".variable_get('webmedia_autoplay', 'True')."'
402 width='".variable_get('webmedia_player_width', 420)."'
403 height='".variable_get('webmedia_player_height', 297)."'
404 uiMode='none'
405 transparentstart='1'
406 loop='".$loop."'
407 controller='".variable_get('webmedia_controller', 'False')."'
408 ShowControls='".$controller."'
409 ShowDisplay=0
410 ShowStatusBar=1
411 src='".$feed."'></embed>
412 </OBJECT>";
413 break;
414 //Flash Video
415 case 5:
416 $output ="
417 <object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'
418 codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0'
419 width='".variable_get('webmedia_player_width', 420)."'
420 height='".variable_get('webmedia_player_height', 297)."' >
421 <param name='movie' value='".$feed."'>
422 <param name='quality' value='high'>
423 <param name='LOOP' value='".variable_get('webmedia_loop', 'False')."'>
424 <embed src='".$feed."'
425 width='".variable_get('webmedia_player_width', 420)."'
426 height='".variable_get('webmedia_player_height', 297)."'
427 loop='".variable_get('webmedia_loop', 'False')."'
428 quality='high'
429 pluginspage='http://www.macromedia.com/go/getflashplayer'
430 type='application/x-shockwave-flash'>
431 </embed >
432 </object >";
433 break;
434 }
435
436 return $output;
437 }
438
439 function _webmedia_redirect_url($nid){
440
441 $webmedia = db_fetch_object(db_query("SELECT * FROM {webmedia} where nid = $nid"));
442
443 $output = "fuck D: $webmedia->media";
444 switch($webmedia->media){
445 //Windows Media
446 case (4):
447 $output =
448 "[Reference]\nRef1=$webmedia->url";
449 break;
450 }
451 header("HTTP/1.1");
452 header("Content-Type: application/x-video");
453 header("Content-Disposition: attachment; filename=webmedia.asx");
454 header("Content-Transfer-Encoding: binary");
455 print $output;
456 }
457
458 function _is_url($url) {
459 if(!preg_match('#^http\:\/\/[a-z0-9-]+.([a-z0-9-]+.)?[a-z]+#i', $url)){
460 return false;
461 } else {
462 return true;
463 }
464 }
465
466 ?>

  ViewVC Help
Powered by ViewVC 1.1.2