rtMedia for WordPress, BuddyPress and bbPress - Version 3.6.10

Version Description

  • Update German and Swedish translations
  • JS fix for WordPress 3.9 Beta
  • Bug fixes
Download this release

Release Info

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

Code changes from version 3.6.9 to 3.6.10

app/admin/RTMediaAdmin.php CHANGED
@@ -91,6 +91,7 @@ if ( ! class_exists ( 'RTMediaAdmin' ) ) {
91
add_action ( 'admin_init', array( $this, 'rtmedia_bp_add_update_type' ) );
92
add_action ( 'admin_notices', array( $this, 'rtmedia_inspirebook_release_notice' ) );
93
add_action ( 'wp_ajax_rtmedia_hide_inspirebook_release_notice', array( $this, 'rtmedia_hide_inspirebook_release_notice' ), 1 );
94
}
95
96
function rtmedia_inspirebook_release_notice() {
91
add_action ( 'admin_init', array( $this, 'rtmedia_bp_add_update_type' ) );
92
add_action ( 'admin_notices', array( $this, 'rtmedia_inspirebook_release_notice' ) );
93
add_action ( 'wp_ajax_rtmedia_hide_inspirebook_release_notice', array( $this, 'rtmedia_hide_inspirebook_release_notice' ), 1 );
94
+ $rtmedia_media_import = new RTMediaMediaSizeImporter(); // do not delete this line. We only need to create object of this class if we are in admin section
95
}
96
97
function rtmedia_inspirebook_release_notice() {
app/admin/RTMediaFormHandler.php CHANGED
@@ -448,7 +448,10 @@ class RTMediaFormHandler {
448
$render_data = self::types_render_options($options);
449
?>
450
<div class="postbox metabox-holder">
451
- <h3 class="hndle"><span>Media Types Settings</span></h3>
452
</div>
453
<div class="rt-table large-12">
454
<div class="row rt-header">
@@ -470,7 +473,7 @@ class RTMediaFormHandler {
470
else {
471
echo '<div class="row rt-even">';
472
}
473
- echo '<div class="row">';
474
do_action("rtmedia_type_settings_before_body");
475
echo '<div class="columns large-4">' . $section['name'] . '</div>';
476
$args = array('key' => 'allowedTypes_'.$key.'_enabled', 'value' => $section['enabled']);
@@ -496,7 +499,7 @@ class RTMediaFormHandler {
496
echo '<label class="columns large-3">'.__("File Extensions","rtmedia").':</label>';
497
echo '<label class="columns large-9 rtmedia_type_settings_filter_extension">' . $extensions . '</label>';
498
echo '</div>';
499
- echo '</div>';
500
} else {
501
echo "<input type='hidden' value='1' name='rtmedia-options[allowedTypes_" . $key . "_enabled]'>";
502
echo "<input type='hidden' value='0' name='rtmedia-options[allowedTypes_" . $key . "_featured]'>";
@@ -877,7 +880,7 @@ class RTMediaFormHandler {
877
if( $i == 1){ $active_class = 'active';} $i++;
878
if ( isset ( $tab[ 'icon' ] ) && ! empty ( $tab[ 'icon' ] ) )
879
$icon = '<i class="' . $tab[ 'icon' ] . '"></i>';
880
- echo '<dd class="' . $active_class . '"><a id="tab-' . substr ( $tab[ 'href' ], 1 ) . '" title="' . $tab[ 'title' ] . '" href="' . $tab[ 'href' ] . '" class="rtmedia-tab-title ' . sanitize_title ( $tab[ 'name' ] ) . '">' . $icon . ' ' . $tab[ 'name' ] . '</a></dd>';
881
}
882
echo "</dl>";
883
?>
448
$render_data = self::types_render_options($options);
449
?>
450
<div class="postbox metabox-holder">
451
+ <h3 class="hndle">
452
+ <span>Media Types Settings</span>
453
+ <?php do_action( 'rtmedia_media_type_setting_message' ); ?>
454
+ </h3>
455
</div>
456
<div class="rt-table large-12">
457
<div class="row rt-header">
473
else {
474
echo '<div class="row rt-even">';
475
}
476
+
477
do_action("rtmedia_type_settings_before_body");
478
echo '<div class="columns large-4">' . $section['name'] . '</div>';
479
$args = array('key' => 'allowedTypes_'.$key.'_enabled', 'value' => $section['enabled']);
499
echo '<label class="columns large-3">'.__("File Extensions","rtmedia").':</label>';
500
echo '<label class="columns large-9 rtmedia_type_settings_filter_extension">' . $extensions . '</label>';
501
echo '</div>';
502
+
503
} else {
504
echo "<input type='hidden' value='1' name='rtmedia-options[allowedTypes_" . $key . "_enabled]'>";
505
echo "<input type='hidden' value='0' name='rtmedia-options[allowedTypes_" . $key . "_featured]'>";
880
if( $i == 1){ $active_class = 'active';} $i++;
881
if ( isset ( $tab[ 'icon' ] ) && ! empty ( $tab[ 'icon' ] ) )
882
$icon = '<i class="' . $tab[ 'icon' ] . '"></i>';
883
+ echo '<dd class="' . $active_class . '"><a id="tab-' . substr ( $tab[ 'href' ], 1 ) . '" title="' . $tab[ 'title' ] . '" href="' . $tab[ 'href' ] . '" class="rtmedia-tab-title ' . sanitize_title ( $tab[ 'name' ] ) . '">' . $icon . $tab[ 'name' ] . '</a></dd>';
884
}
885
echo "</dl>";
886
?>
app/assets/css/admin.css CHANGED
@@ -589,8 +589,6 @@ float:left;
589
border-bottom-color: #F3F3F3;
590
border-bottom-width: 1px;
591
border-bottom-style: solid;
592
- margin-bottom: 5px !important;
593
- padding-bottom: 5px !important;
594
}
595
/* line 39, ../sass/admin.scss */
596
.rt-table div.rt-header h4 {
@@ -684,7 +682,7 @@ abbr {
684
685
.bp-media-admin .premium-page-container .rtm-premium-icon-pro {
686
margin-top: 9px;
687
- width: 40px;
688
}
689
#TB_window #rtmedia-addon-add-container #rtmedia-flat-50-message, #TB_window #rtmedia-addon-add-container #rtmedia-flat-50-link,#TB_window #rtmedia-addon-add-container #rtmedia-flat-50-code {
690
text-align: center;
589
border-bottom-color: #F3F3F3;
590
border-bottom-width: 1px;
591
border-bottom-style: solid;
592
}
593
/* line 39, ../sass/admin.scss */
594
.rt-table div.rt-header h4 {
682
683
.bp-media-admin .premium-page-container .rtm-premium-icon-pro {
684
margin-top: 9px;
685
+ min-width: 50px;
686
}
687
#TB_window #rtmedia-addon-add-container #rtmedia-flat-50-message, #TB_window #rtmedia-addon-add-container #rtmedia-flat-50-link,#TB_window #rtmedia-addon-add-container #rtmedia-flat-50-code {
688
text-align: center;
app/assets/js/rtMedia.backbone.js CHANGED
@@ -3,19 +3,19 @@ var nextpage = 2;
3
var upload_sync = false;
4
var activity_id = -1;
5
var uploaderObj;
6
- var objUploadView ;
7
var rtmedia_load_template_flag = true;
8
9
- jQuery(function($) {
10
11
var o_is_album, o_is_edit_allowed;
12
- if (typeof(is_album) == "undefined") {
13
- o_is_album = new Array("");
14
} else {
15
o_is_album = is_album
16
}
17
- if (typeof(is_edit_allowed) == "undefined") {
18
- o_is_edit_allowed = new Array("")
19
} else {
20
o_is_edit_allowed = is_edit_allowed;
21
}
@@ -24,10 +24,10 @@ jQuery(function($) {
24
25
rtMedia = window.rtMedia || {};
26
27
- rtMedia.Context = Backbone.Model.extend({
28
- url: function() {
29
var url = rtmedia_media_slug + "/";
30
- if (!upload_sync && nextpage > 0)
31
url += 'pg/' + nextpage + '/'
32
return url;
33
},
@@ -35,9 +35,9 @@ jQuery(function($) {
35
"context": "post",
36
"context_id": false
37
}
38
- });
39
40
- rtMedia.Media = Backbone.Model.extend({
41
defaults: {
42
"id": 0,
43
"blog_id": false,
@@ -59,248 +59,255 @@ jQuery(function($) {
59
"width": 0,
60
"height": 0,
61
"rt_permalink": false
62
- // "next" : -1,
63
- // "prev" : -1
64
}
65
66
- });
67
68
- rtMedia.Gallery = Backbone.Collection.extend({
69
model: rtMedia.Media,
70
- url: function() {
71
var temp = window.location.pathname;
72
var url = '';
73
- if (temp.indexOf("/" + rtmedia_media_slug + "/") == -1) {
74
url = rtmedia_media_slug + '/';
75
} else {
76
- if (temp.indexOf('pg/') == -1)
77
url = temp;
78
else
79
- url = window.location.pathname.substr(0, window.location.pathname.lastIndexOf("pg/"));
80
}
81
- if (!upload_sync && nextpage > 1) {
82
- if (url.substr(url.length - 1) != "/")
83
url += "/"
84
url += 'pg/' + nextpage + '/';
85
}
86
return url;
87
},
88
- getNext: function(page, el, element) {
89
- that = this;
90
- if( rtmedia_load_template_flag == true ) {
91
- $("#rtmedia-gallery-item-template").load(template_url, {
92
- backbone: true,
93
- is_album: o_is_album,
94
- is_edit_allowed: o_is_edit_allowed
95
- },function(){
96
- rtmedia_load_template_flag = false;
97
- that.getNext();
98
- });
99
- }
100
- if( !rtmedia_load_template_flag ) {
101
- var query = {
102
- json: true,
103
- rtmedia_page: nextpage
104
- };
105
- if (el == undefined){
106
- el = jQuery(".rtmedia-list").parent().parent();
107
- }
108
- if (el != undefined) {
109
- if(element != undefined) {
110
- $(element).parent().parent().prevAll("input[type=hidden]").each(function(e) {
111
- query[$(this).attr("name")] = $(this).val();
112
- });
113
- } else {
114
- $(el).find("input[type=hidden]").each(function(e) {
115
- query[$(this).attr("name")] = $(this).val();
116
- });
117
- }
118
-
119
- }
120
- this.fetch({
121
- data: query,
122
- success: function(model, response) {
123
- jQuery('.rtm-media-loading').hide();
124
- var list_el = "";
125
- if(typeof(element) === "undefined" )
126
- list_el = $(".rtmedia-list")[0];
127
- else
128
- list_el = element.parent().siblings('.rtmedia-list');
129
- nextpage = response.next;
130
- var galleryViewObj = new rtMedia.GalleryView({
131
- collection: new rtMedia.Gallery(response.data),
132
- el: list_el
133
- });
134
- //element.show();
135
- }
136
- });
137
- }
138
},
139
- reloadView: function() {
140
upload_sync = true;
141
nextpage = 1;
142
this.getNext();
143
}
144
145
146
- });
147
148
- rtMedia.MediaView = Backbone.View.extend({
149
tagName: 'li',
150
className: 'rtmedia-list-item',
151
- initialize: function() {
152
- this.template = _.template($("#rtmedia-gallery-item-template").html());
153
- this.model.bind('change', this.render);
154
- this.model.bind('remove', this.unrender);
155
this.render();
156
},
157
- render: function() {
158
- $(this.el).html(this.template(this.model.toJSON()));
159
return this.el;
160
},
161
- unrender: function() {
162
- $(this.el).remove();
163
},
164
- remove: function() {
165
this.model.destroy();
166
}
167
- });
168
169
- rtMedia.GalleryView = Backbone.View.extend({
170
tagName: 'ul',
171
className: 'rtmedia-list',
172
- initialize: function() {
173
- this.template = _.template($("#rtmedia-gallery-item-template").html());
174
this.render();
175
},
176
- render: function() {
177
178
that = this;
179
180
- if (upload_sync) {
181
- $(that.el).html('');
182
}
183
184
- $.each(this.collection.toJSON(), function(key, media) {
185
- $(that.el).append(that.template(media));
186
- });
187
- if (upload_sync) {
188
upload_sync = false;
189
}
190
- if (nextpage > 1) {
191
- $(that.el).siblings('.rtmedia_next_prev').children('#rtMedia-galary-next').show();
192
- //$("#rtMedia-galary-next").show();
193
}
194
195
196
},
197
- appendTo: function(media) {
198
//console.log("append");
199
- var mediaView = new rtMedia.MediaView({
200
model: media
201
- });
202
- $(this.el).append(mediaView.render().el);
203
}
204
- });
205
206
207
galleryObj = new rtMedia.Gallery();
208
209
- $("body").append('<script id="rtmedia-gallery-item-template" type="text/template"></script>');
210
211
- $(document).on("click", "#rtMedia-galary-next", function(e) {
212
$( this ).before( "<div class='rtm-media-loading'><img src='" + rMedia_loading_media + "' /></div>" );
213
- $(this).hide();
214
- e.preventDefault();
215
- galleryObj.getNext(nextpage, $(this).parent().parent().parent(), $(this));
216
- });
217
-
218
-
219
220
221
- if (window.location.pathname.indexOf(rtmedia_media_slug) != -1) {
222
- var tempNext = window.location.pathname.substring(window.location.pathname.lastIndexOf("pg/") + 5, window.location.pathname.lastIndexOf("/"));
223
- if (isNaN(tempNext) === false) {
224
- nextpage = parseInt(tempNext) + 1;
225
}
226
}
227
228
229
-
230
- window.UploadView = Backbone.View.extend({
231
events: {
232
"click #rtMedia-start-upload": "uploadFiles"
233
},
234
- initialize: function(config) {
235
- this.uploader = new plupload.Uploader(config);
236
},
237
- render: function() {
238
239
},
240
- initUploader: function(a) {
241
-
242
- if(typeof(a)!=="undefined") a=false;// if rtmediapro widget calls the function, dont show max size note.
243
this.uploader.init();
244
//The plupload HTML5 code gives a negative z-index making add files button unclickable
245
- $(".plupload.html5").css({
246
zIndex: 0
247
- });
248
- $("#rtMedia-upload-button").css({
249
zIndex: 2
250
- });
251
- if(a!==false){
252
- window.file_size_info = rtmedia_max_file_msg + " : " + this.uploader.settings.max_file_size_msg ;
253
- window.file_extn_info = rtmedia_allowed_file_formats + " : " + this.uploader.settings.filters[0].extensions;
254
var info = window.file_size_info + ", " + window.file_extn_info;
255
- $(".rtm-file-size-limit").attr('title', info);
256
- //$("#rtMedia-upload-button").after("<span>( <strong>" + rtmedia_max_file_msg + "</strong> "+ this.uploader.settings.max_file_size_msg + ")</span>");
257
}
258
259
return this;
260
},
261
- uploadFiles: function(e) {
262
- if (e != undefined)
263
e.preventDefault();
264
this.uploader.start();
265
return false;
266
}
267
268
- });
269
-
270
271
272
- if ($("#rtMedia-upload-button").length > 0) {
273
- if( typeof rtmedia_upload_type_filter == "object" && rtmedia_upload_type_filter.length > 0 ) {
274
- rtMedia_plupload_config.filters[0].extensions = rtmedia_upload_type_filter.join();
275
- }
276
- uploaderObj = new UploadView(rtMedia_plupload_config);
277
278
uploaderObj.initUploader();
279
280
281
- uploaderObj.uploader.bind('UploadComplete', function(up, files) {
282
- activity_id = -1;
283
- if( typeof rtmedia_gallery_reload_on_upload != "undefined" && rtmedia_gallery_reload_on_upload =='1'){ //reload gallery view when upload completes if enabled( by default enabled)
284
galleryObj.reloadView();
285
}
286
- jQuery('.start-media-upload').hide();
287
- });
288
289
- uploaderObj.uploader.bind('FilesAdded', function(up, files) {
290
var upload_size_error = false;
291
var upload_error = "";
292
var upload_error_sep = "";
293
- var upload_remove_array= [];
294
- $.each(files, function(i, file) {
295
- var hook_respo = rtMediaHook.call('rtmedia_js_file_added', [up,file, "#rtMedia-queue-list tbody"]);
296
- if( hook_respo == false){
297
file.status = -1;
298
- upload_remove_array.push(file.id);
299
return true;
300
}
301
- jQuery('.rtmedia-upload-input').attr('value', rtmedia_add_more_files_msg);
302
- jQuery('.start-media-upload').show();
303
- if (uploaderObj.uploader.settings.max_file_size < file.size) {
304
// upload_size_error = true
305
// upload_error += upload_error_sep + file.name;
306
// upload_error_sep = ",";
@@ -308,219 +315,228 @@ jQuery(function($) {
308
// $("#rtMedia-queue-list tbody").append(tr);
309
return true;
310
}
311
- var tmp_array = file.name.split(".");
312
- var ext_array = uploaderObj.uploader.settings.filters[0].extensions.split(',');
313
- if(tmp_array.length > 1){
314
- var ext= tmp_array[tmp_array.length - 1];
315
- ext = ext.toLowerCase();
316
- if( jQuery.inArray( ext ,ext_array) === -1){
317
return true;
318
}
319
- }else{
320
return true;
321
}
322
323
- uploaderObj.uploader.settings.filters[0].title;
324
- tdName = document.createElement("td");
325
- tdName.innerHTML = file.name;
326
tdName.className = "plupload_file_name";
327
- tdStatus = document.createElement("td");
328
tdStatus.className = "plupload_file_status";
329
tdStatus.innerHTML = rtmedia_waiting_msg;
330
- tdSize = document.createElement("td");
331
tdSize.className = "plupload_file_size";
332
- tdSize.innerHTML = plupload.formatSize(file.size);
333
- tdDelete = document.createElement("td");
334
tdDelete.innerHTML = "<span class='remove-from-queue'>&times;</span>";
335
tdDelete.title = rtmedia_close;
336
tdDelete.className = "close plupload_delete";
337
- tdEdit = document.createElement("td");
338
tdEdit.innerHTML = "";
339
tdEdit.className = "plupload_media_edit";
340
- tr = document.createElement("tr");
341
tr.className = 'upload-waiting';
342
tr.id = file.id;
343
- tr.appendChild(tdName);
344
- tr.appendChild(tdStatus);
345
- tr.appendChild(tdSize);
346
- tr.appendChild(tdEdit);
347
- tr.appendChild(tdDelete);
348
- $("#rtMedia-queue-list").append(tr);
349
//Delete Function
350
- $("#" + file.id + " td.plupload_delete .remove-from-queue").click(function(e) {
351
e.preventDefault();
352
- uploaderObj.uploader.removeFile(up.getFile(file.id));
353
- $("#" + file.id).remove();
354
return false;
355
- });
356
357
- });
358
- $.each(upload_remove_array, function(i, rfile) {
359
- if(up.getFile(rfile))
360
- up.removeFile(up.getFile(rfile));
361
- });
362
363
// if (upload_size_error) {
364
// // alert(upload_error + " because max file size is " + plupload.formatSize(uploaderObj.uploader.settings.max_file_size) );
365
// }
366
- });
367
368
- uploaderObj.uploader.bind('Error', function(up, err) {
369
370
- if(err.code== -600){ //file size error // if file size is greater than server's max allowed size
371
var tmp_array;
372
var ext = tr = '';
373
- tmp_array = err.file.name.split(".");
374
- if(tmp_array.length > 1){
375
- ext= tmp_array[tmp_array.length - 1];
376
- if( !(typeof(up.settings.upload_size) != "undefined" && typeof(up.settings.upload_size[ext]) != "undefined" && typeof(up.settings.upload_size[ext]['size']) )){
377
- tr = "<tr class='upload-error'><td>" + err.file.name + "</td><td> " + rtmedia_max_file_msg + plupload.formatSize( up.settings.max_file_size / 1024 * 1024) + " <i class='rtmicon-info-circle' title='" + window.file_size_info + "'></i></td><td>" + plupload.formatSize(err.file.size) + "</td><td></td><td class='close error_delete'>&times;</td></tr>";
378
}
379
}
380
//append the message to the file queue
381
- $("#rtMedia-queue-list tbody").append(tr);
382
}
383
else {
384
385
- if( err.code == -601) { // file extension error
386
err.message = rtmedia_file_extension_error_msg;
387
}
388
- var tr = "<tr class='upload-error'><td>" + (err.file ? err.file.name : "") + "</td><td>" + err.message + " <i class='rtmicon-info-circle' title='" + window.file_extn_info + "'></i></td><td>" + plupload.formatSize(err.file.size) + "</td><td></td><td class='close error_delete'>&times;</td></tr>";
389
- $("#rtMedia-queue-list tbody").append(tr);
390
}
391
392
- jQuery('.error_delete').on('click',function(e){
393
e.preventDefault();
394
- jQuery(this).parent('tr').remove();
395
- });
396
return false;
397
398
- });
399
400
- jQuery('.start-media-upload').on('click', function(e){
401
e.preventDefault();
402
uploaderObj.uploadFiles();
403
- });
404
405
- uploaderObj.uploader.bind('QueueChanged', function(up) {
406
407
// jQuery('.rtmedia-upload-input').attr('value','Add more files');
408
// jQuery('.start-media-upload').show();
409
410
- });
411
412
- uploaderObj.uploader.bind('UploadProgress', function(up, file) {
413
//$("#" + file.id + " .plupload_file_status").html(file.percent + "%");
414
- $("#" + file.id + " .plupload_file_status").html( rtmedia_uploading_msg + '( ' + file.percent + '% )');
415
- $("#" + file.id).addClass('upload-progress');
416
- if (file.percent == 100) {
417
- $("#" + file.id).toggleClass('upload-success');
418
- }
419
- });
420
- uploaderObj.uploader.bind('BeforeUpload', function(up, file) {
421
- var privacy = $("#rtm-file_upload-ui select.privacy").val();
422
- if(privacy !== undefined) {
423
- up.settings.multipart_params.privacy = $("#rtm-file_upload-ui select.privacy").val();
424
- }
425
- if (jQuery("#rt_upload_hf_redirect").length > 0)
426
up.settings.multipart_params.redirect = up.files.length;
427
- jQuery("#rtmedia-uploader-form input[type=hidden]").each(function() {
428
- up.settings.multipart_params[$(this).attr("name")] = $(this).val();
429
- });
430
up.settings.multipart_params.activity_id = activity_id;
431
- if ($('#rtmedia-uploader-form .rtmedia-user-album-list').length > 0)
432
- up.settings.multipart_params.album_id = $('#rtmedia-uploader-form .rtmedia-user-album-list').find(":selected").val();
433
- else if ($('#rtmedia-uploader-form .rtmedia-current-album').length > 0)
434
- up.settings.multipart_params.album_id = $('#rtmedia-uploader-form .rtmedia-current-album').val();
435
- });
436
-
437
- uploaderObj.uploader.bind('FileUploaded', function(up, file, res) {
438
- if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
439
- var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
440
-
441
- if(ieversion <10) {
442
- if( typeof res.response !== "undefined" )
443
- res.status = 200;
444
- }
445
}
446
var rtnObj;
447
- try {
448
449
- rtnObj = JSON.parse(res.response);
450
uploaderObj.uploader.settings.multipart_params.activity_id = rtnObj.activity_id;
451
activity_id = rtnObj.activity_id;
452
- if(rtnObj.permalink != ''){
453
- $("#" + file.id + " .plupload_file_name").html("<a href='" + rtnObj.permalink + "' target='_blank' title='" + rtnObj.permalink + "'>" + file.name + "</a>");
454
- $("#" + file.id + " .plupload_media_edit").html("<a href='" + rtnObj.permalink + "edit' target='_blank'><span title='" + rtmedia_edit_media + "'><i class='rtmicon-edit'></i> " + rtmedia_edit + "</span></a>");
455
- $("#" + file.id + " .plupload_delete").html("<span id='" + rtnObj.media_id + "' class='rtmedia-delete-uploaded-media' title='" + rtmedia_delete + "'>&times;</span>");
456
}
457
458
- } catch (e) {
459
// console.log('Invalid Activity ID');
460
}
461
- if (res.status == 200 || res.status == 302) {
462
- if (uploaderObj.upload_count == undefined)
463
uploaderObj.upload_count = 1;
464
else
465
uploaderObj.upload_count++;
466
467
- if (uploaderObj.upload_count == up.files.length && jQuery("#rt_upload_hf_redirect").length > 0 && jQuery.trim(rtnObj.redirect_url.indexOf("http") == 0)) {
468
window.location = rtnObj.redirect_url;
469
}
470
471
- $("#" + file.id + " .plupload_file_status").html( rtmedia_uploaded_msg);
472
-
473
- }else {
474
- $("#" + file.id + " .plupload_file_status").html( rtmedia_upload_failed_msg );
475
}
476
477
files = up.files;
478
lastfile = files[files.length - 1];
479
480
481
- });
482
483
uploaderObj.uploader.refresh();//refresh the uploader for opera/IE fix on media page
484
485
- $("#rtMedia-start-upload").click(function(e) {
486
- uploaderObj.uploadFiles(e);
487
- });
488
- $("#rtMedia-start-upload").hide();
489
490
- jQuery(document).on('click', '#rtm_show_upload_ui', function(){
491
- jQuery('#rtm-media-gallery-uploader').slideToggle();
492
uploaderObj.uploader.refresh();//refresh the uploader for opera/IE fix on media page
493
- jQuery('#rtm_show_upload_ui').toggleClass('primary');
494
- });
495
} else {
496
- jQuery(document).on('click', '#rtm_show_upload_ui', function(){
497
- jQuery('#rtm-media-gallery-uploader').slideToggle();
498
- jQuery('#rtm_show_upload_ui').toggleClass('primary');
499
- });
500
}
501
502
- jQuery(document).on( 'click','.plupload_delete .rtmedia-delete-uploaded-media',function(){
503
- var that = $(this);
504
- if(confirm(rtmedia_delete_uploaded_media)){
505
- var nonce = $('#rtmedia-upload-container #rtmedia_media_delete_nonce').val();
506
- var media_id = $(this).attr('id');
507
var data = {
508
- action : 'delete_uploaded_media',
509
- nonce : nonce,
510
- media_id : media_id
511
}
512
513
- $.post( ajaxurl, data, function(response){
514
- if(response == '1'){
515
- that.closest('tr').remove();
516
- $('#'+media_id).remove();
517
}
518
- });
519
}
520
- });
521
522
523
- });
524
/** History Code for route
525
526
var rtMediaRouter = Backbone.Router.extend({
@@ -539,180 +555,190 @@ jQuery(function($) {
539
540
/** Activity Update Js **/
541
542
- jQuery(document).ready(function($) {
543
544
//handling the "post update: button on activity page
545
- jQuery('#aw-whats-new-submit').removeAttr('disabled');
546
- jQuery(document).on( "blur",'#whats-new', function(){
547
- setTimeout(function(){ jQuery('#aw-whats-new-submit').removeAttr('disabled'); },100);
548
- });
549
- jQuery('#aw-whats-new-submit').on('click', function(e){
550
- setTimeout(function(){ jQuery('#aw-whats-new-submit').removeAttr('disabled'); },100);
551
- });
552
553
// when user changes the value in activity "post in" dropdown, hide the privacy dropdown and show when posting in profile.
554
- jQuery('#whats-new-post-in').on('change', function(e){
555
- if( jQuery(this).val() == '0' ){
556
- jQuery("#rtmedia-action-update .privacy").prop('disabled',false).show();
557
- }else{
558
- jQuery("#rtmedia-action-update .privacy").prop('disabled',true).hide();
559
}
560
- });
561
562
- if (typeof rtMedia_update_plupload_config == 'undefined') {
563
return false;
564
}
565
var activity_attachemnt_ids = [];
566
- if ($("#rtmedia-add-media-button-post-update").length > 0) {
567
- $("#whats-new-options").prepend($("#rtmedia-action-update"));
568
- if ($("#rtm-file_upload-ui .privacy").length > 0) {
569
- $("#rtmedia-action-update").append($("#rtm-file_upload-ui .privacy"));
570
}
571
}
572
- objUploadView = new UploadView(rtMedia_update_plupload_config);
573
- $("#whats-new-form").on('click', '#rtmedia-add-media-button-post-update', function(e) {
574
objUploadView.uploader.refresh();
575
- });
576
//whats-new-post-in
577
578
objUploadView.upload_remove_array = [];
579
- objUploadView.uploader.bind('FilesAdded', function(upl, rfiles) {
580
//$("#aw-whats-new-submit").attr('disabled', 'disabled');
581
582
- $.each(rfiles, function(i, file) {
583
- var hook_respo = rtMediaHook.call('rtmedia_js_file_added', [upl,file, "#rtMedia-queue-list tbody"]);
584
- if( hook_respo == false){
585
- file.status = -1;
586
- objUploadView.upload_remove_array.push(file.id);
587
- return true;
588
}
589
- if (objUploadView.uploader.settings.max_file_size < file.size) {
590
return true;
591
}
592
- var tmp_array = file.name.split(".");
593
- var ext_array = objUploadView.uploader.settings.filters[0].extensions.split(',');
594
- if(tmp_array.length > 1){
595
- var ext= tmp_array[tmp_array.length - 1];
596
- ext = ext.toLowerCase();
597
- if( jQuery.inArray( ext ,ext_array) === -1){
598
return true;
599
}
600
- }else{
601
return true;
602
}
603
- tdName = document.createElement("td");
604
- tdName.innerHTML = file.name;
605
- tdStatus = document.createElement("td");
606
tdStatus.className = "plupload_file_status";
607
tdStatus.innerHTML = rtmedia_waiting_msg;
608
- tdSize = document.createElement("td");
609
tdSize.className = "plupload_file_size";
610
- tdSize.innerHTML = plupload.formatSize(file.size);
611
- tdDelete = document.createElement("td");
612
tdDelete.innerHTML = "&times;";
613
tdDelete.title = rtmedia_remove_from_queue;
614
tdDelete.className = "close plupload_delete";
615
- tdEdit = document.createElement("td");
616
tdEdit.innerHTML = "";
617
- tr = document.createElement("tr");
618
tr.className = 'upload-waiting';
619
tr.id = file.id;
620
- tr.appendChild(tdName);
621
- tr.appendChild(tdStatus);
622
- tr.appendChild(tdSize);
623
- tr.appendChild(tdEdit);
624
- tr.appendChild(tdDelete);
625
- jQuery('#whats-new-content').css('padding-bottom','0px');
626
- $("#rtm-upload-start-notice").css('display','block'); // show the file upload notice to the user
627
- $("#rtMedia-queue-list").append(tr);
628
- $("#" + file.id + " td.plupload_delete").click(function(e) {
629
- e.preventDefault();
630
- objUploadView.uploader.removeFile(upl.getFile(file.id));
631
- $("#" + file.id).remove();
632
- return false;
633
- });
634
- });
635
636
- $.each(objUploadView.upload_remove_array, function(i, rfile) {
637
- if(upl.getFile(rfile))
638
- upl.removeFile(upl.getFile(rfile));
639
- });
640
- });
641
642
- objUploadView.uploader.bind('FileUploaded', function(up, file, res) {
643
- if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
644
- var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
645
646
- if(ieversion <10) {
647
try {
648
- if( typeof JSON.parse(res.response) !== "undefined" )
649
res.status = 200;
650
}
651
- catch(e){}
652
}
653
}
654
655
- if (res.status == 200) {
656
try {
657
- var objIds = JSON.parse(res.response);
658
- $.each(objIds, function(key, val) {
659
- activity_attachemnt_ids.push(val);
660
- if ($("#whats-new-form").find("#rtmedia_attached_id_" + val).length < 1) {
661
- $("#whats-new-form").append("<input type='hidden' name='rtMedia_attached_files[]' data-mode='rtMedia-update' id='rtmedia_attached_id_" + val + "' value='"
662
- + val + "' />");
663
}
664
- });
665
- } catch (e) {
666
667
}
668
}
669
- });
670
-
671
- objUploadView.uploader.bind('Error', function(up, err) {
672
-
673
- if(err.code== -600){ //file size error // if file size is greater than server's max allowed size
674
- var tmp_array;
675
- var ext = tr = '';
676
- tmp_array = err.file.name.split(".");
677
- if(tmp_array.length > 1){
678
-
679
- ext= tmp_array[tmp_array.length - 1];
680
- if( !(typeof(up.settings.upload_size) != "undefined" && typeof(up.settings.upload_size[ext]) != "undefined" && (up.settings.upload_size[ext]["size"] < 1 || (up.settings.upload_size[ext]["size"] * 1024 * 1024) >= err.file.size ))){
681
- tr = "<tr class='upload-error'><td>" + err.file.name + "(" + plupload.formatSize(err.file.size) + ")" + "</td><td> " + rtmedia_max_file_msg + plupload.formatSize( up.settings.max_file_size / 1024 * 1024) + " <i class='rtmicon-info-circled' title='" + window.file_size_info + "'></i></td><td>" + plupload.formatSize(err.file.size) + "</td><td></td><td class='close error_delete'>&times;</td></tr>";
682
- }
683
- }
684
- //append the message to the file queue
685
- $("#rtMedia-queue-list tbody").append(tr);
686
- }
687
- else {
688
- if( err.code == -601) { // file extension error
689
- err.message = rtmedia_file_extension_error_msg;
690
- }
691
- var tr = "<tr class='upload-error'><td>" + (err.file ? err.file.name : "") + "</td><td>" + err.message + " <i class='rtmicon-info-circled' title='" + window.file_extn_info + "'></i></td><td>" + plupload.formatSize(err.file.size) + "</td><td></td><td class='close error_delete'>&times;</td></tr>";
692
- $("#rtMedia-queue-list tbody").append(tr);
693
- }
694
-
695
- jQuery('.error_delete').on('click',function(e){
696
- e.preventDefault();
697
- jQuery(this).parent('tr').remove();
698
- });
699
- $("#rtm-upload-start-notice").css('display','block'); // show the file upload notice to the user
700
- return false;
701
702
- });
703
704
- objUploadView.uploader.bind('BeforeUpload', function(up, files) {
705
706
- $.each(objUploadView.upload_remove_array, function(i, rfile) {
707
- if(up.getFile(rfile))
708
- up.removeFile(up.getFile(rfile));
709
- });
710
711
var object = '';
712
- var item_id = jq("#whats-new-post-in").val();
713
- if (item_id == undefined)
714
item_id = 0;
715
- if (item_id > 0) {
716
object = "group";
717
} else {
718
object = "profile";
@@ -721,60 +747,66 @@ jQuery(document).ready(function($) {
721
up.settings.multipart_params.context = object;
722
up.settings.multipart_params.context_id = item_id;
723
// if privacy dropdown is not disabled, then get the privacy value of the update
724
- if( jQuery("select.privacy").prop('disabled') === false ){
725
- up.settings.multipart_params.privacy = jQuery("select.privacy").val();
726
}
727
- });
728
- objUploadView.uploader.bind('UploadComplete', function(up, files) {
729
media_uploading = true;
730
- $("#aw-whats-new-submit").click();
731
//remove the current file list
732
- $("#rtMedia-queue-list tr").remove();
733
- $("#rtm-upload-start-notice").hide();
734
//$("#aw-whats-new-submit").removeAttr('disabled');
735
- });
736
- objUploadView.uploader.bind('UploadProgress', function(up, file) {
737
- $("#" + file.id + " .plupload_file_status").html( rtmedia_uploading_msg + '( ' + file.percent + '% )');
738
- $("#" + file.id).addClass('upload-progress');
739
- if (file.percent == 100) {
740
- $("#" + file.id).toggleClass('upload-success');
741
- }
742
743
- });
744
745
- $("#rtMedia-start-upload").hide();
746
747
objUploadView.initUploader();
748
var change_flag = false
749
var media_uploading = false;
750
- $.ajaxPrefilter(function(options, originalOptions, jqXHR) {
751
// Modify options, control originalOptions, store jqXHR, etc
752
- try{
753
- if (originalOptions.data == null || typeof(originalOptions.data) == "undefined" || typeof(originalOptions.data.action) == "undefined" ) {
754
return true;
755
}
756
- }catch(e){
757
return true;
758
}
759
- if (originalOptions.data.action == 'post_update' || originalOptions.data.action == 'activity_widget_filter') {
760
var temp = activity_attachemnt_ids;
761
- while (activity_attachemnt_ids.length > 0) {
762
options.data += "&rtMedia_attached_files[]=" + activity_attachemnt_ids.pop();
763
}
764
- options.data += "&rtmedia-privacy=" + jQuery("select.privacy").val();
765
activity_attachemnt_ids = temp;
766
var orignalSuccess = originalOptions.success;
767
- options.beforeSend = function() {
768
- if (originalOptions.data.action == 'post_update') {
769
- if ($.trim($("#whats-new").val()) == "") {
770
- alert(rtmedia_empty_activity_msg);
771
- // $("#aw-whats-new-submit").prop("disabled", true).removeClass('loading');
772
- return false;
773
- }
774
- }
775
- if (!media_uploading && objUploadView.uploader.files.length > 0) {
776
- $("#whats-new-post-in").attr('disabled', 'disabled');
777
- $("#rtmedia-add-media-button-post-update").attr('disabled', 'disabled');
778
objUploadView.uploadFiles()
779
media_uploading = true;
780
return false;
@@ -785,173 +817,174 @@ jQuery(document).ready(function($) {
785
786
787
}
788
- options.success = function(response) {
789
- orignalSuccess(response);
790
- if (response[0] + response[1] == '-1') {
791
//Error
792
793
} else {
794
- if( originalOptions.data.action == 'activity_widget_filter' ) {
795
- $("div.activity").bind("fadeIn",function(){
796
- apply_rtMagnificPopup(jQuery('.rtmedia-list-media, .rtmedia-activity-container ul.rtmedia-list, #bp-media-list,.widget-item-listing,.bp-media-sc-list, li.media.album_updated ul,ul.bp-media-list-media, li.activity-item div.activity-content div.activity-inner div.bp_media_content'));
797
- rtMediaHook.call('rtmedia_js_after_activity_added', []);
798
- });
799
- $("div.activity").fadeIn(100);
800
- }
801
- jQuery("input[data-mode=rtMedia-update]").remove();
802
- while (objUploadView.uploader.files.pop() != undefined) {
803
}
804
objUploadView.uploader.refresh()
805
- $('#rtMedia-update-queue-list').html('');
806
//$("#div-attache-rtmedia").hide();
807
- apply_rtMagnificPopup(jQuery('.rtmedia-list-media, .rtmedia-activity-container ul.rtmedia-list, #bp-media-list,.widget-item-listing,.bp-media-sc-list, li.media.album_updated ul,ul.bp-media-list-media, li.activity-item div.activity-content div.activity-inner div.bp_media_content'));
808
- jQuery('ul.activity-list li.rtmedia_update:first-child .wp-audio-shortcode, ul.activity-list li.rtmedia_update:first-child .wp-video-shortcode').mediaelementplayer({
809
-
810
- // if the <video width> is not specified, this is the default
811
- defaultVideoWidth: 480,
812
- // if the <video height> is not specified, this is the default
813
- defaultVideoHeight: 270,
814
- // if set, overrides <video width>
815
- //videoWidth: 1,
816
- // if set, overrides <video height>
817
- //videoHeight: 1
818
- });
819
- rtMediaHook.call('rtmedia_js_after_activity_added', []);
820
}
821
- $("#whats-new-post-in").removeAttr('disabled');
822
- $("#rtmedia-add-media-button-post-update").removeAttr('disabled');
823
824
}
825
}
826
- });
827
- });
828
/**
829
* rtMedia Comment Js
830
*/
831
- jQuery(document).ready(function($) {
832
- jQuery(document).on("click", "#rt_media_comment_form #rt_media_comment_submit", function(e) {
833
e.preventDefault();
834
- if ($.trim($("#comment_content").val()) == "") {
835
- alert(rtmedia_empty_comment_msg);
836
return false;
837
}
838
839
- $(this).attr('disabled', 'disabled');
840
841
- $.ajax({
842
- url: jQuery("#rt_media_comment_form").attr("action"),
843
type: 'post',
844
- data: jQuery("#rt_media_comment_form").serialize() + "&rtajax=true",
845
- success: function(data) {
846
- $('#rtmedia-no-comments').remove();
847
- $("#rtmedia_comment_ul").append(data);
848
- $("#comment_content").val("");
849
- $("#rt_media_comment_form #rt_media_comment_submit").removeAttr('disabled');
850
- rtMediaHook.call('rtmedia_js_after_comment_added', []);
851
}
852
- });
853
-
854
855
856
return false;
857
- });
858
859
//Delete comment
860
- jQuery(document).on('click', '.rtmedia-delete-comment', function(e){
861
- e.preventDefault();
862
- var ask_confirmation = true
863
- ask_confirmation = rtMediaHook.call('rtmedia_js_delete_comment_confirmation', [ask_confirmation]);
864
- if(ask_confirmation && !confirm( rtmedia_media_comment_delete_confirmation ))
865
- return false;
866
- var current_comment = jQuery(this);
867
- var current_comment_parent = current_comment.parent();
868
- var comment_id = current_comment.data('id');
869
- current_comment_parent.css('opacity', '0.4');
870
- if(comment_id == '' || isNaN(comment_id)){
871
- return false;
872
- }
873
- var action = current_comment.closest('ul').data("action");
874
-
875
- jQuery.ajax({
876
- url: action,
877
- type: 'post',
878
- data: { comment_id : comment_id },
879
- success: function(res) {
880
- if(res !='undefined' && res == 1){
881
- current_comment.closest('li').hide(1000, function(){ current_comment.closest('li').remove(); });
882
- }else{
883
- current_comment.css('opacity', '1');
884
- }
885
- rtMediaHook.call('rtmedia_js_after_comment_deleted', []);
886
- }
887
- });
888
-
889
- });
890
-
891
- $(document).on("click", '.rtmedia-like', function(e) {
892
e.preventDefault();
893
var that = this;
894
- $(this).attr('disabled', 'disabled');
895
- var url = $(this).parent().attr("action");
896
- $(that).prepend("<img class='rtm-like-loading' src='" + rMedia_loading_file + "' style='width:10px' />");
897
- $.ajax({
898
url: url,
899
type: 'post',
900
data: "json=true",
901
- success: function(data) {
902
try {
903
- data = JSON.parse(data);
904
- } catch (e) {
905
906
}
907
- $('.rtmedia-like span').html(data.next);
908
- $('.rtm-like-loading').remove();
909
- $(that).removeAttr('disabled');
910
//update the like counter
911
- $('.rtmedia-like-counter').html(data.count);
912
- if(data.count > 0){
913
- $('.rtmedia-like-info').removeClass('hide');
914
- }else {
915
- $('.rtmedia-like-info').addClass('hide');
916
}
917
}
918
- });
919
920
921
- });
922
- $(document).on("click", '.rtmedia-featured', function(e) {
923
e.preventDefault();
924
var that = this;
925
- $(this).attr('disabled', 'disabled');
926
- var url = $(this).parent().attr("action");
927
- $(that).prepend("<img class='rtm-featured-loading' src='" + rMedia_loading_file + "' />");
928
- $.ajax({
929
url: url,
930
type: 'post',
931
data: "json=true",
932
- success: function(data) {
933
try {
934
- data = JSON.parse(data);
935
- } catch (e) {
936
937
}
938
- $(that).find('span').html(data.next);
939
- $('.rtm-featured-loading').remove();
940
- $(that).removeAttr('disabled');
941
}
942
- });
943
944
945
- });
946
- jQuery("#div-attache-rtmedia").find("input[type=file]").each(function() {
947
//$(this).attr("capture", "camera");
948
// $(this).attr("accept", $(this).attr("accept") + ';capture=camera');
949
950
- });
951
952
// manually trigger fadein event so that we can bind some function on this event. It is used in activity when content getting load via ajax
953
var _old_fadein = $.fn.fadeIn;
954
- jQuery.fn.fadeIn = function(){
955
- return _old_fadein.apply(this,arguments).trigger("fadeIn");
956
};
957
- });
3
var upload_sync = false;
4
var activity_id = -1;
5
var uploaderObj;
6
+ var objUploadView;
7
var rtmedia_load_template_flag = true;
8
9
+ jQuery( function ( $ ) {
10
11
var o_is_album, o_is_edit_allowed;
12
+ if ( typeof(is_album) == "undefined" ) {
13
+ o_is_album = new Array( "" );
14
} else {
15
o_is_album = is_album
16
}
17
+ if ( typeof(is_edit_allowed) == "undefined" ) {
18
+ o_is_edit_allowed = new Array( "" )
19
} else {
20
o_is_edit_allowed = is_edit_allowed;
21
}
24
25
rtMedia = window.rtMedia || {};
26
27
+ rtMedia.Context = Backbone.Model.extend( {
28
+ url: function () {
29
var url = rtmedia_media_slug + "/";
30
+ if ( !upload_sync && nextpage > 0 )
31
url += 'pg/' + nextpage + '/'
32
return url;
33
},
35
"context": "post",
36
"context_id": false
37
}
38
+ } );
39
40
+ rtMedia.Media = Backbone.Model.extend( {
41
defaults: {
42
"id": 0,
43
"blog_id": false,
59
"width": 0,
60
"height": 0,
61
"rt_permalink": false
62
+ // "next" : -1,
63
+ // "prev" : -1
64
}
65
66
+ } );
67
68
+ rtMedia.Gallery = Backbone.Collection.extend( {
69
model: rtMedia.Media,
70
+ url: function () {
71
var temp = window.location.pathname;
72
var url = '';
73
+ if ( temp.indexOf( "/" + rtmedia_media_slug + "/" ) == -1 ) {
74
url = rtmedia_media_slug + '/';
75
} else {
76
+ if ( temp.indexOf( 'pg/' ) == -1 )
77
url = temp;
78
else
79
+ url = window.location.pathname.substr( 0, window.location.pathname.lastIndexOf( "pg/" ) );
80
}
81
+ if ( !upload_sync && nextpage > 1 ) {
82
+ if ( url.substr( url.length - 1 ) != "/" )
83
url += "/"
84
url += 'pg/' + nextpage + '/';
85
}
86
return url;
87
},
88
+ getNext: function ( page, el, element ) {
89
+ if ( jQuery( '#bulk-edit-form' ).find( "p:nth-of-type(2)" ).length > 0 ) {
90
+ jQuery( '#bulk-edit-form p:nth-of-type(2)' ).replaceWith( "<ul class='rtmedia-list rtmedia-list-media'></ul>" );
91
+ }
92
+ that = this;
93
+ if ( rtmedia_load_template_flag == true ) {
94
+ $( "#rtmedia-gallery-item-template" ).load( template_url, {
95
+ backbone: true,
96
+ is_album: o_is_album,
97
+ is_edit_allowed: o_is_edit_allowed
98
+ }, function () {
99
+ rtmedia_load_template_flag = false;
100
+ that.getNext();
101
+ } );
102
+ }
103
+ if ( !rtmedia_load_template_flag ) {
104
+ var query = {
105
+ json: true,
106
+ rtmedia_page: nextpage
107
+ };
108
+ if ( el == undefined ) {
109
+ el = jQuery( ".rtmedia-list" ).parent().parent();
110
+ }
111
+ if ( el != undefined ) {
112
+ if ( element != undefined ) {
113
+ $( element ).parent().parent().prevAll( "input[type=hidden]" ).each( function ( e ) {
114
+ query[$( this ).attr( "name" )] = $( this ).val();
115
+ } );
116
+ } else {
117
+ $( el ).find( "input[type=hidden]" ).each( function ( e ) {
118
+ query[$( this ).attr( "name" )] = $( this ).val();
119
+ } );
120
+ }
121
+
122
+ }
123
+ this.fetch( {
124
+ data: query,
125
+ success: function ( model, response ) {
126
+ jQuery( '.rtm-media-loading' ).hide();
127
+ var list_el = "";
128
+ if ( typeof(element) === "undefined" )
129
+ list_el = $( ".rtmedia-list" )[0];
130
+ else
131
+ list_el = element.parent().siblings( '.rtmedia-list' );
132
+ nextpage = response.next;
133
+ var galleryViewObj = new rtMedia.GalleryView( {
134
+ collection: new rtMedia.Gallery( response.data ),
135
+ el: list_el
136
+ } );
137
+ //element.show();
138
+ }
139
+ } );
140
+ }
141
},
142
+ reloadView: function () {
143
upload_sync = true;
144
nextpage = 1;
145
this.getNext();
146
}
147
148
149
+ } );
150
151
+ rtMedia.MediaView = Backbone.View.extend( {
152
tagName: 'li',
153
className: 'rtmedia-list-item',
154
+ initialize: function () {
155
+ this.template = _.template( $( "#rtmedia-gallery-item-template" ).html() );
156
+ this.model.bind( 'change', this.render );
157
+ this.model.bind( 'remove', this.unrender );
158
this.render();
159
},
160
+ render: function () {
161
+ $( this.el ).html( this.template( this.model.toJSON() ) );
162
return this.el;
163
},
164
+ unrender: function () {
165
+ $( this.el ).remove();
166
},
167
+ remove: function () {
168
this.model.destroy();
169
}
170
+ } );
171
172
+ rtMedia.GalleryView = Backbone.View.extend( {
173
tagName: 'ul',
174
className: 'rtmedia-list',
175
+ initialize: function () {
176
+ this.template = _.template( $( "#rtmedia-gallery-item-template" ).html() );
177
this.render();
178
},
179
+ render: function () {
180
181
that = this;
182
183
+ if ( upload_sync ) {
184
+ $( that.el ).html( '' );
185
}
186
187
+ $.each( this.collection.toJSON(), function ( key, media ) {
188
+ $( that.el ).append( that.template( media ) );
189
+ } );
190
+ if ( upload_sync ) {
191
upload_sync = false;
192
}
193
+ if ( nextpage > 1 ) {
194
+ $( that.el ).siblings( '.rtmedia_next_prev' ).children( '#rtMedia-galary-next' ).show();
195
+ //$("#rtMedia-galary-next").show();
196
}
197
198
199
},
200
+ appendTo: function ( media ) {
201
//console.log("append");
202
+ var mediaView = new rtMedia.MediaView( {
203
model: media
204
+ } );
205
+ $( this.el ).append( mediaView.render().el );
206
}
207
+ } );
208
209
210
galleryObj = new rtMedia.Gallery();
211
212
+ $( "body" ).append( '<script id="rtmedia-gallery-item-template" type="text/template"></script>' );
213
214
+ $( document ).on( "click", "#rtMedia-galary-next", function ( e ) {
215
$( this ).before( "<div class='rtm-media-loading'><img src='" + rMedia_loading_media + "' /></div>" );
216
+ $( this ).hide();
217
+ e.preventDefault();
218
+ galleryObj.getNext( nextpage, $( this ).parent().parent().parent(), $( this ) );
219
+ } );
220
221
222
+ if ( window.location.pathname.indexOf( rtmedia_media_slug ) != -1 ) {
223
+ var tempNext = window.location.pathname.substring( window.location.pathname.lastIndexOf( "pg/" ) + 5, window.location.pathname.lastIndexOf( "/" ) );
224
+ if ( isNaN( tempNext ) === false ) {
225
+ nextpage = parseInt( tempNext ) + 1;
226
}
227
}
228
229
230
+ window.UploadView = Backbone.View.extend( {
231
events: {
232
"click #rtMedia-start-upload": "uploadFiles"
233
},
234
+ initialize: function ( config ) {
235
+ this.uploader = new plupload.Uploader( config );
236
},
237
+ render: function () {
238
239
},
240
+ initUploader: function ( a ) {
241
+ if ( typeof(a) !== "undefined" ) a = false;// if rtmediapro widget calls the function, dont show max size note.
242
this.uploader.init();
243
//The plupload HTML5 code gives a negative z-index making add files button unclickable
244
+ $( ".plupload.html5" ).css( {
245
zIndex: 0
246
+ } );
247
+ $( "#rtMedia-upload-button" ).css( {
248
zIndex: 2
249
+ } );
250
+ if ( a !== false ) {
251
+ window.file_size_info = rtmedia_max_file_msg + " : " + this.uploader.settings.max_file_size_msg;
252
+ if ( rtmedia_version_compare( rtm_wp_version, "3.9" ) ) { // plupload getting updated in 3.9
253
+ window.file_extn_info = rtmedia_allowed_file_formats + " : " + this.uploader.settings.filters.mime_types[0].extensions;
254
+ } else {
255
+ window.file_extn_info = rtmedia_allowed_file_formats + " : " + this.uploader.settings.filters[0].extensions;
256
+ }
257
+
258
var info = window.file_size_info + ", " + window.file_extn_info;
259
+ $( ".rtm-file-size-limit" ).attr( 'title', info );
260
+ //$("#rtMedia-upload-button").after("<span>( <strong>" + rtmedia_max_file_msg + "</strong> "+ this.uploader.settings.max_file_size_msg + ")</span>");
261
}
262
263
return this;
264
},
265
+ uploadFiles: function ( e ) {
266
+ if ( e != undefined )
267
e.preventDefault();
268
this.uploader.start();
269
return false;
270
}
271
272
+ } );
273
274
275
+ if ( $( "#rtMedia-upload-button" ).length > 0 ) {
276
+ if ( typeof rtmedia_upload_type_filter == "object" && rtmedia_upload_type_filter.length > 0 ) {
277
+ if ( rtmedia_version_compare( rtm_wp_version, "3.9" ) ) { // plupload getting updated in 3.9
278
+ rtMedia_plupload_config.filters.mime_types[0].extensions = rtmedia_upload_type_filter.join();
279
+ } else {
280
+ rtMedia_plupload_config.filters[0].extensions = rtmedia_upload_type_filter.join();
281
+ }
282
+ }
283
+ uploaderObj = new UploadView( rtMedia_plupload_config );
284
285
uploaderObj.initUploader();
286
287
288
+ uploaderObj.uploader.bind( 'UploadComplete', function ( up, files ) {
289
+ activity_id = -1;
290
+ if ( typeof rtmedia_gallery_reload_on_upload != "undefined" && rtmedia_gallery_reload_on_upload == '1' ) { //reload gallery view when upload completes if enabled( by default enabled)
291
galleryObj.reloadView();
292
}
293
+ jQuery( '.start-media-upload' ).hide();
294
+ } );
295
296
+ uploaderObj.uploader.bind( 'FilesAdded', function ( up, files ) {
297
var upload_size_error = false;
298
var upload_error = "";
299
var upload_error_sep = "";
300
+ var upload_remove_array = [];
301
+ $.each( files, function ( i, file ) {
302
+ var hook_respo = rtMediaHook.call( 'rtmedia_js_file_added', [up, file, "#rtMedia-queue-list tbody"] );
303
+ if ( hook_respo == false ) {
304
file.status = -1;
305
+ upload_remove_array.push( file.id );
306
return true;
307
}
308
+ jQuery( '.rtmedia-upload-input' ).attr( 'value', rtmedia_add_more_files_msg );
309
+ jQuery( '.start-media-upload' ).show();
310
+ if ( uploaderObj.uploader.settings.max_file_size < file.size ) {
311
// upload_size_error = true
312
// upload_error += upload_error_sep + file.name;
313
// upload_error_sep = ",";
315
// $("#rtMedia-queue-list tbody").append(tr);
316
return true;
317
}
318
+ var tmp_array = file.name.split( "." );
319
+ if ( rtmedia_version_compare( rtm_wp_version, "3.9" ) ) { // plupload getting updated in 3.9
320
+ var ext_array = uploaderObj.uploader.settings.filters.mime_types[0].extensions.split( ',' );
321
+ } else {
322
+ var ext_array = uploaderObj.uploader.settings.filters[0].extensions.split( ',' );
323
+ }
324
+ if ( tmp_array.length > 1 ) {
325
+ var ext = tmp_array[tmp_array.length - 1];
326
+ ext = ext.toLowerCase();
327
+ if ( jQuery.inArray( ext, ext_array ) === -1 ) {
328
return true;
329
}
330
+ } else {
331
return true;
332
}
333
334
+ if ( rtmedia_version_compare( rtm_wp_version, "3.9" ) ) { // plupload getting updated in 3.9
335
+ uploaderObj.uploader.settings.filters.mime_types[0].title;
336
+ } else {
337
+ uploaderObj.uploader.settings.filters[0].title;
338
+ }
339
+ tdName = document.createElement( "td" );
340
+ tdName.innerHTML = file.name.substring( 0, 40 );
341
tdName.className = "plupload_file_name";
342
+ tdStatus = document.createElement( "td" );
343
tdStatus.className = "plupload_file_status";
344
tdStatus.innerHTML = rtmedia_waiting_msg;
345
+ tdSize = document.createElement( "td" );
346
tdSize.className = "plupload_file_size";
347
+ tdSize.innerHTML = plupload.formatSize( file.size );
348
+ tdDelete = document.createElement( "td" );
349
tdDelete.innerHTML = "<span class='remove-from-queue'>&times;</span>";
350
tdDelete.title = rtmedia_close;
351
tdDelete.className = "close plupload_delete";
352
+ tdEdit = document.createElement( "td" );
353
tdEdit.innerHTML = "";
354
tdEdit.className = "plupload_media_edit";
355
+ tr = document.createElement( "tr" );
356
tr.className = 'upload-waiting';
357
tr.id = file.id;
358
+ tr.appendChild( tdName );
359
+ tr.appendChild( tdStatus );
360
+ tr.appendChild( tdSize );
361
+ tr.appendChild( tdEdit );
362
+ tr.appendChild( tdDelete );
363
+ $( "#rtMedia-queue-list" ).append( tr );
364
//Delete Function
365
+ $( "#" + file.id + " td.plupload_delete .remove-from-queue" ).click( function ( e ) {
366
e.preventDefault();
367
+ uploaderObj.uploader.removeFile( up.getFile( file.id ) );
368
+ $( "#" + file.id ).remove();
369
+ rtMediaHook.call( 'rtmedia_js_file_remove', [up, file] );
370
return false;
371
+ } );
372
373
+ } );
374
+ $.each( upload_remove_array, function ( i, rfile ) {
375
+ if ( up.getFile( rfile ) )
376
+ up.removeFile( up.getFile( rfile ) );
377
+ } );
378
379
// if (upload_size_error) {
380
// // alert(upload_error + " because max file size is " + plupload.formatSize(uploaderObj.uploader.settings.max_file_size) );
381
// }
382
+ } );
383
384
+ uploaderObj.uploader.bind( 'Error', function ( up, err ) {
385
386
+ if ( err.code == -600 ) { //file size error // if file size is greater than server's max allowed size
387
var tmp_array;
388
var ext = tr = '';
389
+ tmp_array = err.file.name.split( "." );
390
+ if ( tmp_array.length > 1 ) {
391
+ ext = tmp_array[tmp_array.length - 1];
392
+ if ( !(typeof(up.settings.upload_size) != "undefined" && typeof(up.settings.upload_size[ext]) != "undefined" && typeof(up.settings.upload_size[ext]['size']) ) ) {
393
+ tr = "<tr class='upload-error'><td>" + err.file.name.substring( 0, 40 ) + "</td><td> " + rtmedia_max_file_msg + plupload.formatSize( up.settings.max_file_size / 1024 * 1024 ) + " <i class='rtmicon-info-circle' title='" + window.file_size_info + "'></i></td><td>" + plupload.formatSize( err.file.size ) + "</td><td></td><td class='close error_delete'>&times;</td></tr>";
394
}
395
}
396
//append the message to the file queue
397
+ $( "#rtMedia-queue-list tbody" ).append( tr );
398
}
399
else {
400
401
+ if ( err.code == -601 ) { // file extension error
402
err.message = rtmedia_file_extension_error_msg;
403
}
404
+ var tr = "<tr class='upload-error'><td>" + (err.file ? err.file.name.substring( 0, 40 ) : "") + "</td><td>" + err.message + " <i class='rtmicon-info-circle' title='" + window.file_extn_info + "'></i></td><td>" + plupload.formatSize( err.file.size ) + "</td><td></td><td class='close error_delete'>&times;</td></tr>";
405
+ $( "#rtMedia-queue-list tbody" ).append( tr );
406
}
407
408
+ jQuery( '.error_delete' ).on( 'click', function ( e ) {
409
e.preventDefault();
410
+ jQuery( this ).parent( 'tr' ).remove();
411
+ } );
412
return false;
413
414
+ } );
415
416
+ jQuery( '.start-media-upload' ).on( 'click', function ( e ) {
417
e.preventDefault();
418
uploaderObj.uploadFiles();
419
+ } );
420
421
+ uploaderObj.uploader.bind( 'QueueChanged', function ( up ) {
422
423
// jQuery('.rtmedia-upload-input').attr('value','Add more files');
424
// jQuery('.start-media-upload').show();
425
426
+ } );
427
428
+ uploaderObj.uploader.bind( 'UploadProgress', function ( up, file ) {
429
//$("#" + file.id + " .plupload_file_status").html(file.percent + "%");
430
+ $( "#" + file.id + " .plupload_file_status" ).html( rtmedia_uploading_msg + '( ' + file.percent + '% )' );
431
+ $( "#" + file.id ).addClass( 'upload-progress' );
432
+ if ( file.percent == 100 ) {
433
+ $( "#" + file.id ).toggleClass( 'upload-success' );
434
+ }
435
+ } );
436
+ uploaderObj.uploader.bind( 'BeforeUpload', function ( up, file ) {
437
+ var privacy = $( "#rtm-file_upload-ui select.privacy" ).val();
438
+ if ( privacy !== undefined ) {
439
+ up.settings.multipart_params.privacy = $( "#rtm-file_upload-ui select.privacy" ).val();
440
+ }
441
+ if ( jQuery( "#rt_upload_hf_redirect" ).length > 0 )
442
up.settings.multipart_params.redirect = up.files.length;
443
+ jQuery( "#rtmedia-uploader-form input[type=hidden]" ).each( function () {
444
+ up.settings.multipart_params[$( this ).attr( "name" )] = $( this ).val();
445
+ } );
446
up.settings.multipart_params.activity_id = activity_id;
447
+ if ( $( '#rtmedia-uploader-form .rtmedia-user-album-list' ).length > 0 )
448
+ up.settings.multipart_params.album_id = $( '#rtmedia-uploader-form .rtmedia-user-album-list' ).find( ":selected" ).val();
449
+ else if ( $( '#rtmedia-uploader-form .rtmedia-current-album' ).length > 0 )
450
+ up.settings.multipart_params.album_id = $( '#rtmedia-uploader-form .rtmedia-current-album' ).val();
451
+ } );
452
+
453
+ uploaderObj.uploader.bind( 'FileUploaded', function ( up, file, res ) {
454
+ if ( /MSIE (\d+\.\d+);/.test( navigator.userAgent ) ) { //test for MSIE x.x;
455
+ var ieversion = new Number( RegExp.$1 ) // capture x.x portion and store as a number
456
+
457
+ if ( ieversion < 10 ) {
458
+ if ( typeof res.response !== "undefined" )
459
+ res.status = 200;
460
+ }
461
}
462
var rtnObj;
463
+ try {
464
465
+ rtnObj = JSON.parse( res.response );
466
uploaderObj.uploader.settings.multipart_params.activity_id = rtnObj.activity_id;
467
activity_id = rtnObj.activity_id;
468
+ if ( rtnObj.permalink != '' ) {
469
+ $( "#" + file.id + " .plupload_file_name" ).html( "<a href='" + rtnObj.permalink + "' target='_blank' title='" + rtnObj.permalink + "'>" + file.name.substring( 0, 40 ) + "</a>" );
470
+ $( "#" + file.id + " .plupload_media_edit" ).html( "<a href='" + rtnObj.permalink + "edit' target='_blank'><span title='" + rtmedia_edit_media + "'><i class='rtmicon-edit'></i> " + rtmedia_edit + "</span></a>" );
471
+ $( "#" + file.id + " .plupload_delete" ).html( "<span id='" + rtnObj.media_id + "' class='rtmedia-delete-uploaded-media' title='" + rtmedia_delete + "'>&times;</span>" );
472
}
473
474
+ } catch ( e ) {
475
// console.log('Invalid Activity ID');
476
}
477
+ if ( res.status == 200 || res.status == 302 ) {
478
+ if ( uploaderObj.upload_count == undefined )
479
uploaderObj.upload_count = 1;
480
else
481
uploaderObj.upload_count++;
482
483
+ if ( uploaderObj.upload_count == up.files.length && jQuery( "#rt_upload_hf_redirect" ).length > 0 && jQuery.trim( rtnObj.redirect_url.indexOf( "http" ) == 0 ) ) {
484
window.location = rtnObj.redirect_url;
485
}
486
487
+ $( "#" + file.id + " .plupload_file_status" ).html( rtmedia_uploaded_msg );
488
+ rtMediaHook.call( 'rtmedia_js_after_file_upload', [up, file, res] );
489
+ } else {
490
+ $( "#" + file.id + " .plupload_file_status" ).html( rtmedia_upload_failed_msg );
491
}
492
493
files = up.files;
494
lastfile = files[files.length - 1];
495
496
497
+ } );
498
499
uploaderObj.uploader.refresh();//refresh the uploader for opera/IE fix on media page
500
501
+ $( "#rtMedia-start-upload" ).click( function ( e ) {
502
+ uploaderObj.uploadFiles( e );
503
+ } );
504
+ $( "#rtMedia-start-upload" ).hide();
505
506
+ jQuery( document ).on( 'click', '#rtm_show_upload_ui', function () {
507
+ jQuery( '#rtm-media-gallery-uploader' ).slideToggle();
508
uploaderObj.uploader.refresh();//refresh the uploader for opera/IE fix on media page
509
+ jQuery( '#rtm_show_upload_ui' ).toggleClass( 'primary' );
510
+ } );
511
} else {
512
+ jQuery( document ).on( 'click', '#rtm_show_upload_ui', function () {
513
+ jQuery( '#rtm-media-gallery-uploader' ).slideToggle();
514
+ jQuery( '#rtm_show_upload_ui' ).toggleClass( 'primary' );
515
+ } );
516
}
517
518
+ jQuery( document ).on( 'click', '.plupload_delete .rtmedia-delete-uploaded-media', function () {
519
+ var that = $( this );
520
+ if ( confirm( rtmedia_delete_uploaded_media ) ) {
521
+ var nonce = $( '#rtmedia-upload-container #rtmedia_media_delete_nonce' ).val();
522
+ var media_id = $( this ).attr( 'id' );
523
var data = {
524
+ action: 'delete_uploaded_media',
525
+ nonce: nonce,
526
+ media_id: media_id
527
}
528
529
+ $.post( ajaxurl, data, function ( response ) {
530
+ if ( response == '1' ) {
531
+ that.closest( 'tr' ).remove();
532
+ $( '#' + media_id ).remove();
533
}
534
+ } );
535
}
536
+ } );
537
538
539
+ } );
540
/** History Code for route
541
542
var rtMediaRouter = Backbone.Router.extend({
555
556
/** Activity Update Js **/
557
558
+ jQuery( document ).ready( function ( $ ) {
559
560
//handling the "post update: button on activity page
561
+ jQuery( '#aw-whats-new-submit' ).removeAttr( 'disabled' );
562
+ jQuery( document ).on( "blur", '#whats-new', function () {
563
+ setTimeout( function () {
564
+ jQuery( '#aw-whats-new-submit' ).removeAttr( 'disabled' );
565
+ }, 100 );
566
+ } );
567
+ jQuery( '#aw-whats-new-submit' ).on( 'click', function ( e ) {
568
+ setTimeout( function () {
569
+ jQuery( '#aw-whats-new-submit' ).removeAttr( 'disabled' );
570
+ }, 100 );
571
+ } );
572
573
// when user changes the value in activity "post in" dropdown, hide the privacy dropdown and show when posting in profile.
574
+ jQuery( '#whats-new-post-in' ).on( 'change', function ( e ) {
575
+ if ( jQuery( this ).val() == '0' ) {
576
+ jQuery( "#rtmedia-action-update .privacy" ).prop( 'disabled', false ).show();
577
+ } else {
578
+ jQuery( "#rtmedia-action-update .privacy" ).prop( 'disabled', true ).hide();
579
}
580
+ } );
581
582
+ if ( typeof rtMedia_update_plupload_config == 'undefined' ) {
583
return false;
584
}
585
var activity_attachemnt_ids = [];
586
+ if ( $( "#rtmedia-add-media-button-post-update" ).length > 0 ) {
587
+ $( "#whats-new-options" ).prepend( $( "#rtmedia-action-update" ) );
588
+ if ( $( "#rtm-file_upload-ui .privacy" ).length > 0 ) {
589
+ $( "#rtmedia-action-update" ).append( $( "#rtm-file_upload-ui .privacy" ) );
590
}
591
}
592
+ objUploadView = new UploadView( rtMedia_update_plupload_config );
593
+ $( "#whats-new-form" ).on( 'click', '#rtmedia-add-media-button-post-update', function ( e ) {
594
objUploadView.uploader.refresh();
595
+ } );
596
//whats-new-post-in
597
598
objUploadView.upload_remove_array = [];
599
+ objUploadView.uploader.bind( 'FilesAdded', function ( upl, rfiles ) {
600
//$("#aw-whats-new-submit").attr('disabled', 'disabled');
601
602
+ $.each( rfiles, function ( i, file ) {
603
+ var hook_respo = rtMediaHook.call( 'rtmedia_js_file_added', [upl, file, "#rtMedia-queue-list tbody"] );
604
+ if ( hook_respo == false ) {
605
+ file.status = -1;
606
+ objUploadView.upload_remove_array.push( file.id );
607
+ return true;
608
}
609
+ if ( objUploadView.uploader.settings.max_file_size < file.size ) {
610
return true;
611
}
612
+ var tmp_array = file.name.split( "." );
613
+ if ( rtmedia_version_compare( rtm_wp_version, "3.9" ) ) { // plupload getting updated in 3.9
614
+ var ext_array = objUploadView.uploader.settings.filters.mime_types[0].extensions.split( ',' );
615
+ } else {
616
+ var ext_array = objUploadView.uploader.settings.filters[0].extensions.split( ',' );
617
+ }
618
+ if ( tmp_array.length > 1 ) {
619
+ var ext = tmp_array[tmp_array.length - 1];
620
+ ext = ext.toLowerCase();
621
+ if ( jQuery.inArray( ext, ext_array ) === -1 ) {
622
return true;
623
}
624
+ } else {
625
return true;
626
}
627
+ tdName = document.createElement( "td" );
628
+ tdName.innerHTML = file.name.substring( 0, 40 );
629
+ tdStatus = document.createElement( "td" );
630
tdStatus.className = "plupload_file_status";
631
tdStatus.innerHTML = rtmedia_waiting_msg;
632
+ tdSize = document.createElement( "td" );
633
tdSize.className = "plupload_file_size";
634
+ tdSize.innerHTML = plupload.formatSize( file.size );
635
+ tdDelete = document.createElement( "td" );
636
tdDelete.innerHTML = "&times;";
637
tdDelete.title = rtmedia_remove_from_queue;
638
tdDelete.className = "close plupload_delete";
639
+ tdEdit = document.createElement( "td" );
640
tdEdit.innerHTML = "";
641
+ tr = document.createElement( "tr" );
642
tr.className = 'upload-waiting';
643
tr.id = file.id;
644
+ tr.appendChild( tdName );
645
+ tr.appendChild( tdStatus );
646
+ tr.appendChild( tdSize );
647
+ tr.appendChild( tdEdit );
648
+ tr.appendChild( tdDelete );
649
+ jQuery( '#whats-new-content' ).css( 'padding-bottom', '0px' );
650
+ $( "#rtm-upload-start-notice" ).css( 'display', 'block' ); // show the file upload notice to the user
651
+ $( "#rtMedia-queue-list" ).append( tr );
652
+ $( "#" + file.id + " td.plupload_delete" ).click( function ( e ) {
653
+ e.preventDefault();
654
+ objUploadView.uploader.removeFile( upl.getFile( file.id ) );
655
+ $( "#" + file.id ).remove();
656
+ return false;
657
+ } );
658
+ } );
659
660
+ $.each( objUploadView.upload_remove_array, function ( i, rfile ) {
661
+ if ( upl.getFile( rfile ) )
662
+ upl.removeFile( upl.getFile( rfile ) );
663
+ } );
664
+ } );
665
666
+ objUploadView.uploader.bind( 'FileUploaded', function ( up, file, res ) {
667
+ if ( /MSIE (\d+\.\d+);/.test( navigator.userAgent ) ) { //test for MSIE x.x;
668
+ var ieversion = new Number( RegExp.$1 ) // capture x.x portion and store as a number
669
670
+ if ( ieversion < 10 ) {
671
try {
672
+ if ( typeof JSON.parse( res.response ) !== "undefined" )
673
res.status = 200;
674
}
675
+ catch ( e ) {
676
+ }
677
}
678
}
679
680
+ if ( res.status == 200 ) {
681
try {
682
+ var objIds = JSON.parse( res.response );
683
+ $.each( objIds, function ( key, val ) {
684
+ activity_attachemnt_ids.push( val );
685
+ if ( $( "#whats-new-form" ).find( "#rtmedia_attached_id_" + val ).length < 1 ) {
686
+ $( "#whats-new-form" ).append( "<input type='hidden' name='rtMedia_attached_files[]' data-mode='rtMedia-update' id='rtmedia_attached_id_" + val + "' value='"
687
+ + val + "' />" );
688
}
689
+ } );
690
+ } catch ( e ) {
691
692
}
693
+ rtMediaHook.call( 'rtmedia_js_after_file_upload', [up, file, res] );
694
}
695
+ } );
696
+
697
+ objUploadView.uploader.bind( 'Error', function ( up, err ) {
698
+
699
+ if ( err.code == -600 ) { //file size error // if file size is greater than server's max allowed size
700
+ var tmp_array;
701
+ var ext = tr = '';
702
+ tmp_array = err.file.name.split( "." );
703
+ if ( tmp_array.length > 1 ) {
704
+
705
+ ext = tmp_array[tmp_array.length - 1];
706
+ if ( !(typeof(up.settings.upload_size) != "undefined" && typeof(up.settings.upload_size[ext]) != "undefined" && (up.settings.upload_size[ext]["size"] < 1 || (up.settings.upload_size[ext]["size"] * 1024 * 1024) >= err.file.size )) ) {
707
+ tr = "<tr class='upload-error'><td>" + err.file.name.substring( 0, 40 ) + "(" + plupload.formatSize( err.file.size ) + ")" + "</td><td> " + rtmedia_max_file_msg + plupload.formatSize( up.settings.max_file_size / 1024 * 1024 ) + " <i class='rtmicon-info-circled' title='" + window.file_size_info + "'></i></td><td>" + plupload.formatSize( err.file.size ) + "</td><td></td><td class='close error_delete'>&times;</td></tr>";
708
+ }
709
+ }
710
+ //append the message to the file queue
711
+ $( "#rtMedia-queue-list tbody" ).append( tr );
712
+ }
713
+ else {
714
+ if ( err.code == -601 ) { // file extension error
715
+ err.message = rtmedia_file_extension_error_msg;
716
+ }
717
+ var tr = "<tr class='upload-error'><td>" + (err.file ? err.file.name.substring( 0, 40 ) : "") + "</td><td>" + err.message + " <i class='rtmicon-info-circled' title='" + window.file_extn_info + "'></i></td><td>" + plupload.formatSize( err.file.size ) + "</td><td></td><td class='close error_delete'>&times;</td></tr>";
718
+ $( "#rtMedia-queue-list tbody" ).append( tr );
719
+ }
720
+
721
+ jQuery( '.error_delete' ).on( 'click', function ( e ) {
722
+ e.preventDefault();
723
+ jQuery( this ).parent( 'tr' ).remove();
724
+ } );
725
+ $( "#rtm-upload-start-notice" ).css( 'display', 'block' ); // show the file upload notice to the user
726
+ return false;
727
728
+ } );
729
730
+ objUploadView.uploader.bind( 'BeforeUpload', function ( up, files ) {
731
732
+ $.each( objUploadView.upload_remove_array, function ( i, rfile ) {
733
+ if ( up.getFile( rfile ) )
734
+ up.removeFile( up.getFile( rfile ) );
735
+ } );
736
737
var object = '';
738
+ var item_id = jq( "#whats-new-post-in" ).val();
739
+ if ( item_id == undefined )
740
item_id = 0;
741
+ if ( item_id > 0 ) {
742
object = "group";
743
} else {
744
object = "profile";
747
up.settings.multipart_params.context = object;
748
up.settings.multipart_params.context_id = item_id;
749
// if privacy dropdown is not disabled, then get the privacy value of the update
750
+ if ( jQuery( "select.privacy" ).prop( 'disabled' ) === false ) {
751
+ up.settings.multipart_params.privacy = jQuery( "select.privacy" ).val();
752
}
753
+ } );
754
+ objUploadView.uploader.bind( 'UploadComplete', function ( up, files ) {
755
media_uploading = true;
756
+ $( "#aw-whats-new-submit" ).click();
757
//remove the current file list
758
+ $( "#rtMedia-queue-list tr" ).remove();
759
+ $( "#rtm-upload-start-notice" ).hide();
760
//$("#aw-whats-new-submit").removeAttr('disabled');
761
+ } );
762
+ objUploadView.uploader.bind( 'UploadProgress', function ( up, file ) {
763
+ $( "#" + file.id + " .plupload_file_status" ).html( rtmedia_uploading_msg + '( ' + file.percent + '% )' );
764
+ $( "#" + file.id ).addClass( 'upload-progress' );
765
+ if ( file.percent == 100 ) {
766
+ $( "#" + file.id ).toggleClass( 'upload-success' );
767
+ }
768
769
+ } );
770
771
+ $( "#rtMedia-start-upload" ).hide();
772
773
objUploadView.initUploader();
774
var change_flag = false
775
var media_uploading = false;
776
+ $.ajaxPrefilter( function ( options, originalOptions, jqXHR ) {
777
// Modify options, control originalOptions, store jqXHR, etc
778
+ try {
779
+ if ( originalOptions.data == null || typeof(originalOptions.data) == "undefined" || typeof(originalOptions.data.action) == "undefined" ) {
780
return true;
781
}
782
+ } catch ( e ) {
783
return true;
784
}
785
+ if ( originalOptions.data.action == 'post_update' || originalOptions.data.action == 'activity_widget_filter' ) {
786
var temp = activity_attachemnt_ids;
787
+ while ( activity_attachemnt_ids.length > 0 ) {
788
options.data += "&rtMedia_attached_files[]=" + activity_attachemnt_ids.pop();
789
}
790
+ options.data += "&rtmedia-privacy=" + jQuery( "select.privacy" ).val();
791
activity_attachemnt_ids = temp;
792
+ if ( jQuery( '#rtmp-url-no-scrapper' ).length > 0 && jQuery( '#rtmp-url-no-scrapper' ).val() != '0' ) {
793
+ options.data += "&rtmp_link_url=" + jQuery( "#rtmp-url-scrapper-url-hidden" ).val(); // URL link preview
794
+ options.data += "&rtmp_link_title=" + jQuery( "#rtmp-url-scrapper-title-hidden" ).val(); // URL link preview
795
+ options.data += "&rtmp_link_img=" + jQuery( '#rtmp-url-scrapper-img-hidden' ).val(); // URL link preview
796
+ options.data += "&rtmp_link_description=" + jQuery( "#rtmp-url-scrapper-description-hidden" ).val(); // URL link preview
797
+ }
798
var orignalSuccess = originalOptions.success;
799
+ options.beforeSend = function () {
800
+ if ( originalOptions.data.action == 'post_update' ) {
801
+ if ( $.trim( $( "#whats-new" ).val() ) == "" ) {
802
+ alert( rtmedia_empty_activity_msg );
803
+ // $("#aw-whats-new-submit").prop("disabled", true).removeClass('loading');
804
+ return false;
805
+ }
806
+ }
807
+ if ( !media_uploading && objUploadView.uploader.files.length > 0 ) {
808
+ $( "#whats-new-post-in" ).attr( 'disabled', 'disabled' );
809
+ $( "#rtmedia-add-media-button-post-update" ).attr( 'disabled', 'disabled' );
810
objUploadView.uploadFiles()
811
media_uploading = true;
812
return false;
817
818
819
}
820
+ options.success = function ( response ) {
821
+ orignalSuccess( response );
822
+ if ( response[0] + response[1] == '-1' ) {
823
//Error
824
825
} else {
826
+ if ( originalOptions.data.action == 'activity_widget_filter' ) {
827
+ $( "div.activity" ).bind( "fadeIn", function () {
828
+ apply_rtMagnificPopup( jQuery( '.rtmedia-list-media, .rtmedia-activity-container ul.rtmedia-list, #bp-media-list,.widget-item-listing,.bp-media-sc-list, li.media.album_updated ul,ul.bp-media-list-media, li.activity-item div.activity-content div.activity-inner div.bp_media_content' ) );
829
+ rtMediaHook.call( 'rtmedia_js_after_activity_added', [] );
830
+ } );
831
+ $( "div.activity" ).fadeIn( 100 );
832
+ }
833
+ jQuery( "input[data-mode=rtMedia-update]" ).remove();
834
+ while ( objUploadView.uploader.files.pop() != undefined ) {
835
}
836
objUploadView.uploader.refresh()
837
+ $( '#rtMedia-update-queue-list' ).html( '' );
838
//$("#div-attache-rtmedia").hide();
839
+ apply_rtMagnificPopup( jQuery( '.rtmedia-list-media, .rtmedia-activity-container ul.rtmedia-list, #bp-media-list,.widget-item-listing,.bp-media-sc-list, li.media.album_updated ul,ul.bp-media-list-media, li.activity-item div.activity-content div.activity-inner div.bp_media_content' ) );
840
+ jQuery( 'ul.activity-list li.rtmedia_update:first-child .wp-audio-shortcode, ul.activity-list li.rtmedia_update:first-child .wp-video-shortcode' ).mediaelementplayer( {
841
+
842
+ // if the <video width> is not specified, this is the default
843
+ defaultVideoWidth: 480,
844
+ // if the <video height> is not specified, this is the default
845
+ defaultVideoHeight: 270,
846
+ // if set, overrides <video width>
847
+ //videoWidth: 1,
848
+ // if set, overrides <video height>
849
+ //videoHeight: 1
850
+ } );
851
+ rtMediaHook.call( 'rtmedia_js_after_activity_added', [] );
852
}
853
+ $( "#whats-new-post-in" ).removeAttr( 'disabled' );
854
+ $( "#rtmedia-add-media-button-post-update" ).removeAttr( 'disabled' );
855
856
}
857
}
858
+ } );
859
+ } );
860
/**
861
* rtMedia Comment Js
862
*/
863
+ jQuery( document ).ready( function ( $ ) {
864
+ jQuery( document ).on( "click", "#rt_media_comment_form #rt_media_comment_submit", function ( e ) {
865
e.preventDefault();
866
+ if ( $.trim( $( "#comment_content" ).val() ) == "" ) {
867
+ alert( rtmedia_empty_comment_msg );
868
return false;
869
}
870
871
+ $( this ).attr( 'disabled', 'disabled' );
872
873
+ $.ajax( {
874
+ url: jQuery( "#rt_media_comment_form" ).attr( "action" ),
875
type: 'post',
876
+ data: jQuery( "#rt_media_comment_form" ).serialize() + "&rtajax=true",
877
+ success: function ( data ) {
878
+ $( '#rtmedia-no-comments' ).remove();
879
+ $( "#rtmedia_comment_ul" ).append( data );
880
+ $( "#comment_content" ).val( "" );
881
+ $( "#rt_media_comment_form #rt_media_comment_submit" ).removeAttr( 'disabled' );
882
+ rtMediaHook.call( 'rtmedia_js_after_comment_added', [] );
883
}
884
+ } );
885
886
887
return false;
888
+ } );
889
890
//Delete comment
891
+ jQuery( document ).on( 'click', '.rtmedia-delete-comment', function ( e ) {
892
+ e.preventDefault();
893
+ var ask_confirmation = true
894
+ ask_confirmation = rtMediaHook.call( 'rtmedia_js_delete_comment_confirmation', [ask_confirmation] );
895
+ if ( ask_confirmation && !confirm( rtmedia_media_comment_delete_confirmation ) )
896
+ return false;
897
+ var current_comment = jQuery( this );
898
+ var current_comment_parent = current_comment.parent();
899
+ var comment_id = current_comment.data( 'id' );
900
+ current_comment_parent.css( 'opacity', '0.4' );
901
+ if ( comment_id == '' || isNaN( comment_id ) ) {
902
+ return false;
903
+ }
904
+ var action = current_comment.closest( 'ul' ).data( "action" );
905
+
906
+ jQuery.ajax( {
907
+ url: action,
908
+ type: 'post',
909
+ data: { comment_id: comment_id },
910
+ success: function ( res ) {
911
+ if ( res != 'undefined' && res == 1 ) {
912
+ current_comment.closest( 'li' ).hide( 1000, function () {
913
+ current_comment.closest( 'li' ).remove();
914
+ } );
915
+ } else {
916
+ current_comment.css( 'opacity', '1' );
917
+ }
918
+ rtMediaHook.call( 'rtmedia_js_after_comment_deleted', [] );
919
+ }
920
+ } );
921
+
922
+ } );
923
+
924
+ $( document ).on( "click", '.rtmedia-like', function ( e ) {
925
e.preventDefault();
926
var that = this;
927
+ $( this ).attr( 'disabled', 'disabled' );
928
+ var url = $( this ).parent().attr( "action" );
929
+ $( that ).prepend( "<img class='rtm-like-loading' src='" + rMedia_loading_file + "' style='width:10px' />" );
930
+ $.ajax( {
931
url: url,
932
type: 'post',
933
data: "json=true",
934
+ success: function ( data ) {
935
try {
936
+ data = JSON.parse( data );
937
+ } catch ( e ) {
938
939
}
940
+ $( '.rtmedia-like span' ).html( data.next );
941
+ $( '.rtm-like-loading' ).remove();
942
+ $( that ).removeAttr( 'disabled' );
943
//update the like counter
944
+ $( '.rtmedia-like-counter' ).html( data.count );
945
+ if ( data.count > 0 ) {
946
+ $( '.rtmedia-like-info' ).removeClass( 'hide' );
947
+ } else {
948
+ $( '.rtmedia-like-info' ).addClass( 'hide' );
949
}
950
}
951
+ } );
952
953
954
+ } );
955
+ $( document ).on( "click", '.rtmedia-featured', function ( e ) {
956
e.preventDefault();
957
var that = this;
958
+ $( this ).attr( 'disabled', 'disabled' );
959
+ var url = $( this ).parent().attr( "action" );
960
+ $( that ).prepend( "<img class='rtm-featured-loading' src='" + rMedia_loading_file + "' />" );
961
+ $.ajax( {
962
url: url,
963
type: 'post',
964
data: "json=true",
965
+ success: function ( data ) {
966
try {
967
+ data = JSON.parse( data );
968
+ } catch ( e ) {
969
970
}
971
+ $( that ).find( 'span' ).html( data.next );
972
+ $( '.rtm-featured-loading' ).remove();
973
+ $( that ).removeAttr( 'disabled' );
974
}
975
+ } );
976
977
978
+ } );
979
+ jQuery( "#div-attache-rtmedia" ).find( "input[type=file]" ).each( function () {
980
//$(this).attr("capture", "camera");
981
// $(this).attr("accept", $(this).attr("accept") + ';capture=camera');
982
983
+ } );
984
985
// manually trigger fadein event so that we can bind some function on this event. It is used in activity when content getting load via ajax
986
var _old_fadein = $.fn.fadeIn;
987
+ jQuery.fn.fadeIn = function () {
988
+ return _old_fadein.apply( this, arguments ).trigger( "fadeIn" );
989
};
990
+ } );
app/assets/js/rtMedia.js CHANGED
@@ -185,7 +185,7 @@ jQuery('document').ready(function($) {
185
})
186
//rtmedia_lightbox_enabled from setting
187
if (typeof(rtmedia_lightbox_enabled) != 'undefined' && rtmedia_lightbox_enabled == "1") {
188
- apply_rtMagnificPopup('.rtmedia-list-media, .rtmedia-activity-container ul.rtmedia-list, #bp-media-list,.widget-item-listing,.bp-media-sc-list, li.media.album_updated ul,ul.bp-media-list-media, li.activity-item div.activity-content div.activity-inner div.bp_media_content, .rtm-bbp-container');
189
}
190
191
jQuery.ajaxPrefilter(function(options, originalOptions, jqXHR) {
@@ -343,6 +343,7 @@ jQuery('document').ready(function($) {
343
rtmedia_media_view_counts();
344
rtmedia_init_media_deleting();
345
rtmedia_init_popup_navigation();
346
var height = $(window).height() ;
347
//console.log( height );
348
// , .mfp-content #buddypress .rtmedia-container,
@@ -392,6 +393,23 @@ jQuery('document').ready(function($) {
392
rtm_mfp.prev();
393
});
394
}
395
var dragArea = jQuery("#drag-drop-area");
396
var activityArea = jQuery('#whats-new');
397
var content = dragArea.html();
@@ -532,3 +550,19 @@ function bp_media_create_element(id) {
532
};
533
534
})(jQuery);
185
})
186
//rtmedia_lightbox_enabled from setting
187
if (typeof(rtmedia_lightbox_enabled) != 'undefined' && rtmedia_lightbox_enabled == "1") {
188
+ apply_rtMagnificPopup('.rtmedia-list-media, .rtmedia-activity-container ul.rtmedia-list, #bp-media-list,.bp-media-sc-list, li.media.album_updated ul,ul.bp-media-list-media, li.activity-item div.activity-content div.activity-inner div.bp_media_content, .rtm-bbp-container');
189
}
190
191
jQuery.ajaxPrefilter(function(options, originalOptions, jqXHR) {
343
rtmedia_media_view_counts();
344
rtmedia_init_media_deleting();
345
rtmedia_init_popup_navigation();
346
+ rtmedia_disable_popup_navigation_comment_focus();
347
var height = $(window).height() ;
348
//console.log( height );
349
// , .mfp-content #buddypress .rtmedia-container,
393
rtm_mfp.prev();
394
});
395
}
396
+
397
+ function rtmedia_disable_popup_navigation_comment_focus() {
398
+ jQuery('#comment_content').live('focusin',function(){
399
+ jQuery(document).unbind('keydown');
400
+ });
401
+ jQuery('#comment_content').live('focusout',function(){
402
+ var rtm_mfp = jQuery.magnificPopup.instance;
403
+ jQuery(document).on('keydown',function(e) {
404
+ if (e.keyCode === 37) {
405
+ rtm_mfp.prev();
406
+ } else if (e.keyCode === 39) {
407
+ rtm_mfp.next();
408
+ }
409
+ });
410
+ });
411
+ }
412
+
413
var dragArea = jQuery("#drag-drop-area");
414
var activityArea = jQuery('#whats-new');
415
var content = dragArea.html();
550
};
551
552
})(jQuery);
553
+
554
+ function rtmedia_version_compare( left, right ) {
555
+ if (typeof left + typeof right != 'stringstring')
556
+ return false;
557
+ var a = left.split('.')
558
+ , b = right.split('.')
559
+ , i = 0, len = Math.max(a.length, b.length);
560
+ for (; i < len; i++) {
561
+ if ((a[i] && !b[i] && parseInt(a[i]) > 0) || (parseInt(a[i]) > parseInt(b[i]))) {
562
+ return true;
563
+ } else if ((b[i] && !a[i] && parseInt(b[i]) > 0) || (parseInt(a[i]) < parseInt(b[i]))) {
564
+ return false;
565
+ }
566
+ }
567
+ return true;
568
+ }
app/importers/RTMediaMediaSizeImporter.php ADDED
@@ -0,0 +1,243 @@
1
+ <?php
2
+
3
+ /*
4
+ * To change this license header, choose License Headers in Project Properties.
5
+ * To change this template file, choose Tools | Templates
6
+ * and open the template in the editor.
7
+ */
8
+
9
+ /**
10
+ * Description of RTMediaMediaSizeImporter
11
+ *
12
+ * @author ritz
13
+ */
14
+ class RTMediaMediaSizeImporter {
15
+
16
+ function __construct() {
17
+ add_filter( "rtmedia_filter_admin_pages_array", array( $this, "rtmedia_add_admin_page_array" ), 11, 1 );
18
+ add_action( 'wp_ajax_rtmedia_media_size_import', array( $this, "rtmedia_media_size_import" ) );
19
+ add_action( 'admin_init', array( $this, 'add_admin_notice' ) );
20
+ add_action( 'admin_menu', array( $this, 'menu' ), 10 );
21
+ }
22
+
23
+ function menu() {
24
+ add_submenu_page( 'rtmedia-setting', __( 'Media Size Import', 'rtmedia' ), __( 'Media Size Import', 'rtmedia' ), 'manage_options', 'rtmedia-migration-media-size-import', array( $this, 'init' ) );
25
+ }
26
+
27
+ function rtmedia_add_admin_page_array( $admin_pages ) {
28
+ $admin_pages[ ] = "rtmedia_page_rtmedia-media-size-import";
29
+
30
+ return $admin_pages;
31
+ }
32
+
33
+ function add_admin_notice() {
34
+ $pending = $this->get_pending_count();
35
+ if ( $pending < 0 ){
36
+ $pending = 0;
37
+ }
38
+ rtmedia_update_site_option( "rtmedia_media_size_import_pending_count", $pending );
39
+ if ( $pending > 0 ){
40
+ if ( ! ( isset ( $_REQUEST[ "page" ] ) && $_REQUEST[ "page" ] == "rtmedia-migration-media-size-import" ) ){
41
+ $site_option = get_site_option( "rtmedia_media_size_import_notice" );
42
+ if ( ! $site_option || $site_option != "hide" ){
43
+ rtmedia_update_site_option( "rtmedia_media_size_import_notice", "show" );
44
+ add_action( 'admin_notices', array( &$this, 'add_rtmedia_media_size_import_notice' ) );
45
+ }
46
+ }
47
+ }
48
+ }
49
+
50
+ function add_rtmedia_media_size_import_notice() {
51
+ if ( current_user_can( 'manage_options' ) ){
52
+ $this->create_notice( "<p><strong>rtMedia</strong>: <a href='" . admin_url( "admin.php?page=rtmedia-migration-media-size-import&force=true" ) . "'>Click Here</a> to import media sizes. <a href='#' onclick='rtmedia_hide_media_size_import_notice()' style='float:right'>" . __( "Hide" ) . "</a> </p>" );
53
+ ?>
54
+ <script type="text/javascript">
55
+ function rtmedia_hide_media_size_import_notice() {
56
+ var data = {action: 'rtmedia_hide_media_size_import_notice'};
57
+ jQuery.post( ajaxurl, data, function ( response ) {
58
+ response = response.trim();
59
+ if ( response === "1" )
60
+ jQuery( '.rtmedia-media-size-import-error' ).remove();
61
+ } );
62
+ }
63
+ </script>
64
+ <?php
65
+ }
66
+ }
67
+
68
+ function create_notice( $message, $type = "error" ) {
69
+ echo '<div class="' . $type . ' rtmedia-media-size-import-error">' . $message . '</div>';
70
+ }
71
+
72
+ function init() {
73
+ $prog = new rtProgress();
74
+ $pending = $this->get_pending_count();
75
+ $total = $this->get_total_count();
76
+ $done = $total - $pending;
77
+ ?>
78
+ <div class="wrap">
79
+ <h2>rtMedia Media Size Import</h2>
80
+ <?php
81
+ echo '<span class="pending">' . rtmedia_migrate_formatseconds( $total - $done ) . '</span><br />';
82
+ echo '<span class="finished">' . $done . '</span>/<span class="total">' . $total . '</span>';
83
+ echo '<img src="images/loading.gif" alt="syncing" id="rtMediaSyncing" style="display:none" />';
84
+
85
+ $temp = $prog->progress( $done, $total );
86
+ $prog->progress_ui( $temp, true );
87
+ ?>
88
+ <script type="text/javascript">
89
+ var false_count = 0;
90
+ var curr_done = 0;
91
+ jQuery( document ).ready( function ( e ) {
92
+ jQuery( "#toplevel_page_rtmedia-settings" ).addClass( "wp-has-current-submenu" )
93
+ jQuery( "#toplevel_page_rtmedia-settings" ).removeClass( "wp-not-current-submenu" )
94
+ jQuery( "#toplevel_page_rtmedia-settings" ).addClass( "wp-menu-open" )
95
+ jQuery( "#toplevel_page_rtmedia-settings>a" ).addClass( "wp-menu-open" )
96
+ jQuery( "#toplevel_page_rtmedia-settings>a" ).addClass( "wp-has-current-submenu" )
97
+ if ( db_total < 1 )
98
+ jQuery( "#submit" ).attr( 'disabled', "disabled" );
99
+ } )
100
+ function db_start_migration( db_done, db_total ) {
101
+
102
+ if ( db_done < db_total ) {
103
+ jQuery( "#rtMediaSyncing" ).show();
104
+ jQuery.ajax( {
105
+ url: rtmedia_admin_ajax,
106
+ type: 'post',
107
+ data: {
108
+ "action": "rtmedia_media_size_import",
109
+ "done": db_done
110
+ },
111
+ success: function ( sdata ) {
112
+
113
+ try {
114
+ data = JSON.parse( sdata );
115
+ } catch ( e ) {
116
+ jQuery( "#submit" ).attr( 'disabled', "" );
117
+ }
118
+ if ( data.status ) {
119
+ done = parseInt( data.done );
120
+ total = parseInt( data.total );
121
+ var progw = Math.ceil( (done / total) * 100 );
122
+ if ( progw > 100 ) {
123
+ progw = 100;
124
+ }
125
+ ;
126
+ jQuery( '#rtprogressbar>div' ).css( 'width', progw + '%' );
127
+ jQuery( 'span.finished' ).html( done );
128
+ jQuery( 'span.total' ).html( total );
129
+ jQuery( 'span.pending' ).html( data.pending );
130
+ if( curr_done == done ) {
131
+ false_count++;
132
+ } else {
133
+ false_count = 0;
134
+ }
135
+ curr_done = done;
136
+ if( false_count > 5 ) {
137
+ rtm_show_file_error( done, total );
138
+ } else {
139
+ db_start_migration( done, total );
140
+ }
141
+ } else {
142
+ alert( "Migration completed." );
143
+ jQuery( "#rtMediaSyncing" ).hide();
144
+ }
145
+ },
146
+ error: function () {
147
+ alert( "Error During Migration, Please Refresh Page then try again" );
148
+ jQuery( "#submit" ).removeAttr( 'disabled' );
149
+ }
150
+ } );
151
+ } else {
152
+ alert( "Migration completed." );
153
+ jQuery( "#rtMediaSyncing" ).hide();
154
+ }
155
+ }
156
+ function rtm_show_file_error( done, total ) {
157
+ jQuery( 'span.pending' ).html( "File size of " + ( total - done ) + " file(s) are not imported. Don't worry, you can end importing media size now :)" );
158
+ jQuery( "#rtMediaSyncing" ).hide();
159
+ }
160
+ var db_done = <?php echo $done; ?>;
161
+ var db_total = <?php echo $total; ?>;
162
+ jQuery( document ).on( 'click', '#submit', function ( e ) {
163
+ e.preventDefault();
164
+ db_start_migration( db_done, db_total );
165
+ jQuery( this ).attr( 'disabled', 'disabled' );
166
+ } );
167
+ </script>
168
+ <hr/>
169
+ <?php if ( ! ( isset ( $rtmedia_error ) && $rtmedia_error === true ) ){ ?>
170
+ <input type="button" id="submit" value="start" class="button button-primary"/>
171
+ <?php } ?>
172
+ </div>
173
+ <?php
174
+ }
175
+
176
+ function get_pending_count() {
177
+ global $wpdb;
178
+ $rtmedia_model = new RTMediaModel();
179
+ $query_pending = "SELECT COUNT(*) as pending from {$rtmedia_model->table_name} where file_size IS NULL AND media_type in ('photo','video','document','music','other')";
180
+ $pending_count = $wpdb->get_results( $query_pending );
181
+ if ( $pending_count && sizeof( $pending_count ) > 0 ){
182
+ return $pending_count[ 0 ]->pending;
183
+ }
184
+
185
+ return 0;
186
+ }
187
+
188
+ function get_total_count() {
189
+ global $wpdb;
190
+ $rtmedia_model = new RTMediaModel();
191
+ $query_total = "SELECT COUNT(*) as total from {$rtmedia_model->table_name} where media_type in ('photo','video','document','music','other') ";
192
+ $total_count = $wpdb->get_results( $query_total );
193
+ if ( $total_count && sizeof( $total_count ) > 0 ){
194
+ return $total_count[ 0 ]->total;
195
+ }
196
+
197
+ return 0;
198
+ }
199
+
200
+ function rtmedia_media_size_import( $lastid = 0, $limit = 1 ) {
201
+ global $wpdb;
202
+ $rtmedia_model = new RTMediaModel();
203
+ $get_media_sql = "SELECT * from {$rtmedia_model->table_name} where file_size is NULL and media_type in ('photo','video','document','music','other') order by id limit " . $limit;
204
+ if ( $lastid ){
205
+ $get_media_sql = "SELECT * from {$rtmedia_model->table_name} where id > '" . $lastid . "' AND file_size is NULL and media_type in ('photo','video','document','music','other') order by id limit " . $limit;
206
+ }
207
+ $result = $wpdb->get_results( $get_media_sql );
208
+ if ( $result && sizeof( $result ) > 0 ){
209
+ $this->migrate_single_media( $result[ 0 ] );
210
+ }
211
+ $this->return_migration();
212
+ }
213
+
214
+ function migrate_single_media( $result ) {
215
+ global $wpdb;
216
+ $rtmedia_model = new RTMediaModel();
217
+ $attached_file = get_attached_file( $result->media_id );
218
+ if ( ! file_exists( $attached_file ) ){
219
+ $this->rtmedia_media_size_import( $result->id );
220
+ }
221
+ $file_size = filesize( $attached_file );
222
+ $post = get_post( $result->media_id );
223
+ $post_date = $post->post_date;
224
+ $rtmedia_model->update( array( 'upload_date' => $post_date, 'file_size' => $file_size ), array( 'id' => $result->id ) );
225
+ }
226
+
227
+ function return_migration() {
228
+ $total = $this->get_total_count();
229
+ $pending = $this->get_pending_count();
230
+ $done = $total - $pending;
231
+ if ( $pending < 0 ){
232
+ $pending = 0;
233
+ $done = $total;
234
+ }
235
+ if ( $done > $total ){
236
+ $done = $total;
237
+ }
238
+ rtmedia_update_site_option( 'rtmedia_media_size_import_pending_count', $pending );
239
+ $pending_time = rtmedia_migrate_formatseconds( $pending ). " (estimated)";
240
+ echo json_encode( array( "status" => true, "done" => $done, "total" => $total, "pending" => $pending_time ) );
241
+ die();
242
+ }
243
+ }
app/main/RTMedia.php CHANGED
@@ -92,6 +92,9 @@ class RTMedia
92
add_action('rt_db_upgrade', array($this, 'fix_group_media_privacy'));
93
add_action('rt_db_upgrade', array($this, 'fix_db_collation'));
94
$this->update_db();
95
$this->default_thumbnail = apply_filters('rtmedia_default_thumbnail', RTMEDIA_URL . 'assets/thumb_default.png');
96
add_action('init', array($this, 'check_global_album'));
97
add_action('plugins_loaded', array($this, 'init'), 20);
@@ -834,6 +837,7 @@ class RTMedia
834
wp_localize_script('rtmedia-main', 'rtmedia_more', __('more',"rtmedia"));
835
wp_localize_script('rtmedia-main', 'rtmedia_less', __('less',"rtmedia"));
836
wp_localize_script('rtmedia-main', 'rtmedia_delete_uploaded_media', __('This media is uploaded. Are you sure you want to delete this media?',"rtmedia"));
837
wp_localize_script ( 'rtmedia-backbone', 'rMedia_loading_media', RTMEDIA_URL . "app/assets/img/boxspinner.gif" );
838
global $rtmedia_query;
839
if( class_exists('BuddyPress') ) {
@@ -1005,7 +1009,7 @@ function rtmedia_update_site_option($option_name, $option_value) {
1005
1006
function get_rtmedia_group_link($group_id) {
1007
$group = groups_get_group(array('group_id' => $group_id));
1008
- return home_url(trailingslashit(bp_get_groups_root_slug()) . $group->slug);
1009
}
1010
1011
function rtmedia_get_site_option($option_name, $default = false) {
92
add_action('rt_db_upgrade', array($this, 'fix_group_media_privacy'));
93
add_action('rt_db_upgrade', array($this, 'fix_db_collation'));
94
$this->update_db();
95
+ remove_action('rt_db_upgrade', array($this, 'fix_privacy'));
96
+ remove_action('rt_db_upgrade', array($this, 'fix_group_media_privacy'));
97
+ remove_action('rt_db_upgrade', array($this, 'fix_db_collation'));
98
$this->default_thumbnail = apply_filters('rtmedia_default_thumbnail', RTMEDIA_URL . 'assets/thumb_default.png');
99
add_action('init', array($this, 'check_global_album'));
100
add_action('plugins_loaded', array($this, 'init'), 20);
837
wp_localize_script('rtmedia-main', 'rtmedia_more', __('more',"rtmedia"));
838
wp_localize_script('rtmedia-main', 'rtmedia_less', __('less',"rtmedia"));
839
wp_localize_script('rtmedia-main', 'rtmedia_delete_uploaded_media', __('This media is uploaded. Are you sure you want to delete this media?',"rtmedia"));
840
+ wp_localize_script('rtmedia-main', 'rtm_wp_version', get_bloginfo('version') );
841
wp_localize_script ( 'rtmedia-backbone', 'rMedia_loading_media', RTMEDIA_URL . "app/assets/img/boxspinner.gif" );
842
global $rtmedia_query;
843
if( class_exists('BuddyPress') ) {
1009
1010
function get_rtmedia_group_link($group_id) {
1011
$group = groups_get_group(array('group_id' => $group_id));
1012
+ return apply_filters( 'rtmedia_get_group_link', home_url( trailingslashit( bp_get_groups_root_slug() ) . $group->slug) );
1013
}
1014
1015
function rtmedia_get_site_option($option_name, $default = false) {
app/main/controllers/activity/RTMediaBuddyPressActivity.php CHANGED
@@ -108,8 +108,13 @@ class RTMediaBuddyPressActivity {
108
}
109
110
function bp_activity_posted_update ( $content, $user_id, $activity_id ) {
111
if ( isset ( $_POST[ "rtMedia_attached_files" ] ) && is_array ( $_POST[ "rtMedia_attached_files" ] ) ) {
112
- global $wpdb, $bp;
113
$updated_content = $wpdb->get_var ( "select content from {$bp->activity->table_name} where id= $activity_id" );
114
115
$objActivity = new RTMediaActivity ( $_POST[ "rtMedia_attached_files" ], 0, $updated_content );
@@ -121,6 +126,9 @@ class RTMediaBuddyPressActivity {
121
$sql = "update $mediaObj->table_name set activity_id = '" . $activity_id . "' where blog_id = '".get_current_blog_id()."' and id in (" . implode ( ",", $_POST[ "rtMedia_attached_files" ] ) . ")";
122
$wpdb->query ( $sql );
123
}
124
if ( isset ( $_POST[ 'rtmedia-privacy' ] ) ) {
125
$privacy = -1;
126
if ( is_rtmedia_privacy_enable () ) {
@@ -164,9 +172,13 @@ class RTMediaBuddyPressActivity {
164
wp_localize_script ( 'rtmedia-backbone', 'is_edit_allowed', $is_edit_allowed );
165
wp_localize_script ( 'rtmedia-backbone', 'rtMedia_update_plupload_config', $params );
166
167
-
168
- $uploadView = new RTMediaUploadView ( array( 'activity' => true ) );
169
- $uploadView->render ( 'uploader' );
170
}
171
172
function override_allowed_tags ( $activity_allowedtags ) {
108
}
109
110
function bp_activity_posted_update ( $content, $user_id, $activity_id ) {
111
+ global $wpdb, $bp;
112
+ $updated_content = "";
113
+
114
+ // hook for rtmedia buddypress before activity posted
115
+ do_action( 'rtmedia_bp_before_activity_posted', $content, $user_id, $activity_id );
116
+
117
if ( isset ( $_POST[ "rtMedia_attached_files" ] ) && is_array ( $_POST[ "rtMedia_attached_files" ] ) ) {
118
$updated_content = $wpdb->get_var ( "select content from {$bp->activity->table_name} where id= $activity_id" );
119
120
$objActivity = new RTMediaActivity ( $_POST[ "rtMedia_attached_files" ], 0, $updated_content );
126
$sql = "update $mediaObj->table_name set activity_id = '" . $activity_id . "' where blog_id = '".get_current_blog_id()."' and id in (" . implode ( ",", $_POST[ "rtMedia_attached_files" ] ) . ")";
127
$wpdb->query ( $sql );
128
}
129
+ // hook for rtmedia buddypress after activity posted
130
+ do_action( 'rtmedia_bp_activity_posted', $updated_content, $user_id, $activity_id );
131
+
132
if ( isset ( $_POST[ 'rtmedia-privacy' ] ) ) {
133
$privacy = -1;
134
if ( is_rtmedia_privacy_enable () ) {
172
wp_localize_script ( 'rtmedia-backbone', 'is_edit_allowed', $is_edit_allowed );
173
wp_localize_script ( 'rtmedia-backbone', 'rtMedia_update_plupload_config', $params );
174
175
+ $allow_upload = apply_filters( 'rtmedia_allow_uploader_view', true, 'activity' );
176
+ if( $allow_upload ) {
177
+ $uploadView = new RTMediaUploadView ( array( 'activity' => true ) );
178
+ $uploadView->render ( 'uploader' );
179
+ } else {
180
+ echo "<div class='rtmedia-upload-not-allowed'>" . apply_filters( 'rtmedia_upload_not_allowed_message', __('You are not allowed to upload/attach media.','rtmedia'), 'activity' ) . "</div>";
181
+ }
182
}
183
184
function override_allowed_tags ( $activity_allowedtags ) {
app/main/controllers/media/RTMediaMedia.php CHANGED
@@ -367,7 +367,7 @@ class RTMediaMedia {
367
$attachments[ ] = array(
368
'post_mime_type' => $file[ 'type' ],
369
'guid' => $file[ 'url' ],
370
- 'post_title' => $uploaded[ 'title' ] ? $uploaded[ 'title' ] : $file[ 'name' ],
371
'post_content' => $uploaded[ 'description' ] ? $uploaded[ 'description' ] : '',
372
'post_parent' => $album_id,
373
'post_author' => $uploaded[ 'media_author' ]
@@ -472,7 +472,10 @@ class RTMediaMedia {
472
'context_id' => $uploaded[ 'context_id' ],
473
'privacy' => $uploaded[ 'privacy' ]
474
);
475
-
476
$media_id[ ] = $this->model->insert ( $media );
477
}
478
return $media_id;
367
$attachments[ ] = array(
368
'post_mime_type' => $file[ 'type' ],
369
'guid' => $file[ 'url' ],
370
+ 'post_title' => $uploaded[ 'title' ] ? $uploaded[ 'title' ] : preg_replace("/\\.[^.\\s]{3,4}#x2F;", "", $file[ 'name' ]),
371
'post_content' => $uploaded[ 'description' ] ? $uploaded[ 'description' ] : '',
372
'post_parent' => $album_id,
373
'post_author' => $uploaded[ 'media_author' ]
472
'context_id' => $uploaded[ 'context_id' ],
473
'privacy' => $uploaded[ 'privacy' ]
474
);
475
+ if( isset( $file_object ) && isset( $file_object[0] ) && isset( $file_object[0]['file'] ) ) {
476
+ $media['file_size'] = filesize( $file_object[0]['file'] );
477
+ }
478
+ $media['upload_date'] = $attachment['post_date'];
479
$media_id[ ] = $this->model->insert ( $media );
480
}
481
return $media_id;
app/main/controllers/shortcodes/RTMediaGalleryShortcode.php CHANGED
@@ -36,8 +36,10 @@ class RTMediaGalleryShortcode {
36
die();
37
}
38
static function register_scripts () {
39
- wp_enqueue_script ( 'plupload-all' );
40
- wp_enqueue_script ( 'rtmedia-backbone', RTMEDIA_URL . 'app/assets/js/rtMedia.backbone.js', array( 'plupload', 'backbone' ), false, true );
41
42
if(is_rtmedia_album_gallery()) {
43
$template_url = add_query_arg(array("action" => 'rtmedia_get_template', "template" => "album-gallery-item"),admin_url("admin-ajax.php"));
36
die();
37
}
38
static function register_scripts () {
39
+ if( ! wp_script_is ( 'plupload-all' ) ) {
40
+ wp_enqueue_script ( 'plupload-all' );
41
+ }
42
+ wp_enqueue_script ( 'rtmedia-backbone', RTMEDIA_URL . 'app/assets/js/rtMedia.backbone.js', array( 'plupload-all', 'backbone' ), false, true );
43
44
if(is_rtmedia_album_gallery()) {
45
$template_url = add_query_arg(array("action" => 'rtmedia_get_template', "template" => "album-gallery-item"),admin_url("admin-ajax.php"));
app/main/controllers/shortcodes/RTMediaUploadShortcode.php CHANGED
@@ -54,49 +54,54 @@ $flag = ( ! ( is_home () || is_post_type_archive () || is_author ()))
54
* @param type $attr
55
*/
56
static function pre_render ( $attr ) {
57
- global $post;
58
- global $rtmedia_query;
59
- if( ! $rtmedia_query )
60
- $rtmedia_query = new RTMediaQuery ();
61
- if( !isset($attr['is_up_shortcode']) || $attr['is_up_shortcode'] !== false) {
62
- $rtmedia_query->is_upload_shortcode = true;// set is_upload_shortcode in rtmedia query as true
63
- } else {
64
- $rtmedia_query->is_upload_shortcode = false;// set is_upload_shortcode in rtmedia query as true
65
- }
66
-
67
- if( isset( $attr['media_type'] ) ) {
68
- global $rtmedia;
69
- $allowed_media_type = $rtmedia->allowed_types;
70
- if( isset($allowed_media_type[$attr['media_type']]) ) {
71
- wp_localize_script('rtmedia-backbone', "rtmedia_upload_type_filter", $allowed_media_type[$attr['media_type']]['extn']);
72
}
73
- }
74
75
- if ( isset ( $attr ) && !empty($attr)) {
76
- if ( ! is_array ( $attr ) ) {
77
- $attr = Array( );
78
- }
79
- if ( ! isset ( $attr[ "context_id" ] ) && isset ( $post->ID ) ) {
80
- $attr[ "context_id" ] = $post->ID;
81
- }
82
- if ( ! isset ( $attr[ "context" ] ) && isset ( $post->post_type ) ) {
83
- $attr[ "context" ] = $post->post_type;
84
- }
85
- }
86
87
- if ( self::display_allowed () || ( isset( $attr['allow_anonymous'] ) && $attr['allow_anonymous'] === true ) ) {
88
- if ( ! _device_can_upload () ) {
89
- echo '<p>' . __( 'The web browser on your device cannot be used to upload files.', 'rtmedia' ) . '</p>';
90
- return;
91
- }
92
- ob_start ();
93
94
- self::$add_sc_script = true;
95
- RTMediaUploadTemplate::render ( $attr );
96
97
- self::$uploader_displayed = true;
98
- return ob_get_clean ();
99
- }
100
}
101
102
}
54
* @param type $attr
55
*/
56
static function pre_render ( $attr ) {
57
+ $allow_upload = apply_filters( 'rtmedia_allow_uploader_view', true, 'uploader_shortcode' );
58
+ if( $allow_upload ) {
59
+ global $post;
60
+ global $rtmedia_query;
61
+ if( ! $rtmedia_query )
62
+ $rtmedia_query = new RTMediaQuery ();
63
+ if( !isset($attr['is_up_shortcode']) || $attr['is_up_shortcode'] !== false) {
64
+ $rtmedia_query->is_upload_shortcode = true;// set is_upload_shortcode in rtmedia query as true
65
+ } else {
66
+ $rtmedia_query->is_upload_shortcode = false;// set is_upload_shortcode in rtmedia query as true
67
}
68
69
+ if( isset( $attr['media_type'] ) ) {
70
+ global $rtmedia;
71
+ $allowed_media_type = $rtmedia->allowed_types;
72
+ if( isset($allowed_media_type[$attr['media_type']]) ) {
73
+ wp_localize_script('rtmedia-backbone', "rtmedia_upload_type_filter", $allowed_media_type[$attr['media_type']]['extn']);
74
+ }
75
+ }
76
77
+ if ( isset ( $attr ) && !empty($attr)) {
78
+ if ( ! is_array ( $attr ) ) {
79
+ $attr = Array( );
80
+ }
81
+ if ( ! isset ( $attr[ "context_id" ] ) && isset ( $post->ID ) ) {
82
+ $attr[ "context_id" ] = $post->ID;
83
+ }
84
+ if ( ! isset ( $attr[ "context" ] ) && isset ( $post->post_type ) ) {
85
+ $attr[ "context" ] = $post->post_type;
86
+ }
87
+ }
88
89
+ if ( self::display_allowed () || ( isset( $attr['allow_anonymous'] ) && $attr['allow_anonymous'] === true ) ) {
90
+ if ( ! _device_can_upload () ) {
91
+ echo '<p>' . __( 'The web browser on your device cannot be used to upload files.', 'rtmedia' ) . '</p>';
92
+ return;
93
+ }
94
+ ob_start ();
95
96
+ self::$add_sc_script = true;
97
+ RTMediaUploadTemplate::render ( $attr );
98
+
99
+ self::$uploader_displayed = true;
100
+ return ob_get_clean ();
101
+ }
102
+ } else {
103
+ echo "<div class='rtmedia-upload-not-allowed'>" . apply_filters( 'rtmedia_upload_not_allowed_message', __('You are not allowed to upload/attach media.','rtmedia'), 'uploader_shortcode' ) . "</div>";
104
+ }
105
}
106
107
}
app/main/controllers/template/rt-template-functions.php CHANGED
@@ -1153,13 +1153,19 @@ function rtmedia_delete_form ( $echo = true) {
1153
* @param type $attr
1154
*/
1155
function rtmedia_uploader ( $attr = '' ) {
1156
- if ( function_exists ( 'bp_is_blog_page' ) && ! bp_is_blog_page () ) {
1157
- if ( function_exists ( 'bp_is_user' ) && bp_is_user () && function_exists ( 'bp_displayed_user_id' ) && bp_displayed_user_id () == get_current_user_id () )
1158
- echo RTMediaUploadShortcode::pre_render ( $attr );
1159
- else if ( function_exists ( 'bp_is_group' ) && bp_is_group () ) {
1160
- if ( can_user_upload_in_group () )
1161
- echo RTMediaUploadShortcode::pre_render ( $attr );
1162
- }
1163
}
1164
}
1165
@@ -2164,3 +2170,67 @@ function is_rtmedia_page() {
2164
2165
return $rtmedia_interaction->routes[RTMEDIA_MEDIA_SLUG]->is_template();
2166
}
1153
* @param type $attr
1154
*/
1155
function rtmedia_uploader ( $attr = '' ) {
1156
+ $allow_upload = apply_filters( 'rtmedia_allow_uploader_view', true, 'media_gallery' );
1157
+ if( $allow_upload ) {