rtMedia for WordPress, BuddyPress and bbPress - Version 2.7.2

Version Description

  • Fixes warning related to scalar variables
  • Improves Group Wall Post handling
  • Adds lightbox to activity media
  • Fixes mediaelement display
  • Implements forced download for media
  • Fixes image rotation on upload
  • Fixes broken spinner image
  • Fixes some styling
Download this release

Release Info

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

Code changes from version 2.7.1 to 2.7.2

app/assets/img/boxspinner.gif CHANGED
Binary file
app/assets/js/main.js CHANGED
@@ -1,31 +1,43 @@
1
  /*
2
  * BuddyPress Media Default JS
3
  */
4
-
5
  function bp_media_create_element(id){
6
- jQuery('#'+id).mediaelementplayer({
7
- enableKeyboard: false,
8
- startVolume: 1,
9
- success: function(mediaElement,domElement){
10
- var $thisMediaElement = (mediaElement.id) ? jQuery("#"+mediaElement.id) : jQuery(mediaElement);
11
- $thisMediaElement.parents('.mejs-container').find(".mejs-volume-current").css("top","8px");
12
- $thisMediaElement.parents('.mejs-container').find(".mejs-volume-handle").css("top","5px");
13
- }
14
- });
15
  }
16
  var $current;
17
  jQuery(document).ready(function(){
18
 
19
- jQuery('#item-body').on('click','#bp-media-upload-button', function(){
20
- jQuery(this).next().slideToggle();
21
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
- jQuery('#bp-media-upload-ui').bind('dragover', function(e){
24
- jQuery(this).addClass('hover');return 0;
25
- });
26
- jQuery('#bp-media-upload-ui').bind('dragleave', function(e){
27
- jQuery(this).removeClass('hover');return 0;
28
- });
 
 
29
 
30
  var bp_media_recent_tabs = jQuery('.media-tabs-container-tabs');
31
  if(bp_media_recent_tabs.length>0){
@@ -89,42 +101,55 @@ jQuery(document).ready(function(){
89
  $current = jQuery(this);
90
  load_media($current);
91
  });
 
 
 
 
 
 
92
  jQuery('body').on('click','a.modal-next', function(e){
93
  e.preventDefault();
94
- $next_current = $current.closest('li').next().find('a');
95
- if($next_current.length<1){
96
- var args = load_more_data();
97
- var request = jQuery.get(bp_media_vars.ajaxurl, args);
98
- chained = request.then(function( data ) {
99
- if(data.length==0){
100
- jQuery('#bp-media-show-more').parent().remove();
101
- return false;
102
- }else{
103
- jQuery('#bp-media-list').append(data);
104
- return true;
105
- }
106
- });
 
 
 
107
 
108
- chained.done(function( truth ) {
109
- if(truth!=false){
110
- $next_current = $current.closest('li').next().find('a');
111
- $current = $next_current;
112
- transit_media($current);
 
 
113
  }
114
- });
115
- }else{
116
- $current = $next_current;
117
- transit_media($next_current);
118
  }
119
 
120
 
121
  });
122
  jQuery('body').on('click','a.modal-prev', function(e){
123
  e.preventDefault();
124
- if($current.closest('li').prev().length>0 && $current.closest('li').prev().find('#bp-media-upload-ui').length<1 ){
125
- $current = $current.closest('li').prev().find('a');
 
126
 
127
- transit_media($current);
 
128
  }
129
  });
130
  jQuery(document.documentElement).keyup(function (event) {
@@ -218,8 +243,8 @@ jQuery(document).ready(function(){
218
  jQuery('form.ac-form').hide();
219
 
220
  /* Hide excess comments */
221
- // if ( jQuery('.activity-comments').length )
222
- // bp_legacy_theme_hide_comments();
223
 
224
  /* Activity list event delegation */
225
  jQuery('body').on( 'click', '.bp-media-ajax-single div.activity',function(event) {
@@ -246,6 +271,7 @@ jQuery(document).ready(function(){
246
  );
247
  }
248
 
 
249
  /* Favoriting activity stream items */
250
  if ( target.hasClass('fav') || target.hasClass('unfav') ) {
251
  console.log('hua');
1
  /*
2
  * BuddyPress Media Default JS
3
  */
4
+ //Legacy media element for old activities
5
  function bp_media_create_element(id){
6
+ return false;
 
 
 
 
 
 
 
 
7
  }
8
  var $current;
9
  jQuery(document).ready(function(){
10
 
11
+ jQuery('ul#activity-stream').on('mediapreview','video,audio', function(){
12
+ jQuery(this).mediaelementplayer({
13
+ enableKeyboard: false,
14
+ startVolume: 1,
15
+ success: function(mediaElement,domElement){
16
+ var $thisMediaElement = (mediaElement.id) ? jQuery("#"+mediaElement.id) : jQuery(mediaElement);
17
+ $thisMediaElement.parents('.mejs-container').find(".mejs-volume-current").css("top","8px");
18
+ $thisMediaElement.parents('.mejs-container').find(".mejs-volume-handle").css("top","5px");
19
+ }
20
+ });
21
+ });
22
+ jQuery('ul#activity-stream audio,ul#activity-stream video').trigger('mediapreview');
23
+
24
+ jQuery('ul#activity-stream').on('DOMNodeInserted', function(){
25
+ jQuery('ul#activity-stream audio,ul#activity-stream video').trigger('mediapreview');
26
+ })
27
+
28
+
29
+ jQuery('#item-body').on('click','#bp-media-upload-button', function(){
30
+ jQuery(this).next().slideToggle();
31
+ });
32
 
33
+ jQuery('#bp-media-upload-ui').bind('dragover', function(e){
34
+ jQuery(this).addClass('hover');
35
+ return 0;
36
+ });
37
+ jQuery('#bp-media-upload-ui').bind('dragleave', function(e){
38
+ jQuery(this).removeClass('hover');
39
+ return 0;
40
+ });
41
 
42
  var bp_media_recent_tabs = jQuery('.media-tabs-container-tabs');
43
  if(bp_media_recent_tabs.length>0){
101
  $current = jQuery(this);
102
  load_media($current);
103
  });
104
+ jQuery('ul#activity-stream').on('click',
105
+ 'li.media.album_updated ul li a, ul.bp-media-list-media li a, li.activity-item div.activity-content div.activity-inner div.bp_media_content a',function(e){
106
+ e.preventDefault();
107
+ $current = jQuery(this);
108
+ load_media($current);
109
+ });
110
  jQuery('body').on('click','a.modal-next', function(e){
111
  e.preventDefault();
112
+ if(!$current.parent().hasClass('bp_media_content')){
113
+ $next_current = $current.closest('li').next().find('a');
114
+ console.log(jQuery('#bp-media-show-more').length);
115
+ if($next_current.length<1){
116
+ if(jQuery('#bp-media-show-more').length>0){
117
+ var args = load_more_data();
118
+ var request = jQuery.get(bp_media_vars.ajaxurl, args);
119
+ chained = request.then(function( data ) {
120
+ if(data.length==0){
121
+ jQuery('#bp-media-show-more').parent().remove();
122
+ return false;
123
+ }else{
124
+ jQuery('#bp-media-list').append(data);
125
+ return true;
126
+ }
127
+ });
128
 
129
+ chained.done(function( truth ) {
130
+ if(truth!=false){
131
+ $next_current = $current.closest('li').next().find('a');
132
+ $current = $next_current;
133
+ transit_media($current);
134
+ }
135
+ });
136
  }
137
+ }else{
138
+ $current = $next_current;
139
+ transit_media($next_current);
140
+ }
141
  }
142
 
143
 
144
  });
145
  jQuery('body').on('click','a.modal-prev', function(e){
146
  e.preventDefault();
147
+ if(!$current.parent().hasClass('bp_media_content')){
148
+ if($current.closest('li').prev().length>0 && $current.closest('li').prev().find('#bp-media-upload-ui').length<1 ){
149
+ $current = $current.closest('li').prev().find('a');
150
 
151
+ transit_media($current);
152
+ }
153
  }
154
  });
155
  jQuery(document.documentElement).keyup(function (event) {
243
  jQuery('form.ac-form').hide();
244
 
245
  /* Hide excess comments */
246
+ // if ( jQuery('.activity-comments').length )
247
+ // bp_legacy_theme_hide_comments();
248
 
249
  /* Activity list event delegation */
250
  jQuery('body').on( 'click', '.bp-media-ajax-single div.activity',function(event) {
271
  );
272
  }
273
 
274
+
275
  /* Favoriting activity stream items */
276
  if ( target.hasClass('fav') || target.hasClass('unfav') ) {
277
  console.log('hua');
app/main/BuddyPressMedia.php CHANGED
@@ -353,6 +353,7 @@ class BuddyPressMedia {
353
  'actions' => false,
354
  'function' => false,
355
  'privacy' => false,
 
356
  );
357
  $class_construct = apply_filters('bpmedia_class_construct', $class_construct);
358
 
@@ -682,7 +683,7 @@ class BuddyPressMedia {
682
  $plugin_version = $plugin_data['Version'];
683
  return $plugin_version;
684
  }
685
-
686
  static function get_current_user_default_album(){
687
  if ( is_user_logged_in() ) {
688
  $current_user_id = get_current_user_id();
353
  'actions' => false,
354
  'function' => false,
355
  'privacy' => false,
356
+ 'download' => false
357
  );
358
  $class_construct = apply_filters('bpmedia_class_construct', $class_construct);
359
 
683
  $plugin_version = $plugin_data['Version'];
684
  return $plugin_version;
685
  }
686
+
687
  static function get_current_user_default_album(){
688
  if ( is_user_logged_in() ) {
689
  $current_user_id = get_current_user_id();
app/main/includes/BPMediaActions.php CHANGED
@@ -38,6 +38,7 @@ class BPMediaActions {
38
  add_action('bp_media_after_add_media', array($this, 'update_count'), 999);
39
  add_action('bp_media_after_update_media', array($this, 'update_count'), 999);
40
  add_action('bp_media_after_delete_media', array($this, 'update_count'), 999);
 
41
  $linkback = bp_get_option('bp_media_add_linkback', false);
42
  if ($linkback)
43
  add_action('bp_footer', array($this, 'footer'));
@@ -303,7 +304,7 @@ class BPMediaActions {
303
  if ($bp_media_current_entry != NULL) {
304
 
305
  if (isset($bp_media->options['download_enabled']))
306
- $action_buttons[] = '<a href="' . $bp_media_current_entry->get_attachment_url()
307
  . '" target="_blank" class="button item-button bp-secondary-action bp-media-download" title="'
308
  . __('Download', BP_MEDIA_TXT_DOMAIN) . '">' . __('Download', BP_MEDIA_TXT_DOMAIN) . '</a>';
309
 
@@ -479,10 +480,10 @@ class BPMediaActions {
479
  wp_localize_script('bp-media-activity-uploader', 'bp_media_uploader_params', $params);
480
  wp_localize_script('bp-media-activity-uploader', 'activity_ajax_url', admin_url('admin-ajax.php'));
481
  if (bp_is_active('groups') && bp_get_current_group_id())
482
- $default_album = $this->default_group_album();
483
  else
484
- $default_album = $this->default_user_album();
485
- wp_localize_script('bp-media-activity-uploader', 'default_album', $default_album ? $default_album : 0);
486
  } elseif (in_array(bp_current_action(), array(BP_MEDIA_IMAGES_SLUG, BP_MEDIA_VIDEOS_SLUG, BP_MEDIA_AUDIO_SLUG, BP_MEDIA_SLUG, BP_MEDIA_ALBUMS_SLUG))) {
487
  $params = array(
488
  'url' => BP_MEDIA_URL . 'app/main/includes/bp-media-upload-handler.php',
@@ -916,5 +917,10 @@ class BPMediaActions {
916
  return $album_id;
917
  }
918
 
 
 
 
 
 
919
  }
920
  ?>
38
  add_action('bp_media_after_add_media', array($this, 'update_count'), 999);
39
  add_action('bp_media_after_update_media', array($this, 'update_count'), 999);
40
  add_action('bp_media_after_delete_media', array($this, 'update_count'), 999);
41
+ add_action('bp_before_group_settings_creation_step', array($this, 'group_create_default_album'));
42
  $linkback = bp_get_option('bp_media_add_linkback', false);
43
  if ($linkback)
44
  add_action('bp_footer', array($this, 'footer'));
304
  if ($bp_media_current_entry != NULL) {
305
 
306
  if (isset($bp_media->options['download_enabled']))
307
+ $action_buttons[] = '<a href="' . admin_url('admin-ajax.php').'?action=bp_media_download&file='.$bp_media_current_entry->get_attachment_url()
308
  . '" target="_blank" class="button item-button bp-secondary-action bp-media-download" title="'
309
  . __('Download', BP_MEDIA_TXT_DOMAIN) . '">' . __('Download', BP_MEDIA_TXT_DOMAIN) . '</a>';
310
 
480
  wp_localize_script('bp-media-activity-uploader', 'bp_media_uploader_params', $params);
481
  wp_localize_script('bp-media-activity-uploader', 'activity_ajax_url', admin_url('admin-ajax.php'));
482
  if (bp_is_active('groups') && bp_get_current_group_id())
483
+ $default_album = (string)$this->default_group_album();
484
  else
485
+ $default_album = (string)$this->default_user_album();
486
+ wp_localize_script('bp-media-activity-uploader', 'default_album', $default_album ? $default_album : '0');
487
  } elseif (in_array(bp_current_action(), array(BP_MEDIA_IMAGES_SLUG, BP_MEDIA_VIDEOS_SLUG, BP_MEDIA_AUDIO_SLUG, BP_MEDIA_SLUG, BP_MEDIA_ALBUMS_SLUG))) {
488
  $params = array(
489
  'url' => BP_MEDIA_URL . 'app/main/includes/bp-media-upload-handler.php',
917
  return $album_id;
918
  }
919
 
920
+ function group_create_default_album() {
921
+ $bp_album = new BPMediaHostWordpress();
922
+ $bp_album->check_and_create_album(0, bp_get_new_group_id());
923
+ }
924
+
925
  }
926
  ?>
app/main/includes/BPMediaDownload.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * To change this template, choose Tools | Templates
5
+ * and open the template in the editor.
6
+ */
7
+
8
+ /**
9
+ * Description of BPMediaDownload
10
+ *
11
+ * @author saurabh
12
+ */
13
+ class BPMediaDownload {
14
+
15
+ /**
16
+ *
17
+ */
18
+ function __construct() {
19
+ add_action('wp_ajax_bp_media_download', array($this,'download_now'));
20
+ add_action('wp_ajax_no_priv_bp_media_download', array($this,'download_now'));
21
+ }
22
+
23
+ function force_download($file) {
24
+ if ( file_exists( $file ) ) {
25
+ header( 'Content-Description: File Transfer' );
26
+ header( 'Content-Type: application/octet-stream' );
27
+ header( 'Content-Disposition: attachment; filename=' . basename( $file ) );
28
+ header( 'Content-Transfer-Encoding: binary' );
29
+ header( 'Expires: 0' );
30
+ header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
31
+ header( 'Pragma: public' );
32
+ header( 'Content-Length: ' . filesize( $file ) );
33
+ echo readfile( $file );
34
+ exit;
35
+ }
36
+ return false;
37
+ }
38
+
39
+ function get_path_from_url($file){
40
+ $upload_info = wp_upload_dir();
41
+ if(empty($upload_info['error'])){
42
+
43
+ $upload_base_path = $upload_info['basedir'];
44
+ $upload_base_url = $upload_info['baseurl'];
45
+ $file_path = str_replace($upload_base_url,$upload_base_path,$file);
46
+
47
+ $path_info= pathinfo($file_path);
48
+ if (in_array($path_info['extension'],array('gif','png','jpg','mp4','mp3'))){
49
+ return $file_path;
50
+ }
51
+
52
+
53
+ }
54
+ return false;
55
+ }
56
+
57
+ function download_now(){
58
+ if ( isset( $_GET[ 'file' ] ) ) {
59
+ $file = $_GET[ 'file' ];
60
+ $file = $this->get_path_from_url($file);
61
+ $this->force_download($file);
62
+ die();
63
+ }
64
+ }
65
+
66
+ }
67
+
68
+ ?>
app/main/includes/BPMediaFilters.php CHANGED
@@ -18,10 +18,10 @@ class BPMediaFilters {
18
  // and we hook our function via wp_before_admin_bar_render
19
  add_action('admin_bar_menu', array($this, 'my_account_menu'), 1);
20
  // and we hook our function via wp_before_admin_bar_render
21
- global $bp_media;
22
- if(isset($bp_media->options['show_admin_menu']) && ($bp_media->options['show_admin_menu']==true)){
23
- add_action('wp_before_admin_bar_render', 'BPMediaFilters::adminbar_settings_menu');
24
- }
25
  global $bp_media_activity_types;
26
  $bp_media_activity_types = array('media_upload', 'album_updated', 'album_created');
27
  }
@@ -115,28 +115,32 @@ class BPMediaFilters {
115
  function delete_button_handler($link) {
116
  global $activities_template;
117
  $media_label = NULL;
 
 
 
 
118
 
119
- if (bp_current_component() == 'media')
120
- $link = str_replace('delete-activity ', 'delete-activity-single ', $link);
121
-
122
- if ('album_updated' == $activities_template->activity->type) {
123
  $media_label = BP_MEDIA_ALBUMS_LABEL_SINGULAR;
124
- } elseif ($activities_template->activity->item_id) {
125
- $mime_type = get_post_field('post_mime_type', $activities_template->activity->item_id);
126
- $media_type = explode('/', $mime_type);
127
- switch ($media_type[0]) {
128
- case 'image': $media_label = BP_MEDIA_IMAGES_LABEL_SINGULAR;
129
- break;
130
- case 'audio': $media_label = BP_MEDIA_AUDIO_LABEL_SINGULAR;
131
- break;
132
- case 'video': $media_label = BP_MEDIA_VIDEOS_LABEL_SINGULAR;
133
- break;
 
 
 
 
 
134
  }
135
  }
136
-
137
  if ($media_label)
138
  $link = str_replace('Delete', sprintf(__('Delete %s', BP_MEDIA_TXT_DOMAIN), $media_label), $link);
139
-
140
  return $link;
141
  }
142
 
@@ -199,7 +203,7 @@ class BPMediaFilters {
199
  * @return type
200
  */
201
  static function group_activity_query_filter($query) {
202
- global $wpdb,$bp;
203
  $activity_meta_table = $bp->activity->table_name_meta;
204
  $query = preg_replace("/LEFT JOIN/i", "LEFT JOIN $activity_meta_table am ON a.id = am.activity_id LEFT JOIN", $query);
205
  $query = preg_replace("/a.component IN \( 'groups' \) AND a.item_id IN \((.*)\)/i", "( ( a.component IN ( 'groups' ) AND a.item_id IN ( $1 ) ) OR ( a.component IN ( 'media' ) AND am.meta_key = 'group_id' AND am.meta_value IN ( $1 ) ) )", $query);
18
  // and we hook our function via wp_before_admin_bar_render
19
  add_action('admin_bar_menu', array($this, 'my_account_menu'), 1);
20
  // and we hook our function via wp_before_admin_bar_render
21
+ global $bp_media;
22
+ if (isset($bp_media->options['show_admin_menu']) && ($bp_media->options['show_admin_menu'] == true)) {
23
+ add_action('wp_before_admin_bar_render', 'BPMediaFilters::adminbar_settings_menu');
24
+ }
25
  global $bp_media_activity_types;
26
  $bp_media_activity_types = array('media_upload', 'album_updated', 'album_created');
27
  }
115
  function delete_button_handler($link) {
116
  global $activities_template;
117
  $media_label = NULL;
118
+ $link = str_replace('delete-activity ', 'delete-activity-single ', $link);
119
+ $activity_type = bp_get_activity_type();
120
+ $activity_id = bp_get_activity_id();
121
+ $activity_item_id = bp_get_activity_item_id();
122
 
123
+ if ('album_updated' == $activity_type) {
 
 
 
124
  $media_label = BP_MEDIA_ALBUMS_LABEL_SINGULAR;
125
+ } elseif ($activity_id) {
126
+ $query = new WP_Query(array('post_type' => 'attachment', 'post_status' => 'inherit', 'id' => $activity_item_id, 'meta_key' => 'bp_media_child_activity', 'meta_value' => "$activity_id"));
127
+ wp_reset_postdata();
128
+ wp_reset_query();
129
+ if ($query->found_posts) {
130
+ $mime_type = get_post_field('post_mime_type', bp_get_activity_item_id());
131
+ $media_type = explode('/', $mime_type);
132
+ switch ($media_type[0]) {
133
+ case 'image': $media_label = BP_MEDIA_IMAGES_LABEL_SINGULAR;
134
+ break;
135
+ case 'audio': $media_label = BP_MEDIA_AUDIO_LABEL_SINGULAR;
136
+ break;
137
+ case 'video': $media_label = BP_MEDIA_VIDEOS_LABEL_SINGULAR;
138
+ break;
139
+ }
140
  }
141
  }
 
142
  if ($media_label)
143
  $link = str_replace('Delete', sprintf(__('Delete %s', BP_MEDIA_TXT_DOMAIN), $media_label), $link);
 
144
  return $link;
145
  }
146
 
203
  * @return type
204
  */
205
  static function group_activity_query_filter($query) {
206
+ global $wpdb, $bp;
207
  $activity_meta_table = $bp->activity->table_name_meta;
208
  $query = preg_replace("/LEFT JOIN/i", "LEFT JOIN $activity_meta_table am ON a.id = am.activity_id LEFT JOIN", $query);
209
  $query = preg_replace("/a.component IN \( 'groups' \) AND a.item_id IN \((.*)\)/i", "( ( a.component IN ( 'groups' ) AND a.item_id IN ( $1 ) ) OR ( a.component IN ( 'media' ) AND am.meta_key = 'group_id' AND am.meta_value IN ( $1 ) ) )", $query);
app/main/includes/BPMediaHostWordpress.php CHANGED
@@ -2,973 +2,1018 @@
2
 
3
  class BPMediaHostWordpress {
4
 
5
- /**
6
- * Private variables not to be accessible outside this class' member functions
7
- */
8
- protected $id, //id of the entry
9
- $name, //Name of the entry
10
- $description, //Description of the entry
11
- $url, //URL of the entry
12
- $type, //Type of the entry (Video, Image or Audio)
13
- $owner, //Owner of the entry
14
- $delete_url, //The delete url for the media
15
- $thumbnail_id, //The thumbnail's id
16
- $album_id, //The album id to which the media belongs
17
- $edit_url, //The edit page's url for the media
18
- $group_id; //The group id of the current media file if it belongs to a group
19
-
20
- /**
21
- * Constructs a new BP_Media_Host_Wordpress element
22
- *
23
- * @param mixed $media_id optional Media ID of the element to be initialized if not defined, returns an empty element.
24
- *
25
- * @since BuddyPress Media 2.0
26
- */
27
-
28
- /**
29
- *
30
- * @param type $media_id
31
- */
32
- function __construct( $media_id = '' ) {
33
- if ( ! $media_id == '' ) {
34
- $this->init( $media_id );
35
- }
36
- }
37
-
38
- /**
39
- * Initializes the object with the variables from the post
40
- *
41
- * @param mixed $media_id Media ID of the element to be initialized. Can be the ID or the object of the Media
42
- *
43
- * @since BuddyPress Media 2.0
44
- */
45
-
46
- /**
47
- *
48
- * @param type $media_id
49
- * @return boolean
50
- * @throws Exception
51
- */
52
- function init( $media_id = '') {
53
- if ( is_object( $media_id ) ) {
54
- $media = $media_id;
55
- } else {
56
- $media = &get_post( $media_id );
57
- }
58
- if ( empty( $media->ID ) )
59
- throw new Exception( __( 'Sorry, the requested media does not exist.', BP_MEDIA_TXT_DOMAIN ) );
60
- if ( ! 'bp_media_album' == $media->post_type || ! empty( $media->post_mime_type ) )
61
- preg_match_all( '/audio|video|image/i', $media->post_mime_type, $result );
62
- else
63
- $result[ 0 ][ 0 ] = 'album';
64
- if ( isset( $result[ 0 ][ 0 ] ) )
65
- $this->type = $result[ 0 ][ 0 ];
66
- else
67
- return false;
68
-
69
- $required_access = BPMediaPrivacy::required_access($media->ID);
70
- $current_access = BPMediaPrivacy::current_access($media->ID);
71
- $has_access = BPMediaPrivacy::has_access($media->ID);
72
-
73
-
74
- global $bp;
75
- $messages = BPMediaPrivacy::get_messages( $this->type,$bp->displayed_user->fullname );
76
- $this->id = $media->ID;
77
- $meta_key = get_post_meta( $this->id, 'bp-media-key', true );
78
-
79
- /**
80
- * We use bp-media-key to distinguish if the entry belongs to a group or not
81
- * if the value is less than 0 it means it the group id to which the media belongs
82
- * and if its greater than 0 then it means its the author id of the uploader
83
- * But for use in the class, we use group_id as positive integer even though
84
- * we use it as negative value in the bp-media-key meta key
85
- */
86
- $this->group_id = $meta_key < 0 ? -$meta_key : 0;
87
- if($this->group_id<=0){
88
- if(!$has_access){
89
- throw new Exception('<img src="'.BP_MEDIA_URL.'app/assets/img/private.png" title="'. $messages[$required_access] . '" />');
90
- }
91
- }
92
-
93
- $this->description = $media->post_content;
94
- $this->name = $media->post_title;
95
- $this->owner = $media->post_author;
96
- $this->album_id = $media->post_parent;
97
- $this->mime_type = $media->post_mime_type;
98
-
99
-
100
- $this->set_permalinks();
101
- }
102
-
103
- /**
104
- * Handles the uploaded media file and creates attachment post for the file.
105
- *
106
- * @since BuddyPress Media 2.0
107
- */
108
-
109
- /**
110
- *
111
- * @global type $bp
112
- * @global type $wpdb
113
- * @global type $bp_media_count
114
- * @global type $bp_media
115
- * @param type $name
116
- * @param type $description
117
- * @param type $album_id
118
- * @param type $group
119
- * @param type $is_multiple
120
- * @throws Exception
121
- * @uses global var $_FILES
122
- */
123
- function add_media( $name, $description, $album_id = 0, $group = 0, $is_multiple = false, $is_activity = false, $files = false ) {
124
- do_action( 'bp_media_before_add_media' );
125
-
126
- global $bp, $wpdb, $bp_media;
127
- include_once(ABSPATH . 'wp-admin/includes/file.php');
128
- include_once(ABSPATH . 'wp-admin/includes/image.php');
129
-
130
- $post_id = $this->check_and_create_album( $album_id, $group );
131
-
132
- if ( ! $files ) {
133
- $files = $_FILES[ 'bp_media_file' ];
134
- $file = wp_handle_upload( $files );
135
- } else {
136
- $file = wp_handle_sideload( $files );
137
- }
138
-
139
- if ( isset( $file[ 'error' ] ) || $file === null ) {
140
- throw new Exception( __( 'Error Uploading File', BP_MEDIA_TXT_DOMAIN ) );
141
- }
142
-
143
- $attachment = array( );
144
- $url = $file[ 'url' ];
145
- $type = $file[ 'type' ];
146
- $file = $file[ 'file' ];
147
- $title = $name;
148
- $content = $description;
149
- $attachment = array(
150
- 'post_mime_type' => $type,
151
- 'guid' => $url,
152
- 'post_title' => $title,
153
- 'post_content' => $content,
154
- 'post_parent' => $post_id,
155
- );
156
- switch ( $type ) {
157
- case 'video/mp4' :
158
- case 'video/quicktime' :
159
- $type = 'video';
160
- include_once(trailingslashit( BP_MEDIA_PATH ) . 'lib/getid3/getid3.php');
161
- try {
162
- $getID3 = new getID3;
163
- $vid_info = $getID3->analyze( $file );
164
- } catch ( Exception $e ) {
165
- unlink( $file );
166
- $activity_content = false;
167
- throw new Exception( __( 'MP4 file you have uploaded is corrupt.', BP_MEDIA_TXT_DOMAIN ) );
168
- }
169
- if ( is_array( $vid_info ) ) {
170
- if ( ! array_key_exists( 'error', $vid_info ) && array_key_exists( 'fileformat', $vid_info ) && array_key_exists( 'video', $vid_info ) && array_key_exists( 'fourcc', $vid_info[ 'video' ] ) ) {
171
- if ( ! ($vid_info[ 'fileformat' ] == 'mp4' && $vid_info[ 'video' ][ 'fourcc' ] == 'avc1') ) {
172
- unlink( $file );
173
- $activity_content = false;
174
- throw new Exception( __( 'The MP4 file you have uploaded is using an unsupported video codec. Supported video codec is H.264.', BP_MEDIA_TXT_DOMAIN ) );
175
- }
176
- } else {
177
- unlink( $file );
178
- $activity_content = false;
179
- throw new Exception( __( 'The MP4 file you have uploaded is using an unsupported video codec. Supported video codec is H.264.', BP_MEDIA_TXT_DOMAIN ) );
180
- }
181
- } else {
182
- unlink( $file );
183
- $activity_content = false;
184
- throw new Exception( __( 'The MP4 file you have uploaded is not a video file.', BP_MEDIA_TXT_DOMAIN ) );
185
- }
186
- break;
187
- case 'audio/mpeg' :
188
- include_once(trailingslashit( BP_MEDIA_PATH ) . 'lib/getid3/getid3.php');
189
- try {
190
- $getID3 = new getID3;
191
- $file_info = $getID3->analyze( $file );
192
- } catch ( Exception $e ) {
193
- unlink( $file );
194
- $activity_content = false;
195
- throw new Exception( __( 'MP3 file you have uploaded is currupt.', BP_MEDIA_TXT_DOMAIN ) );
196
- }
197
- if ( is_array( $file_info ) ) {
198
- if ( ! array_key_exists( 'error', $file_info ) && array_key_exists( 'fileformat', $file_info ) && array_key_exists( 'audio', $file_info ) && array_key_exists( 'dataformat', $file_info[ 'audio' ] ) ) {
199
- if ( ! ($file_info[ 'fileformat' ] == 'mp3' && $file_info[ 'audio' ][ 'dataformat' ] == 'mp3') ) {
200
- unlink( $file );
201
- $activity_content = false;
202
- throw new Exception( __( 'The MP3 file you have uploaded is using an unsupported audio format. Supported audio format is MP3.', BP_MEDIA_TXT_DOMAIN ) );
203
- }
204
- } else {
205
- unlink( $file );
206
- $activity_content = false;
207
- throw new Exception( __( 'The MP3 file you have uploaded is using an unsupported audio format. Supported audio format is MP3.', BP_MEDIA_TXT_DOMAIN ) );
208
- }
209
- } else {
210
- unlink( $file );
211
- $activity_content = false;
212
- throw new Exception( __( 'The MP3 file you have uploaded is not an audio file.', BP_MEDIA_TXT_DOMAIN ) );
213
- }
214
- $type = 'audio';
215
- break;
216
- case 'image/gif' :
217
- case 'image/jpeg' :
218
- case 'image/png' :
219
- $type = 'image';
220
- break;
221
- default :
222
- unlink( $file );
223
- $activity_content = false;
224
- throw new Exception( __( 'Media File you have tried to upload is not supported. Supported media files are .jpg, .png, .gif, .mp3, .mov and .mp4.', BP_MEDIA_TXT_DOMAIN ) );
225
- }
226
- echo $attachment_id = wp_insert_attachment( $attachment, $file, $post_id );
227
- if ( ! is_wp_error( $attachment_id ) ) {
228
- wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) );
229
- } else {
230
- unlink( $file );
231
- throw new Exception( __( 'Error creating attachment for the media file, please try again', BP_MEDIA_TXT_DOMAIN ) );
232
- }
233
- $this->id = $attachment_id;
234
- $this->name = $name;
235
- $this->description = $description;
236
- $this->type = $type;
237
- $this->owner = get_current_user_id();
238
- $this->album_id = $post_id;
239
- $this->group_id = $group;
240
- $this->set_permalinks();
241
- if ( $group == 0 ) {
242
- update_post_meta( $attachment_id, 'bp-media-key', get_current_user_id() );
243
- } else {
244
- update_post_meta( $attachment_id, 'bp-media-key', (-$group ) );
245
- }
246
- do_action( 'bp_media_after_add_media', $this, $is_multiple, $is_activity, $group );
247
- return $attachment_id;
248
- }
249
-
250
- function get_media_thumbnail($size='thumbnail'){
251
- $thumb = '';
252
- if(in_array($this->type, array('image','video','audio'))){
253
- if ( $this->thumbnail_id ) {
254
- $medium_array = image_downsize( $this->thumbnail_id, $size );
255
- $thumb_url = $medium_array[ 0 ];
256
- } else {
257
- $thumb_url = BP_MEDIA_URL . 'app/assets/img/'.$this->type.'_thumb.png';
258
- }
259
- $thumb = apply_filters( 'bp_media_video_thumb', $thumb_url, $this->thumbnail_id, $this->type );
260
- return $thumb;
261
- }
262
- return false;
263
-
264
- }
265
-
266
- /**
267
- * Fetches the content of the activity of media upload based on its type
268
- *
269
- */
270
-
271
- /**
272
- *
273
- * @global type $bp_media_counter
274
- * @global type $bp_media_default_excerpts
275
- * @global type $bp_media
276
- * @return boolean|string
277
- */
278
- function get_media_activity_content() {
279
- global $bp_media_counter, $bp_media_default_excerpts, $bp_media;
280
- $attachment_id = $this->id;
281
- $activity_content = apply_filters( 'bp_media_single_activity_title', '<div class="bp_media_title"><a href="' . $this->url . '" title="' . __( $this->description, BP_MEDIA_TXT_DOMAIN ) . '">' . __( wp_html_excerpt( $this->name, $bp_media_default_excerpts[ 'activity_entry_title' ] ), BP_MEDIA_TXT_DOMAIN ) . '</a></div>' );
282
- $activity_content .='<div class="bp_media_content">';
283
- switch ( $this->type ) {
284
- case 'video' :
285
- if ( $this->thumbnail_id ) {
286
- $image_array = image_downsize( $this->thumbnail_id, 'bp_media_activity_image' );
287
- $activity_content.=apply_filters( 'bp_media_single_activity_filter', '<video poster="' . $image_array[ 0 ] . '" src="' . wp_get_attachment_url( $attachment_id ) . '" width="320" height="240" type="video/mp4" id="bp_media_video_' . $this->id . '_' . $bp_media_counter . '" controls="controls" preload="none"></video></span><script>bp_media_create_element("bp_media_video_' . $this->id . '_' . $bp_media_counter . '");</script>', $this, true );
288
- } else {
289
- $activity_content.=apply_filters( 'bp_media_single_activity_filter', '<video src="' . wp_get_attachment_url( $attachment_id ) . '" width="320" height="240" type="video/mp4" id="bp_media_video_' . $this->id . '_' . $bp_media_counter . '" controls="controls" preload="none"></video></span><script>bp_media_create_element("bp_media_video_' . $this->id . '_' . $bp_media_counter . '");</script>', $this, true );
290
- }
291
- break;
292
- case 'audio' :
293
- $activity_content.=apply_filters( 'bp_media_single_activity_filter', '<audio src="' . wp_get_attachment_url( $attachment_id ) . '" width="320" type="audio/mp3" id="bp_media_audio_' . $this->id . '_' . $bp_media_counter . '" controls="controls" preload="none" ></audio></span><script>bp_media_create_element("bp_media_audio_' . $this->id . '_' . $bp_media_counter . '");</script>', $this, true );
294
- $type = 'audio';
295
- break;
296
- case 'image' :
297
- $image_array = image_downsize( $attachment_id, 'bp_media_activity_image' );
298
- $activity_content.=apply_filters( 'bp_media_single_activity_filter', '<a href="' . $this->url . '" title="' . __( $this->name, BP_MEDIA_TXT_DOMAIN ) . '"><img src="' . $image_array[ 0 ] . '" id="bp_media_image_' . $this->id . '_' . $bp_media_counter ++ . '" alt="' . __( $this->name, BP_MEDIA_TXT_DOMAIN ) . '" /></a>', $this, true );
299
- $type = 'image';
300
- break;
301
- default :
302
- return false;
303
- }
304
- $activity_content .= '</div>';
305
- $activity_content .= apply_filters( 'bp_media_single_activity_description', '<div class="bp_media_description">' . wp_html_excerpt( $this->description, $bp_media_default_excerpts[ 'activity_entry_description' ] ) . '</div>' );
306
- return $activity_content;
307
- }
308
-
309
- /**
310
- * Returns the single media entry's URL
311
- */
312
-
313
- /**
314
- *
315
- * @return boolean
316
- */
317
- function get_media_activity_url() {
318
- if ( ! bp_is_activity_component() )
319
- return false;
320
- $activity_url = $this->url;
321
- return $activity_url;
322
- }
323
-
324
- /**
325
- * Returns the media activity's action text
326
- */
327
-
328
- /**
329
- *
330
- * @global type $bp_media
331
- * @return boolean
332
- */
333
- function get_media_activity_action() {
334
- global $bp_media;
335
- if ( ! bp_is_activity_component() )
336
- return false;
337
- $activity_action = sprintf( __( "%s uploaded a media.", BP_MEDIA_TXT_DOMAIN ), bp_core_get_userlink( $this->owner ) );
338
- return $activity_action;
339
- }
340
-
341
- /**
342
- * Returns the HTML for content of the single entry page of the Media Entry
343
- */
344
-
345
- /**
346
- *
347
- * @global type $bp_media_default_excerpts
348
- * @global type $bp_media
349
- * @return boolean|string
350
- */
351
- function get_media_single_content() {
352
- global $bp_media_default_excerpts, $bp_media;
353
-
354
- $default_sizes = $bp_media->media_sizes();
355
- $content = '';
356
- if ( $this->group_id > 0 ) {
357
-
358
- $content .= '<div class="bp_media_author">' . __( "Uploaded by ", BP_MEDIA_TXT_DOMAIN ) . bp_core_get_userlink( $this->owner ) . '</div>';
359
- }
360
- $content .= '<div class="bp_media_content">';
361
- switch ( $this->type ) {
362
- case 'video' :
363
- if ( $this->thumbnail_id ) {
364
- $image_array = image_downsize( $this->thumbnail_id, 'bp_media_single_image' );
365
- $content.=apply_filters( 'bp_media_single_content_filter', '<video poster="' . $image_array[ 0 ] . '" src="' . wp_get_attachment_url( $this->id ) . '" width="' . $default_sizes[ 'single_video' ][ 'width' ] . '" height="' . ($default_sizes[ 'single_video' ][ 'height' ] == 0 ? 'auto' : $default_sizes[ 'single_video' ][ 'height' ]) . '" type="video/mp4" id="bp_media_video_' . $this->id . '" controls="controls" preload="none"></video><script>bp_media_create_element("bp_media_video_' . $this->id . '");</script>', $this );
366
- } else {
367
- $content.=apply_filters( 'bp_media_single_content_filter', '<video src="' . wp_get_attachment_url( $this->id ) . '" width="' . $default_sizes[ 'single_video' ][ 'width' ] . '" height="' . ($default_sizes[ 'single_video' ][ 'height' ] == 0 ? 'auto' : $default_sizes[ 'single_video' ][ 'height' ]) . '" type="video/mp4" id="bp_media_video_' . $this->id . '" controls="controls" preload="none"></video><script>bp_media_create_element("bp_media_video_' . $this->id . '");</script>', $this );
368
- }
369
- break;
370
- case 'audio' :
371
- $content.=apply_filters( 'bp_media_single_content_filter', '<audio src="' . wp_get_attachment_url( $this->id ) . '" width="' . $default_sizes[ 'single_audio' ][ 'width' ] . '" type="audio/mp3" id="bp_media_audio_' . $this->id . '" controls="controls" preload="none" ></audio><script>bp_media_create_element("bp_media_audio_' . $this->id . '");</script>', $this );
372
- break;
373
- case 'image' :
374
- $image_array = image_downsize( $this->id, 'bp_media_single_image' );
375
- $content.=apply_filters( 'bp_media_single_content_filter', '<img src="' . $image_array[ 0 ] . '" id="bp_media_image_' . $this->id . '" />', $this );
376
- break;
377
- default :
378
- return false;
379
- }
380
- $content .= '</div>';
381
- $content .= '<div class="bp_media_description">' . nl2br($this->description) . '</div>';
382
- return $content;
383
- }
384
-
385
- /**
386
- * Returns the HTML for title of the single entry page of the Media Entry
387
- */
388
-
389
- /**
390
- *
391
- * @global type $bp_media_default_excerpts
392
- * @global type $bp_media
393
- * @return string
394
- */
395
- function get_media_single_title() {
396
- global $bp_media_default_excerpts, $bp_media;
397
- $content = wp_html_excerpt( $this->name, $bp_media_default_excerpts[ 'single_entry_title' ] );
398
- return $content;
399
- }
400
-
401
- /**
402
- * Returns the HTML for a media entry to be shown in the listing/gallery page
403
- */
404
-
405
- /**
406
- *
407
- * @global type $bp_media
408
- * @return boolean
409
- */
410
- function get_media_gallery_content() {
411
- $attachment = $this->id;
412
- switch ( $this->type ) {
413
- case 'video' :
414
- if ( $this->thumbnail_id ) {
415
- $medium_array = image_downsize( $this->thumbnail_id, 'thumbnail' );
416
- $thumb_url = $medium_array[ 0 ];
417
- } else {
418
- $thumb_url = BP_MEDIA_URL . 'app/assets/img/video_thumb.png';
419
- }
420
- ?>
421
- <li id="bp-media-item-<?php echo $this->id?>">
422
- <a href="<?php echo $this->url ?>" title="<?php _e( $this->description, BP_MEDIA_TXT_DOMAIN ); ?>">
423
- <img src="<?php echo apply_filters( 'bp_media_video_thumb', $thumb_url, $attachment, $this->type ); ?>" />
424
- </a>
425
- <h3 title="<?php echo $this->name; ?>"><a href="<?php echo $this->url ?>" title="<?php _e( $this->description, BP_MEDIA_TXT_DOMAIN ); ?>"><?php echo $this->name; ?></a></h3>
426
- </li>
427
- <?php
428
- break;
429
- case 'audio' :
430
- if ( $this->thumbnail_id ) {
431
- $medium_array = image_downsize( $this->thumbnail_id, 'thumbnail' );
432
- $thumb_url = $medium_array[ 0 ];
433
- } else {
434
- $thumb_url = BP_MEDIA_URL . 'app/assets/img/audio_thumb.png';
435
- }
436
- ?>
437
- <li id="bp-media-item-<?php echo $this->id?>">
438
- <a href="<?php echo $this->url ?>" title="<?php _e( $this->description, BP_MEDIA_TXT_DOMAIN ); ?>">
439
- <img src="<?php echo $thumb_url ?>" />
440
- </a>
441
- <h3 title="<?php echo $this->name; ?>"><a href="<?php echo $this->url ?>" title="<?php _e( $this->description, BP_MEDIA_TXT_DOMAIN ); ?>"><?php echo $this->name ?></a></h3>
442
- <div class="bp-media-ajax-preloader"></div>
443
- </li>
444
- <?php
445
- break;
446
- case 'image' :
447
- $medium_array = image_downsize( $attachment, 'thumbnail' );
448
- $medium_path = $medium_array[ 0 ];
449
- ?>
450
- <li id="bp-media-item-<?php echo $this->id?>">
451
- <a href="<?php echo $this->url ?>" title="<?php echo $this->description ?>">
452
- <img src="<?php echo $medium_path ?>" />
453
- </a>
454
- <h3 title="<?php echo $this->name ?>"><a href="<?php echo $this->url ?>" title="<?php _e( $this->description, BP_MEDIA_TXT_DOMAIN ); ?>"><?php echo $this->name ?></a></h3>
455
- <div class="bp-media-ajax-preloader"></div>
456
- </li>
457
- <?php
458
- break;
459
- default :
460
- return false;
461
- }
462
- }
463
-
464
- function show_comment_form_wordpress() {
465
- query_posts( 'attachment_id=' . $this->id );
466
- while ( have_posts() ): the_post();
467
- add_action( 'comment_form', 'BPMediaFunction::wp_comment_form_mod' );
468
- comments_template();
469
- endwhile;
470
- }
471
-
472
- /**
473
- * Outputs the comments and comment form in the single media entry page
474
- */
475
-
476
- /**
477
- *
478
- * @global type $bp_media
479
- * @return boolean
480
- */
481
- function show_comment_form() {
482
- global $bp_media;
483
- $activity_id = get_post_meta( $this->id, 'bp_media_child_activity', true );
484
- if ( ! $activity_id || ! function_exists( 'bp_has_activities' ) )
485
- return false;
486
- if ( bp_has_activities( array(
487
- 'display_comments' => 'stream',
488
- 'include' => $activity_id,
489
- 'max' => 1
490
- ) ) ) {
491
- while ( bp_activities() ) {
492
- bp_the_activity();
493
- do_action( 'bp_before_activity_entry' );
494
- ?>
495
- <div class="activity">
496
- <ul id="activity-stream" class="activity-list item-list">
497
- <li class="activity activity_update" id="activity-<?php echo $activity_id; ?>">
498
- <div class="activity-content">
499
- <?php do_action( 'bp_activity_entry_content' ); ?>
500
- <?php if ( is_user_logged_in() ) : ?>
501
- <div class="activity-meta no-ajax">
502
- <?php if ( bp_activity_can_comment() ) : ?>
503
- <a href="<?php bp_get_activity_comment_link(); ?>" class="button acomment-reply bp-primary-action" id="acomment-comment-<?php bp_activity_id(); ?>"><?php printf( __( 'Comment <span>%s</span>', BP_MEDIA_TXT_DOMAIN ), bp_activity_get_comment_count() ); ?></a>
504
- <?php endif; ?>
505
- <?php if ( bp_activity_can_favorite() ) : ?>
506
- <?php if ( ! bp_get_activity_is_favorite() ) : ?>
507
- <a href="<?php bp_activity_favorite_link(); ?>" class="button fav bp-secondary-action" title="<?php esc_attr_e( 'Mark as Favorite', BP_MEDIA_TXT_DOMAIN ); ?>"><?php _e( 'Favorite', BP_MEDIA_TXT_DOMAIN ) ?></a>
508
- <?php else : ?>
509
- <a href="<?php bp_activity_unfavorite_link(); ?>" class="button unfav bp-secondary-action" title="<?php esc_attr_e( 'Remove Favorite', BP_MEDIA_TXT_DOMAIN ); ?>"><?php _e( 'Remove Favorite', BP_MEDIA_TXT_DOMAIN ) ?></a>
510
- <?php endif; ?>
511
- <?php endif; ?>
512
- <?php do_action( 'bp_activity_entry_meta' ); ?>
513
- <?php if ( bp_activity_user_can_delete() ) bp_activity_delete_link(); ?>
514
- </div>
515
- <?php endif; ?>
516
- </div>
517
- <?php do_action( 'bp_before_activity_entry_comments' ); ?>
518
- <?php if ( ( is_user_logged_in() && bp_activity_can_comment() ) || bp_activity_get_comment_count() ) : ?>
519
- <div class="activity-comments">
520
- <?php bp_activity_comments(); ?>
521
- <?php if ( is_user_logged_in() ) : ?>
522
- <form action="<?php bp_activity_comment_form_action(); ?>" method="post" id="ac-form-<?php bp_activity_id(); ?>" class="ac-form"<?php bp_activity_comment_form_nojs_display(); ?>>
523
- <div class="ac-reply-avatar"><?php bp_loggedin_user_avatar( 'width=' . BP_AVATAR_THUMB_WIDTH . '&height=' . BP_AVATAR_THUMB_HEIGHT ); ?></div>
524
- <div class="ac-reply-content">
525
- <div class="ac-textarea">
526
- <textarea id="ac-input-<?php bp_activity_id(); ?>" class="ac-input" name="ac_input_<?php bp_activity_id(); ?>"></textarea>
527
- </div>
528
- <input type="submit" name="ac_form_submit" value="<?php _e( 'Post', BP_MEDIA_TXT_DOMAIN ); ?>" /> &nbsp; <?php _e( 'or press esc to cancel.', BP_MEDIA_TXT_DOMAIN ); ?>
529
- <input type="hidden" name="comment_form_id" value="<?php bp_activity_id(); ?>" />
530
- </div>
531
- <?php do_action( 'bp_activity_entry_comments' ); ?>
532
- <?php wp_nonce_field( 'new_activity_comment', '_wpnonce_new_activity_comment' ); ?>
533
- </form>
534
- <?php endif; ?>
535
- </div>
536
- <?php endif; ?>
537
- <?php do_action( 'bp_after_activity_entry_comments' ); ?>
538
- </li>
539
- </ul>
540
- </div>
541
- <?php
542
- }
543
- }
544
- else {
545
- ?>
546
- <div class="activity">
547
- <ul id="activity-stream" class="activity-list item-list">
548
- <li class="activity activity_update" id="activity-<?php echo $activity_id; ?>">
549
- <div class="activity-content">
550
- <?php do_action( 'bp_activity_entry_content' ); ?>
551
- <?php if ( is_user_logged_in() ) : ?>
552
- <div class="activity-meta no-ajax">
553
- <a href="<?php echo $this->get_delete_url(); ?>" class="button item-button bp-secondary-action delete-activity-single confirm" rel="nofollow"><?php _e( "Delete", BP_MEDIA_TXT_DOMAIN ); ?></a>
554
- </div>
555
- <?php endif; ?>
556
- </div>
557
- </li>
558
- </ul>
559
- </div>
560
- <?php
561
- }
562
- }
563
-
564
- /**
565
- * Returns the URL of the single media entry page
566
- */
567
-
568
- /**
569
- *
570
- * @return type
571
- */
572
- function get_url() {
573
- return $this->url;
574
- }
575
-
576
- /**
577
- * Returns the URL of the attached media file
578
- */
579
-
580
- /**
581
- *
582
- * @return type
583
- */
584
- function get_attachment_url() {
585
- return wp_get_attachment_url( $this->id );
586
- }
587
-
588
- /**
589
- * Updates the media entry
590
- *
591
- * @param array $args Array with the following keys:<br/>
592
- * 'name' <br/>
593
- * 'description'<br/>
594
- * 'owner'
595
- *
596
- * @return bool True when the update is successful, False when the update fails
597
- */
598
-
599
- /**
600
- *
601
- * @param type $args
602
- * @return type
603
- */
604
- function update_media( $args = array( ) ) {
605
- $defaults = array(
606
- 'name' => $this->name,
607
- 'description' => $this->description,
608
- 'owner' => $this->owner
609
- );
610
- $args = wp_parse_args( $args, $defaults );
611
- $post = get_post( $this->id, ARRAY_A );
612
- $post[ 'post_title' ] = esc_html( $args[ 'name' ] );
613
- $post[ 'post_content' ] = esc_html( $args[ 'description' ] );
614
- $post[ 'post_author' ] = $args[ 'owner' ];
615
- $result = wp_update_post( $post );
616
- $this->init( $this->id );
617
- do_action( 'bp_media_after_update_media', $this );
618
- return $result;
619
- }
620
-
621
- /**
622
- * Updates activity content's title and description sync with the editing of Media
623
- *
624
- */
625
-
626
- /**
627
- *
628
- * @global type $wpdb
629
- * @global type $bp
630
- * @global type $current_user
631
- * @global type $bp_media
632
- */
633
- function update_media_activity() {
634
- global $wpdb, $bp, $current_user, $bp_media;
635
- $q = $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE type = %s AND item_id = %d", 'media_upload', $this->id );
636
- $activities = $wpdb->get_results( $q );
637
- if ( isset( $activities ) && count( $activities ) > 0 ) {
638
- $activities_template = new BP_Activity_Template( array(
639
- 'max' => TRUE,
640
- 'user_id' => $current_user,
641
- 'in' => $activities[ 0 ]->id
642
- ) );
643
- foreach ( $activities_template->activities as $activity ) {
644
- if (isset($_POST['bp_media_group_id'])) {
645
- $component = $bp->groups->id;
646
- $item_id = $_POST['bp_media_group_id'];
647
- } else {
648
- $component = $bp->activity->id;
649
- $item_id = $this->get_id();
650
  }
651
- $args = array(
652
- 'content' => $this->get_media_activity_content(),
653
- 'id' => $activity->id,
654
- 'type' => $component,
655
- 'action' => apply_filters( 'bp_media_added_media', sprintf( __( '%1$s added a %2$s', BP_MEDIA_TXT_DOMAIN ), bp_core_get_userlink( $this->get_author() ), '<a href="' . $this->get_url() . '">' . $this->get_media_activity_type() . '</a>' ) ),
656
- 'primary_link' => $this->get_url(),
657
- 'item_id' => $item_id,
658
- 'recorded_time' => $activity->date_recorded,
659
- 'user_id' => $this->get_author()
660
- );
661
- $activity_id = BPMediaFunction::record_activity( $args );
662
- }
663
- }
664
- }
665
-
666
- /**
667
- * Deletes the Media Entry
668
- */
669
-
670
- /**
671
- *
672
- * @global type $bp_media_count
673
- */
674
- function delete_media() {
675
- do_action( 'bp_media_before_delete_media', $this->id );
676
- wp_delete_attachment( $this->id, true );
677
- do_action( 'bp_media_after_delete_media', $this->id );
678
- }
679
-
680
- /**
681
- * Function to return the content to be placed in the activity of album
682
- */
683
-
684
- /**
685
- *
686
- * @return boolean|string
687
- */
688
- function get_album_activity_content() {
689
- $attachment = $this->id;
690
- switch ( $this->type ) {
691
- case 'video' :
692
- if ( $this->thumbnail_id ) {
693
- $medium_array = image_downsize( $this->thumbnail_id, 'thumbnail' );
694
- $thumb_url = $medium_array[ 0 ];
695
- } else {
696
- $thumb_url = BP_MEDIA_URL . 'app/assets/img/video_thumb.png';
697
- }
698
- break;
699
- case 'audio' :
700
- if ( $this->thumbnail_id ) {
701
- $medium_array = image_downsize( $this->thumbnail_id, 'thumbnail' );
702
- $thumb_url = $medium_array[ 0 ];
703
- } else {
704
- $thumb_url = BP_MEDIA_URL . 'app/assets/img/audio_thumb.png';
705
- }
706
- break;
707
- case 'image' :
708
- $medium_array = image_downsize( $attachment, 'thumbnail' );
709
- $thumb_url = $medium_array[ 0 ];
710
- break;
711
- default :
712
- return false;
713
- }
714
- $content = '<li>';
715
- $content .= '<a href="' . $this->url . '" title="' . $this->name . '">';
716
- $content .= '<img src="' . $thumb_url . '" />';
717
- $content .= '</a>';
718
- $content .= '</li>';
719
- return $content;
720
- }
721
-
722
- /**
723
- * Returns the description of the Media Entry
724
- */
725
-
726
- /**
727
- *
728
- * @return type
729
- */
730
- function get_content() {
731
- return $this->description;
732
- }
733
-
734
- /**
735
- * Returns the owner id of the Media Entry
736
- */
737
-
738
- /**
739
- *
740
- * @return type
741
- */
742
- function get_author() {
743
- return $this->owner;
744
- }
745
-
746
- /**
747
- * Returns the id of the Media Entry
748
- */
749
-
750
- /**
751
- *
752
- * @return type
753
- */
754
- function get_id() {
755
- return $this->id;
756
- }
757
-
758
- /**
759
- * Returns the edit url of the Media Entry
760
- */
761
-
762
- /**
763
- *
764
- * @return type
765
- */
766
- function get_edit_url() {
767
- return $this->edit_url;
768
- }
769
-
770
- /**
771
- * Returns the delete url of the Media Entry
772
- */
773
-
774
- /**
775
- *
776
- * @return type
777
- */
778
- function get_delete_url() {
779
- return $this->delete_url;
780
- }
781
-
782
- /**
783
- * Returns the type of activity
784
- */
785
-
786
- /**
787
- *
788
- * @return string
789
- */
790
- function get_media_activity_type() {
791
- switch ( $this->type ) {
792
- case 'image':
793
- return BP_MEDIA_IMAGES_LABEL_SINGULAR;
794
- case 'video':
795
- return BP_MEDIA_VIDEOS_LABEL_SINGULAR;
796
- case 'audio':
797
- return BP_MEDIA_AUDIO_LABEL_SINGULAR;
798
- default:
799
- return 'Media';
800
- }
801
- }
802
-
803
- /**
804
- * Returns the album id
805
- */
806
-
807
- /**
808
- *
809
- * @return type
810
- */
811
- function get_album_id() {
812
- return $this->album_id;
813
- }
814
-
815
- /**
816
- * Returns the title of the media
817
- */
818
-
819
- /**
820
- *
821
- * @return type
822
- */
823
- function get_title() {
824
- return $this->name;
825
- }
826
-
827
- /**
828
- * Returns the type of media
829
- */
830
-
831
- /**
832
- *
833
- * @return type
834
- */
835
- function get_type() {
836
- return $this->type;
837
- }
838
-
839
- /**
840
- * Returns the thumbnail id
841
- */
842
- function get_thumbnail_id() {
843
- return $this->thumbnail_id;
844
- }
845
-
846
- /**
847
- * Returns the group id of the media, 0 if it does not belong to a group
848
- */
849
-
850
- /**
851
- *
852
- * @return type
853
- */
854
- function get_group_id() {
855
- return $this->group_id;
856
- }
857
-
858
- /**
859
- * Sets the permalinks of the media depending upon whether its in member directory
860
- * or group and acording to the media type
861
- */
862
-
863
- /**
864
- *
865
- * @return boolean
866
- */
867
- protected function set_permalinks() {
868
-
869
- if ( bp_is_active('groups') && class_exists( 'BP_Group_Extension' ) ) {
870
- if ( $this->group_id > 0 ) {
871
- $current_group = new BP_Groups_Group( $this->group_id );
872
- $pre_url = bp_get_group_permalink( $current_group );
873
- } else {
874
- $pre_url = bp_core_get_user_domain( $this->owner );
875
- }
876
- } else {
877
- $pre_url = bp_core_get_user_domain( $this->owner );
878
- }
879
- switch ( $this->type ) {
880
- case 'video' :
881
- $this->url = trailingslashit( $pre_url . BP_MEDIA_VIDEOS_SLUG . '/' . $this->id );
882
- $this->edit_url = trailingslashit( $pre_url . BP_MEDIA_VIDEOS_SLUG . '/' . BP_MEDIA_VIDEOS_EDIT_SLUG . '/' . $this->id );
883
- $this->delete_url = trailingslashit( $pre_url . BP_MEDIA_VIDEOS_SLUG . '/' . BP_MEDIA_DELETE_SLUG . '/' . $this->id );
884
- $this->thumbnail_id = get_post_meta( $this->id, 'bp_media_thumbnail', true );
885
- break;
886
- case 'audio' :
887
- $this->url = trailingslashit( $pre_url . BP_MEDIA_AUDIO_SLUG . '/' . $this->id );
888
- $this->edit_url = trailingslashit( $pre_url . BP_MEDIA_AUDIO_SLUG . '/' . BP_MEDIA_AUDIO_EDIT_SLUG . '/' . $this->id );
889
- $this->delete_url = trailingslashit( $pre_url . BP_MEDIA_AUDIO_SLUG . '/' . BP_MEDIA_DELETE_SLUG . '/' . $this->id );
890
- $this->thumbnail_id = get_post_meta( $this->id, 'bp_media_thumbnail', true );
891
- break;
892
- case 'image' :
893
- $this->url = trailingslashit( $pre_url . BP_MEDIA_IMAGES_SLUG . '/' . $this->id );
894
- $this->edit_url = trailingslashit( $pre_url . BP_MEDIA_IMAGES_SLUG . '/' . BP_MEDIA_IMAGES_EDIT_SLUG . '/' . $this->id );
895
- $this->delete_url = trailingslashit( $pre_url . BP_MEDIA_IMAGES_SLUG . '/' . BP_MEDIA_DELETE_SLUG . '/' . $this->id );
896
- $image_array = image_downsize( $this->id, 'bp_media_single_image' );
897
- $this->thumbnail_id = $this->id;
898
- break;
899
- case 'album' :
900
- $this->url = trailingslashit( $pre_url . BP_MEDIA_ALBUMS_SLUG . '/' . $this->id );
901
- $this->edit_url = trailingslashit( $pre_url . BP_MEDIA_ALBUMS_SLUG . '/' . BP_MEDIA_ALBUMS_EDIT_SLUG . '/' . $this->id );
902
- $this->delete_url = trailingslashit( $pre_url . BP_MEDIA_ALBUMS_SLUG . '/' . BP_MEDIA_DELETE_SLUG . '/' . $this->id );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
903
  // $this->thumbnail_id = get_post_meta($this->id, 'bp_media_thumbnail', true);
904
- break;
905
- default :
906
- return false;
907
- }
908
- return true;
909
- }
910
-
911
- /**
912
- * Checks if the album given exists if not, creates a new one according to context
913
- */
914
-
915
- /**
916
- *
917
- * @global type $wpdb
918
- * @param type $album_id
919
- * @param type $group
920
- * @return type
921
- */
922
- function check_and_create_album( $album_id, $group ) {
923
- global $wpdb;
924
- $post_wall = __( 'Wall Posts', BP_MEDIA_TXT_DOMAIN );
925
- $create_new_album_flag = false;
926
- if ( $album_id != 0 ) {
927
- $album = get_post( $album_id );
928
- if ( $album->post_author != get_current_user_id() && $group == 0 ) {
929
- $create_new_album_flag = true;
930
- } else {
931
- $post_id = $album->ID;
932
- }
933
- } else {
934
- $create_new_album_flag = true;
935
- }
936
- if ( $create_new_album_flag ) {
937
- if ( $group == 0 ) {
938
- $post_id = $wpdb->get_var(
939
- "SELECT ID
 
940
  FROM $wpdb->posts
941
  WHERE
942
  post_title = $post_wall
943
  AND post_author = '" . get_current_user_id() . "'
944
  AND post_type='bp_media_album'"
945
- );
946
- } else {
947
- $post_id = $wpdb->get_var(
948
- "SELECT wp_posts.ID
949
  FROM $wpdb->posts
950
  INNER JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id
951
  AND $wpdb->postmeta.meta_key = 'bp-media-key'
952
  AND $wpdb->postmeta.meta_value = -$group
953
- AND $wpdb->posts.post_title = $post_wall" );
954
- }
955
- if ( $post_id == null ) {
956
- $album = new BPMediaAlbum();
957
- if ( $group == 0 )
958
- $album->add_album( $post_wall, get_current_user_id(), $group );
959
- else {
960
- $current_user = wp_get_current_user();
961
- $album->add_album( $current_user->display_name . '\'s Album', get_current_user_id(), $group );
962
- }
963
- $post_id = $album->get_id();
964
- }
965
- }
966
- return $post_id;
967
- }
968
-
969
- function get_description(){
970
- return $this->description;
971
- }
972
 
973
  }
974
  ?>
2
 
3
  class BPMediaHostWordpress {
4
 
5
+ /**
6
+ * Private variables not to be accessible outside this class' member functions
7
+ */
8
+ protected $id, //id of the entry
9
+ $name, //Name of the entry
10
+ $description, //Description of the entry
11
+ $url, //URL of the entry
12
+ $type, //Type of the entry (Video, Image or Audio)
13
+ $owner, //Owner of the entry
14
+ $delete_url, //The delete url for the media
15
+ $thumbnail_id, //The thumbnail's id
16
+ $album_id, //The album id to which the media belongs
17
+ $edit_url, //The edit page's url for the media
18
+ $group_id; //The group id of the current media file if it belongs to a group
19
+
20
+ /**
21
+ * Constructs a new BP_Media_Host_Wordpress element
22
+ *
23
+ * @param mixed $media_id optional Media ID of the element to be initialized if not defined, returns an empty element.
24
+ *
25
+ * @since BuddyPress Media 2.0
26
+ */
27
+
28
+ /**
29
+ *
30
+ * @param type $media_id
31
+ */
32
+ function __construct($media_id = '') {
33
+ if ($media_id != '') {
34
+ $this->init($media_id);
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Initializes the object with the variables from the post
40
+ *
41
+ * @param mixed $media_id Media ID of the element to be initialized. Can be the ID or the object of the Media
42
+ *
43
+ * @since BuddyPress Media 2.0
44
+ */
45
+
46
+ /**
47
+ *
48
+ * @param type $media_id
49
+ * @return boolean
50
+ * @throws Exception
51
+ */
52
+ function init($media_id = '') {
53
+ if (is_object($media_id)) {
54
+ $media = $media_id;
55
+ } else {
56
+ $media = &get_post($media_id);
57
+ }
58
+ if (empty($media->ID))
59
+ throw new Exception(__('Sorry, the requested media does not exist.', BP_MEDIA_TXT_DOMAIN));
60
+ if (!'bp_media_album' == $media->post_type || !empty($media->post_mime_type))
61
+ preg_match_all('/audio|video|image/i', $media->post_mime_type, $result);
62
+ else
63
+ $result[0][0] = 'album';
64
+ if (isset($result[0][0]))
65
+ $this->type = $result[0][0];
66
+ else
67
+ return false;
68
+
69
+
70
+ global $bp;
71
+ $this->id = $media->ID;
72
+ $meta_key = get_post_meta($this->id, 'bp-media-key', true);
73
+
74
+ /**
75
+ * We use bp-media-key to distinguish if the entry belongs to a group or not
76
+ * if the value is less than 0 it means it the group id to which the media belongs
77
+ * and if its greater than 0 then it means its the author id of the uploader
78
+ * But for use in the class, we use group_id as positive integer even though
79
+ * we use it as negative value in the bp-media-key meta key
80
+ */
81
+ $this->group_id = $meta_key < 0 ? -$meta_key : 0;
82
+
83
+ $this->description = $media->post_content;
84
+ $this->name = $media->post_title;
85
+ $this->owner = $media->post_author;
86
+ $this->album_id = $media->post_parent;
87
+ $this->mime_type = $media->post_mime_type;
88
+
89
+
90
+ $this->set_permalinks();
91
+ }
92
+
93
+ /**
94
+ * Handles the uploaded media file and creates attachment post for the file.
95
+ *
96
+ * @since BuddyPress Media 2.0
97
+ */
98
+
99
+ /**
100
+ *
101
+ * @global type $bp
102
+ * @global type $wpdb
103
+ * @global type $bp_media_count
104
+ * @global type $bp_media
105
+ * @param type $name
106
+ * @param type $description
107
+ * @param type $album_id
108
+ * @param type $group
109
+ * @param type $is_multiple
110
+ * @throws Exception
111
+ * @uses global var $_FILES
112
+ */
113
+ function add_media($name, $description, $album_id = 0, $group = 0, $is_multiple = false, $is_activity = false, $files = false) {
114
+ do_action('bp_media_before_add_media');
115
+
116
+ global $bp, $wpdb, $bp_media;
117
+ include_once(ABSPATH . 'wp-admin/includes/file.php');
118
+ include_once(ABSPATH . 'wp-admin/includes/image.php');
119
+
120
+ $post_id = $this->check_and_create_album($album_id, $group);
121
+
122
+ if (!$files) {
123
+ $files = $_FILES['bp_media_file'];
124
+ $file = wp_handle_upload($files);
125
+ } else {
126
+ $file = wp_handle_sideload($files);
127
+ }
128
+
129
+ if (isset($file['error']) || $file === null) {
130
+ throw new Exception(__('Error Uploading File', BP_MEDIA_TXT_DOMAIN));
131
+ }
132
+
133
+ $type = $file['type'];
134
+ if (in_array($type, array('image/gif', 'image/jpeg', 'image/png'))) {
135
+ $file = $this->exif($file);
136
+ }
137
+
138
+ $attachment = array();
139
+ $url = $file['url'];
140
+ $file = $file['file'];
141
+ $title = $name;
142
+ $content = $description;
143
+ $attachment = array(
144
+ 'post_mime_type' => $type,
145
+ 'guid' => $url,
146
+ 'post_title' => $title,
147
+ 'post_content' => $content,
148
+ 'post_parent' => $post_id,
149
+ );
150
+ switch ($type) {
151
+ case 'video/mp4' :
152
+ case 'video/quicktime' :
153
+ $type = 'video';
154
+ include_once(trailingslashit(BP_MEDIA_PATH) . 'lib/getid3/getid3.php');
155
+ try {
156
+ $getID3 = new getID3;
157
+ $vid_info = $getID3->analyze($file);
158
+ } catch (Exception $e) {
159
+ unlink($file);
160
+ $activity_content = false;
161
+ throw new Exception(__('MP4 file you have uploaded is corrupt.', BP_MEDIA_TXT_DOMAIN));
162
+ }
163
+ if (is_array($vid_info)) {
164
+ if (!array_key_exists('error', $vid_info) && array_key_exists('fileformat', $vid_info) && array_key_exists('video', $vid_info) && array_key_exists('fourcc', $vid_info['video'])) {
165
+ if (!($vid_info['fileformat'] == 'mp4' && $vid_info['video']['fourcc'] == 'avc1')) {
166
+ unlink($file);
167
+ $activity_content = false;
168
+ throw new Exception(__('The MP4 file you have uploaded is using an unsupported video codec. Supported video codec is H.264.', BP_MEDIA_TXT_DOMAIN));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  }
170
+ } else {
171
+ unlink($file);
172
+ $activity_content = false;
173
+ throw new Exception(__('The MP4 file you have uploaded is using an unsupported video codec. Supported video codec is H.264.', BP_MEDIA_TXT_DOMAIN));
174
+ }
175
+ } else {
176
+ unlink($file);
177
+ $activity_content = false;
178
+ throw new Exception(__('The MP4 file you have uploaded is not a video file.', BP_MEDIA_TXT_DOMAIN));
179
+ }
180
+ break;
181
+ case 'audio/mpeg' :
182
+ include_once(trailingslashit(BP_MEDIA_PATH) . 'lib/getid3/getid3.php');
183
+ try {
184
+ $getID3 = new getID3;
185
+ $file_info = $getID3->analyze($file);
186
+ } catch (Exception $e) {
187
+ unlink($file);
188
+ $activity_content = false;
189
+ throw new Exception(__('MP3 file you have uploaded is currupt.', BP_MEDIA_TXT_DOMAIN));
190
+ }
191
+ if (is_array($file_info)) {
192
+ if (!array_key_exists('error', $file_info) && array_key_exists('fileformat', $file_info) && array_key_exists('audio', $file_info) && array_key_exists('dataformat', $file_info['audio'])) {
193
+ if (!($file_info['fileformat'] == 'mp3' && $file_info['audio']['dataformat'] == 'mp3')) {
194
+ unlink($file);
195
+ $activity_content = false;
196
+ throw new Exception(__('The MP3 file you have uploaded is using an unsupported audio format. Supported audio format is MP3.', BP_MEDIA_TXT_DOMAIN));
197
+ }
198
+ } else {
199
+ unlink($file);
200
+ $activity_content = false;
201
+ throw new Exception(__('The MP3 file you have uploaded is using an unsupported audio format. Supported audio format is MP3.', BP_MEDIA_TXT_DOMAIN));
202
+ }
203
+ } else {
204
+ unlink($file);
205
+ $activity_content = false;
206
+ throw new Exception(__('The MP3 file you have uploaded is not an audio file.', BP_MEDIA_TXT_DOMAIN));
207
+ }
208
+ $type = 'audio';
209
+ break;
210
+ case 'image/gif' :
211
+ case 'image/jpeg' :
212
+ case 'image/png' :
213
+ $type = 'image';
214
+ break;
215
+ default :
216
+ unlink($file);
217
+ $activity_content = false;
218
+ throw new Exception(__('Media File you have tried to upload is not supported. Supported media files are .jpg, .png, .gif, .mp3, .mov and .mp4.', BP_MEDIA_TXT_DOMAIN));
219
+ }
220
+ echo $attachment_id = wp_insert_attachment($attachment, $file, $post_id);
221
+ if (!is_wp_error($attachment_id)) {
222
+ wp_update_attachment_metadata($attachment_id, wp_generate_attachment_metadata($attachment_id, $file));
223
+ } else {
224
+ unlink($file);
225
+ throw new Exception(__('Error creating attachment for the media file, please try again', BP_MEDIA_TXT_DOMAIN));
226
+ }
227
+ $this->id = $attachment_id;
228
+ $this->name = $name;
229
+ $this->description = $description;
230
+ $this->type = $type;
231
+ $this->owner = get_current_user_id();
232
+ $this->album_id = $post_id;
233
+ $this->group_id = $group;
234
+ $this->set_permalinks();
235
+ if ($group == 0) {
236
+ update_post_meta($attachment_id, 'bp-media-key', get_current_user_id());
237
+ } else {
238
+ update_post_meta($attachment_id, 'bp-media-key', (-$group));
239
+ }
240
+ do_action('bp_media_after_add_media', $this, $is_multiple, $is_activity, $group);
241
+ return $attachment_id;
242
+ }
243
+
244
+ function get_media_thumbnail($size = 'thumbnail') {
245
+ $thumb = '';
246
+ if (in_array($this->type, array('image', 'video', 'audio'))) {
247
+ if ($this->thumbnail_id) {
248
+ $medium_array = image_downsize($this->thumbnail_id, $size);
249
+ $thumb_url = $medium_array[0];
250
+ } else {
251
+ $thumb_url = BP_MEDIA_URL . 'app/assets/img/' . $this->type . '_thumb.png';
252
+ }
253
+ $thumb = apply_filters('bp_media_video_thumb', $thumb_url, $this->thumbnail_id, $this->type);
254
+ return $thumb;
255
+ }
256
+ return false;
257
+ }
258
+
259
+ /**
260
+ * Fetches the content of the activity of media upload based on its type
261
+ *
262
+ */
263
+
264
+ /**
265
+ *
266
+ * @global type $bp_media_counter
267
+ * @global type $bp_media_default_excerpts
268
+ * @global type $bp_media
269
+ * @return boolean|string
270
+ */
271
+ function get_media_activity_content() {
272
+ global $bp_media_counter, $bp_media_default_excerpts, $bp_media;
273
+ $attachment_id = $this->id;
274
+ $activity_content = apply_filters('bp_media_single_activity_title', '<div class="bp_media_title"><a href="' . $this->url . '" title="' . __($this->description, BP_MEDIA_TXT_DOMAIN) . '">' . __(wp_html_excerpt($this->name, $bp_media_default_excerpts['activity_entry_title']), BP_MEDIA_TXT_DOMAIN) . '</a></div>');
275
+ $activity_content .='<div class="bp_media_content">';
276
+ switch ($this->type) {
277
+ case 'video' :
278
+ if ($this->thumbnail_id) {
279
+ $image_array = image_downsize($this->thumbnail_id, 'bp_media_activity_image');
280
+ $activity_content.=apply_filters('bp_media_single_activity_filter', '<video poster="' . $image_array[0] . '" src="' . wp_get_attachment_url($attachment_id) . '" width="320" height="240" type="video/mp4" id="bp_media_video_' . $this->id . '_' . $bp_media_counter . '" controls="controls" preload="none"></video></span>', $this, true);
281
+ } else {
282
+ $activity_content.=apply_filters('bp_media_single_activity_filter', '<video src="' . wp_get_attachment_url($attachment_id) . '" width="320" height="240" type="video/mp4" id="bp_media_video_' . $this->id . '_' . $bp_media_counter . '" controls="controls" preload="none"></video></span>', $this, true);
283
+ }
284
+ break;
285
+ case 'audio' :
286
+ $activity_content.=apply_filters('bp_media_single_activity_filter', '<audio src="' . wp_get_attachment_url($attachment_id) . '" width="320" type="audio/mp3" id="bp_media_audio_' . $this->id . '_' . $bp_media_counter . '" controls="controls" preload="none" ></audio></span>', $this, true);
287
+ $type = 'audio';
288
+ break;
289
+ case 'image' :
290
+ $image_array = image_downsize($attachment_id, 'bp_media_activity_image');
291
+ $activity_content.=apply_filters('bp_media_single_activity_filter', '<a href="' . $this->url . '" title="' . __($this->name, BP_MEDIA_TXT_DOMAIN) . '"><img src="' . $image_array[0] . '" id="bp_media_image_' . $this->id . '_' . $bp_media_counter++ . '" alt="' . __($this->name, BP_MEDIA_TXT_DOMAIN) . '" /></a>', $this, true);
292
+ $type = 'image';
293
+ break;
294
+ default :
295
+ return false;
296
+ }
297
+ $activity_content .= '</div>';
298
+ $activity_content .= apply_filters('bp_media_single_activity_description', '<div class="bp_media_description">' . wp_html_excerpt($this->description, $bp_media_default_excerpts['activity_entry_description']) . '</div>');
299
+ return $activity_content;
300
+ }
301
+
302
+ /**
303
+ * Returns the single media entry's URL
304
+ */
305
+
306
+ /**
307
+ *
308
+ * @return boolean
309
+ */
310
+ function get_media_activity_url() {
311
+ if (!bp_is_activity_component())
312
+ return false;
313
+ $activity_url = $this->url;
314
+ return $activity_url;
315
+ }
316
+
317
+ /**
318
+ * Returns the media activity's action text
319
+ */
320
+
321
+ /**
322
+ *
323
+ * @global type $bp_media
324
+ * @return boolean
325
+ */
326
+ function get_media_activity_action() {
327
+ global $bp_media;
328
+ if (!bp_is_activity_component())
329
+ return false;
330
+ $activity_action = sprintf(__("%s uploaded a media.", BP_MEDIA_TXT_DOMAIN), bp_core_get_userlink($this->owner));
331
+ return $activity_action;
332
+ }
333
+
334
+ /**
335
+ * Returns the HTML for content of the single entry page of the Media Entry
336
+ */
337
+
338
+ /**
339
+ *
340
+ * @global type $bp_media_default_excerpts
341
+ * @global type $bp_media
342
+ * @return boolean|string
343
+ */
344
+ function get_media_single_content() {
345
+ global $bp_media_default_excerpts, $bp_media;
346
+
347
+ $default_sizes = $bp_media->media_sizes();
348
+ $content = '';
349
+ if ($this->group_id > 0) {
350
+
351
+ $content .= '<div class="bp_media_author">' . __("Uploaded by ", BP_MEDIA_TXT_DOMAIN) . bp_core_get_userlink($this->owner) . '</div>';
352
+ }
353
+ $content .= '<div class="bp_media_content">';
354
+ switch ($this->type) {
355
+ case 'video' :
356
+ if ($this->thumbnail_id) {
357
+ $image_array = image_downsize($this->thumbnail_id, 'bp_media_single_image');
358
+ $content.=apply_filters('bp_media_single_content_filter', '<video poster="' . $image_array[0] . '" src="' . wp_get_attachment_url($this->id) . '" width="' . $default_sizes['single_video']['width'] . '" height="' . ($default_sizes['single_video']['height'] == 0 ? 'auto' : $default_sizes['single_video']['height']) . '" type="video/mp4" id="bp_media_video_' . $this->id . '" controls="controls" preload="none"></video><script>bp_media_create_element("bp_media_video_' . $this->id . '");</script>', $this);
359
+ } else {
360
+ $content.=apply_filters('bp_media_single_content_filter', '<video src="' . wp_get_attachment_url($this->id) . '" width="' . $default_sizes['single_video']['width'] . '" height="' . ($default_sizes['single_video']['height'] == 0 ? 'auto' : $default_sizes['single_video']['height']) . '" type="video/mp4" id="bp_media_video_' . $this->id . '" controls="controls" preload="none"></video><script>bp_media_create_element("bp_media_video_' . $this->id . '");</script>', $this);
361
+ }
362
+ break;
363
+ case 'audio' :
364
+ $content.=apply_filters('bp_media_single_content_filter', '<audio src="' . wp_get_attachment_url($this->id) . '" width="' . $default_sizes['single_audio']['width'] . '" type="audio/mp3" id="bp_media_audio_' . $this->id . '" controls="controls" preload="none" ></audio><script>bp_media_create_element("bp_media_audio_' . $this->id . '");</script>', $this);
365
+ break;
366
+ case 'image' :
367
+ $image_array = image_downsize($this->id, 'bp_media_single_image');
368
+ $content.=apply_filters('bp_media_single_content_filter', '<img src="' . $image_array[0] . '" id="bp_media_image_' . $this->id . '" />', $this);
369
+ break;
370
+ default :
371
+ return false;
372
+ }
373
+ $content .= '</div>';
374
+ $content .= '<div class="bp_media_description">' . nl2br($this->description) . '</div>';
375
+ return $content;
376
+ }
377
+
378
+ public function exif($file) {
379
+ $exif = read_exif_data($file['file']);
380
+ $exif_orient = isset($exif['Orientation'])?$exif['Orientation']:0;
381
+ $rotateImage = 0;
382
+
383
+ if (6 == $exif_orient) {
384
+ $rotateImage = 90;
385
+ $imageOrientation = 1;
386
+ } elseif (3 == $exif_orient) {
387
+ $rotateImage = 180;
388
+ $imageOrientation = 1;
389
+ } elseif (8 == $exif_orient) {
390
+ $rotateImage = 270;
391
+ $imageOrientation = 1;
392
+ }
393
+
394
+ if ($rotateImage) {
395
+ if (class_exists('Imagick')) {
396
+ $imagick = new \Imagick();
397
+ $imagick->readImage($file['file']);
398
+ $imagick->rotateImage(new \ImagickPixel(), $rotateImage);
399
+ $imagick->setImageOrientation($imageOrientation);
400
+ $imagick->writeImage($file['file']);
401
+ $imagick->clear();
402
+ $imagick->destroy();
403
+ } else {
404
+ $rotateImage = -$rotateImage;
405
+
406
+ switch ($file['type']) {
407
+ case 'image/jpeg':
408
+ $source = imagecreatefromjpeg($file['file']);
409
+ $rotate = imagerotate($source, $rotateImage, 0);
410
+ imagejpeg($rotate, $file['file']);
411
+ break;
412
+ case 'image/png':
413
+ $source = imagecreatefrompng($file['file']);
414
+ $rotate = imagerotate($source, $rotateImage, 0);
415
+ imagepng($rotate, $file['file']);
416
+ break;
417
+ case 'image/gif':
418
+ $source = imagecreatefromgif($file['file']);
419
+ $rotate = imagerotate($source, $rotateImage, 0);
420
+ imagegif($rotate, $file['file']);
421
+ break;
422
+ default:
423
+ break;
424
+ }
425
+ }
426
+ }
427
+ return $file;
428
+ }
429
+
430
+ /**
431
+ * Returns the HTML for title of the single entry page of the Media Entry
432
+ */
433
+
434
+ /**
435
+ *
436
+ * @global type $bp_media_default_excerpts
437
+ * @global type $bp_media
438
+ * @return string
439
+ */
440
+ function get_media_single_title() {
441
+ global $bp_media_default_excerpts, $bp_media;
442
+ $content = wp_html_excerpt($this->name, $bp_media_default_excerpts['single_entry_title']);
443
+ return $content;
444
+ }
445
+
446
+ /**
447
+ * Returns the HTML for a media entry to be shown in the listing/gallery page
448
+ */
449
+
450
+ /**
451
+ *
452
+ * @global type $bp_media
453
+ * @return boolean
454
+ */
455
+ function get_media_gallery_content() {
456
+ $attachment = $this->id;
457
+ switch ($this->type) {
458
+ case 'video' :
459
+ if ($this->thumbnail_id) {
460
+ $medium_array = image_downsize($this->thumbnail_id, 'thumbnail');
461
+ $thumb_url = $medium_array[0];
462
+ } else {
463
+ $thumb_url = BP_MEDIA_URL . 'app/assets/img/video_thumb.png';
464
+ }
465
+ ?>
466
+ <li id="bp-media-item-<?php echo $this->id ?>">
467
+ <a href="<?php echo $this->url ?>" title="<?php _e($this->description, BP_MEDIA_TXT_DOMAIN); ?>">
468
+ <img src="<?php echo apply_filters('bp_media_video_thumb', $thumb_url, $attachment, $this->type); ?>" />
469
+ </a>
470
+ <h3 title="<?php echo $this->name; ?>"><a href="<?php echo $this->url ?>" title="<?php _e($this->description, BP_MEDIA_TXT_DOMAIN); ?>"><?php echo $this->name; ?></a></h3>
471
+ </li>
472
+ <?php
473
+ break;
474
+ case 'audio' :
475
+ if ($this->thumbnail_id) {
476
+ $medium_array = image_downsize($this->thumbnail_id, 'thumbnail');
477
+ $thumb_url = $medium_array[0];
478
+ } else {
479
+ $thumb_url = BP_MEDIA_URL . 'app/assets/img/audio_thumb.png';
480
+ }
481
+ ?>
482
+ <li id="bp-media-item-<?php echo $this->id ?>">
483
+ <a href="<?php echo $this->url ?>" title="<?php _e($this->description, BP_MEDIA_TXT_DOMAIN); ?>">
484
+ <img src="<?php echo $thumb_url ?>" />
485
+ </a>
486
+ <h3 title="<?php echo $this->name; ?>"><a href="<?php echo $this->url ?>" title="<?php _e($this->description, BP_MEDIA_TXT_DOMAIN); ?>"><?php echo $this->name ?></a></h3>
487
+ <div class="bp-media-ajax-preloader"></div>
488
+ </li>
489
+ <?php
490
+ break;
491
+ case 'image' :
492
+ $medium_array = image_downsize($attachment, 'thumbnail');
493
+ $medium_path = $medium_array[0];
494
+ ?>
495
+ <li id="bp-media-item-<?php echo $this->id ?>">
496
+ <a href="<?php echo $this->url ?>" title="<?php echo $this->description ?>">
497
+ <img src="<?php echo $medium_path ?>" />
498
+ </a>
499
+ <h3 title="<?php echo $this->name ?>"><a href="<?php echo $this->url ?>" title="<?php _e($this->description, BP_MEDIA_TXT_DOMAIN); ?>"><?php echo $this->name ?></a></h3>
500
+ <div class="bp-media-ajax-preloader"></div>
501
+ </li>
502
+ <?php
503
+ break;
504
+ default :
505
+ return false;
506
+ }
507
+ }
508
+
509
+ function show_comment_form_wordpress() {
510
+ query_posts('attachment_id=' . $this->id);
511
+ while (have_posts()): the_post();
512
+ add_action('comment_form', 'BPMediaFunction::wp_comment_form_mod');
513
+ comments_template();
514
+ endwhile;
515
+ }
516
+
517
+ /**
518
+ * Outputs the comments and comment form in the single media entry page
519
+ */
520
+
521
+ /**
522
+ *
523
+ * @global type $bp_media
524
+ * @return boolean
525
+ */
526
+ function show_comment_form() {
527
+ global $bp_media;
528
+ $activity_id = get_post_meta($this->id, 'bp_media_child_activity', true);
529
+ if (!$activity_id || !function_exists('bp_has_activities'))
530
+ return false;
531
+ if (bp_has_activities(array(
532
+ 'display_comments' => 'stream',
533
+ 'include' => $activity_id,
534
+ 'max' => 1
535
+ ))) {
536
+ while (bp_activities()) {
537
+ bp_the_activity();
538
+ do_action('bp_before_activity_entry');
539
+ ?>
540
+ <div class="activity">
541
+ <ul id="activity-stream" class="activity-list item-list">
542
+ <li class="activity activity_update" id="activity-<?php echo $activity_id; ?>">
543
+ <div class="activity-content">
544
+ <?php do_action('bp_activity_entry_content'); ?>
545
+ <?php if (is_user_logged_in()) : ?>
546
+ <div class="activity-meta no-ajax">
547
+ <?php if (bp_activity_can_comment()) : ?>
548
+ <a href="<?php bp_get_activity_comment_link(); ?>" class="button acomment-reply bp-primary-action" id="acomment-comment-<?php bp_activity_id(); ?>"><?php printf(__('Comment <span>%s</span>', BP_MEDIA_TXT_DOMAIN), bp_activity_get_comment_count()); ?></a>
549
+ <?php endif; ?>
550
+ <?php if (bp_activity_can_favorite()) : ?>
551
+ <?php if (!bp_get_activity_is_favorite()) : ?>
552
+ <a href="<?php bp_activity_favorite_link(); ?>" class="button fav bp-secondary-action" title="<?php esc_attr_e('Mark as Favorite', BP_MEDIA_TXT_DOMAIN); ?>"><?php _e('Favorite', BP_MEDIA_TXT_DOMAIN) ?></a>
553
+ <?php else : ?>
554
+ <a href="<?php bp_activity_unfavorite_link(); ?>" class="button unfav bp-secondary-action" title="<?php esc_attr_e('Remove Favorite', BP_MEDIA_TXT_DOMAIN); ?>"><?php _e('Remove Favorite', BP_MEDIA_TXT_DOMAIN) ?></a>
555
+ <?php endif; ?>
556
+ <?php endif; ?>
557
+ <?php do_action('bp_activity_entry_meta'); ?>
558
+ <?php if (bp_activity_user_can_delete()) bp_activity_delete_link(); ?>
559
+ </div>
560
+ <?php endif; ?>
561
+ </div>
562
+ <?php do_action('bp_before_activity_entry_comments'); ?>
563
+ <?php if (( is_user_logged_in() && bp_activity_can_comment() ) || bp_activity_get_comment_count()) : ?>
564
+ <div class="activity-comments">
565
+ <?php bp_activity_comments(); ?>
566
+ <?php if (is_user_logged_in()) : ?>
567
+ <form action="<?php bp_activity_comment_form_action(); ?>" method="post" id="ac-form-<?php bp_activity_id(); ?>" class="ac-form"<?php bp_activity_comment_form_nojs_display(); ?>>
568
+ <div class="ac-reply-avatar"><?php bp_loggedin_user_avatar('width=' . BP_AVATAR_THUMB_WIDTH . '&height=' . BP_AVATAR_THUMB_HEIGHT); ?></div>
569
+ <div class="ac-reply-content">
570
+ <div class="ac-textarea">
571
+ <textarea id="ac-input-<?php bp_activity_id(); ?>" class="ac-input" name="ac_input_<?php bp_activity_id(); ?>"></textarea>
572
+ </div>
573
+ <input type="submit" name="ac_form_submit" value="<?php _e('Post', BP_MEDIA_TXT_DOMAIN); ?>" /> &nbsp; <?php _e('or press esc to cancel.', BP_MEDIA_TXT_DOMAIN); ?>
574
+ <input type="hidden" name="comment_form_id" value="<?php bp_activity_id(); ?>" />
575
+ </div>
576
+ <?php do_action('bp_activity_entry_comments'); ?>
577
+ <?php wp_nonce_field('new_activity_comment', '_wpnonce_new_activity_comment'); ?>
578
+ </form>
579
+ <?php endif; ?>
580
+ </div>
581
+ <?php endif; ?>
582
+ <?php do_action('bp_after_activity_entry_comments'); ?>
583
+ </li>
584
+ </ul>
585
+ </div>
586
+ <?php
587
+ }
588
+ }
589
+ else {
590
+ ?>
591
+ <div class="activity">
592
+ <ul id="activity-stream" class="activity-list item-list">
593
+ <li class="activity activity_update" id="activity-<?php echo $activity_id; ?>">
594
+ <div class="activity-content">
595
+ <?php do_action('bp_activity_entry_content'); ?>
596
+ <?php if (is_user_logged_in()) : ?>
597
+ <div class="activity-meta no-ajax">
598
+ <a href="<?php echo $this->get_delete_url(); ?>" class="button item-button bp-secondary-action delete-activity-single confirm" rel="nofollow"><?php _e("Delete", BP_MEDIA_TXT_DOMAIN); ?></a>
599
+ </div>
600
+ <?php endif; ?>
601
+ </div>
602
+ </li>
603
+ </ul>
604
+ </div>
605
+ <?php
606
+ }
607
+ }
608
+
609
+ /**
610
+ * Returns the URL of the single media entry page
611
+ */
612
+
613
+ /**
614
+ *
615
+ * @return type
616
+ */
617
+ function get_url() {
618
+ return $this->url;
619
+ }
620
+
621
+ /**
622
+ * Returns the URL of the attached media file
623
+ */
624
+
625
+ /**
626
+ *
627
+ * @return type
628
+ */
629
+ function get_attachment_url() {
630
+ return wp_get_attachment_url($this->id);
631
+ }
632
+
633
+ /**
634
+ * Updates the media entry
635
+ *
636
+ * @param array $args Array with the following keys:<br/>
637
+ * 'name' <br/>
638
+ * 'description'<br/>
639
+ * 'owner'
640
+ *
641
+ * @return bool True when the update is successful, False when the update fails
642
+ */
643
+
644
+ /**
645
+ *
646
+ * @param type $args
647
+ * @return type
648
+ */
649
+ function update_media($args = array()) {
650
+ $defaults = array(
651
+ 'name' => $this->name,
652
+ 'description' => $this->description,
653
+ 'owner' => $this->owner
654
+ );
655
+ $args = wp_parse_args($args, $defaults);
656
+ $post = get_post($this->id, ARRAY_A);
657
+ $post['post_title'] = esc_html($args['name']);
658
+ $post['post_content'] = esc_html($args['description']);
659
+ $post['post_author'] = $args['owner'];
660
+ $result = wp_update_post($post);
661
+ $this->init($this->id);
662
+ do_action('bp_media_after_update_media', $this);
663
+ return $result;
664
+ }
665
+
666
+ /**
667
+ * Updates activity content's title and description sync with the editing of Media
668
+ *
669
+ */
670
+
671
+ /**
672
+ *
673
+ * @global type $wpdb
674
+ * @global type $bp
675
+ * @global type $current_user
676
+ * @global type $bp_media
677
+ */
678
+ function update_media_activity() {
679
+ global $wpdb, $bp, $current_user, $bp_media;
680
+ $q = $wpdb->prepare("SELECT id FROM {$bp->activity->table_name} WHERE type = %s AND item_id = %d", 'media_upload', $this->id);
681
+ $activities = $wpdb->get_results($q);
682
+ if (isset($activities) && count($activities) > 0) {
683
+ $activities_template = new BP_Activity_Template(array(
684
+ 'max' => TRUE,
685
+ 'user_id' => $current_user,
686
+ 'in' => $activities[0]->id
687
+ ));
688
+ foreach ($activities_template->activities as $activity) {
689
+ if (isset($_POST['bp_media_group_id'])) {
690
+ $component = $bp->groups->id;
691
+ $item_id = $_POST['bp_media_group_id'];
692
+ } else {
693
+ $component = $bp->activity->id;
694
+ $item_id = $this->get_id();
695
+ }
696
+ $args = array(
697
+ 'content' => $this->get_media_activity_content(),
698
+ 'id' => $activity->id,
699
+ 'type' => $component,
700
+ 'action' => apply_filters('bp_media_added_media', sprintf(__('%1$s added a %2$s', BP_MEDIA_TXT_DOMAIN), bp_core_get_userlink($this->get_author()), '<a href="' . $this->get_url() . '">' . $this->get_media_activity_type() . '</a>')),
701
+ 'primary_link' => $this->get_url(),
702
+ 'item_id' => $item_id,
703
+ 'recorded_time' => $activity->date_recorded,
704
+ 'user_id' => $this->get_author()
705
+ );
706
+ $activity_id = BPMediaFunction::record_activity($args);
707
+ }
708
+ }
709
+ }
710
+
711
+ /**
712
+ * Deletes the Media Entry
713
+ */
714
+
715
+ /**
716
+ *
717
+ * @global type $bp_media_count
718
+ */
719
+ function delete_media() {
720
+ do_action('bp_media_before_delete_media', $this->id);
721
+ wp_delete_attachment($this->id, true);
722
+ do_action('bp_media_after_delete_media', $this->id);
723
+ }
724
+
725
+ /**
726
+ * Function to return the content to be placed in the activity of album
727
+ */
728
+
729
+ /**
730
+ *
731
+ * @return boolean|string
732
+ */
733
+ function get_album_activity_content() {
734
+ $attachment = $this->id;
735
+ switch ($this->type) {
736
+ case 'video' :
737
+ if ($this->thumbnail_id) {
738
+ $medium_array = image_downsize($this->thumbnail_id, 'thumbnail');
739
+ $thumb_url = $medium_array[0];
740
+ } else {
741
+ $thumb_url = BP_MEDIA_URL . 'app/assets/img/video_thumb.png';
742
+ }
743
+ break;
744
+ case 'audio' :
745
+ if ($this->thumbnail_id) {
746
+ $medium_array = image_downsize($this->thumbnail_id, 'thumbnail');
747
+ $thumb_url = $medium_array[0];
748
+ } else {
749
+ $thumb_url = BP_MEDIA_URL . 'app/assets/img/audio_thumb.png';
750
+ }
751
+ break;
752
+ case 'image' :
753
+ $medium_array = image_downsize($attachment, 'thumbnail');
754
+ $thumb_url = $medium_array[0];
755
+ break;
756
+ default :
757
+ return false;
758
+ }
759
+ $content = '<li>';
760
+ $content .= '<a href="' . $this->url . '" title="' . $this->name . '">';
761
+ $content .= '<img src="' . $thumb_url . '" />';
762
+ $content .= '</a>';
763
+ $content .= '</li>';
764
+ return $content;
765
+ }
766
+
767
+ /**
768
+ * Returns the description of the Media Entry
769
+ */
770
+
771
+ /**
772
+ *
773
+ * @return type
774
+ */
775
+ function get_content() {
776
+ return $this->description;
777
+ }
778
+
779
+ /**
780
+ * Returns the owner id of the Media Entry
781
+ */
782
+
783
+ /**
784
+ *
785
+ * @return type
786
+ */
787
+ function get_author() {
788
+ return $this->owner;
789
+ }
790
+
791
+ /**
792
+ * Returns the id of the Media Entry
793
+ */
794
+
795
+ /**
796
+ *
797
+ * @return type
798
+ */
799
+ function get_id() {
800
+ return $this->id;
801
+ }
802
+
803
+ /**
804
+ * Returns the edit url of the Media Entry
805
+ */
806
+
807
+ /**
808
+ *
809
+ * @return type
810
+ */
811
+ function get_edit_url() {
812
+ return $this->edit_url;
813
+ }
814
+
815
+ /**
816
+ * Returns the delete url of the Media Entry
817
+ */
818
+
819
+ /**
820
+ *
821
+ * @return type
822
+ */
823
+ function get_delete_url() {
824
+ return $this->delete_url;
825
+ }
826
+
827
+ /**
828
+ * Returns the type of activity
829
+ */
830
+
831
+ /**
832
+ *
833
+ * @return string
834
+ */
835
+ function get_media_activity_type() {
836
+ switch ($this->type) {
837
+ case 'image':
838
+ return BP_MEDIA_IMAGES_LABEL_SINGULAR;
839
+ case 'video':
840
+ return BP_MEDIA_VIDEOS_LABEL_SINGULAR;
841
+ case 'audio':
842
+ return BP_MEDIA_AUDIO_LABEL_SINGULAR;
843
+ default:
844
+ return 'Media';
845
+ }
846
+ }
847
+
848
+ /**
849
+ * Returns the album id
850
+ */
851
+
852
+ /**
853
+ *
854
+ * @return type
855
+ */
856
+ function get_album_id() {
857
+ return $this->album_id;
858
+ }
859
+
860
+ /**
861
+ * Returns the title of the media
862
+ */
863
+
864
+ /**
865
+ *
866
+ * @return type
867
+ */
868
+ function get_title() {
869
+ return $this->name;
870
+ }
871
+
872
+ /**
873
+ * Returns the type of media
874
+ */
875
+
876
+ /**
877
+ *
878
+ * @return type
879
+ */
880
+ function get_type() {
881
+ return $this->type;
882
+ }
883
+
884
+ /**
885
+ * Returns the thumbnail id
886
+ */
887
+ function get_thumbnail_id() {
888
+ return $this->thumbnail_id;
889
+ }
890
+
891
+ /**
892
+ * Returns the group id of the media, 0 if it does not belong to a group
893
+ */
894
+
895
+ /**
896
+ *
897
+ * @return type
898
+ */
899
+ function get_group_id() {
900
+ return $this->group_id;
901
+ }
902
+
903
+ /**
904
+ * Sets the permalinks of the media depending upon whether its in member directory
905
+ * or group and acording to the media type
906
+ */
907
+
908
+ /**
909
+ *
910
+ * @return boolean
911
+ */
912
+ protected function set_permalinks() {
913
+
914
+ if (bp_is_active('groups') && class_exists('BP_Group_Extension')) {
915
+ if ($this->group_id > 0) {
916
+ $current_group = new BP_Groups_Group($this->group_id);
917
+ $pre_url = bp_get_group_permalink($current_group);
918
+ } else {
919
+ $pre_url = bp_core_get_user_domain($this->owner);
920
+ }
921
+ } else {
922
+ $pre_url = bp_core_get_user_domain($this->owner);
923
+ }
924
+ switch ($this->type) {
925
+ case 'video' :
926
+ $this->url = trailingslashit($pre_url . BP_MEDIA_VIDEOS_SLUG . '/' . $this->id);
927
+ $this->edit_url = trailingslashit($pre_url . BP_MEDIA_VIDEOS_SLUG . '/' . BP_MEDIA_VIDEOS_EDIT_SLUG . '/' . $this->id);
928
+ $this->delete_url = trailingslashit($pre_url . BP_MEDIA_VIDEOS_SLUG . '/' . BP_MEDIA_DELETE_SLUG . '/' . $this->id);
929
+ $this->thumbnail_id = get_post_meta($this->id, 'bp_media_thumbnail', true);
930
+ break;
931
+ case 'audio' :
932
+ $this->url = trailingslashit($pre_url . BP_MEDIA_AUDIO_SLUG . '/' . $this->id);
933
+ $this->edit_url = trailingslashit($pre_url . BP_MEDIA_AUDIO_SLUG . '/' . BP_MEDIA_AUDIO_EDIT_SLUG . '/' . $this->id);
934
+ $this->delete_url = trailingslashit($pre_url . BP_MEDIA_AUDIO_SLUG . '/' . BP_MEDIA_DELETE_SLUG . '/' . $this->id);
935
+ $this->thumbnail_id = get_post_meta($this->id, 'bp_media_thumbnail', true);
936
+ break;
937
+ case 'image' :
938
+ $this->url = trailingslashit($pre_url . BP_MEDIA_IMAGES_SLUG . '/' . $this->id);
939
+ $this->edit_url = trailingslashit($pre_url . BP_MEDIA_IMAGES_SLUG . '/' . BP_MEDIA_IMAGES_EDIT_SLUG . '/' . $this->id);
940
+ $this->delete_url = trailingslashit($pre_url . BP_MEDIA_IMAGES_SLUG . '/' . BP_MEDIA_DELETE_SLUG . '/' . $this->id);
941
+ $image_array = image_downsize($this->id, 'bp_media_single_image');
942
+ $this->thumbnail_id = $this->id;
943
+ break;
944
+ case 'album' :
945
+ $this->url = trailingslashit($pre_url . BP_MEDIA_ALBUMS_SLUG . '/' . $this->id);
946
+ $this->edit_url = trailingslashit($pre_url . BP_MEDIA_ALBUMS_SLUG . '/' . BP_MEDIA_ALBUMS_EDIT_SLUG . '/' . $this->id);
947
+ $this->delete_url = trailingslashit($pre_url . BP_MEDIA_ALBUMS_SLUG . '/' . BP_MEDIA_DELETE_SLUG . '/' . $this->id);
948
  // $this->thumbnail_id = get_post_meta($this->id, 'bp_media_thumbnail', true);
949
+ break;
950
+ default :
951
+ return false;
952
+ }
953
+ return true;
954
+ }
955
+
956
+ /**
957
+ * Checks if the album given exists if not, creates a new one according to context
958
+ */
959
+
960
+ /**
961
+ *
962
+ * @global type $wpdb
963
+ * @param type $album_id
964
+ * @param type $group
965
+ * @return type
966
+ */
967
+ function check_and_create_album($album_id, $group) {
968
+ global $wpdb;
969
+ $post_wall = __('Wall Posts', BP_MEDIA_TXT_DOMAIN);
970
+ $create_new_album_flag = false;
971
+ if ($album_id != 0) {
972
+ $album = get_post($album_id);
973
+ if ($album->post_author != get_current_user_id() && $group == 0) {
974
+ $create_new_album_flag = true;
975
+ } else {
976
+ $post_id = $album->ID;
977
+ }
978
+ } else {
979
+ $create_new_album_flag = true;
980
+ }
981
+ $current_user = wp_get_current_user();
982
+ if ($create_new_album_flag) {
983
+ if ($group == 0) {
984
+ $post_id = $wpdb->get_var(
985
+ "SELECT ID
986
  FROM $wpdb->posts
987
  WHERE
988
  post_title = $post_wall
989
  AND post_author = '" . get_current_user_id() . "'
990
  AND post_type='bp_media_album'"
991
+ );
992
+ } else {
993
+ $post_id = $wpdb->get_var(
994
+ "SELECT wp_posts.ID
995
  FROM $wpdb->posts
996
  INNER JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id
997
  AND $wpdb->postmeta.meta_key = 'bp-media-key'
998
  AND $wpdb->postmeta.meta_value = -$group
999
+ AND $wpdb->posts.post_title = '$current_user->display_name\'s Album'");
1000
+ }
1001
+ if ($post_id == null) {
1002
+ $album = new BPMediaAlbum();
1003
+ if ($group == 0)
1004
+ $album->add_album($post_wall, get_current_user_id(), $group);
1005
+ else {
1006
+ $album->add_album($current_user->display_name . '\'s Album', get_current_user_id(), $group);
1007
+ }
1008
+ $post_id = $album->get_id();
1009
+ }
1010
+ }
1011
+ return $post_id;
1012
+ }
1013
+
1014
+ function get_description() {
1015
+ return $this->description;
1016
+ }
 
1017
 
1018
  }
1019
  ?>
app/main/profile/BPMediaTemplate.php CHANGED
@@ -56,7 +56,11 @@ class BPMediaTemplate {
56
  $albums = new WP_Query(array(
57
  'post_type' => 'bp_media_album',
58
  'posts_per_page' => -1,
59
- 'author' => get_current_user_id()
 
 
 
 
60
  ));
61
  }
62
  if (isset($albums->posts) && is_array($albums->posts) && count($albums->posts) > 0) {
56
  $albums = new WP_Query(array(
57
  'post_type' => 'bp_media_album',
58
  'posts_per_page' => -1,
59
+ 'author' => get_current_user_id(),
60
+ 'meta_key' => 'bp-media-key',
61
+ 'meta_value' => get_current_user_id(),
62
+ 'meta_compare' => '='
63
+
64
  ));
65
  }
66
  if (isset($albums->posts) && is_array($albums->posts) && count($albums->posts) > 0) {
index.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: BuddyPress Media
4
  Plugin URI: http://rtcamp.com/buddypress-media/?utm_source=dashboard&utm_medium=plugin&utm_campaign=buddypress-media
5
  Description: This plugin adds missing media rich features like photos, videos and audio uploading to BuddyPress which are essential if you are building social network, seriously!
6
- Version: 2.7.1
7
  Author: rtCamp
8
  Text Domain: buddypress-media
9
  Author URI: http://rtcamp.com/?utm_source=dashboard&utm_medium=plugin&utm_campaign=buddypress-media
3
  Plugin Name: BuddyPress Media
4
  Plugin URI: http://rtcamp.com/buddypress-media/?utm_source=dashboard&utm_medium=plugin&utm_campaign=buddypress-media
5
  Description: This plugin adds missing media rich features like photos, videos and audio uploading to BuddyPress which are essential if you are building social network, seriously!
6
+ Version: 2.7.2
7
  Author: rtCamp
8
  Text Domain: buddypress-media
9
  Author URI: http://rtcamp.com/?utm_source=dashboard&utm_medium=plugin&utm_campaign=buddypress-media
readme.txt CHANGED
@@ -6,7 +6,7 @@ License: GPLv2 or later
6
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
7
  Requires at least: WordPress 3.5 + BuddyPress 1.6
8
  Tested up to: WordPress 3.5 + BuddyPress 1.6
9
- Stable tag: 2.7.1
10
 
11
  Adds Photos, Music, Videos & Albums to BuddyPress. Supports mobile devices (iPhone/iPad, etc) and automatic audio/video conversion.
12
 
@@ -120,6 +120,17 @@ Please visit [BuddyPress Media's Features page](http://rtcamp.com/buddypress-med
120
  == Changelog ==
121
 
122
  Please visit [BuddyPress Media's Roadmap page](http://rtcamp.com/buddypress-media/roadmap/?utm_source=readme&utm_medium=plugin&utm_campaign=buddypress-media "Visit BuddyPress Media's Features page") to get some details about future releases.
 
 
 
 
 
 
 
 
 
 
 
123
  = 2.7.1 =
124
  * Fixes bug related to group ids.
125
  * Fixes bug with stylesheet loading
@@ -318,5 +329,5 @@ Please visit [BuddyPress Media's Roadmap page](http://rtcamp.com/buddypress-medi
318
  * HTML5 Video Tag Support (with fallback)
319
 
320
  == Upgrade Notice ==
321
- = 2.7 =
322
- Activity Uploader and lightbox
6
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
7
  Requires at least: WordPress 3.5 + BuddyPress 1.6
8
  Tested up to: WordPress 3.5 + BuddyPress 1.6
9
+ Stable tag: 2.7.2
10
 
11
  Adds Photos, Music, Videos & Albums to BuddyPress. Supports mobile devices (iPhone/iPad, etc) and automatic audio/video conversion.
12
 
120
  == Changelog ==
121
 
122
  Please visit [BuddyPress Media's Roadmap page](http://rtcamp.com/buddypress-media/roadmap/?utm_source=readme&utm_medium=plugin&utm_campaign=buddypress-media "Visit BuddyPress Media's Features page") to get some details about future releases.
123
+
124
+ = 2.7.2 =
125
+ * Fixes warning related to scalar variables
126
+ * Improves Group Wall Post handling
127
+ * Adds lightbox to activity media
128
+ * Fixes mediaelement display
129
+ * Implements forced download for media
130
+ * Fixes image rotation on upload
131
+ * Fixes broken spinner image
132
+ * Fixes some styling
133
+
134
  = 2.7.1 =
135
  * Fixes bug related to group ids.
136
  * Fixes bug with stylesheet loading
329
  * HTML5 Video Tag Support (with fallback)
330
 
331
  == Upgrade Notice ==
332
+ = 2.7.2 =
333
+ Activity Uploader and lightbox, Bug fixes