rtMedia for WordPress, BuddyPress and bbPress - Version 2.0.2

Version Description

  • Delete functionality fixed
  • Edit functionality for Media Title and Media Description
  • Admins can manage which media types to allow
Download this release

Release Info

Developer rtcamp
Plugin Icon 128x128 rtMedia for WordPress, BuddyPress and bbPress
Version 2.0.2
Comparing to
See all releases

Code changes from version 2.0.1 to 2.0.2

includes/bp-media-actions.php CHANGED
@@ -5,13 +5,37 @@
5
* @since BP Media 2.0
6
*/
7
function bp_media_handle_uploads() {
8
- global $bp;
9
if (isset($_POST['action']) && $_POST['action'] == 'wp_handle_upload') {
10
if (isset($_FILES) && is_array($_FILES) && array_key_exists('bp_media_file', $_FILES) && $_FILES['bp_media_file']['name'] != '') {
11
$bp_media_entry = new BP_Media_Host_Wordpress();
12
try {
13
$title = isset($_POST['bp_media_title']) ? ($_POST['bp_media_title'] != "") ? $_POST['bp_media_title'] : pathinfo($_FILES['bp_media_file']['name'], PATHINFO_FILENAME) : pathinfo($_FILES['bp_media_file']['name'], PATHINFO_FILENAME);
14
- $entry = $bp_media_entry->add_media($title, $_POST['bp_media_description']);
15
$bp->{BP_MEDIA_SLUG}->messages['updated'][] = __('Upload Successful', 'bp-media');
16
} catch (Exception $e) {
17
$bp->{BP_MEDIA_SLUG}->messages['error'][] = $e->getMessage();
@@ -83,7 +107,26 @@ function bp_media_delete_activity_handler($activity_id, $user) {
83
}
84
85
/* Adds bp_media_delete_activity_handler() function to be called on bp_activity_before_action_delete_activity hook */
86
- add_action('bp_activity_before_action_delete_activity', 'bp_media_delete_activity_handler', 10, 2);
87
88
/**
89
* Called on bp_init by screen functions
@@ -126,18 +169,21 @@ function bp_media_set_query() {
126
}
127
128
/**
129
- * Adds a download button on single entry pages of media files.
130
*
131
* @since BP Media 2.0
132
*/
133
- function bp_media_action_download_button() {
134
if(!in_array('bp_media_current_entry', $GLOBALS))
135
return false;
136
global $bp_media_current_entry;
137
- if($bp_media_current_entry!=NULL)
138
echo '<a href="'.$bp_media_current_entry->get_attachment_url().'" class="button item-button bp-secondary-action bp-media-download" title="Download">Download</a>';
139
}
140
- add_action('bp_activity_entry_meta', 'bp_media_action_download_button');
141
142
/* Should be used with Content Disposition Type for media files set to attachment */
143
@@ -183,4 +229,29 @@ function bp_media_footer() { ?>
183
}
184
if(get_option('bp_media_remove_linkback')!='1')
185
add_action('bp_footer','bp_media_footer');
186
?>
5
* @since BP Media 2.0
6
*/
7
function bp_media_handle_uploads() {
8
+ global $bp,$bp_media_options;
9
+ global $bp_media_options;
10
+ $bp_media_options = get_option('bp_media_options',array(
11
+ 'videos_enabled' => true,
12
+ 'audio_enabled' => true,
13
+ 'images_enabled' => true,
14
+ ));
15
if (isset($_POST['action']) && $_POST['action'] == 'wp_handle_upload') {
16
if (isset($_FILES) && is_array($_FILES) && array_key_exists('bp_media_file', $_FILES) && $_FILES['bp_media_file']['name'] != '') {
17
+ if(preg_match('/image/',$_FILES['bp_media_file']['type'])){
18
+ if($bp_media_options['images_enabled']==false){
19
+ $bp->{BP_MEDIA_SLUG}->messages['error'][] = __('Image uploads are disabled');
20
+ return;
21
+ }
22
+ }
23
+ else if(preg_match('/video/',$_FILES['bp_media_file']['type'])){
24
+ if($bp_media_options['videos_enabled']==false){
25
+ $bp->{BP_MEDIA_SLUG}->messages['error'][] = __('Video uploads are disabled');
26
+ return;
27
+ }
28
+ }
29
+ else if(preg_match('/audio/',$_FILES['bp_media_file']['type'])){
30
+ if($bp_media_options['audio_enabled']==false){
31
+ $bp->{BP_MEDIA_SLUG}->messages['error'][] = __('Audio uploads are disabled');
32
+ return;
33
+ }
34
+ }
35
$bp_media_entry = new BP_Media_Host_Wordpress();
36
try {
37
$title = isset($_POST['bp_media_title']) ? ($_POST['bp_media_title'] != "") ? $_POST['bp_media_title'] : pathinfo($_FILES['bp_media_file']['name'], PATHINFO_FILENAME) : pathinfo($_FILES['bp_media_file']['name'], PATHINFO_FILENAME);
38
+ $entry = $bp_media_entry->add_media($title, array_key_exists('bp_media_description',$_POST)?$_POST['bp_media_description']:'');
39
$bp->{BP_MEDIA_SLUG}->messages['updated'][] = __('Upload Successful', 'bp-media');
40
} catch (Exception $e) {
41
$bp->{BP_MEDIA_SLUG}->messages['error'][] = $e->getMessage();
107
}
108
109
/* Adds bp_media_delete_activity_handler() function to be called on bp_activity_before_action_delete_activity hook */
110
+ //add_action('bp_before_activity_delete', 'bp_media_delete_activity_handler', 1, 2);
111
+ //The above hook isn't at right place yet, so skipped it till its corrected
112
+ //add_action('bp_activity_before_action_delete_activity', 'bp_media_delete_activity_handler', 10, 2);
113
+
114
+ function bp_media_delete_activity_handler_old($args){
115
+ global $bp_media_count,$wpdb;
116
+
117
+ if(!array_key_exists('id', $args))
118
+ return;
119
+
120
+ $activity_id=$args['id'];
121
+ $query="SELECT post_id from $wpdb->postmeta WHERE meta_key='bp_media_child_activity' AND meta_value=$activity_id";
122
+ $result=$wpdb->get_results($query);
123
+ if(!(is_array($result)&& count($result)==1 ))
124
+ return;
125
+ $post_id=$result[0]->post_id;
126
+ $media = new BP_Media_Host_Wordpress($post_id);
127
+ $media->delete_media();
128
+ }
129
+ add_action('bp_before_activity_delete', 'bp_media_delete_activity_handler_old');
130
131
/**
132
* Called on bp_init by screen functions
169
}
170
171
/**
172
+ * Adds a download button and edit button on single entry pages of media files.
173
*
174
* @since BP Media 2.0
175
*/
176
+ function bp_media_action_buttons() {
177
if(!in_array('bp_media_current_entry', $GLOBALS))
178
return false;
179
global $bp_media_current_entry;
180
+ if($bp_media_current_entry!=NULL){
181
+ if(bp_displayed_user_id()== bp_loggedin_user_id()) echo '<a href="'.$bp_media_current_entry->get_edit_url().'" class="button item-button bp-secondary-action bp-media-edit" title="Edit Media">Edit</a>';
182
echo '<a href="'.$bp_media_current_entry->get_attachment_url().'" class="button item-button bp-secondary-action bp-media-download" title="Download">Download</a>';
183
+
184
+ }
185
}
186
+ add_action('bp_activity_entry_meta', 'bp_media_action_buttons');
187
188
/* Should be used with Content Disposition Type for media files set to attachment */
189
229
}
230
if(get_option('bp_media_remove_linkback')!='1')
231
add_action('bp_footer','bp_media_footer');
232
+
233
+ function bp_media_upload_enqueue(){
234
+ $params=array(
235
+ 'url'=>plugins_url('bp-media-upload-handler.php',__FILE__),
236
+ 'runtimes' => 'gears,html5,flash,silverlight,browserplus',
237
+ 'browse_button' => 'bp-media-upload-browse-button',
238
+ 'container' => 'bp-media-upload-ui',
239
+ 'drop_element' => 'drag-drop-area',
240
+ 'filters' => array(array('title' => "Media Files",'extensions'=> "mp4,jpg,png,jpeg,gif,mp3")),
241
+ 'max_file_size' => '100mb',
242
+ 'multipart' => true,
243
+ 'urlstream_upload' => true,
244
+ 'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ),
245
+ 'silverlight_xap_url' => includes_url( 'js/plupload/plupload.silverlight.xap' ),
246
+ 'file_data_name' => 'bp_media_file', // key passed to $_FILE.
247
+ 'multi_selection' => true,
248
+ 'multipart_params' => array('action'=>'wp_handle_upload')
249
+ //var resize_height = 1024, resize_width = 1024,wpUploaderInit = {"runtimes":"html5,silverlight,flash,html4","browse_button":"plupload-browse-button","container":"plupload-upload-ui","drop_element":"drag-drop-area","file_data_name":"async-upload","multiple_queues":true,"max_file_size":"524288000b","url":"http:\/\/dummy\/pdfconverter\/wp-admin\/async-upload.php","flash_swf_url":"http:\/\/dummy\/pdfconverter\/wp-includes\/js\/plupload\/plupload.flash.swf","silverlight_xap_url":"http:\/\/dummy\/pdfconverter\/wp-includes\/js\/plupload\/plupload.silverlight.xap","filters":[{"title":"Allowed Files","extensions":"*"}],"multipart":true,"urlstream_upload":true,"multipart_params":{"post_id":0,"_wpnonce":"14a410f0fa","type":"","tab":"","short":"1"}};
250
+ );
251
+ wp_enqueue_script('bp-media-uploader',plugins_url('js/bp-media-uploader.js',__FILE__),array('plupload', 'plupload-html5', 'plupload-flash', 'plupload-silverlight', 'plupload-html4','plupload-handlers'));
252
+ wp_localize_script('bp-media-uploader','bp_media_uploader_params',$params);
253
+ wp_enqueue_style('bp-media-uploader',plugins_url('css/bp-media-uploader.css',__FILE__));
254
+ }
255
+ //add_action('wp_enqueue_scripts','bp_media_upload_enqueue');
256
+ //This is used only on the uploads page
257
?>
includes/bp-media-admin.php CHANGED
@@ -23,7 +23,12 @@ add_action(bp_core_admin_hook(), 'bp_media_add_admin_menu');
23
function bp_media_admin_menu() {
24
$bp_media_errors=array();
25
$bp_media_messages=array();
26
-
27
if(array_key_exists('submit', $_POST)){
28
check_admin_referer('bp_media_update_options');
29
if(array_key_exists('refresh_media_count', $_POST)){
@@ -38,8 +43,30 @@ function bp_media_admin_menu() {
38
else{
39
update_option('bp_media_remove_linkback', '0');
40
}
41
}
42
- ?>
43
<div class="metabox-fixed metabox-holder alignright">
44
<?php bp_media_default_admin_sidebar(); ?>
45
</div>
@@ -53,6 +80,7 @@ function bp_media_admin_menu() {
53
<?php }?>
54
<form method="post">
55
<?php wp_nonce_field( 'bp_media_update_options' ); ?>
56
<table class="form-table ">
57
<tbody>
58
<tr valign="top">
@@ -73,6 +101,38 @@ function bp_media_admin_menu() {
73
</tr>
74
</tbody>
75
</table>
76
<p class="submit"><input type="submit" name="submit" id="submit" class="button-primary" value="Save Changes"></p></form>
77
</div>
78
<?php
23
function bp_media_admin_menu() {
24
$bp_media_errors=array();
25
$bp_media_messages=array();
26
+ global $bp_media_options;
27
+ $bp_media_options = get_option('bp_media_options',array(
28
+ 'videos_enabled' => true,
29
+ 'audio_enabled' => true,
30
+ 'images_enabled' => true,
31
+ ));
32
if(array_key_exists('submit', $_POST)){
33
check_admin_referer('bp_media_update_options');
34
if(array_key_exists('refresh_media_count', $_POST)){
43
else{
44
update_option('bp_media_remove_linkback', '0');
45
}
46
+ if(array_key_exists('enable_videos',$_POST)){
47
+ $bp_media_options['videos_enabled'] = true;
48
+ }
49
+ else
50
+ {
51
+ $bp_media_options['videos_enabled'] = false;
52
+ }
53
+ if(array_key_exists('enable_audio',$_POST)){
54
+ $bp_media_options['audio_enabled'] = true;
55
+ }
56
+ else
57
+ {
58
+ $bp_media_options['audio_enabled'] = false;
59
+ }
60
+ if(array_key_exists('enable_images',$_POST)){
61
+ $bp_media_options['images_enabled'] = true;
62
+ }
63
+ else
64
+ {
65
+ $bp_media_options['images_enabled'] = false;
66
+ }
67
+ update_option('bp_media_options', $bp_media_options);
68
}
69
+ ?>
70
<div class="metabox-fixed metabox-holder alignright">
71
<?php bp_media_default_admin_sidebar(); ?>
72
</div>
80
<?php }?>
81
<form method="post">
82
<?php wp_nonce_field( 'bp_media_update_options' ); ?>
83
+ <h3>General Settings</h3>
84
<table class="form-table ">
85
<tbody>
86
<tr valign="top">
101
</tr>
102
</tbody>
103
</table>
104
+ <h3>Media Types Enabled</h3>
105
+ <table class="form-table ">
106
+ <tbody>
107
+ <tr valign="top">
108
+ <th scope="row"><label for="enable_videos">Videos</label></th>
109
+ <td>
110
+ <fieldset>
111
+ <legend class="screen-reader-text"><span>Enable Videos</span></legend>
112
+ <label for="enable_videos"><input name="enable_videos" type="checkbox" id="enable_videos" value="1" <?php global $bp_media_options;checked($bp_media_options['videos_enabled'],true) ?>> (Check to enable video upload functionality)</label>
113
+ </fieldset>
114
+ </td>
115
+ </tr>
116
+ <tr valign="top">
117
+ <th scope="row"><label for="enable_audio">Audio</label></th>
118
+ <td>
119
+ <fieldset>
120
+ <legend class="screen-reader-text"><span>Enable Audio</span></legend>
121
+ <label for="enable_audio"><input name="enable_audio" type="checkbox" id="enable_audio" value="1" <?php checked($bp_media_options['audio_enabled'],true) ?>> (Check to enable audio upload functionality)</label>
122
+ </fieldset>
123
+ </td>
124
+ </tr>
125
+ <tr valign="top">
126
+ <th scope="row"><label for="enable_images">Images</label></th>
127
+ <td>
128
+ <fieldset>
129
+ <legend class="screen-reader-text"><span>Enable Images</span></legend>
130
+ <label for="enable_images"><input name="enable_images" type="checkbox" id="enable_images" value="1" <?php checked($bp_media_options['images_enabled'],true) ?>> (Check to enable images upload functionality)</label>
131
+ </fieldset>
132
+ </td>
133
+ </tr>
134
+ </tbody>
135
+ </table>
136
<p class="submit"><input type="submit" name="submit" id="submit" class="button-primary" value="Save Changes"></p></form>
137
</div>
138
<?php
includes/bp-media-class-wordpress.php CHANGED
@@ -10,8 +10,10 @@ class BP_Media_Host_Wordpress {
10
$url, //URL of the entry
11
$type, //Type of the entry (Video, Image or Audio)
12
$owner, //Owner of the entry
13
- $attachment_id; //The attachment ID of the media file
14
-
15
/**
16
* Constructs a new BP_Media_Host_Wordpress element
17
*
@@ -39,7 +41,7 @@ class BP_Media_Host_Wordpress {
39
$media = &get_post($media_id);
40
}
41
if (empty($media->ID))
42
- throw new Exception(__('Sorry, the requested entry does not exist.', 'bp-media'));
43
$this->id = $media->ID;
44
$this->description = $media->post_content;
45
$this->name = $media->post_title;
@@ -48,12 +50,18 @@ class BP_Media_Host_Wordpress {
48
switch ($this->type) {
49
case 'video' :
50
$this->url = trailingslashit(bp_core_get_user_domain($this->owner) . BP_MEDIA_VIDEOS_SLUG . '/' . BP_MEDIA_VIDEOS_ENTRY_SLUG . '/' . $this->id);
51
break;
52
case 'audio' :
53
$this->url = trailingslashit(bp_core_get_user_domain($this->owner) . BP_MEDIA_AUDIO_SLUG . '/' . BP_MEDIA_AUDIO_ENTRY_SLUG . '/' . $this->id);
54
break;
55
case 'image' :
56
$this->url = trailingslashit(bp_core_get_user_domain($this->owner) . BP_MEDIA_IMAGES_SLUG . '/' . BP_MEDIA_IMAGES_ENTRY_SLUG . '/' . $this->id);
57
break;
58
default :
59
return false;
@@ -226,7 +234,6 @@ class BP_Media_Host_Wordpress {
226
227
function get_media_single_content() {
228
global $bp_media_default_sizes, $bp_media_default_excerpts;
229
-
230
$content = '<div class="bp_media_title">' . wp_html_excerpt($this->name, $bp_media_default_excerpts['single_entry_title']) . '</div><div class="bp_media_content">';
231
switch ($this->type) {
232
case 'video' :
@@ -347,6 +354,23 @@ class BP_Media_Host_Wordpress {
347
</div>
348
<?php
349
endwhile;
350
endif;
351
}
352
@@ -357,5 +381,64 @@ class BP_Media_Host_Wordpress {
357
function get_attachment_url(){
358
return wp_get_attachment_url($this->attachment_id);
359
}
360
}
361
?>
10
$url, //URL of the entry
11
$type, //Type of the entry (Video, Image or Audio)
12
$owner, //Owner of the entry
13
+ $attachment_id, //The attachment ID of the media file
14
+ $delete_url, //The delete url for the media
15
+ $edit_url; //The edit page's url for the media
16
+
17
/**
18
* Constructs a new BP_Media_Host_Wordpress element
19
*
41
$media = &get_post($media_id);
42
}
43
if (empty($media->ID))
44
+ throw new Exception(__('Sorry, the requested media does not exist.', 'bp-media'));
45
$this->id = $media->ID;
46
$this->description = $media->post_content;
47
$this->name = $media->post_title;
50
switch ($this->type) {
51
case 'video' :
52
$this->url = trailingslashit(bp_core_get_user_domain($this->owner) . BP_MEDIA_VIDEOS_SLUG . '/' . BP_MEDIA_VIDEOS_ENTRY_SLUG . '/' . $this->id);
53
+ $this->edit_url = trailingslashit(bp_core_get_user_domain($this->owner) . BP_MEDIA_VIDEOS_SLUG . '/' . BP_MEDIA_VIDEOS_EDIT_SLUG . '/' . $this->id);
54
+ $this->delete_url = trailingslashit(bp_core_get_user_domain($this->owner) . BP_MEDIA_VIDEOS_SLUG . '/' . BP_MEDIA_DELETE_SLUG . '/' . $this->id);
55
break;
56
case 'audio' :
57
$this->url = trailingslashit(bp_core_get_user_domain($this->owner) . BP_MEDIA_AUDIO_SLUG . '/' . BP_MEDIA_AUDIO_ENTRY_SLUG . '/' . $this->id);
58
+ $this->edit_url = trailingslashit(bp_core_get_user_domain($this->owner) . BP_MEDIA_AUDIO_SLUG . '/' . BP_MEDIA_AUDIO_EDIT_SLUG . '/' . $this->id);
59
+ $this->delete_url = trailingslashit(bp_core_get_user_domain($this->owner) . BP_MEDIA_AUDIO_SLUG . '/' . BP_MEDIA_DELETE_SLUG . '/' . $this->id);
60
break;
61
case 'image' :
62
$this->url = trailingslashit(bp_core_get_user_domain($this->owner) . BP_MEDIA_IMAGES_SLUG . '/' . BP_MEDIA_IMAGES_ENTRY_SLUG . '/' . $this->id);
63
+ $this->edit_url = trailingslashit(bp_core_get_user_domain($this->owner) . BP_MEDIA_IMAGES_SLUG . '/' . BP_MEDIA_IMAGES_EDIT_SLUG . '/' . $this->id);
64
+ $this->delete_url = trailingslashit(bp_core_get_user_domain($this->owner) . BP_MEDIA_IMAGES_SLUG . '/' . BP_MEDIA_DELETE_SLUG . '/' . $this->id);
65
break;
66
default :
67
return false;
234
235
function get_media_single_content() {
236
global $bp_media_default_sizes, $bp_media_default_excerpts;
237
$content = '<div class="bp_media_title">' . wp_html_excerpt($this->name, $bp_media_default_excerpts['single_entry_title']) . '</div><div class="bp_media_content">';
238
switch ($this->type) {
239
case 'video' :
354
</div>
355
<?php
356
endwhile;
357
+ else: ?>
358
+ <div class="activity">
359
+ <ul id="activity-stream" class="activity-list item-list">
360
+ <li class="activity activity_update" id="activity-<?php echo $activity_id; ?>">
361
+ <div class="activity-content">
362
+ <?php do_action('bp_activity_entry_content'); ?>
363
+ <?php if (is_user_logged_in()) : ?>
364
+ <div class="activity-meta no-ajax">
365
+
366
+ <a href="<?php echo $this->get_delete_url(); ?>" class="button item-button bp-secondary-action delete-activity-single confirm" rel="nofollow">Delete</a>
367
+ </div>
368
+ <?php endif; ?>
369
+ </div>
370
+ </li>
371
+ </ul>
372
+ </div>
373
+ <?
374
endif;
375
}
376
381
function get_attachment_url(){
382
return wp_get_attachment_url($this->attachment_id);
383
}
384
+
385
+ function update_media($args=array()){
386
+ $defaults=array(
387
+ 'name' => $this->name,
388
+ 'description' => $this->description,
389
+ 'owner' => $this->owner
390
+ );
391
+ $args = wp_parse_args( $args, $defaults );
392
+ $post=get_post($this->id,ARRAY_A);
393
+ $post['post_title']=esc_html($args['name']);
394
+ $post['post_content']=esc_html($args['description']);
395
+ $post['post_author']=$args['owner'];
396
+ $result = wp_update_post($post);
397
+ $this->init($this->id);
398
+ return $result;
399
+ }
400
+
401
+ function delete_media(){
402
+ global $bp_media_count;
403
+ bp_media_init_count($this->owner);
404
+ switch ($this->type) {
405
+ case 'image':
406
+ $bp_media_count['images'] = intval($bp_media_count['images']) - 1;
407
+ break;
408
+ case 'video':
409
+ $bp_media_count['videos'] = intval($bp_media_count['videos']) - 1;
410
+ break;
411
+ case 'audio':
412
+ $bp_media_count['audio'] = intval($bp_media_count['audio']) - 1;
413
+ break;
414
+ }
415
+
416
+ wp_delete_attachment($this->attachment_id);
417
+ // $activity_id = get_post_meta($post_id, 'bp_media_child_activity', true);
418
+ // if($activity_id)
419
+ // bp_activity_delete_by_activity_id($activity_id);
420
+ wp_delete_post($this->id);
421
+ bp_update_user_meta($this->owner, 'bp_media_count', $bp_media_count);
422
+ }
423
+
424
+ function get_title() {
425
+ return $this->name;
426
+ }
427
+
428
+ function get_content() {
429
+ return $this->description;
430
+ }
431
+ function get_author() {
432
+ return $this->owner;
433
+ }
434
+ function get_id(){
435
+ return $this->id;
436
+ }
437
+ function get_edit_url() {
438
+ return $this->edit_url;
439
+ }
440
+ function get_delete_url() {
441
+ return $this->delete_url;
442
+ }
443
}
444
?>
includes/bp-media-filters.php CHANGED
@@ -48,7 +48,7 @@ add_filter('bp_get_activity_parent_content', 'bp_media_activity_parent_content_f
48
49
function bp_media_delete_button_handler($link) {
50
if(bp_current_component()=='media')
51
- $link=str_replace('class="button', 'class="button delete-activity-single"', $link);
52
return $link;
53
}
54
add_filter('bp_get_activity_delete_link','bp_media_delete_button_handler');
48
49
function bp_media_delete_button_handler($link) {
50
if(bp_current_component()=='media')
51
+ $link=str_replace('delete-activity ', 'delete-activity-single ', $link);
52
return $link;
53
}
54
add_filter('bp_get_activity_delete_link','bp_media_delete_button_handler');
includes/bp-media-functions.php CHANGED
@@ -115,4 +115,39 @@ function bp_media_update_count() {
115
}
116
return true;
117
}
118
?>
115
}
116
return true;
117
}
118
+
119
+ function bp_media_update_media(){
120
+ global $bp_media_current_entry;
121
+ if($bp_media_current_entry->update_media(array('name'=> esc_html($_POST['bp_media_title']),'description'=> esc_html($_POST['bp_media_description'])))){
122
+ @setcookie('bp-message', 'The media has been updated' , time() + 60 * 60 * 24, COOKIEPATH);
123
+ @setcookie('bp-message-type', 'success' , time() + 60 * 60 * 24, COOKIEPATH);
124
+ wp_redirect($bp_media_current_entry->get_url());
125
+ exit;
126
+ }
127
+ else{
128
+ @setcookie('bp-message', 'The media update failed' , time() + 60 * 60 * 24, COOKIEPATH);
129
+ @setcookie('bp-message-type', 'error' , time() + 60 * 60 * 24, COOKIEPATH);
130
+ wp_redirect($bp_media_current_entry->get_edit_url());
131
+ exit;
132
+ }
133
+ }
134
+
135
+ function bp_media_check_user() {
136
+ if (bp_loggedin_user_id() != bp_displayed_user_id()) {
137
+ bp_core_no_access(array(
138
+ 'message' => __('You do not have access to this page.', 'buddypress'),
139
+ 'root' => bp_displayed_user_domain(),
140
+ 'redirect' => false
141
+ ));
142
+ exit;
143
+ }
144
+ }
145
+
146
+ function bp_media_page_not_exist() {
147
+ @setcookie('bp-message', 'The requested url does not exist' , time() + 60 * 60 * 24, COOKIEPATH);
148
+ @setcookie('bp-message-type', 'error' , time() + 60 * 60 * 24, COOKIEPATH);
149
+ wp_redirect(trailingslashit(bp_displayed_user_domain() . BP_MEDIA_IMAGES_SLUG));
150
+ exit;
151
+ }
152
+
153
?>
includes/bp-media-loader.php CHANGED
@@ -9,6 +9,7 @@ if (!defined('ABSPATH'))
9
/* Slug Constants */
10
define('BP_MEDIA_SLUG', 'media');
11
define('BP_MEDIA_UPLOAD_SLUG', 'upload');
12
13
define('BP_MEDIA_IMAGES_SLUG', 'images');
14
define('BP_MEDIA_IMAGES_ENTRY_SLUG', 'view');
@@ -80,6 +81,12 @@ $bp_media_default_excerpts=array(
80
'activity_entry_description'=> 500
81
);
82
83
/* To set the language according to the locale selected and availability of the language file. */
84
if (file_exists(BP_MEDIA_PLUGIN_DIR . '/languages/' . get_locale() . '.mo'))
85
load_textdomain('bp-media', BP_MEDIA_PLUGIN_DIR . '/languages/' . get_locale() . '.mo');
@@ -234,7 +241,16 @@ class BP_Media_Component extends BP_Component {
234
'parent_slug' => BP_MEDIA_IMAGES_SLUG, /* URL slug of the parent nav item */
235
'parent_url' => trailingslashit(bp_loggedin_user_domain() . BP_MEDIA_IMAGES_SLUG), /* URL of the parent item */
236
'position' => 90, /* Index of where this nav item should be positioned */
237
- 'screen_function' => 'bp_media_images_edit_screen', /* The name of the function to run when clicked */
238
));
239
240
bp_core_new_subnav_item(array(
@@ -246,6 +262,15 @@ class BP_Media_Component extends BP_Component {
246
'screen_function' => 'bp_media_audio_edit_screen', /* The name of the function to run when clicked */
247
));
248
249
bp_core_new_subnav_item(array(
250
'name' => 'Edit', /* Display name for the nav item(It won't be shown anywhere) */
251
'slug' => BP_MEDIA_VIDEOS_EDIT_SLUG, /* URL slug for the nav item */
@@ -255,6 +280,15 @@ class BP_Media_Component extends BP_Component {
255
'screen_function' => 'bp_media_videos_edit_screen', /* The name of the function to run when clicked */
256
));
257
258
bp_core_new_subnav_item(array(
259
'name' => 'Page', /* Display name for the nav item(It won't be shown anywhere) */
260
'slug' => 'page', /* URL slug for the nav item */
9
/* Slug Constants */
10
define('BP_MEDIA_SLUG', 'media');
11
define('BP_MEDIA_UPLOAD_SLUG', 'upload');
12
+ define('BP_MEDIA_DELETE_SLUG', 'delete');
13
14
define('BP_MEDIA_IMAGES_SLUG', 'images');
15
define('BP_MEDIA_IMAGES_ENTRY_SLUG', 'view');
81
'activity_entry_description'=> 500
82
);
83
84
+ $bp_media_options = get_option('bp_media_options',array(
85
+ 'videos_enabled' => true,
86
+ 'audio_enabled' => true,
87
+ 'images_enabled' => true,
88
+ ));
89
+
90
/* To set the language according to the locale selected and availability of the language file. */
91
if (file_exists(BP_MEDIA_PLUGIN_DIR . '/languages/' . get_locale() . '.mo'))
92
load_textdomain('bp-media', BP_MEDIA_PLUGIN_DIR . '/languages/' . get_locale() . '.mo');
241
'parent_slug' => BP_MEDIA_IMAGES_SLUG, /* URL slug of the parent nav item */
242
'parent_url' => trailingslashit(bp_loggedin_user_domain() . BP_MEDIA_IMAGES_SLUG), /* URL of the parent item */
243
'position' => 90, /* Index of where this nav item should be positioned */
244
+ 'screen_function' => 'bp_media_images_screen', /* The name of the function to run when clicked */
245
+ ));
246
+
247
+ bp_core_new_subnav_item(array(
248
+ 'name' => 'Delete', /* Display name for the nav item(It won't be shown anywhere) */
249
+ 'slug' => BP_MEDIA_DELETE_SLUG, /* URL slug for the nav item */
250
+ 'parent_slug' => BP_MEDIA_IMAGES_SLUG, /* URL slug of the parent nav item */
251
+ 'parent_url' => trailingslashit(bp_loggedin_user_domain() . BP_MEDIA_IMAGES_SLUG), /* URL of the parent item */
252
+ 'position' => 90, /* Index of where this nav item should be positioned */
253
+ 'screen_function' => 'bp_media_images_screen', /* The name of the function to run when clicked */
254
));
255
256
bp_core_new_subnav_item(array(
262
'screen_function' => 'bp_media_audio_edit_screen', /* The name of the function to run when clicked */
263
));
264
265
+ bp_core_new_subnav_item(array(
266
+ 'name' => 'Delete', /* Display name for the nav item(It won't be shown anywhere) */
267
+ 'slug' => BP_MEDIA_DELETE_SLUG, /* URL slug for the nav item */
268
+ 'parent_slug' => BP_MEDIA_AUDIO_SLUG, /* URL slug of the parent nav item */
269
+ 'parent_url' => trailingslashit(bp_loggedin_user_domain() . BP_MEDIA_AUDIO_SLUG), /* URL of the parent item */
270
+ 'position' => 90, /* Index of where this nav item should be positioned */
271
+ 'screen_function' => 'bp_media_audio_screen', /* The name of the function to run when clicked */
272
+ ));
273
+
274
bp_core_new_subnav_item(array(
275
'name' => 'Edit', /* Display name for the nav item(It won't be shown anywhere) */
276
'slug' => BP_MEDIA_VIDEOS_EDIT_SLUG, /* URL slug for the nav item */
280
'screen_function' => 'bp_media_videos_edit_screen', /* The name of the function to run when clicked */
281
));
282
283
+ bp_core_new_subnav_item(array(
284
+ 'name' => 'Delete', /* Display name for the nav item(It won't be shown anywhere) */
285
+ 'slug' => BP_MEDIA_DELETE_SLUG, /* URL slug for the nav item */
286
+ 'parent_slug' => BP_MEDIA_VIDEOS_SLUG, /* URL slug of the parent nav item */
287
+ 'parent_url' => trailingslashit(bp_loggedin_user_domain() . BP_MEDIA_VIDEOS_SLUG), /* URL of the parent item */
288
+ 'position' => 90, /* Index of where this nav item should be positioned */
289
+ 'screen_function' => 'bp_media_videos_screen', /* The name of the function to run when clicked */
290
+ ));
291
+
292
bp_core_new_subnav_item(array(
293
'name' => 'Page', /* Display name for the nav item(It won't be shown anywhere) */
294
'slug' => 'page', /* URL slug for the nav item */
includes/bp-media-screens.php CHANGED
@@ -12,13 +12,14 @@ if (!defined('ABSPATH'))
12
* Screen function for Upload page
13
*/
14
function bp_media_upload_screen() {
15
add_action('bp_template_title', 'bp_media_upload_screen_title');
16
add_action('bp_template_content', 'bp_media_upload_screen_content');
17
bp_core_load_template(apply_filters('bp_core_template_plugin', 'members/single/plugins'));
18
}
19
20
function bp_media_upload_screen_title() {
21
- _e('Upload Page');
22
}
23
24
function bp_media_upload_screen_content() {
@@ -39,19 +40,34 @@ function bp_media_images_screen() {
39
break;
40
case BP_MEDIA_IMAGES_ENTRY_SLUG:
41
global $bp_media_current_entry;
42
- if (!$bp->action_variables[0] == BP_MEDIA_IMAGES_ENTRY_SLUG)
43
- return false;
44
try {
45
$bp_media_current_entry = new BP_Media_Host_Wordpress($bp->action_variables[1]);
46
} catch (Exception $e) {
47
/* Send the values to the cookie for page reload display */
48
- @setcookie('bp-message', $_COOKIE['bp-message'], time() + 60 * 60 * 24, COOKIEPATH);
49
- @setcookie('bp-message-type', $_COOKIE['bp-message-type'], time() + 60 * 60 * 24, COOKIEPATH);
50
wp_redirect(trailingslashit(bp_displayed_user_domain() . BP_MEDIA_IMAGES_SLUG));
51
exit;
52
}
53
add_action('bp_template_content', 'bp_media_images_entry_screen_content');
54
break;
55
default:
56
bp_media_set_query();
57
add_action('bp_template_content', 'bp_media_images_screen_content');
@@ -88,26 +104,45 @@ function bp_media_images_screen_content() {
88
* Screen function for Images Edit page
89
*/
90
function bp_media_images_edit_screen() {
91
- if (bp_loggedin_user_id() != bp_displayed_user_id()) {
92
- bp_core_no_access(array(
93
- 'message' => __('You do not have access to this page.', 'buddypress'),
94
- 'root' => bp_displayed_user_domain(),
95
- 'redirect' => false
96
- ));
97
exit;
98
}
99
add_action('bp_template_title', 'bp_media_images_edit_screen_title');
100
add_action('bp_template_content', 'bp_media_images_edit_screen_content');
101
bp_core_load_template(apply_filters('bp_core_template_plugin', 'members/single/plugins'));
102
}
103
104
function bp_media_images_edit_screen_title() {
105
- _e('Images Edit Page');
106
}
107
108
function bp_media_images_edit_screen_content() {
109
- global $bp;
110
- _e('Images Edit Page Content');
111
}
112
113
/**
@@ -143,7 +178,7 @@ function bp_media_videos_screen() {
143
if (isset($bp->action_variables[0])) {
144
switch ($bp->action_variables[0]) {
145
case BP_MEDIA_VIDEOS_EDIT_SLUG :
146
- add_action('bp_template_content', 'bp_media_videos_edit_screen_content');
147
break;
148
case BP_MEDIA_VIDEOS_ENTRY_SLUG:
149
global $bp_media_current_entry;
@@ -160,6 +195,12 @@ function bp_media_videos_screen() {
160
}
161
add_action('bp_template_content', 'bp_media_videos_entry_screen_content');
162
break;
163
default:
164
bp_media_set_query();
165
add_action('bp_template_content', 'bp_media_videos_screen_content');
@@ -196,18 +237,45 @@ function bp_media_videos_screen_content() {
196
* Screen function for Videos Edit page
197
*/
198
function bp_media_videos_edit_screen() {
199
add_action('bp_template_title', 'bp_media_videos_edit_screen_title');
200
add_action('bp_template_content', 'bp_media_videos_edit_screen_content');
201
bp_core_load_template(apply_filters('bp_core_template_plugin', 'members/single/plugins'));
202
}
203
204
function bp_media_videos_edit_screen_title() {
205
- _e('Videos Edit Page');
206
}
207
208
function bp_media_videos_edit_screen_content() {
209
- global $bp;
210
- _e('Videos Edit Page Content');
211
}
212
213
/**
@@ -243,7 +311,7 @@ function bp_media_audio_screen() {
243
if (isset($bp->action_variables[0])) {
244
switch ($bp->action_variables[0]) {
245
case BP_MEDIA_AUDIO_EDIT_SLUG :
246
- add_action('bp_template_content', 'bp_media_audio_edit_screen_content');
247
break;
248
case BP_MEDIA_AUDIO_ENTRY_SLUG:
249
global $bp_media_current_entry;
@@ -260,6 +328,12 @@ function bp_media_audio_screen() {
260
}
261
add_action('bp_template_content', 'bp_media_audio_entry_screen_content');
262
break;
263
default:
264
bp_media_set_query();
265
add_action('bp_template_content', 'bp_media_audio_screen_content');
@@ -296,18 +370,45 @@ function bp_media_audio_screen_content() {
296
* Screen function for Audio Edit page
297
*/
298
function bp_media_audio_edit_screen() {
299
add_action('bp_template_title', 'bp_media_audio_edit_screen_title');
300
add_action('bp_template_content', 'bp_media_audio_edit_screen_content');
301
bp_core_load_template(apply_filters('bp_core_template_plugin', 'members/single/plugins'));
302
}
303
304
function bp_media_audio_edit_screen_title() {
305
- _e('Audio Edit Page');
306
}
307
308
function bp_media_audio_edit_screen_content() {
309
- global $bp;
310
- _e('Audio Edit Page Content');
311
}
312
313
/**
@@ -334,4 +435,42 @@ function bp_media_audio_entry_screen_content() {
334
echo '</div>';
335
do_action('bp_media_after_content');
336
}
337
?>
12
* Screen function for Upload page
13
*/
14
function bp_media_upload_screen() {
15
+ //add_action('wp_enqueue_scripts','bp_media_upload_enqueue');
16
add_action('bp_template_title', 'bp_media_upload_screen_title');
17
add_action('bp_template_content', 'bp_media_upload_screen_content');
18
bp_core_load_template(apply_filters('bp_core_template_plugin', 'members/single/plugins'));
19
}
20
21
function bp_media_upload_screen_title() {
22
+ _e('Upload Media');
23
}
24
25
function bp_media_upload_screen_content() {
40
break;
41
case BP_MEDIA_IMAGES_ENTRY_SLUG:
42
global $bp_media_current_entry;
43
+ if(!isset($bp->action_variables[1])){
44
+ bp_media_page_not_exist();
45
+ }
46
try {
47
$bp_media_current_entry = new BP_Media_Host_Wordpress($bp->action_variables[1]);
48
+ if($bp_media_current_entry->get_author()!= bp_displayed_user_id())
49
+ throw new Exception(__('Sorry, the requested media does not belong to the user'));
50
} catch (Exception $e) {
51
/* Send the values to the cookie for page reload display */
52
+ if(isset($_COOKIE['bp-message'])&&$_COOKIE['bp-message']!=''){
53
+ @setcookie('bp-message', $_COOKIE['bp-message'], time() + 60 * 60 * 24, COOKIEPATH);
54
+ @setcookie('bp-message-type', $_COOKIE['bp-message-type'], time() + 60 * 60 * 24, COOKIEPATH);
55
+ }
56
+ else{
57
+ @setcookie('bp-message', $e->getMessage(), time() + 60 * 60 * 24, COOKIEPATH);
58
+ @setcookie('bp-message-type', 'error', time() + 60 * 60 * 24, COOKIEPATH);
59
+ }
60
wp_redirect(trailingslashit(bp_displayed_user_domain() . BP_MEDIA_IMAGES_SLUG));
61
exit;
62
}
63
add_action('bp_template_content', 'bp_media_images_entry_screen_content');
64
break;
65
+ case BP_MEDIA_DELETE_SLUG :
66
+ if(!isset($bp->action_variables[1])){
67
+ bp_media_page_not_exist();
68
+ }
69
+ bp_media_entry_delete();
70
+ break;
71
default:
72
bp_media_set_query();
73
add_action('bp_template_content', 'bp_media_images_screen_content');
104
* Screen function for Images Edit page
105
*/
106
function bp_media_images_edit_screen() {
107
+ global $bp_media_current_entry,$bp;
108
+ if(!isset($bp->action_variables[1])){
109
+ bp_media_page_not_exist();
110
+ }
111
+ //Creating global bp_media_current_entry for later use
112
+ try {
113
+ $bp_media_current_entry = new BP_Media_Host_Wordpress($bp->action_variables[1]);
114
+
115
+ } catch (Exception $e) {
116
+ /* Send the values to the cookie for page reload display */
117
+ @setcookie('bp-message', $e->getMessage(), time() + 60 * 60 * 24, COOKIEPATH);
118
+ @setcookie('bp-message-type', 'error', time() + 60 * 60 * 24, COOKIEPATH);
119
+ wp_redirect(trailingslashit(bp_displayed_user_domain() . BP_MEDIA_IMAGES_SLUG));
120
exit;
121
}
122
+ bp_media_check_user();
123
+
124
+ //For saving the data if the form is submitted
125
+ if(array_key_exists('bp_media_title', $_POST)){
126
+ bp_media_update_media();
127
+ }
128
add_action('bp_template_title', 'bp_media_images_edit_screen_title');
129
add_action('bp_template_content', 'bp_media_images_edit_screen_content');
130
bp_core_load_template(apply_filters('bp_core_template_plugin', 'members/single/plugins'));
131
}
132
133
function bp_media_images_edit_screen_title() {
134
+ _e('Edit Image','bp-media');
135
}
136
137
function bp_media_images_edit_screen_content() {
138
+ global $bp, $bp_media_current_entry,$bp_media_default_excerpts;
139
+ ?>
140
+ <form method="post" class="standard-form" id="bp-media-upload-form">
141
+ <label for="bp-media-upload-input-title"><?php _e('Image Title', 'bp-media'); ?></label><input id="bp-media-upload-input-title" type="text" name="bp_media_title" class="settings-input" maxlength="<?php echo max(array($bp_media_default_excerpts['single_entry_title'],$bp_media_default_excerpts['activity_entry_title'])) ?>" value="<?php echo $bp_media_current_entry->get_title(); ?>" />
142
+ <label for="bp-media-upload-input-description"><?php _e('Image Description', 'bp-media'); ?></label><input id="bp-media-upload-input-description" type="text" name="bp_media_description" class="settings-input" maxlength="<?php echo max(array($bp_media_default_excerpts['single_entry_description'],$bp_media_default_excerpts['activity_entry_description'])) ?>" value="<?php echo $bp_media_current_entry->get_content(); ?>" />
143
+ <div class="submit"><input type="submit" class="auto" value="Update" /><a href="<?php echo $bp_media_current_entry->get_url(); ?>" class="button" title="Back to Media File">Back to Media</a></div>
144
+ </form>
145
+ <?php
146
}
147
148
/**
178
if (isset($bp->action_variables[0])) {
179
switch ($bp->action_variables[0]) {
180
case BP_MEDIA_VIDEOS_EDIT_SLUG :
181
+ bp_media_video_edit_screen();
182
break;
183
case BP_MEDIA_VIDEOS_ENTRY_SLUG:
184
global $bp_media_current_entry;
195
}
196
add_action('bp_template_content', 'bp_media_videos_entry_screen_content');
197
break;
198
+ case BP_MEDIA_DELETE_SLUG :
199
+ if(!isset($bp->action_variables[1])){
200
+ bp_media_page_not_exist();
201
+ }
202
+ bp_media_entry_delete();
203
+ break;
204
default:
205
bp_media_set_query();
206
add_action('bp_template_content', 'bp_media_videos_screen_content');
237
* Screen function for Videos Edit page
238
*/
239
function bp_media_videos_edit_screen() {
240
+ global $bp_media_current_entry,$bp;
241
+ if(!isset($bp->action_variables[1])){
242
+ bp_media_page_not_exist();
243
+ }
244
+ //Creating global bp_media_current_entry for later use
245
+ try {
246
+ $bp_media_current_entry = new BP_Media_Host_Wordpress($bp->action_variables[1]);
247
+
248
+ } catch (Exception $e) {
249
+ /* Send the values to the cookie for page reload display */
250
+ @setcookie('bp-message', $e->getMessage(), time() + 60 * 60 * 24, COOKIEPATH);
251
+ @setcookie('bp-message-type', 'error', time() + 60 * 60 * 24, COOKIEPATH);
252
+ wp_redirect(trailingslashit(bp_displayed_user_domain() . BP_MEDIA_IMAGES_SLUG));
253
+ exit;
254
+ }
255
+ bp_media_check_user();
256
+
257
+ //For saving the data if the form is submitted
258
+ if(array_key_exists('bp_media_title', $_POST)){
259
+ bp_media_update_media();
260
+ }
261
add_action('bp_template_title', 'bp_media_videos_edit_screen_title');
262
add_action('bp_template_content', 'bp_media_videos_edit_screen_content');
263
bp_core_load_template(apply_filters('bp_core_template_plugin', 'members/single/plugins'));
264
}
265
266
function bp_media_videos_edit_screen_title() {
267
+ _e('Edit Video');
268
}
269
270
function bp_media_videos_edit_screen_content() {
271
+ global $bp, $bp_media_current_entry,$bp_media_default_excerpts;
272
+ ?>
273
+ <form method="post" class="standard-form" id="bp-media-upload-form">
274
+ <label for="bp-media-upload-input-title"><?php _e('Video Title', 'bp-media'); ?></label><input id="bp-media-upload-input-title" type="text" name="bp_media_title" class="settings-input" maxlength="<?php echo max(array($bp_media_default_excerpts['single_entry_title'],$bp_media_default_excerpts['activity_entry_title'])) ?>" value="<?php echo $bp_media_current_entry->get_title(); ?>" />
275
+ <label for="bp-media-upload-input-description"><?php _e('Video Description', 'bp-media'); ?></label><input id="bp-media-upload-input-description" type="text" name="bp_media_description" class="settings-input" maxlength="<?php echo max(array($bp_media_default_excerpts['single_entry_description'],$bp_media_default_excerpts['activity_entry_description'])) ?>" value="<?php echo $bp_media_current_entry->get_content(); ?>" />
276
+ <div class="submit"><input type="submit" class="auto" value="Update" /><a href="<?php echo $bp_media_current_entry->get_url(); ?>" class="button" title="Back to Media File">Back to Media</a></div>
277
+ </form>
278
+ <?php
279
}
280
281
/**
311
if (isset($bp->action_variables[0])) {
312
switch ($bp->action_variables[0]) {
313
case BP_MEDIA_AUDIO_EDIT_SLUG :
314
+ bp_media_audio_edit_screen();
315
break;
316
case BP_MEDIA_AUDIO_ENTRY_SLUG:
317
global $bp_media_current_entry;
328
}
329
add_action('bp_template_content', 'bp_media_audio_entry_screen_content');
330
break;
331
+ case BP_MEDIA_DELETE_SLUG :
332
+ if(!isset($bp->action_variables[1])){
333
+ bp_media_page_not_exist();
334
+ }
335
+ bp_media_entry_delete();
336
+ break;
337
default:
338
bp_media_set_query();
339
add_action('bp_template_content', 'bp_media_audio_screen_content');
370
* Screen function for Audio Edit page
371
*/
372
function bp_media_audio_edit_screen() {
373
+ global $bp_media_current_entry,$bp;
374
+ if(!isset($bp->action_variables[1])){
375
+ bp_media_page_not_exist();
376
+ }
377
+ //Creating global bp_media_current_entry for later use
378
+ try {
379
+ $bp_media_current_entry = new BP_Media_Host_Wordpress($bp->action_variables[1]);
380
+
381
+ } catch (Exception $e) {
382
+ /* Send the values to the cookie for page reload display */
383
+ @setcookie('bp-message', $e->getMessage(), time() + 60 * 60 * 24, COOKIEPATH);
384
+ @setcookie('bp-message-type', 'error', time() + 60 * 60 * 24, COOKIEPATH);
385
+ wp_redirect(trailingslashit(bp_displayed_user_domain() . BP_MEDIA_IMAGES_SLUG));
386
+ exit;
387
+ }
388
+ bp_media_check_user();
389
+
390
+ //For saving the data if the form is submitted
391
+ if(array_key_exists('bp_media_title', $_POST)){
392
+ bp_media_update_media();
393
+ }
394
add_action('bp_template_title', 'bp_media_audio_edit_screen_title');
395
add_action('bp_template_content', 'bp_media_audio_edit_screen_content');
396
bp_core_load_template(apply_filters('bp_core_template_plugin', 'members/single/plugins'));
397
}
398
399
function bp_media_audio_edit_screen_title() {
400
+ _e('Edit Audio');
401
}
402
403
function bp_media_audio_edit_screen_content() {
404
+ global $bp, $bp_media_current_entry,$bp_media_default_excerpts;
405
+ ?>
406
+ <form method="post" class="standard-form" id="bp-media-upload-form">
407
+ <label for="bp-media-upload-input-title"><?php _e('Audio Title', 'bp-media'); ?></label><input id="bp-media-upload-input-title" type="text" name="bp_media_title" class="settings-input" maxlength="<?php echo max(array($bp_media_default_excerpts['single_entry_title'],$bp_media_default_excerpts['activity_entry_title'])) ?>" value="<?php echo $bp_media_current_entry->get_title(); ?>" />
408
+ <label for="bp-media-upload-input-description"><?php _e('Audio Description', 'bp-media'); ?></label><input id="bp-media-upload-input-description" type="text" name="bp_media_description" class="settings-input" maxlength="<?php echo max(array($bp_media_default_excerpts['single_entry_description'],$bp_media_default_excerpts['activity_entry_description'])) ?>" value="<?php echo $bp_media_current_entry->get_content(); ?>" />
409
+ <div class="submit"><input type="submit" class="auto" value="Update" /><a href="<?php echo $bp_media_current_entry->get_url(); ?>" class="button" title="Back to Media File">Back to Media</a></div>
410
+ </form>
411
+ <?php
412
}
413
414
/**
435
echo '</div>';
436
do_action('bp_media_after_content');
437
}
438
+
439
+ function bp_media_entry_delete() {
440
+ global $bp;
441
+ if (bp_loggedin_user_id() != bp_displayed_user_id()) {
442
+ bp_core_no_access(array(
443
+ 'message' => __('You do not have access to this page.', 'buddypress'),
444
+ 'root' => bp_displayed_user_domain(),
445
+ 'redirect' => false
446
+ ));
447
+ exit;
448
+ }
449
+ if(!isset($bp->action_variables[1])){
450
+ @setcookie('bp-message', 'The requested url does not exist' , time() + 60 * 60 * 24, COOKIEPATH);
451
+ @setcookie('bp-message-type', 'error' , time() + 60 * 60 * 24, COOKIEPATH);
452
+ wp_redirect(trailingslashit(bp_displayed_user_domain() . BP_MEDIA_IMAGES_SLUG));
453
+ exit;
454
+ }
455
+ global $bp_media_current_entry;
456
+ try {
457
+ $bp_media_current_entry = new BP_Media_Host_Wordpress($bp->action_variables[1]);
458
+ } catch (Exception $e) {
459
+ /* Send the values to the cookie for page reload display */
460
+ @setcookie('bp-message', $e->getMessage(), time() + 60 * 60 * 24, COOKIEPATH);
461
+ @setcookie('bp-message-type', 'error', time() + 60 * 60 * 24, COOKIEPATH);
462
+ wp_redirect(trailingslashit(bp_displayed_user_domain() . BP_MEDIA_IMAGES_SLUG));
463
+ exit;
464
+ }
465
+ $post_id = $bp_media_current_entry->get_id();
466
+ $activity_id=get_post_meta($post_id,'bp_media_child_activity',true);
467
+
468
+ bp_activity_delete_by_activity_id($activity_id);
469
+ $bp_media_current_entry->delete_media();
470
+
471
+ @setcookie('bp-message', __('Media deleted successfully','bp-media'), time() + 60 * 60 * 24, COOKIEPATH);
472
+ @setcookie('bp-message-type', 'success', time() + 60 * 60 * 24, COOKIEPATH);
473
+ wp_redirect(trailingslashit(bp_displayed_user_domain() . BP_MEDIA_IMAGES_SLUG));
474
+ exit;
475
+ }
476
?>
includes/bp-media-template-functions.php CHANGED
@@ -1,17 +1,49 @@
1
<?php
2
function bp_media_show_upload_form() {
3
- global $bp,$bp_media_default_excerpts;
4
?>
5
<form method="post" enctype="multipart/form-data" class="standard-form" id="bp-media-upload-form">
6
<label for="bp-media-upload-input-title"><?php _e('Media Title', 'bp-media'); ?></label><input id="bp-media-upload-input-title" type="text" name="bp_media_title" class="settings-input" maxlength="<?php echo max(array($bp_media_default_excerpts['single_entry_title'],$bp_media_default_excerpts['activity_entry_title'])) ?>" />
7
<label for="bp-media-upload-input-description"><?php _e('Media Description', 'bp-media'); ?></label><input id="bp-media-upload-input-description" type="text" name="bp_media_description" class="settings-input" maxlength="<?php echo max(array($bp_media_default_excerpts['single_entry_description'],$bp_media_default_excerpts['activity_entry_description'])) ?>" />
8
- <label for="bp-media-upload-file"><?php _e('Select Media File', 'bp-media') ?> (Max File Size:<?php echo min(array(ini_get('upload_max_filesize'),ini_get('post_max_size'))); ?>)</label><input type="file" name="bp_media_file" id="bp-media-upload-file" />
9
<input type="hidden" name="action" value="wp_handle_upload" />
10
<div class="submit"><input type="submit" class="auto" value="Upload" /></div>
11
</form>
12
<?php
13
}
14
15
function bp_media_show_pagination($type = 'top') {
16
global $bp, $bp_media_paginated_links, $bp_media_query;
17
switch ($bp->current_action) {
1
<?php
2
function bp_media_show_upload_form() {
3
+ global $bp,$bp_media_default_excerpts,$bp_media_options;
4
+ $allowed=array();
5
+ $accept = array();
6
+ if($bp_media_options['images_enabled']){
7
+ $allowed[] = 'image';
8
+ $accept[] = 'image/*';
9
+ }
10
+ if($bp_media_options['audio_enabled']){
11
+ $allowed[] = 'audio';
12
+ $accept[] = 'audio/mp3';
13
+ }
14
+ if($bp_media_options['videos_enabled']){
15
+ $allowed[] = 'video';
16
+ $accept[] = 'video/mp4';
17
+ }
18
+ $accept = implode(',',$accept);
19
+
20
?>
21
<form method="post" enctype="multipart/form-data" class="standard-form" id="bp-media-upload-form">
22
<label for="bp-media-upload-input-title"><?php _e('Media Title', 'bp-media'); ?></label><input id="bp-media-upload-input-title" type="text" name="bp_media_title" class="settings-input" maxlength="<?php echo max(array($bp_media_default_excerpts['single_entry_title'],$bp_media_default_excerpts['activity_entry_title'])) ?>" />
23
<label for="bp-media-upload-input-description"><?php _e('Media Description', 'bp-media'); ?></label><input id="bp-media-upload-input-description" type="text" name="bp_media_description" class="settings-input" maxlength="<?php echo max(array($bp_media_default_excerpts['single_entry_description'],$bp_media_default_excerpts['activity_entry_description'])) ?>" />
24
+ <label for="bp-media-upload-file"><?php _e('Select Media File', 'bp-media') ?> (Max File Size:<?php echo min(array(ini_get('upload_max_filesize'),ini_get('post_max_size'))); ?> , Allowed types: <?php echo implode(', ',$allowed) ?>)</label><input type="file" name="bp_media_file" id="bp-media-upload-file" accept="<?php echo $accept ?>" />
25
<input type="hidden" name="action" value="wp_handle_upload" />
26
<div class="submit"><input type="submit" class="auto" value="Upload" /></div>
27
</form>
28
<?php
29
}
30
31
+ function bp_media_show_upload_form2() {
32
+ global $bp,$bp_media_default_excerpts;
33
+ ?>
34
+ <div id="bp-media-upload-ui" class="hide-if-no-js drag-drop">
35
+ <div id="drag-drop-area">
36
+ <div class="drag-drop-inside">
37
+ <p class="drag-drop-info">Drop files here</p>
38
+ <p>or</p>
39
+ <p class="drag-drop-buttons"><input id="bp-media-upload-browse-button" type="button" value="Select Files" class="button" /></p>
40
+ </div>
41
+ </div>
42
+ </div>
43
+ <div id="bp-media-uploaded-files"></div>
44
+ <?php
45
+ }
46
+
47
function bp_media_show_pagination($type = 'top') {
48
global $bp, $bp_media_paginated_links, $bp_media_query;
49
switch ($bp->current_action) {
includes/bp-media-upload-handler.php ADDED
@@ -0,0 +1,17 @@
1
+ <?php
2
+ ignore_user_abort(true);
3
+
4
+ require_once('lib/bootstrap.php');
5
+
6
+ // Disable error reporting or else AJAX Requests might give different data format
7
+ error_reporting(E_ALL);
8
+
9
+ // Check for rights
10
+ if ( !is_user_logged_in() )
11
+ wp_die(__("You are not allowed to be here"));
12
+
13
+ //set_time_limit(0);
14
+
15
+ bp_media_handle_uploads();
16
+
17
+ ?>
includes/css/bp-media-uploader.css ADDED
@@ -0,0 +1,98 @@
1
+ /*
2
+ Document : bp-media-uploader
3
+ Created on : Aug 21, 2012, 1:24:31 PM
4
+ Author : Gagan
5
+ Description:
6
+ Purpose of the stylesheet follows.
7
+ */
8
+ #bp-media-upload-ui{position: relative;}
9
+ #bp-media-upload-ui #drag-drop-area{border: 4px dashed #DDD;height: 200px;}
10
+ #bp-media-upload-ui .drag-drop-inside{margin: 70px auto 0;width: 250px;}
11
+ #bp-media-upload-ui .drag-drop-inside p{display: block;text-align: center;color: #AAA;margin: 5px 0;}
12
+ #bp-media-upload-ui .drag-drop-info{font-size: 20px;}
13
+ #bp-media-upload-ui .drag-drop-buttons input{border-color: #BBB;
14
+ color: #464646;
15
+ text-decoration: none;
16
+ font-size: 12px!important;
17
+ line-height: 13px;
18
+ padding: 3px 8px;
19
+ cursor: pointer;
20
+ border-width: 1px;
21
+ border-style: solid;
22
+ -webkit-border-radius: 11px;
23
+ border-radius: 11px;
24
+ -moz-box-sizing: content-box;
25
+ -webkit-box-sizing: content-box;
26
+ box-sizing: content-box;}
27
+ .bp-media-progressbar{height: 28px;
28
+ margin: 6px 10px 0 0;
29
+ line-height: 2em;
30
+ padding: 0;
31
+ overflow: hidden;
32
+ margin-bottom: 2px;
33
+ border: 1px solid
34
+ #D1D1D1;
35
+ background:
36
+ white;
37
+ background-image: linear-gradient(bottom,
38
+ white 0,
39
+ #F7F7F7 100%);
40
+ background-image: -o-linear-gradient(bottom,
41
+ white 0,
42
+ #F7F7F7 100%);
43
+ background-image: -moz-linear-gradient(bottom,
44
+ white 0,
45
+ #F7F7F7 100%);
46
+ background-image: -webkit-linear-gradient(bottom,
47
+ white 0,
48
+ #F7F7F7 100%);
49
+ background-image: -ms-linear-gradient(bottom,
50
+ white 0,
51
+ #F7F7F7 100%);
52
+ -webkit-border-radius: 3px;
53
+ border-radius: 3px;
54
+ -webkit-box-shadow: inset 0 0 3px
55
+ rgba(0, 0, 0, 0.1);
56
+ box-shadow: inset 0 0 3px
57
+ rgba(0, 0, 0, 0.1)}
58
+
59
+ .bp-media-progress-text{z-index: 10;
60
+ position: relative;
61
+ width: 100%;
62
+ padding: 0 8px;
63
+ text-shadow: 0 1px 0
64
+ rgba(255, 255, 255, 0.4);
65
+ color:
66
+ rgba(0, 0, 0, 0.6);
67
+ font-size:16px;
68
+ line-height: 28px;
69
+ }
70
+
71
+ .bp-media-progress-completed{z-index: 9;
72
+ width: 0;
73
+ height: 35px;
74
+ margin-top: -35px;
75
+ background-color:
76
+ #83B4D8;
77
+ background-image: linear-gradient(bottom,
78
+ #72A7CF 0,
79
+ #90C5EE 100%);
80
+ background-image: -o-linear-gradient(bottom,
81
+ #72A7CF 0,
82
+ #90C5EE 100%);
83
+ background-image: -moz-linear-gradient(bottom,
84
+ #72A7CF 0,
85
+ #90C5EE 100%);
86
+ background-image: -webkit-linear-gradient(bottom,
87
+ #72A7CF 0,
88
+ #90C5EE 100%);
89
+ background-image: -ms-linear-gradient(bottom,
90
+ #72A7CF 0,
91
+ #90C5EE 100%);
92
+ -webkit-border-radius: 3px;
93
+ border-radius: 3px;
94
+ -webkit-box-shadow: 0 0 3px
95
+ rgba(0, 0, 0, 0.3);
96
+ box-shadow: 0 0 3px
97
+ rgba(0, 0, 0, 0.3);
98
+ }
includes/js/bp-media-uploader.js ADDED
@@ -0,0 +1,37 @@
1
+ /*
2
+ * To change this template, choose Tools | Templates
3
+ * and open the template in the editor.
4
+ */
5
+
6
+ jQuery(document).ready(function(){
7
+ var bp_media_uploader=new plupload.Uploader(bp_media_uploader_params);
8
+ bp_media_uploader.init();
9
+ bp_media_uploader.bind('FilesAdded', function(up, files) {
10
+ jQuery.each(files, function(i, file) {
11
+ jQuery('#bp-media-uploaded-files').append(
12
+ '<div id="bp-media-progress-'+file.id+'" class="bp-media-progressbar"><div class="bp-media-progress-text">' +
13
+ file.name + ' (' + plupload.formatSize(file.size) + ')(<b></b>)</div><div class="bp-media-progress-completed"></div></div>');
14
+ });
15
+ bp_media_uploader.start();
16
+ up.refresh(); // Reposition Flash/Silverlight
17
+ });
18
+ bp_media_uploader.bind('UploadProgress', function(up, file) {
19
+ jQuery('#bp-media-progress-'+file.id+' .bp-media-progress-completed').width(file.percent+'%');
20
+ jQuery('#bp-media-progress-'+file.id+' .bp-media-progress-text b').html(file.percent+'%');
21
+ });
22
+
23
+ bp_media_uploader.bind('Error', function(up, err) {
24
+ jQuery('#bp-media-uploaded-files').html('<div class="error"><p>Error: ' + err.code +
25
+ ', Message: ' + err.message +
26
+ (err.file ? ', File: ' + err.file.name : '') +
27
+ '</p></div>'
28
+ );
29
+
30
+ up.refresh(); // Reposition Flash/Silverlight
31
+ });
32
+
33
+ bp_media_uploader.bind('FileUploaded', function(up, file) {
34
+ console.log('done');
35
+ jQuery('#bp-media-progress-'+file.id+' .bp-media-progress-text b').html("100%");
36
+ });
37
+ });
includes/lib/bootstrap.php ADDED
@@ -0,0 +1,35 @@
1
+ <?php
2
+ /**
3
+ * Bootstrap file for getting the ABSPATH constant to wp-load.php
4
+ * This is requried when a plugin requires access not via the admin screen.
5
+ *
6
+ * If the wp-load.php file is not found, then an error will be displayed
7
+ *
8
+ * @package PDF Converter
9
+ * @since Version 0.0
10
+ */
11
+
12
+ /** Define the server path to the file wp-config here, if you placed WP-CONTENT outside the classic file structure */
13
+
14
+ $path = ''; // It should be end with a trailing slash
15
+
16
+ /** That's all, stop editing from here **/
17
+
18
+ if ( !defined('WP_LOAD_PATH') ) {
19
+
20
+ /** classic root path if wp-content and plugins is below wp-config.php */
21
+ $classic_root = dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))) . '/' ;
22
+ if (file_exists( $classic_root . 'wp-load.php') )
23
+ define( 'WP_LOAD_PATH', $classic_root);
24
+ else
25
+ if (file_exists( $path . 'wp-load.php') )
26
+ define( 'WP_LOAD_PATH', $path);
27
+ else
28
+ exit("Could not find wp-load.php");
29
+ }
30
+
31
+ // let's load WordPress
32
+ require_once( WP_LOAD_PATH . 'wp-load.php');
33
+
34
+ //require_once( WP_LOAD_PATH . 'wp-admin/admin.php');
35
+ ?>
includes/media-element/mediaelement-and-player.js CHANGED
@@ -11,147 +11,147 @@
11
* Dual licensed under the MIT or GPL Version 2 licenses.
12
*
13
*/
14
- // Namespace
15
- var mejs = mejs || {};
16
-
17
- // version number
18
- mejs.version = '2.9.1';
19
-
20
- // player number (for missing, same id attr)
21
- mejs.meIndex = 0;
22
-
23
- // media types accepted by plugins
24
- mejs.plugins = {
25
- silverlight: [
26
- {version: [3,0], types: ['video/mp4','video/m4v','video/mov','video/wmv','audio/wma','audio/m4a','audio/mp3','audio/wav','audio/mpeg']}
27
- ],
28
- flash: [
29
- {version: [9,0,124], types: ['video/mp4','video/m4v','video/mov','video/flv','video/x-flv','audio/flv','audio/x-flv','audio/mp3','audio/m4a','audio/mpeg', 'video/youtube', 'video/x-youtube']}
30
- //,{version: [12,0], types: ['video/webm']} // for future reference (hopefully!)
31
- ],
32
- youtube: [
33
- {version: null, types: ['video/youtube', 'video/x-youtube']}
34
- ],
35
- vimeo: [
36
- {version: null, types: ['video/vimeo']}
37
- ]
38
- };
39
-
40
- /*
41
- Utility methods
42
- */
43
- mejs.Utility = {
44
- encodeUrl: function(url) {
45
- return encodeURIComponent(url); //.replace(/\?/gi,'%3F').replace(/=/gi,'%3D').replace(/&/gi,'%26');
46
- },
47
- escapeHTML: function(s) {
48
- return s.toString().split('&').join('&amp;').split('<').join('&lt;').split('"').join('&quot;');
49
- },
50
- absolutizeUrl: function(url) {
51
- var el = document.createElement('div');
52
- el.innerHTML = '<a href="' + this.escapeHTML(url) + '">x</a>';
53
- return el.firstChild.href;
54
- },
55
- getScriptPath: function(scriptNames) {
56
- var
57
- i = 0,
58
- j,
59
- path = '',
60
- name = '',
61
- script,
62
- scripts = document.getElementsByTagName('script'),
63
- il = scripts.length,
64
- jl = scriptNames.length;
65
-
66
- for (; i < il; i++) {
67
- script = scripts[i].src;
68
- for (j = 0; j < jl; j++) {
69
- name = scriptNames[j];
70
- if (script.indexOf(name) > -1) {
71
- path = script.substring(0, script.indexOf(name));
72
- break;
73
- }
74
- }
75
- if (path !== '') {
76
- break;
77
- }
78
- }
79
- return path;
80
- },
81
- secondsToTimeCode: function(time, forceHours, showFrameCount, fps) {
82
- //add framecount
83
- if (typeof showFrameCount == 'undefined') {
84
- showFrameCount=false;
85
- } else if(typeof fps == 'undefined') {
86
- fps = 25;
87
- }
88
-
89
- var hours = Math.floor(time / 3600) % 24,
90
- minutes = Math.floor(time / 60) % 60,
91
- seconds = Math.floor(time % 60),
92
- frames = Math.floor(((time % 1)*fps).toFixed(3)),
93
- result =
94
- ( (forceHours || hours > 0) ? (hours < 10 ? '0' + hours : hours) + ':' : '')
95
- + (minutes < 10 ? '0' + minutes : minutes) + ':'
96
- + (seconds < 10 ? '0' + seconds : seconds)
97
- + ((showFrameCount) ? ':' + (frames < 10 ? '0' + frames : frames) : '');
98
-
99
- return result;
100
- },
101
-
102
- timeCodeToSeconds: function(hh_mm_ss_ff, forceHours, showFrameCount, fps){
103
- if (typeof showFrameCount == 'undefined') {
104
- showFrameCount=false;
105
- } else if(typeof fps == 'undefined') {
106
- fps = 25;
107
- }
108
-
109
- var tc_array = hh_mm_ss_ff.split(":"),
110
- tc_hh = parseInt(tc_array[0], 10),
111
- tc_mm = parseInt(tc_array[1], 10),
112
- tc_ss = parseInt(tc_array[2], 10),
113
- tc_ff = 0,
114
- tc_in_seconds = 0;
115
-
116
- if (showFrameCount) {
117
- tc_ff = parseInt(tc_array[3])/fps;
118
- }
119
-
120
- tc_in_seconds = ( tc_hh * 3600 ) + ( tc_mm * 60 ) + tc_ss + tc_ff;
121
-
122
- return tc_in_seconds;
123
- },
124
-
125
- /* borrowed from SWFObject: http://code.google.com/p/swfobject/source/browse/trunk/swfobject/src/swfobject.js#474 */
126
- removeSwf: function(id) {
127
- var obj = document.getElementById(id);
128
- if (obj && obj.nodeName == "OBJECT") {
129
- if (mejs.MediaFeatures.isIE) {
130
- obj.style.display = "none";
131
- (function(){
132
- if (obj.readyState == 4) {
133
- mejs.Utility.removeObjectInIE(id);
134
- } else {
135
- setTimeout(arguments.callee, 10);
136
- }
137
- })();
138
- } else {
139
- obj.parentNode.removeChild(obj);
140
- }
141
- }
142
- },
143
- removeObjectInIE: function(id) {
144
- var obj = document.getElementById(id);
145
- if (obj) {
146
- for (var i in obj) {
147
- if (typeof obj[i] == "function") {
148
- obj[i] = null;
149
- }
150
- }
151
- obj.parentNode.removeChild(obj);
152
- }
153
- }
154
};
155
156
157
// Core detector, plugins are added below
@@ -1532,1191 +1532,1191 @@ if (typeof jQuery != 'undefined') {
1532
} else if (typeof ender != 'undefined') {
1533
mejs.$ = ender;
1534
}
1535
- (function ($) {
1536
-
1537
- // default player values
1538
- mejs.MepDefaults = {
1539
- // url to poster (to fix iOS 3.x)
1540
- poster: '',
1541
- // default if the <video width> is not specified
1542
- defaultVideoWidth: 480,
1543
- // default if the <video height> is not specified
1544
- defaultVideoHeight: 270,
1545
- // if set, overrides <video width>
1546
- videoWidth: -1,
1547
- // if set, overrides <video height>
1548
- videoHeight: -1,
1549
- // default if the user doesn't specify
1550
- defaultAudioWidth: 400,
1551
- // default if the user doesn't specify
1552
- defaultAudioHeight: 30,
1553
- // width of audio player
1554
- audioWidth: -1,
1555
- // height of audio player
1556
- audioHeight: -1,
1557
- // initial volume when the player starts (overrided by user cookie)
1558
- startVolume: 0.8,
1559
- // useful for <audio> player loops
1560
- loop: false,
1561
- // resize to media dimensions
1562
- enableAutosize: true,
1563
- // forces the hour marker (##:00:00)
1564
- alwaysShowHours: false,
1565
-
1566
- // show framecount in timecode (##:00:00:00)
1567
- showTimecodeFrameCount: false,
1568
- // used when showTimecodeFrameCount is set to true
1569
- framesPerSecond: 25,
1570
-
1571
- // automatically calculate the width of the progress bar based on the sizes of other elements
1572
- autosizeProgress : true,
1573
- // Hide controls when playing and mouse is not over the video
1574
- alwaysShowControls: false,
1575
- // force iPad's native controls
1576
- iPadUseNativeControls: false,
1577
- // force iPhone's native controls
1578
- iPhoneUseNativeControls: false,
1579
- // force Android's native controls
1580
- AndroidUseNativeControls: false,
1581
- // features to show
1582
- features: ['playpause','current','progress','duration','tracks','volume','fullscreen'],
1583
- // only for dynamic
1584
- isVideo: true,
1585
-
1586
- // turns keyboard support on and off for this instance
1587
- enableKeyboard: true,
1588
-
1589
- // whenthis player starts, it will pause other players
1590
- pauseOtherPlayers: true,
1591
-
1592
- // array of keyboard actions such as play pause
1593
- keyActions: [
1594
- {
1595
- keys: [
1596
- 32, // SPACE
1597
- 179 // GOOGLE play/pause button
1598
- ],
1599
- action: function(player, media) {
1600
- if (media.paused || media.ended) {
1601
- media.play();
1602
- } else {
1603
- media.pause();
1604
- }
1605
- }
1606
- },
1607
- {
1608
- keys: [38], // UP
1609
- action: function(player, media) {
1610
- var newVolume = Math.min(media.volume + 0.1, 1);
1611
- media.setVolume(newVolume);
1612
- }
1613
- },
1614
- {
1615
- keys: [40], // DOWN
1616
- action: function(player, media) {
1617
- var newVolume = Math.max(media.volume - 0.1, 0);
1618
- media.setVolume(newVolume);
1619
- }
1620
- },
1621
- {
1622
- keys: [
1623
- 37, // LEFT
1624
- 227 // Google TV rewind
1625
- ],
1626
- action: function(player, media) {
1627
- if (!isNaN(media.duration) && media.duration > 0) {
1628
- if (player.isVideo) {
1629
- player.showControls();
1630
- player.startControlsTimer();
1631
- }
1632
-
1633
- // 5%
1634
- var newTime = Math.max(media.currentTime - (media.duration * 0.05), 0);
1635
- media.setCurrentTime(newTime);
1636
- }
1637
- }
1638
- },
1639
- {
1640
- keys: [
1641
- 39, // RIGHT
1642
- 228 // Google TV forward
1643
- ],
1644
- action: function(player, media) {
1645
- if (!isNaN(media.duration) && media.duration > 0) {
1646
- if (player.isVideo) {
1647
- player.showControls();
1648
- player.startControlsTimer();
1649
- }
1650
-
1651
- // 5%
1652
- var newTime = Math.min(media.currentTime + (media.duration * 0.05), media.duration);
1653
- media.setCurrentTime(newTime);
1654
- }
1655
- }
1656
- },
1657
- {
1658
- keys: [70], // f
1659
- action: function(player, media) {
1660
- if (typeof player.enterFullScreen != 'undefined') {
1661
- if (player.isFullScreen) {
1662
- player.exitFullScreen();
1663
- } else {
1664
- player.enterFullScreen();
1665
- }
1666
- }
1667
- }
1668
- }
1669
- ]
1670
- };
1671
-
1672
- mejs.mepIndex = 0;
1673
-
1674
- mejs.players = [];
1675
-
1676
- // wraps a MediaElement object in player controls
1677
- mejs.MediaElementPlayer = function(node, o) {
1678
- // enforce object, even without "new" (via John Resig)
1679
- if ( !(this instanceof mejs.MediaElementPlayer) ) {
1680
- return new mejs.MediaElementPlayer(node, o);
1681
- }
1682
-
1683
- var t = this;
1684
-
1685
- // these will be reset after the MediaElement.success fires
1686
- t.$media = t.$node = $(node);
1687
- t.node = t.media = t.$media[0];
1688
-
1689
- // check for existing player
1690
- if (typeof t.node.player != 'undefined') {
1691
- return t.node.player;
1692
- } else {
1693
- // attach player to DOM node for reference
1694
- t.node.player = t;
1695
- }
1696
-
1697
-
1698
- // try to get options from data-mejsoptions
1699
- if (typeof o == 'undefined') {
1700
- o = t.$node.data('mejsoptions');
1701
- }
1702
-
1703
- // extend default options
1704
- t.options = $.extend({},mejs.MepDefaults,o);
1705
-
1706
- // add to player array (for focus events)
1707
- mejs.players.push(t);
1708
-
1709
- // start up
1710
- t.init();
1711
1712
- return t;
1713
- };
1714
1715
- // actual player
1716
- mejs.MediaElementPlayer.prototype = {
1717
-
1718
- hasFocus: false,
1719
-
1720
- controlsAreVisible: true,
1721
-
1722
- init: function() {
1723
1724
- var
1725
t = this,
1726
- mf = mejs.MediaFeatures,
1727
- // options for MediaElement (shim)
1728
- meOptions = $.extend(true, {}, t.options, {
1729
- success: function(media, domNode) { t.meReady(media, domNode); },
1730
- error: function(e) { t.handleError(e);}
1731
- }),
1732
- tagName = t.media.tagName.toLowerCase();
1733
-
1734
- t.isDynamic = (tagName !== 'audio' && tagName !== 'video');
1735
-
1736
- if (t.isDynamic) {
1737
- // get video from src or href?
1738
- t.isVideo = t.options.isVideo;
1739
- } else {
1740
- t.isVideo = (tagName !== 'audio' && t.options.isVideo);
1741
- }
1742
-
1743
- // use native controls in iPad, iPhone, and Android
1744
- if ((mf.isiPad && t.options.iPadUseNativeControls) || (mf.isiPhone && t.options.iPhoneUseNativeControls)) {
1745
-
1746
- // add controls and stop
1747
- t.$media.attr('controls', 'controls');
1748
-
1749
- // attempt to fix iOS 3 bug
1750
- //t.$media.removeAttr('poster');
1751
- // no Issue found on iOS3 -ttroxell
1752
-
1753
- // override Apple's autoplay override for iPads
1754
- if (mf.isiPad && t.media.getAttribute('autoplay') !== null) {
1755
- t.media.load();
1756
- t.media.play();
1757
- }
1758
-
1759
- } else if (mf.isAndroid && t.AndroidUseNativeControls) {
1760
-
1761
- // leave default player
1762
-
1763
- } else {
1764
-
1765
- // DESKTOP: use MediaElementPlayer controls
1766
-
1767
- // remove native controls
1768
- t.$media.removeAttr('controls');
1769
-
1770
- // unique ID
1771
- t.id = 'mep_' + mejs.mepIndex++;
1772
-
1773
- // build container
1774
- t.container =
1775
- $('<div id="' + t.id + '" class="mejs-container">'+
1776
- '<div class="mejs-inner">'+
1777
- '<div class="mejs-mediaelement"></div>'+
1778
- '<div class="mejs-layers"></div>'+
1779
- '<div class="mejs-controls"></div>'+
1780
- '<div class="mejs-clear"></div>'+
1781
- '</div>' +
1782
- '</div>')
1783
- .addClass(t.$media[0].className)
1784
- .insertBefore(t.$media);
1785
-
1786
- // add classes for user and content
1787
- t.container.addClass(
1788
- (mf.isAndroid ? 'mejs-android ' : '') +
1789
- (mf.isiOS ? 'mejs-ios ' : '') +
1790
- (mf.isiPad ? 'mejs-ipad ' : '') +
1791
- (mf.isiPhone ? 'mejs-iphone ' : '') +
1792
- (t.isVideo ? 'mejs-video ' : 'mejs-audio ')
1793
- );
1794
-
1795
-
1796
- // move the <video/video> tag into the right spot
1797
- if (mf.isiOS) {
1798
1799
- // sadly, you can't move nodes in iOS, so we have to destroy and recreate it!
1800
- var $newMedia = t.$media.clone();
1801
-
1802
- t.container.find('.mejs-mediaelement').append($newMedia);
1803
-
1804
- t.$media.remove();
1805
- t.$node = t.$media = $newMedia;
1806
- t.node = t.media = $newMedia[0]
1807
-
1808
- } else {
1809
1810
- // normal way of moving it into place (doesn't work on iOS)
1811
- t.container.find('.mejs-mediaelement').append(t.$media);
1812
- }
1813
-
1814
- // find parts
1815
- t.controls = t.container.find('.mejs-controls');
1816
- t.layers = t.container.find('.mejs-layers');
1817
1818
- // determine the size
1819
-
1820
- /* size priority:
1821
- (1) videoWidth (forced),
1822
- (2) style="width;height;"
1823
- (3) width attribute,
1824
- (4) defaultVideoWidth (for unspecified cases)
1825
- */
1826
-
1827
- var capsTagName = tagName.substring(0,1).toUpperCase() + tagName.substring(1);
1828
-
1829
- if (t.options[tagName + 'Width'] > 0 || t.options[tagName + 'Width'].toString().indexOf('%') > -1) {
1830
- t.width = t.options[tagName + 'Width'];
1831
- } else if (t.media.style.width !== '' && t.media.style.width !== null) {
1832
- t.width = t.media.style.width;
1833
- } else if (t.media.getAttribute('width') !== null) {
1834
- t.width = t.$media.attr('width');
1835
- } else {
1836
- t.width = t.options['default' + capsTagName + 'Width'];
1837
- }
1838
-
1839
- if (t.options[tagName + 'Height'] > 0 || t.options[tagName + 'Height'].toString().indexOf('%') > -1) {
1840
- t.height = t.options[tagName + 'Height'];
1841
- } else if (t.media.style.height !== '' && t.media.style.height !== null) {
1842
- t.height = t.media.style.height;
1843
- } else if (t.$media[0].getAttribute('height') !== null) {
1844
- t.height = t.$media.attr('height');
1845
- } else {
1846
- t.height = t.options['default' + capsTagName + 'Height'];
1847
- }
1848
1849
- // set the size, while we wait for the plugins to load below
1850
- t.setPlayerSize(t.width, t.height);
1851
-
1852
- // create MediaElementShim
1853
- meOptions.pluginWidth = t.height;
1854
- meOptions.pluginHeight = t.width;
1855
- }
1856
-
1857
-
1858
1859
- // create MediaElement shim
1860
- mejs.MediaElement(t.$media[0], meOptions);
1861
- },
1862
-
1863
- showControls: function(doAnimation) {
1864
- var t = this;
1865
-
1866
- doAnimation = typeof doAnimation == 'undefined' || doAnimation;
1867
-
1868
- if (t.controlsAreVisible)
1869
- return;
1870
-
1871
- if (doAnimation) {
1872
- t.controls
1873
- .css('visibility','visible')
1874
- .stop(true, true).fadeIn(200, function() {t.controlsAreVisible = true;});
1875
-
1876
- // any additional controls people might add and want to hide
1877
- t.container.find('.mejs-control')
1878
- .css('visibility','visible')
1879
- .stop(true, true).fadeIn(200, function() {t.controlsAreVisible = true;});
1880
-
1881
- } else {
1882
- t.controls
1883
- .css('visibility','visible')
1884
- .css('display','block');
1885
1886
- // any additional controls people might add and want to hide
1887
- t.container.find('.mejs-control')
1888
- .css('visibility','visible')
1889
- .css('display','block');
1890
-
1891
- t.controlsAreVisible = true;
1892
- }
1893
-
1894
- t.setControlsSize();
1895
-
1896
- },
1897
1898
- hideControls: function(doAnimation) {
1899
- var t = this;
1900
-
1901
- doAnimation = typeof doAnimation == 'undefined' || doAnimation;
1902
-
1903
- if (!t.controlsAreVisible)
1904
- return;
1905
-
1906
- if (doAnimation) {
1907
- // fade out main controls
1908
- t.controls.stop(true, true).fadeOut(200, function() {
1909
- $(this)
1910
- .css('visibility','hidden')
1911
- .css('display','block');
1912
-
1913
- t.controlsAreVisible = false;
1914
- });
1915
-
1916
- // any additional controls people might add and want to hide
1917
- t.container.find('.mejs-control').stop(true, true).fadeOut(200, function() {
1918
- $(this)
1919
- .css('visibility','hidden')
1920
- .css('display','block');
1921
- });
1922
- } else {
1923
-
1924
- // hide main controls
1925
- t.controls
1926
- .css('visibility','hidden')
1927
- .css('display','block');
1928
-
1929
- // hide others
1930
- t.container.find('.mejs-control')
1931
- .css('visibility','hidden')
1932
- .css('display','block');
1933
-
1934
- t.controlsAreVisible = false;
1935
- }
1936
- },
1937
1938
- controlsTimer: null,
1939
1940
- startControlsTimer: function(timeout) {
1941
1942
- var t = this;
1943
-
1944
- timeout = typeof timeout != 'undefined' ? timeout : 1500;
1945
1946
- t.killControlsTimer('start');
1947
1948
- t.controlsTimer = setTimeout(function() {
1949
- //console.log('timer fired');
1950
- t.hideControls();
1951
- t.killControlsTimer('hide');
1952
- }, timeout);
1953
- },
1954
1955
- killControlsTimer: function(src) {
1956
-
1957
- var t = this;
1958
-
1959
- if (t.controlsTimer !== null) {
1960
- clearTimeout(t.controlsTimer);
1961
- delete t.controlsTimer;
1962
- t.controlsTimer = null;
1963
- }
1964
- },
1965
-
1966
- controlsEnabled: true,
1967
-
1968
- disableControls: function() {
1969
- var t= this;
1970
-
1971
- t.killControlsTimer();
1972
- t.hideControls(false);
1973
- this.controlsEnabled = false;
1974
- },
1975
-
1976
- enableControls: function() {
1977
- var t= this;
1978
-
1979
- t.showControls(false);
1980
-
1981
- t.controlsEnabled = true;
1982
- },
1983
-
1984
-
1985
- // Sets up all controls and events
1986
- meReady: function(media, domNode) {
1987
-
1988
-
1989
- var t = this,
1990
- mf = mejs.MediaFeatures,
1991
- autoplayAttr = domNode.getAttribute('autoplay'),
1992
- autoplay = !(typeof autoplayAttr == 'undefined' || autoplayAttr === null || autoplayAttr === 'false'),
1993
- featureIndex,
1994
- feature;
1995
-
1996
- // make sure it can't create itself again if a plugin reloads
1997
- if (t.created)
1998
- return;
1999
- else
2000
- t.created = true;
2001
-
2002
- t.media = media;
2003
- t.domNode = domNode;
2004
-
2005
- if (!(mf.isAndroid && t.options.AndroidUseNativeControls) && !(mf.isiPad && t.options.iPadUseNativeControls) && !(mf.isiPhone && t.options.iPhoneUseNativeControls)) {
2006
-
2007
- // two built in features
2008
- t.buildposter(t, t.controls, t.layers, t.media);
2009
- t.buildkeyboard(t, t.controls, t.layers, t.media);
2010
- t.buildoverlays(t, t.controls, t.layers, t.media);
2011
-
2012
- // grab for use by features
2013
- t.findTracks();
2014
-
2015
- // add user-defined features/controls
2016
- for (featureIndex in t.options.features) {
2017
- feature = t.options.features[featureIndex];
2018
- if (t['build' + feature]) {
2019
- try {
2020
- t['build' + feature](t, t.controls, t.layers, t.media);
2021
- } catch (e) {
2022
- // TODO: report control error
2023
- //throw e;
2024
- //console.log('error building ' + feature);
2025
- //console.log(e);
2026
- }
2027
- }
2028
- }
2029
-
2030
- t.container.trigger('controlsready');
2031
-
2032
- // reset all layers and controls
2033
- t.setPlayerSize(t.width, t.height);
2034
- t.setControlsSize();
2035
-
2036
-
2037
- // controls fade
2038
- if (t.isVideo) {
2039
-
2040
- if (mejs.MediaFeatures.hasTouch) {
2041
-
2042
- // for touch devices (iOS, Android)
2043
- // show/hide without animation on touch
2044
-
2045
- t.$media.bind('touchstart', function() {
2046
-
2047
-
2048
- // toggle controls
2049
- if (t.controlsAreVisible) {
2050
- t.hideControls(false);
2051
- } else {
2052
- if (t.controlsEnabled) {
2053
- t.showControls(false);
2054
- }
2055
- }
2056
- });
2057
-
2058
- } else {
2059
- // click controls
2060
- var clickElement = (t.media.pluginType == 'native') ? t.$media : $(t.media.pluginElement);
2061
-
2062
- // click to play/pause
2063
- clickElement.click(function() {
2064
- if (media.paused) {
2065
- media.play();
2066
- } else {
2067
- media.pause();
2068
- }
2069
- });
2070
-
2071
-
2072
- // show/hide controls
2073
- t.container
2074
- .bind('mouseenter mouseover', function () {
2075
- if (t.controlsEnabled) {
2076
- if (!t.options.alwaysShowControls) {
2077
- t.killControlsTimer('enter');
2078
- t.showControls();
2079
- t.startControlsTimer(2500);
2080
- }
2081
- }
2082
- })
2083
- .bind('mousemove', function() {
2084
- if (t.controlsEnabled) {
2085