rtMedia for WordPress, BuddyPress and bbPress - Version 2.8

Version Description

  • Adds importer for BP Album
  • Tested with reallifescrapped, an aswesome social network for scrapbookers by Meg
  • Other minor bug fixes, especially for Groups
Download this release

Release Info

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

Code changes from version 2.7.6 to 2.8

app/admin/BPMediaAdmin.php CHANGED
@@ -27,8 +27,11 @@ if (!class_exists('BPMediaAdmin')) {
27
  add_action('wp_ajax_bp_media_submit_request', array($this->bp_media_support, 'submit_request'), 1);
28
  add_action('wp_ajax_bp_media_fetch_feed', array($bp_media_feed, 'fetch_feed'), 1);
29
  add_action('wp_ajax_bp_media_linkback', array($this, 'linkback'), 1);
30
- // add_action('wp_ajax_bp_media_bp_album_import', 'BPMediaAlbumimporter::bpmedia_ajax_import_callback', 1);
31
- // add_action('wp_ajax_bp_media_bp_album_cleanup', 'BPMediaAlbumimporter::cleanup_after_install');
 
 
 
32
  add_action('wp_ajax_bp_media_convert_videos_form', array($this, 'convert_videos_mailchimp_send'), 1);
33
  add_filter('plugin_row_meta', array($this, 'plugin_meta_premium_addon_link'), 1, 4);
34
  if (is_admin()) {
@@ -59,7 +62,7 @@ if (!class_exists('BPMediaAdmin')) {
59
  wp_localize_script('bp-media-admin', 'settings_url', add_query_arg(
60
  array('page' => 'bp-media-settings'), (is_multisite() ? network_admin_url('admin.php') : admin_url('admin.php'))
61
  ) . '#privacy_enabled');
62
- wp_localize_script('bp-media-admin', 'settings_bp_album_import_url', add_query_arg(
63
  array('page' => 'bp-media-settings'), (is_multisite() ? network_admin_url('admin.php') : admin_url('admin.php'))
64
  ));
65
  wp_enqueue_style('bp-media-admin', BP_MEDIA_URL . 'app/assets/css/main.css', '', BP_MEDIA_VERSION);
@@ -79,8 +82,8 @@ if (!class_exists('BPMediaAdmin')) {
79
  }
80
  $bp_album_active = BPMediaImporter::_active('bp-album/loader.php');
81
  $table = "{$wpdb->base_prefix}bp_album";
82
- if (BPMediaImporter::table_exists($table) && $bp_album_active!=-1) {
83
- add_submenu_page('bp-media-settings', __('BP Album Import', BP_MEDIA_TXT_DOMAIN), __('BP Album Importer', BP_MEDIA_TXT_DOMAIN), 'manage_options', 'bp-media-bp-album-importer', array($this, 'bp_album_importer_page'));
84
  }
85
  add_submenu_page('bp-media-settings', __('BuddyPress Media Addons', BP_MEDIA_TXT_DOMAIN), __('Addons', BP_MEDIA_TXT_DOMAIN), 'manage_options', 'bp-media-addons', array($this, 'addons_page'));
86
  add_submenu_page('bp-media-settings', __('BuddyPress Media Support', BP_MEDIA_TXT_DOMAIN), __('Support ', BP_MEDIA_TXT_DOMAIN), 'manage_options', 'bp-media-support', array($this, 'support_page'));
@@ -100,8 +103,8 @@ if (!class_exists('BPMediaAdmin')) {
100
  $this->render_page('bp-media-privacy');
101
  }
102
 
103
- public function bp_album_importer_page() {
104
- $this->render_page('bp-media-bp-album-importer');
105
  }
106
 
107
  public function convert_videos_page() {
@@ -253,6 +256,18 @@ if (!class_exists('BPMediaAdmin')) {
253
  'class' => ($tab == 'bp-media-convert-videos') ? $active_class : $idle_class . ' last_tab'
254
  );
255
  }
 
 
 
 
 
 
 
 
 
 
 
 
256
 
257
  $tabs = apply_filters('bp_media_add_sub_tabs', $tabs, $tab);
258
  foreach ($tabs as $tab) {
27
  add_action('wp_ajax_bp_media_submit_request', array($this->bp_media_support, 'submit_request'), 1);
28
  add_action('wp_ajax_bp_media_fetch_feed', array($bp_media_feed, 'fetch_feed'), 1);
29
  add_action('wp_ajax_bp_media_linkback', array($this, 'linkback'), 1);
30
+ add_action('wp_ajax_bp_media_bp_album_deactivate', 'BPMediaAlbumimporter::bp_album_deactivate', 1);
31
+ add_action('wp_ajax_bp_media_bp_album_import', 'BPMediaAlbumimporter::bpmedia_ajax_import_callback', 1);
32
+ add_action('wp_ajax_bp_media_bp_album_import_favorites', 'BPMediaAlbumimporter::bpmedia_ajax_import_favorites', 1);
33
+ add_action('wp_ajax_bp_media_bp_album_import_step_favorites', 'BPMediaAlbumimporter::bpmedia_ajax_import_step_favorites', 1);
34
+ add_action('wp_ajax_bp_media_bp_album_cleanup', 'BPMediaAlbumimporter::cleanup_after_install');
35
  add_action('wp_ajax_bp_media_convert_videos_form', array($this, 'convert_videos_mailchimp_send'), 1);
36
  add_filter('plugin_row_meta', array($this, 'plugin_meta_premium_addon_link'), 1, 4);
37
  if (is_admin()) {
62
  wp_localize_script('bp-media-admin', 'settings_url', add_query_arg(
63
  array('page' => 'bp-media-settings'), (is_multisite() ? network_admin_url('admin.php') : admin_url('admin.php'))
64
  ) . '#privacy_enabled');
65
+ wp_localize_script('bp-media-admin', 'settings_bp_album_import_url', add_query_arg(
66
  array('page' => 'bp-media-settings'), (is_multisite() ? network_admin_url('admin.php') : admin_url('admin.php'))
67
  ));
68
  wp_enqueue_style('bp-media-admin', BP_MEDIA_URL . 'app/assets/css/main.css', '', BP_MEDIA_VERSION);
82
  }
83
  $bp_album_active = BPMediaImporter::_active('bp-album/loader.php');
84
  $table = "{$wpdb->base_prefix}bp_album";
85
+ if (BPMediaImporter::table_exists($table) && $bp_album_active != -1) {
86
+ add_submenu_page('bp-media-settings', __('Importer', BP_MEDIA_TXT_DOMAIN), __('Importer', BP_MEDIA_TXT_DOMAIN), 'manage_options', 'bp-media-importer', array($this, 'bp_importer_page'));
87
  }
88
  add_submenu_page('bp-media-settings', __('BuddyPress Media Addons', BP_MEDIA_TXT_DOMAIN), __('Addons', BP_MEDIA_TXT_DOMAIN), 'manage_options', 'bp-media-addons', array($this, 'addons_page'));
89
  add_submenu_page('bp-media-settings', __('BuddyPress Media Support', BP_MEDIA_TXT_DOMAIN), __('Support ', BP_MEDIA_TXT_DOMAIN), 'manage_options', 'bp-media-support', array($this, 'support_page'));
103
  $this->render_page('bp-media-privacy');
104
  }
105
 
106
+ public function bp_importer_page() {
107
+ $this->render_page('bp-media-importer');
108
  }
109
 
110
  public function convert_videos_page() {
256
  'class' => ($tab == 'bp-media-convert-videos') ? $active_class : $idle_class . ' last_tab'
257
  );
258
  }
259
+
260
+ global $wpdb;
261
+ $bp_album_active = BPMediaImporter::_active('bp-album/loader.php');
262
+ $table = "{$wpdb->base_prefix}bp_album";
263
+ if (BPMediaImporter::table_exists($table) && $bp_album_active!=-1) {
264
+ $tabs[] = array(
265
+ 'href' => bp_get_admin_url(add_query_arg(array('page' => 'bp-media-importer'), 'admin.php')),
266
+ 'title' => __('Importer', BP_MEDIA_TXT_DOMAIN),
267
+ 'name' => __('Importer', BP_MEDIA_TXT_DOMAIN),
268
+ 'class' => ($tab == 'bp-media-importer') ? $active_class : $idle_class
269
+ );
270
+ }
271
 
272
  $tabs = apply_filters('bp_media_add_sub_tabs', $tabs, $tab);
273
  foreach ($tabs as $tab) {
app/assets/css/main.css CHANGED
@@ -38,8 +38,8 @@ ul#social li{display:inline;}
38
  #spread-the-word .button{display:inline-block; margin: 9px 5px 0 5px;}
39
  #spread-the-word label{display:block;}
40
  #spread-the-word .inside{text-align: center;}
41
- #spread-the-word .button-tweet{background: #33ACE6; border-color: #3399DD #3399DD #2288CC; color: #FFFFFF !important; text-shadow: -1px -1px 0 #3399DD;}
42
- #spread-the-word .button-tweet:hover{background: #3399DD;border-color: #2288CC;box-shadow: 0 0 4px rgba(82, 168, 236, 0.75);}
43
  #spread-the-word .button-rating{background: #8A8A8A; border-color: #222; color: #FFFFFF !important; text-shadow: -1px -1px 0 #444;}
44
  #spread-the-word .button-rating:hover{background: #7E7E7E;border-color: #444;box-shadow: 0 0 4px rgba(128,128,128, 0.75);}
45
  .wrap.bp-media-admin .bp-media-settings-tabs a.nav-tab{padding-left:20px;background:url('../img/tab-icon.png') 3px -4px no-repeat;}
@@ -92,6 +92,40 @@ a.toplevel_page_bp-media-settings div.wp-menu-image{
92
  box-shadow: 0 1px rgba(0, 0, 0, 0.2), 0 0 1px rgba(0, 0, 0, 0.4) inset;
93
  color: #FFFFFF;}
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  /* Admin bar Menu */
96
  #wpadminbar .bp-media-settings-menu > .ab-item .ab-icon{background: url("../img/bpm-icon-16.png") no-repeat scroll -8px -7px transparent}
97
  #wpadminbar .bp-media-settings-menu:hover .ab-icon{background-position: -8px -41px}
38
  #spread-the-word .button{display:inline-block; margin: 9px 5px 0 5px;}
39
  #spread-the-word label{display:block;}
40
  #spread-the-word .inside{text-align: center;}
41
+ #spread-the-word .button-tweet, #bpmedia-bpalbumimporter .button-import-tweet{background: #33ACE6; border-color: #3399DD #3399DD #2288CC; color: #FFFFFF !important; text-shadow: -1px -1px 0 #3399DD;}
42
+ #spread-the-word .button-tweet:hover, #bpmedia-bpalbumimporter .button-import-tweet:hover{background: #3399DD;border-color: #2288CC;box-shadow: 0 0 4px rgba(82, 168, 236, 0.75);}
43
  #spread-the-word .button-rating{background: #8A8A8A; border-color: #222; color: #FFFFFF !important; text-shadow: -1px -1px 0 #444;}
44
  #spread-the-word .button-rating:hover{background: #7E7E7E;border-color: #444;box-shadow: 0 0 4px rgba(128,128,128, 0.75);}
45
  .wrap.bp-media-admin .bp-media-settings-tabs a.nav-tab{padding-left:20px;background:url('../img/tab-icon.png') 3px -4px no-repeat;}
92
  box-shadow: 0 1px rgba(0, 0, 0, 0.2), 0 0 1px rgba(0, 0, 0, 0.4) inset;
93
  color: #FFFFFF;}
94
 
95
+ div.i-accept{ background-color: #dff0d8 !important; }
96
+ div.bp-album-import-accept{ padding: 1px 2px; margin-bottom: 15px; }
97
+ .bp-album-importer-wizard { display: none; margin-top: 15px; }
98
+ #setting-error-bp-album-importer { line-height: 1.8em; }
99
+ .wp-core-ui .btn-warning {
100
+ color: #ffffff;
101
+ text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
102
+ background-color: #faa732;
103
+ *background-color: #f89406;
104
+ background-image: -moz-linear-gradient(top, #fbb450, #f89406);
105
+ background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#fbb450), to(#f89406));
106
+ background-image: -webkit-linear-gradient(top, #fbb450, #f89406);
107
+ background-image: -o-linear-gradient(top, #fbb450, #f89406);
108
+ background-image: linear-gradient(to bottom, #fbb450, #f89406);
109
+ background-repeat: repeat-x;
110
+ border-color: #f89406 #f89406 #ad6704;
111
+ border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
112
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fffbb450', endColorstr='#fff89406', GradientType=0);
113
+ filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
114
+ }
115
+
116
+ .wp-core-ui .btn-warning:hover,
117
+ .wp-core-ui .btn-warning:focus,
118
+ .wp-core-ui .btn-warning:active,
119
+ .wp-core-ui .btn-warning.active,
120
+ .wp-core-ui .btn-warning.disabled,
121
+ .wp-core-ui .btn-warning[disabled] {
122
+ color: #ffffff;
123
+ background: #f89406;
124
+ background-color: #f89406;
125
+ *background: #df8505;
126
+ *background-color: #df8505;
127
+ }
128
+
129
  /* Admin bar Menu */
130
  #wpadminbar .bp-media-settings-menu > .ab-item .ab-icon{background: url("../img/bpm-icon-16.png") no-repeat scroll -8px -7px transparent}
131
  #wpadminbar .bp-media-settings-menu:hover .ab-icon{background-position: -8px -41px}
app/assets/js/admin.js CHANGED
@@ -76,7 +76,6 @@ jQuery(document).ready(function(){
76
  if(response != 0){
77
  var redirect = false;
78
  var progw = Math.ceil((((parseInt(response)*20)+parseInt(data.values['finished']))/parseInt(data.values['total'])) *100);
79
- console.log(progw);
80
  if(progw>100){
81
  progw=100;
82
  redirect=true
@@ -96,6 +95,11 @@ jQuery(document).ready(function(){
96
  }
97
  });
98
  }
 
 
 
 
 
99
 
100
  jQuery('#rtprivacyinstall').click(function(e){
101
  e.preventDefault();
@@ -140,54 +144,154 @@ jQuery(document).ready(function(){
140
  });
141
 
142
  function fireimportRequest(data) {
143
- return jQuery.post(ajaxurl, data, function(response){
144
- cleanup = false;
145
- if(response != 0){
146
  var redirect = false;
147
- var progw = Math.ceil((((parseInt(response)*20)+parseInt(data.values['finished']))/parseInt(data.values['total'])) *100);
148
- if(progw>100){
149
- progw=100;
150
- cleanup=true
 
 
 
 
 
 
 
151
  };
152
- jQuery('#rtprogressbar>div').css('width',progw+'%');
153
- finished = jQuery('#bpmedia-bpalbumimport span.finished').html();
154
- jQuery('#bpmedia-bpalbumimport span.finished').html(parseInt(finished)+data.count);
155
- if ( cleanup ) {
156
- window.location = document.URL;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  }
158
  } else {
159
- jQuery('#map_progress_msgs').html('<div class="map_mapping_failure">Row '+response+' failed.</div>');
160
  }
161
  });
162
  }
163
 
164
- jQuery('#bpmedia-bpalbumimport-cleanup').click(function(e){
165
- e.preventDefault();
166
- jQuery.post(ajaxurl, {
167
- action: 'bp_media_bp_album_cleanup'
168
- }, function(response){
169
- window.location = settings_bp_album_import_url;
170
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
 
172
- });
 
 
 
 
 
 
173
 
174
- jQuery('#bpmedia-bpalbumimport').click(function(e){
 
 
175
  e.preventDefault();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  $progress_parent = jQuery('#bpmedia-bpalbumimport');
177
  $values=[];
178
  jQuery(this).parent().find('input').each(function(){
179
  $values [jQuery(this).attr('name')]=[jQuery(this).val()];
180
 
181
  });
182
- console.log($values);
 
 
183
 
184
  $data = {};
185
  for(var i=1;i<=$values['steps'][0];i++ ){
186
- $count=20;
187
  if(i==$values['steps'][0]){
188
  $count=parseInt($values['laststep'][0]);
189
  if($count==0){
190
- $count=20
191
  };
192
  }
193
  newvals = {
@@ -198,7 +302,6 @@ jQuery(document).ready(function(){
198
  }
199
  $data[i] = newvals;
200
  }
201
- console.log($data);
202
  var $startingpoint = jQuery.Deferred();
203
  $startingpoint.resolve();
204
  jQuery.each($data, function(i, v){
@@ -233,6 +336,20 @@ jQuery(document).ready(function(){
233
  });
234
  return false;
235
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236
 
237
 
238
  });
76
  if(response != 0){
77
  var redirect = false;
78
  var progw = Math.ceil((((parseInt(response)*20)+parseInt(data.values['finished']))/parseInt(data.values['total'])) *100);
 
79
  if(progw>100){
80
  progw=100;
81
  redirect=true
95
  }
96
  });
97
  }
98
+
99
+ jQuery('#bpmedia-bpalbumimporter').on('change','#bp-album-import-accept',function(){
100
+ jQuery('.bp-album-import-accept').toggleClass('i-accept');
101
+ jQuery('.bp-album-importer-wizard').slideToggle();
102
+ });
103
 
104
  jQuery('#rtprivacyinstall').click(function(e){
105
  e.preventDefault();
144
  });
145
 
146
  function fireimportRequest(data) {
147
+ return jQuery.getJSON(ajaxurl, data, function(response){
148
+ favorites = false;
149
+ if(response){
150
  var redirect = false;
151
+ var media_progw = Math.ceil((((parseInt(response.page)*5)+parseInt(data.values['finished']))/parseInt(data.values['total'])) *100);
152
+ comments_total = jQuery('#bpmedia-bpalbumimporter .bp-album-comments span.total').html();
153
+ users_total = jQuery('#bpmedia-bpalbumimporter .bp-album-users span.total').html();
154
+ media_total = jQuery('#bpmedia-bpalbumimporter .bp-album-media span.total').html();
155
+ comments_finished = jQuery('#bpmedia-bpalbumimporter .bp-album-comments span.finished').html();
156
+ users_finished = jQuery('#bpmedia-bpalbumimporter .bp-album-users span.finished').html();
157
+ var comments_progw = Math.ceil((((parseInt(response.comments))+parseInt(comments_finished))/parseInt(comments_total)) *100);
158
+ var users_progw = Math.ceil((parseInt(response.users)/parseInt(users_total)) *100);
159
+ if(media_progw>100 || media_progw==100 ){
160
+ media_progw=100;
161
+ favorites=true
162
  };
163
+ jQuery('.bp-album-media #rtprogressbar>div').css('width',media_progw+'%');
164
+ jQuery('.bp-album-comments #rtprogressbar>div').css('width',comments_progw+'%');
165
+ jQuery('.bp-album-users #rtprogressbar>div').css('width',users_progw+'%');
166
+ media_finished = jQuery('#bpmedia-bpalbumimporter .bp-album-media span.finished').html();
167
+ if (parseInt(media_finished)<parseInt(media_total))
168
+ jQuery('#bpmedia-bpalbumimporter .bp-album-media span.finished').html(parseInt(media_finished)+data.count);
169
+ jQuery('#bpmedia-bpalbumimporter .bp-album-comments span.finished').html(parseInt(response.comments)+parseInt(comments_finished));
170
+ jQuery('#bpmedia-bpalbumimporter .bp-album-users span.finished').html(parseInt(response.users));
171
+ if ( favorites ) {
172
+ favorite_data = {
173
+ 'action':'bp_media_bp_album_import_favorites'
174
+ }
175
+ jQuery.post(ajaxurl,favorite_data,function(response){
176
+ if(response.favorites!==0||response.favorites!=='0'){
177
+ if(!jQuery('.bp-album-favorites').length)
178
+ jQuery('.bp-album-comments').after('<br /><div class="bp-album-favorites"><strong>User\'s Favorites: <span class="finished">0</span> / <span class="total">'+response.users+'</span></strong><div id="rtprogressbar"><div style="width:0%"></div></div></div>');
179
+ $favorites = {};
180
+ if (response.offset != 0 || response.offset != '0')
181
+ start = response.offset*1+1;
182
+ else
183
+ start = 1
184
+ for(var i=start;i<=response.users;i++ ){
185
+ $count=1;
186
+ if(i==response.users){
187
+ $count=parseInt(response.users % $count);
188
+ if($count==0){
189
+ $count=1;
190
+ }
191
+ }
192
+
193
+ newvals = {
194
+ 'action':'bp_media_bp_album_import_step_favorites',
195
+ 'offset':(i-1)*1,
196
+ 'redirect':i==response.users
197
+ }
198
+ $favorites[i] = newvals;
199
+ }
200
+ var $startingpoint = jQuery.Deferred();
201
+ $startingpoint.resolve();
202
+ jQuery.each($favorites, function(i, v){
203
+ $startingpoint = $startingpoint.pipe( function() {
204
+ return fireimportfavoriteRequest(v);
205
+ });
206
+ });
207
+
208
+ } else {
209
+ window.setTimeout(reload_url, 2000);
210
+ }
211
+ },'json');
212
  }
213
  } else {
214
+ jQuery('#map_progress_msgs').html('<div class="map_mapping_failure">Row '+response.page+' failed.</div>');
215
  }
216
  });
217
  }
218
 
219
+ function fireimportfavoriteRequest(data) {
220
+ return jQuery.post(ajaxurl, data, function(response){
221
+ redirect=false;
222
+ favorites_total = jQuery('#bpmedia-bpalbumimporter .bp-album-favorites span.total').html();
223
+ favorites_finished = jQuery('#bpmedia-bpalbumimporter .bp-album-favorites span.finished').html();
224
+ jQuery('#bpmedia-bpalbumimporter .bp-album-favorites span.finished').html(parseInt(favorites_finished)+1);
225
+ var favorites_progw = Math.ceil((parseInt(favorites_finished+1)/parseInt(favorites_total)) *100);
226
+ if(favorites_progw>100 || favorites_progw==100 ){
227
+ favorites_progw=100;
228
+ redirect=true;
229
+ }
230
+ jQuery('.bp-album-favorites #rtprogressbar>div').css('width',favorites_progw+'%');
231
+ if(redirect){
232
+ window.setTimeout(reload_url, 2000);
233
+ }
234
+ });
235
+ }
236
+
237
+ function reload_url(){
238
+ window.location = document.URL;
239
+ }
240
 
241
+ jQuery('#bpmedia-bpalbumimport-cleanup').click(function(e){
242
+ e.preventDefault();
243
+ jQuery.post(ajaxurl, {
244
+ action: 'bp_media_bp_album_cleanup'
245
+ }, function(response){
246
+ window.location = settings_bp_album_import_url;
247
+ });
248
 
249
+ });
250
+
251
+ jQuery('#bpmedia-bpalbumimporter').on('click','#bpmedia-bpalbumimport',function(e){
252
  e.preventDefault();
253
+ if(!jQuery('#bp-album-import-accept').prop('checked')){
254
+ jQuery('html, body').animate({
255
+ scrollTop: jQuery( '#bp-album-import-accept' ).offset().top
256
+ }, 500);
257
+ var $el = jQuery('.bp-album-import-accept'),
258
+ x = 500,
259
+ originalColor = '#FFEBE8',
260
+ i = 3; //counter
261
+
262
+ (function loop() { //recurisve IIFE
263
+ $el.css("background-color", "#EE0000");
264
+ setTimeout(function () {
265
+ $el.css("background-color", originalColor);
266
+ if (--i) setTimeout(loop, x); //restart loop
267
+ }, x);
268
+ }());
269
+ return;
270
+ } else {
271
+ jQuery(this).prop('disabled', true);
272
+ }
273
+ wp_admin_url = ajaxurl.replace('admin-ajax.php','');
274
+ if (!jQuery('.bpm-ajax-loader').length)
275
+ jQuery(this).after(' <img class="bpm-ajax-loader" src="'+wp_admin_url+'images/wpspin_light.gif" /> <strong>Please do not refresh this page.</strong>');
276
+
277
+
278
  $progress_parent = jQuery('#bpmedia-bpalbumimport');
279
  $values=[];
280
  jQuery(this).parent().find('input').each(function(){
281
  $values [jQuery(this).attr('name')]=[jQuery(this).val()];
282
 
283
  });
284
+
285
+ if ( $values['steps'][0] == 0 )
286
+ $values['steps'][0]=1;
287
 
288
  $data = {};
289
  for(var i=1;i<=$values['steps'][0];i++ ){
290
+ $count=5;
291
  if(i==$values['steps'][0]){
292
  $count=parseInt($values['laststep'][0]);
293
  if($count==0){
294
+ $count=5
295
  };
296
  }
297
  newvals = {
302
  }
303
  $data[i] = newvals;
304
  }
 
305
  var $startingpoint = jQuery.Deferred();
306
  $startingpoint.resolve();
307
  jQuery.each($data, function(i, v){
336
  });
337
  return false;
338
  });
339
+
340
+ jQuery('#bpmedia-bpalbumimporter').on('click','.deactivate-bp-album',function(e){
341
+ e.preventDefault();
342
+ $bpalbum = jQuery(this);
343
+ var data = {
344
+ action: 'bp_media_bp_album_deactivate'
345
+ }
346
+ jQuery.get(ajaxurl, data, function(response) {
347
+ if(response)
348
+ location.reload();
349
+ else
350
+ $bpalbum.parent().after('<p>Something went wronng. Please <a href onclick="location.reload();">refresh</a> page.</p>');
351
+ });
352
+ });
353
 
354
 
355
  });
app/helper/BPMediaSettings.php CHANGED
@@ -156,8 +156,7 @@ if (!class_exists('BPMediaSettings')) {
156
  $table = "{$wpdb->base_prefix}bp_album";
157
  if (BPMediaImporter::table_exists($table) && $bp_album_active!=-1) {
158
  $bp_media_album_importer = new BPMediaAlbumimporter();
159
- add_filter('bp_media_add_sub_tabs', array($bp_media_album_importer, 'tab'), 99, 2);
160
- add_settings_section('bpm-bp-album-importer', __('BP Album Importer', BP_MEDIA_TXT_DOMAIN), array($bp_media_album_importer, 'ui'), 'bp-media-bp-album-importer');
161
  }
162
 
163
  add_settings_section('bpm-convert-videos', '', array($this, 'convert_videos_form'), 'bp-media-convert-videos');
156
  $table = "{$wpdb->base_prefix}bp_album";
157
  if (BPMediaImporter::table_exists($table) && $bp_album_active!=-1) {
158
  $bp_media_album_importer = new BPMediaAlbumimporter();
159
+ add_settings_section('bpm-bp-album-importer', __('BP-Album Importer', BP_MEDIA_TXT_DOMAIN), array($bp_media_album_importer, 'ui'), 'bp-media-importer');
 
160
  }
161
 
162
  add_settings_section('bpm-convert-videos', '', array($this, 'convert_videos_form'), 'bp-media-convert-videos');
app/importers/BPMediaAlbumimporter.php CHANGED
@@ -15,10 +15,8 @@ class BPMediaAlbumimporter extends BPMediaImporter {
15
  function __construct() {
16
  global $wpdb;
17
  parent::__construct();
18
- $this->path = 'bp-album/loader.php';
19
- $this->active = $this->_active($this->path);
20
  $table = "{$wpdb->base_prefix}bp_album";
21
- if (BPMediaImporter::table_exists($table) && $this->active != -1 && !$this->column_exists('import_status')) {
22
  $this->update_table();
23
  }
24
  }
@@ -28,8 +26,11 @@ class BPMediaAlbumimporter extends BPMediaImporter {
28
  return;
29
  global $wpdb;
30
  return $wpdb->query(
31
- "ALTER TABLE {$wpdb->base_prefix}bp_album ADD COLUMN
32
- import_status TINYINT (1) NOT NULL DEFAULT 0"
 
 
 
33
  );
34
  }
35
 
@@ -40,70 +41,121 @@ class BPMediaAlbumimporter extends BPMediaImporter {
40
  );
41
  }
42
 
43
- function tab($tabs, $tab) {
44
- $idle_class = 'nav-tab';
45
- $active_class = 'nav-tab nav-tab-active';
46
- $tabs[] = array(
47
- 'href' => bp_get_admin_url(add_query_arg(array('page' => 'bp-media-bp-album-importer'), 'admin.php')),
48
- 'title' => __('Import BP-Album', BP_MEDIA_TXT_DOMAIN),
49
- 'name' => __('Import BP-Album', BP_MEDIA_TXT_DOMAIN),
50
- 'class' => ($tab == 'bp-media-bp-album-importer') ? $active_class : $idle_class
51
- );
52
- return $tabs;
53
- }
54
-
55
  function ui() {
56
  $this->progress = new rtProgress();
57
- $total = $this->get_total_count();
58
- $finished = $this->get_completed_count();
59
-
60
-
61
- //(isset($total) && isset($finished) && is_array($total) && is_array($finished)){
 
 
 
62
  echo '<div id="bpmedia-bpalbumimporter">';
63
- if ($finished != $total) {
64
- if (!$total) {
65
  echo '<p><strong>' . __('You have nothing to import') . '</strong></p>';
66
- } elseif ($this->active != 1) {
67
  echo '<div id="setting-error-bp-album-importer" class="error settings-error below-h2">
68
- <p><strong>' . __('This process is irreversible. Please take a backup of your database and files, before proceeding.', BP_MEDIA_TXT_DOMAIN) . '</strong></p></div>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  echo '<strong>';
70
- echo '<span class="finished">' . $finished . '</span> / <span class="total">' . $total . '</span>';
71
  echo '</strong>';
72
  $progress = 100;
73
- if ($total != 0) {
74
- $todo = $total - $finished;
75
- $steps = ceil($todo / 20);
76
- $laststep = $todo % 20;
77
- $progress = $this->progress->progress($finished, $total);
78
- echo '<input type="hidden" value="' . $finished . '" name="finished"/>';
79
- echo '<input type="hidden" value="' . $total . '" name="total"/>';
80
  echo '<input type="hidden" value="' . $todo . '" name="todo"/>';
81
  echo '<input type="hidden" value="' . $steps . '" name="steps"/>';
82
  echo '<input type="hidden" value="' . $laststep . '" name="laststep"/>';
83
  $this->progress->progress_ui($progress);
84
- echo "<br>";
85
  }
86
- echo '<button id="bpmedia-bpalbumimport" class="button button-primary">';
87
- _e('Start', BP_MEDIA_TXT_DOMAIN);
88
- echo '</button>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  } else {
90
- $install_link = wp_nonce_url(admin_url('plugins.php?action=deactivate&amp;plugin=' . urlencode($this->path)), 'deactivate-plugin_' . $this->path);
91
- echo '<p><strong>' . sprintf(__('Please <a href="%s">deactivate</a> BP-Album first', BP_MEDIA_TXT_DOMAIN), $install_link) . '</strong></p>';
 
92
  }
93
  } else {
94
- echo '<p class="info">';
95
- _e('All media from BP Album has been imported. However, there are a lot of extra files and a database table eating up your resources. Would you like to delete them now?', BP_MEDIA_TXT_DOMAIN);
96
- echo '</p>';
97
- echo '<div id="setting-error-bp-album-importer" class="error settings-error below-h2">
98
- <p><strong>' . __('This process is irreversible. Please take a backup of your database and files, before proceeding.', BP_MEDIA_TXT_DOMAIN) . '</strong></p></div>';
99
- echo '<button id="bpmedia-bpalbumimport-cleanup" class="button button-primary">';
100
- _e('Clean Up', BP_MEDIA_TXT_DOMAIN);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  echo '</button>';
 
 
 
 
 
102
  }
103
  echo '</div>';
104
  }
105
 
106
- function create_album($author_id, $album_name = 'BP Album') {
107
  global $bp_media, $wpdb;
108
 
109
  if (array_key_exists('bp_album_import_name', $bp_media->options)) {
@@ -121,61 +173,171 @@ class BPMediaAlbumimporter extends BPMediaImporter {
121
  } else {
122
  $album_id = $result[0]->ID;
123
  }
124
- $wpdb->update($wpdb->prefix . 'bp_activity', array('secondary_item_id' => -999), array('id' => get_post_meta($album_id, 'bp_media_child_activity', true)));
125
 
126
  return $album_id;
127
  }
128
 
129
- function get_total_count() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  global $wpdb;
131
  $table = $wpdb->base_prefix . 'bp_album';
132
- if ($this->table_exists($table) && $this->active != -1) {
133
- return $wpdb->query("SELECT * FROM $table");
134
  }
135
  return 0;
136
  }
137
 
138
- function get_completed_count() {
139
  global $wpdb;
140
  $table = $wpdb->base_prefix . 'bp_album';
141
- if ($this->table_exists($table) && $this->active != -1) {
142
- return $wpdb->query("SELECT * FROM $table WHERE import_status!=0");
143
  }
144
  return 0;
145
  }
146
 
147
- static function batch_import($offset = 0, $count = 20) {
148
  global $wpdb;
149
  $table = $wpdb->base_prefix . 'bp_album';
150
- $bp_album_data = $wpdb->get_results("SELECT * FROM $table WHERE import_status=0 LIMIT $count OFFSET $offset");
151
  return $bp_album_data;
152
  }
153
 
154
  static function bpmedia_ajax_import_callback() {
155
 
156
  $page = isset($_GET['page']) ? $_GET['page'] : 1;
157
- $count = isset($_GET['count']) ? $_GET['count'] : 20;
158
- $offset = ($page > 1) ? (($page - 1) * 20 + $count) : 0;
159
-
160
- $bp_album_data = BPMediaAlbumimporter::batch_import($offset, $count);
161
  global $wpdb;
162
  $table = $wpdb->base_prefix . 'bp_album';
163
-
 
 
164
  foreach ($bp_album_data as &$bp_album_item) {
165
 
166
  if (get_site_option('bp_media_bp_album_importer_base_path') == '') {
167
  $base_path = pathinfo($bp_album_item->pic_org_path);
168
  update_site_option('bp_media_bp_album_importer_base_path', $base_path['dirname']);
169
  }
170
- $album_id = BPMediaAlbumimporter::create_album($bp_album_item->owner_id, 'BP Album');
 
 
171
  $imported_media_id = BPMediaImporter::add_media(
172
- $album_id, $bp_album_item->title, $bp_album_item->description, $bp_album_item->pic_org_path, $bp_album_item->privacy, $bp_album_item->owner_id
173
  );
174
- $wpdb->update($table, array('import_status' => $imported_media_id), array('id' => $bp_album_item->id), array('%d'), array('%d'));
175
- BPMediaAlbumimporter::update_recorded_time_and_comments($imported_media_id, $bp_album_item->id, "{$wpdb->base_prefix}bp_album");
 
 
 
 
 
 
 
 
 
176
  }
177
 
178
- echo $page;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  die();
180
  }
181
 
@@ -198,24 +360,33 @@ class BPMediaAlbumimporter extends BPMediaImporter {
198
  }
199
  }
200
  $activity_id = get_post_meta($media->get_id(), 'bp_media_child_activity', true);
201
-
202
  if ($activity_id) {
203
  $date_uploaded = $wpdb->get_var("SELECT date_uploaded from $table WHERE id = $bp_album_id");
204
- $old_activity_id = $wpdb->get_var("SELECT id from {$wpdb->prefix}bp_activity WHERE component = 'album' AND type = 'bp_album_picture' AND item_id = $bp_album_id");
205
- $comments = $wpdb->get_results("SELECT id,secondary_item_id from {$wpdb->prefix}bp_activity WHERE component = 'activity' AND type = 'activity_comment' AND item_id = $old_activity_id");
206
- foreach ($comments as $comment) {
207
- $update = array('item_id' => $activity_id);
208
- if ($comment->secondary_item_id == $old_activity_id) {
209
- $update['secondary_item_id'] = $activity_id;
 
 
 
 
210
  }
211
- $wpdb->update($wpdb->prefix . 'bp_activity', $update, array('id' => $comment->id));
212
- BP_Activity_Activity::rebuild_activity_comment_tree($activity_id);
213
  }
214
- $wpdb->update($wpdb->prefix . 'bp_activity', array('date_recorded' => $date_uploaded), array('id' => $activity_id));
 
215
  }
 
 
216
  }
217
  }
218
 
 
 
 
 
 
219
  }
220
 
221
  ?>
15
  function __construct() {
16
  global $wpdb;
17
  parent::__construct();
 
 
18
  $table = "{$wpdb->base_prefix}bp_album";
19
+ if (BPMediaImporter::table_exists($table) && BPMediaAlbumimporter::_active('bp-album/loader.php') != -1 && !$this->column_exists('import_status')) {
20
  $this->update_table();
21
  }
22
  }
26
  return;
27
  global $wpdb;
28
  return $wpdb->query(
29
+ "ALTER TABLE {$wpdb->base_prefix}bp_album
30
+ ADD COLUMN import_status BIGINT (20) NOT NULL DEFAULT 0,
31
+ ADD COLUMN old_activity_id BIGINT (20) NOT NULL DEFAULT 0,
32
+ ADD COLUMN new_activity_id BIGINT (20) NOT NULL DEFAULT 0,
33
+ ADD COLUMN favorites TINYINT (1) NOT NULL DEFAULT 0"
34
  );
35
  }
36
 
41
  );
42
  }
43
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  function ui() {
45
  $this->progress = new rtProgress();
46
+ $total = BPMediaAlbumimporter::get_total_count();
47
+ $remaining_comments = $this->get_remaining_comments();
48
+ $finished = BPMediaAlbumimporter::get_completed_media($total);
49
+ $finished_users = BPMediaAlbumimporter::get_completed_users();
50
+ $finished_comments = $this->get_finished_comments();
51
+ $total_comments = (int) $finished_comments + (int) $remaining_comments;
52
+ $completed_users_favorites = (int) get_site_option('bp_media_bp_album_favorite_import_status', 0);
53
+ $users = count_users();
54
  echo '<div id="bpmedia-bpalbumimporter">';
55
+ if (($finished[0]->media != $total[0]->media) || ( $users['total_users'] > $completed_users_favorites )) {
56
+ if (!$total[0]->media) {
57
  echo '<p><strong>' . __('You have nothing to import') . '</strong></p>';
58
+ } elseif (BPMediaAlbumimporter::_active('bp-album/loader.php') != 1) {
59
  echo '<div id="setting-error-bp-album-importer" class="error settings-error below-h2">
60
+ <p><strong>' . __('Warning!', BP_MEDIA_TXT_DOMAIN) . '</strong> ' . sprintf(__('This import process is irreversible. Although everything is tested, please take a <a target="_blank" href="http://codex.wordpress.org/WordPress_Backups">backup of your database and files</a>, before proceeding. If you don\'t know your way around databases and files, consider <a target="_blank" href="%s">hiring us</a>, or another professional.', BP_MEDIA_TXT_DOMAIN), 'http://rtcamp.com/contact/?purpose=buddypress&utm_source=dashboard&utm_medium=plugin&utm_campaign=buddypress-media') . '</p>';
61
+ echo '<p>' . __('If you have set "WP_DEBUG" in you wp-config.php file, please make sure it is set to "false", so that it doesn\'t conflict with the import process.', BP_MEDIA_TXT_DOMAIN) . '</p></div>';
62
+ echo '<div class="bp-album-import-accept"><p><strong><label for="bp-album-import-accept"><input type="checkbox" value="accept" name="bp-album-import-accept" id="bp-album-import-accept" /> ' . __('I have taken a backup of the database and files of this site.', BP_MEDIA_TXT_DOMAIN) . '</label></strong></p></div>';
63
+ echo '<button id="bpmedia-bpalbumimport" class="button button-primary">';
64
+ _e('Start Import', BP_MEDIA_TXT_DOMAIN);
65
+ echo '</button>';
66
+ echo '<div class="bp-album-importer-wizard">';
67
+ echo '<div class="bp-album-users">';
68
+ echo '<strong>';
69
+ echo __('Users', BP_MEDIA_TXT_DOMAIN) . ': <span class="finished">' . $finished_users[0]->users . '</span> / <span class="total">' . $total[0]->users . '</span>';
70
+ echo '</strong>';
71
+ if ($total[0]->users != 0) {
72
+ $users_progress = $this->progress->progress($finished_users[0]->users, $total[0]->users);
73
+ $this->progress->progress_ui($users_progress);
74
+ }
75
+ echo '</div>';
76
+ echo '<br />';
77
+ echo '<div class="bp-album-media">';
78
  echo '<strong>';
79
+ echo __('Media', BP_MEDIA_TXT_DOMAIN) . ': <span class="finished">' . $finished[0]->media . '</span> / <span class="total">' . $total[0]->media . '</span>';
80
  echo '</strong>';
81
  $progress = 100;
82
+ if ($total[0]->media != 0) {
83
+ $todo = $total[0]->media - $finished[0]->media;
84
+ $steps = ceil($todo / 5);
85
+ $laststep = $todo % 5;
86
+ $progress = $this->progress->progress($finished[0]->media, $total[0]->media);
87
+ echo '<input type="hidden" value="' . $finished[0]->media . '" name="finished"/>';
88
+ echo '<input type="hidden" value="' . $total[0]->media . '" name="total"/>';
89
  echo '<input type="hidden" value="' . $todo . '" name="todo"/>';
90
  echo '<input type="hidden" value="' . $steps . '" name="steps"/>';
91
  echo '<input type="hidden" value="' . $laststep . '" name="laststep"/>';
92
  $this->progress->progress_ui($progress);
 
93
  }
94
+ echo '</div>';
95
+ echo "<br>";
96
+ echo '<div class="bp-album-comments">';
97
+ if ($total_comments != 0) {
98
+ echo '<strong>';
99
+ echo __('Comments', BP_MEDIA_TXT_DOMAIN) . ': <span class="finished">' . $finished_comments . '</span> / <span class="total">' . $total_comments . '</span>';
100
+ echo '</strong>';
101
+ $comments_progress = $this->progress->progress($finished_comments, $total_comments);
102
+ $this->progress->progress_ui($comments_progress);
103
+ echo '<br />';
104
+ } else {
105
+ echo '<p><strong>' . __('Comments: 0/0 (No comments to import)', BP_MEDIA_TXT_DOMAIN) . '</strong></p>';
106
+ }
107
+ echo '</div>';
108
+ if ($completed_users_favorites != 0) {
109
+ echo '<br />';
110
+ echo '<div class="bp-album-favorites">';
111
+ echo '<strong>';
112
+ echo __('User\'s Favorites', BP_MEDIA_TXT_DOMAIN) . ': <span class="finished">' . $completed_users_favorites . '</span> / <span class="total">' . $users['total_users'] . '</span>';
113
+ echo '</strong>';
114
+ $favorites_progress = $this->progress->progress($completed_users_favorites, $users['total_users']);
115
+ $this->progress->progress_ui($favorites_progress);
116
+ echo '</div>';
117
+ }
118
+ echo '</div>';
119
  } else {
120
+ $deactivate_link = wp_nonce_url(admin_url('plugins.php?action=deactivate&amp;plugin=' . urlencode($this->path)), 'deactivate-plugin_' . $this->path);
121
+ echo '<p>' . __('BP-Album is active on your site and will cause problems with the import.', BP_MEDIA_TXT_DOMAIN) . '</p>';
122
+ echo '<p><a class="button button-primary deactivate-bp-album" href="' . $deactivate_link . '">' . __('Click here to deactivate BP-Album and continue importing', BP_MEDIA_TXT_DOMAIN) . '</a></p>';
123
  }
124
  } else {
125
+ $corrupt_media = BPMediaAlbumimporter::get_corrupt_media();
126
+ if ($corrupt_media) {
127
+ echo '<div class="error below-h2">';
128
+ echo '<p><strong>' . __('Some of the media failed to import. The file might be corrupt or deleted.', BP_MEDIA_TXT_DOMAIN) . '</strong></p>';
129
+ echo '<p>' . sprintf(__('The following %d BP Album Media id\'s could not be imported', BP_MEDIA_TXT_DOMAIN), count($corrupt_media)) . ': </p>';
130
+ $corrupt_prefix_path = str_replace('/wp-content','',WP_CONTENT_URL);
131
+ foreach ($corrupt_media as $corrupt) {
132
+ echo '<p>'.$corrupt->id.' => <a href="'.$corrupt_prefix_path.$corrupt->pic_org_url.'">'.$corrupt->title.'</a></p>';
133
+ }
134
+ echo '</div>';
135
+ } else {
136
+ echo '<div class="bp-album-import-accept i-accept">';
137
+ echo '<p class="info">';
138
+ $message = sprintf(__('I just imported bp-album to @buddypressmedia http://goo.gl/8Upmv on %s', BP_MEDIA_TXT_DOMAIN), home_url());
139
+ echo '<strong>' . __('Congratulations!', BP_MEDIA_TXT_DOMAIN) . '</strong> ' . __('All media from BP Album has been imported.', BP_MEDIA_TXT_DOMAIN);
140
+ echo ' <a href="http://twitter.com/home/?status=' . $message . '" class="button button-import-tweet" target= "_blank">' . __('Tweet this', BP_MEDIA_TXT_DOMAIN) . '</a>';
141
+ echo '</p>';
142
+ echo '</div>';
143
+ }
144
+ echo '<p>' . __('However, a lot of unnecessary files and a database table are still eating up your resources. If everything seems fine, you can clean this data up.', BP_MEDIA_TXT_DOMAIN) . '</p>';
145
+ echo '<br />';
146
+ echo '<button id="bpmedia-bpalbumimport-cleanup" class="button btn-warning">';
147
+ _e('Clean up Now', BP_MEDIA_TXT_DOMAIN);
148
  echo '</button>';
149
+ echo ' <a href="' . add_query_arg(
150
+ array('page' => 'bp-media-settings'), (is_multisite() ? network_admin_url('admin.php') : admin_url('admin.php'))
151
+ ) . '" id="bpmedia-bpalbumimport-cleanup-later" class="button">';
152
+ _e('Clean up Later', BP_MEDIA_TXT_DOMAIN);
153
+ echo '</a>';
154
  }
155
  echo '</div>';
156
  }
157
 
158
+ function create_album($author_id, $album_name = 'Imported Media') {
159
  global $bp_media, $wpdb;
160
 
161
  if (array_key_exists('bp_album_import_name', $bp_media->options)) {
173
  } else {
174
  $album_id = $result[0]->ID;
175
  }
176
+ $wpdb->update($wpdb->base_prefix . 'bp_activity', array('secondary_item_id' => -999), array('id' => get_post_meta($album_id, 'bp_media_child_activity', true)));
177
 
178
  return $album_id;
179
  }
180
 
181
+ static function get_total_count() {
182
+ global $wpdb;
183
+ $table = $wpdb->base_prefix . 'bp_album';
184
+ if (BPMediaAlbumimporter::table_exists($table) && BPMediaAlbumimporter::_active('bp-album/loader.php') != -1) {
185
+ return $wpdb->get_results("SELECT COUNT(DISTINCT owner_id) as users, COUNT(id) as media FROM $table");
186
+ }
187
+ return 0;
188
+ }
189
+
190
+ function get_remaining_comments() {
191
+ global $wpdb;
192
+ $bp_album_table = $wpdb->base_prefix . 'bp_album';
193
+ $activity_table = $wpdb->base_prefix . 'bp_activity';
194
+ if ($this->table_exists($bp_album_table) && BPMediaAlbumimporter::_active('bp-album/loader.php') != -1) {
195
+ return $wpdb->get_var("SELECT SUM( b.count ) AS total
196
+ FROM (
197
+ SELECT (
198
+ SELECT COUNT( a.id )
199
+ FROM $activity_table a
200
+ WHERE a.item_id = activity.id
201
+ AND a.component = 'activity'
202
+ AND a.type = 'activity_comment'
203
+ ) AS count
204
+ FROM $activity_table AS activity
205
+ INNER JOIN $bp_album_table AS album ON ( album.id = activity.item_id )
206
+ WHERE activity.component = 'album'
207
+ AND activity.type = 'bp_album_picture'
208
+ AND album.import_status =0
209
+ )b");
210
+ }
211
+ return 0;
212
+ }
213
+
214
+ function get_finished_comments() {
215
+ global $wpdb;
216
+ $bp_album_table = $wpdb->base_prefix . 'bp_album';
217
+ $activity_table = $wpdb->base_prefix . 'bp_activity';
218
+ if ($this->table_exists($bp_album_table) && BPMediaAlbumimporter::_active('bp-album/loader.php') != -1) {
219
+ return $wpdb->get_var("SELECT COUNT( activity.id ) AS count
220
+ FROM $activity_table AS activity
221
+ INNER JOIN $bp_album_table AS album ON ( activity.item_id = album.import_status )
222
+ WHERE activity.component = 'activity'
223
+ AND activity.type = 'activity_comment'");
224
+ }
225
+ return 0;
226
+ }
227
+
228
+ static function get_completed_users() {
229
+ global $wpdb;
230
+ $table = $wpdb->base_prefix . 'bp_album';
231
+ if (BPMediaAlbumimporter::table_exists($table) && BPMediaAlbumimporter::_active('bp-album/loader.php') != -1) {
232
+ return $wpdb->get_results("SELECT COUNT( DISTINCT owner_id ) AS users
233
+ FROM $table
234
+ WHERE owner_id NOT
235
+ IN (
236
+ SELECT a.owner_id
237
+ FROM $table a
238
+ WHERE a.import_status =0
239
+ )
240
+ ");
241
+ }
242
+ return 0;
243
+ }
244
+
245
+ static function get_completed_media() {
246
  global $wpdb;
247
  $table = $wpdb->base_prefix . 'bp_album';
248
+ if (BPMediaAlbumimporter::table_exists($table) && BPMediaAlbumimporter::_active('bp-album/loader.php') != -1) {
249
+ return $wpdb->get_results("SELECT COUNT(id) as media FROM $table WHERE import_status!=0");
250
  }
251
  return 0;
252
  }
253
 
254
+ static function get_corrupt_media() {
255
  global $wpdb;
256
  $table = $wpdb->base_prefix . 'bp_album';
257
+ if (BPMediaAlbumimporter::table_exists($table) && BPMediaAlbumimporter::_active('bp-album/loader.php') != -1) {
258
+ return $wpdb->get_results("SELECT id,title,pic_org_url FROM $table WHERE import_status=-1");
259
  }
260
  return 0;
261
  }
262
 
263
+ static function batch_import($count = 5) {
264
  global $wpdb;
265
  $table = $wpdb->base_prefix . 'bp_album';
266
+ $bp_album_data = $wpdb->get_results("SELECT * FROM $table WHERE import_status = 0 ORDER BY owner_id LIMIT $count");
267
  return $bp_album_data;
268
  }
269
 
270
  static function bpmedia_ajax_import_callback() {
271
 
272
  $page = isset($_GET['page']) ? $_GET['page'] : 1;
273
+ $count = isset($_GET['count']) ? $_GET['count'] : 5;
274
+ $bp_album_data = BPMediaAlbumimporter::batch_import($count);
 
 
275
  global $wpdb;
276
  $table = $wpdb->base_prefix . 'bp_album';
277
+ $activity_table = $wpdb->base_prefix . 'bp_activity';
278
+ $activity_meta_table = $wpdb->base_prefix . 'bp_activity_meta';
279
+ $comments = 0;
280
  foreach ($bp_album_data as &$bp_album_item) {
281
 
282
  if (get_site_option('bp_media_bp_album_importer_base_path') == '') {
283
  $base_path = pathinfo($bp_album_item->pic_org_path);
284
  update_site_option('bp_media_bp_album_importer_base_path', $base_path['dirname']);
285
  }
286
+ $bpm_host_wp = new BPMediaHostWordpress();
287
+ $bpm_host_wp->check_and_create_album(0, 0, $bp_album_item->owner_id);
288
+ $album_id = BPMediaAlbumimporter::create_album($bp_album_item->owner_id, 'Imported Media');
289
  $imported_media_id = BPMediaImporter::add_media(
290
+ $album_id, $bp_album_item->title, $bp_album_item->description, $bp_album_item->pic_org_path, $bp_album_item->privacy, $bp_album_item->owner_id, 'Imported Media'
291
  );
292
+ $wpdb->update($table, array('import_status' => ($imported_media_id) ? $imported_media_id : -1), array('id' => $bp_album_item->id), array('%d'), array('%d'));
293
+ if ($imported_media_id) {
294
+ $comments += (int) BPMediaAlbumimporter::update_recorded_time_and_comments($imported_media_id, $bp_album_item->id, "{$wpdb->base_prefix}bp_album");
295
+ $bp_album_media_id = $wpdb->get_var("SELECT activity.id from $activity_table as activity INNER JOIN $table as album ON ( activity.item_id = album.id ) WHERE activity.item_id = $bp_album_item->id AND activity.component = 'album' AND activity.type='bp_album_picture'");
296
+ $wpdb->update($table, array('old_activity_id' => $bp_album_media_id), array('id' => $bp_album_item->id), array('%d'), array('%d'));
297
+ $bp_new_activity_id = $wpdb->get_var("SELECT id from $activity_table WHERE item_id = $imported_media_id AND component = 'activity' AND type='activity_update' AND secondary_item_id=0");
298
+ $wpdb->update($table, array('new_activity_id' => $bp_new_activity_id), array('id' => $bp_album_item->id), array('%d'), array('%d'));
299
+ if ($wpdb->update($activity_meta_table, array('activity_id' => $bp_new_activity_id), array('activity_id' => $bp_album_media_id, 'meta_key' => 'favorite_count'), array('%d'), array('%d'))) {
300
+ $wpdb->update($table, array('favorites' => 1), array('id' => $bp_album_item->id), array('%d'), array('%d'));
301
+ }
302
+ }
303
  }
304
 
305
+ $finished_users = BPMediaAlbumimporter::get_completed_users();
306
+
307
+ echo json_encode(array('page' => $page, 'users' => $finished_users[0]->users, 'comments' => $comments));
308
+ die();
309
+ }
310
+
311
+ static function bpmedia_ajax_import_favorites() {
312
+ global $wpdb;
313
+ $table = $wpdb->base_prefix . 'bp_album';
314
+ $users = count_users();
315
+ echo json_encode(array('favorites' => $wpdb->get_var("SELECT COUNT(id) from $table WHERE favorites != 0"), 'users' => $users['total_users'], 'offset' => (int) get_site_option('bp_media_bp_album_favorite_import_status', 0)));
316
+ die();
317
+ }
318
+
319
+ static function bpmedia_ajax_import_step_favorites() {
320
+ $offset = isset($_POST['offset']) ? $_POST['offset'] : 0;
321
+ $redirect = isset($_POST['redirect']) ? $_POST['redirect'] : FALSE;
322
+ global $wpdb;
323
+ $table = $wpdb->base_prefix . 'bp_album';
324
+ $blogusers = get_users(array('meta_key' => 'bp_favorite_activities', 'offset' => $offset, 'number' => 1));
325
+ if ($blogusers) {
326
+ foreach ($blogusers as $user) {
327
+ $favorite_activities = get_user_meta($user->ID, 'bp_favorite_activities', true);
328
+ if ($favorite_activities) {
329
+ $new_favorite_activities = $favorite_activities;
330
+ foreach ($favorite_activities as $key => $favorite) {
331
+ if ($new_act = $wpdb->get_var("SELECT new_activity_id from $table WHERE old_activity_id = $favorite"))
332
+ $new_favorite_activities[$key] = $new_act;
333
+ }
334
+ update_user_meta($user->ID, 'bp_favorite_activities', $new_favorite_activities);
335
+ }
336
+ $completed_users_favorites = (int) get_site_option('bp_media_bp_album_favorite_import_status', 0) + 1;
337
+ update_site_option('bp_media_bp_album_favorite_import_status', $completed_users_favorites);
338
+ }
339
+ }
340
+ echo $redirect;
341
  die();
342
  }
343
 
360
  }
361
  }
362
  $activity_id = get_post_meta($media->get_id(), 'bp_media_child_activity', true);
 
363
  if ($activity_id) {
364
  $date_uploaded = $wpdb->get_var("SELECT date_uploaded from $table WHERE id = $bp_album_id");
365
+ $old_activity_id = $wpdb->get_var("SELECT id from {$wpdb->base_prefix}bp_activity WHERE component = 'album' AND type = 'bp_album_picture' AND item_id = $bp_album_id");
366
+ if ($old_activity_id) {
367
+ $comments = $wpdb->get_results("SELECT id,secondary_item_id from {$wpdb->base_prefix}bp_activity WHERE component = 'activity' AND type = 'activity_comment' AND item_id = $old_activity_id");
368
+ foreach ($comments as $comment) {
369
+ $update = array('item_id' => $activity_id);
370
+ if ($comment->secondary_item_id == $old_activity_id) {
371
+ $update['secondary_item_id'] = $activity_id;
372
+ }
373
+ $wpdb->update($wpdb->base_prefix . 'bp_activity', $update, array('id' => $comment->id));
374
+ BP_Activity_Activity::rebuild_activity_comment_tree($activity_id);
375
  }
 
 
376
  }
377
+ $wpdb->update($wpdb->base_prefix . 'bp_activity', array('date_recorded' => $date_uploaded), array('id' => $activity_id));
378
+ return count($comments);
379
  }
380
+
381
+ return 0;
382
  }
383
  }
384
 
385
+ static function bp_album_deactivate() {
386
+ deactivate_plugins('bp-album/loader.php');
387
+ die(true);
388
+ }
389
+
390
  }
391
 
392
  ?>
app/importers/BPMediaImporter.php CHANGED
@@ -22,11 +22,7 @@ class BPMediaImporter {
22
 
23
  }
24
 
25
- function table_exists($table) {
26
-
27
- //for 2.7.6 please remove for 2.8
28
- return false;
29
-
30
  global $wpdb;
31
 
32
  if ($wpdb->query("SHOW TABLES LIKE '" . $table . "'") == 1) {
@@ -37,10 +33,6 @@ class BPMediaImporter {
37
  }
38
 
39
  static function _active($path) {
40
-
41
- //for 2.7.6 please remove for 2.8
42
- return -1;
43
-
44
  if (!function_exists('is_plugin_inactive')) {
45
  require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
46
  }
@@ -75,9 +67,12 @@ class BPMediaImporter {
75
  if (!is_dir($tmp_dir)) {
76
  wp_mkdir_p($tmp_dir);
77
  }
78
- if (copy($filepath, $newpath)) {
79
- return BPMediaImporter::file_array($newpath);
 
 
80
  }
 
81
  }
82
 
83
  function create_album($album_name = '', $author_id = 1) {
@@ -101,18 +96,18 @@ class BPMediaImporter {
101
  return $album_id;
102
  }
103
 
104
- static function add_media($album_id, $title = '', $description = '', $filepath = '', $privacy = 0, $author_id = false) {
105
 
106
 
107
  $files = BPMediaImporter::make_copy($filepath);
108
  if ($files) {
109
-
110
  $bp_imported_media = new BPMediaHostWordpress();
111
  // add_filter('bp_media_force_hide_activity', create_function('', 'return true;'));
112
- $imported_media_id = $bp_imported_media->add_media($title, $description, $album_id, 0, false, false, $files);
113
-
114
  wp_update_post($args = array('ID' => $imported_media_id, 'post_author' => $author_id));
115
-
116
  $bp_album_privacy = $privacy;
117
  if ($bp_album_privacy == 10)
118
  $bp_album_privacy = 6;
22
 
23
  }
24
 
25
+ static function table_exists($table) {
 
 
 
 
26
  global $wpdb;
27
 
28
  if ($wpdb->query("SHOW TABLES LIKE '" . $table . "'") == 1) {
33
  }
34
 
35
  static function _active($path) {
 
 
 
 
36
  if (!function_exists('is_plugin_inactive')) {
37
  require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
38
  }
67
  if (!is_dir($tmp_dir)) {
68
  wp_mkdir_p($tmp_dir);
69
  }
70
+ if(file_exists($filepath)) {
71
+ if (copy($filepath, $newpath)) {
72
+ return BPMediaImporter::file_array($newpath);
73
+ }
74
  }
75
+ return 0;
76
  }
77
 
78
  function create_album($album_name = '', $author_id = 1) {
96
  return $album_id;
97
  }
98
 
99
+ static function add_media($album_id, $title = '', $description = '', $filepath = '', $privacy = 0, $author_id = false, $album_name = false) {
100
 
101
 
102
  $files = BPMediaImporter::make_copy($filepath);
103
  if ($files) {
104
+ global $wpdb;
105
  $bp_imported_media = new BPMediaHostWordpress();
106
  // add_filter('bp_media_force_hide_activity', create_function('', 'return true;'));
107
+ $imported_media_id = $bp_imported_media->insert_media($title, $description, $album_id, 0, false, false, $files, $author_id, $album_name);
108
+
109
  wp_update_post($args = array('ID' => $imported_media_id, 'post_author' => $author_id));
110
+
111
  $bp_album_privacy = $privacy;
112
  if ($bp_album_privacy == 10)
113
  $bp_album_privacy = 6;
app/main/group/BPMediaGroupElementExtension.php CHANGED
@@ -29,7 +29,10 @@ if (class_exists('BP_Group_Extension')) :
29
  * @throws Exception
30
  */
31
  function display() {
32
- global $bp;
 
 
 
33
  $current_tab = BP_MEDIA_IMAGES_SLUG;
34
  if (isset($bp->action_variables[0])) {
35
  $current_tab = $bp->action_variables[0];
@@ -61,11 +64,20 @@ if (class_exists('BP_Group_Extension')) :
61
  default:
62
  /** @todo Error is to be displayed for 404 */
63
  }
 
 
 
 
 
 
 
 
 
64
  if ($slug != "" && $media_type != "") {
65
  if (isset($bp->action_variables[1])) {
66
  switch ($bp->action_variables[1]) {
67
  case 'edit':
68
- //Edit screen for image
69
  break;
70
  case 'delete':
71
  //Delete function for media file
@@ -83,11 +95,10 @@ if (class_exists('BP_Group_Extension')) :
83
  return;
84
  }
85
  if ($media_type == "album") {
86
- $bp_media_content = new BPMediaAlbumScreen($media_type, BP_MEDIA_ALBUMS_VIEW_SLUG);
87
  $bp->action_variables[0] = BP_MEDIA_ALBUMS_VIEW_SLUG;
 
88
  $bp_media_content->entry_screen();
89
  } else {
90
- $bp_media_content = new BPMediaScreen($media_type, $slug);
91
  }
92
  $bp_media_content->entry_screen_content();
93
 
@@ -99,15 +110,12 @@ if (class_exists('BP_Group_Extension')) :
99
  } else {
100
  if ($media_type == "album") {
101
  BPMediaGroupAction::bp_media_groups_albums_set_query();
102
- $bp_media_content = new BPMediaAlbumScreen($media_type, $slug);
103
  $bp_media_content->screen_content();
104
  } else if ($media_type == 'upload') {
105
  if (BPMediaGroupLoader::can_upload()) {
106
- $bp_media_upload = new BPMediaUploadScreen('upload', BP_MEDIA_UPLOAD_SLUG);
107
- $bp_media_upload->upload_screen_content();
108
  }
109
  } else {
110
- $bp_media_content = new BPMediaScreen($media_type, $slug);
111
  $bp_media_content->screen_content();
112
  }
113
  }
29
  * @throws Exception
30
  */
31
  function display() {
32
+ global $bp,$bp_media_current_entry;
33
+ //For saving the data if the form is submitted
34
+ if ( bp_action_variable(2) )
35
+ $bp_media_current_entry = new BPMediaHostWordpress(bp_action_variable(2));
36
  $current_tab = BP_MEDIA_IMAGES_SLUG;
37
  if (isset($bp->action_variables[0])) {
38
  $current_tab = $bp->action_variables[0];
64
  default:
65
  /** @todo Error is to be displayed for 404 */
66
  }
67
+ if ($media_type == "album") {
68
+ $bp_media_content = new BPMediaAlbumScreen($media_type, $slug);
69
+ } else if ($media_type == 'upload') {
70
+ if (BPMediaGroupLoader::can_upload()) {
71
+ $bp_media_content = new BPMediaUploadScreen('upload', BP_MEDIA_UPLOAD_SLUG);
72
+ }
73
+ } else {
74
+ $bp_media_content = new BPMediaScreen($media_type, $slug);
75
+ }
76
  if ($slug != "" && $media_type != "") {
77
  if (isset($bp->action_variables[1])) {
78
  switch ($bp->action_variables[1]) {
79
  case 'edit':
80
+ //$bp_media_content->edit_screen_content();
81
  break;
82
  case 'delete':
83
  //Delete function for media file
95
  return;
96
  }
97
  if ($media_type == "album") {
 
98
  $bp->action_variables[0] = BP_MEDIA_ALBUMS_VIEW_SLUG;
99
+ echo '<h3>'.get_the_title($bp->action_variables[1]).'</h3>';
100
  $bp_media_content->entry_screen();
101
  } else {
 
102
  }
103
  $bp_media_content->entry_screen_content();
104
 
110
  } else {
111
  if ($media_type == "album") {
112
  BPMediaGroupAction::bp_media_groups_albums_set_query();
 
113
  $bp_media_content->screen_content();
114
  } else if ($media_type == 'upload') {
115
  if (BPMediaGroupLoader::can_upload()) {
116
+ $bp_media_content->upload_screen_content();
 
117
  }
118
  } else {
 
119
  $bp_media_content->screen_content();
120
  }
121
  }
app/main/includes/BPMediaActions.php CHANGED
@@ -150,8 +150,8 @@ class BPMediaActions {
150
  wp_enqueue_script('jquery-ui-tabs');
151
  wp_enqueue_script('bp-media-mejs', BP_MEDIA_URL . 'lib/media-element/mediaelement-and-player.min.js', '', BP_MEDIA_VERSION);
152
  wp_enqueue_script('bp-media-default', BP_MEDIA_URL . 'app/assets/js/main.js', '', BP_MEDIA_VERSION);
153
- $lightbox = isset($bp_media->options['enable_lightbox'])?$bp_media->options['enable_lightbox']:0;
154
- if ( $lightbox )
155
  wp_enqueue_script('bp-media-modal', BP_MEDIA_URL . 'lib/simplemodal/jquery.simplemodal-1.4.4.js', '', BP_MEDIA_VERSION);
156
  $cur_group_id = NULL;
157
  if (bp_is_active("groups"))
@@ -306,7 +306,7 @@ class BPMediaActions {
306
  if ($bp_media_current_entry != NULL) {
307
 
308
  if (isset($bp_media->options['download_enabled']))
309
- $action_buttons[] = '<a href="' . admin_url('admin-ajax.php').'?action=bp_media_download&file='.$bp_media_current_entry->get_attachment_url()
310
  . '" target="_blank" class="button item-button bp-secondary-action bp-media-download" title="'
311
  . __('Download', BP_MEDIA_TXT_DOMAIN) . '">' . __('Download', BP_MEDIA_TXT_DOMAIN) . '</a>';
312
 
@@ -482,9 +482,9 @@ class BPMediaActions {
482
  wp_localize_script('bp-media-activity-uploader', 'bp_media_uploader_params', $params);
483
  wp_localize_script('bp-media-activity-uploader', 'activity_ajax_url', admin_url('admin-ajax.php'));
484
  if (bp_is_active('groups') && bp_get_current_group_id())
485
- $default_album = (string)$this->default_group_album();
486
  else
487
- $default_album = (string)$this->default_user_album();
488
  wp_localize_script('bp-media-activity-uploader', 'default_album', $default_album ? $default_album : '0');
489
  } 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))) {
490
  $params = array(
@@ -886,6 +886,14 @@ class BPMediaActions {
886
  if ($album_id) {
887
  update_user_meta($current_user_id, 'bp-media-default-album', $album_id);
888
  }
 
 
 
 
 
 
 
 
889
  }
890
  return $album_id;
891
  }
@@ -913,6 +921,14 @@ class BPMediaActions {
913
  if ($album_id) {
914
  groups_update_groupmeta($group_id, 'bp_media_default_album', $album_id);
915
  }
 
 
 
 
 
 
 
 
916
  }
917
  }
918
  }
150
  wp_enqueue_script('jquery-ui-tabs');
151
  wp_enqueue_script('bp-media-mejs', BP_MEDIA_URL . 'lib/media-element/mediaelement-and-player.min.js', '', BP_MEDIA_VERSION);
152
  wp_enqueue_script('bp-media-default', BP_MEDIA_URL . 'app/assets/js/main.js', '', BP_MEDIA_VERSION);
153
+ $lightbox = isset($bp_media->options['enable_lightbox']) ? $bp_media->options['enable_lightbox'] : 0;
154
+ if ($lightbox)
155
  wp_enqueue_script('bp-media-modal', BP_MEDIA_URL . 'lib/simplemodal/jquery.simplemodal-1.4.4.js', '', BP_MEDIA_VERSION);
156
  $cur_group_id = NULL;
157
  if (bp_is_active("groups"))
306
  if ($bp_media_current_entry != NULL) {
307
 
308
  if (isset($bp_media->options['download_enabled']))
309
+ $action_buttons[] = '<a href="' . admin_url('admin-ajax.php') . '?action=bp_media_download&file=' . $bp_media_current_entry->get_attachment_url()
310
  . '" target="_blank" class="button item-button bp-secondary-action bp-media-download" title="'
311
  . __('Download', BP_MEDIA_TXT_DOMAIN) . '">' . __('Download', BP_MEDIA_TXT_DOMAIN) . '</a>';
312
 
482
  wp_localize_script('bp-media-activity-uploader', 'bp_media_uploader_params', $params);
483
  wp_localize_script('bp-media-activity-uploader', 'activity_ajax_url', admin_url('admin-ajax.php'));
484
  if (bp_is_active('groups') && bp_get_current_group_id())
485
+ $default_album = (string) $this->default_group_album();
486
  else
487
+ $default_album = (string) $this->default_user_album();
488
  wp_localize_script('bp-media-activity-uploader', 'default_album', $default_album ? $default_album : '0');
489
  } 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))) {
490
  $params = array(
886
  if ($album_id) {
887
  update_user_meta($current_user_id, 'bp-media-default-album', $album_id);
888
  }
889
+ } else {
890
+ global $wpdb;
891
+ $exists = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE ID = $album_id");
892
+ if (!$exists) {
893
+ $bpm_host_wp = new BPMediaHostWordpress();
894
+ $album_id = $bpm_host_wp->check_and_create_album(0, 0, $current_user_id);
895
+ update_user_meta($current_user_id, 'bp-media-default-album', $album_id);
896
+ }
897
  }
898
  return $album_id;
899
  }
921
  if ($album_id) {
922
  groups_update_groupmeta($group_id, 'bp_media_default_album', $album_id);
923
  }
924
+ } else {
925
+ global $wpdb;
926
+ $exists = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE ID = $album_id");
927
+ if (!$exists) {
928
+ $bp_album = new BPMediaHostWordpress();
929
+ $album_id = $bp_album->check_and_create_album(0, bp_get_current_group_id());
930
+ groups_update_groupmeta($group_id, 'bp_media_default_album', $album_id);
931
+ }
932
  }
933
  }
934
  }
app/main/includes/BPMediaHostWordpress.php CHANGED
@@ -110,14 +110,21 @@ class BPMediaHostWordpress {
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'];
@@ -220,7 +227,7 @@ class BPMediaHostWordpress {
220
  $activity_content = false;
221
  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));
222
  }
223
- echo $attachment_id = wp_insert_attachment($attachment, $file, $post_id);
224
  if (!is_wp_error($attachment_id)) {
225
  wp_update_attachment_metadata($attachment_id, wp_generate_attachment_metadata($attachment_id, $file));
226
  } else {
@@ -231,12 +238,12 @@ class BPMediaHostWordpress {
231
  $this->name = $name;
232
  $this->description = $description;
233
  $this->type = $type;
234
- $this->owner = get_current_user_id();
235
  $this->album_id = $post_id;
236
  $this->group_id = $group;
237
  $this->set_permalinks();
238
  if ($group == 0) {
239
- update_post_meta($attachment_id, 'bp-media-key', get_current_user_id());
240
  } else {
241
  update_post_meta($attachment_id, 'bp-media-key', (-$group));
242
  }
@@ -274,7 +281,7 @@ class BPMediaHostWordpress {
274
  function get_media_activity_content() {
275
  global $bp_media_counter, $bp_media_default_excerpts, $bp_media;
276
  $attachment_id = $this->id;
277
- $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>');
278
  $activity_content .='<div class="bp_media_content">';
279
  switch ($this->type) {
280
  case 'video' :
@@ -358,13 +365,13 @@ class BPMediaHostWordpress {
358
  case 'video' :
359
  if ($this->thumbnail_id) {
360
  $image_array = image_downsize($this->thumbnail_id, 'bp_media_single_image');
361
- $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);
362
  } else {
363
- $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);
364
  }
365
  break;
366
  case 'audio' :
367
- $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);
368
  break;
369
  case 'image' :
370
  $image_array = image_downsize($this->id, 'bp_media_single_image');
@@ -971,13 +978,14 @@ class BPMediaHostWordpress {
971
  * @param type $group
972
  * @return type
973
  */
974
- function check_and_create_album($album_id, $group) {
975
  global $wpdb;
976
- $post_wall = __('Wall Posts', BP_MEDIA_TXT_DOMAIN);
 
977
  $create_new_album_flag = false;
978
  if ($album_id != 0) {
979
  $album = get_post($album_id);
980
- if ($album->post_author != get_current_user_id() && $group == 0) {
981
  $create_new_album_flag = true;
982
  } else {
983
  $post_id = $album->ID;
@@ -992,13 +1000,13 @@ class BPMediaHostWordpress {
992
  "SELECT ID
993
  FROM $wpdb->posts
994
  WHERE
995
- post_title = $post_wall
996
- AND post_author = '" . get_current_user_id() . "'
997
  AND post_type='bp_media_album'"
998
  );
999
  } else {
1000
  $post_id = $wpdb->get_var(
1001
- "SELECT wp_posts.ID
1002
  FROM $wpdb->posts
1003
  INNER JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id
1004
  AND $wpdb->postmeta.meta_key = 'bp-media-key'
@@ -1008,9 +1016,9 @@ class BPMediaHostWordpress {
1008
  if ($post_id == null) {
1009
  $album = new BPMediaAlbum();
1010
  if ($group == 0)
1011
- $album->add_album($post_wall, get_current_user_id(), $group);
1012
  else {
1013
- $album->add_album($current_user->display_name . '\'s Album', get_current_user_id(), $group);
1014
  }
1015
  $post_id = $album->get_id();
1016
  }
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, $author_id = false, $album_name = false) {
114
+ echo $this->insert_media($name, $description, $album_id, $group, $is_multiple, $is_activity, $files, $author_id, $album_name);
115
+ }
116
+
117
+ function insert_media($name, $description, $album_id = 0, $group = 0, $is_multiple = false, $is_activity = false, $files = false, $author_id = false, $album_name = false){
118
  do_action('bp_media_before_add_media');
119
 
120
  global $bp, $wpdb, $bp_media;
121
  include_once(ABSPATH . 'wp-admin/includes/file.php');
122
  include_once(ABSPATH . 'wp-admin/includes/image.php');
123
+
124
+ if ( !$author_id )
125
+ $author_id = get_current_user_id ();
126
+
127
+ $post_id = $this->check_and_create_album($album_id, $group, $author_id, $album_name);
128
 
129
  if (!$files) {
130
  $files = $_FILES['bp_media_file'];
227
  $activity_content = false;
228
  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));
229
  }
230
+ $attachment_id = wp_insert_attachment($attachment, $file, $post_id);
231
  if (!is_wp_error($attachment_id)) {
232
  wp_update_attachment_metadata($attachment_id, wp_generate_attachment_metadata($attachment_id, $file));
233
  } else {
238
  $this->name = $name;
239
  $this->description = $description;
240
  $this->type = $type;
241
+ $this->owner = $author_id;
242
  $this->album_id = $post_id;
243
  $this->group_id = $group;
244
  $this->set_permalinks();
245
  if ($group == 0) {
246
+ update_post_meta($attachment_id, 'bp-media-key', $author_id);
247
  } else {
248
  update_post_meta($attachment_id, 'bp-media-key', (-$group));
249
  }
281
  function get_media_activity_content() {
282
  global $bp_media_counter, $bp_media_default_excerpts, $bp_media;
283
  $attachment_id = $this->id;
284
+ $activity_content = apply_filters('bp_media_single_activity_title', '<div class="bp_media_title"><a href="' . $this->url . '" title="' . __($this->name, BP_MEDIA_TXT_DOMAIN) . '">' . __(wp_html_excerpt($this->name, $bp_media_default_excerpts['activity_entry_title']), BP_MEDIA_TXT_DOMAIN) . '</a></div>');
285
  $activity_content .='<div class="bp_media_content">';
286
  switch ($this->type) {
287
  case 'video' :
365
  case 'video' :
366
  if ($this->thumbnail_id) {
367
  $image_array = image_downsize($this->thumbnail_id, 'bp_media_single_image');
368
+ $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>', $this);
369
  } else {
370
+ $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>', $this);
371
  }
372
  break;
373
  case 'audio' :
374
+ $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>', $this);
375
  break;
376
  case 'image' :
377
  $image_array = image_downsize($this->id, 'bp_media_single_image');
978
  * @param type $group
979
  * @return type
980
  */
981
+ function check_and_create_album($album_id, $group, $author_id = false, $album_name = false) {
982
  global $wpdb;
983
+ if (!$album_name)
984
+ $album_name = __('Wall Posts', BP_MEDIA_TXT_DOMAIN);
985
  $create_new_album_flag = false;
986
  if ($album_id != 0) {
987
  $album = get_post($album_id);
988
+ if ($album->post_author != $author_id && $group == 0) {
989
  $create_new_album_flag = true;
990
  } else {
991
  $post_id = $album->ID;
1000
  "SELECT ID
1001
  FROM $wpdb->posts
1002
  WHERE
1003
+ post_title = '$album_name'
1004
+ AND post_author = '" . $author_id . "'
1005
  AND post_type='bp_media_album'"
1006
  );
1007
  } else {
1008
  $post_id = $wpdb->get_var(
1009
+ "SELECT $wpdb->posts.ID
1010
  FROM $wpdb->posts
1011
  INNER JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id
1012
  AND $wpdb->postmeta.meta_key = 'bp-media-key'
1016
  if ($post_id == null) {
1017
  $album = new BPMediaAlbum();
1018
  if ($group == 0)
1019
+ $album->add_album($album_name, $author_id, $group);
1020
  else {
1021
+ $album->add_album($current_user->display_name . '\'s Album', $author_id, $group);
1022
  }
1023
  $post_id = $album->get_id();
1024
  }
app/main/profile/BPMediaAlbumScreen.php CHANGED
@@ -42,7 +42,11 @@ class BPMediaAlbumScreen extends BPMediaScreen {
42
  if (!isset($bp->action_variables[1])) {
43
  $this->page_not_exist();
44
  }
45
- $this->entry_delete();
 
 
 
 
46
  break;
47
  default:
48
  $this->set_query();
@@ -133,7 +137,9 @@ class BPMediaAlbumScreen extends BPMediaScreen {
133
  if ($allowed_edit != false) {
134
  echo '<div class="album-edit">';
135
  echo '<a href="' . $bp_media_current_album->get_edit_url() . '" class="button item-button bp-secondary-action bp-media-edit bp-media-edit-album" title="' . __('Edit Album', BP_MEDIA_TXT_DOMAIN) . '">' . __('Edit', BP_MEDIA_TXT_DOMAIN) . '</a>';
136
- echo '<a href="' . $bp_media_current_album->get_delete_url() . '" class="button item-button bp-secondary-action delete-activity-single confirm" rel="nofollow">' . __("Delete", BP_MEDIA_TXT_DOMAIN) . '</a>';
 
 
137
  echo '</div>';
138
  }
139
  }
42
  if (!isset($bp->action_variables[1])) {
43
  $this->page_not_exist();
44
  }
45
+ $media_actions = new BPMediaActions();
46
+ if ( $media_actions->default_user_album() != $bp->action_variables[1])
47
+ $this->entry_delete();
48
+ else
49
+ $this->page_not_exist();
50
  break;
51
  default:
52
  $this->set_query();
137
  if ($allowed_edit != false) {
138
  echo '<div class="album-edit">';
139
  echo '<a href="' . $bp_media_current_album->get_edit_url() . '" class="button item-button bp-secondary-action bp-media-edit bp-media-edit-album" title="' . __('Edit Album', BP_MEDIA_TXT_DOMAIN) . '">' . __('Edit', BP_MEDIA_TXT_DOMAIN) . '</a>';
140
+ $media_actions = new BPMediaActions();
141
+ if ( $media_actions->default_user_album() != $bp_media_current_album->get_id())
142
+ echo '<a href="' . $bp_media_current_album->get_delete_url() . '" class="button item-button bp-secondary-action delete-activity-single confirm" rel="nofollow">' . __("Delete", BP_MEDIA_TXT_DOMAIN) . '</a>';
143
  echo '</div>';
144
  }
145
  }
app/main/profile/BPMediaScreen.php CHANGED
@@ -108,7 +108,7 @@ class BPMediaScreen {
108
  *
109
  * @global type $bp_media
110
  */
111
- private function page_not_exist() {
112
  @setcookie('bp-message', __('The requested url does not exist', BP_MEDIA_TXT_DOMAIN), time() + 60 * 60 * 24, COOKIEPATH);
113
  @setcookie('bp-message-type', 'error', time() + 60 * 60 * 24, COOKIEPATH);
114
  $this->template->redirect($this->media_const);
108
  *
109
  * @global type $bp_media
110
  */
111
+ public function page_not_exist() {
112
  @setcookie('bp-message', __('The requested url does not exist', BP_MEDIA_TXT_DOMAIN), time() + 60 * 60 * 24, COOKIEPATH);
113
  @setcookie('bp-message-type', 'error', time() + 60 * 60 * 24, COOKIEPATH);
114
  $this->template->redirect($this->media_const);
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.6
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.8
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.6
10
 
11
  Adds Photos, Music, Videos & Albums to BuddyPress. Supports mobile devices (iPhone/iPad, etc) and automatic audio/video conversion.
12
 
@@ -122,6 +122,11 @@ Please visit [BuddyPress Media's Features page](http://rtcamp.com/buddypress-med
122
 
123
  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.
124
 
 
 
 
 
 
125
  = 2.7.6 =
126
  * Fixes errors due to absence of EXIF
127
  * Fixes duplicate comment box on lightbox
@@ -348,5 +353,5 @@ Please visit [BuddyPress Media's Roadmap page](http://rtcamp.com/buddypress-medi
348
  * HTML5 Video Tag Support (with fallback)
349
 
350
  == Upgrade Notice ==
351
- = 2.7.6 =
352
- Fixes bugs and improves activity uploader
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.8
10
 
11
  Adds Photos, Music, Videos & Albums to BuddyPress. Supports mobile devices (iPhone/iPad, etc) and automatic audio/video conversion.
12
 
122
 
123
  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.
124
 
125
+ = 2.8 =
126
+ * Adds importer for BP Album
127
+ * Tested with [reallifescrapped](http://reallifescrapped), an aswesome social network for scrapbookers by [Meg](http://profiles.wordpress.org/oceanwidedesigns)
128
+ * Other minor bug fixes, especially for Groups
129
+
130
  = 2.7.6 =
131
  * Fixes errors due to absence of EXIF
132
  * Fixes duplicate comment box on lightbox
353
  * HTML5 Video Tag Support (with fallback)
354
 
355
  == Upgrade Notice ==
356
+ = 2.8 =
357
+ BP-Media Importer added